MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / forbody

Function forbody

third-party/lua-5.5.0/src/lparser.c:1659–1682  ·  view source on GitHub ↗

** Generate code for a 'for' loop. */

Source from the content-addressed store, hash-verified

1657** Generate code for a 'for' loop.
1658*/
1659static 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
1685static void fornum (LexState *ls, TString *varname, int line) {

Callers 2

fornumFunction · 0.70
forlistFunction · 0.70

Calls 11

checknextFunction · 0.70
luaK_codeABxFunction · 0.70
enterblockFunction · 0.70
adjustlocalvarsFunction · 0.70
luaK_reserveregsFunction · 0.70
blockFunction · 0.70
leaveblockFunction · 0.70
fixforjumpFunction · 0.70
luaK_getlabelFunction · 0.70
luaK_fixlineFunction · 0.70
luaK_codeABCFunction · 0.50

Tested by

no test coverage detected