Unverified Commit a92da3c3 authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

Lua 5.1 / 5.3 alignment and document (#3193)

parent 1f386e93
.gdb_history .gdb_history
app/lua/.std
app/lua53/.std
sdk/ sdk/
cache/ cache/
.ccache/ .ccache/
......
...@@ -7,7 +7,6 @@ extern "C" { ...@@ -7,7 +7,6 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#define MAXOPT 16 #define MAXOPT 16
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "lua.h" #include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h"
#include "os_type.h" #include "os_type.h"
#include "user_interface.h" #include "user_interface.h"
......
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
#include "osapi.h" #include "osapi.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "user_interface.h" #include "user_interface.h"
#include "espconn.h" #include "espconn.h"
#include "mem.h" #include "mem.h"
#include "limits.h"
#include "httpclient.h" #include "httpclient.h"
#include "stdlib.h"
#include "pm/swtimer.h" #include "pm/swtimer.h"
#define REDIRECTION_FOLLOW_MAX 20 #define REDIRECTION_FOLLOW_MAX 20
......
...@@ -247,7 +247,8 @@ ...@@ -247,7 +247,8 @@
#define LUA_TASK_PRIO USER_TASK_PRIO_0 #define LUA_TASK_PRIO USER_TASK_PRIO_0
#define LUA_PROCESS_LINE_SIG 2 #define LUA_PROCESS_LINE_SIG 2
#define LUA_OPTIMIZE_DEBUG 2 // LUAI_OPTIMIZE_DEBUG 0 = Keep all debug; 1 = keep line number info; 2 = remove all debug
#define LUAI_OPTIMIZE_DEBUG 1
#define READLINE_INTERVAL 80 #define READLINE_INTERVAL 80
#define STRBUF_DEFAULT_INCREMENT 3 #define STRBUF_DEFAULT_INCREMENT 3
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback() #define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()
......
...@@ -152,6 +152,16 @@ LUA_API lua_State *lua_newthread (lua_State *L) { ...@@ -152,6 +152,16 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
*/ */
/*
** convert an acceptable stack index into an absolute index
*/
LUA_API int lua_absindex (lua_State *L, int idx) {
return (idx > 0 || idx <= LUA_REGISTRYINDEX)
? idx
: cast_int(L->top - L->base) - 1 + idx;
}
LUA_API int lua_gettop (lua_State *L) { LUA_API int lua_gettop (lua_State *L) {
return cast_int(L->top - L->base); return cast_int(L->top - L->base);
} }
...@@ -241,7 +251,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { ...@@ -241,7 +251,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) {
LUA_API int lua_type (lua_State *L, int idx) { LUA_API int lua_type (lua_State *L, int idx) {
StkId o = index2adr(L, idx); StkId o = index2adr(L, idx);
return (o == luaO_nilobject) ? LUA_TNONE : basettype(o); return (o == luaO_nilobject) ? LUA_TNONE : ttnov(o);
} }
...@@ -253,7 +263,7 @@ LUA_API int lua_fulltype (lua_State *L, int idx) { ...@@ -253,7 +263,7 @@ LUA_API int lua_fulltype (lua_State *L, int idx) {
LUA_API const char *lua_typename (lua_State *L, int t) { LUA_API const char *lua_typename (lua_State *L, int t) {
UNUSED(L); UNUSED(L);
return (t == LUA_TNONE) ? "no value" : luaT_typenames[t]; return (t == LUA_TNONE || t >= LUA_NUMTAGS) ? "no value" : luaT_typenames[t];
} }
...@@ -290,32 +300,25 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { ...@@ -290,32 +300,25 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
} }
LUA_API int lua_equal (lua_State *L, int index1, int index2) { LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
StkId o1, o2;
int i;
lua_lock(L); /* may call tag method */
o1 = index2adr(L, index1);
o2 = index2adr(L, index2);
i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);
lua_unlock(L);
return i;
}
LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
StkId o1, o2; StkId o1, o2;
int i; int i = 0;
lua_lock(L); /* may call tag method */ lua_lock(L); /* may call tag method */
o1 = index2adr(L, index1); o1 = index2adr(L, index1);
o2 = index2adr(L, index2); o2 = index2adr(L, index2);
i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 if (o1 != luaO_nilobject && o2 != luaO_nilobject) {
: luaV_lessthan(L, o1, o2); switch (op) {
case LUA_OPEQ: i = luaV_equalval(L, o1, o2); break;
case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
default: api_check(L, 0);
}
}
lua_unlock(L); lua_unlock(L);
return i; return i;
} }
LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
TValue n; TValue n;
const TValue *o = index2adr(L, idx); const TValue *o = index2adr(L, idx);
...@@ -366,7 +369,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { ...@@ -366,7 +369,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
LUA_API size_t lua_objlen (lua_State *L, int idx) { LUA_API size_t lua_objlen (lua_State *L, int idx) {
StkId o = index2adr(L, idx); StkId o = index2adr(L, idx);
switch (basettype(o)) { switch (ttnov(o)) {
case LUA_TSTRING: return tsvalue(o)->len; case LUA_TSTRING: return tsvalue(o)->len;
case LUA_TUSERDATA: return uvalue(o)->len; case LUA_TUSERDATA: return uvalue(o)->len;
case LUA_TTABLE: return luaH_getn(hvalue(o)); case LUA_TTABLE: return luaH_getn(hvalue(o));
...@@ -552,16 +555,17 @@ LUA_API int lua_pushthread (lua_State *L) { ...@@ -552,16 +555,17 @@ LUA_API int lua_pushthread (lua_State *L) {
*/ */
LUA_API void lua_gettable (lua_State *L, int idx) { LUA_API int lua_gettable (lua_State *L, int idx) {
StkId t; StkId t;
lua_lock(L); lua_lock(L);
t = index2adr(L, idx); t = index2adr(L, idx);
api_checkvalidindex(L, t); api_checkvalidindex(L, t);
luaV_gettable(L, t, L->top - 1, L->top - 1); luaV_gettable(L, t, L->top - 1, L->top - 1);
lua_unlock(L); lua_unlock(L);
return ttnov(L->top - 1);
} }
LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { LUA_API int lua_getfield (lua_State *L, int idx, const char *k) {
StkId t; StkId t;
TValue key; TValue key;
lua_lock(L); lua_lock(L);
...@@ -573,20 +577,36 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { ...@@ -573,20 +577,36 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
luaV_gettable(L, t, &key, L->top); luaV_gettable(L, t, &key, L->top);
api_incr_top(L); api_incr_top(L);
lua_unlock(L); lua_unlock(L);
return ttnov(L->top - 1);
} }
LUA_API int lua_geti (lua_State *L, int idx, int n) {
StkId t;
TValue key;
lua_lock(L);
t = index2adr(L, idx);
api_checkvalidindex(L, t);
fixedstack(L);
setnvalue(&key, n);
unfixedstack(L);
luaV_gettable(L, t, &key, L->top);
api_incr_top(L);
lua_unlock(L);
return ttnov(L->top - 1);
}
LUA_API void lua_rawget (lua_State *L, int idx) { LUA_API int lua_rawget (lua_State *L, int idx) {
StkId t; StkId t;
lua_lock(L); lua_lock(L);
t = index2adr(L, idx); t = index2adr(L, idx);
api_check(L, ttistable(t)); api_check(L, ttistable(t));
setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
lua_unlock(L); lua_unlock(L);
return ttnov(L->top - 1);
} }
LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { LUA_API int lua_rawgeti (lua_State *L, int idx, int n) {
StkId o; StkId o;
lua_lock(L); lua_lock(L);
o = index2adr(L, idx); o = index2adr(L, idx);
...@@ -594,6 +614,21 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { ...@@ -594,6 +614,21 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
setobj2s(L, L->top, luaH_getnum(hvalue(o), n)); setobj2s(L, L->top, luaH_getnum(hvalue(o), n));
api_incr_top(L); api_incr_top(L);
lua_unlock(L); lua_unlock(L);
return ttnov(L->top - 1);
}
LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {
StkId t;
TValue k;
lua_lock(L);
t = index2adr(L, idx);
api_check(L, ttistable(t));
setpvalue(&k, cast(void *, p));
setobj2s(L, L->top, luaH_get(hvalue(t), &k));
api_incr_top(L);
lua_unlock(L);
return ttnov(L->top - 1);
} }
...@@ -612,7 +647,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { ...@@ -612,7 +647,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
int res; int res;
lua_lock(L); lua_lock(L);
obj = index2adr(L, objindex); obj = index2adr(L, objindex);
switch (basettype(obj)) { switch (ttnov(obj)) {
case LUA_TTABLE: case LUA_TTABLE:
mt = hvalue(obj)->metatable; mt = hvalue(obj)->metatable;
break; break;
...@@ -620,7 +655,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { ...@@ -620,7 +655,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
mt = uvalue(obj)->metatable; mt = uvalue(obj)->metatable;
break; break;
default: default:
mt = G(L)->mt[basettype(obj)]; mt = G(L)->mt[ttnov(obj)];
break; break;
} }
if (mt == NULL) if (mt == NULL)
...@@ -720,6 +755,23 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { ...@@ -720,6 +755,23 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
} }
LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
StkId o;
TValue k;
lua_lock(L);
api_checknelems(L, 1);
o = index2adr(L, idx);
api_check(L, ttistable(o));
fixedstack(L);
setpvalue(&k, cast(void *, p))
setobj2t(L, luaH_set(L, hvalue(o), &k), L->top-1);
unfixedstack(L);
luaC_barriert(L, hvalue(o), L->top-1);
L->top--;
lua_unlock(L);
}
LUA_API int lua_setmetatable (lua_State *L, int objindex) { LUA_API int lua_setmetatable (lua_State *L, int objindex) {
TValue *obj; TValue *obj;
Table *mt; Table *mt;
...@@ -750,7 +802,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { ...@@ -750,7 +802,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
break; break;
} }
default: { default: {
G(L)->mt[basettype(obj)] = mt; G(L)->mt[ttnov(obj)] = mt;
break; break;
} }
} }
...@@ -901,7 +953,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, ...@@ -901,7 +953,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
} }
LUA_API int lua_dumpEx (lua_State *L, lua_Writer writer, void *data, int stripping) { LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int stripping) {
int status; int status;
TValue *o; TValue *o;
lua_lock(L); lua_lock(L);
...@@ -916,6 +968,30 @@ LUA_API int lua_dumpEx (lua_State *L, lua_Writer writer, void *data, int strippi ...@@ -916,6 +968,30 @@ LUA_API int lua_dumpEx (lua_State *L, lua_Writer writer, void *data, int strippi
} }
LUA_API int lua_stripdebug (lua_State *L, int stripping){
TValue *o = L->top - 1;
Proto *p = NULL;
int res = -1;
lua_lock(L);
api_checknelems(L, 1);
if (isLfunction(o)) {
p = clvalue(o)->l.p;
if (p && !isLFSobject(p) && (unsigned) stripping < 3 ) {
// found a valid proto to strip
res = luaG_stripdebug(L, p, stripping, 1);
}
} else if (ttisnil(L->top - 1)) {
// get or set the default strip level
if ((unsigned) stripping < 3)
G(L)->stripdefault = stripping;
res = G(L)->stripdefault;
}
L->top--;
lua_unlock(L);
return res;
}
LUA_API int lua_status (lua_State *L) { LUA_API int lua_status (lua_State *L) {
return L->status; return L->status;
} }
...@@ -1136,15 +1212,15 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { ...@@ -1136,15 +1212,15 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
return name; return name;
} }
LUA_API void lua_setegcmode( lua_State *L, int mode, int limit) { LUA_API void lua_setegcmode ( lua_State *L, int mode, int limit) {
G(L)->egcmode = mode; G(L)->egcmode = mode;
G(L)->memlimit = limit; G(L)->memlimit = limit;
} }
LUA_API void legc_set_mode(lua_State *L, int mode, int limit) { LUA_API void lua_getegcinfo (lua_State *L, int *totals) {
global_State *g = G(L); if (totals) {
totals[0] = G(L)->totalbytes;
g->egcmode = mode; totals[1] = G(L)->estimate;
g->memlimit = limit; }
} }
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
*/ */
#define lauxlib_c #define lauxlib_c
#include "lauxlib.h"
#define LUA_LIB #define LUA_LIB
#include "lauxlib.h"
#include "lgc.h" #include "lgc.h"
#include "ldo.h" #include "ldo.h"
#include "lobject.h" #include "lobject.h"
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#define lauxlib_h #define lauxlib_h
#include "lua.h" #include "lua.h"
#ifdef LUA_LIB
#include "lnodemcu.h"
#endif
#include <stdio.h> #include <stdio.h>
...@@ -73,7 +76,7 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, ...@@ -73,7 +76,7 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
LUALIB_API int (luaL_ref) (lua_State *L, int t); LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
#define luaL_unref2(l,t,r) luaL_unref(L, (t), (r)); r = LUA_NOREF #define luaL_unref2(l,t,r) do {luaL_unref(L, (t), (r)); r = LUA_NOREF;} while (0)
LUALIB_API void (luaL_reref) (lua_State *L, int t, int *ref); LUALIB_API void (luaL_reref) (lua_State *L, int t, int *ref);
LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
...@@ -108,8 +111,8 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message) ...@@ -108,8 +111,8 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message)
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#define luaL_checktable(L,n) luaL_checktype(L, (n), LUA_TTABLE); #define luaL_checktable(L,n) luaL_checktype(L, (n), LUA_TTABLE)
#define luaL_checkfunction(L,n) luaL_checktype(L, (n), LUA_TFUNCTION); #define luaL_checkfunction(L,n) luaL_checktype(L, (n), LUA_TFUNCTION)
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
...@@ -162,8 +165,16 @@ LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); ...@@ -162,8 +165,16 @@ LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
/* }====================================================== */ /* }====================================================== */
LUALIB_API int luaL_pcallx (lua_State *L, int narg, int nres); LUALIB_API int (luaL_pushlfsmodules) (lua_State *L);
LUALIB_API int luaL_posttask( lua_State* L, int prio ); LUALIB_API int (luaL_pushlfsmodule) (lua_State *L);
LUALIB_API int (luaL_pushlfsdts) (lua_State *L);
LUALIB_API void (luaL_lfsreload) (lua_State *L);
LUALIB_API int (luaL_pcallx) (lua_State *L, int narg, int nres);
LUALIB_API int (luaL_posttask) ( lua_State* L, int prio );
#define LUA_TASK_LOW 0
#define LUA_TASK_MEDIUM 1
#define LUA_TASK_HIGH 2
/* }====================================================== */ /* }====================================================== */
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#define LUA_LIB #define LUA_LIB
#include "lua.h" #include "lua.h"
#include "lnodemcu.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
......
...@@ -780,8 +780,6 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { ...@@ -780,8 +780,6 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
} }
#ifdef LUA_OPTIMIZE_DEBUG
/* /*
* Attempted to write to last (null terminator) byte of lineinfo, so need * Attempted to write to last (null terminator) byte of lineinfo, so need
* to grow the lineinfo vector and extend the fill bytes * to grow the lineinfo vector and extend the fill bytes
...@@ -828,10 +826,8 @@ static void generateInfoDeltaLine(FuncState *fs, int line) { ...@@ -828,10 +826,8 @@ static void generateInfoDeltaLine(FuncState *fs, int line) {
fs->lastlineOffset = p - fs->f->packedlineinfo - 1; fs->lastlineOffset = p - fs->f->packedlineinfo - 1;
#undef addDLbyte #undef addDLbyte
} }
#endif
void luaK_fixline (FuncState *fs, int line) { void luaK_fixline (FuncState *fs, int line) {
#ifdef LUA_OPTIMIZE_DEBUG
/* The fixup line can be the same as existing one and in this case there's nothing to do */ /* The fixup line can be the same as existing one and in this case there's nothing to do */
if (line != fs->lastline) { if (line != fs->lastline) {
/* first remove the current line reference */ /* first remove the current line reference */
...@@ -862,9 +858,6 @@ void luaK_fixline (FuncState *fs, int line) { ...@@ -862,9 +858,6 @@ void luaK_fixline (FuncState *fs, int line) {
/* Then add the new line reference */ /* Then add the new line reference */
generateInfoDeltaLine(fs, line); generateInfoDeltaLine(fs, line);
} }
#else
fs->f->lineinfo[fs->pc - 1] = line;
#endif
} }
...@@ -876,7 +869,6 @@ static int luaK_code (FuncState *fs, Instruction i, int line) { ...@@ -876,7 +869,6 @@ static int luaK_code (FuncState *fs, Instruction i, int line) {
MAX_INT, "code size overflow"); MAX_INT, "code size overflow");
f->code[fs->pc] = i; f->code[fs->pc] = i;
/* save corresponding line information */ /* save corresponding line information */
#ifdef LUA_OPTIMIZE_DEBUG
/* note that frst time fs->lastline==0 through, so the else branch is taken */ /* note that frst time fs->lastline==0 through, so the else branch is taken */
if (fs->pc == fs->lineinfoLastPC+1) { if (fs->pc == fs->lineinfoLastPC+1) {
if (line == fs->lastline && f->packedlineinfo[fs->lastlineOffset] < INFO_MAX_LINECNT) { if (line == fs->lastline && f->packedlineinfo[fs->lastlineOffset] < INFO_MAX_LINECNT) {
...@@ -890,11 +882,6 @@ static int luaK_code (FuncState *fs, Instruction i, int line) { ...@@ -890,11 +882,6 @@ static int luaK_code (FuncState *fs, Instruction i, int line) {
luaK_fixline(fs,line); luaK_fixline(fs,line);
} }
fs->lineinfoLastPC = fs->pc; fs->lineinfoLastPC = fs->pc;
#else
luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
MAX_INT, "code size overflow");
f->lineinfo[fs->pc] = line;
#endif
return fs->pc++; return fs->pc++;
} }
......
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
#include "lstring.h"
#include "lflash.h"
#include "lnodemcu.h"
#include "user_modules.h" #include "user_modules.h"
...@@ -27,34 +24,16 @@ static int db_getregistry (lua_State *L) { ...@@ -27,34 +24,16 @@ static int db_getregistry (lua_State *L) {
} }
static int db_getstrings (lua_State *L) { static int db_getstrings (lua_State *L) {
size_t i,n=0; static const char *const opts[] = {"RAM","ROM",NULL};
stringtable *tb; int opt = luaL_checkoption(L, 1, "RAM", opts);
GCObject *o; if (lua_pushstringsarray(L, opt)) {
#ifndef LUA_CROSS_COMPILER if(lua_getglobal(L, "table") == LUA_TTABLE) {
const char *opt = lua_tolstring (L, 1, &n); lua_getfield(L, -1, "sort"); /* look up table.sort function */
if (n==3 && memcmp(opt, "ROM", 4) == 0) { lua_replace(L, -2); /* dump the table table */
if (G(L)->ROstrt.hash == NULL) lua_pushvalue(L, -2); /* duplicate the strt_copy ref */
return 0; lua_call(L, 1, 0); /* table.sort(strt_copy) */
tb = &G(L)->ROstrt;
}
else
#endif
tb = &G(L)->strt;
lua_settop(L, 0);
lua_createtable(L, tb->nuse, 0); /* create table the same size as the strt */
for (i=0, n=1; i<tb->size; i++) {
for(o = tb->hash[i]; o; o=o->gch.next) {
TString *ts =cast(TString *, o);
lua_pushnil(L);
setsvalue2s(L, L->top-1, ts);
lua_rawseti(L, -2, n++); /* enumerate the strt, adding elements */
} }
} }
lua_getfield(L, LUA_GLOBALSINDEX, "table");
lua_getfield(L, -1, "sort"); /* look up table.sort function */
lua_replace(L, -2); /* dump the table table */
lua_pushvalue(L, -2); /* duplicate the strt_copy ref */
lua_call(L, 1, 0); /* table.sort(strt_copy) */
return 1; return 1;
} }
......
...@@ -182,8 +182,7 @@ static void info_tailcall (lua_Debug *ar) { ...@@ -182,8 +182,7 @@ static void info_tailcall (lua_Debug *ar) {
# define INFO_DELTA_7BITS 0x7F # define INFO_DELTA_7BITS 0x7F
# define INFO_MAX_LINECNT 126 # define INFO_MAX_LINECNT 126
Table *t = luaH_new(L, 0, 0); Table *t = luaH_new(L, 0, 0);
#ifdef LUA_OPTIMIZE_DEBUG
int line = 0; int line = 0;
unsigned char *p = f->l.p->packedlineinfo; unsigned char *p = f->l.p->packedlineinfo;
if (p) { if (p) {
...@@ -203,18 +202,11 @@ static void info_tailcall (lua_Debug *ar) { ...@@ -203,18 +202,11 @@ static void info_tailcall (lua_Debug *ar) {
setbvalue(luaH_setnum(L, t, line), 1); setbvalue(luaH_setnum(L, t, line), 1);
} }
} }
#else sethvalue(L, L->top, t);
int *lineinfo = f->l.p->lineinfo;
int i;
for (i=0; i<f->l.p->sizelineinfo; i++)
setbvalue(luaH_setnum(L, t, lineinfo[i]), 1);
#endif
sethvalue(L, L->top, t);
} }
incr_top(L); incr_top(L);
} }
#ifdef LUA_OPTIMIZE_DEBUG
/* /*
* This may seem expensive but this is only accessed frequently in traceexec * This may seem expensive but this is only accessed frequently in traceexec
* and the while loop will be executed roughly half the number of non-blank * and the while loop will be executed roughly half the number of non-blank
...@@ -249,18 +241,17 @@ int luaG_getline (const Proto *f, int pc) { ...@@ -249,18 +241,17 @@ int luaG_getline (const Proto *f, int pc) {
static int stripdebug (lua_State *L, Proto *f, int level) { static int stripdebug (lua_State *L, Proto *f, int level) {
int len = 0, sizepackedlineinfo; int len = 0, sizepackedlineinfo;
TString* dummy;
switch (level) { switch (level) {
case 3:
sizepackedlineinfo = strlen(cast(char *, f->packedlineinfo))+1;
f->packedlineinfo = luaM_freearray(L, f->packedlineinfo, sizepackedlineinfo, unsigned char);
len += sizepackedlineinfo;
case 2: case 2:
len += f->sizelocvars * (sizeof(struct LocVar) + sizeof(dummy->tsv) + sizeof(struct LocVar *)); if (f->packedlineinfo) {
sizepackedlineinfo = strlen(cast(char *, f->packedlineinfo))+1;
f->packedlineinfo = luaM_freearray(L, f->packedlineinfo, sizepackedlineinfo, unsigned char);
len += sizepackedlineinfo;
}
case 1:
f->locvars = luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); f->locvars = luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
f->upvalues = luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); f->upvalues = luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
len += f->sizelocvars * (sizeof(struct LocVar) + sizeof(dummy->tsv) + sizeof(struct LocVar *)) + len += f->sizelocvars*sizeof(struct LocVar) + f->sizeupvalues*sizeof(TString *);
f->sizeupvalues * (sizeof(dummy->tsv) + sizeof(TString *));
f->sizelocvars = 0; f->sizelocvars = 0;
f->sizeupvalues = 0; f->sizeupvalues = 0;
} }
...@@ -276,7 +267,6 @@ LUA_API int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv){ ...@@ -276,7 +267,6 @@ LUA_API int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv){
len += stripdebug (L, f, level); len += stripdebug (L, f, level);
return len; return len;
} }
#endif
static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
...@@ -379,9 +369,6 @@ static int precheck (const Proto *pt) { ...@@ -379,9 +369,6 @@ static int precheck (const Proto *pt) {
check(!(pt->is_vararg & VARARG_NEEDSARG) || check(!(pt->is_vararg & VARARG_NEEDSARG) ||
(pt->is_vararg & VARARG_HASARG)); (pt->is_vararg & VARARG_HASARG));
check(pt->sizeupvalues <= pt->nups); check(pt->sizeupvalues <= pt->nups);
#ifndef LUA_OPTIMIZE_DEBUG
check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
#endif
check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
return 1; return 1;
} }
...@@ -668,7 +655,7 @@ static int isinstack (CallInfo *ci, const TValue *o) { ...@@ -668,7 +655,7 @@ static int isinstack (CallInfo *ci, const TValue *o) {
void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
const char *name = NULL; const char *name = NULL;
const char *t = luaT_typenames[basettype(o)]; const char *t = luaT_typenames[ttnov(o)];
const char *kind = (isinstack(L->ci, o)) ? const char *kind = (isinstack(L->ci, o)) ?
getobjname(L, L->ci, cast_int(o - L->base), &name) : getobjname(L, L->ci, cast_int(o - L->base), &name) :
NULL; NULL;
...@@ -696,8 +683,8 @@ void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { ...@@ -696,8 +683,8 @@ void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {
int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
const char *t1 = luaT_typenames[basettype(p1)]; const char *t1 = luaT_typenames[ttnov(p1)];
const char *t2 = luaT_typenames[basettype(p2)]; const char *t2 = luaT_typenames[ttnov(p2)];
if (t1[2] == t2[2]) if (t1[2] == t2[2])
luaG_runerror(L, "attempt to compare two %s values", t1); luaG_runerror(L, "attempt to compare two %s values", t1);
else else
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
#ifdef LUA_OPTIMIZE_DEBUG
# include "lvm.h" # include "lvm.h"
# define getline(f,pc) (((f)->packedlineinfo) ? luaG_getline((f), pc) : 0) # define getline(f,pc) (((f)->packedlineinfo) ? luaG_getline((f), pc) : 0)
# define INFO_FILL_BYTE 0x7F # define INFO_FILL_BYTE 0x7F
...@@ -23,9 +22,6 @@ ...@@ -23,9 +22,6 @@
# define INFO_DELTA_7BITS 0x7F # define INFO_DELTA_7BITS 0x7F
# define INFO_MAX_LINECNT 126 # define INFO_MAX_LINECNT 126
# define lineInfoTop(fs) ((fs)->f->packedlineinfo + (fs)->lastlineOffset) # define lineInfoTop(fs) ((fs)->f->packedlineinfo + (fs)->lastlineOffset)
#else
# define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
#endif
#define resethookcount(L) (L->hookcount = L->basehookcount) #define resethookcount(L) (L->hookcount = L->basehookcount)
...@@ -41,9 +37,7 @@ LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); ...@@ -41,9 +37,7 @@ LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
LUAI_FUNC void luaG_errormsg (lua_State *L); LUAI_FUNC void luaG_errormsg (lua_State *L);
LUAI_FUNC int luaG_checkcode (const Proto *pt); LUAI_FUNC int luaG_checkcode (const Proto *pt);
LUAI_FUNC int luaG_checkopenop (Instruction i); LUAI_FUNC int luaG_checkopenop (Instruction i);
#ifdef LUA_OPTIMIZE_DEBUG
LUAI_FUNC int luaG_getline (const Proto *f, int pc); LUAI_FUNC int luaG_getline (const Proto *f, int pc);
LUAI_FUNC int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv); LUAI_FUNC int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv);
#endif
#endif #endif
...@@ -228,7 +228,6 @@ static void DumpDebug(const Proto* f, DumpState* D) ...@@ -228,7 +228,6 @@ static void DumpDebug(const Proto* f, DumpState* D)
{ {
int i,n; int i,n;
#ifdef LUA_OPTIMIZE_DEBUG
n = (D->strip || f->packedlineinfo == NULL) ? 0: strlen(cast(char *,f->packedlineinfo))+1; n = (D->strip || f->packedlineinfo == NULL) ? 0: strlen(cast(char *,f->packedlineinfo))+1;
DumpInt(n,D); DumpInt(n,D);
Align4(D); Align4(D);
...@@ -236,15 +235,6 @@ static void DumpDebug(const Proto* f, DumpState* D) ...@@ -236,15 +235,6 @@ static void DumpDebug(const Proto* f, DumpState* D)
{ {
DumpBlock(f->packedlineinfo, n, D); DumpBlock(f->packedlineinfo, n, D);
} }
#else
n= (D->strip) ? 0 : f->sizelineinfo;
DumpInt(n,D);
Align4(D);
for (i=0; i<n; i++)
{
DumpInt(f->lineinfo[i],D);
}
#endif
n= (D->strip) ? 0 : f->sizelocvars; n= (D->strip) ? 0 : f->sizelocvars;
DumpInt(n,D); DumpInt(n,D);
......
...@@ -194,21 +194,20 @@ static int loadLFS (lua_State *L); ...@@ -194,21 +194,20 @@ static int loadLFS (lua_State *L);
static int loadLFSgc (lua_State *L); static int loadLFSgc (lua_State *L);
static void procFirstPass (void); static void procFirstPass (void);
/* lua_lfsreload() and lua_lfsindex() are exported via lua.h */ /* luaL_lfsreload() is exported via lauxlib.h */
/* /*
* Library function called by node.flashreload(filename). * Library function called by node.flashreload(filename).
*/ */
LUALIB_API int lua_lfsreload (lua_State *L) { LUALIB_API void luaL_lfsreload (lua_State *L) {
const char *fn = lua_tostring(L, 1), *msg = ""; const char *fn = lua_tostring(L, 1), *msg = "";
int status; int status;
if (G(L)->LFSsize == 0) { if (G(L)->LFSsize == 0) {
lua_pushstring(L, "No LFS partition allocated"); lua_pushstring(L, "No LFS partition allocated");
return 1; return;
} }
/* /*
* Do a protected call of loadLFS. * Do a protected call of loadLFS.
* *
...@@ -237,7 +236,7 @@ LUALIB_API int lua_lfsreload (lua_State *L) { ...@@ -237,7 +236,7 @@ LUALIB_API int lua_lfsreload (lua_State *L) {
lua_cpcall(L, &loadLFSgc, NULL); lua_cpcall(L, &loadLFSgc, NULL);
lua_settop(L, 0); lua_settop(L, 0);
lua_pushstring(L, msg); lua_pushstring(L, msg);
return 1; return;
} }
if (status == 0) { if (status == 0) {
...@@ -257,60 +256,21 @@ LUALIB_API int lua_lfsreload (lua_State *L) { ...@@ -257,60 +256,21 @@ LUALIB_API int lua_lfsreload (lua_State *L) {
NODE_ERR(msg); NODE_ERR(msg);
while (1) {} // Force WDT as the ROM software_reset() doesn't seem to work while (1) {} // Force WDT as the ROM software_reset() doesn't seem to work
return 0;
} }
/* LUA_API void lua_getlfsconfig (lua_State *L, int *config) {
* If the arg is a valid LFS module name then return the LClosure if (!config)
* pointing to it. Otherwise return: return;
* - The Unix time that the LFS was built config[0] = (int) flashAddr; /* LFS region mapped address */
* - The base address and length of the LFS config[1] = flashAddrPhys; /* LFS region base flash address */
* - An array of the module names in the LFS config[2] = G(L)->LFSsize; /* LFS region actual size */
*/ config[3] = (G(L)->ROstrt.hash) ? cast(FlashHeader *, flashAddr)->flash_size : 0;
LUAI_FUNC int lua_lfsindex (lua_State *L) { /* LFS region used */
int n = lua_gettop(L); config[4] = 0; /* Not used in Lua 5.1 */
}
/* Return nil + the LFS base address if the LFS size > 0 and it isn't loaded */
if (!(G(L)->ROpvmain)) {
lua_settop(L, 0);
lua_pushnil(L);
if (G(L)->LFSsize) {
lua_pushinteger(L, (lua_Integer) flashAddr);
lua_pushinteger(L, flashAddrPhys);
lua_pushinteger(L, G(L)->LFSsize);
return 4;
} else {
return 1;
}
}
/* Push the LClosure of the LFS index function */
Closure *cl = luaF_newLclosure(L, 0, hvalue(gt(L)));
cl->l.p = G(L)->ROpvmain;
lua_settop(L, n+1);
setclvalue(L, L->top-1, cl);
/* Move it infront of the arguments and call the index function */
lua_insert(L, 1);
lua_call(L, n, LUA_MULTRET);
/* Return it if the response if a single value (the function) */
if (lua_gettop(L) == 1)
return 1;
lua_assert(lua_gettop(L) == 2);
/* Otherwise add the base address of the LFS, and its size bewteen the */
/* Unix time and the module list, then return all 4 params. */
lua_pushinteger(L, (lua_Integer) flashAddr);
lua_insert(L, 2);
lua_pushinteger(L, flashAddrPhys);
lua_insert(L, 3);
lua_pushinteger(L, cast(FlashHeader *, flashAddr)->flash_size);
lua_insert(L, 4);
return 5;
}
/* ===================================================================================== /* =====================================================================================
* The following routines use my uzlib which was based on pfalcon's inflate and * The following routines use my uzlib which was based on pfalcon's inflate and
* deflate routines. The standard NodeMCU make also makes two host tools uz_zip * deflate routines. The standard NodeMCU make also makes two host tools uz_zip
...@@ -483,7 +443,7 @@ void procSecondPass (void) { ...@@ -483,7 +443,7 @@ void procSecondPass (void) {
} }
/* /*
* loadLFS)() is protected called from luaN_reload_reboot so that it can recover * loadLFS)() is protected called from luaL_lfsreload() so that it can recover
* from out of memory and other thrown errors. loadLFSgc() GCs any resources. * from out of memory and other thrown errors. loadLFSgc() GCs any resources.
*/ */
static int loadLFS (lua_State *L) { static int loadLFS (lua_State *L) {
......
...@@ -43,8 +43,5 @@ typedef struct { ...@@ -43,8 +43,5 @@ typedef struct {
} FlashHeader; } FlashHeader;
LUAI_FUNC void luaN_init (lua_State *L); LUAI_FUNC void luaN_init (lua_State *L);
LUAI_FUNC int luaN_flashSetup (lua_State *L);
LUAI_FUNC int luaN_reload_reboot (lua_State *L);
LUAI_FUNC int luaN_index (lua_State *L);
#endif #endif
...@@ -125,12 +125,7 @@ Proto *luaF_newproto (lua_State *L) { ...@@ -125,12 +125,7 @@ Proto *luaF_newproto (lua_State *L) {
f->numparams = 0; f->numparams = 0;
f->is_vararg = 0; f->is_vararg = 0;
f->maxstacksize = 0; f->maxstacksize = 0;
#ifdef LUA_OPTIMIZE_DEBUG
f->packedlineinfo = NULL; f->packedlineinfo = NULL;
#else
f->sizelineinfo = 0;
f->lineinfo = NULL;
#endif
f->sizelocvars = 0; f->sizelocvars = 0;
f->locvars = NULL; f->locvars = NULL;
f->linedefined = 0; f->linedefined = 0;
...@@ -146,13 +141,9 @@ void luaF_freeproto (lua_State *L, Proto *f) { ...@@ -146,13 +141,9 @@ void luaF_freeproto (lua_State *L, Proto *f) {
luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
luaM_freearray(L, f->code, f->sizecode, Instruction); luaM_freearray(L, f->code, f->sizecode, Instruction);
#ifdef LUA_OPTIMIZE_DEBUG
if (f->packedlineinfo) { if (f->packedlineinfo) {
luaM_freearray(L, f->packedlineinfo, strlen(cast(char *, f->packedlineinfo))+1, unsigned char); luaM_freearray(L, f->packedlineinfo, strlen(cast(char *, f->packedlineinfo))+1, unsigned char);
} }
#else
luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
#endif
luaM_free(L, f); luaM_free(L, f);
} }
......
...@@ -327,11 +327,7 @@ static l_mem propagatemark (global_State *g) { ...@@ -327,11 +327,7 @@ static l_mem propagatemark (global_State *g) {
sizeof(LocVar) * p->sizelocvars + sizeof(LocVar) * p->sizelocvars +
sizeof(TString *) * p->sizeupvalues + sizeof(TString *) * p->sizeupvalues +
sizeof(Instruction) * p->sizecode + sizeof(Instruction) * p->sizecode +
#ifdef LUA_OPTIMIZE_DEBUG
(p->packedlineinfo ? strlen(cast(char *, p->packedlineinfo))+1 : 0); (p->packedlineinfo ? strlen(cast(char *, p->packedlineinfo))+1 : 0);
#else
sizeof(int) * p->sizelineinfo;
#endif
} }
default: lua_assert(0); return 0; default: lua_assert(0); return 0;
} }
...@@ -515,7 +511,7 @@ void luaC_freeall (lua_State *L) { ...@@ -515,7 +511,7 @@ void luaC_freeall (lua_State *L) {
static void markmt (global_State *g) { static void markmt (global_State *g) {
int i; int i;
for (i=0; i<NUM_TAGS; i++) for (i=0; i<LUA_NUMTAGS; i++)
if (g->mt[i] && isrwtable(g->mt[i])) markobject(g, g->mt[i]); if (g->mt[i] && isrwtable(g->mt[i])) markobject(g, g->mt[i]);
} }
......
...@@ -61,7 +61,7 @@ extern LROT_TABLE(math); ...@@ -61,7 +61,7 @@ extern LROT_TABLE(math);
#if defined(LUA_CROSS_COMPILER) #if defined(LUA_CROSS_COMPILER)
extern LROT_TABLE(base_func); extern LROT_TABLE(base_func);
LROT_BEGIN(rotables_meta, NULL, LROT_MASK_INDEX) LROT_BEGIN(rotables_meta, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( _index, base_func) LROT_TABENTRY( __index, base_func)
LROT_END(rotables_meta, NULL, LROT_MASK_INDEX) LROT_END(rotables_meta, NULL, LROT_MASK_INDEX)
extern LROT_TABLE(oslib); extern LROT_TABLE(oslib);
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
#include "lnodemcu.h"
#undef PI #undef PI
#define PI (3.14159265358979323846) #define PI (3.14159265358979323846)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment