-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lua tidy-up to reduce delta against esp32 branch. #3468
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ static void save (LexState *ls, int c) { | |
|
||
|
||
void luaX_init (lua_State *L) { | ||
(void)L; | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,7 @@ LUALIB_API int luaL_posttask( lua_State* L, int prio ) { // [-1, +0, -] | |
} | ||
#else | ||
LUALIB_API int luaL_posttask( lua_State* L, int prio ) { | ||
(void)L; (void)prio; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again use |
||
return 0; | ||
} /* Dummy stub on host */ | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,9 +45,11 @@ | |
static ROTable_entry LOCK_IN_SECTION(s) rt ## _entries[] = { | ||
#define LROT_END(rt,mt,f) {NULL, LRO_NILVAL} }; \ | ||
const ROTable rt ## _ROTable = { \ | ||
(GCObject *)1, LUA_TROTABLE, LROT_MARKED, \ | ||
cast(lu_byte, ~(f)), (sizeof(rt ## _entries)/sizeof(ROTable_entry)) - 1, \ | ||
cast(Table *, mt), cast(ROTable_entry *, rt ## _entries) }; | ||
.next = (GCObject *)1, .tt = LUA_TROTABLE, .marked = LROT_MARKED, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is quite a change to the ROTable layout. The current code uses exploit the fact that a common subset of |
||
.flags = cast(lu_byte, ~(f)), \ | ||
.lsizenode = (sizeof(rt ## _entries)/sizeof(ROTable_entry)) - 1, \ | ||
.metatable = cast(Table *, mt), \ | ||
.entry = cast(ROTable_entry *, rt ## _entries) }; | ||
#define LROT_BREAK(rt) }; | ||
|
||
#define LROT_MASK(m) cast(lu_byte, 1<<TM_ ## m) | ||
|
@@ -65,10 +67,9 @@ | |
#define LROT_MASK_NEWINDEX LROT_MASK(NEWINDEX) | ||
#define LROT_MASK_GC_INDEX (LROT_MASK_GC | LROT_MASK_INDEX) | ||
|
||
/* Maximum length of a rotable name and of a string key*/ | ||
#define LUA_MAX_ROTABLE_NAME 32 /* Maximum length of a rotable name and of a string key*/ | ||
|
||
#ifdef LUA_CORE | ||
|
||
#endif | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,10 +68,7 @@ int luaO_log2 (unsigned int x) { | |
while (x >= 256) { l += 8; x >>= 8; } | ||
return l + log_2[x]; | ||
#else | ||
/* Use Normalization Shift Amount Unsigned: 0x1=>31 up to 0xffffffff =>0 | ||
* See Xtensa Instruction Set Architecture (ISA) Refman P 462 */ | ||
asm volatile ("nsau %0, %1;" :"=r"(x) : "r"(x)); | ||
return 31 - x; | ||
return 31 - __builtin_clz(x); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same point about use of builtins vs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah on Xtensa |
||
#endif | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
#define LUA_TUPVAL (LAST_TAG+2) | ||
#define LUA_TDEADKEY (LAST_TAG+3) | ||
|
||
#ifdef LUA_USE_ESP | ||
#ifdef LUA_USE_ESP8266 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the ESP32 support unaligned data fetches from IRAM and IFLASH?. If so then how many extra clocks? The access macros add one extra register instruction to use an aligned read. If this is still faster then why have this difference between the ESP8266 and ESP32 versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this is predominantly an Xtensa vs RISC-V issue here. But yes, data memory regions are byte accessible. Some optimisation may be possible, but has not been a priority for me at this point - getting NodeMCU to run on all the different ESP32 SoCs has been :) |
||
/* | ||
** force aligned access to critical fields in Flash-based structures | ||
** wo is the offset of aligned word in bytes 0,4,8,.. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,7 +296,7 @@ LUA_API void lua_getlfsconfig (lua_State *L, int *config) { | |
} | ||
} | ||
|
||
LUA_API int (lua_pushlfsindex) (lua_State *L) { | ||
LUA_API int lua_pushlfsindex(lua_State *L) { | ||
lua_lock(L); | ||
setobj2n(L, L->top, &G(L)->LFStable); | ||
api_incr_top(L); | ||
|
@@ -309,7 +309,7 @@ LUA_API int (lua_pushlfsindex) (lua_State *L) { | |
* one upvalue that must be the set to the _ENV variable when its closure is | ||
* created, and as such this parallels some ldo.c processing. | ||
*/ | ||
LUA_API int (lua_pushlfsfunc) (lua_State *L) { | ||
LUA_API int lua_pushlfsfunc(lua_State *L) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The standard pattern is to add the parentheses where a define macro might be encoded to force sensible compile errors here. Why change this? Ditto on following cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The standard pattern is to only parenthesise function names only when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just feel that we should follow the standard Lua coding standards where practical |
||
lua_lock(L); | ||
const TValue *t = &G(L)->LFStable; | ||
if (ttisstring(L->top-1) && ttistable(t)) { | ||
|
@@ -341,7 +341,7 @@ LUA_API int (lua_pushlfsfunc) (lua_State *L) { | |
/* | ||
* Return an array of functions in LFS | ||
*/ | ||
LUALIB_API int (luaL_pushlfsmodules) (lua_State *L) { | ||
LUALIB_API int luaL_pushlfsmodules(lua_State *L) { | ||
int i = 1; | ||
if (lua_pushlfsindex(L) == LUA_TNIL) | ||
return 0; /* return nil if LFS not loaded */ | ||
|
@@ -357,7 +357,7 @@ LUALIB_API int (luaL_pushlfsmodules) (lua_State *L) { | |
return 1; | ||
} | ||
|
||
LUALIB_API int (luaL_pushlfsdts) (lua_State *L) { | ||
LUALIB_API int luaL_pushlfsdts(lua_State *L) { | ||
int config[5]; | ||
lua_getlfsconfig(L, config); | ||
lua_pushinteger(L, config[4]); | ||
|
@@ -427,7 +427,9 @@ static const char *readF (lua_State *L, void *ud, size_t *size) { | |
|
||
static void eraseLFS(LFSflashState *F) { | ||
lu_int32 i; | ||
#ifdef LUA_USE_ESP | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surely, the use of bare There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about this, we should move towards POSIX compliant source wherever practical. The real issue here is that printing should be deprecated, except for very specific circumstances, as it will be unusual for a human or logging system to be 'listening' to the serial output, mainly development debugging. This .... progress bar is really a development tool. |
||
printf("\nErasing LFS from flash addr 0x%06x", F->addrPhys); | ||
#endif | ||
unlockFlashWrite(); | ||
for (i = 0; i < F->size; i += FLASH_PAGE_SIZE) { | ||
size_t *f = cast(size_t *, F->addr + i/sizeof(*f)); | ||
|
@@ -436,11 +438,13 @@ static void eraseLFS(LFSflashState *F) { | |
#ifdef LUA_USE_ESP | ||
if (*f == ~0 && !memcmp(f, f + 1, FLASH_PAGE_SIZE - sizeof(*f))) | ||
continue; | ||
printf("."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above re use of print. The code skips the erase where it is not need and this makes flashing of smaller LFS images a lot faster. The dots are a pretty useful visual progress bar |
||
#endif | ||
platform_flash_erase_sector(s); | ||
printf("."); | ||
} | ||
#ifdef LUA_USE_ESP | ||
printf(" to 0x%06x\n", F->addrPhys + F->size-1); | ||
#endif | ||
flush_icache(F); | ||
lockFlashWrite(); | ||
} | ||
|
@@ -623,7 +627,6 @@ LUALIB_API void luaL_lfsreload (lua_State *L) { | |
|
||
|
||
#ifdef LUA_USE_ESP | ||
extern void lua_main(void); | ||
/* | ||
** Task callback handler. Uses luaN_call to do a protected call with full traceback | ||
*/ | ||
|
@@ -634,7 +637,7 @@ static void do_task (platform_task_param_t task_fn_ref, uint8_t prio) { | |
return; | ||
} | ||
if (prio < LUA_TASK_LOW|| prio > LUA_TASK_HIGH) | ||
luaL_error(L, "invalid posk task"); | ||
luaL_error(L, "invalid post task"); | ||
/* Pop the CB func from the Reg */ | ||
lua_rawgeti(L, LUA_REGISTRYINDEX, (int) task_fn_ref); | ||
luaL_checktype(L, -1, LUA_TFUNCTION); | ||
|
@@ -662,14 +665,15 @@ LUALIB_API int luaL_posttask ( lua_State* L, int prio ) { // [-1, +0, -] | |
} | ||
return task_fn_ref; | ||
} else { | ||
return luaL_error(L, "invalid posk task"); | ||
return luaL_error(L, "invalid post task"); | ||
} | ||
} | ||
#else | ||
/* | ||
** Task execution isn't supported on HOST builds so returns a -1 status | ||
*/ | ||
LUALIB_API int luaL_posttask( lua_State* L, int prio ) { // [-1, +0, -] | ||
(void)L; (void)prio; | ||
return -1; | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a host macro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is