From 764f89bb88912045d4db3d6619097e01770f483c Mon Sep 17 00:00:00 2001 From: Curle Date: Sat, 14 Nov 2020 22:26:12 +0000 Subject: [PATCH] Add missing functions, fix missing breaks on switch --- include/Defs.h | 2 +- src/Assembler.c | 8 ++++---- src/Types.c | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/Defs.h b/include/Defs.h index 8a45bbe..78d6dee 100644 --- a/include/Defs.h +++ b/include/Defs.h @@ -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; diff --git a/src/Assembler.c b/src/Assembler.c index bd7adf8..3f9051a 100644 --- a/src/Assembler.c +++ b/src/Assembler.c @@ -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; } } diff --git a/src/Types.c b/src/Types.c index 2b592ce..c1845cc 100644 --- a/src/Types.c +++ b/src/Types.c @@ -7,6 +7,19 @@ #include #include + +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