aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-10 14:58:31 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-10 14:58:31 -0300
commitbe8445d7e4b6122620c428877b51a27d464253d5 (patch)
treee0160895d105e5a3c20ec65c3196bffa042bd93f /lparser.c
parent3d296304ef14ac9a6d1fa9357541ddd9bb54722f (diff)
downloadlua-be8445d7e4b6122620c428877b51a27d464253d5.tar.gz
lua-be8445d7e4b6122620c428877b51a27d464253d5.tar.bz2
lua-be8445d7e4b6122620c428877b51a27d464253d5.zip
Details
In the generic for loop, it is simpler for OP_TFORLOOP to use the same 'ra' as OP_TFORCALL. Moreover, the internal names of the loop temporaries "(for ...)" don't need to leak internal details (even because the numerical for loop doesn't have a fixed role for each of its temporaries).
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/lparser.c b/lparser.c
index c4626ba1..7f282bf9 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1527,7 +1527,6 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isgen) {
1527 if (isgen) { /* generic for? */ 1527 if (isgen) { /* generic for? */
1528 luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars); 1528 luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);
1529 luaK_fixline(fs, line); 1529 luaK_fixline(fs, line);
1530 base += 2; /* base for 'OP_TFORLOOP' (skips function and state) */
1531 } 1530 }
1532 endfor = luaK_codeABx(fs, forloop[isgen], base, 0); 1531 endfor = luaK_codeABx(fs, forloop[isgen], base, 0);
1533 fixforjump(fs, endfor, prep + 1, 1); 1532 fixforjump(fs, endfor, prep + 1, 1);
@@ -1539,9 +1538,9 @@ static void fornum (LexState *ls, TString *varname, int line) {
1539 /* fornum -> NAME = exp,exp[,exp] forbody */ 1538 /* fornum -> NAME = exp,exp[,exp] forbody */
1540 FuncState *fs = ls->fs; 1539 FuncState *fs = ls->fs;
1541 int base = fs->freereg; 1540 int base = fs->freereg;
1542 new_localvarliteral(ls, "(for index)"); 1541 new_localvarliteral(ls, "(for state)");
1543 new_localvarliteral(ls, "(for limit)"); 1542 new_localvarliteral(ls, "(for state)");
1544 new_localvarliteral(ls, "(for step)"); 1543 new_localvarliteral(ls, "(for state)");
1545 new_localvar(ls, varname); 1544 new_localvar(ls, varname);
1546 checknext(ls, '='); 1545 checknext(ls, '=');
1547 exp1(ls); /* initial value */ 1546 exp1(ls); /* initial value */
@@ -1566,10 +1565,10 @@ static void forlist (LexState *ls, TString *indexname) {
1566 int line; 1565 int line;
1567 int base = fs->freereg; 1566 int base = fs->freereg;
1568 /* create control variables */ 1567 /* create control variables */
1569 new_localvarliteral(ls, "(for generator)");
1570 new_localvarliteral(ls, "(for state)"); 1568 new_localvarliteral(ls, "(for state)");
1571 new_localvarliteral(ls, "(for control)"); 1569 new_localvarliteral(ls, "(for state)");
1572 new_localvarliteral(ls, "(for toclose)"); 1570 new_localvarliteral(ls, "(for state)");
1571 new_localvarliteral(ls, "(for state)");
1573 /* create declared variables */ 1572 /* create declared variables */
1574 new_localvar(ls, indexname); 1573 new_localvar(ls, indexname);
1575 while (testnext(ls, ',')) { 1574 while (testnext(ls, ',')) {