From 9d98b75bc0fd041a4e123be3612228c4e953beee Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Sun, 4 May 2025 14:30:04 -0400 Subject: [PATCH] I think it was broken so I fixed it --- src/grammar.y | 73 +++++++------------ tests/sprint3/test/sp3_if_else_sse.alpha | 17 +++-- tests/sprint3/test/sp3_if_else_sse2.alpha | 23 +++--- .../sprint3/test/sp3_while_nested_bools.alpha | 10 +-- 4 files changed, 57 insertions(+), 66 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index b2cc77b..c190783 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -550,21 +550,6 @@ compound_statement: emit_label(*l); S_Push(stack, l, 2); } expression R_PAREN { - emit_backpatch(S_Pop(TrueList), getLabel(current)); - emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $4)); - Stack * t = S_Peek(TrueList); - if(t==NULL){ - t = S_Init(); - S_Push(TrueList, t, 1); - } - S_Push(t, current, 1); - emit_goto(0); - t = S_Peek(FalseList); - if(t==NULL){ - t = S_Init(); - S_Push(FalseList, t, 1); - } - S_Push(t, current, 1); emit_label(label_gen()); emit_backpatch(S_Pop(TrueList), getLabel(current)); } sblock { @@ -854,40 +839,40 @@ expression: | expression AND expression { // ---------------------------------------------------------------------------- - emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $1)); - Stack * t1 = S_Peek(TrueList); - if(t1==NULL){ - t1 = S_Init(); - S_Push(TrueList, t1, 1); - } - S_Push(t1, current, 1); - emit_goto(0); - t1 = S_Peek(FalseList); + 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){ t1 = S_Init(); S_Push(FalseList, t1, 1); } S_Push(t1, current, 1); + emit_goto(0); + t1 = S_Peek(TrueList); + if(t1==NULL){ + t1 = S_Init(); + S_Push(TrueList, t1, 1); + } + S_Push(t1, current, 1); emit_label(label_gen()); emit_backpatch(S_Pop(TrueList), getLabel(current)); - - emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $3)); - Stack * t = S_Peek(TrueList); - if(t==NULL){ - t = S_Init(); - S_Push(TrueList, t, 1); - } - S_Push(t, current, 1); - emit_goto(0); - t = S_Peek(FalseList); + emit_conditional_jump(E_IF_X_FALSE, 0, tn_or_const(NODE, $3)); + Stack * t = S_Peek(FalseList); if(t==NULL){ t = S_Init(); S_Push(FalseList, t, 1); } S_Push(t, current, 1); + + emit_goto(0); + t = S_Peek(TrueList); + if(t==NULL){ + t = S_Init(); + S_Push(TrueList, t, 1); + } + S_Push(t, current, 1); S_Merge(FalseList); - emit_label(label_gen()); - emit_backpatch(S_Pop(TrueList), getLabel(current)); // ---------------------------------------------------------------------------- printdebug("AND"); char* temp = temp_var_gen(); @@ -904,6 +889,8 @@ expression: | expression OR expression { // ---------------------------------------------------------------------------- + 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){ @@ -920,7 +907,6 @@ expression: S_Push(t1, current, 1); emit_label(label_gen()); emit_backpatch(S_Pop(FalseList), getLabel(current)); - emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $3)); Stack * t = S_Peek(TrueList); if(t==NULL){ @@ -936,14 +922,11 @@ expression: } S_Push(t, current, 1); S_Merge(TrueList); - // This is very inportant. - // With OR W DO NOT BP THE TRUELIST Only with AND // ---------------------------------------------------------------------------- printdebug("OR"); if((getTypeEntry((TableNode*)$1)==getTypeEntry((TableNode*)$3)) && getTypeEntry((TableNode*)$1) == boo) { char* temp = temp_var_gen(); TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL); - // emit_binary_op(E_OR,node,tn_or_const(NODE,$1),tn_or_const(NODE,$3)); $$ = node; } else { $$=undefined; @@ -956,6 +939,8 @@ expression: char* temp = temp_var_gen(); TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL); // ---------------------------------------------------------------------------- + emit_label(label_gen()); + emit_backpatch(S_Pop(TrueList), getLabel(current)); emit_binary_op(E_LESS_THAN, node, tn_or_const(NODE,$1), tn_or_const(NODE,$3)); emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, node)); Stack * t = S_Peek(TrueList); @@ -971,10 +956,6 @@ expression: S_Push(FalseList, t, 1); } S_Push(t, current, 1); - // emit_label(label_gen()); - // emit_backpatch(S_Pop(TrueList), getLabel(current)); - /* - */ // ---------------------------------------------------------------------------- printdebug("less than expression"); if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1)==integ) { @@ -992,6 +973,8 @@ expression: char* temp = temp_var_gen(); TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL); // ---------------------------------------------------------------------------- + emit_label(label_gen()); + emit_backpatch(S_Pop(TrueList), getLabel(current)); emit_binary_op(E_EQUAL_TO, node, tn_or_const(NODE,$1), tn_or_const(NODE,$3)); emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, node)); Stack * t = S_Peek(TrueList); @@ -1007,8 +990,6 @@ expression: S_Push(FalseList, t, 1); } S_Push(t, current, 1); - // emit_label(label_gen()); - // emit_backpatch(S_Pop(TrueList), getLabel(current)); // ---------------------------------------------------------------------------- printdebug("equals check expression"); if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1) != undefined) { diff --git a/tests/sprint3/test/sp3_if_else_sse.alpha b/tests/sprint3/test/sp3_if_else_sse.alpha index 24ec9ee..f5d7d79 100644 --- a/tests/sprint3/test/sp3_if_else_sse.alpha +++ b/tests/sprint3/test/sp3_if_else_sse.alpha @@ -6,19 +6,24 @@ type main: string -> integer function entry: main function bar: T2 + (* bar (r,s) := { return 0; } + *) entry (arg) := { [ Boolean:x ; Boolean:y ; Boolean:z ; Boolean:t] - if ( !( x < y ) & ( z & t ) ) then { - (* if ( result < w.y ) then { - result := 8; + if ( ( x < y ) (* < ( z & t )*)) then { + + (* + if ( x