From 456346f68ee7ccdcf7849360f5a3c3341bd1fecd Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Thu, 1 May 2025 11:12:58 -0400 Subject: [PATCH] I added some code to push args but its not working --- src/grammar.y | 21 +++++++++++++++++---- src/intermediate_code.h | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 1aedc30..8688a6b 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -654,8 +654,11 @@ rec_op: ablock: - L_PAREN {} - argument_list R_PAREN + L_PAREN{ + emit_push_all(S_Pop(stack)); + } + argument_list { + } R_PAREN { // here $$ = $3; @@ -671,7 +674,6 @@ argument_list: expression{ TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL); // this emits params for function and arrays TODO: fix - emit_parameter(tn_or_const(NODE,arg)); Stack * t = S_Peek(stack); if (stack == NULL){ stack = S_Init(); @@ -680,6 +682,7 @@ argument_list: t = S_Init(); S_Push(stack, t, 0); } + emit_parameter(tn_or_const(NODE,arg)); S_Push(t, current, 1); emit_detach(); //printdebug("[ARGUMENT_LIST] argument list is %d", $$); @@ -691,8 +694,17 @@ argument_list: { TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL); + Stack * t = S_Peek(stack); + if (stack == NULL){ + stack = S_Init(); + } + if(t == NULL){ + t = S_Init(); + S_Push(stack, t, 0); + } emit_parameter(tn_or_const(NODE,arg)); - emit_push_all(S_Pop(stack)); + S_Push(t, current, 1); + emit_detach(); $$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $$); } @@ -1023,6 +1035,7 @@ assignable: int a = S_Size(S_Peek(stack)); } */ + emit_push_all(S_Pop(stack)); emit_function_call(node, a, tn_or_const(NODE, $1)); $$ = node; //NOTE ADD ASSIGNMENT EMIT HERE (MIGHT NEED TO PUSH TO STACK for function call) diff --git a/src/intermediate_code.h b/src/intermediate_code.h index 493542c..c85c2bc 100644 --- a/src/intermediate_code.h +++ b/src/intermediate_code.h @@ -143,6 +143,9 @@ void emit_release(TableNode * pointer); void emit_field_access(char* result, char* record, char* field); void emit_array_access(Op op, TableNode * result, TNodeOrConst * array, TNodeOrConst * index); void emit_bounds_check(TNodeOrConst * index, TNodeOrConst * arr); +void emit_goto(int i); +void emit_detach(); +void emit_push_all(Stack * s); int getLabel(Instruction * i);