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 {
|
||||
|
Reference in New Issue
Block a user