diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-13 10:04:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-13 10:04:33 -0300 |
commit | 5c8770f8969a73cf4ca503f54c2217f76de62e04 (patch) | |
tree | d5dac87490011d117277d94c81f6f2fd47b1b094 /ldo.c | |
parent | 7647d5d13d016f114dac4be0b9da62d502eab400 (diff) | |
download | lua-5c8770f8969a73cf4ca503f54c2217f76de62e04.tar.gz lua-5c8770f8969a73cf4ca503f54c2217f76de62e04.tar.bz2 lua-5c8770f8969a73cf4ca503f54c2217f76de62e04.zip |
back to old-style vararg system (with vararg table collecting extra
arguments)
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 41 |
1 files changed, 6 insertions, 35 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.156 2016/09/20 16:37:45 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.157 2016/12/13 15:52:21 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 | */ |
@@ -290,23 +290,6 @@ static void callhook (lua_State *L, CallInfo *ci) { | |||
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
293 | static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { | ||
294 | int i; | ||
295 | int nfixargs = p->numparams; | ||
296 | StkId base, fixed; | ||
297 | /* move fixed parameters to final position */ | ||
298 | fixed = L->top - actual; /* first fixed argument */ | ||
299 | base = L->top; /* final position of first argument */ | ||
300 | for (i = 0; i < nfixargs && i < actual; i++) { | ||
301 | setobjs2s(L, L->top++, fixed + i); | ||
302 | setnilvalue(fixed + i); /* erase original copy (for GC) */ | ||
303 | } | ||
304 | for (; i < nfixargs; i++) | ||
305 | setnilvalue(L->top++); /* complete missing arguments */ | ||
306 | return base; | ||
307 | } | ||
308 | |||
309 | |||
310 | /* | 293 | /* |
311 | ** Check whether __call metafield of 'func' is a function. If so, put | 294 | ** Check whether __call metafield of 'func' is a function. If so, put |
312 | ** it in stack below original 'func' so that 'luaD_precall' can call | 295 | ** it in stack below original 'func' so that 'luaD_precall' can call |
@@ -395,14 +378,6 @@ int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { | |||
395 | #define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L))) | 378 | #define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L))) |
396 | 379 | ||
397 | 380 | ||
398 | /* macro to check stack size, preserving 'p' */ | ||
399 | #define checkstackp(L,n,p) \ | ||
400 | luaD_checkstackaux(L, n, \ | ||
401 | ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \ | ||
402 | luaC_checkGC(L), /* stack grow uses memory */ \ | ||
403 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */ | ||
404 | |||
405 | |||
406 | /* | 381 | /* |
407 | ** Prepares a function call: checks the stack, creates a new CallInfo | 382 | ** Prepares a function call: checks the stack, creates a new CallInfo |
408 | ** entry, fills in the relevant information, calls hook if needed. | 383 | ** entry, fills in the relevant information, calls hook if needed. |
@@ -438,23 +413,19 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
438 | return 1; | 413 | return 1; |
439 | } | 414 | } |
440 | case LUA_TLCL: { /* Lua function: prepare its call */ | 415 | case LUA_TLCL: { /* Lua function: prepare its call */ |
441 | StkId base; | ||
442 | Proto *p = clLvalue(func)->p; | 416 | Proto *p = clLvalue(func)->p; |
443 | int n = cast_int(L->top - func) - 1; /* number of real arguments */ | 417 | int n = cast_int(L->top - func) - 1; /* number of real arguments */ |
444 | int fsize = p->maxstacksize; /* frame size */ | 418 | int fsize = p->maxstacksize; /* frame size */ |
445 | checkstackp(L, fsize, func); | 419 | checkstackp(L, fsize, func); |
420 | for (; n < p->numparams - p->is_vararg; n++) | ||
421 | setnilvalue(L->top++); /* complete missing arguments */ | ||
446 | if (p->is_vararg) | 422 | if (p->is_vararg) |
447 | base = adjust_varargs(L, p, n); | 423 | luaT_adjustvarargs(L, p, n); |
448 | else { /* non vararg function */ | ||
449 | for (; n < p->numparams; n++) | ||
450 | setnilvalue(L->top++); /* complete missing arguments */ | ||
451 | base = func + 1; | ||
452 | } | ||
453 | ci = next_ci(L); /* now 'enter' new function */ | 424 | ci = next_ci(L); /* now 'enter' new function */ |
454 | ci->nresults = nresults; | 425 | ci->nresults = nresults; |
455 | ci->func = func; | 426 | ci->func = func; |
456 | ci->u.l.base = base; | 427 | ci->u.l.base = func + 1; |
457 | L->top = ci->top = base + fsize; | 428 | L->top = ci->top = func + 1 + fsize; |
458 | lua_assert(ci->top <= L->stack_last); | 429 | lua_assert(ci->top <= L->stack_last); |
459 | ci->u.l.savedpc = p->code; /* starting point */ | 430 | ci->u.l.savedpc = p->code; /* starting point */ |
460 | ci->callstatus = CIST_LUA; | 431 | ci->callstatus = CIST_LUA; |