added a lot of new fucntions

This commit is contained in:
Partho
2025-05-06 14:16:21 -04:00
parent 8b177b2807
commit 07255a5193
4 changed files with 125 additions and 13 deletions

View File

@ -5,7 +5,9 @@
Constant_Stack *head = NULL;
Context_stack *context_head = NULL;
TableNode* comparator = NULL;
//TableNode* comparator = NULL;
Function_Stack *function_head = NULL;
int temp2_count = 0;
int temp3_count = 0;
@ -55,14 +57,20 @@ Constant_Stack *Push(TableNode *type, void *value, bool isConst) {
return cs;
}
Context_stack *PushContext(int context) {
Context_stack *PushContext(int context, TableNode *typeToCompare) {
if (context != 1 && context != 2 && context != 3 && context != 0) {
printdebug(
"invalid context passed in");
return NULL;
}
Context_stack *cs = (Context_stack *)malloc(sizeof(Context_stack));
if(typeToCompare == NULL) {
printdebug(
"passed a NULL reference to PushContext. Invalid.");
return NULL;
}
Context_stack *cs = (Context_stack *)calloc(1,sizeof(Context_stack));
cs->con = context;
cs->typeToCompare = typeToCompare;
if (context_head == NULL) {
context_head = cs;
cs->next = NULL;
@ -73,17 +81,89 @@ Context_stack *PushContext(int context) {
return cs;
}
int PopContext() {
Function_Stack *PushFunction(int arg, TableNode* FunctionType) {
if (FunctionType == NULL) {
printdebug(
"passed a NULL reference to PushFunction. Invalid.");
return NULL;
}
if(FunctionType == undefined) {
printdebug(
"passed an undefined reference to PushFunction. Invalid.");
return NULL;
}
Function_Stack *fs = (Function_Stack *)calloc(1,sizeof(Function_Stack));
fs->arg = arg;
fs->FunctionType = FunctionType;
if (function_head == NULL) {
function_head = fs;
fs->next = NULL;
} else {
fs->next = function_head;
function_head = fs;
}
return fs;
}
Function_Stack *PopFunction() {
if (function_head == NULL) {
printf("cannot pop from an empty stack. Invalid.\n");
return NULL;
}
Function_Stack *fs = function_head;
function_head = function_head->next;
return fs;
}
int getArgumentNumber(Function_Stack *fs) {
if (fs == NULL) {
printdebug(
"passed a NULL reference to getArgumentNumber. Invalid.");
return -1;
}
return fs->arg;
}
TableNode* getFunctionTypeContext(Function_Stack *fs) {
if (fs == NULL) {
printdebug(
"passed a NULL reference to getFunctionTypeContext. Invalid.");
return undefined;
}
TableNode* tn = fs->FunctionType;
return tn;
}
Context_stack *PopContext() {
if (context_head == NULL) {
printf("cannot pop from an empty stack. Invalid.\n");
return -1;
return NULL;
}
Context_stack *cs = context_head;
context_head = context_head->next;
printf("Popped context off stack: number %d\n", cs->con);
return cs;
}
int getContextType(Context_stack *cs) {
if (cs == NULL) {
printdebug(
"passed a NULL reference to getContextType. Invalid.");
return -1;
}
return cs->con;
}
//should be
TableNode *getContextTypeEntry(Context_stack *cs) {
if (cs == NULL) {
printdebug(
"passed a NULL reference to getContextTypeEntry. Invalid.");
return undefined;
}
TableNode* tn = cs->typeToCompare;
return NULL;
}
Constant_Stack *Pop() {
if (head == NULL) {
printf("cannot pop from an empty stack. Invalid.\n");