** Generate code for a 'for' loop. */
| 1530 | ** Generate code for a 'for' loop. |
| 1531 | */ |
| 1532 | static void forbody (LexState *ls, int base, int line, int nvars, int isgen) { |
| 1533 | /* forbody -> DO block */ |
| 1534 | static const OpCode forprep[2] = {OP_FORPREP, OP_TFORPREP}; |
| 1535 | static const OpCode forloop[2] = {OP_FORLOOP, OP_TFORLOOP}; |
| 1536 | BlockCnt bl; |
| 1537 | FuncState *fs = ls->fs; |
| 1538 | int prep, endfor; |
| 1539 | checknext(ls, TK_DO); |
| 1540 | prep = luaK_codeABx(fs, forprep[isgen], base, 0); |
| 1541 | enterblock(fs, &bl, 0); /* scope for declared variables */ |
| 1542 | adjustlocalvars(ls, nvars); |
| 1543 | luaK_reserveregs(fs, nvars); |
| 1544 | block(ls); |
| 1545 | leaveblock(fs); /* end of scope for declared variables */ |
| 1546 | fixforjump(fs, prep, luaK_getlabel(fs), 0); |
| 1547 | if (isgen) { /* generic for? */ |
| 1548 | luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars); |
| 1549 | luaK_fixline(fs, line); |
| 1550 | } |
| 1551 | endfor = luaK_codeABx(fs, forloop[isgen], base, 0); |
| 1552 | fixforjump(fs, endfor, prep + 1, 1); |
| 1553 | luaK_fixline(fs, line); |
| 1554 | } |
| 1555 | |
| 1556 | |
| 1557 | static void fornum (LexState *ls, TString *varname, int line) { |
no test coverage detected