diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-05-14 09:32:46 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-05-14 09:32:46 -0300 |
commit | 5cc448386adad1da2901e381481e4129034b692b (patch) | |
tree | a2280f9646958471eed8a271579a804faf93407c /lparser.c | |
parent | c116dcb92b2ee36ef5c4541a88e73540837f1057 (diff) | |
download | lua-5cc448386adad1da2901e381481e4129034b692b.tar.gz lua-5cc448386adad1da2901e381481e4129034b692b.tar.bz2 lua-5cc448386adad1da2901e381481e4129034b692b.zip |
new syntax: `... [= name]'
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.208 2003/04/03 13:35:34 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.209 2003/05/13 20:15:59 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 | */ |
@@ -173,12 +173,6 @@ static void new_localvarstr (LexState *ls, const char *name, int n) { | |||
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | static void create_local (LexState *ls, const char *name) { | ||
177 | new_localvarstr(ls, name, 0); | ||
178 | adjustlocalvars(ls, 1); | ||
179 | } | ||
180 | |||
181 | |||
182 | static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { | 176 | static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { |
183 | int i; | 177 | int i; |
184 | Proto *f = fs->f; | 178 | Proto *f = fs->f; |
@@ -267,14 +261,19 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { | |||
267 | } | 261 | } |
268 | 262 | ||
269 | 263 | ||
270 | static void code_params (LexState *ls, int nparams, int dots) { | 264 | static void code_params (LexState *ls, int nparams, TString *dots) { |
271 | FuncState *fs = ls->fs; | 265 | FuncState *fs = ls->fs; |
266 | Proto *f = fs->f; | ||
272 | adjustlocalvars(ls, nparams); | 267 | adjustlocalvars(ls, nparams); |
273 | luaX_checklimit(ls, fs->nactvar, MAXPARAMS, "parameters"); | 268 | luaX_checklimit(ls, fs->nactvar, MAXPARAMS, "parameters"); |
274 | fs->f->numparams = cast(lu_byte, fs->nactvar); | 269 | f->numparams = cast(lu_byte, fs->nactvar); |
275 | fs->f->is_vararg = cast(lu_byte, dots); | 270 | if (!dots) |
276 | if (dots) | 271 | f->is_vararg = 0; |
277 | create_local(ls, "arg"); | 272 | else { |
273 | f->is_vararg = 1; | ||
274 | new_localvar(ls, dots, 0); | ||
275 | adjustlocalvars(ls, 1); | ||
276 | } | ||
278 | luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ | 277 | luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ |
279 | } | 278 | } |
280 | 279 | ||
@@ -528,12 +527,17 @@ static void constructor (LexState *ls, expdesc *t) { | |||
528 | static void parlist (LexState *ls) { | 527 | static void parlist (LexState *ls) { |
529 | /* parlist -> [ param { `,' param } ] */ | 528 | /* parlist -> [ param { `,' param } ] */ |
530 | int nparams = 0; | 529 | int nparams = 0; |
531 | int dots = 0; | 530 | TString *dots = NULL; |
532 | if (ls->t.token != ')') { /* is `parlist' not empty? */ | 531 | if (ls->t.token != ')') { /* is `parlist' not empty? */ |
533 | do { | 532 | do { |
534 | switch (ls->t.token) { | 533 | switch (ls->t.token) { |
535 | case TK_DOTS: dots = 1; next(ls); break; | ||
536 | case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; | 534 | case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; |
535 | case TK_DOTS: { | ||
536 | next(ls); | ||
537 | dots = (testnext(ls, '=')) ? str_checkname(ls) : | ||
538 | luaS_new(ls->L, "arg"); | ||
539 | break; | ||
540 | } | ||
537 | default: luaX_syntaxerror(ls, "<name> or `...' expected"); | 541 | default: luaX_syntaxerror(ls, "<name> or `...' expected"); |
538 | } | 542 | } |
539 | } while (!dots && testnext(ls, ',')); | 543 | } while (!dots && testnext(ls, ',')); |
@@ -548,8 +552,10 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { | |||
548 | open_func(ls, &new_fs); | 552 | open_func(ls, &new_fs); |
549 | new_fs.f->lineDefined = line; | 553 | new_fs.f->lineDefined = line; |
550 | check(ls, '('); | 554 | check(ls, '('); |
551 | if (needself) | 555 | if (needself) { |
552 | create_local(ls, "self"); | 556 | new_localvarstr(ls, "self", 0); |
557 | adjustlocalvars(ls, 1); | ||
558 | } | ||
553 | parlist(ls); | 559 | parlist(ls); |
554 | check(ls, ')'); | 560 | check(ls, ')'); |
555 | chunk(ls); | 561 | chunk(ls); |