diff options
-rw-r--r-- | lcode.c | 23 | ||||
-rw-r--r-- | lopcodes.h | 23 |
2 files changed, 35 insertions, 11 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) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.48 2000/03/10 18:37:44 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.49 2000/03/13 20:37:16 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -161,4 +161,25 @@ OP_SETLINE/* U - - LINE=u */ | |||
161 | #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) (<=MAXARG_B) */ | 161 | #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) (<=MAXARG_B) */ |
162 | 162 | ||
163 | 163 | ||
164 | /* | ||
165 | ** we use int to manipulte most arguments, so they must fit | ||
166 | */ | ||
167 | #if MAXARG_U > MAX_INT | ||
168 | #undef MAXARG_U | ||
169 | #define MAXARG_U MAX_INT | ||
170 | #endif | ||
171 | #if MAXARG_S > MAX_INT | ||
172 | #undef MAXARG_S | ||
173 | #define MAXARG_S MAX_INT | ||
174 | #endif | ||
175 | #if MAXARG_A > MAX_INT | ||
176 | #undef MAXARG_A | ||
177 | #define MAXARG_A MAX_INT | ||
178 | #endif | ||
179 | #if MAXARG_B > MAX_INT | ||
180 | #undef MAXARG_B | ||
181 | #define MAXARG_B MAX_INT | ||
182 | #endif | ||
183 | |||
184 | |||
164 | #endif | 185 | #endif |