Browse Source

do not eliminate varargs from functions that do not use varargs

(confuses the debug lib and gains very little in performance)
pull/9/head
Roberto Ierusalimschy 8 years ago
parent
commit
e4a9e6fcca
  1. 8
      ldo.c
  2. 4
      lobject.h
  3. 7
      lparser.c

8
ldo.c

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 2.151 2015/12/16 16:40:07 roberto Exp roberto $
** $Id: ldo.c,v 2.152 2016/07/29 17:12:44 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -374,13 +374,13 @@ int luaD_precall (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);
if (p->is_vararg != 1) { /* do not use vararg? */
if (p->is_vararg)
base = adjust_varargs(L, p, n);
else { /* non vararg function */
for (; n < p->numparams; n++)
setnilvalue(L->top++); /* complete missing arguments */
base = func + 1;
}
else
base = adjust_varargs(L, p, n);
ci = next_ci(L); /* now 'enter' new function */
ci->nresults = nresults;
ci->func = func;

4
lobject.h

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 2.115 2015/10/28 17:28:40 roberto Exp roberto $
** $Id: lobject.h,v 2.116 2015/11/03 18:33:10 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -407,7 +407,7 @@ typedef struct LocVar {
typedef struct Proto {
CommonHeader;
lu_byte numparams; /* number of fixed parameters */
lu_byte is_vararg; /* 2: declared vararg; 1: uses vararg */
lu_byte is_vararg;
lu_byte maxstacksize; /* number of registers needed by this function */
int sizeupvalues; /* size of 'upvalues' */
int sizek; /* size of 'k' */

7
lparser.c

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 2.153 2016/05/13 19:10:16 roberto Exp roberto $
** $Id: lparser.c,v 2.154 2016/06/22 15:48:25 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@ -766,7 +766,7 @@ static void parlist (LexState *ls) {
}
case TK_DOTS: { /* param -> '...' */
luaX_next(ls);
f->is_vararg = 2; /* declared vararg */
f->is_vararg = 1; /* declared vararg */
break;
}
default: luaX_syntaxerror(ls, "<name> or '...' expected");
@ -962,7 +962,6 @@ static void simpleexp (LexState *ls, expdesc *v) {
FuncState *fs = ls->fs;
check_condition(ls, fs->f->is_vararg,
"cannot use '...' outside a vararg function");
fs->f->is_vararg = 1; /* function actually uses vararg */
init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
break;
}
@ -1614,7 +1613,7 @@ static void mainfunc (LexState *ls, FuncState *fs) {
BlockCnt bl;
expdesc v;
open_func(ls, fs, &bl);
fs->f->is_vararg = 2; /* main function is always declared vararg */
fs->f->is_vararg = 1; /* main function is always declared vararg */
init_exp(&v, VLOCAL, 0); /* create and... */
newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */
luaX_next(ls); /* read first token */

Loading…
Cancel
Save