summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-01-26 19:13:39 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-01-26 19:13:39 +0330
commitbb87887ec288f341256d324f271bac6267fc83f4 (patch)
tree5060b790282e088bdd3ea83998d55c2f58c6acb0
parente2fc93a2985b1085048a07753e7c93b23abf06ed (diff)
add better type checks
-rw-r--r--src/compiler/ast-tree.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index 2d129c2..729aa18 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -7,9 +7,10 @@
#include <string.h>
const char *AST_TREE_TOKEN_STRINGS[] = {
- "AST_TREE_TOKEN_FUNCTION", "AST_TREE_TOKEN_KEYWORD_PRINT",
- "AST_TREE_TOKEN_NONE", "AST_TREE_TOKEN_TYPE_FUNCTION",
- "AST_TREE_TOKEN_TYPE_VOID",
+ "AST_TREE_TOKEN_FUNCTION", "AST_TREE_TOKEN_KEYWORD_PRINT",
+ "AST_TREE_TOKEN_NONE", "AST_TREE_TOKEN_TYPE_FUNCTION",
+ "AST_TREE_TOKEN_TYPE_VOID", "AST_TREE_TOKEN_FUNCTION_CALL",
+ "AST_TREE_TOKEN_IDENTIFIER",
};
void astTreePrint(const AstTree *tree, int indent) {
@@ -116,7 +117,7 @@ void astTreeRootPrint(const AstTreeRoot *root) {
(int)(variable->name_end - variable->name_begin),
variable->name_begin);
astTreePrint(variable->value, 1);
- printf("\n},\n");
+ printf("\n}\n");
}
}
@@ -567,4 +568,27 @@ ERROR:
exit(1);
}
-bool typeIsEqual(AstTree *type0, AstTree *type1) { return true; }
+bool typeIsEqual(AstTree *type0, AstTree *type1) {
+ switch (type0->token) {
+ case AST_TREE_TOKEN_FUNCTION:
+ case AST_TREE_TOKEN_KEYWORD_PRINT:
+ return false;
+ case AST_TREE_TOKEN_TYPE_VOID:
+ return type1->token == AST_TREE_TOKEN_TYPE_VOID;
+ case AST_TREE_TOKEN_TYPE_FUNCTION:
+ if(type1->token != AST_TREE_TOKEN_TYPE_FUNCTION){
+ return false;
+ }
+ printLog("Not implemented yet");
+ exit(1);
+ case AST_TREE_TOKEN_FUNCTION_CALL:
+ printLog("Not implemented yet");
+ exit(1);
+ case AST_TREE_TOKEN_IDENTIFIER:
+ return type1->token == AST_TREE_TOKEN_IDENTIFIER &&
+ type0->metadata == type1->metadata;
+ case AST_TREE_TOKEN_NONE:
+ }
+ printLog("Bad token '%d'", type0->token);
+ exit(1);
+}