|
@@ -1558,6 +1558,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isgen) {
|
|
int prep, endfor;
|
|
int prep, endfor;
|
|
checknext(ls, TK_DO);
|
|
checknext(ls, TK_DO);
|
|
prep = luaK_codeABx(fs, forprep[isgen], base, 0);
|
|
prep = luaK_codeABx(fs, forprep[isgen], base, 0);
|
|
|
|
+ fs->freereg--; /* both 'forprep' remove one register from the stack */
|
|
enterblock(fs, &bl, 0); /* scope for declared variables */
|
|
enterblock(fs, &bl, 0); /* scope for declared variables */
|
|
adjustlocalvars(ls, nvars);
|
|
adjustlocalvars(ls, nvars);
|
|
luaK_reserveregs(fs, nvars);
|
|
luaK_reserveregs(fs, nvars);
|
|
@@ -1591,8 +1592,7 @@ static void fornum (LexState *ls, TString *varname, int line) {
|
|
luaK_int(fs, fs->freereg, 1);
|
|
luaK_int(fs, fs->freereg, 1);
|
|
luaK_reserveregs(fs, 1);
|
|
luaK_reserveregs(fs, 1);
|
|
}
|
|
}
|
|
- adjustlocalvars(ls, 2); /* start scope for internal state variables */
|
|
|
|
- fs->freereg--; /* OP_FORPREP removes one register from the stack */
|
|
|
|
|
|
+ adjustlocalvars(ls, 2); /* start scope for internal variables */
|
|
forbody(ls, base, line, 1, 0);
|
|
forbody(ls, base, line, 1, 0);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1601,14 +1601,13 @@ static void forlist (LexState *ls, TString *indexname) {
|
|
/* forlist -> NAME {,NAME} IN explist forbody */
|
|
/* forlist -> NAME {,NAME} IN explist forbody */
|
|
FuncState *fs = ls->fs;
|
|
FuncState *fs = ls->fs;
|
|
expdesc e;
|
|
expdesc e;
|
|
- int nvars = 5; /* gen, state, control, toclose, 'indexname' */
|
|
|
|
|
|
+ int nvars = 4; /* function, state, closing, control */
|
|
int line;
|
|
int line;
|
|
int base = fs->freereg;
|
|
int base = fs->freereg;
|
|
- /* create control variables */
|
|
|
|
- new_localvarliteral(ls, "(for state)");
|
|
|
|
- new_localvarliteral(ls, "(for state)");
|
|
|
|
- new_localvarliteral(ls, "(for state)");
|
|
|
|
- new_localvarliteral(ls, "(for state)");
|
|
|
|
|
|
+ /* create internal variables */
|
|
|
|
+ new_localvarliteral(ls, "(for state)"); /* iterator function */
|
|
|
|
+ new_localvarliteral(ls, "(for state)"); /* state */
|
|
|
|
+ new_localvarliteral(ls, "(for state)"); /* closing var. (after swap) */
|
|
new_localvarkind(ls, indexname, RDKCONST); /* control variable */
|
|
new_localvarkind(ls, indexname, RDKCONST); /* control variable */
|
|
/* other declared variables */
|
|
/* other declared variables */
|
|
while (testnext(ls, ',')) {
|
|
while (testnext(ls, ',')) {
|
|
@@ -1618,10 +1617,10 @@ static void forlist (LexState *ls, TString *indexname) {
|
|
checknext(ls, TK_IN);
|
|
checknext(ls, TK_IN);
|
|
line = ls->linenumber;
|
|
line = ls->linenumber;
|
|
adjust_assign(ls, 4, explist(ls, &e), &e);
|
|
adjust_assign(ls, 4, explist(ls, &e), &e);
|
|
- adjustlocalvars(ls, 4); /* control variables */
|
|
|
|
- marktobeclosed(fs); /* last control var. must be closed */
|
|
|
|
- luaK_checkstack(fs, 3); /* extra space to call generator */
|
|
|
|
- forbody(ls, base, line, nvars - 4, 1);
|
|
|
|
|
|
+ adjustlocalvars(ls, 3); /* start scope for internal variables */
|
|
|
|
+ marktobeclosed(fs); /* last internal var. must be closed */
|
|
|
|
+ luaK_checkstack(fs, 2); /* extra space to call iterator */
|
|
|
|
+ forbody(ls, base, line, nvars - 3, 1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|