updated grammar to pass up instances. Still need IR to compile to properly emit
This commit is contained in:
@ -3,6 +3,9 @@
|
||||
|
||||
#include "symbol_table.h"
|
||||
|
||||
Constant_Stack* head = NULL;
|
||||
int temp2_count = 0;
|
||||
|
||||
void printdebug_impl(char *file, int line, const char *format, ...) {
|
||||
if (DEBUG) {
|
||||
printf("%s<%s> [%d]%s ", COLOR_DARKGRAY, file, line,
|
||||
@ -15,6 +18,76 @@ void printdebug_impl(char *file, int line, const char *format, ...) {
|
||||
}
|
||||
}
|
||||
|
||||
char * temp_var_gen(){
|
||||
char * ret = calloc(9, sizeof(*ret));
|
||||
sprintf(ret, "$t%d", temp2_count);
|
||||
temp2_count++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Constant_Stack *Push(TableNode *type, void *value, bool isConst) {
|
||||
if (type == NULL || type == undefined) {
|
||||
printdebug(
|
||||
"passed a NULL reference/undefined reference to "
|
||||
"CreateConstantStack. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
Constant_Stack *cs = (Constant_Stack *)malloc(sizeof(Constant_Stack));
|
||||
cs->theType = type;
|
||||
cs->theValue = value;
|
||||
cs->isConst = isConst;
|
||||
if(head == NULL){
|
||||
head = cs;
|
||||
cs->next = NULL;
|
||||
}else{
|
||||
cs->next = head;
|
||||
head = cs;
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
Constant_Stack *Pop() {
|
||||
if (head == NULL) {
|
||||
printf("cannot pop from an empty stack. Invalid.\n");
|
||||
return NULL;
|
||||
}
|
||||
Constant_Stack *cs = head;
|
||||
head = head->next;
|
||||
printf("Popped something of type %s\n", getName(cs->theType));
|
||||
return cs;
|
||||
}
|
||||
|
||||
Constant_Stack* Print_Stack(){
|
||||
if (head == NULL) {
|
||||
printdebug("cannot print an empty stack. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
Constant_Stack *cs = head;
|
||||
while (cs != NULL) {
|
||||
if(cs->theValue == NULL){
|
||||
printf("Type: %s, Value: NULL", getName(cs->theType));
|
||||
}
|
||||
if(cs->theType == stri){
|
||||
printf("Type: %s, Value: %s\n", getName(cs->theType), *(char*)(cs->theValue));
|
||||
}
|
||||
if(cs->theType == integ){
|
||||
printf("Type: %s, Value: %d\n", getName(cs->theType), (int *)(cs->theValue));
|
||||
}
|
||||
if(cs->theType == chara){
|
||||
printf("Type: %s, Value: %c\n", getName(cs->theType), *(char *)cs->theValue);
|
||||
}
|
||||
if(cs->theType == boo){
|
||||
if(*(bool *)cs->theValue == true){
|
||||
printf("Type: %s, Value: true\n", getName(cs->theType));}
|
||||
else{
|
||||
printf("Type: %s, Value: false\n", getName(cs->theType));
|
||||
}
|
||||
}
|
||||
cs = cs->next;
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
// primitive additional info only stores the size of that type
|
||||
AdInfo *CreatePrimitiveInfo(int size) {
|
||||
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
|
||||
|
Reference in New Issue
Block a user