fixed everything breaking i think

This commit is contained in:
Annie
2025-05-06 21:45:09 -04:00
parent 63bdb0a470
commit e23e91477a
2 changed files with 22 additions and 21 deletions

View File

@ -85,6 +85,7 @@ int generate() {
break;
case E_FUNC_DEC:
generateFunctionDec(i);
break;
default:;
}
i = i->next;
@ -388,10 +389,10 @@ int generateOr(Instruction *inst) {
int label = label_gen();
fprintf(cg_flag, "\tcmpl\t$0, %d(%%rbp)\t#start or\n", getAddress(op1CG));
fprintf(cg_flag, "\tcmpb\t$0, %d(%%rbp)\t#start or\n", getAddress(op1CG));
fprintf(cg_flag, "\tjne\t.L%dor2\n", label);
fprintf(cg_flag, "\tcmpl\t$0, %d(%%rbp)\n", getAddress(op2CG));
fprintf(cg_flag, "\tcmpb\t$0, %d(%%rbp)\n", getAddress(op2CG));
fprintf(cg_flag, "\tje\t.L%dor3\n", label);
fprintf(cg_flag, ".L%dor2:\n", label);
@ -439,10 +440,10 @@ int generateAnd(Instruction *inst) {
}
int label = label_gen();
fprintf(cg_flag, "\tcmpl\t$0, %d(%%rbp)\t#start and\n", getAddress(op1CG));
fprintf(cg_flag, "\tcmpb\t$0, %d(%%rbp)\t#start and\n", getAddress(op1CG));
fprintf(cg_flag, "\tje\t.L%dor2\n", label);
fprintf(cg_flag, "\tcmpl\t$0, %d(%%rbp)\n", getAddress(op2CG));
fprintf(cg_flag, "\tcmpb\t$0, %d(%%rbp)\n", getAddress(op2CG));
fprintf(cg_flag, "\tje\t.L%dor2\n", label);
fprintf(cg_flag, "\tmovl\t$1, %%eax\n");
@ -534,7 +535,7 @@ int generateAssign(Instruction *inst) {
printdebug("generateAssign failed, %s is not constant but not in CGlist", getName(getTN(op1)));
return -1;
}
if (getAdInfoType(getTN(op1)) != TYPE_FUNCTION_DECLARATION || !isAnActualFunction(getTN(op1))){
if (getAdInfoType(getTN(op1)) != TYPE_FUNCTION_DECLARATION || table_lookup(getAncestor(cur), getName(getTN(op1))) == undefined){
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#assign start\n", getAddress(op1CG));
fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\t#assign end\n", getAddress(cg));
} else {
@ -724,7 +725,7 @@ int generateReturn(Instruction *inst) {
printdebug("generateReturn failed, trying to return %s not in CGList", getName(getTN(op1)));
return -1;
}
if (isAnActualFunction(getTN(op1))) {
if (table_lookup(getAncestor(cur), getName(getTN(op1))) != undefined) {
fprintf(cg_flag, "\tmovl\t$%s,%%eax\t#return a function\n", getName(getTN(op1)));
} else {
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#return %s\n", getAddress(cg), getName(getTN(op1)));
@ -851,7 +852,7 @@ int generateFunctionStart(Instruction *inst) {
}
}
if (strcmp(getName(funDecTN), "entry") == 0) {
/* if (strcmp(getName(funDecTN), "entry") == 0) {
if (funList == NULL) {
return -1;
}
@ -862,6 +863,6 @@ int generateFunctionStart(Instruction *inst) {
fprintf(cg_flag, "\tmovq\t$%s, %d(%%rbp)\t#storing function declaration\n", getName(funDec), getAddress(cg));
funList = funList->next;
}
}
} */
return 0;
}

View File

@ -1,6 +1,6 @@
(* TEST: [-asc -tc] *)
(* Type definitions *)
#include "std.alpha"
(* mapping type *)
type string2int: string -> integer
@ -9,9 +9,9 @@ type funArray: 1 -> string2int
(* record of functions *)
type funRec: [ string2int: f; string2int: g ]
type int2int: integer -> integer
(* function returning function *)
type integer_2_string2int: integer -> string2int
type integer_2_int2int: integer -> int2int
(* function returning function *)
type string2int_2_integer: string2int -> integer
@ -22,8 +22,8 @@ type iXiXc: [integer: a; integer: b; character: c]
type iic2b: iXiXc -> Boolean
(* Function declarations using the above type definitions *)
function a: string2int
function b: integer_2_string2int
function a: int2int
function b: integer_2_int2int
function c: string2int_2_integer
function d: iic2b
@ -37,8 +37,8 @@ function entry: string2int
a(x) := {
[string : s]
s := x;
x:= printInteger(x);
return 0;
}
@ -51,7 +51,7 @@ b(x) := {
c(x) := {
[string: s]
s := "Hi!";
return a(s);
return 3;
}
@ -59,11 +59,11 @@ c(x) := {
entry is the first function called
*)
entry(arg) := {
[integer: result; string2int: f; integer: temp]
temp := a("Hello");
[integer: result; int2int: f; integer: temp]
temp := 7;
f := b(temp);
result := f("ahhh");
result := c(f);
result := f(temp);
(*result := c(f);*)
if (d(1,2,'c'))
then {
result := 0;
@ -72,6 +72,6 @@ entry(arg) := {
[ Boolean : b]
result := entry("hello");
}
result := c(f);
(*result := c(f);*)
return result;
}