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; break;
case E_FUNC_DEC: case E_FUNC_DEC:
generateFunctionDec(i); generateFunctionDec(i);
break;
default:; default:;
} }
i = i->next; i = i->next;
@ -388,10 +389,10 @@ int generateOr(Instruction *inst) {
int label = label_gen(); 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, "\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, "\tje\t.L%dor3\n", label);
fprintf(cg_flag, ".L%dor2:\n", label); fprintf(cg_flag, ".L%dor2:\n", label);
@ -439,10 +440,10 @@ int generateAnd(Instruction *inst) {
} }
int label = label_gen(); 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, "\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, "\tje\t.L%dor2\n", label);
fprintf(cg_flag, "\tmovl\t$1, %%eax\n"); 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))); printdebug("generateAssign failed, %s is not constant but not in CGlist", getName(getTN(op1)));
return -1; 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%d(%%rbp), %%eax\t#assign start\n", getAddress(op1CG));
fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\t#assign end\n", getAddress(cg)); fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\t#assign end\n", getAddress(cg));
} else { } else {
@ -724,7 +725,7 @@ int generateReturn(Instruction *inst) {
printdebug("generateReturn failed, trying to return %s not in CGList", getName(getTN(op1))); printdebug("generateReturn failed, trying to return %s not in CGList", getName(getTN(op1)));
return -1; 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))); fprintf(cg_flag, "\tmovl\t$%s,%%eax\t#return a function\n", getName(getTN(op1)));
} else { } else {
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#return %s\n", getAddress(cg), getName(getTN(op1))); 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) { if (funList == NULL) {
return -1; 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)); fprintf(cg_flag, "\tmovq\t$%s, %d(%%rbp)\t#storing function declaration\n", getName(funDec), getAddress(cg));
funList = funList->next; funList = funList->next;
} }
} } */
return 0; return 0;
} }

View File

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