-
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
First cut of new LFS for initial review #3272
Conversation
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.
Some initial nits; I haven't pulled the code to play with it.
L = luaL_newstate(); | ||
if (L == NULL) fatal("not enough memory for state"); | ||
if (L == NULL) | ||
fatal("not enough memory for state"); |
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.
There are a great many "stylistic" changes like the above three lines of diff in these commits. Do they increase or decrease the diff between "upstream Lua" and "nodemcu Lua"? Most of them appear to my mind to be improvements in the code readability; if they increase the gap between "upstream" and "nodemcu", can we send them upstream? :)
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.
luac.c
needs a lot more work largely because the unification of the LFS and LC formats. Given the volume of change and the previous nasty non-standard formatting of lauc.c which is nothing like the rest of the lua core codebase, I have been considering running it through a pretty print style formatter to make it more readable anyway.
PS. Mindfart. Already done this, but the code still needs a tidy.
@@ -359,256 +269,286 @@ int main(int argc, char *argv[]) { | |||
lua_close(L); | |||
continue; /* and loop around once more simulating restart */ | |||
} | |||
char *err = strdup(lua_tostring(L, -1)); | |||
char * |
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.
This appears to be some violence. What happened to the rest of the line?
case '\t': printf("\\t"); break; | ||
case '\v': printf("\\v"); break; | ||
default: | ||
printf(isprint(c) ? "%c" : "\\%03d", c); |
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.
While "obviously" equivalent, this still takes a moment to check, so I'd advocate either for reverting to match mainline or proposing this change to mainline for their inclusion. Many of the following changes also have the same feel.
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.
I will post a general discussion in #3206. Have read and review in that light.
LoadF lf; | ||
(void)(multi); //// TODO |
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.
Yea, I think I'm content with multi
waiting for a later PR. :)
@@ -1153,6 +1154,8 @@ static int errhandler_aux (lua_State *L) { | |||
** to convert into an error message which it handles in a separate posted task. | |||
*/ | |||
static int errhandler (lua_State *L) { | |||
if (!strncmp(lua_tostring(L, -1), "!LFS reload!", sizeof("!LFS reload!") - 1)) |
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.
It's not really worth using strncmp
when one of the parameters is a constant; go ahead and use strcmp
without the repetition. The compiler's going to inline it anyway, one imagines.
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.
Yup memcmp
is better. We can't use strcmp
because the various reload messages include a qualification.
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.
"include a qualification"?
As a codicil to my #3206 comments, I do suggest that reviewers print off and go through the three main rewrites: |
I will be adding #3145 to this PR as this is needed for on-ESP LFS maintenance. |
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.
Phew! Big stuff!
Overall looks good. See review comments for some qs and comments.
I haven't reviewed the dump/undump logic in depth - I'm not in a headspace to manage that right now, and besides I'm figuring you'll have caught any nasty surprises in your testing anyway :)
#include "lnodemcu.h" | ||
#include "lobject.h" | ||
#include "lstate.h" | ||
#include "lstring.h" | ||
#include "lstring.h" // ??? |
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.
I guess these three can/should be reviewed before commit?
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.
Johny, in terms of this and all of your luac.c
comments, I get the impression that the original luac.c
was a "throw-in" not developed by the original Lua developers. The coding style and layout is quite different to the core Lua code. We are getting to the stage where this is heavily modified because of our LFS, Absolute LFS and execution environment support. I've pretty much decided to give this a complete hose down starting with a pretty print reformat, and getting rid of the some of the coding nasties. I'll add this to the next push. I will also reflect your general comments.
#define IROM0_SEG 0x40200000ul | ||
#define IROM0_SEGMAX 0x00100000ul | ||
#define IROM_OFFSET(a) (cast(lu_int32, (a)) - IROM0_SEG) | ||
|
||
#define IROM_OFFSET(a)(((lu_int32) (a)) - IROM0_SEG) |
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.
A space after the first close-bracket would be nice. Weren't you the proponent of using a cast
macro for easier greppability in the first place btw?
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.
I personally prefer cast()
for readability. I am not sure of the rationale here, but it is defined in limits.h
and this is typically pathed in via lobject.h
which is included in most of the LUA_CORE
modules but not the LUA_LIB
so
- the Lua library modules (
l*lib.c
) -- i.e.the ones that interface to the core through thelua.h
API -- don't use it, but - the Lua core itself which access the VM internals, internal data structures, etc., do.
Standard luac.c
(even though it includes object.h
for the code listing function) treats itself as non-core and therefore doesn't use cast(). Confused?
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.
Confused?
Yup! 😄
" -v show version information\n" | ||
" -- stop handling options\n" | ||
" - stop handling options and process stdin\n", progname, Output); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
#define IS(s) (strcmp(argv[i],s)==0) | ||
#define IS(s)(strcmp(argv[i], s) == 0) |
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.
I don't think the space after the macro name & param should be removed. Personal view, of course.
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.
Sorry pretty print reformatting did this. I'll go through these.
} else if (IS("-m")) { /* specify a maximum image size */ | ||
flash = lookup = 1; | ||
} else if (IS("-m")) { /* specify a maximum image size */ | ||
// flash = lookup = 1; |
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.
Hmm? Looks suspicious! :D
maxSize = strtol(argv[++i], NULL, 0); | ||
if (maxSize & 0xFFF) | ||
if (maxSize &0xFFF) |
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.
I can't help but feel some auto-spacer has gone a bit trigger happy in places
luaH_setint(L, t, 1, L->top - 2); | ||
luaC_barrierback(L, t, L->top - 2); | ||
status = luaU_dump(L, t, writer, data, strip); | ||
L->top--; /* Drop able and ceck GC */ |
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.
Here, have a t
and an h
;)
lu_int32 protoHead; /* offset of linked list of Protos in LFS */ | ||
lu_int32 shortTShead; /* offset of linked list of short TStrings in LFS */ | ||
lu_int32 longTShead; /* offset of linked list of long TStrings in LFS */ | ||
short nFiles; |
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.
How come short
rather than an explicit 16bit type?
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.
I will make these a lu_int16
type. The reason for the 16-bit was that I wanted to keep the header the same size if possible and need to pass and additional two integer parameters from pass 1 to pass 2 but only had 4 bytes reserved. Both are small integers so 2 × lu_int16 is fine.
typedef struct LFSflashState { | ||
lua_State *L; | ||
LoadState *S; | ||
int pass; /* 1 or 2; also 0 implies 1 */ |
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.
Should we be explicit about integer width here too (and in nSave
below), for consistency if nothing else?
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.
Not really. This an internal state structure (which is private to nodemcu.c
. This pattern just follows Lua coding style which uses int
in its structures for generic integer. The reason for the lu_int32
declarations is that these must be 32bit.
** The following compression maps are used in Store() ONLY in the case of | ||
** 64-bit hosts to repack structs to adjust for 64-bit->32-bit points in | ||
** absolute mode LFS creation. These must match the definitions in lobject.h | ||
*/ |
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.
Thanks Terry! :)
} else if (S->mode == MODE_LFSA && pack) { | ||
/* | ||
* 64-bit hosts have two LFS modes. The default LFS mode is for writing to a | ||
* when writing to native LFS where the address pointers are 64 bit and any |
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.
Is there a line missing here? Or is it just a mangled comment?
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.
mangled will rewrite
As I'm not that knowledgeable in Lua internals I can only test this PR. My observations:
|
@galjonsfigur, thanks I will add these to the TODO list. In terms of flash output, there isn't any difference between an LC file and a Flash Image file. Hence the |
Sorry for late reply - didn't notice it. As now |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Fixes #3206 (part)
dev
branch rather than formaster
.docs/*
.Notes
luac.cross -e
environment. Create a script containingdebug.debug()
and execute this to make a basic interpreter available.os
andio
are available and there are (HOST only) base functionslfsreload
andlfsindex
.