Browse Source

'Proto->numparams' does not include vararg parameter

(one less subtraction when calling functions...)
pull/15/head
Roberto Ierusalimschy 7 years ago
parent
commit
b3f924bc69
  1. 4
      ldebug.c
  2. 6
      ldo.c
  3. 9
      lparser.c
  4. 4
      ltm.c

4
ldebug.c

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 2.147 2017/12/07 15:44:10 roberto Exp roberto $
** $Id: ldebug.c,v 2.148 2017/12/13 18:32:09 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -328,7 +328,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
}
else {
ar->isvararg = f->l.p->is_vararg;
ar->nparams = f->l.p->numparams;
ar->nparams = f->l.p->numparams + f->l.p->is_vararg;
}
break;
}

6
ldo.c

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 2.179 2017/12/11 12:43:40 roberto Exp roberto $
** $Id: ldo.c,v 2.180 2017/12/12 11:57:30 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -415,7 +415,7 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n) {
for (i = 0; i < n; i++) /* move down function and arguments */
setobjs2s(L, ci->func + i, func + i);
checkstackp(L, fsize, func);
for (; i < p->numparams - p->is_vararg; i++)
for (; i < p->numparams; i++)
setnilvalue(s2v(ci->func + i)); /* complete missing parameters */
if (p->is_vararg) {
L->top -= (func - ci->func); /* move down top */
@ -469,7 +469,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
int n = cast_int(L->top - func) - 1; /* number of real arguments */
int fsize = p->maxstacksize; /* frame size */
checkstackp(L, fsize, func);
for (; n < p->numparams - p->is_vararg; n++)
for (; n < p->numparams; n++)
setnilvalue(s2v(L->top++)); /* complete missing arguments */
if (p->is_vararg)
luaT_adjustvarargs(L, p, n);

9
lparser.c

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 2.170 2017/12/06 18:36:31 roberto Exp roberto $
** $Id: lparser.c,v 2.171 2017/12/14 14:24:02 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@ -765,7 +765,6 @@ static void parlist (LexState *ls) {
FuncState *fs = ls->fs;
Proto *f = fs->f;
int nparams = 0;
f->is_vararg = 0;
if (ls->t.token != ')') { /* is 'parlist' not empty? */
do {
switch (ls->t.token) {
@ -789,7 +788,7 @@ static void parlist (LexState *ls) {
} while (!f->is_vararg && testnext(ls, ','));
}
adjustlocalvars(ls, nparams);
f->numparams = cast_byte(fs->nactvar);
f->numparams = cast_byte(fs->nactvar) - f->is_vararg;
luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
}
@ -975,7 +974,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
}
case TK_DOTS: { /* vararg */
FuncState *fs = ls->fs;
int lastparam = fs->f->numparams - 1;
int lastparam = fs->f->numparams;
check_condition(ls, fs->f->is_vararg,
"cannot use '...' outside a vararg function");
init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, lastparam));
@ -1676,7 +1675,7 @@ static void mainfunc (LexState *ls, FuncState *fs) {
expdesc v;
open_func(ls, fs, &bl);
fs->f->is_vararg = 1; /* main function is always declared vararg */
fs->f->numparams = 1;
fs->f->numparams = 0;
new_localvarliteral(ls, "_ARG");
adjustlocalvars(ls, 1);
luaK_reserveregs(fs, 1); /* reserve register for vararg */

4
ltm.c

@ -1,5 +1,5 @@
/*
** $Id: ltm.c,v 2.51 2017/11/30 15:37:16 roberto Exp roberto $
** $Id: ltm.c,v 2.52 2017/12/13 18:32:09 roberto Exp roberto $
** Tag methods
** See Copyright Notice in lua.h
*/
@ -219,7 +219,7 @@ void luaT_adjustvarargs (lua_State *L, Proto *p, int actual) {
int i;
Table *vtab;
TValue nname;
int nfixparams = p->numparams - 1; /* number of fixed parameters */
int nfixparams = p->numparams; /* number of fixed parameters */
actual -= nfixparams; /* number of extra arguments */
vtab = luaH_new(L); /* create vararg table */
sethvalue2s(L, L->top, vtab); /* anchor it for resizing */

Loading…
Cancel
Save