aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/lparser.c b/lparser.c
index 61032552..e5dc330d 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.57 2008/04/02 17:19:22 roberto Exp roberto $ 2** $Id: lparser.c,v 2.58 2008/05/08 15:44:51 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*/
@@ -1008,7 +1008,7 @@ static void whilestat (LexState *ls, int line) {
1008 enterblock(fs, &bl, 1); 1008 enterblock(fs, &bl, 1);
1009 checknext(ls, TK_DO); 1009 checknext(ls, TK_DO);
1010 block(ls); 1010 block(ls);
1011 luaK_patchlist(fs, luaK_jump(fs), whileinit); 1011 luaK_jumpto(fs, whileinit);
1012 check_match(ls, TK_END, TK_WHILE, line); 1012 check_match(ls, TK_END, TK_WHILE, line);
1013 leaveblock(fs); 1013 leaveblock(fs);
1014 luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ 1014 luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
@@ -1029,13 +1029,13 @@ static void repeatstat (LexState *ls, int line) {
1029 condexit = cond(ls); /* read condition (inside scope block) */ 1029 condexit = cond(ls); /* read condition (inside scope block) */
1030 if (!bl2.upval) { /* no upvalues? */ 1030 if (!bl2.upval) { /* no upvalues? */
1031 leaveblock(fs); /* finish scope */ 1031 leaveblock(fs); /* finish scope */
1032 luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */ 1032 luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
1033 } 1033 }
1034 else { /* complete semantics when there are upvalues */ 1034 else { /* complete semantics when there are upvalues */
1035 breakstat(ls); /* if condition then break */ 1035 breakstat(ls); /* if condition then break */
1036 luaK_patchtohere(ls->fs, condexit); /* else... */ 1036 luaK_patchtohere(ls->fs, condexit); /* else... */
1037 leaveblock(fs); /* finish scope... */ 1037 leaveblock(fs); /* finish scope... */
1038 luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */ 1038 luaK_jumpto(fs, repeat_init); /* and repeat */
1039 } 1039 }
1040 leaveblock(fs); /* finish loop */ 1040 leaveblock(fs); /* finish loop */
1041} 1041}
@@ -1055,7 +1055,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) {
1055 /* forbody -> DO block */ 1055 /* forbody -> DO block */
1056 BlockCnt bl; 1056 BlockCnt bl;
1057 FuncState *fs = ls->fs; 1057 FuncState *fs = ls->fs;
1058 int prep, endfor; 1058 int prep;
1059 adjustlocalvars(ls, 3); /* control variables */ 1059 adjustlocalvars(ls, 3); /* control variables */
1060 checknext(ls, TK_DO); 1060 checknext(ls, TK_DO);
1061 prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); 1061 prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
@@ -1065,10 +1065,16 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) {
1065 block(ls); 1065 block(ls);
1066 leaveblock(fs); /* end of scope for declared variables */ 1066 leaveblock(fs); /* end of scope for declared variables */
1067 luaK_patchtohere(fs, prep); 1067 luaK_patchtohere(fs, prep);
1068 endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) : 1068 if (isnum) { /* numeric for? */
1069 luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); 1069 int endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);
1070 luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */ 1070 luaK_patchlist(fs, endfor, prep + 1);
1071 luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1); 1071 }
1072 else { /* generic for */
1073 luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars);
1074 luaK_fixline(fs, line);
1075 luaK_jumpto(fs, prep + 1);
1076 }
1077 luaK_fixline(fs, line);
1072} 1078}
1073 1079
1074 1080