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) {