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

Function luaK_nil

third-party/lua-5.5.0/src/lcode.c:132–148  ·  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

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

Callers 2

adjust_assignFunction · 0.70
discharge2regFunction · 0.70

Calls 2

previousinstructionFunction · 0.70
luaK_codeABCFunction · 0.50

Tested by

no test coverage detected