It seems to be working but I need to ckeck again
This commit is contained in:
114
src/grammar.y
114
src/grammar.y
@ -631,23 +631,8 @@ compound_statement:
|
||||
S_Push(TrueList, S_Init(), 0);
|
||||
S_Push(FalseList, S_Init(), 0);
|
||||
}expression R_PAREN THEN {
|
||||
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 ELSE {
|
||||
// NOTE we are not going back to
|
||||
int l = label_gen();
|
||||
@ -921,11 +906,47 @@ 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);
|
||||
if(t1==NULL){
|
||||
t1 = S_Init();
|
||||
S_Push(FalseList, 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);
|
||||
if(t==NULL){
|
||||
t = S_Init();
|
||||
S_Push(FalseList, 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();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
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_AND,node,tn_or_const(NODE,$1),tn_or_const(NODE,$3));
|
||||
//emit_binary_op(E_AND,node,tn_or_const(NODE,$1),tn_or_const(NODE,$3));
|
||||
$$ = node;
|
||||
} else {
|
||||
$$=undefined;
|
||||
@ -935,11 +956,47 @@ expression:
|
||||
|
||||
| expression OR 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);
|
||||
if(t1==NULL){
|
||||
t1 = S_Init();
|
||||
S_Push(FalseList, t1, 1);
|
||||
}
|
||||
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){
|
||||
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);
|
||||
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));
|
||||
// emit_binary_op(E_OR,node,tn_or_const(NODE,$1),tn_or_const(NODE,$3));
|
||||
$$ = node;
|
||||
} else {
|
||||
$$=undefined;
|
||||
@ -949,11 +1006,10 @@ expression:
|
||||
|
||||
| expression LESS_THAN expression
|
||||
{
|
||||
// ----------------------------------------------------------------------------
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
// ----------------------------------------------------------------------------
|
||||
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);
|
||||
if(t==NULL){
|
||||
@ -968,6 +1024,9 @@ 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");
|
||||
@ -983,13 +1042,11 @@ expression:
|
||||
|
||||
| expression EQUAL_TO expression
|
||||
{
|
||||
printdebug("equals check expression");
|
||||
if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1) != undefined) {
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
// ----------------------------------------------------------------------------
|
||||
emit_binary_op(E_EQUAL_TO, node, tn_or_const(NODE,$1), tn_or_const(NODE,$3));
|
||||
/*
|
||||
emit_conditional_jump(E_EQUAL_TO, 0, 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);
|
||||
if(t==NULL){
|
||||
t = S_Init();
|
||||
@ -1003,7 +1060,12 @@ 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) {
|
||||
// emit_binary_op(E_EQUAL_TO, node, tn_or_const(NODE,$1), tn_or_const(NODE,$3));
|
||||
$$ = node;
|
||||
|
||||
} else {
|
||||
|
@ -58,7 +58,16 @@ int S_Size(Stack *s){
|
||||
return s->size;
|
||||
}
|
||||
|
||||
void S_Merge(Stack *s1, Stack *s2){
|
||||
void S_Merge(Stack *list){
|
||||
Stack* s1 = S_Pop(list);
|
||||
Stack* s2 = S_Peek(list);
|
||||
if(s1 == NULL){
|
||||
return;
|
||||
}
|
||||
if(s2 == NULL){
|
||||
S_Push(list, s1, 0);
|
||||
return;
|
||||
}
|
||||
for (Instruction * i = S_Pop(s1); i; i = S_Pop(s1)){
|
||||
S_Push(s2, i, 1);
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ void * S_Pop(Stack *s);
|
||||
void * S_Peek(Stack *s);
|
||||
bool S_IsEmpty(Stack *s);
|
||||
int S_Size(Stack *s);
|
||||
void S_Merge(Stack *list);
|
||||
//______________________________________________________________________________________________
|
||||
|
||||
typedef union TNConstUnion TNConstUnion;
|
||||
|
26
tests/sprint3/test/sp3_if_else_sse.alpha
Normal file
26
tests/sprint3/test/sp3_if_else_sse.alpha
Normal file
@ -0,0 +1,26 @@
|
||||
type rec: [character: x; integer: y]
|
||||
|
||||
type T2: rec -> integer
|
||||
|
||||
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;
|
||||
} else {
|
||||
result := 9;
|
||||
} *)
|
||||
z := t;
|
||||
} else {
|
||||
y := true; (* bar('c', 7); *)
|
||||
}
|
||||
return 0;
|
||||
}
|
29
tests/sprint3/test/sp3_if_else_sse2.alpha
Normal file
29
tests/sprint3/test/sp3_if_else_sse2.alpha
Normal file
@ -0,0 +1,29 @@
|
||||
type rec: [character: x; integer: y]
|
||||
|
||||
type T2: rec -> integer
|
||||
|
||||
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 ( y & z | t ) then {
|
||||
(* if ( ( x < y ) & ( z = t ) ) then {
|
||||
y := z < t;
|
||||
t:= 0;
|
||||
} else {
|
||||
t := z = t;
|
||||
z := 1;
|
||||
} *)
|
||||
t := true;
|
||||
} else {
|
||||
y := true; (* bar('c', 7); *)
|
||||
}
|
||||
(* x := x & y; *)
|
||||
return 0;
|
||||
}
|
27
tests/sprint3/test/sp3_while_sse.alpha
Normal file
27
tests/sprint3/test/sp3_while_sse.alpha
Normal file
@ -0,0 +1,27 @@
|
||||
type rec: [character: x; integer: y]
|
||||
|
||||
type T2: rec -> integer
|
||||
|
||||
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]
|
||||
while ( !( x & y ) (* | ( z | t ) *) ) {
|
||||
(*
|
||||
if ( ( x < y ) & ( z = t ) ) then {
|
||||
y := z < t;
|
||||
} else {
|
||||
t := z = t;
|
||||
}
|
||||
*)
|
||||
y := true; (* bar('c', 7); *)
|
||||
}
|
||||
(* x := x & y; *)
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user