From b3adc63e8b78dbcec1547cc8b8ae5d929746bb33 Mon Sep 17 00:00:00 2001 From: Anicka Bernathova Date: Tue, 21 Jul 2009 19:36:22 +0200 Subject: [PATCH] fix if-else bug --- code.c | 2 +- int.c | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/code.c b/code.c index 170fd3a..dfb47a6 100644 --- a/code.c +++ b/code.c @@ -271,7 +271,7 @@ do_if(struct tree *t, struct list* where) c = eval_cond(t->pt.tif.c, -1, where); compile(t->pt.tif.i, if_branch); - compile(t->pt.tif.i, else_branch); + compile(t->pt.tif.e, else_branch); new_instr(nop, else_branch); jmp.u.jump.target = list_last(else_branch); new_instr(jmp, if_branch); diff --git a/int.c b/int.c index 60c40d5..bf3f2d9 100644 --- a/int.c +++ b/int.c @@ -690,7 +690,8 @@ interp(struct list* ins, struct list* hash) char* result; int v; - LIST_FOREACH(p, ins) { + p = (void*) ins->head.next; + while ((struct node*) p != &ins->head) { switch (p->opcode) { case OPC_SET: result = get_var(p->u.set.r); @@ -699,20 +700,20 @@ interp(struct list* ins, struct list* hash) break; case OPC_JUMP: p = p->u.jump.target; - continue; - break; + continue; case OPC_JUMP_IF: - if (eval_cond(p->u.jump_if.cond)) + if (eval_cond(p->u.jump_if.cond)) { p = p->u.jump_if.target; - continue; + continue; + } break; case OPC_JUMP_UNLESS: - if (!eval_cond(p->u.jump_unless.cond)) + if (!eval_cond(p->u.jump_unless.cond)) { p = p->u.jump_unless.target; - continue; + continue; + } break; case OPC_NOP: - continue; break; case OPC_GT: case OPC_LT: @@ -758,7 +759,9 @@ interp(struct list* ins, struct list* hash) case OPC_DISCARD: bye(0, NULL); break; - }} + } + p = (void*) ((struct node*) p)->next; + } deliver(default_mailbox, 0, hash); } -- 2.39.2