I fixed the way we are doing the evaluation of == and < Getting to &&, || next. Not sure if ! is correct

This commit is contained in:
Meyer Simon
2025-05-03 12:52:23 -04:00
parent 6434b7dfeb
commit 2ed5372761
2 changed files with 58 additions and 16 deletions

View File

@ -58,6 +58,11 @@ int S_Size(Stack *s){
return s->size;
}
void S_Merge(Stack *s1, Stack *s2){
for (Instruction * i = S_Pop(s1); i; i = S_Pop(s1)){
S_Push(s2, i, 1);
}
}
void emit_backpatch(Stack * s, int l){
for (Instruction * i = S_Pop(s); i; i = S_Pop(s)){
i->label = l;
@ -501,7 +506,7 @@ void emit_as_file(FILE * out_file, Instruction * i){
break;
case E_IF_X_TRUE:
fprintf(out_file,
"%4.d: if %s GOTO %d\n",
"%4.d: if %s True GOTO %d\n",
i->index,
get_string(i->operand1),
i->label
@ -509,7 +514,7 @@ void emit_as_file(FILE * out_file, Instruction * i){
break;
case E_IF_X_FALSE:
fprintf(out_file,
"%4.d: if %s false GOTO %d\n",
"%4.d: if %s False GOTO %d\n",
i->index,
get_string(i->operand1),
i->label
@ -518,21 +523,21 @@ void emit_as_file(FILE * out_file, Instruction * i){
case E_LESS_THAN:
// this feels wrong I need to TODO: this
fprintf(out_file,
"%4.d: if ( %s < %s ) GOTO %d\n",
"%4.d: %s = %s < %s\n",
i->index,
getName(i->result),
get_string(i->operand1),
get_string(i->operand2),
i->label
get_string(i->operand2)
);
break;
case E_EQUAL_TO:
// this feels wrong I need to TODO: this
fprintf(out_file,
"%4.d: if ( %s = %s ) GOTO %d\n",
"%4.d: %s = %s == %s\n",
i->index,
getName(i->result),
get_string(i->operand1),
get_string(i->operand2),
i->label
get_string(i->operand2)
);
break;
case E_CALL: