** Generate code for a 'for' loop. */
| 1657 | ** Generate code for a 'for' loop. |
| 1658 | */ |
| 1659 | static void forbody (LexState *ls, int base, int line, int nvars, int isgen) { |
| 1660 | /* forbody -> DO block */ |
| 1661 | static const OpCode forprep[2] = {OP_FORPREP, OP_TFORPREP}; |
| 1662 | static const OpCode forloop[2] = {OP_FORLOOP, OP_TFORLOOP}; |
| 1663 | BlockCnt bl; |
| 1664 | FuncState *fs = ls->fs; |
| 1665 | int prep, endfor; |
| 1666 | checknext(ls, TK_DO); |
| 1667 | prep = luaK_codeABx(fs, forprep[isgen], base, 0); |
| 1668 | fs->freereg--; /* both 'forprep' remove one register from the stack */ |
| 1669 | enterblock(fs, &bl, 0); /* scope for declared variables */ |
| 1670 | adjustlocalvars(ls, nvars); |
| 1671 | luaK_reserveregs(fs, nvars); |
| 1672 | block(ls); |
| 1673 | leaveblock(fs); /* end of scope for declared variables */ |
| 1674 | fixforjump(fs, prep, luaK_getlabel(fs), 0); |
| 1675 | if (isgen) { /* generic for? */ |
| 1676 | luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars); |
| 1677 | luaK_fixline(fs, line); |
| 1678 | } |
| 1679 | endfor = luaK_codeABx(fs, forloop[isgen], base, 0); |
| 1680 | fixforjump(fs, endfor, prep + 1, 1); |
| 1681 | luaK_fixline(fs, line); |
| 1682 | } |
| 1683 | |
| 1684 | |
| 1685 | static void fornum (LexState *ls, TString *varname, int line) { |
no test coverage detected