From 8c409561b73593a2de04fbf9ed32f6522a7991d5 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Tue, 6 May 2025 19:35:49 -0400 Subject: [PATCH] I made a rebase --- src/grammar.y | 7 +++++-- src/intermediate_code.c | 3 +++ src/symbol_table.c | 4 ++-- tests/programs/fib.alpha | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index a94f5dd..ccdd9da 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -608,6 +608,9 @@ compound_statement: emit_label(*l); S_Push(stack, l, 2); } expression R_PAREN { + emit_conditional_jump(E_IF_X_FALSE, 0, tn_or_const(NODE, $4)); + Stack * t = S_Peek(FalseList); + S_Push(t, current, 1); emit_label(label_gen()); emit_backpatch(S_Pop(TrueList), getLabel(current)); } sblock { @@ -1030,7 +1033,6 @@ expression: // 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); if(t==NULL){ @@ -1045,6 +1047,7 @@ expression: S_Push(FalseList, t, 1); } S_Push(t, current, 1); + /* */ // ---------------------------------------------------------------------------- printdebug("less than expression"); @@ -1064,7 +1067,6 @@ expression: 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_IF_X_TRUE, 0, tn_or_const(NODE, node)); Stack * t = S_Peek(TrueList); if(t==NULL){ @@ -1079,6 +1081,7 @@ expression: S_Push(FalseList, t, 1); } S_Push(t, current, 1); + /* */ // emit_label(label_gen()); // emit_backpatch(S_Pop(TrueList), getLabel(current)); diff --git a/src/intermediate_code.c b/src/intermediate_code.c index 3a473a1..618fbba 100644 --- a/src/intermediate_code.c +++ b/src/intermediate_code.c @@ -316,7 +316,10 @@ void emit_return(TNodeOrConst *value) { void emit_reserve(TableNode *result, TNodeOrConst *size) { // this needs to change // we need to take a int + /* emit_binary_op(E_MUL, result, + */ + emit_parameter(size); emit_function_call(result, 1, tn_or_const(NODE, look_up(cur, "reserve"))); } diff --git a/src/symbol_table.c b/src/symbol_table.c index 9f81805..2f2e8ac 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -1489,7 +1489,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if ((getFirstChild(node)) == NULL) { print_symbol_table(getFirstChild(node), file_ptr); } else { - if (getLine(getFirstChild(node)) < 0) { + if (getLine(getFirstChild(node)) < -3) { continue; } else { print_symbol_table(getFirstChild(node), file_ptr); @@ -1763,4 +1763,4 @@ int getStackSize() { if (i % 16 != 0) i += 8; return i; -} \ No newline at end of file +} diff --git a/tests/programs/fib.alpha b/tests/programs/fib.alpha index 287614b..1a9d185 100644 --- a/tests/programs/fib.alpha +++ b/tests/programs/fib.alpha @@ -40,7 +40,7 @@ entry (arg) := { input := inI(1); fibValue := fib(input); - + result := printI(fibValue); return 0;