summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-11-02 11:17:58 +0800
committerLi Jin <dragon-fly@qq.com>2021-11-02 11:17:58 +0800
commit827c3736f357e09168fc108e8e740c6425d37d9b (patch)
tree259f977bf7f4ebe0e397fe5e1b74e7fbb1b75e8e
parentaed806476fe50899c0f01750175531ac41267b9d (diff)
downloadyuescript-827c3736f357e09168fc108e8e740c6425d37d9b.tar.gz
yuescript-827c3736f357e09168fc108e8e740c6425d37d9b.tar.bz2
yuescript-827c3736f357e09168fc108e8e740c6425d37d9b.zip
fix a wrong code generating issue, update builtin Lua.
-rw-r--r--spec/inputs/nil_coalesing.yue3
-rw-r--r--spec/outputs/nil_coalesing.lua18
-rw-r--r--src/3rdParty/lua/lapi.c12
-rw-r--r--src/3rdParty/lua/lauxlib.h8
-rw-r--r--src/3rdParty/lua/lbaselib.c3
-rw-r--r--src/3rdParty/lua/ldebug.c2
-rw-r--r--src/3rdParty/lua/ldo.c77
-rw-r--r--src/3rdParty/lua/ldo.h17
-rw-r--r--src/3rdParty/lua/llimits.h14
-rw-r--r--src/3rdParty/lua/lobject.h2
-rw-r--r--src/3rdParty/lua/lstrlib.c112
-rw-r--r--src/3rdParty/lua/ltable.c18
-rw-r--r--src/3rdParty/lua/ltablib.c3
-rw-r--r--src/3rdParty/lua/lua.c37
-rw-r--r--src/3rdParty/lua/lutf8lib.c11
-rw-r--r--src/3rdParty/lua/lvm.c36
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp3
17 files changed, 245 insertions, 131 deletions
diff --git a/spec/inputs/nil_coalesing.yue b/spec/inputs/nil_coalesing.yue
index 45b34f4..facd64c 100644
--- a/spec/inputs/nil_coalesing.yue
+++ b/spec/inputs/nil_coalesing.yue
@@ -36,5 +36,8 @@ do
36 a or= 1 36 a or= 1
37 b ??= c ?? 2 37 b ??= c ?? 2
38 38
39do
40 a = 1 ?? 2 ?? 3
41
39nil 42nil
40 43
diff --git a/spec/outputs/nil_coalesing.lua b/spec/outputs/nil_coalesing.lua
index 36a6644..b434671 100644
--- a/spec/outputs/nil_coalesing.lua
+++ b/spec/outputs/nil_coalesing.lua
@@ -135,4 +135,22 @@ do
135 end 135 end
136 end 136 end
137end 137end
138do
139 local a
140 do
141 local _exp_0 = 1
142 if _exp_0 ~= nil then
143 a = _exp_0
144 else
145 do
146 local _exp_1 = 2
147 if _exp_1 ~= nil then
148 a = _exp_1
149 else
150 a = 3
151 end
152 end
153 end
154 end
155end
138return nil 156return nil
diff --git a/src/3rdParty/lua/lapi.c b/src/3rdParty/lua/lapi.c
index 3467891..071a06f 100644
--- a/src/3rdParty/lua/lapi.c
+++ b/src/3rdParty/lua/lapi.c
@@ -86,10 +86,12 @@ static TValue *index2value (lua_State *L, int idx) {
86 } 86 }
87} 87}
88 88
89
90
89/* 91/*
90** Convert a valid actual index (not a pseudo-index) to its address. 92** Convert a valid actual index (not a pseudo-index) to its address.
91*/ 93*/
92static StkId index2stack (lua_State *L, int idx) { 94l_sinline StkId index2stack (lua_State *L, int idx) {
93 CallInfo *ci = L->ci; 95 CallInfo *ci = L->ci;
94 if (idx > 0) { 96 if (idx > 0) {
95 StkId o = ci->func + idx; 97 StkId o = ci->func + idx;
@@ -226,7 +228,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) {
226** Note that we move(copy) only the value inside the stack. 228** Note that we move(copy) only the value inside the stack.
227** (We do not move additional fields that may exist.) 229** (We do not move additional fields that may exist.)
228*/ 230*/
229static void reverse (lua_State *L, StkId from, StkId to) { 231l_sinline void reverse (lua_State *L, StkId from, StkId to) {
230 for (; from < to; from++, to--) { 232 for (; from < to; from++, to--) {
231 TValue temp; 233 TValue temp;
232 setobj(L, &temp, s2v(from)); 234 setobj(L, &temp, s2v(from));
@@ -446,7 +448,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
446} 448}
447 449
448 450
449static void *touserdata (const TValue *o) { 451l_sinline void *touserdata (const TValue *o) {
450 switch (ttype(o)) { 452 switch (ttype(o)) {
451 case LUA_TUSERDATA: return getudatamem(uvalue(o)); 453 case LUA_TUSERDATA: return getudatamem(uvalue(o));
452 case LUA_TLIGHTUSERDATA: return pvalue(o); 454 case LUA_TLIGHTUSERDATA: return pvalue(o);
@@ -638,7 +640,7 @@ LUA_API int lua_pushthread (lua_State *L) {
638*/ 640*/
639 641
640 642
641static int auxgetstr (lua_State *L, const TValue *t, const char *k) { 643l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) {
642 const TValue *slot; 644 const TValue *slot;
643 TString *str = luaS_new(L, k); 645 TString *str = luaS_new(L, k);
644 if (luaV_fastget(L, t, str, slot, luaH_getstr)) { 646 if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
@@ -713,7 +715,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
713} 715}
714 716
715 717
716static int finishrawget (lua_State *L, const TValue *val) { 718l_sinline int finishrawget (lua_State *L, const TValue *val) {
717 if (isempty(val)) /* avoid copying empty items to the stack */ 719 if (isempty(val)) /* avoid copying empty items to the stack */
718 setnilvalue(s2v(L->top)); 720 setnilvalue(s2v(L->top));
719 else 721 else
diff --git a/src/3rdParty/lua/lauxlib.h b/src/3rdParty/lua/lauxlib.h
index 72f70e7..6f9695e 100644
--- a/src/3rdParty/lua/lauxlib.h
+++ b/src/3rdParty/lua/lauxlib.h
@@ -154,6 +154,14 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
154#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) 154#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
155 155
156 156
157/*
158** Perform arithmetic operations on lua_Integer values with wrap-around
159** semantics, as the Lua core does.
160*/
161#define luaL_intop(op,v1,v2) \
162 ((lua_Integer)((lua_Unsigned)(v1) op (lua_Unsigned)(v2)))
163
164
157/* push the value used to represent failure/error */ 165/* push the value used to represent failure/error */
158#define luaL_pushfail(L) lua_pushnil(L) 166#define luaL_pushfail(L) lua_pushnil(L)
159 167
diff --git a/src/3rdParty/lua/lbaselib.c b/src/3rdParty/lua/lbaselib.c
index fd6687e..912c4cc 100644
--- a/src/3rdParty/lua/lbaselib.c
+++ b/src/3rdParty/lua/lbaselib.c
@@ -285,7 +285,8 @@ static int luaB_pairs (lua_State *L) {
285** Traversal function for 'ipairs' 285** Traversal function for 'ipairs'
286*/ 286*/
287static int ipairsaux (lua_State *L) { 287static int ipairsaux (lua_State *L) {
288 lua_Integer i = luaL_checkinteger(L, 2) + 1; 288 lua_Integer i = luaL_checkinteger(L, 2);
289 i = luaL_intop(+, i, 1);
289 lua_pushinteger(L, i); 290 lua_pushinteger(L, i);
290 return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2; 291 return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;
291} 292}
diff --git a/src/3rdParty/lua/ldebug.c b/src/3rdParty/lua/ldebug.c
index 433a875..dde4669 100644
--- a/src/3rdParty/lua/ldebug.c
+++ b/src/3rdParty/lua/ldebug.c
@@ -64,7 +64,7 @@ static int getbaseline (const Proto *f, int pc, int *basepc) {
64 } 64 }
65 else { 65 else {
66 int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */ 66 int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */
67 /* estimate must be a lower bond of the correct base */ 67 /* estimate must be a lower bound of the correct base */
68 lua_assert(i < 0 || 68 lua_assert(i < 0 ||
69 (i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc)); 69 (i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc));
70 while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc) 70 while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc)
diff --git a/src/3rdParty/lua/ldo.c b/src/3rdParty/lua/ldo.c
index 93fcbb1..88b20f9 100644
--- a/src/3rdParty/lua/ldo.c
+++ b/src/3rdParty/lua/ldo.c
@@ -387,15 +387,17 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) {
387** stack, below original 'func', so that 'luaD_precall' can call it. Raise 387** stack, below original 'func', so that 'luaD_precall' can call it. Raise
388** an error if there is no '__call' metafield. 388** an error if there is no '__call' metafield.
389*/ 389*/
390void luaD_tryfuncTM (lua_State *L, StkId func) { 390StkId luaD_tryfuncTM (lua_State *L, StkId func) {
391 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); 391 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL);
392 StkId p; 392 StkId p;
393 checkstackGCp(L, 1, func); /* space for metamethod */
393 if (l_unlikely(ttisnil(tm))) 394 if (l_unlikely(ttisnil(tm)))
394 luaG_callerror(L, s2v(func)); /* nothing to call */ 395 luaG_callerror(L, s2v(func)); /* nothing to call */
395 for (p = L->top; p > func; p--) /* open space for metamethod */ 396 for (p = L->top; p > func; p--) /* open space for metamethod */
396 setobjs2s(L, p, p-1); 397 setobjs2s(L, p, p-1);
397 L->top++; /* stack space pre-allocated by the caller */ 398 L->top++; /* stack space pre-allocated by the caller */
398 setobj2s(L, func, tm); /* metamethod is the new function to be called */ 399 setobj2s(L, func, tm); /* metamethod is the new function to be called */
400 return func;
399} 401}
400 402
401 403
@@ -405,7 +407,7 @@ void luaD_tryfuncTM (lua_State *L, StkId func) {
405** expressions, multiple results for tail calls/single parameters) 407** expressions, multiple results for tail calls/single parameters)
406** separated. 408** separated.
407*/ 409*/
408static void moveresults (lua_State *L, StkId res, int nres, int wanted) { 410l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) {
409 StkId firstresult; 411 StkId firstresult;
410 int i; 412 int i;
411 switch (wanted) { /* handle typical cases separately */ 413 switch (wanted) { /* handle typical cases separately */
@@ -474,33 +476,36 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
474 476
475 477
476/* 478/*
477** In a tail call, move function and parameters to previous call frame. 479** Prepare a function for a tail call, building its call info on top
478** (This is done only when no more errors can occur before entering the 480** of the current call info. 'narg1' is the number of arguments plus 1
479** new function, to keep debug information always consistent.) 481** (so that it includes the function itself).
480*/ 482*/
481static void moveparams (lua_State *L, StkId prevf, StkId func) { 483void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) {
484 Proto *p = clLvalue(s2v(func))->p;
485 int fsize = p->maxstacksize; /* frame size */
486 int nfixparams = p->numparams;
482 int i; 487 int i;
483 for (i = 0; func + i < L->top; i++) /* move down function and arguments */ 488 for (i = 0; i < narg1; i++) /* move down function and arguments */
484 setobjs2s(L, prevf + i, func + i); 489 setobjs2s(L, ci->func + i, func + i);
485 L->top = prevf + i; /* correct top */ 490 checkstackGC(L, fsize);
486} 491 func = ci->func; /* moved-down function */
487 492 for (; narg1 <= nfixparams; narg1++)
488 493 setnilvalue(s2v(func + narg1)); /* complete missing arguments */
489static CallInfo *prepCallInfo (lua_State *L, StkId func, int retdel, 494 ci->top = func + 1 + fsize; /* top for new function */
490 int mask) { 495 lua_assert(ci->top <= L->stack_last);
491 CallInfo *ci; 496 ci->u.l.savedpc = p->code; /* starting point */
492 if (isdelta(retdel)) { /* tail call? */ 497 ci->callstatus |= CIST_TAIL;
493 ci = L->ci; /* reuse stack frame */ 498 L->top = func + narg1; /* set top */
494 ci->func -= retdel2delta(retdel); /* correct 'func' */ 499}
495 ci->callstatus |= mask | CIST_TAIL; 500
496 moveparams(L, ci->func, func); 501
497 } 502l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
498 else { /* regular call */ 503 int mask, StkId top) {
499 ci = L->ci = next_ci(L); /* new frame */ 504 CallInfo *ci = L->ci = next_ci(L); /* new frame */
500 ci->func = func; 505 ci->func = func;
501 ci->nresults = retdel; 506 ci->nresults = nret;
502 ci->callstatus = mask; 507 ci->callstatus = mask;
503 } 508 ci->top = top;
504 return ci; 509 return ci;
505} 510}
506 511
@@ -512,12 +517,8 @@ static CallInfo *prepCallInfo (lua_State *L, StkId func, int retdel,
512** to be executed, if it was a Lua function. Otherwise (a C function) 517** to be executed, if it was a Lua function. Otherwise (a C function)
513** returns NULL, with all the results on the stack, starting at the 518** returns NULL, with all the results on the stack, starting at the
514** original function position. 519** original function position.
515** For regular calls, 'delta1' is 0. For tail calls, 'delta1' is the
516** 'delta' (correction of base for vararg functions) plus 1, so that it
517** cannot be zero. Like 'moveparams', this correction can only be done
518** when no more errors can occur in the call.
519*/ 520*/
520CallInfo *luaD_precall (lua_State *L, StkId func, int retdel) { 521CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
521 lua_CFunction f; 522 lua_CFunction f;
522 retry: 523 retry:
523 switch (ttypetag(s2v(func))) { 524 switch (ttypetag(s2v(func))) {
@@ -530,8 +531,8 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int retdel) {
530 int n; /* number of returns */ 531 int n; /* number of returns */
531 CallInfo *ci; 532 CallInfo *ci;
532 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ 533 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
533 ci = prepCallInfo(L, func, retdel, CIST_C); 534 L->ci = ci = prepCallInfo(L, func, nresults, CIST_C,
534 ci->top = L->top + LUA_MINSTACK; 535 L->top + LUA_MINSTACK);
535 lua_assert(ci->top <= L->stack_last); 536 lua_assert(ci->top <= L->stack_last);
536 if (l_unlikely(L->hookmask & LUA_MASKCALL)) { 537 if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
537 int narg = cast_int(L->top - func) - 1; 538 int narg = cast_int(L->top - func) - 1;
@@ -551,17 +552,15 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int retdel) {
551 int nfixparams = p->numparams; 552 int nfixparams = p->numparams;
552 int fsize = p->maxstacksize; /* frame size */ 553 int fsize = p->maxstacksize; /* frame size */
553 checkstackGCp(L, fsize, func); 554 checkstackGCp(L, fsize, func);
554 ci = prepCallInfo(L, func, retdel, 0); 555 L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize);
555 ci->u.l.savedpc = p->code; /* starting point */ 556 ci->u.l.savedpc = p->code; /* starting point */
556 ci->top = func + 1 + fsize;
557 for (; narg < nfixparams; narg++) 557 for (; narg < nfixparams; narg++)
558 setnilvalue(s2v(L->top++)); /* complete missing arguments */ 558 setnilvalue(s2v(L->top++)); /* complete missing arguments */
559 lua_assert(ci->top <= L->stack_last); 559 lua_assert(ci->top <= L->stack_last);
560 return ci; 560 return ci;
561 } 561 }
562 default: { /* not a function */ 562 default: { /* not a function */
563 checkstackGCp(L, 1, func); /* space for metamethod */ 563 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
564 luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
565 goto retry; /* try again with metamethod */ 564 goto retry; /* try again with metamethod */
566 } 565 }
567 } 566 }
@@ -573,7 +572,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int retdel) {
573** number of recursive invocations in the C stack) or nyci (the same 572** number of recursive invocations in the C stack) or nyci (the same
574** plus increment number of non-yieldable calls). 573** plus increment number of non-yieldable calls).
575*/ 574*/
576static void ccall (lua_State *L, StkId func, int nResults, int inc) { 575l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) {
577 CallInfo *ci; 576 CallInfo *ci;
578 L->nCcalls += inc; 577 L->nCcalls += inc;
579 if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) 578 if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS))
diff --git a/src/3rdParty/lua/ldo.h b/src/3rdParty/lua/ldo.h
index 49fbb49..9fb772f 100644
--- a/src/3rdParty/lua/ldo.h
+++ b/src/3rdParty/lua/ldo.h
@@ -49,18 +49,6 @@
49 luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0) 49 luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
50 50
51 51
52/*
53** 'luaD_precall' is used for regular calls, when it needs the
54** number of results, and in tail calls, when it needs the 'delta'
55** (correction of base for vararg functions). The argument 'retdel'
56** codes these two options. A number of results is represented by
57** itself, while a delta is represented by 'delta2retdel(delta)'
58*/
59#define delta2retdel(d) (-(d) + LUA_MULTRET - 1)
60#define retdel2delta(d) (-(d) + LUA_MULTRET - 1)
61#define isdelta(rd) ((rd) < LUA_MULTRET)
62
63
64/* type of protected functions, to be ran by 'runprotected' */ 52/* type of protected functions, to be ran by 'runprotected' */
65typedef void (*Pfunc) (lua_State *L, void *ud); 53typedef void (*Pfunc) (lua_State *L, void *ud);
66 54
@@ -70,10 +58,11 @@ LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
70LUAI_FUNC void luaD_hook (lua_State *L, int event, int line, 58LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
71 int fTransfer, int nTransfer); 59 int fTransfer, int nTransfer);
72LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci); 60LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
73LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int retdel); 61LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n);
62LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
74LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 63LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
75LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 64LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
76LUAI_FUNC void luaD_tryfuncTM (lua_State *L, StkId func); 65LUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func);
77LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status); 66LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status);
78LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 67LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
79 ptrdiff_t oldtop, ptrdiff_t ef); 68 ptrdiff_t oldtop, ptrdiff_t ef);
diff --git a/src/3rdParty/lua/llimits.h b/src/3rdParty/lua/llimits.h
index 025f1c8..6c56ba5 100644
--- a/src/3rdParty/lua/llimits.h
+++ b/src/3rdParty/lua/llimits.h
@@ -166,6 +166,20 @@ typedef LUAI_UACINT l_uacInt;
166 166
167 167
168/* 168/*
169** Inline functions
170*/
171#if !defined(LUA_USE_C89)
172#define l_inline inline
173#elif defined(__GNUC__)
174#define l_inline __inline__
175#else
176#define l_inline /* empty */
177#endif
178
179#define l_sinline static l_inline
180
181
182/*
169** type for virtual-machine instructions; 183** type for virtual-machine instructions;
170** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 184** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
171*/ 185*/
diff --git a/src/3rdParty/lua/lobject.h b/src/3rdParty/lua/lobject.h
index a1b4554..0e05b3e 100644
--- a/src/3rdParty/lua/lobject.h
+++ b/src/3rdParty/lua/lobject.h
@@ -68,7 +68,7 @@ typedef struct TValue {
68 68
69 69
70#define val_(o) ((o)->value_) 70#define val_(o) ((o)->value_)
71#define valraw(o) (&val_(o)) 71#define valraw(o) (val_(o))
72 72
73 73
74/* raw type tag of a TValue */ 74/* raw type tag of a TValue */
diff --git a/src/3rdParty/lua/lstrlib.c b/src/3rdParty/lua/lstrlib.c
index 74501f7..0b4fdbb 100644
--- a/src/3rdParty/lua/lstrlib.c
+++ b/src/3rdParty/lua/lstrlib.c
@@ -1090,13 +1090,31 @@ static int lua_number2strx (lua_State *L, char *buff, int sz,
1090 1090
1091 1091
1092/* valid flags in a format specification */ 1092/* valid flags in a format specification */
1093#if !defined(L_FMTFLAGS) 1093#if !defined(L_FMTFLAGSF)
1094#define L_FMTFLAGS "-+ #0" 1094
1095/* valid flags for a, A, e, E, f, F, g, and G conversions */
1096#define L_FMTFLAGSF "-+#0 "
1097
1098/* valid flags for o, x, and X conversions */
1099#define L_FMTFLAGSX "-#0"
1100
1101/* valid flags for d and i conversions */
1102#define L_FMTFLAGSI "-+0 "
1103
1104/* valid flags for u conversions */
1105#define L_FMTFLAGSU "-0"
1106
1107/* valid flags for c, p, and s conversions */
1108#define L_FMTFLAGSC "-"
1109
1095#endif 1110#endif
1096 1111
1097 1112
1098/* 1113/*
1099** maximum size of each format specification (such as "%-099.99d") 1114** Maximum size of each format specification (such as "%-099.99d"):
1115** Initial '%', flags (up to 5), width (2), period, precision (2),
1116** length modifier (8), conversion specifier, and final '\0', plus some
1117** extra.
1100*/ 1118*/
1101#define MAX_FORMAT 32 1119#define MAX_FORMAT 32
1102 1120
@@ -1189,25 +1207,53 @@ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) {
1189} 1207}
1190 1208
1191 1209
1192static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { 1210static const char *get2digits (const char *s) {
1193 const char *p = strfrmt; 1211 if (isdigit(uchar(*s))) {
1194 while (*p != '\0' && strchr(L_FMTFLAGS, *p) != NULL) p++; /* skip flags */ 1212 s++;
1195 if ((size_t)(p - strfrmt) >= sizeof(L_FMTFLAGS)/sizeof(char)) 1213 if (isdigit(uchar(*s))) s++; /* (2 digits at most) */
1196 luaL_error(L, "invalid format (repeated flags)"); 1214 }
1197 if (isdigit(uchar(*p))) p++; /* skip width */ 1215 return s;
1198 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ 1216}
1199 if (*p == '.') { 1217
1200 p++; 1218
1201 if (isdigit(uchar(*p))) p++; /* skip precision */ 1219/*
1202 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ 1220** Check whether a conversion specification is valid. When called,
1221** first character in 'form' must be '%' and last character must
1222** be a valid conversion specifier. 'flags' are the accepted flags;
1223** 'precision' signals whether to accept a precision.
1224*/
1225static void checkformat (lua_State *L, const char *form, const char *flags,
1226 int precision) {
1227 const char *spec = form + 1; /* skip '%' */
1228 spec += strspn(spec, flags); /* skip flags */
1229 if (*spec != '0') { /* a width cannot start with '0' */
1230 spec = get2digits(spec); /* skip width */
1231 if (*spec == '.' && precision) {
1232 spec++;
1233 spec = get2digits(spec); /* skip precision */
1234 }
1203 } 1235 }
1204 if (isdigit(uchar(*p))) 1236 if (!isalpha(uchar(*spec))) /* did not go to the end? */
1205 luaL_error(L, "invalid format (width or precision too long)"); 1237 luaL_error(L, "invalid conversion specification: '%s'", form);
1238}
1239
1240
1241/*
1242** Get a conversion specification and copy it to 'form'.
1243** Return the address of its last character.
1244*/
1245static const char *getformat (lua_State *L, const char *strfrmt,
1246 char *form) {
1247 /* spans flags, width, and precision ('0' is included as a flag) */
1248 size_t len = strspn(strfrmt, L_FMTFLAGSF "123456789.");
1249 len++; /* adds following character (should be the specifier) */
1250 /* still needs space for '%', '\0', plus a length modifier */
1251 if (len >= MAX_FORMAT - 10)
1252 luaL_error(L, "invalid format (too long)");
1206 *(form++) = '%'; 1253 *(form++) = '%';
1207 memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char)); 1254 memcpy(form, strfrmt, len * sizeof(char));
1208 form += (p - strfrmt) + 1; 1255 *(form + len) = '\0';
1209 *form = '\0'; 1256 return strfrmt + len - 1;
1210 return p;
1211} 1257}
1212 1258
1213 1259
@@ -1230,6 +1276,7 @@ static int str_format (lua_State *L) {
1230 size_t sfl; 1276 size_t sfl;
1231 const char *strfrmt = luaL_checklstring(L, arg, &sfl); 1277 const char *strfrmt = luaL_checklstring(L, arg, &sfl);
1232 const char *strfrmt_end = strfrmt+sfl; 1278 const char *strfrmt_end = strfrmt+sfl;
1279 const char *flags;
1233 luaL_Buffer b; 1280 luaL_Buffer b;
1234 luaL_buffinit(L, &b); 1281 luaL_buffinit(L, &b);
1235 while (strfrmt < strfrmt_end) { 1282 while (strfrmt < strfrmt_end) {
@@ -1239,25 +1286,35 @@ static int str_format (lua_State *L) {
1239 luaL_addchar(&b, *strfrmt++); /* %% */ 1286 luaL_addchar(&b, *strfrmt++); /* %% */
1240 else { /* format item */ 1287 else { /* format item */
1241 char form[MAX_FORMAT]; /* to store the format ('%...') */ 1288 char form[MAX_FORMAT]; /* to store the format ('%...') */
1242 int maxitem = MAX_ITEM; 1289 int maxitem = MAX_ITEM; /* maximum length for the result */
1243 char *buff = luaL_prepbuffsize(&b, maxitem); /* to put formatted item */ 1290 char *buff = luaL_prepbuffsize(&b, maxitem); /* to put result */
1244 int nb = 0; /* number of bytes in added item */ 1291 int nb = 0; /* number of bytes in result */
1245 if (++arg > top) 1292 if (++arg > top)
1246 return luaL_argerror(L, arg, "no value"); 1293 return luaL_argerror(L, arg, "no value");
1247 strfrmt = scanformat(L, strfrmt, form); 1294 strfrmt = getformat(L, strfrmt, form);
1248 switch (*strfrmt++) { 1295 switch (*strfrmt++) {
1249 case 'c': { 1296 case 'c': {
1297 checkformat(L, form, L_FMTFLAGSC, 0);
1250 nb = l_sprintf(buff, maxitem, form, (int)luaL_checkinteger(L, arg)); 1298 nb = l_sprintf(buff, maxitem, form, (int)luaL_checkinteger(L, arg));
1251 break; 1299 break;
1252 } 1300 }
1253 case 'd': case 'i': 1301 case 'd': case 'i':
1254 case 'o': case 'u': case 'x': case 'X': { 1302 flags = L_FMTFLAGSI;
1303 goto intcase;
1304 case 'u':
1305 flags = L_FMTFLAGSU;
1306 goto intcase;
1307 case 'o': case 'x': case 'X':
1308 flags = L_FMTFLAGSX;
1309 intcase: {
1255 lua_Integer n = luaL_checkinteger(L, arg); 1310 lua_Integer n = luaL_checkinteger(L, arg);
1311 checkformat(L, form, flags, 1);
1256 addlenmod(form, LUA_INTEGER_FRMLEN); 1312 addlenmod(form, LUA_INTEGER_FRMLEN);
1257 nb = l_sprintf(buff, maxitem, form, (LUAI_UACINT)n); 1313 nb = l_sprintf(buff, maxitem, form, (LUAI_UACINT)n);
1258 break; 1314 break;
1259 } 1315 }
1260 case 'a': case 'A': 1316 case 'a': case 'A':
1317 checkformat(L, form, L_FMTFLAGSF, 1);
1261 addlenmod(form, LUA_NUMBER_FRMLEN); 1318 addlenmod(form, LUA_NUMBER_FRMLEN);
1262 nb = lua_number2strx(L, buff, maxitem, form, 1319 nb = lua_number2strx(L, buff, maxitem, form,
1263 luaL_checknumber(L, arg)); 1320 luaL_checknumber(L, arg));
@@ -1268,12 +1325,14 @@ static int str_format (lua_State *L) {
1268 /* FALLTHROUGH */ 1325 /* FALLTHROUGH */
1269 case 'e': case 'E': case 'g': case 'G': { 1326 case 'e': case 'E': case 'g': case 'G': {
1270 lua_Number n = luaL_checknumber(L, arg); 1327 lua_Number n = luaL_checknumber(L, arg);
1328 checkformat(L, form, L_FMTFLAGSF, 1);
1271 addlenmod(form, LUA_NUMBER_FRMLEN); 1329 addlenmod(form, LUA_NUMBER_FRMLEN);
1272 nb = l_sprintf(buff, maxitem, form, (LUAI_UACNUMBER)n); 1330 nb = l_sprintf(buff, maxitem, form, (LUAI_UACNUMBER)n);
1273 break; 1331 break;
1274 } 1332 }
1275 case 'p': { 1333 case 'p': {
1276 const void *p = lua_topointer(L, arg); 1334 const void *p = lua_topointer(L, arg);
1335 checkformat(L, form, L_FMTFLAGSC, 0);
1277 if (p == NULL) { /* avoid calling 'printf' with argument NULL */ 1336 if (p == NULL) { /* avoid calling 'printf' with argument NULL */
1278 p = "(null)"; /* result */ 1337 p = "(null)"; /* result */
1279 form[strlen(form) - 1] = 's'; /* format it as a string */ 1338 form[strlen(form) - 1] = 's'; /* format it as a string */
@@ -1294,7 +1353,8 @@ static int str_format (lua_State *L) {
1294 luaL_addvalue(&b); /* keep entire string */ 1353 luaL_addvalue(&b); /* keep entire string */
1295 else { 1354 else {
1296 luaL_argcheck(L, l == strlen(s), arg, "string contains zeros"); 1355 luaL_argcheck(L, l == strlen(s), arg, "string contains zeros");
1297 if (!strchr(form, '.') && l >= 100) { 1356 checkformat(L, form, L_FMTFLAGSC, 1);
1357 if (strchr(form, '.') == NULL && l >= 100) {
1298 /* no precision and string is too long to be formatted */ 1358 /* no precision and string is too long to be formatted */
1299 luaL_addvalue(&b); /* keep entire string */ 1359 luaL_addvalue(&b); /* keep entire string */
1300 } 1360 }
diff --git a/src/3rdParty/lua/ltable.c b/src/3rdParty/lua/ltable.c
index af87836..c82286d 100644
--- a/src/3rdParty/lua/ltable.c
+++ b/src/3rdParty/lua/ltable.c
@@ -150,22 +150,22 @@ static int l_hashfloat (lua_Number n) {
150** and value in 'vkl') so that we can call it on keys inserted into 150** and value in 'vkl') so that we can call it on keys inserted into
151** nodes. 151** nodes.
152*/ 152*/
153static Node *mainposition (const Table *t, int ktt, const Value *kvl) { 153static Node *mainposition (const Table *t, int ktt, const Value kvl) {
154 switch (withvariant(ktt)) { 154 switch (withvariant(ktt)) {
155 case LUA_VNUMINT: { 155 case LUA_VNUMINT: {
156 lua_Integer key = ivalueraw(*kvl); 156 lua_Integer key = ivalueraw(kvl);
157 return hashint(t, key); 157 return hashint(t, key);
158 } 158 }
159 case LUA_VNUMFLT: { 159 case LUA_VNUMFLT: {
160 lua_Number n = fltvalueraw(*kvl); 160 lua_Number n = fltvalueraw(kvl);
161 return hashmod(t, l_hashfloat(n)); 161 return hashmod(t, l_hashfloat(n));
162 } 162 }
163 case LUA_VSHRSTR: { 163 case LUA_VSHRSTR: {
164 TString *ts = tsvalueraw(*kvl); 164 TString *ts = tsvalueraw(kvl);
165 return hashstr(t, ts); 165 return hashstr(t, ts);
166 } 166 }
167 case LUA_VLNGSTR: { 167 case LUA_VLNGSTR: {
168 TString *ts = tsvalueraw(*kvl); 168 TString *ts = tsvalueraw(kvl);
169 return hashpow2(t, luaS_hashlongstr(ts)); 169 return hashpow2(t, luaS_hashlongstr(ts));
170 } 170 }
171 case LUA_VFALSE: 171 case LUA_VFALSE:
@@ -173,15 +173,15 @@ static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
173 case LUA_VTRUE: 173 case LUA_VTRUE:
174 return hashboolean(t, 1); 174 return hashboolean(t, 1);
175 case LUA_VLIGHTUSERDATA: { 175 case LUA_VLIGHTUSERDATA: {
176 void *p = pvalueraw(*kvl); 176 void *p = pvalueraw(kvl);
177 return hashpointer(t, p); 177 return hashpointer(t, p);
178 } 178 }
179 case LUA_VLCF: { 179 case LUA_VLCF: {
180 lua_CFunction f = fvalueraw(*kvl); 180 lua_CFunction f = fvalueraw(kvl);
181 return hashpointer(t, f); 181 return hashpointer(t, f);
182 } 182 }
183 default: { 183 default: {
184 GCObject *o = gcvalueraw(*kvl); 184 GCObject *o = gcvalueraw(kvl);
185 return hashpointer(t, o); 185 return hashpointer(t, o);
186 } 186 }
187 } 187 }
@@ -691,7 +691,7 @@ void luaH_newkey (lua_State *L, Table *t, const TValue *key, TValue *value) {
691 return; 691 return;
692 } 692 }
693 lua_assert(!isdummy(t)); 693 lua_assert(!isdummy(t));
694 othern = mainposition(t, keytt(mp), &keyval(mp)); 694 othern = mainposition(t, keytt(mp), keyval(mp));
695 if (othern != mp) { /* is colliding node out of its main position? */ 695 if (othern != mp) { /* is colliding node out of its main position? */
696 /* yes; move colliding node into free position */ 696 /* yes; move colliding node into free position */
697 while (othern + gnext(othern) != mp) /* find previous */ 697 while (othern + gnext(othern) != mp) /* find previous */
diff --git a/src/3rdParty/lua/ltablib.c b/src/3rdParty/lua/ltablib.c
index dbfe250..868d78f 100644
--- a/src/3rdParty/lua/ltablib.c
+++ b/src/3rdParty/lua/ltablib.c
@@ -59,8 +59,9 @@ static void checktab (lua_State *L, int arg, int what) {
59 59
60 60
61static int tinsert (lua_State *L) { 61static int tinsert (lua_State *L) {
62 lua_Integer e = aux_getn(L, 1, TAB_RW) + 1; /* first empty element */
63 lua_Integer pos; /* where to insert new element */ 62 lua_Integer pos; /* where to insert new element */
63 lua_Integer e = aux_getn(L, 1, TAB_RW);
64 e = luaL_intop(+, e, 1); /* first empty element */
64 switch (lua_gettop(L)) { 65 switch (lua_gettop(L)) {
65 case 2: { /* called with only 2 arguments */ 66 case 2: { /* called with only 2 arguments */
66 pos = e; /* insert new element at the end */ 67 pos = e; /* insert new element at the end */
diff --git a/src/3rdParty/lua/lua.c b/src/3rdParty/lua/lua.c
index 46b48db..0f19004 100644
--- a/src/3rdParty/lua/lua.c
+++ b/src/3rdParty/lua/lua.c
@@ -89,14 +89,15 @@ static void print_usage (const char *badoption) {
89 lua_writestringerror( 89 lua_writestringerror(
90 "usage: %s [options] [script [args]]\n" 90 "usage: %s [options] [script [args]]\n"
91 "Available options are:\n" 91 "Available options are:\n"
92 " -e stat execute string 'stat'\n" 92 " -e stat execute string 'stat'\n"
93 " -i enter interactive mode after executing 'script'\n" 93 " -i enter interactive mode after executing 'script'\n"
94 " -l name require library 'name' into global 'name'\n" 94 " -l mod require library 'mod' into global 'mod'\n"
95 " -v show version information\n" 95 " -l g=mod require library 'mod' into global 'g'\n"
96 " -E ignore environment variables\n" 96 " -v show version information\n"
97 " -W turn warnings on\n" 97 " -E ignore environment variables\n"
98 " -- stop handling options\n" 98 " -W turn warnings on\n"
99 " - stop handling options and execute stdin\n" 99 " -- stop handling options\n"
100 " - stop handling options and execute stdin\n"
100 , 101 ,
101 progname); 102 progname);
102} 103}
@@ -207,16 +208,22 @@ static int dostring (lua_State *L, const char *s, const char *name) {
207 208
208 209
209/* 210/*
210** Calls 'require(name)' and stores the result in a global variable 211** Receives 'globname[=modname]' and runs 'globname = require(modname)'.
211** with the given name.
212*/ 212*/
213static int dolibrary (lua_State *L, const char *name) { 213static int dolibrary (lua_State *L, char *globname) {
214 int status; 214 int status;
215 char *modname = strchr(globname, '=');
216 if (modname == NULL) /* no explicit name? */
217 modname = globname; /* module name is equal to global name */
218 else {
219 *modname = '\0'; /* global name ends here */
220 modname++; /* module name starts after the '=' */
221 }
215 lua_getglobal(L, "require"); 222 lua_getglobal(L, "require");
216 lua_pushstring(L, name); 223 lua_pushstring(L, modname);
217 status = docall(L, 1, 1); /* call 'require(name)' */ 224 status = docall(L, 1, 1); /* call 'require(modname)' */
218 if (status == LUA_OK) 225 if (status == LUA_OK)
219 lua_setglobal(L, name); /* global[name] = require return */ 226 lua_setglobal(L, globname); /* globname = require(modname) */
220 return report(L, status); 227 return report(L, status);
221} 228}
222 229
@@ -327,7 +334,7 @@ static int runargs (lua_State *L, char **argv, int n) {
327 switch (option) { 334 switch (option) {
328 case 'e': case 'l': { 335 case 'e': case 'l': {
329 int status; 336 int status;
330 const char *extra = argv[i] + 2; /* both options need an argument */ 337 char *extra = argv[i] + 2; /* both options need an argument */
331 if (*extra == '\0') extra = argv[++i]; 338 if (*extra == '\0') extra = argv[++i];
332 lua_assert(extra != NULL); 339 lua_assert(extra != NULL);
333 status = (option == 'e') 340 status = (option == 'e')
diff --git a/src/3rdParty/lua/lutf8lib.c b/src/3rdParty/lua/lutf8lib.c
index 901d985..e7bf098 100644
--- a/src/3rdParty/lua/lutf8lib.c
+++ b/src/3rdParty/lua/lutf8lib.c
@@ -224,14 +224,11 @@ static int byteoffset (lua_State *L) {
224static int iter_aux (lua_State *L, int strict) { 224static int iter_aux (lua_State *L, int strict) {
225 size_t len; 225 size_t len;
226 const char *s = luaL_checklstring(L, 1, &len); 226 const char *s = luaL_checklstring(L, 1, &len);
227 lua_Integer n = lua_tointeger(L, 2) - 1; 227 lua_Unsigned n = (lua_Unsigned)lua_tointeger(L, 2);
228 if (n < 0) /* first iteration? */ 228 if (n < len) {
229 n = 0; /* start from here */ 229 while (iscont(s + n)) n++; /* skip continuation bytes */
230 else if (n < (lua_Integer)len) {
231 n++; /* skip current byte */
232 while (iscont(s + n)) n++; /* and its continuations */
233 } 230 }
234 if (n >= (lua_Integer)len) 231 if (n >= len) /* (also handles original 'n' being negative) */
235 return 0; /* no more codepoints */ 232 return 0; /* no more codepoints */
236 else { 233 else {
237 utfint code; 234 utfint code;
diff --git a/src/3rdParty/lua/lvm.c b/src/3rdParty/lua/lvm.c
index c84a665..49ed3dd 100644
--- a/src/3rdParty/lua/lvm.c
+++ b/src/3rdParty/lua/lvm.c
@@ -406,7 +406,7 @@ static int l_strcmp (const TString *ls, const TString *rs) {
406** from float to int.) 406** from float to int.)
407** When 'f' is NaN, comparisons must result in false. 407** When 'f' is NaN, comparisons must result in false.
408*/ 408*/
409static int LTintfloat (lua_Integer i, lua_Number f) { 409l_sinline int LTintfloat (lua_Integer i, lua_Number f) {
410 if (l_intfitsf(i)) 410 if (l_intfitsf(i))
411 return luai_numlt(cast_num(i), f); /* compare them as floats */ 411 return luai_numlt(cast_num(i), f); /* compare them as floats */
412 else { /* i < f <=> i < ceil(f) */ 412 else { /* i < f <=> i < ceil(f) */
@@ -423,7 +423,7 @@ static int LTintfloat (lua_Integer i, lua_Number f) {
423** Check whether integer 'i' is less than or equal to float 'f'. 423** Check whether integer 'i' is less than or equal to float 'f'.
424** See comments on previous function. 424** See comments on previous function.
425*/ 425*/
426static int LEintfloat (lua_Integer i, lua_Number f) { 426l_sinline int LEintfloat (lua_Integer i, lua_Number f) {
427 if (l_intfitsf(i)) 427 if (l_intfitsf(i))
428 return luai_numle(cast_num(i), f); /* compare them as floats */ 428 return luai_numle(cast_num(i), f); /* compare them as floats */
429 else { /* i <= f <=> i <= floor(f) */ 429 else { /* i <= f <=> i <= floor(f) */
@@ -440,7 +440,7 @@ static int LEintfloat (lua_Integer i, lua_Number f) {
440** Check whether float 'f' is less than integer 'i'. 440** Check whether float 'f' is less than integer 'i'.
441** See comments on previous function. 441** See comments on previous function.
442*/ 442*/
443static int LTfloatint (lua_Number f, lua_Integer i) { 443l_sinline int LTfloatint (lua_Number f, lua_Integer i) {
444 if (l_intfitsf(i)) 444 if (l_intfitsf(i))
445 return luai_numlt(f, cast_num(i)); /* compare them as floats */ 445 return luai_numlt(f, cast_num(i)); /* compare them as floats */
446 else { /* f < i <=> floor(f) < i */ 446 else { /* f < i <=> floor(f) < i */
@@ -457,7 +457,7 @@ static int LTfloatint (lua_Number f, lua_Integer i) {
457** Check whether float 'f' is less than or equal to integer 'i'. 457** Check whether float 'f' is less than or equal to integer 'i'.
458** See comments on previous function. 458** See comments on previous function.
459*/ 459*/
460static int LEfloatint (lua_Number f, lua_Integer i) { 460l_sinline int LEfloatint (lua_Number f, lua_Integer i) {
461 if (l_intfitsf(i)) 461 if (l_intfitsf(i))
462 return luai_numle(f, cast_num(i)); /* compare them as floats */ 462 return luai_numle(f, cast_num(i)); /* compare them as floats */
463 else { /* f <= i <=> ceil(f) <= i */ 463 else { /* f <= i <=> ceil(f) <= i */
@@ -473,7 +473,7 @@ static int LEfloatint (lua_Number f, lua_Integer i) {
473/* 473/*
474** Return 'l < r', for numbers. 474** Return 'l < r', for numbers.
475*/ 475*/
476static int LTnum (const TValue *l, const TValue *r) { 476l_sinline int LTnum (const TValue *l, const TValue *r) {
477 lua_assert(ttisnumber(l) && ttisnumber(r)); 477 lua_assert(ttisnumber(l) && ttisnumber(r));
478 if (ttisinteger(l)) { 478 if (ttisinteger(l)) {
479 lua_Integer li = ivalue(l); 479 lua_Integer li = ivalue(l);
@@ -495,7 +495,7 @@ static int LTnum (const TValue *l, const TValue *r) {
495/* 495/*
496** Return 'l <= r', for numbers. 496** Return 'l <= r', for numbers.
497*/ 497*/
498static int LEnum (const TValue *l, const TValue *r) { 498l_sinline int LEnum (const TValue *l, const TValue *r) {
499 lua_assert(ttisnumber(l) && ttisnumber(r)); 499 lua_assert(ttisnumber(l) && ttisnumber(r));
500 if (ttisinteger(l)) { 500 if (ttisinteger(l)) {
501 lua_Integer li = ivalue(l); 501 lua_Integer li = ivalue(l);
@@ -768,6 +768,7 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
768*/ 768*/
769#define luaV_shiftr(x,y) luaV_shiftl(x,intop(-, 0, y)) 769#define luaV_shiftr(x,y) luaV_shiftl(x,intop(-, 0, y))
770 770
771
771lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) { 772lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
772 if (y < 0) { /* shift right? */ 773 if (y < 0) { /* shift right? */
773 if (y <= -NBITS) return 0; 774 if (y <= -NBITS) return 0;
@@ -1108,7 +1109,7 @@ void luaV_finishOp (lua_State *L) {
1108#define ProtectNT(exp) (savepc(L), (exp), updatetrap(ci)) 1109#define ProtectNT(exp) (savepc(L), (exp), updatetrap(ci))
1109 1110
1110/* 1111/*
1111** Protect code that can only raise errors. (That is, it cannnot change 1112** Protect code that can only raise errors. (That is, it cannot change
1112** the stack or hooks.) 1113** the stack or hooks.)
1113*/ 1114*/
1114#define halfProtect(exp) (savestate(L,ci), (exp)) 1115#define halfProtect(exp) (savestate(L,ci), (exp))
@@ -1647,19 +1648,32 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1647 int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0; 1648 int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0;
1648 if (b != 0) 1649 if (b != 0)
1649 L->top = ra + b; 1650 L->top = ra + b;
1650 /* else previous instruction set top */ 1651 else /* previous instruction set top */
1652 b = cast_int(L->top - ra);
1651 savepc(ci); /* several calls here can raise errors */ 1653 savepc(ci); /* several calls here can raise errors */
1652 if (TESTARG_k(i)) { 1654 if (TESTARG_k(i)) {
1653 luaF_closeupval(L, base); /* close upvalues from current call */ 1655 luaF_closeupval(L, base); /* close upvalues from current call */
1654 lua_assert(L->tbclist < base); /* no pending tbc variables */ 1656 lua_assert(L->tbclist < base); /* no pending tbc variables */
1655 lua_assert(base == ci->func + 1); 1657 lua_assert(base == ci->func + 1);
1656 } 1658 }
1657 if (luaD_precall(L, ra, delta2retdel(delta))) /* Lua function? */ 1659 while (!ttisfunction(s2v(ra))) { /* not a function? */
1658 goto startfunc; /* execute the callee */ 1660 ra = luaD_tryfuncTM(L, ra); /* try '__call' metamethod */
1659 else { /* C function */ 1661 b++; /* there is now one extra argument */
1662 }
1663 if (!ttisLclosure(s2v(ra))) { /* C function? */
1664 luaD_precall(L, ra, LUA_MULTRET); /* call it */
1660 updatetrap(ci); 1665 updatetrap(ci);
1666 updatestack(ci); /* stack may have been relocated */
1667 ci->func -= delta; /* restore 'func' (if vararg) */
1668 luaD_poscall(L, ci, cast_int(L->top - ra)); /* finish caller */
1669 updatetrap(ci); /* 'luaD_poscall' can change hooks */
1661 goto ret; /* caller returns after the tail call */ 1670 goto ret; /* caller returns after the tail call */
1662 } 1671 }
1672 else { /* Lua function */
1673 ci->func -= delta; /* restore 'func' (if vararg) */
1674 luaD_pretailcall(L, ci, ra, b); /* prepare call frame */
1675 goto startfunc; /* execute the callee */
1676 }
1663 } 1677 }
1664 vmcase(OP_RETURN) { 1678 vmcase(OP_RETURN) {
1665 int n = GETARG_B(i) - 1; /* number of results */ 1679 int n = GETARG_B(i) - 1; /* number of results */
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 415fcd3..e004821 100755
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -60,7 +60,7 @@ using namespace parserlib;
60 60
61typedef std::list<std::string> str_list; 61typedef std::list<std::string> str_list;
62 62
63const std::string_view version = "0.8.4"sv; 63const std::string_view version = "0.8.5"sv;
64const std::string_view extension = "yue"sv; 64const std::string_view extension = "yue"sv;
65 65
66class YueCompilerImpl { 66class YueCompilerImpl {
@@ -530,6 +530,7 @@ private:
530 } 530 }
531 if (!exp) return nullptr; 531 if (!exp) return nullptr;
532 BLOCK_START 532 BLOCK_START
533 BREAK_IF(exp->nilCoalesed);
533 BREAK_IF(!exp->opValues.empty()); 534 BREAK_IF(!exp->opValues.empty());
534 BREAK_IF(exp->pipeExprs.size() != 1); 535 BREAK_IF(exp->pipeExprs.size() != 1);
535 auto unary = static_cast<unary_exp_t*>(exp->pipeExprs.back()); 536 auto unary = static_cast<unary_exp_t*>(exp->pipeExprs.back());