summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-10-28 15:28:40 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-10-28 15:28:40 -0200
commit6707ce63491ad5f233f30b1d561ed7f0f0b9a0c8 (patch)
treebe151820c74eb2ebc4655783a100c96504c107aa
parent257961c601fdec1ea1f9640d460e0d31c39333a1 (diff)
downloadlua-6707ce63491ad5f233f30b1d561ed7f0f0b9a0c8.tar.gz
lua-6707ce63491ad5f233f30b1d561ed7f0f0b9a0c8.tar.bz2
lua-6707ce63491ad5f233f30b1d561ed7f0f0b9a0c8.zip
function prepares vararg only if it really uses them (chunks
are always declared vararg but seldom uses them)
-rw-r--r--ldo.c4
-rw-r--r--lobject.h4
-rw-r--r--lparser.c7
3 files changed, 8 insertions, 7 deletions
diff --git a/ldo.c b/ldo.c
index 564bacd4..0cb6173b 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.142 2015/10/28 12:06:45 roberto Exp roberto $ 2** $Id: ldo.c,v 2.143 2015/10/28 12:25:36 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*/
@@ -357,7 +357,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
357 checkstackp(L, p->maxstacksize, func); 357 checkstackp(L, p->maxstacksize, func);
358 for (; n < p->numparams; n++) 358 for (; n < p->numparams; n++)
359 setnilvalue(L->top++); /* complete missing arguments */ 359 setnilvalue(L->top++); /* complete missing arguments */
360 if (!p->is_vararg) 360 if (p->is_vararg != 1) /* do not use vararg? */
361 base = func + 1; 361 base = func + 1;
362 else { 362 else {
363 ptrdiff_t funcr = savestack(L, func); 363 ptrdiff_t funcr = savestack(L, func);
diff --git a/lobject.h b/lobject.h
index e095f43f..7a9c0707 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.113 2015/09/08 16:54:52 roberto Exp roberto $ 2** $Id: lobject.h,v 2.114 2015/09/17 15:51:05 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -407,7 +407,7 @@ typedef struct LocVar {
407typedef struct Proto { 407typedef struct Proto {
408 CommonHeader; 408 CommonHeader;
409 lu_byte numparams; /* number of fixed parameters */ 409 lu_byte numparams; /* number of fixed parameters */
410 lu_byte is_vararg; 410 lu_byte is_vararg; /* 2: declared vararg; 1: uses vararg */
411 lu_byte maxstacksize; /* number of registers needed by this function */ 411 lu_byte maxstacksize; /* number of registers needed by this function */
412 int sizeupvalues; /* size of 'upvalues' */ 412 int sizeupvalues; /* size of 'upvalues' */
413 int sizek; /* size of 'k' */ 413 int sizek; /* size of 'k' */
diff --git a/lparser.c b/lparser.c
index d65e8884..e621f680 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.146 2014/11/27 18:41:43 roberto Exp roberto $ 2** $Id: lparser.c,v 2.147 2014/12/27 20:31:43 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -760,7 +760,7 @@ static void parlist (LexState *ls) {
760 } 760 }
761 case TK_DOTS: { /* param -> '...' */ 761 case TK_DOTS: { /* param -> '...' */
762 luaX_next(ls); 762 luaX_next(ls);
763 f->is_vararg = 1; 763 f->is_vararg = 2; /* declared vararg */
764 break; 764 break;
765 } 765 }
766 default: luaX_syntaxerror(ls, "<name> or '...' expected"); 766 default: luaX_syntaxerror(ls, "<name> or '...' expected");
@@ -956,6 +956,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
956 FuncState *fs = ls->fs; 956 FuncState *fs = ls->fs;
957 check_condition(ls, fs->f->is_vararg, 957 check_condition(ls, fs->f->is_vararg,
958 "cannot use '...' outside a vararg function"); 958 "cannot use '...' outside a vararg function");
959 fs->f->is_vararg = 1; /* function actually uses vararg */
959 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); 960 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
960 break; 961 break;
961 } 962 }
@@ -1610,7 +1611,7 @@ static void mainfunc (LexState *ls, FuncState *fs) {
1610 BlockCnt bl; 1611 BlockCnt bl;
1611 expdesc v; 1612 expdesc v;
1612 open_func(ls, fs, &bl); 1613 open_func(ls, fs, &bl);
1613 fs->f->is_vararg = 1; /* main function is always vararg */ 1614 fs->f->is_vararg = 2; /* main function is always declared vararg */
1614 init_exp(&v, VLOCAL, 0); /* create and... */ 1615 init_exp(&v, VLOCAL, 0); /* create and... */
1615 newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */ 1616 newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */
1616 luaX_next(ls); /* read first token */ 1617 luaX_next(ls); /* read first token */