diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-07-29 15:51:00 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-07-29 15:51:00 -0300 |
commit | e89945aaa1f42cb41f401c44c56ed0c4a98004c6 (patch) | |
tree | e6c10116e2250192f6f462613b3e85404c8e9edc | |
parent | d407d3fe0eb44b9bad0b5f37e55400b8eeb095ec (diff) | |
download | lua-e89945aaa1f42cb41f401c44c56ed0c4a98004c6.tar.gz lua-e89945aaa1f42cb41f401c44c56ed0c4a98004c6.tar.bz2 lua-e89945aaa1f42cb41f401c44c56ed0c4a98004c6.zip |
syntax `...=var' changed to `var=...'
-rw-r--r-- | lparser.c | 45 |
1 files changed, 20 insertions, 25 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.213 2003/07/09 20:11:30 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.214 2003/07/28 18:31:20 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 | */ |
@@ -264,23 +264,6 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { | |||
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
267 | static void code_params (LexState *ls, int nparams, TString *dots) { | ||
268 | FuncState *fs = ls->fs; | ||
269 | Proto *f = fs->f; | ||
270 | adjustlocalvars(ls, nparams); | ||
271 | luaX_checklimit(ls, fs->nactvar, MAXPARAMS, "parameters"); | ||
272 | f->numparams = fs->nactvar; | ||
273 | if (!dots) | ||
274 | f->is_vararg = 0; | ||
275 | else { | ||
276 | f->is_vararg = 1; | ||
277 | new_localvar(ls, dots, 0); | ||
278 | adjustlocalvars(ls, 1); | ||
279 | } | ||
280 | luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ | ||
281 | } | ||
282 | |||
283 | |||
284 | static void enterblock (FuncState *fs, BlockCnt *bl, int isbreakable) { | 267 | static void enterblock (FuncState *fs, BlockCnt *bl, int isbreakable) { |
285 | bl->breaklist = NO_JUMP; | 268 | bl->breaklist = NO_JUMP; |
286 | bl->isbreakable = isbreakable; | 269 | bl->isbreakable = isbreakable; |
@@ -529,23 +512,35 @@ static void constructor (LexState *ls, expdesc *t) { | |||
529 | 512 | ||
530 | static void parlist (LexState *ls) { | 513 | static void parlist (LexState *ls) { |
531 | /* parlist -> [ param { `,' param } ] */ | 514 | /* parlist -> [ param { `,' param } ] */ |
515 | FuncState *fs = ls->fs; | ||
516 | Proto *f = fs->f; | ||
532 | int nparams = 0; | 517 | int nparams = 0; |
533 | TString *dots = NULL; | 518 | f->is_vararg = 0; |
534 | if (ls->t.token != ')') { /* is `parlist' not empty? */ | 519 | if (ls->t.token != ')') { /* is `parlist' not empty? */ |
535 | do { | 520 | do { |
536 | switch (ls->t.token) { | 521 | switch (ls->t.token) { |
537 | case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; | 522 | case TK_NAME: { /* param -> NAME [ `=' `...' ] */ |
538 | case TK_DOTS: { | 523 | new_localvar(ls, str_checkname(ls), nparams++); |
524 | if (testnext(ls, '=')) { | ||
525 | check(ls, TK_DOTS); | ||
526 | f->is_vararg = 1; | ||
527 | } | ||
528 | break; | ||
529 | } | ||
530 | case TK_DOTS: { /* param -> `...' */ | ||
539 | next(ls); | 531 | next(ls); |
540 | dots = (testnext(ls, '=')) ? str_checkname(ls) : | 532 | /* use `arg' as default name */ |
541 | luaS_new(ls->L, "arg"); | 533 | new_localvar(ls, luaS_new(ls->L, "arg"), nparams++); |
534 | f->is_vararg = 1; | ||
542 | break; | 535 | break; |
543 | } | 536 | } |
544 | default: luaX_syntaxerror(ls, "<name> or `...' expected"); | 537 | default: luaX_syntaxerror(ls, "<name> or `...' expected"); |
545 | } | 538 | } |
546 | } while (!dots && testnext(ls, ',')); | 539 | } while (!f->is_vararg && testnext(ls, ',')); |
547 | } | 540 | } |
548 | code_params(ls, nparams, dots); | 541 | adjustlocalvars(ls, nparams); |
542 | f->numparams = fs->nactvar - f->is_vararg; | ||
543 | luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ | ||
549 | } | 544 | } |
550 | 545 | ||
551 | 546 | ||