From a52fdf470aa2c164108aeccc2c83bad62208913c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 9 Mar 2019 14:14:09 +0100 Subject: Start on resolving ast. Add recursive declaration check --- include/ast.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'include/ast.h') diff --git a/include/ast.h b/include/ast.h index 1d40a89..f0020d7 100644 --- a/include/ast.h +++ b/include/ast.h @@ -1,6 +1,7 @@ #ifndef AMALGAM_AST_H #define AMALGAM_AST_H +#include "defs.h" #include "std/buffer_view.h" #include "std/buffer.h" #include "std/misc.h" @@ -8,6 +9,8 @@ #include "std/hash_map.h" #include "binop_type.h" +#include + /* General error */ #define AST_ERR -1 #define AST_ERR_DEF_DUP -20 @@ -45,9 +48,16 @@ typedef enum { AST_BINOP } AstType; +typedef enum { + AST_NOT_RESOLVED, + AST_RESOLVING, + AST_RESOLVED +} AstResolveStatus; + typedef struct { AstValue value; AstType type; + AstResolveStatus resolve_status; } Ast; struct Scope { @@ -56,17 +66,16 @@ struct Scope { }; struct FunctionDecl { - BufferView name; Scope body; }; struct FunctionCall { BufferView name; - Buffer args; + Buffer/*Ast*/ args; }; struct LhsExpr { - int isConst; + int is_const; BufferView type_name; BufferView var_name; Ast rhs_expr; @@ -90,6 +99,7 @@ struct Number { struct Variable { BufferView name; + Ast resolved_variable; }; struct Binop { @@ -100,7 +110,13 @@ struct Binop { bool grouped; }; +typedef struct { + jmp_buf env; + Parser *parser; +} AstCompilerContext; + Ast ast_none(); +void ast_init(Ast *self, AstValue value, AstType type); BufferView ast_get_name(Ast *self); CHECK_RESULT int funcdecl_init(FunctionDecl *self, ScopedAllocator *allocator); @@ -109,10 +125,11 @@ void lhsexpr_init(LhsExpr *self, int isConst, BufferView var_name); void import_init(Import *self, BufferView path); CHECK_RESULT int string_init(String *self, BufferView str); void number_init(Number *self, i64 value, bool is_integer); +void variable_init(Variable *self, BufferView name); void binop_init(Binop *self); CHECK_RESULT int scope_init(Scope *self, ScopedAllocator *allocator); CHECK_RESULT int scope_add_child(Scope *self, Ast *child); -void scope_resolve(Scope *self); +void scope_resolve(Scope *self, AstCompilerContext *context); #endif -- cgit v1.2.3