aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/lparser.c b/lparser.c
index ff6f4009..c0eb7890 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1558,6 +1558,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isgen) {
1558 int prep, endfor; 1558 int prep, endfor;
1559 checknext(ls, TK_DO); 1559 checknext(ls, TK_DO);
1560 prep = luaK_codeABx(fs, forprep[isgen], base, 0); 1560 prep = luaK_codeABx(fs, forprep[isgen], base, 0);
1561 fs->freereg--; /* both 'forprep' remove one register from the stack */
1561 enterblock(fs, &bl, 0); /* scope for declared variables */ 1562 enterblock(fs, &bl, 0); /* scope for declared variables */
1562 adjustlocalvars(ls, nvars); 1563 adjustlocalvars(ls, nvars);
1563 luaK_reserveregs(fs, nvars); 1564 luaK_reserveregs(fs, nvars);
@@ -1591,8 +1592,7 @@ static void fornum (LexState *ls, TString *varname, int line) {
1591 luaK_int(fs, fs->freereg, 1); 1592 luaK_int(fs, fs->freereg, 1);
1592 luaK_reserveregs(fs, 1); 1593 luaK_reserveregs(fs, 1);
1593 } 1594 }
1594 adjustlocalvars(ls, 2); /* start scope for internal state variables */ 1595 adjustlocalvars(ls, 2); /* start scope for internal variables */
1595 fs->freereg--; /* OP_FORPREP removes one register from the stack */
1596 forbody(ls, base, line, 1, 0); 1596 forbody(ls, base, line, 1, 0);
1597} 1597}
1598 1598
@@ -1601,14 +1601,13 @@ static void forlist (LexState *ls, TString *indexname) {
1601 /* forlist -> NAME {,NAME} IN explist forbody */ 1601 /* forlist -> NAME {,NAME} IN explist forbody */
1602 FuncState *fs = ls->fs; 1602 FuncState *fs = ls->fs;
1603 expdesc e; 1603 expdesc e;
1604 int nvars = 5; /* gen, state, control, toclose, 'indexname' */ 1604 int nvars = 4; /* function, state, closing, control */
1605 int line; 1605 int line;
1606 int base = fs->freereg; 1606 int base = fs->freereg;
1607 /* create control variables */ 1607 /* create internal variables */
1608 new_localvarliteral(ls, "(for state)"); 1608 new_localvarliteral(ls, "(for state)"); /* iterator function */
1609 new_localvarliteral(ls, "(for state)"); 1609 new_localvarliteral(ls, "(for state)"); /* state */
1610 new_localvarliteral(ls, "(for state)"); 1610 new_localvarliteral(ls, "(for state)"); /* closing var. (after swap) */
1611 new_localvarliteral(ls, "(for state)");
1612 new_localvarkind(ls, indexname, RDKCONST); /* control variable */ 1611 new_localvarkind(ls, indexname, RDKCONST); /* control variable */
1613 /* other declared variables */ 1612 /* other declared variables */
1614 while (testnext(ls, ',')) { 1613 while (testnext(ls, ',')) {
@@ -1618,10 +1617,10 @@ static void forlist (LexState *ls, TString *indexname) {
1618 checknext(ls, TK_IN); 1617 checknext(ls, TK_IN);
1619 line = ls->linenumber; 1618 line = ls->linenumber;
1620 adjust_assign(ls, 4, explist(ls, &e), &e); 1619 adjust_assign(ls, 4, explist(ls, &e), &e);
1621 adjustlocalvars(ls, 4); /* control variables */ 1620 adjustlocalvars(ls, 3); /* start scope for internal variables */
1622 marktobeclosed(fs); /* last control var. must be closed */ 1621 marktobeclosed(fs); /* last internal var. must be closed */
1623 luaK_checkstack(fs, 3); /* extra space to call generator */ 1622 luaK_checkstack(fs, 2); /* extra space to call iterator */
1624 forbody(ls, base, line, nvars - 4, 1); 1623 forbody(ls, base, line, nvars - 3, 1);
1625} 1624}
1626 1625
1627 1626