Commit dba57fa0 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Merge branch 'dev-esp32-idf4-lua53' into dev-esp32-idf4

parents 3a6961cc 8e5ce49d
......@@ -7,7 +7,6 @@
#define lcode_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include <stdlib.h>
......@@ -781,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
* to grow the lineinfo vector and extend the fill bytes
......@@ -829,10 +826,8 @@ static void generateInfoDeltaLine(FuncState *fs, int line) {
fs->lastlineOffset = p - fs->f->packedlineinfo - 1;
#undef addDLbyte
}
#endif
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 */
if (line != fs->lastline) {
/* first remove the current line reference */
......@@ -863,9 +858,6 @@ void luaK_fixline (FuncState *fs, int line) {
/* Then add the new line reference */
generateInfoDeltaLine(fs, line);
}
#else
fs->f->lineinfo[fs->pc - 1] = line;
#endif
}
......@@ -877,7 +869,6 @@ static int luaK_code (FuncState *fs, Instruction i, int line) {
MAX_INT, "code size overflow");
f->code[fs->pc] = i;
/* save corresponding line information */
#ifdef LUA_OPTIMIZE_DEBUG
/* note that frst time fs->lastline==0 through, so the else branch is taken */
if (fs->pc == fs->lineinfoLastPC+1) {
if (line == fs->lastline && f->packedlineinfo[fs->lastlineOffset] < INFO_MAX_LINECNT) {
......@@ -891,11 +882,6 @@ static int luaK_code (FuncState *fs, Instruction i, int line) {
luaK_fixline(fs,line);
}
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++;
}
......
......@@ -7,7 +7,6 @@
#define ldblib_c
#define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h"
#include <stdio.h>
......@@ -18,8 +17,6 @@
#include "lualib.h"
#include "lstring.h"
#include "lflash.h"
#include "lrotable.h"
#include "sdkconfig.h"
static int db_getregistry (lua_State *L) {
......@@ -28,34 +25,16 @@ static int db_getregistry (lua_State *L) {
}
static int db_getstrings (lua_State *L) {
size_t i,n=0;
stringtable *tb;
GCObject *o;
#ifndef LUA_CROSS_COMPILER
const char *opt = lua_tolstring (L, 1, &n);
if (n==3 && memcmp(opt, "ROM", 4) == 0) {
if (G(L)->ROstrt.hash == NULL)
return 0;
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");
static const char *const opts[] = {"RAM","ROM",NULL};
int opt = luaL_checkoption(L, 1, "RAM", opts);
if (lua_pushstringsarray(L, opt)) {
if(lua_getglobal(L, "table") == LUA_TTABLE) {
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;
}
......@@ -144,7 +123,7 @@ static int db_getinfo (lua_State *L) {
return 1;
}
}
else if (lua_isfunction(L, arg+1) || lua_islightfunction(L, arg+1)) {
else if (lua_isfunction(L, arg+1)) {
lua_pushfstring(L, ">%s", options);
options = lua_tostring(L, -1);
lua_pushvalue(L, arg+1);
......@@ -302,7 +281,7 @@ static int db_sethook (lua_State *L) {
}
else {
const char *smask = luaL_checkstring(L, arg+2);
luaL_checkanyfunction(L, arg+1);
luaL_checkfunction(L, arg+1);
count = luaL_optint(L, arg+3, 0);
func = hookf; mask = makemask(smask, count);
}
......@@ -367,7 +346,7 @@ static int db_debug (lua_State *L) {
#define LEVELS1 12 /* size of the first part of the stack */
#define LEVELS2 10 /* size of the second part of the stack */
static int db_errorfb (lua_State *L) {
static int debug_errorfb (lua_State *L) {
int level;
int firstpart = 1; /* still before eventual `...' */
int arg;
......@@ -419,7 +398,7 @@ static int db_errorfb (lua_State *L) {
return 1;
}
LROT_PUBLIC_BEGIN(dblib)
LROT_BEGIN(dblib, NULL, 0)
#ifndef CONFIG_LUA_BUILTIN_DEBUG_MINIMAL
#if defined(LUA_CROSS_COMPILER)
LROT_FUNCENTRY( debug, db_debug )
......@@ -440,7 +419,7 @@ LROT_PUBLIC_BEGIN(dblib)
LROT_FUNCENTRY( setmetatable, db_setmetatable )
LROT_FUNCENTRY( setupvalue, db_setupvalue )
#endif
LROT_FUNCENTRY( traceback, db_errorfb )
LROT_FUNCENTRY( traceback, debug_errorfb )
LROT_END(dblib, NULL, 0)
LUALIB_API int luaopen_debug (lua_State *L) {
......
......@@ -7,7 +7,6 @@
#define ldebug_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include <string.h>
......@@ -184,7 +183,6 @@ static void info_tailcall (lua_Debug *ar) {
# define INFO_MAX_LINECNT 126
Table *t = luaH_new(L, 0, 0);
#ifdef LUA_OPTIMIZE_DEBUG
int line = 0;
unsigned char *p = f->l.p->packedlineinfo;
if (p) {
......@@ -204,18 +202,11 @@ static void info_tailcall (lua_Debug *ar) {
setbvalue(luaH_setnum(L, t, line), 1);
}
}
#else
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);
}
#ifdef LUA_OPTIMIZE_DEBUG
/*
* 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
......@@ -250,19 +241,18 @@ int luaG_getline (const Proto *f, int pc) {
static int stripdebug (lua_State *L, Proto *f, int level) {
int len = 0, sizepackedlineinfo;
TString* dummy;
switch (level) {
case 3:
case 2:
if (f->packedlineinfo) {
sizepackedlineinfo = strlen(cast(char *, f->packedlineinfo))+1;
f->packedlineinfo = luaM_freearray(L, f->packedlineinfo, sizepackedlineinfo, unsigned char);
len += sizepackedlineinfo;
}
// fall-through
case 2:
len += f->sizelocvars * (sizeof(struct LocVar) + sizeof(dummy->tsv) + sizeof(struct LocVar *));
case 1:
f->locvars = luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
f->upvalues = luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
len += f->sizelocvars * (sizeof(struct LocVar) + sizeof(dummy->tsv) + sizeof(struct LocVar *)) +
f->sizeupvalues * (sizeof(dummy->tsv) + sizeof(TString *));
len += f->sizelocvars*sizeof(struct LocVar) + f->sizeupvalues*sizeof(TString *);
f->sizelocvars = 0;
f->sizeupvalues = 0;
}
......@@ -278,7 +268,6 @@ LUA_API int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv){
len += stripdebug (L, f, level);
return len;
}
#endif
static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
......@@ -328,21 +317,21 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
lua_lock(L);
if (*what == '>') {
StkId func = L->top - 1;
luai_apicheck(L, ttisfunction(func) || ttislightfunction(func));
luai_apicheck(L, ttisfunction(func));
what++; /* skip the '>' */
if (ttisfunction(func))
f = clvalue(func);
else
if (ttislightfunction(func))
plight = fvalue(func);
else
f = clvalue(func);
L->top--; /* pop function */
}
else if (ar->i_ci != 0) { /* no tail call? */
ci = L->base_ci + ar->i_ci;
lua_assert(ttisfunction(ci->func) || ttislightfunction(ci->func));
if (ttisfunction(ci->func))
f = clvalue(ci->func);
else
lua_assert(ttisfunction(ci->func));
if (ttislightfunction(ci->func))
plight = fvalue(ci->func);
else
f = clvalue(ci->func);
}
status = auxgetinfo(L, what, ar, f, plight, ci);
if (strchr(what, 'f')) {
......@@ -381,9 +370,6 @@ static int precheck (const Proto *pt) {
check(!(pt->is_vararg & VARARG_NEEDSARG) ||
(pt->is_vararg & VARARG_HASARG));
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);
return 1;
}
......@@ -670,7 +656,7 @@ static int isinstack (CallInfo *ci, const TValue *o) {
void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
const char *name = NULL;
const char *t = luaT_typenames[ttype(o)];
const char *t = luaT_typenames[ttnov(o)];
const char *kind = (isinstack(L->ci, o)) ?
getobjname(L, L->ci, cast_int(o - L->base), &name) :
NULL;
......@@ -698,8 +684,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) {
const char *t1 = luaT_typenames[ttype(p1)];
const char *t2 = luaT_typenames[ttype(p2)];
const char *t1 = luaT_typenames[ttnov(p1)];
const char *t2 = luaT_typenames[ttnov(p2)];
if (t1[2] == t2[2])
luaG_runerror(L, "attempt to compare two %s values", t1);
else
......@@ -722,7 +708,7 @@ static void addinfo (lua_State *L, const char *msg) {
void luaG_errormsg (lua_State *L) {
if (L->errfunc != 0) { /* is there an error handling function? */
StkId errfunc = restorestack(L, L->errfunc);
if (!ttisfunction(errfunc) && !ttislightfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
setobjs2s(L, L->top, L->top - 1); /* move argument */
setobjs2s(L, L->top - 1, errfunc); /* push function */
incr_top(L);
......
......@@ -13,7 +13,6 @@
#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
#ifdef LUA_OPTIMIZE_DEBUG
# include "lvm.h"
# define getline(f,pc) (((f)->packedlineinfo) ? luaG_getline((f), pc) : 0)
# define INFO_FILL_BYTE 0x7F
......@@ -23,9 +22,6 @@
# define INFO_DELTA_7BITS 0x7F
# define INFO_MAX_LINECNT 126
# 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)
......@@ -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 int luaG_checkcode (const Proto *pt);
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_stripdebug (lua_State *L, Proto *f, int level, int recv);
#endif
#endif
......@@ -8,7 +8,6 @@
#define ldo_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include <string.h>
......@@ -106,7 +105,7 @@ void luaD_throw (lua_State *L, int errcode) {
lua_unlock(L);
G(L)->panic(L);
}
// exit(EXIT_FAILURE);
// c_exit(EXIT_FAILURE);
}
}
......@@ -254,13 +253,13 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
return base;
}
static StkId tryfuncTM (lua_State *L, StkId func) {
const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);
StkId p;
ptrdiff_t funcr = savestack(L, func);
if (!ttisfunction(tm))
if (!ttisfunction(tm)) {
luaG_typeerror(L, func, "call");
}
/* Open a hole inside the stack at `func' */
for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);
incr_top(L);
......@@ -279,10 +278,10 @@ static StkId tryfuncTM (lua_State *L, StkId func) {
int luaD_precall (lua_State *L, StkId func, int nresults) {
ptrdiff_t funcr;
LClosure *cl = NULL;
if (!ttisfunction(func) && !ttislightfunction(func)) /* `func' is not a function? */
if (!ttisfunction(func)) /* `func' is not a function? */
func = tryfuncTM(L, func); /* check the `function' tag method */
funcr = savestack(L, func);
if (ttisfunction(func))
if (!ttislightfunction(func))
cl = &clvalue(func)->l;
L->ci->savedpc = L->savedpc;
if (cl && !cl->isC) { /* Lua function? prepare its call */
......@@ -332,10 +331,10 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
if (L->hookmask & LUA_MASKCALL)
luaD_callhook(L, LUA_HOOKCALL, -1);
lua_unlock(L);
if (ttisfunction(ci->func))
n = (*curr_func(L)->c.f)(L); /* do the actual call */
else
if (ttislightfunction(ci->func))
n = ((lua_CFunction)fvalue(ci->func))(L); /* do the actual call */
else
n = (*curr_func(L)->c.f)(L); /* do the actual call */
lua_lock(L);
if (n < 0) /* yielding? */
return PCRYIELD;
......
......@@ -6,7 +6,6 @@
#define ldump_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include <string.h>
......@@ -229,7 +228,6 @@ static void DumpDebug(const Proto* f, DumpState* D)
{
int i,n;
#ifdef LUA_OPTIMIZE_DEBUG
n = (D->strip || f->packedlineinfo == NULL) ? 0: strlen(cast(char *,f->packedlineinfo))+1;
DumpInt(n,D);
Align4(D);
......@@ -237,15 +235,6 @@ static void DumpDebug(const Proto* f, DumpState* 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;
DumpInt(n,D);
......
......@@ -5,7 +5,6 @@
#define lflash_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include "lobject.h"
......@@ -24,6 +23,8 @@
#include <stdlib.h>
#include <string.h>
#include "lfs.h"
/*
* Flash memory is a fixed memory addressable block that is serially allocated by the
* luac build process and the out image can be downloaded into SPIFSS and loaded into
......@@ -72,7 +73,7 @@ struct OUTPUT {
outBlock buffer;
int ndx;
uint32_t crc;
int (*fullBlkCB) (void);
void (*fullBlkCB) (void);
int flashLen;
int flagsLen;
int flagsNdx;
......@@ -80,12 +81,6 @@ struct OUTPUT {
const char *error;
} *out;
#ifdef CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
extern const char lua_flash_store_reserved[0];
#endif
#ifdef NODE_DEBUG
extern void printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void dumpStrt(stringtable *tb, const char *type) {
......@@ -97,9 +92,8 @@ void dumpStrt(stringtable *tb, const char *type) {
for (i=0; i<tb->size; i++)
for(o = tb->hash[i], j=0; o; (o=o->gch.next), j++ ) {
TString *ts =cast(TString *, o);
NODE_DBG("%5d %5d %08x %08x %5d %1s %s\n",
i, j, (size_t) ts, ts->tsv.hash, ts->tsv.len,
ts_isreadonly(ts) ? "R" : " ", getstr(ts));
NODE_DBG("%5d %5d %08x %08x %5d %s\n",
i, j, (size_t) ts, ts->tsv.hash, ts->tsv.len, getstr(ts));
}
}
......@@ -117,17 +111,25 @@ LUA_API void dumpStrings(lua_State *L) {
* writes are suppressed if the global writeToFlash is false. This is used in
* phase I where the pass is used to size the structures in flash.
*/
static void flashSetPosition(uint32_t offset){
static const char *flashPosition(void){
return flashAddr + curOffset;
}
static const char *flashSetPosition(uint32_t offset){
NODE_DBG("flashSetPosition(%04x)\n", offset);
curOffset = offset;
return flashPosition();
}
static void flashBlock(const void* b, size_t size) {
NODE_DBG("flashBlock((%04x),%08x,%04x)\n", curOffset,(unsigned int)b,size);
static const char *flashBlock(const void* b, size_t size) {
const void *cur = flashPosition();
NODE_DBG("flashBlock((%04x),%p,%04x)\n", curOffset,b,size);
lua_assert(ALIGN_BITS(b) == 0 && ALIGN_BITS(size) == 0);
platform_flash_write(b, flashAddrPhys+curOffset, size);
curOffset += size;
return cur;
}
......@@ -142,11 +144,11 @@ static void flashErase(uint32_t start, uint32_t end){
static int loadLFS (lua_State *L);
static int loadLFSgc (lua_State *L);
static int procFirstPass (void);
static void procFirstPass (void);
#endif
/* =====================================================================================
* luaN_init(), luaN_reload_reboot() and luaN_index() are exported via lflash.h.
* luaN_init() is exported via lflash.h.
* The first is the startup hook used in lstate.c and the last two are
* implementations of the node.flash API calls.
*/
......@@ -155,40 +157,15 @@ static int procFirstPass (void);
* Hook in lstate.c:f_luaopen() to set up ROstrt and ROpvmain if needed
*/
LUAI_FUNC void luaN_init (lua_State *L) {
#ifdef CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
flashSize = CONFIG_NODEMCU_EMBEDDED_LFS_SIZE;
flashAddr = lua_flash_store_reserved;
flashAddrPhys = spi_flash_cache2phys(lua_flash_store_reserved);
if (flashAddrPhys == SPI_FLASH_CACHE2PHYS_FAIL) {
NODE_ERR("spi_flash_cache2phys failed\n");
return;
}
#else
const esp_partition_t *part = esp_partition_find_first(
PLATFORM_PARTITION_TYPE_NODEMCU,
PLATFORM_PARTITION_SUBTYPE_NODEMCU_LFS,
NULL);
if (!part)
return; // Nothing to do if the size is zero
flashSize = part->size; // in bytes
flashAddrPhys = part->address;
flashAddr = spi_flash_phys2cache(flashAddrPhys, SPI_FLASH_MMAP_DATA);
if (!flashAddr) {
spi_flash_mmap_handle_t ignored;
esp_err_t err = spi_flash_mmap(
flashAddrPhys, flashSize, SPI_FLASH_MMAP_DATA,
cast(const void **, &flashAddr), &ignored);
if (err != ESP_OK) {
NODE_ERR("Unable to access LFS partition - is it 64kB aligned as it needs to be?\n");
lfs_location_info_t lfs_loc;
if (!lfs_get_location(&lfs_loc))
return;
}
}
#endif
G(L)->LFSsize = flashSize;
flashSector = platform_flash_get_sector_of_address(flashAddrPhys);
FlashHeader *fh = cast(FlashHeader *, flashAddr);
G(L)->LFSsize = flashSize = lfs_loc.size;
flashAddr = lfs_loc.addr_mem;
flashAddrPhys = lfs_loc.addr_phys;
flashSector = platform_flash_get_sector_of_address(lfs_loc.addr_phys);
FlashHeader *fh = cast(FlashHeader *, lfs_loc.addr_mem);
curOffset = 0;
/*
......@@ -204,15 +181,15 @@ LUAI_FUNC void luaN_init (lua_State *L) {
}
if ((fh->flash_sig & (~FLASH_SIG_ABSOLUTE)) != FLASH_SIG ) {
NODE_ERR("Flash sig not correct: %u vs %u\n",
NODE_ERR("LFS sig not correct: 0x%x vs expected 0x%x\n",
fh->flash_sig & (~FLASH_SIG_ABSOLUTE), FLASH_SIG);
return;
}
if (fh->pROhash == ALL_SET ||
((fh->mainProto - cast(FlashAddr, fh)) >= fh->flash_size)) {
NODE_ERR("Flash size check failed: %x vs 0xFFFFFFFF; size: %u\n",
fh->mainProto - cast(FlashAddr, fh), fh->flash_size);
NODE_ERR("Flash size check failed: 0x%08x vs 0xFFFFFFFF; 0x%08x >= 0x%08x\n",
fh->pROhash, fh->mainProto - cast(FlashAddr, fh), fh->flash_size);
return;
}
......@@ -222,23 +199,24 @@ LUAI_FUNC void luaN_init (lua_State *L) {
G(L)->ROpvmain = cast(Proto *,fh->mainProto);
}
/* luaL_lfsreload() is exported via lauxlib.h */
/*
* Library function called by node.flashreload(filename).
*/
LUALIB_API int luaN_reload_reboot (lua_State *L) {
LUALIB_API void luaL_lfsreload (lua_State *L) {
#ifdef CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
// Updating the LFS section is disabled for now because any changes to the
// image requires updating its checksum to prevent boot failure.
lua_pushstring(L, "Not allowed to write to LFS section");
return 1;
return;
#else
// luaL_dbgbreak();
const char *fn = lua_tostring(L, 1), *msg = "";
int status;
if (G(L)->LFSsize == 0) {
lua_pushstring(L, "No LFS partition allocated");
return 1;
return;
}
......@@ -270,7 +248,7 @@ LUALIB_API int luaN_reload_reboot (lua_State *L) {
lua_cpcall(L, &loadLFSgc, NULL);
lua_settop(L, 0);
lua_pushstring(L, msg);
return 1;
return;
}
if (status == 0) {
......@@ -290,62 +268,22 @@ LUALIB_API int luaN_reload_reboot (lua_State *L) {
NODE_ERR("%s\n", msg);
esp_restart();
return 0;
#endif // CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
}
/*
* If the arg is a valid LFS module name then return the LClosure
* pointing to it. Otherwise return:
* - The Unix time that the LFS was built
* - The base address and length of the LFS
* - An array of the module names in the LFS
*/
LUAI_FUNC int luaN_index (lua_State *L) {
int n = lua_gettop(L);
/* 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;
LUA_API void lua_getlfsconfig (lua_State *L, intptr_t *config) {
if (!config)
return;
config[0] = (intptr_t) flashAddr; /* LFS region mapped address */
config[1] = flashAddrPhys; /* LFS region base flash address */
config[2] = G(L)->LFSsize; /* LFS region actual size */
config[3] = (G(L)->ROstrt.hash) ? cast(FlashHeader *, flashAddr)->flash_size : 0;
/* LFS region used */
config[4] = 0; /* Not used in Lua 5.1 */
}
#ifndef CONFIG_NODEMCU_EMBEDDED_LFS_SIZE
/* =====================================================================================
* The following routines use my uzlib which was based on pfalcon's inflate and
......@@ -440,7 +378,7 @@ static uint8_t recall_byte (uint32_t offset) {
* - Once the flags array is in-buffer this is also captured.
* This logic is slightly complicated by the last buffer is typically short.
*/
int procFirstPass (void) {
void procFirstPass (void) {
int len = (out->ndx % WRITE_BLOCKSIZE) ?
out->ndx % WRITE_BLOCKSIZE : WRITE_BLOCKSIZE;
if (out->ndx <= WRITE_BLOCKSIZE) {
......@@ -475,12 +413,10 @@ int procFirstPass (void) {
memcpy(out->flags + out->flagsNdx, out->block[0]->byte + start, len - start);
out->flagsNdx += (len -start) / WORDSIZE; /* flashLen and len are word aligned */
}
return 1;
}
int procSecondPass (void) {
void procSecondPass (void) {
/*
* The length rules are different for the second pass since this only processes
* upto the flashLen and not the full image. This also works in word units.
......@@ -518,12 +454,10 @@ int procSecondPass (void) {
flashBlock(&out->flash_sig, WORDSIZE);
out->fullBlkCB = NULL;
}
return 1;
}
/*
* 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.
*/
static int loadLFS (lua_State *L) {
......@@ -548,7 +482,7 @@ static int loadLFS (lua_State *L) {
in->len = vfs_size(in->fd);
if (in->len <= 200 || /* size of an empty luac output */
vfs_lseek(in->fd, in->len-4, VFS_SEEK_SET) != in->len-4 ||
vfs_read(in->fd, &out->len, sizeof(uint)) != sizeof(uint))
vfs_read(in->fd, &out->len, sizeof(uint32_t)) != sizeof(uint32_t))
flash_error("read error on LFS image file");
vfs_lseek(in->fd, 0, VFS_SEEK_SET);
......
......@@ -43,8 +43,5 @@ typedef struct {
} FlashHeader;
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
......@@ -6,7 +6,6 @@
#define lfunc_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include <string.h>
......@@ -126,12 +125,7 @@ Proto *luaF_newproto (lua_State *L) {
f->numparams = 0;
f->is_vararg = 0;
f->maxstacksize = 0;
#ifdef LUA_OPTIMIZE_DEBUG
f->packedlineinfo = NULL;
#else
f->sizelineinfo = 0;
f->lineinfo = NULL;
#endif
f->sizelocvars = 0;
f->locvars = NULL;
f->linedefined = 0;
......@@ -146,16 +140,10 @@ void luaF_freeproto (lua_State *L, Proto *f) {
luaM_freearray(L, f->k, f->sizek, TValue);
luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
if (!proto_isreadonly(f)) {
luaM_freearray(L, f->code, f->sizecode, Instruction);
#ifdef LUA_OPTIMIZE_DEBUG
if (f->packedlineinfo) {
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);
}
......
......@@ -6,7 +6,6 @@
#define lgc_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include <string.h>
......@@ -21,14 +20,12 @@
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lrotable.h"
#define GCSTEPSIZE 1024u
#define GCSWEEPMAX 40
#define GCSWEEPCOST 10
#define GCFINALIZECOST 100
#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
#define makewhite(g,x) \
......@@ -55,7 +52,6 @@
#define markobject(g,t) { if (iswhite(obj2gco(t))) \
reallymarkobject(g, obj2gco(t)); }
#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause)
......@@ -82,7 +78,7 @@ static void reallymarkobject (global_State *g, GCObject *o) {
case LUA_TUSERDATA: {
Table *mt = gco2u(o)->metatable;
gray2black(o); /* udata are never gray */
if (mt && !luaR_isrotable(mt)) markobject(g, mt);
if (mt && isrwtable(mt)) markobject(g, mt);
markobject(g, gco2u(o)->env);
return;
}
......@@ -160,7 +156,6 @@ size_t luaC_separateudata (lua_State *L, int all) {
return deadmem;
}
static int traversetable (global_State *g, Table *h) {
int i;
int weakkey = 0;
......@@ -168,7 +163,7 @@ static int traversetable (global_State *g, Table *h) {
const TValue *mode = luaO_nilobject;
if (h->metatable) {
if (!luaR_isrotable(h->metatable))
if (isrwtable(h->metatable))
markobject(g, h->metatable);
mode = gfasttm(g, h->metatable, TM_MODE);
}
......@@ -331,14 +326,8 @@ static l_mem propagatemark (global_State *g) {
sizeof(TValue) * p->sizek +
sizeof(LocVar) * p->sizelocvars +
sizeof(TString *) * p->sizeupvalues +
(proto_isreadonly(p) ? 0 : sizeof(Instruction) * p->sizecode +
#ifdef LUA_OPTIMIZE_DEBUG
(p->packedlineinfo ?
strlen(cast(char *, p->packedlineinfo))+1 :
0));
#else
sizeof(int) * p->sizelineinfo);
#endif
sizeof(Instruction) * p->sizecode +
(p->packedlineinfo ? strlen(cast(char *, p->packedlineinfo))+1 : 0);
}
default: lua_assert(0); return 0;
}
......@@ -522,8 +511,8 @@ void luaC_freeall (lua_State *L) {
static void markmt (global_State *g) {
int i;
for (i=0; i<NUM_TAGS; i++)
if (g->mt[i] && !luaR_isrotable(g->mt[i])) markobject(g, g->mt[i]);
for (i=0; i<LUA_NUMTAGS; i++)
if (g->mt[i] && isrwtable(g->mt[i])) markobject(g, g->mt[i]);
}
......@@ -713,7 +702,7 @@ void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {
global_State *g = G(L);
lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
lua_assert(o->gch.tt != LUA_TTABLE);
lua_assert((gettt(o) & LUA_TMASK) != LUA_TTABLE);
/* must keep invariant? */
if (g->gcstate == GCSpropagate)
reallymarkobject(g, v); /* Restore invariant */
......
......@@ -7,7 +7,6 @@
#define llex_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include <ctype.h>
......@@ -62,6 +61,7 @@ static void save (LexState *ls, int c) {
void luaX_init (lua_State *L) {
(void)L;
}
......
......@@ -8,8 +8,6 @@
#define llimits_h
//#include <limits.h>
#include "lua.h"
typedef LUAI_UINT32 lu_int32;
......
......@@ -7,7 +7,6 @@
#define lmathlib_c
#define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h"
#include <stdlib.h>
......@@ -15,7 +14,6 @@
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
#undef PI
#define PI (3.14159265358979323846)
......@@ -309,7 +307,7 @@ static int math_randomseed (lua_State *L) {
return 0;
}
LROT_PUBLIC_BEGIN(math)
LROT_BEGIN(mathlib, NULL, 0)
#ifdef LUA_NUMBER_INTEGRAL
LROT_FUNCENTRY( abs, math_abs )
LROT_FUNCENTRY( ceil, math_identity )
......@@ -354,7 +352,7 @@ LROT_PUBLIC_BEGIN(math)
LROT_NUMENTRY( pi, PI )
LROT_NUMENTRY( huge, HUGE_VAL )
#endif // #ifdef LUA_NUMBER_INTEGRAL
LROT_END(math, NULL, 0)
LROT_END(mathlib, NULL, 0)
/*
......
......@@ -7,7 +7,6 @@
#define lmem_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
......
......@@ -8,12 +8,6 @@
#define lmem_h
//#ifdef LUA_CROSS_COMPILER
//#include <stddef.h>
//#else
//#include "c_stddef.h"
//#endif
#include "llimits.h"
#include "lua.h"
......
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