aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/lcode.c b/lcode.c
index a34eed8e..6d463311 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.98 2002/05/06 15:51:41 roberto Exp roberto $ 2** $Id: lcode.c,v 1.99 2002/05/07 17:36:56 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*/
@@ -338,22 +338,19 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) {
338 338
339static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) { 339static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) {
340 discharge2reg(fs, e, reg); 340 discharge2reg(fs, e, reg);
341 if (e->k == VJMP || hasjumps(e)) { 341 if (e->k == VJMP)
342 luaK_concat(fs, &e->t, e->info); /* put this jump in `t' list */
343 if (hasjumps(e)) {
342 int final; /* position after whole expression */ 344 int final; /* position after whole expression */
343 int p_f = NO_JUMP; /* position of an eventual PUSH false */ 345 int p_f = NO_JUMP; /* position of an eventual LOAD false */
344 int p_t = NO_JUMP; /* position of an eventual PUSH true */ 346 int p_t = NO_JUMP; /* position of an eventual LOAD true */
345 if (e->k == VJMP || need_value(fs, e->t, 1) 347 if (need_value(fs, e->t, 1) || need_value(fs, e->f, 0)) {
346 || need_value(fs, e->f, 0)) {
347 if (e->k != VJMP) { 348 if (e->k != VJMP) {
348 luaK_getlabel(fs); /* these instruction may be jump target */ 349 luaK_getlabel(fs); /* this instruction may be a jump target */
349 luaK_codeAsBx(fs, OP_JMP, 0, 2); /* to jump over both pushes */ 350 luaK_codeAsBx(fs, OP_JMP, 0, 2); /* to jump over both pushes */
350 } 351 }
351 else { /* last expression is a conditional (test + jump) */ 352 p_f = code_label(fs, reg, 0, 1);
352 fs->pc--; /* remove its jump */ 353 p_t = code_label(fs, reg, 1, 0);
353 lua_assert(testOpMode(GET_OPCODE(fs->f->code[fs->pc - 1]), OpModeT));
354 }
355 p_t = code_label(fs, reg, 1, 1);
356 p_f = code_label(fs, reg, 0, 0);
357 } 354 }
358 final = luaK_getlabel(fs); 355 final = luaK_getlabel(fs);
359 luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f); 356 luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f);