aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/ldo.c b/ldo.c
index 50ab0012..15bec173 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.186 2018/01/10 19:19:27 roberto Exp roberto $ 2** $Id: ldo.c,v 2.187 2018/01/28 12:08:04 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -405,25 +405,27 @@ void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {
405 405
406/* 406/*
407** Prepare a function for a tail call, building its call info on top 407** Prepare a function for a tail call, building its call info on top
408** of the current call info. 'n' is the number of arguments plus 1 408** of the current call info. 'narg1' is the number of arguments plus 1
409** (so that it includes the function itself). 409** (so that it includes the function itself).
410*/ 410*/
411void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n) { 411void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) {
412 Proto *p = clLvalue(s2v(func))->p; 412 Proto *p = clLvalue(s2v(func))->p;
413 int fsize = p->maxstacksize; /* frame size */ 413 int fsize = p->maxstacksize; /* frame size */
414 int nfixparams = p->numparams;
414 int i; 415 int i;
415 for (i = 0; i < n; i++) /* move down function and arguments */ 416 for (i = 0; i < narg1; i++) /* move down function and arguments */
416 setobjs2s(L, ci->func + i, func + i); 417 setobjs2s(L, ci->func + i, func + i);
417 checkstackp(L, fsize, func); 418 checkstackp(L, fsize, func);
418 for (; i <= p->numparams; i++) 419 func = ci->func; /* moved-down function */
419 setnilvalue(s2v(ci->func + i)); /* complete missing arguments */ 420 for (; narg1 <= nfixparams; narg1++)
420 ci->top = ci->func + 1 + fsize; /* top for new function */ 421 setnilvalue(s2v(func + narg1)); /* complete missing arguments */
422 ci->top = func + 1 + fsize; /* top for new function */
421 lua_assert(ci->top <= L->stack_last); 423 lua_assert(ci->top <= L->stack_last);
422 ci->u.l.savedpc = p->code; /* starting point */ 424 ci->u.l.savedpc = p->code; /* starting point */
423 ci->callstatus |= CIST_TAIL; 425 ci->callstatus |= CIST_TAIL;
424 if (p->is_vararg) { 426 if (p->is_vararg) {
425 L->top -= (func - ci->func); /* move down top */ 427 L->top = func + narg1; /* set top */
426 luaT_adjustvarargs(L, p, n - 1); 428 luaT_adjustvarargs(L, nfixparams, narg1 - 1);
427 } 429 }
428 if (L->hookmask) 430 if (L->hookmask)
429 hookcall(L, ci, 1); 431 hookcall(L, ci, 1);
@@ -464,12 +466,13 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
464 luaD_poscall(L, ci, L->top - n, n); 466 luaD_poscall(L, ci, L->top - n, n);
465 break; 467 break;
466 } 468 }
467 case LUA_TLCL: { /* Lua function: prepare its call */ 469 case LUA_TLCL: { /* Lua function */
468 Proto *p = clLvalue(funcv)->p; 470 Proto *p = clLvalue(funcv)->p;
469 int n = cast_int(L->top - func) - 1; /* number of real arguments */ 471 int narg = cast_int(L->top - func) - 1; /* number of real arguments */
472 int nfixparams = p->numparams;
470 int fsize = p->maxstacksize; /* frame size */ 473 int fsize = p->maxstacksize; /* frame size */
471 checkstackp(L, fsize, func); 474 checkstackp(L, fsize, func);
472 for (; n < p->numparams; n++) 475 for (; narg < nfixparams; narg++)
473 setnilvalue(s2v(L->top++)); /* complete missing arguments */ 476 setnilvalue(s2v(L->top++)); /* complete missing arguments */
474 ci = next_ci(L); /* now 'enter' new function */ 477 ci = next_ci(L); /* now 'enter' new function */
475 ci->nresults = nresults; 478 ci->nresults = nresults;
@@ -479,7 +482,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
479 ci->u.l.savedpc = p->code; /* starting point */ 482 ci->u.l.savedpc = p->code; /* starting point */
480 ci->callstatus = 0; 483 ci->callstatus = 0;
481 if (p->is_vararg) 484 if (p->is_vararg)
482 luaT_adjustvarargs(L, p, n); /* may invoke GC */ 485 luaT_adjustvarargs(L, nfixparams, narg); /* may invoke GC */
483 if (L->hookmask) 486 if (L->hookmask)
484 hookcall(L, ci, 0); 487 hookcall(L, ci, 0);
485 luaV_execute(L, ci); /* run the function */ 488 luaV_execute(L, ci); /* run the function */