diff options
| -rw-r--r-- | llex.c | 3 | ||||
| -rw-r--r-- | llex.h | 1 | ||||
| -rw-r--r-- | lparser.c | 6 |
3 files changed, 7 insertions, 3 deletions
| @@ -190,6 +190,9 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, | |||
| 190 | ls->lastline = 1; | 190 | ls->lastline = 1; |
| 191 | ls->source = source; | 191 | ls->source = source; |
| 192 | ls->envn = luaS_newliteral(L, LUA_ENV); /* get env name */ | 192 | ls->envn = luaS_newliteral(L, LUA_ENV); /* get env name */ |
| 193 | ls->brkn = luaS_newliteral(L, "break"); /* get "break" name */ | ||
| 194 | /* "break" cannot be collected, as it is a reserved word" */ | ||
| 195 | lua_assert(isreserved(ls->brkn)); | ||
| 193 | luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ | 196 | luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ |
| 194 | } | 197 | } |
| 195 | 198 | ||
| @@ -75,6 +75,7 @@ typedef struct LexState { | |||
| 75 | struct Dyndata *dyd; /* dynamic structures used by the parser */ | 75 | struct Dyndata *dyd; /* dynamic structures used by the parser */ |
| 76 | TString *source; /* current source name */ | 76 | TString *source; /* current source name */ |
| 77 | TString *envn; /* environment variable name */ | 77 | TString *envn; /* environment variable name */ |
| 78 | TString *brkn; /* "break" name (used as a label) */ | ||
| 78 | } LexState; | 79 | } LexState; |
| 79 | 80 | ||
| 80 | 81 | ||
| @@ -707,7 +707,7 @@ static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) { | |||
| 707 | */ | 707 | */ |
| 708 | static l_noret undefgoto (LexState *ls, Labeldesc *gt) { | 708 | static l_noret undefgoto (LexState *ls, Labeldesc *gt) { |
| 709 | /* breaks are checked when created, cannot be undefined */ | 709 | /* breaks are checked when created, cannot be undefined */ |
| 710 | lua_assert(!eqstr(gt->name, luaS_newliteral(ls->L, "break"))); | 710 | lua_assert(!eqstr(gt->name, ls->brkn)); |
| 711 | luaK_semerror(ls, "no visible label '%s' for <goto> at line %d", | 711 | luaK_semerror(ls, "no visible label '%s' for <goto> at line %d", |
| 712 | getstr(gt->name), gt->line); | 712 | getstr(gt->name), gt->line); |
| 713 | } | 713 | } |
| @@ -723,7 +723,7 @@ static void leaveblock (FuncState *fs) { | |||
| 723 | removevars(fs, bl->nactvar); /* remove block locals */ | 723 | removevars(fs, bl->nactvar); /* remove block locals */ |
| 724 | lua_assert(bl->nactvar == fs->nactvar); /* back to level on entry */ | 724 | lua_assert(bl->nactvar == fs->nactvar); /* back to level on entry */ |
| 725 | if (bl->isloop == 2) /* has to fix pending breaks? */ | 725 | if (bl->isloop == 2) /* has to fix pending breaks? */ |
| 726 | createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0); | 726 | createlabel(ls, ls->brkn, 0, 0); |
| 727 | solvegotos(fs, bl); | 727 | solvegotos(fs, bl); |
| 728 | if (bl->previous == NULL) { /* was it the last block? */ | 728 | if (bl->previous == NULL) { /* was it the last block? */ |
| 729 | if (bl->firstgoto < ls->dyd->gt.n) /* still pending gotos? */ | 729 | if (bl->firstgoto < ls->dyd->gt.n) /* still pending gotos? */ |
| @@ -1497,7 +1497,7 @@ static void breakstat (LexState *ls, int line) { | |||
| 1497 | ok: | 1497 | ok: |
| 1498 | bl->isloop = 2; /* signal that block has pending breaks */ | 1498 | bl->isloop = 2; /* signal that block has pending breaks */ |
| 1499 | luaX_next(ls); /* skip break */ | 1499 | luaX_next(ls); /* skip break */ |
| 1500 | newgotoentry(ls, luaS_newliteral(ls->L, "break"), line); | 1500 | newgotoentry(ls, ls->brkn, line); |
| 1501 | } | 1501 | } |
| 1502 | 1502 | ||
| 1503 | 1503 | ||
