aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/lua/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdParty/lua/ldo.c')
-rw-r--r--src/3rdParty/lua/ldo.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/src/3rdParty/lua/ldo.c b/src/3rdParty/lua/ldo.c
index 7135079..93fcbb1 100644
--- a/src/3rdParty/lua/ldo.c
+++ b/src/3rdParty/lua/ldo.c
@@ -474,26 +474,34 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
474 474
475 475
476/* 476/*
477** Prepare a function for a tail call, building its call info on top 477** In a tail call, move function and parameters to previous call frame.
478** of the current call info. 'narg1' is the number of arguments plus 1 478** (This is done only when no more errors can occur before entering the
479** (so that it includes the function itself). 479** new function, to keep debug information always consistent.)
480*/ 480*/
481void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { 481static void moveparams (lua_State *L, StkId prevf, StkId func) {
482 Proto *p = clLvalue(s2v(func))->p;
483 int fsize = p->maxstacksize; /* frame size */
484 int nfixparams = p->numparams;
485 int i; 482 int i;
486 for (i = 0; i < narg1; i++) /* move down function and arguments */ 483 for (i = 0; func + i < L->top; i++) /* move down function and arguments */
487 setobjs2s(L, ci->func + i, func + i); 484 setobjs2s(L, prevf + i, func + i);
488 checkstackGC(L, fsize); 485 L->top = prevf + i; /* correct top */
489 func = ci->func; /* moved-down function */ 486}
490 for (; narg1 <= nfixparams; narg1++) 487
491 setnilvalue(s2v(func + narg1)); /* complete missing arguments */ 488
492 ci->top = func + 1 + fsize; /* top for new function */ 489static CallInfo *prepCallInfo (lua_State *L, StkId func, int retdel,
493 lua_assert(ci->top <= L->stack_last); 490 int mask) {
494 ci->u.l.savedpc = p->code; /* starting point */ 491 CallInfo *ci;
495 ci->callstatus |= CIST_TAIL; 492 if (isdelta(retdel)) { /* tail call? */
496 L->top = func + narg1; /* set top */ 493 ci = L->ci; /* reuse stack frame */
494 ci->func -= retdel2delta(retdel); /* correct 'func' */
495 ci->callstatus |= mask | CIST_TAIL;
496 moveparams(L, ci->func, func);
497 }
498 else { /* regular call */
499 ci = L->ci = next_ci(L); /* new frame */
500 ci->func = func;
501 ci->nresults = retdel;
502 ci->callstatus = mask;
503 }
504 return ci;
497} 505}
498 506
499 507
@@ -504,8 +512,12 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) {
504** to be executed, if it was a Lua function. Otherwise (a C function) 512** to be executed, if it was a Lua function. Otherwise (a C function)
505** returns NULL, with all the results on the stack, starting at the 513** returns NULL, with all the results on the stack, starting at the
506** original function position. 514** 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.
507*/ 519*/
508CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { 520CallInfo *luaD_precall (lua_State *L, StkId func, int retdel) {
509 lua_CFunction f; 521 lua_CFunction f;
510 retry: 522 retry:
511 switch (ttypetag(s2v(func))) { 523 switch (ttypetag(s2v(func))) {
@@ -518,11 +530,8 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
518 int n; /* number of returns */ 530 int n; /* number of returns */
519 CallInfo *ci; 531 CallInfo *ci;
520 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ 532 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
521 L->ci = ci = next_ci(L); 533 ci = prepCallInfo(L, func, retdel, CIST_C);
522 ci->nresults = nresults;
523 ci->callstatus = CIST_C;
524 ci->top = L->top + LUA_MINSTACK; 534 ci->top = L->top + LUA_MINSTACK;
525 ci->func = func;
526 lua_assert(ci->top <= L->stack_last); 535 lua_assert(ci->top <= L->stack_last);
527 if (l_unlikely(L->hookmask & LUA_MASKCALL)) { 536 if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
528 int narg = cast_int(L->top - func) - 1; 537 int narg = cast_int(L->top - func) - 1;
@@ -542,12 +551,9 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
542 int nfixparams = p->numparams; 551 int nfixparams = p->numparams;
543 int fsize = p->maxstacksize; /* frame size */ 552 int fsize = p->maxstacksize; /* frame size */
544 checkstackGCp(L, fsize, func); 553 checkstackGCp(L, fsize, func);
545 L->ci = ci = next_ci(L); 554 ci = prepCallInfo(L, func, retdel, 0);
546 ci->nresults = nresults;
547 ci->u.l.savedpc = p->code; /* starting point */ 555 ci->u.l.savedpc = p->code; /* starting point */
548 ci->top = func + 1 + fsize; 556 ci->top = func + 1 + fsize;
549 ci->func = func;
550 L->ci = ci;
551 for (; narg < nfixparams; narg++) 557 for (; narg < nfixparams; narg++)
552 setnilvalue(s2v(L->top++)); /* complete missing arguments */ 558 setnilvalue(s2v(L->top++)); /* complete missing arguments */
553 lua_assert(ci->top <= L->stack_last); 559 lua_assert(ci->top <= L->stack_last);