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