I think it was broken so I fixed it

This commit is contained in:
Meyer Simon
2025-05-04 14:30:04 -04:00
parent 18b5daea0e
commit 4ae76d0341
4 changed files with 57 additions and 66 deletions

View File

@ -603,21 +603,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 {
@ -907,40 +892,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();
@ -957,6 +942,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){
@ -973,7 +960,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){
@ -989,14 +975,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;
@ -1009,6 +992,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);
@ -1024,10 +1009,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) {
@ -1045,6 +1026,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);
@ -1060,8 +1043,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) {

View File

@ -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<y & !(x=y) ) then {
t := 8;
} else {
result := 9;
} *)
z := t;
}
*)
z := 9;
} else {
y := true; (* bar('c', 7); *)
}

View File

@ -12,18 +12,23 @@ bar (r,s) := {
entry (arg) := {
[ Boolean:x ; Boolean:y ; Boolean:z ; Boolean:t]
if ( y & z | t ) then {
(* if ( ( x < y ) & ( z = t ) ) then {
y := z < t;
t:= 0;
} else {
t := z = t;
z := 1;
} *)
(* if ( y & (z | t) ) then { *)
if ( ( x = y ) & ( z < t ) ) then {
(* y := z < t; *)
t:= 0;
} else {
(* t := z = t; *)
z := 1;
}
(*
if ( x & y ) then {
t := true;
} else {
y := true; (* bar('c', 7); *)
y := true;
}
*)
(* } else { *)
(* } *)
(* x := x & y; *)
return 0;
}

View File

@ -11,19 +11,19 @@ bar (r,s) := {
}
entry (arg) := {
[ integer: x ; integer: y; integer: z;integer: t]
while ( (!(x = y)) < ( z = t ) ) {
x := x;
while ( (x < y) = ( z < t ) ) {
[ Boolean: x ; Boolean: y; Boolean: z;Boolean: t]
while ( ((x = y)) < ( z | t ) ) {
while ( (x & y) = ( z < t ) ) {
y := y;
}
(*
x := x;
*)
if ( (x = y) = ( z < t ) ) then {
x := 1;
} else {
x := 1;
}
*)
}
return 0;
}