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
3
** Stack and Call structure of Lua
4
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
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
409
** (so that it includes the function itself).
410
410
*/
411
- void luaD_pretailcall (lua_State * L , CallInfo * ci , StkId func , int n ) {
411
+ void luaD_pretailcall (lua_State * L , CallInfo * ci , StkId func , int narg1 ) {
412
412
Proto * p = clLvalue (s2v (func ))-> p ;
413
413
int fsize = p -> maxstacksize ; /* frame size */
414
+ int nfixparams = p -> numparams ;
414
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
417
setobjs2s (L , ci -> func + i , func + i );
417
418
checkstackp (L , fsize , func );
418
- for (; i <= p -> numparams ; i ++ )
419
- setnilvalue (s2v (ci -> func + i )); /* complete missing arguments */
420
- ci -> top = ci -> func + 1 + fsize ; /* top for new function */
419
+ func = ci -> func ; /* moved-down function */
420
+ for (; narg1 <= nfixparams ; narg1 ++ )
421
+ setnilvalue (s2v (func + narg1 )); /* complete missing arguments */
422
+ ci -> top = func + 1 + fsize ; /* top for new function */
421
423
lua_assert (ci -> top <= L -> stack_last );
422
424
ci -> u .l .savedpc = p -> code ; /* starting point */
423
425
ci -> callstatus |= CIST_TAIL ;
424
426
if (p -> is_vararg ) {
425
- L -> top -= ( func - ci -> func ) ; /* move down top */
426
- luaT_adjustvarargs (L , p , n - 1 );
427
+ L -> top = func + narg1 ; /* set top */
428
+ luaT_adjustvarargs (L , nfixparams , narg1 - 1 );
427
429
}
428
430
if (L -> hookmask )
429
431
hookcall (L , ci , 1 );
@@ -464,12 +466,13 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
464
466
luaD_poscall (L , ci , L -> top - n , n );
465
467
break ;
466
468
}
467
- case LUA_TLCL : { /* Lua function: prepare its call */
469
+ case LUA_TLCL : { /* Lua function */
468
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
473
int fsize = p -> maxstacksize ; /* frame size */
471
474
checkstackp (L , fsize , func );
472
- for (; n < p -> numparams ; n ++ )
475
+ for (; narg < nfixparams ; narg ++ )
473
476
setnilvalue (s2v (L -> top ++ )); /* complete missing arguments */
474
477
ci = next_ci (L ); /* now 'enter' new function */
475
478
ci -> nresults = nresults ;
@@ -479,7 +482,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
479
482
ci -> u .l .savedpc = p -> code ; /* starting point */
480
483
ci -> callstatus = 0 ;
481
484
if (p -> is_vararg )
482
- luaT_adjustvarargs (L , p , n ); /* may invoke GC */
485
+ luaT_adjustvarargs (L , nfixparams , narg ); /* may invoke GC */
483
486
if (L -> hookmask )
484
487
hookcall (L , ci , 0 );
485
488
luaV_execute (L , ci ); /* run the function */
0 commit comments