no more repeat ... end.

This commit is contained in:
Roberto Ierusalimschy 2000-04-11 15:37:18 -03:00
parent 0810bc707f
commit 0433e42023

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 1.79 2000/04/07 19:35:20 roberto Exp roberto $ ** $Id: lparser.c,v 1.80 2000/04/10 19:21:14 roberto Exp roberto $
** LL(1) Parser and code generator for Lua ** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -214,8 +214,15 @@ static void adjustlocalvars (LexState *ls, int nvars, int line) {
} }
static void add_localvar (LexState *ls, TString *name) { static void removelocalvars (LexState *ls, int nvars, int line) {
store_localvar(ls, name, 0); ls->fs->nlocalvar -= nvars;
while (nvars--)
luaI_unregisterlocalvar(ls, line);
}
static void add_localvar (LexState *ls, const char *name) {
store_localvar(ls, luaS_newfixed(ls->L, name), 0);
adjustlocalvars(ls, 1, 0); adjustlocalvars(ls, 1, 0);
} }
@ -305,7 +312,7 @@ static void code_args (LexState *ls, int nparams, int dots) {
luaK_deltastack(fs, nparams); luaK_deltastack(fs, nparams);
else { else {
luaK_deltastack(fs, nparams+1); luaK_deltastack(fs, nparams+1);
add_localvar(ls, luaS_newfixed(ls->L, "arg")); add_localvar(ls, "arg");
} }
} }
@ -830,8 +837,7 @@ static void block (LexState *ls) {
int nlocalvar = fs->nlocalvar; int nlocalvar = fs->nlocalvar;
chunk(ls); chunk(ls);
luaK_adjuststack(fs, fs->nlocalvar - nlocalvar); /* remove local variables */ luaK_adjuststack(fs, fs->nlocalvar - nlocalvar); /* remove local variables */
for (; fs->nlocalvar > nlocalvar; fs->nlocalvar--) removelocalvars(ls, fs->nlocalvar - nlocalvar, fs->lastsetline);
luaI_unregisterlocalvar(ls, fs->lastsetline);
} }
@ -892,16 +898,10 @@ static void repeatstat (LexState *ls, int line) {
enterbreak(fs, &bl); enterbreak(fs, &bl);
setline_and_next(ls); /* trace REPEAT when looping */ setline_and_next(ls); /* trace REPEAT when looping */
block(ls); block(ls);
if (ls->token == TK_END) { check_match(ls, TK_UNTIL, TK_REPEAT, line);
luaK_patchlist(fs, luaK_jump(fs), repeat_init); expr(ls, &v);
next(ls); luaK_goiftrue(fs, &v, 0);
} luaK_patchlist(fs, v.u.l.f, repeat_init);
else {
check_match(ls, TK_UNTIL, TK_REPEAT, line);
expr(ls, &v);
luaK_goiftrue(fs, &v, 0);
luaK_patchlist(fs, v.u.l.f, repeat_init);
}
leavebreak(fs, &bl); leavebreak(fs, &bl);
} }
@ -1135,7 +1135,7 @@ static void body (LexState *ls, int needself, int line) {
new_fs.f->lineDefined = line; new_fs.f->lineDefined = line;
check(ls, '('); check(ls, '(');
if (needself) if (needself)
add_localvar(ls, luaS_newfixed(ls->L, "self")); add_localvar(ls, "self");
parlist(ls); parlist(ls);
check(ls, ')'); check(ls, ')');
chunk(ls); chunk(ls);