diff options
| -rw-r--r-- | lcode.c | 35 | ||||
| -rw-r--r-- | lcode.h | 3 |
2 files changed, 24 insertions, 14 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 1.101 2002/05/10 17:02:32 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.102 2002/05/10 19:22:11 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 | */ |
| @@ -75,12 +75,6 @@ int luaK_getlabel (FuncState *fs) { | |||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | 77 | ||
| 78 | void luaK_dischargejpc (FuncState *fs) { | ||
| 79 | luaK_patchlist(fs, fs->jpc, fs->pc); /* discharge old list `jpc' */ | ||
| 80 | fs->jpc = NO_JUMP; | ||
| 81 | } | ||
| 82 | |||
| 83 | |||
| 84 | static int luaK_getjump (FuncState *fs, int pc) { | 78 | static int luaK_getjump (FuncState *fs, int pc) { |
| 85 | int offset = GETARG_sBx(fs->f->code[pc]); | 79 | int offset = GETARG_sBx(fs->f->code[pc]); |
| 86 | if (offset == NO_JUMP) /* point to itself represents end of list */ | 80 | if (offset == NO_JUMP) /* point to itself represents end of list */ |
| @@ -144,9 +138,19 @@ static void luaK_patchlistaux (FuncState *fs, int list, | |||
| 144 | } | 138 | } |
| 145 | 139 | ||
| 146 | 140 | ||
| 141 | void luaK_dischargejpc (FuncState *fs) { | ||
| 142 | luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc); | ||
| 143 | fs->jpc = NO_JUMP; | ||
| 144 | } | ||
| 145 | |||
| 146 | |||
| 147 | void luaK_patchlist (FuncState *fs, int list, int target) { | 147 | void luaK_patchlist (FuncState *fs, int list, int target) { |
| 148 | lua_assert(target <= fs->pc); | 148 | if (target == fs->pc) |
| 149 | luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target); | 149 | luaK_patchtohere(fs, list); |
| 150 | else { | ||
| 151 | lua_assert(target < fs->pc); | ||
| 152 | luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target); | ||
| 153 | } | ||
| 150 | } | 154 | } |
| 151 | 155 | ||
| 152 | 156 | ||
| @@ -342,12 +346,12 @@ static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) { | |||
| 342 | int p_f = NO_JUMP; /* position of an eventual LOAD false */ | 346 | int p_f = NO_JUMP; /* position of an eventual LOAD false */ |
| 343 | int p_t = NO_JUMP; /* position of an eventual LOAD true */ | 347 | int p_t = NO_JUMP; /* position of an eventual LOAD true */ |
| 344 | if (need_value(fs, e->t, 1) || need_value(fs, e->f, 0)) { | 348 | if (need_value(fs, e->t, 1) || need_value(fs, e->f, 0)) { |
| 345 | if (e->k != VJMP) { | 349 | int fj = NO_JUMP; /* first jump (over LOAD ops.) */ |
| 346 | luaK_getlabel(fs); /* this instruction may be a jump target */ | 350 | if (e->k != VJMP) |
| 347 | luaK_codeAsBx(fs, OP_JMP, 0, 2); /* to jump over both pushes */ | 351 | fj = luaK_jump(fs); |
| 348 | } | ||
| 349 | p_f = code_label(fs, reg, 0, 1); | 352 | p_f = code_label(fs, reg, 0, 1); |
| 350 | p_t = code_label(fs, reg, 1, 0); | 353 | p_t = code_label(fs, reg, 1, 0); |
| 354 | luaK_patchtohere(fs, fj); | ||
| 351 | } | 355 | } |
| 352 | final = luaK_getlabel(fs); | 356 | final = luaK_getlabel(fs); |
| 353 | luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f); | 357 | luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f); |
| @@ -724,6 +728,11 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { | |||
| 724 | } | 728 | } |
| 725 | 729 | ||
| 726 | 730 | ||
| 731 | void luaK_fixline (FuncState *fs, int line) { | ||
| 732 | fs->f->lineinfo[fs->pc - 1] = line; | ||
| 733 | } | ||
| 734 | |||
| 735 | |||
| 727 | int luaK_code (FuncState *fs, Instruction i, int line) { | 736 | int luaK_code (FuncState *fs, Instruction i, int line) { |
| 728 | Proto *f = fs->f; | 737 | Proto *f = fs->f; |
| 729 | int oldsize = f->sizecode; | 738 | int oldsize = f->sizecode; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.h,v 1.34 2002/05/10 17:02:32 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.35 2002/05/10 19:22:11 roberto Exp $ |
| 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 | */ |
| @@ -44,6 +44,7 @@ typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; | |||
| 44 | int luaK_code (FuncState *fs, Instruction i, int line); | 44 | int luaK_code (FuncState *fs, Instruction i, int line); |
| 45 | int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); | 45 | int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); |
| 46 | int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); | 46 | int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); |
| 47 | void luaK_fixline (FuncState *fs, int line); | ||
| 47 | void luaK_nil (FuncState *fs, int from, int n); | 48 | void luaK_nil (FuncState *fs, int from, int n); |
| 48 | void luaK_reserveregs (FuncState *fs, int n); | 49 | void luaK_reserveregs (FuncState *fs, int n); |
| 49 | int luaK_stringK (FuncState *fs, TString *s); | 50 | int luaK_stringK (FuncState *fs, TString *s); |
