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