Browse Source

function prepares vararg only if it really uses them (chunks

are always declared vararg but seldom uses them)
pull/9/head
Roberto Ierusalimschy 9 years ago
parent
commit
6707ce6349
  1. 4
      ldo.c
  2. 4
      lobject.h
  3. 7
      lparser.c

4
ldo.c

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 2.142 2015/10/28 12:06:45 roberto Exp roberto $
** $Id: ldo.c,v 2.143 2015/10/28 12:25:36 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -357,7 +357,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
checkstackp(L, p->maxstacksize, func);
for (; n < p->numparams; n++)
setnilvalue(L->top++); /* complete missing arguments */
if (!p->is_vararg)
if (p->is_vararg != 1) /* do not use vararg? */
base = func + 1;
else {
ptrdiff_t funcr = savestack(L, func);

4
lobject.h

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 2.113 2015/09/08 16:54:52 roberto Exp roberto $
** $Id: lobject.h,v 2.114 2015/09/17 15:51:05 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;
lu_byte is_vararg; /* 2: declared vararg; 1: uses 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.146 2014/11/27 18:41:43 roberto Exp roberto $
** $Id: lparser.c,v 2.147 2014/12/27 20:31:43 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@ -760,7 +760,7 @@ static void parlist (LexState *ls) {
}
case TK_DOTS: { /* param -> '...' */
luaX_next(ls);
f->is_vararg = 1;
f->is_vararg = 2; /* declared vararg */
break;
}
default: luaX_syntaxerror(ls, "<name> or '...' expected");
@ -956,6 +956,7 @@ 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;
}
@ -1610,7 +1611,7 @@ static void mainfunc (LexState *ls, FuncState *fs) {
BlockCnt bl;
expdesc v;
open_func(ls, fs, &bl);
fs->f->is_vararg = 1; /* main function is always vararg */
fs->f->is_vararg = 2; /* 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