diff options
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 1.11 2000/03/13 20:37:16 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.12 2000/03/15 20:50:33 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 | */ |
@@ -38,7 +38,7 @@ static Instruction *previous_instruction (FuncState *fs) { | |||
38 | 38 | ||
39 | 39 | ||
40 | static int luaK_primitivecode (FuncState *fs, Instruction i) { | 40 | static int luaK_primitivecode (FuncState *fs, Instruction i) { |
41 | luaM_growvector(fs->L, fs->f->code, fs->pc, 1, Instruction, codeEM, MAXARG_S); | 41 | luaM_growvector(fs->L, fs->f->code, fs->pc, 1, Instruction, codeEM, MAX_INT); |
42 | fs->f->code[fs->pc] = i; | 42 | fs->f->code[fs->pc] = i; |
43 | return fs->pc++; | 43 | return fs->pc++; |
44 | } | 44 | } |
@@ -114,6 +114,7 @@ static void luaK_neq (FuncState *fs) { | |||
114 | if (*previous == CREATE_U(OP_PUSHNIL, 1)) { | 114 | if (*previous == CREATE_U(OP_PUSHNIL, 1)) { |
115 | fs->pc--; /* remove PUSHNIL */ | 115 | fs->pc--; /* remove PUSHNIL */ |
116 | luaK_deltastack(fs, -1); /* undo effect of PUSHNIL */ | 116 | luaK_deltastack(fs, -1); /* undo effect of PUSHNIL */ |
117 | luaK_getlabel(fs); /* previous instruction could be a (closed) call */ | ||
117 | } | 118 | } |
118 | else | 119 | else |
119 | luaK_S(fs, OP_IFNEQJMP, 0, -2); | 120 | luaK_S(fs, OP_IFNEQJMP, 0, -2); |
@@ -150,12 +151,14 @@ int luaK_code (FuncState *fs, Instruction i, int delta) { | |||
150 | 151 | ||
151 | void luaK_fixjump (FuncState *fs, int pc, int dest) { | 152 | void luaK_fixjump (FuncState *fs, int pc, int dest) { |
152 | Instruction *jmp = &fs->f->code[pc]; | 153 | Instruction *jmp = &fs->f->code[pc]; |
153 | if (dest != NO_JUMP) { | 154 | if (dest == NO_JUMP) |
154 | /* jump is relative to position following jump instruction */ | ||
155 | SETARG_S(*jmp, dest-(pc+1)); | ||
156 | } | ||
157 | else | ||
158 | SETARG_S(*jmp, 0); /* absolute value to represent end of list */ | 155 | SETARG_S(*jmp, 0); /* absolute value to represent end of list */ |
156 | else { /* jump is relative to position following jump instruction */ | ||
157 | int offset = dest-(pc+1); | ||
158 | if (offset < -MAXARG_S || offset > MAXARG_S) | ||
159 | luaK_error(fs->ls, "control structure too long"); | ||
160 | SETARG_S(*jmp, offset); | ||
161 | } | ||
159 | } | 162 | } |
160 | 163 | ||
161 | 164 | ||
@@ -164,7 +167,7 @@ static int luaK_getjump (FuncState *fs, int pc) { | |||
164 | if (offset == 0) | 167 | if (offset == 0) |
165 | return NO_JUMP; /* end of list */ | 168 | return NO_JUMP; /* end of list */ |
166 | else | 169 | else |
167 | return (pc+1)+offset; | 170 | return (pc+1)+offset; /* turn offset into absolute position */ |
168 | } | 171 | } |
169 | 172 | ||
170 | 173 | ||
@@ -344,9 +347,9 @@ static void luaK_patchlistaux (FuncState *fs, int list, int target, | |||
344 | Instruction *i = &code[list]; | 347 | Instruction *i = &code[list]; |
345 | OpCode op = GET_OPCODE(*i); | 348 | OpCode op = GET_OPCODE(*i); |
346 | if (op == special) /* this `op' already has a value */ | 349 | if (op == special) /* this `op' already has a value */ |
347 | SETARG_S(*i, special_target-(list+1)); | 350 | luaK_fixjump(fs, list, special_target); |
348 | else { | 351 | else { |
349 | SETARG_S(*i, target-(list+1)); /* do the patch */ | 352 | luaK_fixjump(fs, list, target); /* do the patch */ |
350 | if (op == OP_ONTJMP) /* remove eventual values */ | 353 | if (op == OP_ONTJMP) /* remove eventual values */ |
351 | SET_OPCODE(*i, OP_IFTJMP); | 354 | SET_OPCODE(*i, OP_IFTJMP); |
352 | else if (op == OP_ONFJMP) | 355 | else if (op == OP_ONFJMP) |