Add missing functions, fix missing breaks on switch

This commit is contained in:
Curle 2020-11-14 22:26:12 +00:00
parent 610c45e3e1
commit 764f89bb88
Signed by: TheCurle
GPG Key ID: 2F2E62F0DA69A5AE
3 changed files with 19 additions and 5 deletions

View File

@ -123,7 +123,7 @@ enum SyntaxOps {
// A node in a Binary Tree that forms the syntax of Erythro
struct ASTNode {
int Operation;
int Operation; // SyntaxOps Index
int ExprType; // Value->IntValue's DataType
struct ASTNode* Left;
struct ASTNode* Middle;

View File

@ -454,10 +454,10 @@ void AsNewSymb(int ID) {
Symbols[ID].Name);
switch(TypeSize) {
case 1: fprintf(OutputFile, "%s:\t.byte\t0\n", Symbols[ID].Name);
case 4: fprintf(OutputFile, "%s:\t.long\t0\n", Symbols[ID].Name);
case 8: fprintf(OutputFile, "%s:\t.quad\t0\n", Symbols[ID].Name);
default: DieDecimal("Unknown type in AsNewSymbol", TypeSize);
case 1: fprintf(OutputFile, "%s:\t.byte\t0\n", Symbols[ID].Name); break;
case 4: fprintf(OutputFile, "%s:\t.long\t0\n", Symbols[ID].Name); break;
case 8: fprintf(OutputFile, "%s:\t.quad\t0\n", Symbols[ID].Name); break;
default: DieDecimal("Unknown type in AsNewSymbol", TypeSize); break;
}
}

View File

@ -7,6 +7,19 @@
#include <Defs.h>
#include <Data.h>
int TypeIsInt(int Type) {
if(Type == RET_CHAR || Type == RET_INT || Type == RET_LONG)
return 1;
return 0;
}
int TypeIsPtr(int Type) {
if(Type == PTR_VOID || Type == PTR_CHAR || Type == PTR_INT || Type == PTR_LONG)
return 1;
return 0;
}
/*
* Turn a token type into its appropriate
* primitive type.
@ -136,6 +149,7 @@ struct ASTNode* MutateType(struct ASTNode* Tree, int RightType, int Operation) {
LeftType = Tree->ExprType;
printf("\tCalculating compatibility between ltype %d and rtype %d\r\n", LeftType, RightType);
if(TypeIsInt(LeftType) && TypeIsInt(RightType)) {
// Short-circuit for valid types