diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-01-26 19:13:39 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-01-26 19:13:39 +0330 |
commit | bb87887ec288f341256d324f271bac6267fc83f4 (patch) | |
tree | 5060b790282e088bdd3ea83998d55c2f58c6acb0 /src | |
parent | e2fc93a2985b1085048a07753e7c93b23abf06ed (diff) |
add better type checks
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/ast-tree.c | 34 |
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); +} |