diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-01-18 15:39:40 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-01-18 15:39:40 -0200 |
| commit | b38e594ed738238d352bb5344446ef07d15510b4 (patch) | |
| tree | 985c5405bbe275ab61e1cb34559f0a8e6b762a3e | |
| parent | 448517e47e40814f6ee12eae8dd6c3120f1d48bb (diff) | |
| download | lua-b38e594ed738238d352bb5344446ef07d15510b4.tar.gz lua-b38e594ed738238d352bb5344446ef07d15510b4.tar.bz2 lua-b38e594ed738238d352bb5344446ef07d15510b4.zip | |
small improvements
Diffstat (limited to '')
| -rw-r--r-- | lcode.c | 27 |
1 files changed, 6 insertions, 21 deletions
| @@ -31,27 +31,15 @@ void luaK_error (LexState *ls, const char *msg) { | |||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | /* | ||
| 35 | ** Returns the the previous instruction, for optimizations. | ||
| 36 | ** If there is a jump target between this and the current instruction, | ||
| 37 | ** returns a dummy instruction to avoid wrong optimizations. | ||
| 38 | */ | ||
| 39 | static Instruction previous_instruction (FuncState *fs) { | ||
| 40 | if (fs->pc > fs->lasttarget) /* no jumps to current position? */ | ||
| 41 | return fs->f->code[fs->pc-1]; /* returns previous instruction */ | ||
| 42 | else | ||
| 43 | return cast(Instruction, -1);/* invalid instruction avoids optimizations */ | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | void luaK_nil (FuncState *fs, int from, int n) { | 34 | void luaK_nil (FuncState *fs, int from, int n) { |
| 48 | Instruction previous = previous_instruction(fs); | 35 | Instruction *previous; |
| 49 | if (GET_OPCODE(previous) == OP_LOADNIL) { | 36 | if (fs->pc > fs->lasttarget && /* no jumps to current position? */ |
| 50 | int pfrom = GETARG_A(previous); | 37 | GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) { |
| 51 | int pto = GETARG_B(previous); | 38 | int pfrom = GETARG_A(*previous); |
| 39 | int pto = GETARG_B(*previous); | ||
| 52 | if (pfrom <= from && from <= pto+1) { /* can connect both? */ | 40 | if (pfrom <= from && from <= pto+1) { /* can connect both? */ |
| 53 | if (from+n-1 > pto) | 41 | if (from+n-1 > pto) |
| 54 | SETARG_B(fs->f->code[fs->pc-1], from+n-1); | 42 | SETARG_B(*previous, from+n-1); |
| 55 | return; | 43 | return; |
| 56 | } | 44 | } |
| 57 | } | 45 | } |
| @@ -126,8 +114,6 @@ static int luaK_getjump (FuncState *fs, int pc) { | |||
| 126 | 114 | ||
| 127 | static Instruction *getjumpcontrol (FuncState *fs, int pc) { | 115 | static Instruction *getjumpcontrol (FuncState *fs, int pc) { |
| 128 | Instruction *pi = &fs->f->code[pc]; | 116 | Instruction *pi = &fs->f->code[pc]; |
| 129 | OpCode op = GET_OPCODE(*pi); | ||
| 130 | lua_assert(op == OP_JMP || op == OP_FORLOOP || op == OP_TFORLOOP); | ||
| 131 | if (pc >= 1 && testOpMode(GET_OPCODE(*(pi-1)), OpModeT)) | 117 | if (pc >= 1 && testOpMode(GET_OPCODE(*(pi-1)), OpModeT)) |
| 132 | return pi-1; | 118 | return pi-1; |
| 133 | else | 119 | else |
| @@ -790,7 +776,6 @@ static int luaK_code (FuncState *fs, Instruction i) { | |||
| 790 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, | 776 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, |
| 791 | MAX_INT, "code size overflow"); | 777 | MAX_INT, "code size overflow"); |
| 792 | f->code[fs->pc] = i; | 778 | f->code[fs->pc] = i; |
| 793 | /*printf("free: %d ", fs->freereg); printopcode(f, fs->pc);*/ | ||
| 794 | return fs->pc++; | 779 | return fs->pc++; |
| 795 | } | 780 | } |
| 796 | 781 | ||
