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); emit_label(*l);
S_Push(stack, l, 2); S_Push(stack, l, 2);
} expression R_PAREN { } 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_label(label_gen());
emit_backpatch(S_Pop(TrueList), getLabel(current)); emit_backpatch(S_Pop(TrueList), getLabel(current));
} sblock { } sblock {
@ -907,40 +892,40 @@ expression:
| expression AND expression | expression AND expression
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $1)); emit_label(label_gen());
Stack * t1 = S_Peek(TrueList); emit_backpatch(S_Pop(TrueList), getLabel(current));
if(t1==NULL){ emit_conditional_jump(E_IF_X_FALSE, 0, tn_or_const(NODE, $1));
t1 = S_Init(); Stack * t1 = S_Peek(FalseList);
S_Push(TrueList, t1, 1);
}
S_Push(t1, current, 1);
emit_goto(0);
t1 = S_Peek(FalseList);
if(t1==NULL){ if(t1==NULL){
t1 = S_Init(); t1 = S_Init();
S_Push(FalseList, t1, 1); S_Push(FalseList, t1, 1);
} }
S_Push(t1, current, 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_label(label_gen());
emit_backpatch(S_Pop(TrueList), getLabel(current)); emit_backpatch(S_Pop(TrueList), getLabel(current));
emit_conditional_jump(E_IF_X_FALSE, 0, tn_or_const(NODE, $3));
emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $3)); Stack * t = S_Peek(FalseList);
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){ if(t==NULL){
t = S_Init(); t = S_Init();
S_Push(FalseList, t, 1); S_Push(FalseList, t, 1);
} }
S_Push(t, current, 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); S_Merge(FalseList);
emit_label(label_gen());
emit_backpatch(S_Pop(TrueList), getLabel(current));
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
printdebug("AND"); printdebug("AND");
char* temp = temp_var_gen(); char* temp = temp_var_gen();
@ -957,6 +942,8 @@ expression:
| expression OR 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)); emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $1));
Stack * t1 = S_Peek(TrueList); Stack * t1 = S_Peek(TrueList);
if(t1==NULL){ if(t1==NULL){
@ -973,7 +960,6 @@ expression:
S_Push(t1, current, 1); S_Push(t1, current, 1);
emit_label(label_gen()); emit_label(label_gen());
emit_backpatch(S_Pop(FalseList), getLabel(current)); emit_backpatch(S_Pop(FalseList), getLabel(current));
emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $3)); emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, $3));
Stack * t = S_Peek(TrueList); Stack * t = S_Peek(TrueList);
if(t==NULL){ if(t==NULL){
@ -989,14 +975,11 @@ expression:
} }
S_Push(t, current, 1); S_Push(t, current, 1);
S_Merge(TrueList); S_Merge(TrueList);
// This is very inportant.
// With OR W DO NOT BP THE TRUELIST Only with AND
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
printdebug("OR"); printdebug("OR");
if((getTypeEntry((TableNode*)$1)==getTypeEntry((TableNode*)$3)) && getTypeEntry((TableNode*)$1) == boo) { if((getTypeEntry((TableNode*)$1)==getTypeEntry((TableNode*)$3)) && getTypeEntry((TableNode*)$1) == boo) {
char* temp = temp_var_gen(); char* temp = temp_var_gen();
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL); 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; $$ = node;
} else { } else {
$$=undefined; $$=undefined;
@ -1009,6 +992,8 @@ expression:
char* temp = temp_var_gen(); char* temp = temp_var_gen();
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL); 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_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)); emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, node));
Stack * t = S_Peek(TrueList); Stack * t = S_Peek(TrueList);
@ -1024,10 +1009,6 @@ expression:
S_Push(FalseList, t, 1); S_Push(FalseList, t, 1);
} }
S_Push(t, current, 1); S_Push(t, current, 1);
// emit_label(label_gen());
// emit_backpatch(S_Pop(TrueList), getLabel(current));
/*
*/
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
printdebug("less than expression"); printdebug("less than expression");
if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1)==integ) { if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1)==integ) {
@ -1045,6 +1026,8 @@ expression:
char* temp = temp_var_gen(); char* temp = temp_var_gen();
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL); 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_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)); emit_conditional_jump(E_IF_X_TRUE, 0, tn_or_const(NODE, node));
Stack * t = S_Peek(TrueList); Stack * t = S_Peek(TrueList);
@ -1060,8 +1043,6 @@ expression:
S_Push(FalseList, t, 1); S_Push(FalseList, t, 1);
} }
S_Push(t, current, 1); S_Push(t, current, 1);
// emit_label(label_gen());
// emit_backpatch(S_Pop(TrueList), getLabel(current));
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
printdebug("equals check expression"); printdebug("equals check expression");
if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1) != undefined) { 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 entry: main
function bar: T2 function bar: T2
(*
bar (r,s) := { bar (r,s) := {
return 0; return 0;
} }
*)
entry (arg) := { entry (arg) := {
[ Boolean:x ; Boolean:y ; Boolean:z ; Boolean:t] [ Boolean:x ; Boolean:y ; Boolean:z ; Boolean:t]
if ( !( x < y ) & ( z & t ) ) then { if ( ( x < y ) (* < ( z & t )*)) then {
(* if ( result < w.y ) then {
result := 8; (*
if ( x<y & !(x=y) ) then {
t := 8;
} else { } else {
result := 9; }
} *) *)
z := t;
z := 9;
} else { } else {
y := true; (* bar('c', 7); *) y := true; (* bar('c', 7); *)
} }

View File

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

View File

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