From 5d46c19b25a05a289ccecfa38bc0be849af87877 Mon Sep 17 00:00:00 2001 From: A404M Date: Fri, 24 Jan 2025 04:12:03 +0330 Subject: add types and type checking (not complete) --- src/compiler/ast-tree.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src/compiler/ast-tree.h') diff --git a/src/compiler/ast-tree.h b/src/compiler/ast-tree.h index 758d113..23f0b9c 100644 --- a/src/compiler/ast-tree.h +++ b/src/compiler/ast-tree.h @@ -6,12 +6,11 @@ typedef enum AstTreeToken { AST_TREE_TOKEN_FUNCTION, AST_TREE_TOKEN_KEYWORD_PRINT, + AST_TREE_TOKEN_TYPE_FUNCTION, + AST_TREE_TOKEN_TYPE_VOID, AST_TREE_TOKEN_NONE, } AstTreeToken; -typedef struct AstTreeType { -} AstTreeType; - typedef struct AstTree { AstTreeToken token; void *metadata; @@ -20,7 +19,7 @@ typedef struct AstTree { typedef struct AstTreeVariable { char *name_begin; char *name_end; - AstTreeType type; + AstTree *type; AstTree *value; } AstTreeVariable; @@ -40,9 +39,22 @@ typedef struct AstTreeScope { size_t expressions_size; } AstTreeScope; +typedef struct AstTreeFunction { + AstTreeVariable *arguments; + size_t arguments_size; + AstTreeScope scope; + AstTree *returnType; +} AstTreeFunction; + +typedef struct AstTreeTypeFunction { + AstTree **arguments; + size_t arguments_size; + AstTree *returnType; +} AstTreeTypeFunction; + extern const char *AST_TREE_TOKEN_STRINGS[]; -void astTreePrint(const AstTree *tree,int indent); +void astTreePrint(const AstTree *tree, int indent); void astTreeRootPrint(const AstTreeRoot *root); void astTreeDestroy(AstTree tree); @@ -62,3 +74,10 @@ AstTree *astTreeParse(ParserNode *parserNode, AstTreeVariables *variables, AstTree *astTreeParseFunction(ParserNode *parserNode, AstTreeVariables *variables, size_t variables_size); + +AstTree *astTreeParseTypeFunction(ParserNode *parserNode, + AstTreeVariables *variables, + size_t variables_size); + +bool hasTypeOf(AstTree *value, AstTree *type); +bool typeIsEqual(AstTree *type0, AstTree *type1); -- cgit v1.2.3