diff options
author | Li Jin <dragon-fly@qq.com> | 2021-11-02 11:17:58 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2021-11-02 11:17:58 +0800 |
commit | 827c3736f357e09168fc108e8e740c6425d37d9b (patch) | |
tree | 259f977bf7f4ebe0e397fe5e1b74e7fbb1b75e8e /src/3rdParty/lua/ldo.c | |
parent | aed806476fe50899c0f01750175531ac41267b9d (diff) | |
download | yuescript-827c3736f357e09168fc108e8e740c6425d37d9b.tar.gz yuescript-827c3736f357e09168fc108e8e740c6425d37d9b.tar.bz2 yuescript-827c3736f357e09168fc108e8e740c6425d37d9b.zip |
fix a wrong code generating issue, update builtin Lua.
Diffstat (limited to 'src/3rdParty/lua/ldo.c')
-rw-r--r-- | src/3rdParty/lua/ldo.c | 77 |
1 files changed, 38 insertions, 39 deletions
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 | */ |
390 | void luaD_tryfuncTM (lua_State *L, StkId func) { | 390 | StkId 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 | */ |
408 | static void moveresults (lua_State *L, StkId res, int nres, int wanted) { | 410 | l_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 | */ |
481 | static void moveparams (lua_State *L, StkId prevf, StkId func) { | 483 | void 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 */ | |
489 | static 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 | } | 502 | l_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 | */ |
520 | CallInfo *luaD_precall (lua_State *L, StkId func, int retdel) { | 521 | CallInfo *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 | */ |
576 | static void ccall (lua_State *L, StkId func, int nResults, int inc) { | 575 | l_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)) |