I believe that the backpatching before the and and or are wrong

This commit is contained in:
Meyer Simon
2025-05-06 10:07:13 -04:00
parent bab71df517
commit a459cb1112
2 changed files with 10 additions and 7 deletions

View File

@ -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
{
// ----------------------------------------------------------------------------
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){

View File

@ -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;