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

Function luaK_nil

3rd/lua-5.4.3/src/lcode.c:130–146  ·  view source on GitHub ↗

** Create a OP_LOADNIL instruction, but try to optimize: if the previous ** instruction is also OP_LOADNIL and ranges are compatible, adjust ** range of previous instruction instead of emitting a new one. (For ** instance, 'local a; local b' will generate a single opcode.) */

Source from the content-addressed store, hash-verified

128** instance, 'local a; local b' will generate a single opcode.)
129*/
130void luaK_nil (FuncState *fs, int from, int n) {
131 int l = from + n - 1; /* last register to set nil */
132 Instruction *previous = previousinstruction(fs);
133 if (GET_OPCODE(*previous) == OP_LOADNIL) { /* previous is LOADNIL? */
134 int pfrom = GETARG_A(*previous); /* get previous range */
135 int pl = pfrom + GETARG_B(*previous);
136 if ((pfrom <= from && from <= pl + 1) ||
137 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
138 if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
139 if (pl > l) l = pl; /* l = max(l, pl) */
140 SETARG_A(*previous, from);
141 SETARG_B(*previous, l - from);
142 return;
143 } /* else go through */
144 }
145 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
146}
147
148
149/*

Callers 2

adjust_assignFunction · 0.85
discharge2regFunction · 0.85

Calls 1

previousinstructionFunction · 0.85

Tested by

no test coverage detected