From a459cb11120300f50ea4b53c932850dc949e4586 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Tue, 6 May 2025 10:07:13 -0400 Subject: [PATCH] I believe that the backpatching before the and and or are wrong --- src/grammar.y | 13 ++++++++----- tests/sprint3/test/sp3_if_else.alpha | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 3d7db57..104653f 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -617,6 +617,7 @@ compound_statement: emit_goto(*(int*)(S_Pop(stack))); emit_label(l); } + // IF L_PAREN expression R_PAREN THEN sblock ELSE sblock | IF L_PAREN { S_Push(TrueList, S_Init(), 0); S_Push(FalseList, S_Init(), 0); @@ -680,7 +681,9 @@ simple_statement: } ASSIGN expression { // ---------------------------------------------------------------------------- - emit_label(label_gen()); + if ( getTypeEntry((TableNode*)$4) == boo ) { + emit_label(label_gen()); + } emit_backpatch(S_Pop(TrueList), getLabel(current)); emit_backpatch(S_Pop(FalseList), getLabel(current)); // ---------------------------------------------------------------------------- @@ -921,8 +924,8 @@ expression: // ---------------------------------------------------------------------------- uint_least8_t b = 0; emit_assignment(node, tn_or_const(BOOLEAN,&b)); - emit_label(label_gen()); - emit_backpatch(S_Pop(TrueList), getLabel(current)); + // emit_label(label_gen()); + // emit_backpatch(S_Pop(TrueList), getLabel(current)); emit_conditional_jump(E_IF_X_FALSE, 0, tn_or_const(NODE, $1)); Stack * t1 = S_Peek(FalseList); if(t1==NULL){ @@ -974,8 +977,8 @@ expression: // ---------------------------------------------------------------------------- uint_least8_t b = 1; emit_assignment(node, tn_or_const(BOOLEAN,&b)); - emit_label(label_gen()); - emit_backpatch(S_Pop(TrueList), getLabel(current)); + // emit_label(label_gen()); + // emit_backpatch(S_Pop(TrueList), getLabel(current)); emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $1)); Stack * t1 = S_Peek(TrueList); if(t1==NULL){ diff --git a/tests/sprint3/test/sp3_if_else.alpha b/tests/sprint3/test/sp3_if_else.alpha index 40c2580..6825b77 100644 --- a/tests/sprint3/test/sp3_if_else.alpha +++ b/tests/sprint3/test/sp3_if_else.alpha @@ -13,8 +13,8 @@ bar (r,s) := { entry (arg) := { [ integer: r ; integer: s; Boolean: x] - x := (r < s) & x; - if ( r < s ) then { + (* x := (r < s) & x; *) + if ( ( r < s ) & (s = r) ) then { r := 5; } else { r := 7;