Not working

This commit is contained in:
Meyer Simon
2025-04-30 21:55:36 -04:00
parent cd4393d052
commit 2b07464f84
6 changed files with 143 additions and 28 deletions

View File

@ -270,7 +270,7 @@ definition:
}
//printf("Ending ID: %s\n", $1);
//printf("Ending Type: %s\n", getType(table_lookup(getAncestor(cur), $1)));
} idlist R_PAREN ASSIGN sblock
}
;
@ -367,6 +367,7 @@ idlist:
sblock:
L_BRACE
{
// emit_label(label_gen());
if (getLine(cur) != 0) {
cur = CreateScope(cur,@1.first_line,@1.first_column);
printdebug("Created a new scope");
@ -554,19 +555,15 @@ compound_statement statement_list {
compound_statement:
WHILE L_PAREN
{
if (!TrueList) {TrueList = S_Init();}
if (!FalseList) {FalseList = S_Init();}
S_Push(TrueList, S_Init());
S_Push(FalseList, S_Init());
} expression R_PAREN {
emit_label(label_gen());
backpatch(S_Pop(TrueList), getLabel(current));
} sblock {
$$ = $7;
emit_label(label_gen());
backpatch(S_Pop(FalseList), getLabel(current));
}
| IF L_PAREN expression R_PAREN THEN {emit_label(label_gen());} sblock ELSE {emit_label(label_gen());} sblock {
| IF L_PAREN expression R_PAREN THEN {emit_label(label_gen());}
sblock ELSE {emit_label(label_gen());}
sblock {
/*
*/
if ($7 == undefined && $10 != undefined) {
@ -657,9 +654,11 @@ rec_op:
ablock:
L_PAREN argument_list R_PAREN
L_PAREN {}
argument_list R_PAREN
{
$$ = $2;
// here
$$ = $3;
printdebug("ablock is %d", $$);
}
@ -669,13 +668,20 @@ ablock:
argument_list:
//NEED TO EMIT PARAMETERS HERE. MAYBE USE STACK STRUCTURE
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));
//S_Push(stack,current);
//emit_detach();
Stack * t = S_Peek(stack);
if (stack == NULL){
stack = S_Init();
}
if(t == NULL){
t = S_Init();
S_Push(stack, t, 0);
}
S_Push(t, current, 1);
emit_detach();
//printdebug("[ARGUMENT_LIST] argument list is %d", $$);
}
COMMA argument_list
@ -686,8 +692,7 @@ argument_list:
{
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
emit_parameter(tn_or_const(NODE,arg));
//S_Push(stack,current);
//emit_detach();
emit_push_all(S_Pop(stack));
$$ = 1;
printdebug("[ARGUMENT_LIST] argument list is %d", $$);
}
@ -840,7 +845,7 @@ expression:
| expression LESS_THAN expression
{
emit_conditional_jump(E_LESS_THAN, 0, tn_or_const(NODE,$1), tn_or_const(NODE,$3));
S_Push(S_Peek(TrueList), current);
emit_goto(0);
printdebug("less than expression");
if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1)==integ) {
char* temp = temp_var_gen();
@ -859,6 +864,7 @@ expression:
char* temp = temp_var_gen();
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
emit_conditional_jump(E_EQUAL_TO, 0, tn_or_const(NODE,$1), tn_or_const(NODE,$3));
emit_goto(0);
$$ = node;
} else {
@ -1008,7 +1014,16 @@ assignable:
t= TYPE_UNDEFINED;
throw_error(ERROR_TYPE, "Undefined type returned by function.");
}
// TODO: add from stack
// TODO: emit_function_call
TableNode* node = CreateEntry(cur,t, typeNode2, temp, NULL);
int a = 0;
/*
if(S_IsEmpty(stack)){
int a = S_Size(S_Peek(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)
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName(typeNode2), getName((TableNode*)$1));
@ -1037,8 +1052,8 @@ assignable:
throw_error(ERROR_TYPE, "Undefined type stored in array.");
}
TableNode* node = CreateEntry(cur,t, typeNode2, temp, NULL);
//emit assign here
//emit_array_access(char* node, char* array, ...)
//TODO: emit assign here
//TODO: emit_array_access(char* node, char* array, ...)
$$ = node;
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getType((TableNode*)$1), getName((TableNode*)$1));
}