aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-02-24 10:20:06 +0800
committerLi Jin <dragon-fly@qq.com>2022-02-24 10:20:19 +0800
commitfa9aad9300fd5c1b7ae697881d787d015fa9ef24 (patch)
treea3860d3a535ce269ff23be17cdee174bf7416c2e /src
parent63878b93b0f142af74b397a02b2c80be039b03ec (diff)
downloadyuescript-fa9aad9300fd5c1b7ae697881d787d015fa9ef24.tar.gz
yuescript-fa9aad9300fd5c1b7ae697881d787d015fa9ef24.tar.bz2
yuescript-fa9aad9300fd5c1b7ae697881d787d015fa9ef24.zip
update for windows build dll.
Diffstat (limited to 'src')
-rw-r--r--src/3rdParty/lua/lapi.c17
-rw-r--r--src/3rdParty/lua/lbaselib.c19
-rw-r--r--src/3rdParty/lua/lcode.c2
-rw-r--r--src/3rdParty/lua/ldebug.c56
-rw-r--r--src/3rdParty/lua/ldo.c2
-rw-r--r--src/3rdParty/lua/lgc.c17
-rw-r--r--src/3rdParty/lua/lgc.h10
-rw-r--r--src/3rdParty/lua/llimits.h2
-rw-r--r--src/3rdParty/lua/lmathlib.c4
-rw-r--r--src/3rdParty/lua/lobject.c10
-rw-r--r--src/3rdParty/lua/lparser.c1
-rw-r--r--src/3rdParty/lua/lstate.c5
-rw-r--r--src/3rdParty/lua/lstate.h4
-rw-r--r--src/3rdParty/lua/ltable.c35
-rw-r--r--src/3rdParty/lua/lua.c35
-rw-r--r--src/3rdParty/lua/lua.h4
-rw-r--r--src/3rdParty/lua/lvm.c121
-rw-r--r--src/yuescript/yuescript.cpp8
18 files changed, 231 insertions, 121 deletions
diff --git a/src/3rdParty/lua/lapi.c b/src/3rdParty/lua/lapi.c
index 071a06f..5ee6579 100644
--- a/src/3rdParty/lua/lapi.c
+++ b/src/3rdParty/lua/lapi.c
@@ -1136,18 +1136,19 @@ LUA_API int lua_status (lua_State *L) {
1136LUA_API int lua_gc (lua_State *L, int what, ...) { 1136LUA_API int lua_gc (lua_State *L, int what, ...) {
1137 va_list argp; 1137 va_list argp;
1138 int res = 0; 1138 int res = 0;
1139 global_State *g; 1139 global_State *g = G(L);
1140 if (g->gcstp & GCSTPGC) /* internal stop? */
1141 return -1; /* all options are invalid when stopped */
1140 lua_lock(L); 1142 lua_lock(L);
1141 g = G(L);
1142 va_start(argp, what); 1143 va_start(argp, what);
1143 switch (what) { 1144 switch (what) {
1144 case LUA_GCSTOP: { 1145 case LUA_GCSTOP: {
1145 g->gcrunning = 0; 1146 g->gcstp = GCSTPUSR; /* stopped by the user */
1146 break; 1147 break;
1147 } 1148 }
1148 case LUA_GCRESTART: { 1149 case LUA_GCRESTART: {
1149 luaE_setdebt(g, 0); 1150 luaE_setdebt(g, 0);
1150 g->gcrunning = 1; 1151 g->gcstp = 0; /* (GCSTPGC must be already zero here) */
1151 break; 1152 break;
1152 } 1153 }
1153 case LUA_GCCOLLECT: { 1154 case LUA_GCCOLLECT: {
@@ -1166,8 +1167,8 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
1166 case LUA_GCSTEP: { 1167 case LUA_GCSTEP: {
1167 int data = va_arg(argp, int); 1168 int data = va_arg(argp, int);
1168 l_mem debt = 1; /* =1 to signal that it did an actual step */ 1169 l_mem debt = 1; /* =1 to signal that it did an actual step */
1169 lu_byte oldrunning = g->gcrunning; 1170 lu_byte oldstp = g->gcstp;
1170 g->gcrunning = 1; /* allow GC to run */ 1171 g->gcstp = 0; /* allow GC to run (GCSTPGC must be zero here) */
1171 if (data == 0) { 1172 if (data == 0) {
1172 luaE_setdebt(g, 0); /* do a basic step */ 1173 luaE_setdebt(g, 0); /* do a basic step */
1173 luaC_step(L); 1174 luaC_step(L);
@@ -1177,7 +1178,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
1177 luaE_setdebt(g, debt); 1178 luaE_setdebt(g, debt);
1178 luaC_checkGC(L); 1179 luaC_checkGC(L);
1179 } 1180 }
1180 g->gcrunning = oldrunning; /* restore previous state */ 1181 g->gcstp = oldstp; /* restore previous state */
1181 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */ 1182 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */
1182 res = 1; /* signal it */ 1183 res = 1; /* signal it */
1183 break; 1184 break;
@@ -1195,7 +1196,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
1195 break; 1196 break;
1196 } 1197 }
1197 case LUA_GCISRUNNING: { 1198 case LUA_GCISRUNNING: {
1198 res = g->gcrunning; 1199 res = gcrunning(g);
1199 break; 1200 break;
1200 } 1201 }
1201 case LUA_GCGEN: { 1202 case LUA_GCGEN: {
diff --git a/src/3rdParty/lua/lbaselib.c b/src/3rdParty/lua/lbaselib.c
index 912c4cc..1d60c9d 100644
--- a/src/3rdParty/lua/lbaselib.c
+++ b/src/3rdParty/lua/lbaselib.c
@@ -182,12 +182,20 @@ static int luaB_rawset (lua_State *L) {
182 182
183 183
184static int pushmode (lua_State *L, int oldmode) { 184static int pushmode (lua_State *L, int oldmode) {
185 lua_pushstring(L, (oldmode == LUA_GCINC) ? "incremental" 185 if (oldmode == -1)
186 : "generational"); 186 luaL_pushfail(L); /* invalid call to 'lua_gc' */
187 else
188 lua_pushstring(L, (oldmode == LUA_GCINC) ? "incremental"
189 : "generational");
187 return 1; 190 return 1;
188} 191}
189 192
190 193
194/*
195** check whether call to 'lua_gc' was valid (not inside a finalizer)
196*/
197#define checkvalres(res) { if (res == -1) break; }
198
191static int luaB_collectgarbage (lua_State *L) { 199static int luaB_collectgarbage (lua_State *L) {
192 static const char *const opts[] = {"stop", "restart", "collect", 200 static const char *const opts[] = {"stop", "restart", "collect",
193 "count", "step", "setpause", "setstepmul", 201 "count", "step", "setpause", "setstepmul",
@@ -200,12 +208,14 @@ static int luaB_collectgarbage (lua_State *L) {
200 case LUA_GCCOUNT: { 208 case LUA_GCCOUNT: {
201 int k = lua_gc(L, o); 209 int k = lua_gc(L, o);
202 int b = lua_gc(L, LUA_GCCOUNTB); 210 int b = lua_gc(L, LUA_GCCOUNTB);
211 checkvalres(k);
203 lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024)); 212 lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024));
204 return 1; 213 return 1;
205 } 214 }
206 case LUA_GCSTEP: { 215 case LUA_GCSTEP: {
207 int step = (int)luaL_optinteger(L, 2, 0); 216 int step = (int)luaL_optinteger(L, 2, 0);
208 int res = lua_gc(L, o, step); 217 int res = lua_gc(L, o, step);
218 checkvalres(res);
209 lua_pushboolean(L, res); 219 lua_pushboolean(L, res);
210 return 1; 220 return 1;
211 } 221 }
@@ -213,11 +223,13 @@ static int luaB_collectgarbage (lua_State *L) {
213 case LUA_GCSETSTEPMUL: { 223 case LUA_GCSETSTEPMUL: {
214 int p = (int)luaL_optinteger(L, 2, 0); 224 int p = (int)luaL_optinteger(L, 2, 0);
215 int previous = lua_gc(L, o, p); 225 int previous = lua_gc(L, o, p);
226 checkvalres(previous);
216 lua_pushinteger(L, previous); 227 lua_pushinteger(L, previous);
217 return 1; 228 return 1;
218 } 229 }
219 case LUA_GCISRUNNING: { 230 case LUA_GCISRUNNING: {
220 int res = lua_gc(L, o); 231 int res = lua_gc(L, o);
232 checkvalres(res);
221 lua_pushboolean(L, res); 233 lua_pushboolean(L, res);
222 return 1; 234 return 1;
223 } 235 }
@@ -234,10 +246,13 @@ static int luaB_collectgarbage (lua_State *L) {
234 } 246 }
235 default: { 247 default: {
236 int res = lua_gc(L, o); 248 int res = lua_gc(L, o);
249 checkvalres(res);
237 lua_pushinteger(L, res); 250 lua_pushinteger(L, res);
238 return 1; 251 return 1;
239 } 252 }
240 } 253 }
254 luaL_pushfail(L); /* invalid call (inside a finalizer) */
255 return 1;
241} 256}
242 257
243 258
diff --git a/src/3rdParty/lua/lcode.c b/src/3rdParty/lua/lcode.c
index 9cba24f..06425a1 100644
--- a/src/3rdParty/lua/lcode.c
+++ b/src/3rdParty/lua/lcode.c
@@ -607,7 +607,7 @@ static int luaK_numberK (FuncState *fs, lua_Number r) {
607 return addk(fs, &o, &o); /* use number itself as key */ 607 return addk(fs, &o, &o); /* use number itself as key */
608 else { /* must build an alternative key */ 608 else { /* must build an alternative key */
609 const int nbm = l_floatatt(MANT_DIG); 609 const int nbm = l_floatatt(MANT_DIG);
610 const lua_Number q = l_mathop(ldexp)(1.0, -nbm + 1); 610 const lua_Number q = l_mathop(ldexp)(l_mathop(1.0), -nbm + 1);
611 const lua_Number k = (ik == 0) ? q : r + r*q; /* new key */ 611 const lua_Number k = (ik == 0) ? q : r + r*q; /* new key */
612 TValue kv; 612 TValue kv;
613 setfltvalue(&kv, k); 613 setfltvalue(&kv, k);
diff --git a/src/3rdParty/lua/ldebug.c b/src/3rdParty/lua/ldebug.c
index 30a2882..a716d95 100644
--- a/src/3rdParty/lua/ldebug.c
+++ b/src/3rdParty/lua/ldebug.c
@@ -34,8 +34,8 @@
34#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_VCCL) 34#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_VCCL)
35 35
36 36
37static const char *funcnamefromcode (lua_State *L, CallInfo *ci, 37static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
38 const char **name); 38 const char **name);
39 39
40 40
41static int currentpc (CallInfo *ci) { 41static int currentpc (CallInfo *ci) {
@@ -304,7 +304,7 @@ static void collectvalidlines (lua_State *L, Closure *f) {
304 if (!p->is_vararg) /* regular function? */ 304 if (!p->is_vararg) /* regular function? */
305 i = 0; /* consider all instructions */ 305 i = 0; /* consider all instructions */
306 else { /* vararg function */ 306 else { /* vararg function */
307 lua_assert(p->code[0] == OP_VARARGPREP); 307 lua_assert(GET_OPCODE(p->code[0]) == OP_VARARGPREP);
308 currentline = nextline(p, currentline, 0); 308 currentline = nextline(p, currentline, 0);
309 i = 1; /* skip first instruction (OP_VARARGPREP) */ 309 i = 1; /* skip first instruction (OP_VARARGPREP) */
310 } 310 }
@@ -317,15 +317,9 @@ static void collectvalidlines (lua_State *L, Closure *f) {
317 317
318 318
319static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { 319static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
320 if (ci == NULL) /* no 'ci'? */ 320 /* calling function is a known function? */
321 return NULL; /* no info */ 321 if (ci != NULL && !(ci->callstatus & CIST_TAIL))
322 else if (ci->callstatus & CIST_FIN) { /* is this a finalizer? */ 322 return funcnamefromcall(L, ci->previous, name);
323 *name = "__gc";
324 return "metamethod"; /* report it as such */
325 }
326 /* calling function is a known Lua function? */
327 else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
328 return funcnamefromcode(L, ci->previous, name);
329 else return NULL; /* no way to find a name */ 323 else return NULL; /* no way to find a name */
330} 324}
331 325
@@ -597,16 +591,10 @@ static const char *getobjname (const Proto *p, int lastpc, int reg,
597** Returns what the name is (e.g., "for iterator", "method", 591** Returns what the name is (e.g., "for iterator", "method",
598** "metamethod") and sets '*name' to point to the name. 592** "metamethod") and sets '*name' to point to the name.
599*/ 593*/
600static const char *funcnamefromcode (lua_State *L, CallInfo *ci, 594static const char *funcnamefromcode (lua_State *L, const Proto *p,
601 const char **name) { 595 int pc, const char **name) {
602 TMS tm = (TMS)0; /* (initial value avoids warnings) */ 596 TMS tm = (TMS)0; /* (initial value avoids warnings) */
603 const Proto *p = ci_func(ci)->p; /* calling function */
604 int pc = currentpc(ci); /* calling instruction index */
605 Instruction i = p->code[pc]; /* calling instruction */ 597 Instruction i = p->code[pc]; /* calling instruction */
606 if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
607 *name = "?";
608 return "hook";
609 }
610 switch (GET_OPCODE(i)) { 598 switch (GET_OPCODE(i)) {
611 case OP_CALL: 599 case OP_CALL:
612 case OP_TAILCALL: 600 case OP_TAILCALL:
@@ -643,6 +631,26 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
643 return "metamethod"; 631 return "metamethod";
644} 632}
645 633
634
635/*
636** Try to find a name for a function based on how it was called.
637*/
638static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
639 const char **name) {
640 if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
641 *name = "?";
642 return "hook";
643 }
644 else if (ci->callstatus & CIST_FIN) { /* was it called as a finalizer? */
645 *name = "__gc";
646 return "metamethod"; /* report it as such */
647 }
648 else if (isLua(ci))
649 return funcnamefromcode(L, ci_func(ci)->p, currentpc(ci), name);
650 else
651 return NULL;
652}
653
646/* }====================================================== */ 654/* }====================================================== */
647 655
648 656
@@ -728,14 +736,14 @@ l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
728 736
729 737
730/* 738/*
731** Raise an error for calling a non-callable object. Try to find 739** Raise an error for calling a non-callable object. Try to find a name
732** a name for the object based on the code that made the call 740** for the object based on how it was called ('funcnamefromcall'); if it
733** ('funcnamefromcode'); if it cannot get a name there, try 'varinfo'. 741** cannot get a name there, try 'varinfo'.
734*/ 742*/
735l_noret luaG_callerror (lua_State *L, const TValue *o) { 743l_noret luaG_callerror (lua_State *L, const TValue *o) {
736 CallInfo *ci = L->ci; 744 CallInfo *ci = L->ci;
737 const char *name = NULL; /* to avoid warnings */ 745 const char *name = NULL; /* to avoid warnings */
738 const char *kind = (isLua(ci)) ? funcnamefromcode(L, ci, &name) : NULL; 746 const char *kind = funcnamefromcall(L, ci, &name);
739 const char *extra = kind ? formatvarinfo(L, kind, name) : varinfo(L, o); 747 const char *extra = kind ? formatvarinfo(L, kind, name) : varinfo(L, o);
740 typeerror(L, o, "call", extra); 748 typeerror(L, o, "call", extra);
741} 749}
diff --git a/src/3rdParty/lua/ldo.c b/src/3rdParty/lua/ldo.c
index f282a77..a48e35f 100644
--- a/src/3rdParty/lua/ldo.c
+++ b/src/3rdParty/lua/ldo.c
@@ -530,10 +530,10 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
530 int fsize = p->maxstacksize; /* frame size */ 530 int fsize = p->maxstacksize; /* frame size */
531 int nfixparams = p->numparams; 531 int nfixparams = p->numparams;
532 int i; 532 int i;
533 checkstackGCp(L, fsize - delta, func);
533 ci->func -= delta; /* restore 'func' (if vararg) */ 534 ci->func -= delta; /* restore 'func' (if vararg) */
534 for (i = 0; i < narg1; i++) /* move down function and arguments */ 535 for (i = 0; i < narg1; i++) /* move down function and arguments */
535 setobjs2s(L, ci->func + i, func + i); 536 setobjs2s(L, ci->func + i, func + i);
536 checkstackGC(L, fsize);
537 func = ci->func; /* moved-down function */ 537 func = ci->func; /* moved-down function */
538 for (; narg1 <= nfixparams; narg1++) 538 for (; narg1 <= nfixparams; narg1++)
539 setnilvalue(s2v(func + narg1)); /* complete missing arguments */ 539 setnilvalue(s2v(func + narg1)); /* complete missing arguments */
diff --git a/src/3rdParty/lua/lgc.c b/src/3rdParty/lua/lgc.c
index b360eed..42a73d8 100644
--- a/src/3rdParty/lua/lgc.c
+++ b/src/3rdParty/lua/lgc.c
@@ -906,18 +906,18 @@ static void GCTM (lua_State *L) {
906 if (!notm(tm)) { /* is there a finalizer? */ 906 if (!notm(tm)) { /* is there a finalizer? */
907 int status; 907 int status;
908 lu_byte oldah = L->allowhook; 908 lu_byte oldah = L->allowhook;
909 int running = g->gcrunning; 909 int oldgcstp = g->gcstp;
910 g->gcstp |= GCSTPGC; /* avoid GC steps */
910 L->allowhook = 0; /* stop debug hooks during GC metamethod */ 911 L->allowhook = 0; /* stop debug hooks during GC metamethod */
911 g->gcrunning = 0; /* avoid GC steps */
912 setobj2s(L, L->top++, tm); /* push finalizer... */ 912 setobj2s(L, L->top++, tm); /* push finalizer... */
913 setobj2s(L, L->top++, &v); /* ... and its argument */ 913 setobj2s(L, L->top++, &v); /* ... and its argument */
914 L->ci->callstatus |= CIST_FIN; /* will run a finalizer */ 914 L->ci->callstatus |= CIST_FIN; /* will run a finalizer */
915 status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); 915 status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);
916 L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */ 916 L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */
917 L->allowhook = oldah; /* restore hooks */ 917 L->allowhook = oldah; /* restore hooks */
918 g->gcrunning = running; /* restore state */ 918 g->gcstp = oldgcstp; /* restore state */
919 if (l_unlikely(status != LUA_OK)) { /* error while running __gc? */ 919 if (l_unlikely(status != LUA_OK)) { /* error while running __gc? */
920 luaE_warnerror(L, "__gc metamethod"); 920 luaE_warnerror(L, "__gc");
921 L->top--; /* pops error object */ 921 L->top--; /* pops error object */
922 } 922 }
923 } 923 }
@@ -1011,7 +1011,8 @@ static void correctpointers (global_State *g, GCObject *o) {
1011void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { 1011void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
1012 global_State *g = G(L); 1012 global_State *g = G(L);
1013 if (tofinalize(o) || /* obj. is already marked... */ 1013 if (tofinalize(o) || /* obj. is already marked... */
1014 gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */ 1014 gfasttm(g, mt, TM_GC) == NULL || /* or has no finalizer... */
1015 (g->gcstp & GCSTPCLS)) /* or closing state? */
1015 return; /* nothing to be done */ 1016 return; /* nothing to be done */
1016 else { /* move 'o' to 'finobj' list */ 1017 else { /* move 'o' to 'finobj' list */
1017 GCObject **p; 1018 GCObject **p;
@@ -1502,12 +1503,13 @@ static void deletelist (lua_State *L, GCObject *p, GCObject *limit) {
1502*/ 1503*/
1503void luaC_freeallobjects (lua_State *L) { 1504void luaC_freeallobjects (lua_State *L) {
1504 global_State *g = G(L); 1505 global_State *g = G(L);
1506 g->gcstp = GCSTPCLS; /* no extra finalizers after here */
1505 luaC_changemode(L, KGC_INC); 1507 luaC_changemode(L, KGC_INC);
1506 separatetobefnz(g, 1); /* separate all objects with finalizers */ 1508 separatetobefnz(g, 1); /* separate all objects with finalizers */
1507 lua_assert(g->finobj == NULL); 1509 lua_assert(g->finobj == NULL);
1508 callallpendingfinalizers(L); 1510 callallpendingfinalizers(L);
1509 deletelist(L, g->allgc, obj2gco(g->mainthread)); 1511 deletelist(L, g->allgc, obj2gco(g->mainthread));
1510 deletelist(L, g->finobj, NULL); 1512 lua_assert(g->finobj == NULL); /* no new finalizers */
1511 deletelist(L, g->fixedgc, NULL); /* collect fixed objects */ 1513 deletelist(L, g->fixedgc, NULL); /* collect fixed objects */
1512 lua_assert(g->strt.nuse == 0); 1514 lua_assert(g->strt.nuse == 0);
1513} 1515}
@@ -1647,6 +1649,7 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
1647} 1649}
1648 1650
1649 1651
1652
1650/* 1653/*
1651** Performs a basic incremental step. The debt and step size are 1654** Performs a basic incremental step. The debt and step size are
1652** converted from bytes to "units of work"; then the function loops 1655** converted from bytes to "units of work"; then the function loops
@@ -1678,7 +1681,7 @@ static void incstep (lua_State *L, global_State *g) {
1678void luaC_step (lua_State *L) { 1681void luaC_step (lua_State *L) {
1679 global_State *g = G(L); 1682 global_State *g = G(L);
1680 lua_assert(!g->gcemergency); 1683 lua_assert(!g->gcemergency);
1681 if (g->gcrunning) { /* running? */ 1684 if (gcrunning(g)) { /* running? */
1682 if(isdecGCmodegen(g)) 1685 if(isdecGCmodegen(g))
1683 genstep(L, g); 1686 genstep(L, g);
1684 else 1687 else
diff --git a/src/3rdParty/lua/lgc.h b/src/3rdParty/lua/lgc.h
index 073e2a4..4a12563 100644
--- a/src/3rdParty/lua/lgc.h
+++ b/src/3rdParty/lua/lgc.h
@@ -148,6 +148,16 @@
148*/ 148*/
149#define isdecGCmodegen(g) (g->gckind == KGC_GEN || g->lastatomic != 0) 149#define isdecGCmodegen(g) (g->gckind == KGC_GEN || g->lastatomic != 0)
150 150
151
152/*
153** Control when GC is running:
154*/
155#define GCSTPUSR 1 /* bit true when GC stopped by user */
156#define GCSTPGC 2 /* bit true when GC stopped by itself */
157#define GCSTPCLS 4 /* bit true when closing Lua state */
158#define gcrunning(g) ((g)->gcstp == 0)
159
160
151/* 161/*
152** Does one step of collection when debt becomes positive. 'pre'/'pos' 162** Does one step of collection when debt becomes positive. 'pre'/'pos'
153** allows some adjustments to be done only when needed. macro 163** allows some adjustments to be done only when needed. macro
diff --git a/src/3rdParty/lua/llimits.h b/src/3rdParty/lua/llimits.h
index 6c56ba5..52a32f9 100644
--- a/src/3rdParty/lua/llimits.h
+++ b/src/3rdParty/lua/llimits.h
@@ -361,7 +361,7 @@ typedef l_uint32 Instruction;
361#define condchangemem(L,pre,pos) ((void)0) 361#define condchangemem(L,pre,pos) ((void)0)
362#else 362#else
363#define condchangemem(L,pre,pos) \ 363#define condchangemem(L,pre,pos) \
364 { if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } } 364 { if (gcrunning(G(L))) { pre; luaC_fullgc(L, 0); pos; } }
365#endif 365#endif
366 366
367#endif 367#endif
diff --git a/src/3rdParty/lua/lmathlib.c b/src/3rdParty/lua/lmathlib.c
index 5f5983a..e0c61a1 100644
--- a/src/3rdParty/lua/lmathlib.c
+++ b/src/3rdParty/lua/lmathlib.c
@@ -475,7 +475,7 @@ static lua_Number I2d (Rand64 x) {
475 475
476/* 2^(-FIGS) = 1.0 / 2^30 / 2^3 / 2^(FIGS-33) */ 476/* 2^(-FIGS) = 1.0 / 2^30 / 2^3 / 2^(FIGS-33) */
477#define scaleFIG \ 477#define scaleFIG \
478 ((lua_Number)1.0 / (UONE << 30) / 8.0 / (UONE << (FIGS - 33))) 478 (l_mathop(1.0) / (UONE << 30) / l_mathop(8.0) / (UONE << (FIGS - 33)))
479 479
480/* 480/*
481** use FIGS - 32 bits from lower half, throwing out the other 481** use FIGS - 32 bits from lower half, throwing out the other
@@ -486,7 +486,7 @@ static lua_Number I2d (Rand64 x) {
486/* 486/*
487** higher 32 bits go after those (FIGS - 32) bits: shiftHI = 2^(FIGS - 32) 487** higher 32 bits go after those (FIGS - 32) bits: shiftHI = 2^(FIGS - 32)
488*/ 488*/
489#define shiftHI ((lua_Number)(UONE << (FIGS - 33)) * 2.0) 489#define shiftHI ((lua_Number)(UONE << (FIGS - 33)) * l_mathop(2.0))
490 490
491 491
492static lua_Number I2d (Rand64 x) { 492static lua_Number I2d (Rand64 x) {
diff --git a/src/3rdParty/lua/lobject.c b/src/3rdParty/lua/lobject.c
index 0e504be..301aa90 100644
--- a/src/3rdParty/lua/lobject.c
+++ b/src/3rdParty/lua/lobject.c
@@ -164,7 +164,7 @@ static int isneg (const char **s) {
164*/ 164*/
165static lua_Number lua_strx2number (const char *s, char **endptr) { 165static lua_Number lua_strx2number (const char *s, char **endptr) {
166 int dot = lua_getlocaledecpoint(); 166 int dot = lua_getlocaledecpoint();
167 lua_Number r = 0.0; /* result (accumulator) */ 167 lua_Number r = l_mathop(0.0); /* result (accumulator) */
168 int sigdig = 0; /* number of significant digits */ 168 int sigdig = 0; /* number of significant digits */
169 int nosigdig = 0; /* number of non-significant digits */ 169 int nosigdig = 0; /* number of non-significant digits */
170 int e = 0; /* exponent correction */ 170 int e = 0; /* exponent correction */
@@ -174,7 +174,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
174 while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */ 174 while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */
175 neg = isneg(&s); /* check sign */ 175 neg = isneg(&s); /* check sign */
176 if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */ 176 if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */
177 return 0.0; /* invalid format (no '0x') */ 177 return l_mathop(0.0); /* invalid format (no '0x') */
178 for (s += 2; ; s++) { /* skip '0x' and read numeral */ 178 for (s += 2; ; s++) { /* skip '0x' and read numeral */
179 if (*s == dot) { 179 if (*s == dot) {
180 if (hasdot) break; /* second dot? stop loop */ 180 if (hasdot) break; /* second dot? stop loop */
@@ -184,14 +184,14 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
184 if (sigdig == 0 && *s == '0') /* non-significant digit (zero)? */ 184 if (sigdig == 0 && *s == '0') /* non-significant digit (zero)? */
185 nosigdig++; 185 nosigdig++;
186 else if (++sigdig <= MAXSIGDIG) /* can read it without overflow? */ 186 else if (++sigdig <= MAXSIGDIG) /* can read it without overflow? */
187 r = (r * cast_num(16.0)) + luaO_hexavalue(*s); 187 r = (r * l_mathop(16.0)) + luaO_hexavalue(*s);
188 else e++; /* too many digits; ignore, but still count for exponent */ 188 else e++; /* too many digits; ignore, but still count for exponent */
189 if (hasdot) e--; /* decimal digit? correct exponent */ 189 if (hasdot) e--; /* decimal digit? correct exponent */
190 } 190 }
191 else break; /* neither a dot nor a digit */ 191 else break; /* neither a dot nor a digit */
192 } 192 }
193 if (nosigdig + sigdig == 0) /* no digits? */ 193 if (nosigdig + sigdig == 0) /* no digits? */
194 return 0.0; /* invalid format */ 194 return l_mathop(0.0); /* invalid format */
195 *endptr = cast_charp(s); /* valid up to here */ 195 *endptr = cast_charp(s); /* valid up to here */
196 e *= 4; /* each digit multiplies/divides value by 2^4 */ 196 e *= 4; /* each digit multiplies/divides value by 2^4 */
197 if (*s == 'p' || *s == 'P') { /* exponent part? */ 197 if (*s == 'p' || *s == 'P') { /* exponent part? */
@@ -200,7 +200,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
200 s++; /* skip 'p' */ 200 s++; /* skip 'p' */
201 neg1 = isneg(&s); /* sign */ 201 neg1 = isneg(&s); /* sign */
202 if (!lisdigit(cast_uchar(*s))) 202 if (!lisdigit(cast_uchar(*s)))
203 return 0.0; /* invalid; must have at least one digit */ 203 return l_mathop(0.0); /* invalid; must have at least one digit */
204 while (lisdigit(cast_uchar(*s))) /* read exponent */ 204 while (lisdigit(cast_uchar(*s))) /* read exponent */
205 exp1 = exp1 * 10 + *(s++) - '0'; 205 exp1 = exp1 * 10 + *(s++) - '0';
206 if (neg1) exp1 = -exp1; 206 if (neg1) exp1 = -exp1;
diff --git a/src/3rdParty/lua/lparser.c b/src/3rdParty/lua/lparser.c
index 3abe3d7..a5cd552 100644
--- a/src/3rdParty/lua/lparser.c
+++ b/src/3rdParty/lua/lparser.c
@@ -468,6 +468,7 @@ static void singlevar (LexState *ls, expdesc *var) {
468 expdesc key; 468 expdesc key;
469 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ 469 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
470 lua_assert(var->k != VVOID); /* this one must exist */ 470 lua_assert(var->k != VVOID); /* this one must exist */
471 luaK_exp2anyregup(fs, var); /* but could be a constant */
471 codestring(&key, varname); /* key is variable name */ 472 codestring(&key, varname); /* key is variable name */
472 luaK_indexed(fs, var, &key); /* env[varname] */ 473 luaK_indexed(fs, var, &key); /* env[varname] */
473 } 474 }
diff --git a/src/3rdParty/lua/lstate.c b/src/3rdParty/lua/lstate.c
index 5cb0847..1ffe1a0 100644
--- a/src/3rdParty/lua/lstate.c
+++ b/src/3rdParty/lua/lstate.c
@@ -236,7 +236,7 @@ static void f_luaopen (lua_State *L, void *ud) {
236 luaS_init(L); 236 luaS_init(L);
237 luaT_init(L); 237 luaT_init(L);
238 luaX_init(L); 238 luaX_init(L);
239 g->gcrunning = 1; /* allow gc */ 239 g->gcstp = 0; /* allow gc */
240 setnilvalue(&g->nilvalue); /* now state is complete */ 240 setnilvalue(&g->nilvalue); /* now state is complete */
241 luai_userstateopen(L); 241 luai_userstateopen(L);
242} 242}
@@ -271,6 +271,7 @@ static void close_state (lua_State *L) {
271 if (!completestate(g)) /* closing a partially built state? */ 271 if (!completestate(g)) /* closing a partially built state? */
272 luaC_freeallobjects(L); /* just collect its objects */ 272 luaC_freeallobjects(L); /* just collect its objects */
273 else { /* closing a fully built state */ 273 else { /* closing a fully built state */
274 L->ci = &L->base_ci; /* unwind CallInfo list */
274 luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */ 275 luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */
275 luaC_freeallobjects(L); /* collect all objects */ 276 luaC_freeallobjects(L); /* collect all objects */
276 luai_userstateclose(L); 277 luai_userstateclose(L);
@@ -372,7 +373,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
372 g->ud_warn = NULL; 373 g->ud_warn = NULL;
373 g->mainthread = L; 374 g->mainthread = L;
374 g->seed = luai_makeseed(L); 375 g->seed = luai_makeseed(L);
375 g->gcrunning = 0; /* no GC while building state */ 376 g->gcstp = GCSTPGC; /* no GC while building state */
376 g->strt.size = g->strt.nuse = 0; 377 g->strt.size = g->strt.nuse = 0;
377 g->strt.hash = NULL; 378 g->strt.hash = NULL;
378 setnilvalue(&g->l_registry); 379 setnilvalue(&g->l_registry);
diff --git a/src/3rdParty/lua/lstate.h b/src/3rdParty/lua/lstate.h
index 44cf939..61e82cd 100644
--- a/src/3rdParty/lua/lstate.h
+++ b/src/3rdParty/lua/lstate.h
@@ -209,7 +209,7 @@ typedef struct CallInfo {
209#define CIST_YPCALL (1<<4) /* doing a yieldable protected call */ 209#define CIST_YPCALL (1<<4) /* doing a yieldable protected call */
210#define CIST_TAIL (1<<5) /* call was tail called */ 210#define CIST_TAIL (1<<5) /* call was tail called */
211#define CIST_HOOKYIELD (1<<6) /* last hook called yielded */ 211#define CIST_HOOKYIELD (1<<6) /* last hook called yielded */
212#define CIST_FIN (1<<7) /* call is running a finalizer */ 212#define CIST_FIN (1<<7) /* function "called" a finalizer */
213#define CIST_TRAN (1<<8) /* 'ci' has transfer information */ 213#define CIST_TRAN (1<<8) /* 'ci' has transfer information */
214#define CIST_CLSRET (1<<9) /* function is closing tbc variables */ 214#define CIST_CLSRET (1<<9) /* function is closing tbc variables */
215/* Bits 10-12 are used for CIST_RECST (see below) */ 215/* Bits 10-12 are used for CIST_RECST (see below) */
@@ -263,7 +263,7 @@ typedef struct global_State {
263 lu_byte gcstopem; /* stops emergency collections */ 263 lu_byte gcstopem; /* stops emergency collections */
264 lu_byte genminormul; /* control for minor generational collections */ 264 lu_byte genminormul; /* control for minor generational collections */
265 lu_byte genmajormul; /* control for major generational collections */ 265 lu_byte genmajormul; /* control for major generational collections */
266 lu_byte gcrunning; /* true if GC is running */ 266 lu_byte gcstp; /* control whether GC is running */
267 lu_byte gcemergency; /* true if this is an emergency collection */ 267 lu_byte gcemergency; /* true if this is an emergency collection */
268 lu_byte gcpause; /* size of pause between successive GCs */ 268 lu_byte gcpause; /* size of pause between successive GCs */
269 lu_byte gcstepmul; /* GC "speed" */ 269 lu_byte gcstepmul; /* GC "speed" */
diff --git a/src/3rdParty/lua/ltable.c b/src/3rdParty/lua/ltable.c
index c82286d..1b1cd24 100644
--- a/src/3rdParty/lua/ltable.c
+++ b/src/3rdParty/lua/ltable.c
@@ -146,26 +146,24 @@ static int l_hashfloat (lua_Number n) {
146 146
147/* 147/*
148** returns the 'main' position of an element in a table (that is, 148** returns the 'main' position of an element in a table (that is,
149** the index of its hash value). The key comes broken (tag in 'ktt' 149** the index of its hash value).
150** and value in 'vkl') so that we can call it on keys inserted into
151** nodes.
152*/ 150*/
153static Node *mainposition (const Table *t, int ktt, const Value kvl) { 151static Node *mainpositionTV (const Table *t, const TValue *key) {
154 switch (withvariant(ktt)) { 152 switch (ttypetag(key)) {
155 case LUA_VNUMINT: { 153 case LUA_VNUMINT: {
156 lua_Integer key = ivalueraw(kvl); 154 lua_Integer i = ivalue(key);
157 return hashint(t, key); 155 return hashint(t, i);
158 } 156 }
159 case LUA_VNUMFLT: { 157 case LUA_VNUMFLT: {
160 lua_Number n = fltvalueraw(kvl); 158 lua_Number n = fltvalue(key);
161 return hashmod(t, l_hashfloat(n)); 159 return hashmod(t, l_hashfloat(n));
162 } 160 }
163 case LUA_VSHRSTR: { 161 case LUA_VSHRSTR: {
164 TString *ts = tsvalueraw(kvl); 162 TString *ts = tsvalue(key);
165 return hashstr(t, ts); 163 return hashstr(t, ts);
166 } 164 }
167 case LUA_VLNGSTR: { 165 case LUA_VLNGSTR: {
168 TString *ts = tsvalueraw(kvl); 166 TString *ts = tsvalue(key);
169 return hashpow2(t, luaS_hashlongstr(ts)); 167 return hashpow2(t, luaS_hashlongstr(ts));
170 } 168 }
171 case LUA_VFALSE: 169 case LUA_VFALSE:
@@ -173,26 +171,25 @@ static Node *mainposition (const Table *t, int ktt, const Value kvl) {
173 case LUA_VTRUE: 171 case LUA_VTRUE:
174 return hashboolean(t, 1); 172 return hashboolean(t, 1);
175 case LUA_VLIGHTUSERDATA: { 173 case LUA_VLIGHTUSERDATA: {
176 void *p = pvalueraw(kvl); 174 void *p = pvalue(key);
177 return hashpointer(t, p); 175 return hashpointer(t, p);
178 } 176 }
179 case LUA_VLCF: { 177 case LUA_VLCF: {
180 lua_CFunction f = fvalueraw(kvl); 178 lua_CFunction f = fvalue(key);
181 return hashpointer(t, f); 179 return hashpointer(t, f);
182 } 180 }
183 default: { 181 default: {
184 GCObject *o = gcvalueraw(kvl); 182 GCObject *o = gcvalue(key);
185 return hashpointer(t, o); 183 return hashpointer(t, o);
186 } 184 }
187 } 185 }
188} 186}
189 187
190 188
191/* 189l_sinline Node *mainpositionfromnode (const Table *t, Node *nd) {
192** Returns the main position of an element given as a 'TValue' 190 TValue key;
193*/ 191 getnodekey(cast(lua_State *, NULL), &key, nd);
194static Node *mainpositionTV (const Table *t, const TValue *key) { 192 return mainpositionTV(t, &key);
195 return mainposition(t, rawtt(key), valraw(key));
196} 193}
197 194
198 195
@@ -691,7 +688,7 @@ void luaH_newkey (lua_State *L, Table *t, const TValue *key, TValue *value) {
691 return; 688 return;
692 } 689 }
693 lua_assert(!isdummy(t)); 690 lua_assert(!isdummy(t));
694 othern = mainposition(t, keytt(mp), keyval(mp)); 691 othern = mainpositionfromnode(t, mp);
695 if (othern != mp) { /* is colliding node out of its main position? */ 692 if (othern != mp) { /* is colliding node out of its main position? */
696 /* yes; move colliding node into free position */ 693 /* yes; move colliding node into free position */
697 while (othern + gnext(othern) != mp) /* find previous */ 694 while (othern + gnext(othern) != mp) /* find previous */
diff --git a/src/3rdParty/lua/lua.c b/src/3rdParty/lua/lua.c
index 0f19004..7f7dc2b 100644
--- a/src/3rdParty/lua/lua.c
+++ b/src/3rdParty/lua/lua.c
@@ -177,10 +177,11 @@ static void print_version (void) {
177** to the script (everything after 'script') go to positive indices; 177** to the script (everything after 'script') go to positive indices;
178** other arguments (before the script name) go to negative indices. 178** other arguments (before the script name) go to negative indices.
179** If there is no script name, assume interpreter's name as base. 179** If there is no script name, assume interpreter's name as base.
180** (If there is no interpreter's name either, 'script' is -1, so
181** table sizes are zero.)
180*/ 182*/
181static void createargtable (lua_State *L, char **argv, int argc, int script) { 183static void createargtable (lua_State *L, char **argv, int argc, int script) {
182 int i, narg; 184 int i, narg;
183 if (script == argc) script = 0; /* no script name? */
184 narg = argc - (script + 1); /* number of positive indices */ 185 narg = argc - (script + 1); /* number of positive indices */
185 lua_createtable(L, narg, script + 1); 186 lua_createtable(L, narg, script + 1);
186 for (i = 0; i < argc; i++) { 187 for (i = 0; i < argc; i++) {
@@ -268,14 +269,23 @@ static int handle_script (lua_State *L, char **argv) {
268 269
269/* 270/*
270** Traverses all arguments from 'argv', returning a mask with those 271** Traverses all arguments from 'argv', returning a mask with those
271** needed before running any Lua code (or an error code if it finds 272** needed before running any Lua code or an error code if it finds any
272** any invalid argument). 'first' returns the first not-handled argument 273** invalid argument. In case of error, 'first' is the index of the bad
273** (either the script name or a bad argument in case of error). 274** argument. Otherwise, 'first' is -1 if there is no program name,
275** 0 if there is no script name, or the index of the script name.
274*/ 276*/
275static int collectargs (char **argv, int *first) { 277static int collectargs (char **argv, int *first) {
276 int args = 0; 278 int args = 0;
277 int i; 279 int i;
278 for (i = 1; argv[i] != NULL; i++) { 280 if (argv[0] != NULL) { /* is there a program name? */
281 if (argv[0][0]) /* not empty? */
282 progname = argv[0]; /* save it */
283 }
284 else { /* no program name */
285 *first = -1;
286 return 0;
287 }
288 for (i = 1; argv[i] != NULL; i++) { /* handle arguments */
279 *first = i; 289 *first = i;
280 if (argv[i][0] != '-') /* not an option? */ 290 if (argv[i][0] != '-') /* not an option? */
281 return args; /* stop handling options */ 291 return args; /* stop handling options */
@@ -316,7 +326,7 @@ static int collectargs (char **argv, int *first) {
316 return has_error; 326 return has_error;
317 } 327 }
318 } 328 }
319 *first = i; /* no script name */ 329 *first = 0; /* no script name */
320 return args; 330 return args;
321} 331}
322 332
@@ -609,8 +619,8 @@ static int pmain (lua_State *L) {
609 char **argv = (char **)lua_touserdata(L, 2); 619 char **argv = (char **)lua_touserdata(L, 2);
610 int script; 620 int script;
611 int args = collectargs(argv, &script); 621 int args = collectargs(argv, &script);
622 int optlim = (script > 0) ? script : argc; /* first argv not an option */
612 luaL_checkversion(L); /* check that interpreter has correct version */ 623 luaL_checkversion(L); /* check that interpreter has correct version */
613 if (argv[0] && argv[0][0]) progname = argv[0];
614 if (args == has_error) { /* bad arg? */ 624 if (args == has_error) { /* bad arg? */
615 print_usage(argv[script]); /* 'script' has index of bad arg. */ 625 print_usage(argv[script]); /* 'script' has index of bad arg. */
616 return 0; 626 return 0;
@@ -628,14 +638,15 @@ static int pmain (lua_State *L) {
628 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */ 638 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
629 return 0; /* error running LUA_INIT */ 639 return 0; /* error running LUA_INIT */
630 } 640 }
631 if (!runargs(L, argv, script)) /* execute arguments -e and -l */ 641 if (!runargs(L, argv, optlim)) /* execute arguments -e and -l */
632 return 0; /* something failed */ 642 return 0; /* something failed */
633 if (script < argc && /* execute main script (if there is one) */ 643 if (script > 0) { /* execute main script (if there is one) */
634 handle_script(L, argv + script) != LUA_OK) 644 if (handle_script(L, argv + script) != LUA_OK)
635 return 0; 645 return 0; /* interrupt in case of error */
646 }
636 if (args & has_i) /* -i option? */ 647 if (args & has_i) /* -i option? */
637 doREPL(L); /* do read-eval-print loop */ 648 doREPL(L); /* do read-eval-print loop */
638 else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */ 649 else if (script < 1 && !(args & (has_e | has_v))) { /* no active option? */
639 if (lua_stdin_is_tty()) { /* running in interactive mode? */ 650 if (lua_stdin_is_tty()) { /* running in interactive mode? */
640 print_version(); 651 print_version();
641 doREPL(L); /* do read-eval-print loop */ 652 doREPL(L); /* do read-eval-print loop */
diff --git a/src/3rdParty/lua/lua.h b/src/3rdParty/lua/lua.h
index c3dbce1..e661839 100644
--- a/src/3rdParty/lua/lua.h
+++ b/src/3rdParty/lua/lua.h
@@ -25,7 +25,7 @@
25 25
26#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR 26#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
27#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE 27#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
28#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2021 Lua.org, PUC-Rio" 28#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2022 Lua.org, PUC-Rio"
29#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes" 29#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
30 30
31 31
@@ -492,7 +492,7 @@ struct lua_Debug {
492 492
493 493
494/****************************************************************************** 494/******************************************************************************
495* Copyright (C) 1994-2021 Lua.org, PUC-Rio. 495* Copyright (C) 1994-2022 Lua.org, PUC-Rio.
496* 496*
497* Permission is hereby granted, free of charge, to any person obtaining 497* Permission is hereby granted, free of charge, to any person obtaining
498* a copy of this software and associated documentation files (the 498* a copy of this software and associated documentation files (the
diff --git a/src/3rdParty/lua/lvm.c b/src/3rdParty/lua/lvm.c
index 2ec3440..f3a5662 100644
--- a/src/3rdParty/lua/lvm.c
+++ b/src/3rdParty/lua/lvm.c
@@ -898,6 +898,7 @@ void luaV_finishOp (lua_State *L) {
898** operation, 'fop' is the float operation. 898** operation, 'fop' is the float operation.
899*/ 899*/
900#define op_arithI(L,iop,fop) { \ 900#define op_arithI(L,iop,fop) { \
901 StkId ra = RA(i); \
901 TValue *v1 = vRB(i); \ 902 TValue *v1 = vRB(i); \
902 int imm = GETARG_sC(i); \ 903 int imm = GETARG_sC(i); \
903 if (ttisinteger(v1)) { \ 904 if (ttisinteger(v1)) { \
@@ -926,6 +927,7 @@ void luaV_finishOp (lua_State *L) {
926** Arithmetic operations over floats and others with register operands. 927** Arithmetic operations over floats and others with register operands.
927*/ 928*/
928#define op_arithf(L,fop) { \ 929#define op_arithf(L,fop) { \
930 StkId ra = RA(i); \
929 TValue *v1 = vRB(i); \ 931 TValue *v1 = vRB(i); \
930 TValue *v2 = vRC(i); \ 932 TValue *v2 = vRC(i); \
931 op_arithf_aux(L, v1, v2, fop); } 933 op_arithf_aux(L, v1, v2, fop); }
@@ -935,6 +937,7 @@ void luaV_finishOp (lua_State *L) {
935** Arithmetic operations with K operands for floats. 937** Arithmetic operations with K operands for floats.
936*/ 938*/
937#define op_arithfK(L,fop) { \ 939#define op_arithfK(L,fop) { \
940 StkId ra = RA(i); \
938 TValue *v1 = vRB(i); \ 941 TValue *v1 = vRB(i); \
939 TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \ 942 TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \
940 op_arithf_aux(L, v1, v2, fop); } 943 op_arithf_aux(L, v1, v2, fop); }
@@ -944,6 +947,7 @@ void luaV_finishOp (lua_State *L) {
944** Arithmetic operations over integers and floats. 947** Arithmetic operations over integers and floats.
945*/ 948*/
946#define op_arith_aux(L,v1,v2,iop,fop) { \ 949#define op_arith_aux(L,v1,v2,iop,fop) { \
950 StkId ra = RA(i); \
947 if (ttisinteger(v1) && ttisinteger(v2)) { \ 951 if (ttisinteger(v1) && ttisinteger(v2)) { \
948 lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \ 952 lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \
949 pc++; setivalue(s2v(ra), iop(L, i1, i2)); \ 953 pc++; setivalue(s2v(ra), iop(L, i1, i2)); \
@@ -973,6 +977,7 @@ void luaV_finishOp (lua_State *L) {
973** Bitwise operations with constant operand. 977** Bitwise operations with constant operand.
974*/ 978*/
975#define op_bitwiseK(L,op) { \ 979#define op_bitwiseK(L,op) { \
980 StkId ra = RA(i); \
976 TValue *v1 = vRB(i); \ 981 TValue *v1 = vRB(i); \
977 TValue *v2 = KC(i); \ 982 TValue *v2 = KC(i); \
978 lua_Integer i1; \ 983 lua_Integer i1; \
@@ -986,6 +991,7 @@ void luaV_finishOp (lua_State *L) {
986** Bitwise operations with register operands. 991** Bitwise operations with register operands.
987*/ 992*/
988#define op_bitwise(L,op) { \ 993#define op_bitwise(L,op) { \
994 StkId ra = RA(i); \
989 TValue *v1 = vRB(i); \ 995 TValue *v1 = vRB(i); \
990 TValue *v2 = vRC(i); \ 996 TValue *v2 = vRC(i); \
991 lua_Integer i1; lua_Integer i2; \ 997 lua_Integer i1; lua_Integer i2; \
@@ -1000,18 +1006,19 @@ void luaV_finishOp (lua_State *L) {
1000** integers. 1006** integers.
1001*/ 1007*/
1002#define op_order(L,opi,opn,other) { \ 1008#define op_order(L,opi,opn,other) { \
1003 int cond; \ 1009 StkId ra = RA(i); \
1004 TValue *rb = vRB(i); \ 1010 int cond; \
1005 if (ttisinteger(s2v(ra)) && ttisinteger(rb)) { \ 1011 TValue *rb = vRB(i); \
1006 lua_Integer ia = ivalue(s2v(ra)); \ 1012 if (ttisinteger(s2v(ra)) && ttisinteger(rb)) { \
1007 lua_Integer ib = ivalue(rb); \ 1013 lua_Integer ia = ivalue(s2v(ra)); \
1008 cond = opi(ia, ib); \ 1014 lua_Integer ib = ivalue(rb); \
1009 } \ 1015 cond = opi(ia, ib); \
1010 else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \ 1016 } \
1011 cond = opn(s2v(ra), rb); \ 1017 else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \
1012 else \ 1018 cond = opn(s2v(ra), rb); \
1013 Protect(cond = other(L, s2v(ra), rb)); \ 1019 else \
1014 docondjump(); } 1020 Protect(cond = other(L, s2v(ra), rb)); \
1021 docondjump(); }
1015 1022
1016 1023
1017/* 1024/*
@@ -1019,20 +1026,21 @@ void luaV_finishOp (lua_State *L) {
1019** always small enough to have an exact representation as a float.) 1026** always small enough to have an exact representation as a float.)
1020*/ 1027*/
1021#define op_orderI(L,opi,opf,inv,tm) { \ 1028#define op_orderI(L,opi,opf,inv,tm) { \
1022 int cond; \ 1029 StkId ra = RA(i); \
1023 int im = GETARG_sB(i); \ 1030 int cond; \
1024 if (ttisinteger(s2v(ra))) \ 1031 int im = GETARG_sB(i); \
1025 cond = opi(ivalue(s2v(ra)), im); \ 1032 if (ttisinteger(s2v(ra))) \
1026 else if (ttisfloat(s2v(ra))) { \ 1033 cond = opi(ivalue(s2v(ra)), im); \
1027 lua_Number fa = fltvalue(s2v(ra)); \ 1034 else if (ttisfloat(s2v(ra))) { \
1028 lua_Number fim = cast_num(im); \ 1035 lua_Number fa = fltvalue(s2v(ra)); \
1029 cond = opf(fa, fim); \ 1036 lua_Number fim = cast_num(im); \
1030 } \ 1037 cond = opf(fa, fim); \
1031 else { \ 1038 } \
1032 int isf = GETARG_C(i); \ 1039 else { \
1033 Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \ 1040 int isf = GETARG_C(i); \
1034 } \ 1041 Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \
1035 docondjump(); } 1042 } \
1043 docondjump(); }
1036 1044
1037/* }================================================================== */ 1045/* }================================================================== */
1038 1046
@@ -1128,7 +1136,6 @@ void luaV_finishOp (lua_State *L) {
1128 updatebase(ci); /* correct stack */ \ 1136 updatebase(ci); /* correct stack */ \
1129 } \ 1137 } \
1130 i = *(pc++); \ 1138 i = *(pc++); \
1131 ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \
1132} 1139}
1133 1140
1134#define vmdispatch(o) switch(o) 1141#define vmdispatch(o) switch(o)
@@ -1164,7 +1171,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1164 /* main loop of interpreter */ 1171 /* main loop of interpreter */
1165 for (;;) { 1172 for (;;) {
1166 Instruction i; /* instruction being executed */ 1173 Instruction i; /* instruction being executed */
1167 StkId ra; /* instruction's A register */
1168 vmfetch(); 1174 vmfetch();
1169 #if 0 1175 #if 0
1170 /* low-level line tracing for debugging Lua */ 1176 /* low-level line tracing for debugging Lua */
@@ -1176,44 +1182,53 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1176 lua_assert(isIT(i) || (cast_void(L->top = base), 1)); 1182 lua_assert(isIT(i) || (cast_void(L->top = base), 1));
1177 vmdispatch (GET_OPCODE(i)) { 1183 vmdispatch (GET_OPCODE(i)) {
1178 vmcase(OP_MOVE) { 1184 vmcase(OP_MOVE) {
1185 StkId ra = RA(i);
1179 setobjs2s(L, ra, RB(i)); 1186 setobjs2s(L, ra, RB(i));
1180 vmbreak; 1187 vmbreak;
1181 } 1188 }
1182 vmcase(OP_LOADI) { 1189 vmcase(OP_LOADI) {
1190 StkId ra = RA(i);
1183 lua_Integer b = GETARG_sBx(i); 1191 lua_Integer b = GETARG_sBx(i);
1184 setivalue(s2v(ra), b); 1192 setivalue(s2v(ra), b);
1185 vmbreak; 1193 vmbreak;
1186 } 1194 }
1187 vmcase(OP_LOADF) { 1195 vmcase(OP_LOADF) {
1196 StkId ra = RA(i);
1188 int b = GETARG_sBx(i); 1197 int b = GETARG_sBx(i);
1189 setfltvalue(s2v(ra), cast_num(b)); 1198 setfltvalue(s2v(ra), cast_num(b));
1190 vmbreak; 1199 vmbreak;
1191 } 1200 }
1192 vmcase(OP_LOADK) { 1201 vmcase(OP_LOADK) {
1202 StkId ra = RA(i);
1193 TValue *rb = k + GETARG_Bx(i); 1203 TValue *rb = k + GETARG_Bx(i);
1194 setobj2s(L, ra, rb); 1204 setobj2s(L, ra, rb);
1195 vmbreak; 1205 vmbreak;
1196 } 1206 }
1197 vmcase(OP_LOADKX) { 1207 vmcase(OP_LOADKX) {
1208 StkId ra = RA(i);
1198 TValue *rb; 1209 TValue *rb;
1199 rb = k + GETARG_Ax(*pc); pc++; 1210 rb = k + GETARG_Ax(*pc); pc++;
1200 setobj2s(L, ra, rb); 1211 setobj2s(L, ra, rb);
1201 vmbreak; 1212 vmbreak;
1202 } 1213 }
1203 vmcase(OP_LOADFALSE) { 1214 vmcase(OP_LOADFALSE) {
1215 StkId ra = RA(i);
1204 setbfvalue(s2v(ra)); 1216 setbfvalue(s2v(ra));
1205 vmbreak; 1217 vmbreak;
1206 } 1218 }
1207 vmcase(OP_LFALSESKIP) { 1219 vmcase(OP_LFALSESKIP) {
1220 StkId ra = RA(i);
1208 setbfvalue(s2v(ra)); 1221 setbfvalue(s2v(ra));
1209 pc++; /* skip next instruction */ 1222 pc++; /* skip next instruction */
1210 vmbreak; 1223 vmbreak;
1211 } 1224 }
1212 vmcase(OP_LOADTRUE) { 1225 vmcase(OP_LOADTRUE) {
1226 StkId ra = RA(i);
1213 setbtvalue(s2v(ra)); 1227 setbtvalue(s2v(ra));
1214 vmbreak; 1228 vmbreak;
1215 } 1229 }
1216 vmcase(OP_LOADNIL) { 1230 vmcase(OP_LOADNIL) {
1231 StkId ra = RA(i);
1217 int b = GETARG_B(i); 1232 int b = GETARG_B(i);
1218 do { 1233 do {
1219 setnilvalue(s2v(ra++)); 1234 setnilvalue(s2v(ra++));
@@ -1221,17 +1236,20 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1221 vmbreak; 1236 vmbreak;
1222 } 1237 }
1223 vmcase(OP_GETUPVAL) { 1238 vmcase(OP_GETUPVAL) {
1239 StkId ra = RA(i);
1224 int b = GETARG_B(i); 1240 int b = GETARG_B(i);
1225 setobj2s(L, ra, cl->upvals[b]->v); 1241 setobj2s(L, ra, cl->upvals[b]->v);
1226 vmbreak; 1242 vmbreak;
1227 } 1243 }
1228 vmcase(OP_SETUPVAL) { 1244 vmcase(OP_SETUPVAL) {
1245 StkId ra = RA(i);
1229 UpVal *uv = cl->upvals[GETARG_B(i)]; 1246 UpVal *uv = cl->upvals[GETARG_B(i)];
1230 setobj(L, uv->v, s2v(ra)); 1247 setobj(L, uv->v, s2v(ra));
1231 luaC_barrier(L, uv, s2v(ra)); 1248 luaC_barrier(L, uv, s2v(ra));
1232 vmbreak; 1249 vmbreak;
1233 } 1250 }
1234 vmcase(OP_GETTABUP) { 1251 vmcase(OP_GETTABUP) {
1252 StkId ra = RA(i);
1235 const TValue *slot; 1253 const TValue *slot;
1236 TValue *upval = cl->upvals[GETARG_B(i)]->v; 1254 TValue *upval = cl->upvals[GETARG_B(i)]->v;
1237 TValue *rc = KC(i); 1255 TValue *rc = KC(i);
@@ -1244,6 +1262,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1244 vmbreak; 1262 vmbreak;
1245 } 1263 }
1246 vmcase(OP_GETTABLE) { 1264 vmcase(OP_GETTABLE) {
1265 StkId ra = RA(i);
1247 const TValue *slot; 1266 const TValue *slot;
1248 TValue *rb = vRB(i); 1267 TValue *rb = vRB(i);
1249 TValue *rc = vRC(i); 1268 TValue *rc = vRC(i);
@@ -1258,6 +1277,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1258 vmbreak; 1277 vmbreak;
1259 } 1278 }
1260 vmcase(OP_GETI) { 1279 vmcase(OP_GETI) {
1280 StkId ra = RA(i);
1261 const TValue *slot; 1281 const TValue *slot;
1262 TValue *rb = vRB(i); 1282 TValue *rb = vRB(i);
1263 int c = GETARG_C(i); 1283 int c = GETARG_C(i);
@@ -1272,6 +1292,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1272 vmbreak; 1292 vmbreak;
1273 } 1293 }
1274 vmcase(OP_GETFIELD) { 1294 vmcase(OP_GETFIELD) {
1295 StkId ra = RA(i);
1275 const TValue *slot; 1296 const TValue *slot;
1276 TValue *rb = vRB(i); 1297 TValue *rb = vRB(i);
1277 TValue *rc = KC(i); 1298 TValue *rc = KC(i);
@@ -1297,6 +1318,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1297 vmbreak; 1318 vmbreak;
1298 } 1319 }
1299 vmcase(OP_SETTABLE) { 1320 vmcase(OP_SETTABLE) {
1321 StkId ra = RA(i);
1300 const TValue *slot; 1322 const TValue *slot;
1301 TValue *rb = vRB(i); /* key (table is in 'ra') */ 1323 TValue *rb = vRB(i); /* key (table is in 'ra') */
1302 TValue *rc = RKC(i); /* value */ 1324 TValue *rc = RKC(i); /* value */
@@ -1311,6 +1333,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1311 vmbreak; 1333 vmbreak;
1312 } 1334 }
1313 vmcase(OP_SETI) { 1335 vmcase(OP_SETI) {
1336 StkId ra = RA(i);
1314 const TValue *slot; 1337 const TValue *slot;
1315 int c = GETARG_B(i); 1338 int c = GETARG_B(i);
1316 TValue *rc = RKC(i); 1339 TValue *rc = RKC(i);
@@ -1325,6 +1348,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1325 vmbreak; 1348 vmbreak;
1326 } 1349 }
1327 vmcase(OP_SETFIELD) { 1350 vmcase(OP_SETFIELD) {
1351 StkId ra = RA(i);
1328 const TValue *slot; 1352 const TValue *slot;
1329 TValue *rb = KB(i); 1353 TValue *rb = KB(i);
1330 TValue *rc = RKC(i); 1354 TValue *rc = RKC(i);
@@ -1337,6 +1361,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1337 vmbreak; 1361 vmbreak;
1338 } 1362 }
1339 vmcase(OP_NEWTABLE) { 1363 vmcase(OP_NEWTABLE) {
1364 StkId ra = RA(i);
1340 int b = GETARG_B(i); /* log2(hash size) + 1 */ 1365 int b = GETARG_B(i); /* log2(hash size) + 1 */
1341 int c = GETARG_C(i); /* array size */ 1366 int c = GETARG_C(i); /* array size */
1342 Table *t; 1367 Table *t;
@@ -1355,6 +1380,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1355 vmbreak; 1380 vmbreak;
1356 } 1381 }
1357 vmcase(OP_SELF) { 1382 vmcase(OP_SELF) {
1383 StkId ra = RA(i);
1358 const TValue *slot; 1384 const TValue *slot;
1359 TValue *rb = vRB(i); 1385 TValue *rb = vRB(i);
1360 TValue *rc = RKC(i); 1386 TValue *rc = RKC(i);
@@ -1412,6 +1438,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1412 vmbreak; 1438 vmbreak;
1413 } 1439 }
1414 vmcase(OP_SHRI) { 1440 vmcase(OP_SHRI) {
1441 StkId ra = RA(i);
1415 TValue *rb = vRB(i); 1442 TValue *rb = vRB(i);
1416 int ic = GETARG_sC(i); 1443 int ic = GETARG_sC(i);
1417 lua_Integer ib; 1444 lua_Integer ib;
@@ -1421,6 +1448,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1421 vmbreak; 1448 vmbreak;
1422 } 1449 }
1423 vmcase(OP_SHLI) { 1450 vmcase(OP_SHLI) {
1451 StkId ra = RA(i);
1424 TValue *rb = vRB(i); 1452 TValue *rb = vRB(i);
1425 int ic = GETARG_sC(i); 1453 int ic = GETARG_sC(i);
1426 lua_Integer ib; 1454 lua_Integer ib;
@@ -1478,6 +1506,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1478 vmbreak; 1506 vmbreak;
1479 } 1507 }
1480 vmcase(OP_MMBIN) { 1508 vmcase(OP_MMBIN) {
1509 StkId ra = RA(i);
1481 Instruction pi = *(pc - 2); /* original arith. expression */ 1510 Instruction pi = *(pc - 2); /* original arith. expression */
1482 TValue *rb = vRB(i); 1511 TValue *rb = vRB(i);
1483 TMS tm = (TMS)GETARG_C(i); 1512 TMS tm = (TMS)GETARG_C(i);
@@ -1487,6 +1516,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1487 vmbreak; 1516 vmbreak;
1488 } 1517 }
1489 vmcase(OP_MMBINI) { 1518 vmcase(OP_MMBINI) {
1519 StkId ra = RA(i);
1490 Instruction pi = *(pc - 2); /* original arith. expression */ 1520 Instruction pi = *(pc - 2); /* original arith. expression */
1491 int imm = GETARG_sB(i); 1521 int imm = GETARG_sB(i);
1492 TMS tm = (TMS)GETARG_C(i); 1522 TMS tm = (TMS)GETARG_C(i);
@@ -1496,6 +1526,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1496 vmbreak; 1526 vmbreak;
1497 } 1527 }
1498 vmcase(OP_MMBINK) { 1528 vmcase(OP_MMBINK) {
1529 StkId ra = RA(i);
1499 Instruction pi = *(pc - 2); /* original arith. expression */ 1530 Instruction pi = *(pc - 2); /* original arith. expression */
1500 TValue *imm = KB(i); 1531 TValue *imm = KB(i);
1501 TMS tm = (TMS)GETARG_C(i); 1532 TMS tm = (TMS)GETARG_C(i);
@@ -1505,6 +1536,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1505 vmbreak; 1536 vmbreak;
1506 } 1537 }
1507 vmcase(OP_UNM) { 1538 vmcase(OP_UNM) {
1539 StkId ra = RA(i);
1508 TValue *rb = vRB(i); 1540 TValue *rb = vRB(i);
1509 lua_Number nb; 1541 lua_Number nb;
1510 if (ttisinteger(rb)) { 1542 if (ttisinteger(rb)) {
@@ -1519,6 +1551,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1519 vmbreak; 1551 vmbreak;
1520 } 1552 }
1521 vmcase(OP_BNOT) { 1553 vmcase(OP_BNOT) {
1554 StkId ra = RA(i);
1522 TValue *rb = vRB(i); 1555 TValue *rb = vRB(i);
1523 lua_Integer ib; 1556 lua_Integer ib;
1524 if (tointegerns(rb, &ib)) { 1557 if (tointegerns(rb, &ib)) {
@@ -1529,6 +1562,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1529 vmbreak; 1562 vmbreak;
1530 } 1563 }
1531 vmcase(OP_NOT) { 1564 vmcase(OP_NOT) {
1565 StkId ra = RA(i);
1532 TValue *rb = vRB(i); 1566 TValue *rb = vRB(i);
1533 if (l_isfalse(rb)) 1567 if (l_isfalse(rb))
1534 setbtvalue(s2v(ra)); 1568 setbtvalue(s2v(ra));
@@ -1537,10 +1571,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1537 vmbreak; 1571 vmbreak;
1538 } 1572 }
1539 vmcase(OP_LEN) { 1573 vmcase(OP_LEN) {
1574 StkId ra = RA(i);
1540 Protect(luaV_objlen(L, ra, vRB(i))); 1575 Protect(luaV_objlen(L, ra, vRB(i)));
1541 vmbreak; 1576 vmbreak;
1542 } 1577 }
1543 vmcase(OP_CONCAT) { 1578 vmcase(OP_CONCAT) {
1579 StkId ra = RA(i);
1544 int n = GETARG_B(i); /* number of elements to concatenate */ 1580 int n = GETARG_B(i); /* number of elements to concatenate */
1545 L->top = ra + n; /* mark the end of concat operands */ 1581 L->top = ra + n; /* mark the end of concat operands */
1546 ProtectNT(luaV_concat(L, n)); 1582 ProtectNT(luaV_concat(L, n));
@@ -1548,10 +1584,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1548 vmbreak; 1584 vmbreak;
1549 } 1585 }
1550 vmcase(OP_CLOSE) { 1586 vmcase(OP_CLOSE) {
1587 StkId ra = RA(i);
1551 Protect(luaF_close(L, ra, LUA_OK, 1)); 1588 Protect(luaF_close(L, ra, LUA_OK, 1));
1552 vmbreak; 1589 vmbreak;
1553 } 1590 }
1554 vmcase(OP_TBC) { 1591 vmcase(OP_TBC) {
1592 StkId ra = RA(i);
1555 /* create new to-be-closed upvalue */ 1593 /* create new to-be-closed upvalue */
1556 halfProtect(luaF_newtbcupval(L, ra)); 1594 halfProtect(luaF_newtbcupval(L, ra));
1557 vmbreak; 1595 vmbreak;
@@ -1561,6 +1599,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1561 vmbreak; 1599 vmbreak;
1562 } 1600 }
1563 vmcase(OP_EQ) { 1601 vmcase(OP_EQ) {
1602 StkId ra = RA(i);
1564 int cond; 1603 int cond;
1565 TValue *rb = vRB(i); 1604 TValue *rb = vRB(i);
1566 Protect(cond = luaV_equalobj(L, s2v(ra), rb)); 1605 Protect(cond = luaV_equalobj(L, s2v(ra), rb));
@@ -1576,6 +1615,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1576 vmbreak; 1615 vmbreak;
1577 } 1616 }
1578 vmcase(OP_EQK) { 1617 vmcase(OP_EQK) {
1618 StkId ra = RA(i);
1579 TValue *rb = KB(i); 1619 TValue *rb = KB(i);
1580 /* basic types do not use '__eq'; we can use raw equality */ 1620 /* basic types do not use '__eq'; we can use raw equality */
1581 int cond = luaV_rawequalobj(s2v(ra), rb); 1621 int cond = luaV_rawequalobj(s2v(ra), rb);
@@ -1583,6 +1623,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1583 vmbreak; 1623 vmbreak;
1584 } 1624 }
1585 vmcase(OP_EQI) { 1625 vmcase(OP_EQI) {
1626 StkId ra = RA(i);
1586 int cond; 1627 int cond;
1587 int im = GETARG_sB(i); 1628 int im = GETARG_sB(i);
1588 if (ttisinteger(s2v(ra))) 1629 if (ttisinteger(s2v(ra)))
@@ -1611,11 +1652,13 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1611 vmbreak; 1652 vmbreak;
1612 } 1653 }
1613 vmcase(OP_TEST) { 1654 vmcase(OP_TEST) {
1655 StkId ra = RA(i);
1614 int cond = !l_isfalse(s2v(ra)); 1656 int cond = !l_isfalse(s2v(ra));
1615 docondjump(); 1657 docondjump();
1616 vmbreak; 1658 vmbreak;
1617 } 1659 }
1618 vmcase(OP_TESTSET) { 1660 vmcase(OP_TESTSET) {
1661 StkId ra = RA(i);
1619 TValue *rb = vRB(i); 1662 TValue *rb = vRB(i);
1620 if (l_isfalse(rb) == GETARG_k(i)) 1663 if (l_isfalse(rb) == GETARG_k(i))
1621 pc++; 1664 pc++;
@@ -1626,6 +1669,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1626 vmbreak; 1669 vmbreak;
1627 } 1670 }
1628 vmcase(OP_CALL) { 1671 vmcase(OP_CALL) {
1672 StkId ra = RA(i);
1629 CallInfo *newci; 1673 CallInfo *newci;
1630 int b = GETARG_B(i); 1674 int b = GETARG_B(i);
1631 int nresults = GETARG_C(i) - 1; 1675 int nresults = GETARG_C(i) - 1;
@@ -1642,6 +1686,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1642 vmbreak; 1686 vmbreak;
1643 } 1687 }
1644 vmcase(OP_TAILCALL) { 1688 vmcase(OP_TAILCALL) {
1689 StkId ra = RA(i);
1645 int b = GETARG_B(i); /* number of arguments + 1 (function) */ 1690 int b = GETARG_B(i); /* number of arguments + 1 (function) */
1646 int n; /* number of results when calling a C function */ 1691 int n; /* number of results when calling a C function */
1647 int nparams1 = GETARG_C(i); 1692 int nparams1 = GETARG_C(i);
@@ -1667,6 +1712,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1667 } 1712 }
1668 } 1713 }
1669 vmcase(OP_RETURN) { 1714 vmcase(OP_RETURN) {
1715 StkId ra = RA(i);
1670 int n = GETARG_B(i) - 1; /* number of results */ 1716 int n = GETARG_B(i) - 1; /* number of results */
1671 int nparams1 = GETARG_C(i); 1717 int nparams1 = GETARG_C(i);
1672 if (n < 0) /* not fixed? */ 1718 if (n < 0) /* not fixed? */
@@ -1689,6 +1735,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1689 } 1735 }
1690 vmcase(OP_RETURN0) { 1736 vmcase(OP_RETURN0) {
1691 if (l_unlikely(L->hookmask)) { 1737 if (l_unlikely(L->hookmask)) {
1738 StkId ra = RA(i);
1692 L->top = ra; 1739 L->top = ra;
1693 savepc(ci); 1740 savepc(ci);
1694 luaD_poscall(L, ci, 0); /* no hurry... */ 1741 luaD_poscall(L, ci, 0); /* no hurry... */
@@ -1705,6 +1752,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1705 } 1752 }
1706 vmcase(OP_RETURN1) { 1753 vmcase(OP_RETURN1) {
1707 if (l_unlikely(L->hookmask)) { 1754 if (l_unlikely(L->hookmask)) {
1755 StkId ra = RA(i);
1708 L->top = ra + 1; 1756 L->top = ra + 1;
1709 savepc(ci); 1757 savepc(ci);
1710 luaD_poscall(L, ci, 1); /* no hurry... */ 1758 luaD_poscall(L, ci, 1); /* no hurry... */
@@ -1716,6 +1764,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1716 if (nres == 0) 1764 if (nres == 0)
1717 L->top = base - 1; /* asked for no results */ 1765 L->top = base - 1; /* asked for no results */
1718 else { 1766 else {
1767 StkId ra = RA(i);
1719 setobjs2s(L, base - 1, ra); /* at least this result */ 1768 setobjs2s(L, base - 1, ra); /* at least this result */
1720 L->top = base; 1769 L->top = base;
1721 for (; l_unlikely(nres > 1); nres--) 1770 for (; l_unlikely(nres > 1); nres--)
@@ -1731,6 +1780,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1731 } 1780 }
1732 } 1781 }
1733 vmcase(OP_FORLOOP) { 1782 vmcase(OP_FORLOOP) {
1783 StkId ra = RA(i);
1734 if (ttisinteger(s2v(ra + 2))) { /* integer loop? */ 1784 if (ttisinteger(s2v(ra + 2))) { /* integer loop? */
1735 lua_Unsigned count = l_castS2U(ivalue(s2v(ra + 1))); 1785 lua_Unsigned count = l_castS2U(ivalue(s2v(ra + 1)));
1736 if (count > 0) { /* still more iterations? */ 1786 if (count > 0) { /* still more iterations? */
@@ -1749,12 +1799,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1749 vmbreak; 1799 vmbreak;
1750 } 1800 }
1751 vmcase(OP_FORPREP) { 1801 vmcase(OP_FORPREP) {
1802 StkId ra = RA(i);
1752 savestate(L, ci); /* in case of errors */ 1803 savestate(L, ci); /* in case of errors */
1753 if (forprep(L, ra)) 1804 if (forprep(L, ra))
1754 pc += GETARG_Bx(i) + 1; /* skip the loop */ 1805 pc += GETARG_Bx(i) + 1; /* skip the loop */
1755 vmbreak; 1806 vmbreak;
1756 } 1807 }
1757 vmcase(OP_TFORPREP) { 1808 vmcase(OP_TFORPREP) {
1809 StkId ra = RA(i);
1758 /* create to-be-closed upvalue (if needed) */ 1810 /* create to-be-closed upvalue (if needed) */
1759 halfProtect(luaF_newtbcupval(L, ra + 3)); 1811 halfProtect(luaF_newtbcupval(L, ra + 3));
1760 pc += GETARG_Bx(i); 1812 pc += GETARG_Bx(i);
@@ -1763,7 +1815,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1763 goto l_tforcall; 1815 goto l_tforcall;
1764 } 1816 }
1765 vmcase(OP_TFORCALL) { 1817 vmcase(OP_TFORCALL) {
1766 l_tforcall: 1818 l_tforcall: {
1819 StkId ra = RA(i);
1767 /* 'ra' has the iterator function, 'ra + 1' has the state, 1820 /* 'ra' has the iterator function, 'ra + 1' has the state,
1768 'ra + 2' has the control variable, and 'ra + 3' has the 1821 'ra + 2' has the control variable, and 'ra + 3' has the
1769 to-be-closed variable. The call will use the stack after 1822 to-be-closed variable. The call will use the stack after
@@ -1777,16 +1830,18 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1777 i = *(pc++); /* go to next instruction */ 1830 i = *(pc++); /* go to next instruction */
1778 lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i)); 1831 lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i));
1779 goto l_tforloop; 1832 goto l_tforloop;
1780 } 1833 }}
1781 vmcase(OP_TFORLOOP) { 1834 vmcase(OP_TFORLOOP) {
1782 l_tforloop: 1835 l_tforloop: {
1836 StkId ra = RA(i);
1783 if (!ttisnil(s2v(ra + 4))) { /* continue loop? */ 1837 if (!ttisnil(s2v(ra + 4))) { /* continue loop? */
1784 setobjs2s(L, ra + 2, ra + 4); /* save control variable */ 1838 setobjs2s(L, ra + 2, ra + 4); /* save control variable */
1785 pc -= GETARG_Bx(i); /* jump back */ 1839 pc -= GETARG_Bx(i); /* jump back */
1786 } 1840 }
1787 vmbreak; 1841 vmbreak;
1788 } 1842 }}
1789 vmcase(OP_SETLIST) { 1843 vmcase(OP_SETLIST) {
1844 StkId ra = RA(i);
1790 int n = GETARG_B(i); 1845 int n = GETARG_B(i);
1791 unsigned int last = GETARG_C(i); 1846 unsigned int last = GETARG_C(i);
1792 Table *h = hvalue(s2v(ra)); 1847 Table *h = hvalue(s2v(ra));
@@ -1810,12 +1865,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1810 vmbreak; 1865 vmbreak;
1811 } 1866 }
1812 vmcase(OP_CLOSURE) { 1867 vmcase(OP_CLOSURE) {
1868 StkId ra = RA(i);
1813 Proto *p = cl->p->p[GETARG_Bx(i)]; 1869 Proto *p = cl->p->p[GETARG_Bx(i)];
1814 halfProtect(pushclosure(L, p, cl->upvals, base, ra)); 1870 halfProtect(pushclosure(L, p, cl->upvals, base, ra));
1815 checkGC(L, ra + 1); 1871 checkGC(L, ra + 1);
1816 vmbreak; 1872 vmbreak;
1817 } 1873 }
1818 vmcase(OP_VARARG) { 1874 vmcase(OP_VARARG) {
1875 StkId ra = RA(i);
1819 int n = GETARG_C(i) - 1; /* required results */ 1876 int n = GETARG_C(i) - 1; /* required results */
1820 Protect(luaT_getvarargs(L, ci, ra, n)); 1877 Protect(luaT_getvarargs(L, ci, ra, n));
1821 vmbreak; 1878 vmbreak;
diff --git a/src/yuescript/yuescript.cpp b/src/yuescript/yuescript.cpp
index 37cc605..5e21fc5 100644
--- a/src/yuescript/yuescript.cpp
+++ b/src/yuescript/yuescript.cpp
@@ -7,6 +7,12 @@ The above copyright notice and this permission notice shall be included in all c
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8#include "yuescript/yue_compiler.h" 8#include "yuescript/yue_compiler.h"
9 9
10#if defined(YUE_BUILD_AS_DLL)
11#define YUE_API __declspec(dllexport)
12#else
13#define YUE_API
14#endif
15
10extern "C" { 16extern "C" {
11 17
12#include "lua.h" 18#include "lua.h"
@@ -132,7 +138,7 @@ static const luaL_Reg yuelib[] = {
132 {nullptr, nullptr} 138 {nullptr, nullptr}
133}; 139};
134 140
135int luaopen_yue(lua_State* L) { 141YUE_API int luaopen_yue(lua_State* L) {
136#if LUA_VERSION_NUM > 501 142#if LUA_VERSION_NUM > 501
137 luaL_newlib(L, yuelib); // yue 143 luaL_newlib(L, yuelib); // yue
138#else 144#else