MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / forbody

Function forbody

3rd/lua-5.4.3/src/lparser.c:1532–1554  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1530** Generate code for a 'for' loop.
1531*/
1532static 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
1557static void fornum (LexState *ls, TString *varname, int line) {

Callers 2

fornumFunction · 0.85
forlistFunction · 0.85

Calls 10

checknextFunction · 0.85
luaK_codeABxFunction · 0.85
enterblockFunction · 0.85
adjustlocalvarsFunction · 0.85
luaK_reserveregsFunction · 0.85
blockFunction · 0.85
leaveblockFunction · 0.85
fixforjumpFunction · 0.85
luaK_getlabelFunction · 0.85
luaK_fixlineFunction · 0.85

Tested by

no test coverage detected