Simplification in opcodes for numerical 'for'

As the control variable is read only, the code doesn't need to keep
an internal copy of it.
This commit is contained in:
Roberto Ierusalimschy
2022-12-21 15:35:40 -03:00
parent b2f7b3b79f
commit 873588dc5f
2 changed files with 27 additions and 27 deletions

View File

@@ -1580,7 +1580,6 @@ static void fornum (LexState *ls, TString *varname, int line) {
int base = fs->freereg;
new_localvarliteral(ls, "(for state)");
new_localvarliteral(ls, "(for state)");
new_localvarliteral(ls, "(for state)");
new_localvarkind(ls, varname, RDKCONST); /* control variable */
checknext(ls, '=');
exp1(ls); /* initial value */
@@ -1592,7 +1591,8 @@ static void fornum (LexState *ls, TString *varname, int line) {
luaK_int(fs, fs->freereg, 1);
luaK_reserveregs(fs, 1);
}
adjustlocalvars(ls, 3); /* control variables */
adjustlocalvars(ls, 2); /* start scope for internal state variables */
fs->freereg--; /* OP_FORPREP removes one register from the stack */
forbody(ls, base, line, 1, 0);
}