diff options
author | Mike Pall <mike> | 2024-01-22 19:06:36 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2024-01-22 19:06:36 +0100 |
commit | 4b90f6c4d7420139c135435e1580acb52ea18436 (patch) | |
tree | 1c3543b6baa4f8b30a33e8a624b60edc6feb0206 /src/lj_load.c | |
parent | c525bcb9024510cad9e170e12b6209aedb330f83 (diff) | |
download | luajit-4b90f6c4d7420139c135435e1580acb52ea18436.tar.gz luajit-4b90f6c4d7420139c135435e1580acb52ea18436.tar.bz2 luajit-4b90f6c4d7420139c135435e1580acb52ea18436.zip |
Add cross-32/64 bit and deterministic bytecode generation.
Contributed by Peter Cawley. #993 #1008
Diffstat (limited to 'src/lj_load.c')
-rw-r--r-- | src/lj_load.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/lj_load.c b/src/lj_load.c index 07304487..152ef6da 100644 --- a/src/lj_load.c +++ b/src/lj_load.c | |||
@@ -34,14 +34,28 @@ static TValue *cpparser(lua_State *L, lua_CFunction dummy, void *ud) | |||
34 | UNUSED(dummy); | 34 | UNUSED(dummy); |
35 | cframe_errfunc(L->cframe) = -1; /* Inherit error function. */ | 35 | cframe_errfunc(L->cframe) = -1; /* Inherit error function. */ |
36 | bc = lj_lex_setup(L, ls); | 36 | bc = lj_lex_setup(L, ls); |
37 | if (ls->mode && !strchr(ls->mode, bc ? 'b' : 't')) { | 37 | if (ls->mode) { |
38 | setstrV(L, L->top++, lj_err_str(L, LJ_ERR_XMODE)); | 38 | int xmode = 1; |
39 | lj_err_throw(L, LUA_ERRSYNTAX); | 39 | const char *mode = ls->mode; |
40 | char c; | ||
41 | while ((c = *mode++)) { | ||
42 | if (c == (bc ? 'b' : 't')) xmode = 0; | ||
43 | if (c == (LJ_FR2 ? 'W' : 'X')) ls->fr2 = !LJ_FR2; | ||
44 | } | ||
45 | if (xmode) { | ||
46 | setstrV(L, L->top++, lj_err_str(L, LJ_ERR_XMODE)); | ||
47 | lj_err_throw(L, LUA_ERRSYNTAX); | ||
48 | } | ||
40 | } | 49 | } |
41 | pt = bc ? lj_bcread(ls) : lj_parse(ls); | 50 | pt = bc ? lj_bcread(ls) : lj_parse(ls); |
42 | fn = lj_func_newL_empty(L, pt, tabref(L->env)); | 51 | if (ls->fr2 == LJ_FR2) { |
43 | /* Don't combine above/below into one statement. */ | 52 | fn = lj_func_newL_empty(L, pt, tabref(L->env)); |
44 | setfuncV(L, L->top++, fn); | 53 | /* Don't combine above/below into one statement. */ |
54 | setfuncV(L, L->top++, fn); | ||
55 | } else { | ||
56 | /* Non-native generation returns a dumpable, but non-runnable prototype. */ | ||
57 | setprotoV(L, L->top++, pt); | ||
58 | } | ||
45 | return NULL; | 59 | return NULL; |
46 | } | 60 | } |
47 | 61 | ||
@@ -159,9 +173,10 @@ LUALIB_API int luaL_loadstring(lua_State *L, const char *s) | |||
159 | LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data) | 173 | LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data) |
160 | { | 174 | { |
161 | cTValue *o = L->top-1; | 175 | cTValue *o = L->top-1; |
176 | uint32_t flags = LJ_FR2*BCDUMP_F_FR2; /* Default mode for legacy C API. */ | ||
162 | lj_checkapi(L->top > L->base, "top slot empty"); | 177 | lj_checkapi(L->top > L->base, "top slot empty"); |
163 | if (tvisfunc(o) && isluafunc(funcV(o))) | 178 | if (tvisfunc(o) && isluafunc(funcV(o))) |
164 | return lj_bcwrite(L, funcproto(funcV(o)), writer, data, 0); | 179 | return lj_bcwrite(L, funcproto(funcV(o)), writer, data, flags); |
165 | else | 180 | else |
166 | return 1; | 181 | return 1; |
167 | } | 182 | } |