** 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.) */
| 69 | ** instance, 'local a; local b' will generate a single opcode.) |
| 70 | */ |
| 71 | void luaK_nil (FuncState *fs, int from, int n) { |
| 72 | Instruction *previous; |
| 73 | int l = from + n - 1; /* last register to set nil */ |
| 74 | if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ |
| 75 | previous = &fs->f->code[fs->pc-1]; |
| 76 | if (GET_OPCODE(*previous) == OP_LOADNIL) { /* previous is LOADNIL? */ |
| 77 | int pfrom = GETARG_A(*previous); /* get previous range */ |
| 78 | int pl = pfrom + GETARG_B(*previous); |
| 79 | if ((pfrom <= from && from <= pl + 1) || |
| 80 | (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */ |
| 81 | if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */ |
| 82 | if (pl > l) l = pl; /* l = max(l, pl) */ |
| 83 | SETARG_A(*previous, from); |
| 84 | SETARG_B(*previous, l - from); |
| 85 | return; |
| 86 | } |
| 87 | } /* else go through */ |
| 88 | } |
| 89 | luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */ |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /* |
no test coverage detected