MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / luaK_nil

Function luaK_nil

src/lcode.cpp: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 4

discharge2regFunction · 0.85
adjust_assignFunction · 0.85
method_call_funcargsFunction · 0.85
safe_navigationFunction · 0.85

Calls 1

previousinstructionFunction · 0.85

Tested by

no test coverage detected