diff options
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 18 |
1 files changed, 11 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.51 2011/02/01 18:03:10 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.52 2011/04/07 18:14:12 roberto Exp roberto $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -35,19 +35,23 @@ static int isnumeral(expdesc *e) { | |||
| 35 | 35 | ||
| 36 | void luaK_nil (FuncState *fs, int from, int n) { | 36 | void luaK_nil (FuncState *fs, int from, int n) { |
| 37 | Instruction *previous; | 37 | Instruction *previous; |
| 38 | int l = from + n - 1; /* last register to set nil */ | ||
| 38 | if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ | 39 | if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ |
| 39 | previous = &fs->f->code[fs->pc-1]; | 40 | previous = &fs->f->code[fs->pc-1]; |
| 40 | if (GET_OPCODE(*previous) == OP_LOADNIL) { | 41 | if (GET_OPCODE(*previous) == OP_LOADNIL) { |
| 41 | int pfrom = GETARG_A(*previous); | 42 | int pfrom = GETARG_A(*previous); |
| 42 | int pto = GETARG_B(*previous); | 43 | int pl = pfrom + GETARG_B(*previous); |
| 43 | if (pfrom <= from && from <= pto+1) { /* can connect both? */ | 44 | if ((pfrom <= from && from <= pl + 1) || |
| 44 | if (from+n-1 > pto) | 45 | (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */ |
| 45 | SETARG_B(*previous, from+n-1); | 46 | if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */ |
| 47 | if (pl > l) l = pl; /* l = max(l, pl) */ | ||
| 48 | SETARG_A(*previous, from); | ||
| 49 | SETARG_B(*previous, l - from); | ||
| 46 | return; | 50 | return; |
| 47 | } | 51 | } |
| 48 | } | 52 | } /* else go through */ |
| 49 | } | 53 | } |
| 50 | luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ | 54 | luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */ |
| 51 | } | 55 | } |
| 52 | 56 | ||
| 53 | 57 | ||
