** 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.) */
| 128 | ** instance, 'local a; local b' will generate a single opcode.) |
| 129 | */ |
| 130 | void 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 | /* |
no test coverage detected