aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-03-26 09:57:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-03-26 09:57:01 -0300
commit3dbf30540892b4b9c86e0cb663069cd478a0c900 (patch)
tree0a86ef692b04ce14b57734b0034452e32aadd610
parent6d0ae11c576106b490a53215c3f227b65ace2776 (diff)
downloadlua-3dbf30540892b4b9c86e0cb663069cd478a0c900.tar.gz
lua-3dbf30540892b4b9c86e0cb663069cd478a0c900.tar.bz2
lua-3dbf30540892b4b9c86e0cb663069cd478a0c900.zip
no more support for old-style varargs
-rw-r--r--ldebug.c8
-rw-r--r--ldo.c22
-rw-r--r--lobject.h8
-rw-r--r--lparser.c14
-rw-r--r--luaconf.h9
5 files changed, 10 insertions, 51 deletions
diff --git a/ldebug.c b/ldebug.c
index 64ad70eb..8492a97b 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.43 2009/03/04 13:32:29 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.44 2009/03/10 17:14:37 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -278,8 +278,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
278 278
279static int precheck (const Proto *pt) { 279static int precheck (const Proto *pt) {
280 check(pt->maxstacksize <= MAXSTACK); 280 check(pt->maxstacksize <= MAXSTACK);
281 check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); 281 check(pt->numparams <= pt->maxstacksize);
282 check(!(pt->is_vararg & VARARG_NEEDSARG) || (pt->is_vararg & VARARG_HASARG));
283 check(pt->sizeupvalues == pt->nups || pt->sizeupvalues == 0); 282 check(pt->sizeupvalues == pt->nups || pt->sizeupvalues == 0);
284 check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0); 283 check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
285 check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); 284 check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
@@ -445,8 +444,7 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
445 break; 444 break;
446 } 445 }
447 case OP_VARARG: { 446 case OP_VARARG: {
448 check((pt->is_vararg & VARARG_ISVARARG) && 447 check(pt->is_vararg);
449 !(pt->is_vararg & VARARG_NEEDSARG));
450 b--; 448 b--;
451 if (b == LUA_MULTRET) check(checkopenop(pt, pc)); 449 if (b == LUA_MULTRET) check(checkopenop(pt, pc));
452 checkreg(pt, a+b-1); 450 checkreg(pt, a+b-1);
diff --git a/ldo.c b/ldo.c
index b89a2919..2afcd7af 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.55 2009/03/10 17:14:37 roberto Exp roberto $ 2** $Id: ldo.c,v 2.56 2009/03/23 14:26:12 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*/
@@ -205,24 +205,9 @@ void luaD_callhook (lua_State *L, int event, int line) {
205static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { 205static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
206 int i; 206 int i;
207 int nfixargs = p->numparams; 207 int nfixargs = p->numparams;
208 Table *htab = NULL;
209 StkId base, fixed; 208 StkId base, fixed;
210 for (; actual < nfixargs; ++actual) 209 for (; actual < nfixargs; ++actual)
211 setnilvalue(L->top++); 210 setnilvalue(L->top++);
212#if defined(LUA_COMPAT_VARARG)
213 if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */
214 int nvar = actual - nfixargs; /* number of extra arguments */
215 lua_assert(p->is_vararg & VARARG_HASARG);
216 luaC_checkGC(L);
217 htab = luaH_new(L); /* create `arg' table */
218 sethvalue(L, L->top++, htab);
219 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */
220 setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i - 1);
221 /* store counter in field `n' */
222 setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar));
223 L->top--;
224 }
225#endif
226 /* move fixed parameters to final position */ 211 /* move fixed parameters to final position */
227 fixed = L->top - actual; /* first fixed argument */ 212 fixed = L->top - actual; /* first fixed argument */
228 base = L->top; /* final position of first argument */ 213 base = L->top; /* final position of first argument */
@@ -230,11 +215,6 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
230 setobjs2s(L, L->top++, fixed+i); 215 setobjs2s(L, L->top++, fixed+i);
231 setnilvalue(fixed+i); 216 setnilvalue(fixed+i);
232 } 217 }
233 /* add `arg' parameter */
234 if (htab) {
235 sethvalue(L, L->top++, htab);
236 lua_assert(iswhite(obj2gco(htab)));
237 }
238 return base; 218 return base;
239} 219}
240 220
diff --git a/lobject.h b/lobject.h
index 8b60155f..3172cda6 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.23 2008/01/30 18:05:23 roberto Exp roberto $ 2** $Id: lobject.h,v 2.24 2008/08/05 19:26:23 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*/
@@ -253,12 +253,6 @@ typedef struct Proto {
253} Proto; 253} Proto;
254 254
255 255
256/* masks for new-style vararg */
257#define VARARG_HASARG 1
258#define VARARG_ISVARARG 2
259#define VARARG_NEEDSARG 4
260
261
262typedef struct LocVar { 256typedef struct LocVar {
263 TString *varname; 257 TString *varname;
264 int startpc; /* first point where variable is active */ 258 int startpc; /* first point where variable is active */
diff --git a/lparser.c b/lparser.c
index 562e2f96..e99bb342 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.59 2008/10/28 12:55:00 roberto Exp roberto $ 2** $Id: lparser.c,v 2.60 2008/10/30 15:39:30 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*/
@@ -394,7 +394,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
394 lexstate.buff = buff; 394 lexstate.buff = buff;
395 luaX_setinput(L, &lexstate, z, tname); 395 luaX_setinput(L, &lexstate, z, tname);
396 open_func(&lexstate, &funcstate); 396 open_func(&lexstate, &funcstate);
397 funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ 397 funcstate.f->is_vararg = 1; /* main func. is always vararg */
398 luaX_next(&lexstate); /* read first token */ 398 luaX_next(&lexstate); /* read first token */
399 chunk(&lexstate); 399 chunk(&lexstate);
400 check(&lexstate, TK_EOS); 400 check(&lexstate, TK_EOS);
@@ -563,12 +563,7 @@ static void parlist (LexState *ls) {
563 } 563 }
564 case TK_DOTS: { /* param -> `...' */ 564 case TK_DOTS: { /* param -> `...' */
565 luaX_next(ls); 565 luaX_next(ls);
566#if defined(LUA_COMPAT_VARARG) 566 f->is_vararg = 1;
567 /* use `arg' as default name */
568 new_localvarliteral(ls, "arg", nparams++);
569 f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG;
570#endif
571 f->is_vararg |= VARARG_ISVARARG;
572 break; 567 break;
573 } 568 }
574 default: luaX_syntaxerror(ls, "<name> or " LUA_QL("...") " expected"); 569 default: luaX_syntaxerror(ls, "<name> or " LUA_QL("...") " expected");
@@ -576,7 +571,7 @@ static void parlist (LexState *ls) {
576 } while (!f->is_vararg && testnext(ls, ',')); 571 } while (!f->is_vararg && testnext(ls, ','));
577 } 572 }
578 adjustlocalvars(ls, nparams); 573 adjustlocalvars(ls, nparams);
579 f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG)); 574 f->numparams = cast_byte(fs->nactvar);
580 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ 575 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
581} 576}
582 577
@@ -761,7 +756,6 @@ static void simpleexp (LexState *ls, expdesc *v) {
761 FuncState *fs = ls->fs; 756 FuncState *fs = ls->fs;
762 check_condition(ls, fs->f->is_vararg, 757 check_condition(ls, fs->f->is_vararg,
763 "cannot use " LUA_QL("...") " outside a vararg function"); 758 "cannot use " LUA_QL("...") " outside a vararg function");
764 fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */
765 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); 759 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
766 break; 760 break;
767 } 761 }
diff --git a/luaconf.h b/luaconf.h
index 9da44ea5..a848f2e0 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.102 2009/02/18 13:17:10 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.103 2009/02/20 13:50:27 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -352,13 +352,6 @@
352 352
353 353
354/* 354/*
355@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
356** CHANGE it to undefined as soon as your programs use only '...' to
357** access vararg parameters (instead of the old 'arg' table).
358*/
359#define LUA_COMPAT_VARARG
360
361/*
362@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. 355@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
363** CHANGE it to undefined as soon as you rename 'string.gfind' to 356** CHANGE it to undefined as soon as you rename 'string.gfind' to
364** 'string.gmatch'. 357** 'string.gmatch'.