I fixed the way we are doing the evaluation of == and < Getting to &&, || next. Not sure if ! is correct
This commit is contained in:
@ -603,6 +603,21 @@ 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 {
|
||||
@ -616,8 +631,23 @@ 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();
|
||||
@ -805,8 +835,10 @@ expression:
|
||||
if(getTypeEntry((TableNode*)$2) == boo) {
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
emit_unary_op(E_NOT,node,tn_or_const(NODE,$2));
|
||||
//NOTE ADD ASSIGNMENT EMIT HERE (MIGHT NEED TO PUSH TO STACK)
|
||||
Stack * t = S_Pop(TrueList);
|
||||
Stack * f = S_Pop(FalseList);
|
||||
S_Push(TrueList, f, 0);
|
||||
S_Push(FalseList, t, 0);
|
||||
//result of unary operation
|
||||
$$ = node;
|
||||
} else {
|
||||
@ -917,7 +949,12 @@ expression:
|
||||
|
||||
| expression LESS_THAN expression
|
||||
{
|
||||
emit_conditional_jump(E_LESS_THAN, 0, tn_or_const(NODE,$1), tn_or_const(NODE,$3));
|
||||
// ----------------------------------------------------------------------------
|
||||
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){
|
||||
t = S_Init();
|
||||
@ -931,15 +968,12 @@ expression:
|
||||
S_Push(FalseList, t, 1);
|
||||
}
|
||||
S_Push(t, current, 1);
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
printdebug("less than expression");
|
||||
if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1)==integ) {
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
$$ = node;
|
||||
} else 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_LESS_THAN,node,tn_or_const(NODE,$1),tn_or_const(NODE,$3));
|
||||
$$ = node;
|
||||
}else {
|
||||
$$=undefined;
|
||||
@ -953,6 +987,8 @@ 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));
|
||||
Stack * t = S_Peek(TrueList);
|
||||
if(t==NULL){
|
||||
@ -967,6 +1003,7 @@ expression:
|
||||
S_Push(FalseList, t, 1);
|
||||
}
|
||||
S_Push(t, current, 1);
|
||||
*/
|
||||
$$ = node;
|
||||
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user