From 95c37db9ff79e3de1a98c123eda4cc2115b6ff84 Mon Sep 17 00:00:00 2001 From: Partho Date: Fri, 25 Apr 2025 13:37:32 -0400 Subject: [PATCH] fixing still --- src/grammar.y | 2 ++ src/runner.c | 2 +- src/symbol_table.c | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 74d7e92..72aa3b3 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -615,6 +615,7 @@ expression: if(getTypeEntry((TableNode*)$2) == integ) { char* temp = temp_var_gen(); TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, integ, temp, NULL); + emit_unary_op(E_NEG,node,tn_or_const(NODE,$2)); //NOTE ADD ASSIGNMENT EMIT HERE (MIGHT NEED TO PUSH TO STACK) //result of unary operation $$ = node; @@ -630,6 +631,7 @@ 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) //result of unary operation $$ = node; diff --git a/src/runner.c b/src/runner.c index 9ca6cfa..c10cd6a 100644 --- a/src/runner.c +++ b/src/runner.c @@ -121,7 +121,7 @@ int run(FILE *alpha) { if (st_flag != NULL) { print_symbol_table(top, st_flag); - //emit_as_file(stdout, begin); + emit_as_file(stdout, begin); fclose(st_flag); } diff --git a/src/symbol_table.c b/src/symbol_table.c index 5fe39c3..db7523e 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -1601,6 +1601,7 @@ bool isConst(TNodeOrConst * tnc) { TNodeOrConst * tn_or_const(Discriminant d, void * tnc) { TNodeOrConst * count = calloc(1, sizeof(*count)); count->d = d; + count->tnc_union = calloc(1, sizeof(*count->tnc_union)); switch (d) { case NODE: count->tnc_union->node = tnc; @@ -1632,7 +1633,7 @@ static void emit_helper(void){ } else { current->next = inst; inst->prev = current; - inst->index = current->index++; + inst->index = current->index+1; current = inst; } } @@ -1661,6 +1662,7 @@ void emit_assignment(TableNode * target, TNodeOrConst * source){ } char * get_string(TNodeOrConst * tc){ + char * s; switch (tc->d) { case NODE: @@ -1670,10 +1672,12 @@ char * get_string(TNodeOrConst * tc){ case STRING: return tc->tnc_union->string; case INTEGER: + return getName(integ); s = calloc(10, sizeof(char)); sprintf(s, "%d", tc->tnc_union->integer); return s; case CHARACTER: + return getName(chara); s = calloc(2, sizeof(char)); sprintf(s, "%c", tc->tnc_union->character); return s;