From 2323ca6c9ec3c8ee76b9acf13745b80b92952a6a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 18 Mar 2019 23:47:45 +0100 Subject: Add struct, import caching, binop ops etc --- include/ast.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'include/ast.h') diff --git a/include/ast.h b/include/ast.h index 6077d5d..e49ad08 100644 --- a/include/ast.h +++ b/include/ast.h @@ -18,6 +18,8 @@ typedef struct FunctionDecl FunctionDecl; typedef struct FunctionCall FunctionCall; +typedef struct StructDecl StructDecl; +typedef struct StructField StructField; typedef struct LhsExpr LhsExpr; typedef struct Import Import; typedef struct String String; @@ -29,6 +31,8 @@ typedef union { void *data; FunctionDecl *func_decl; FunctionCall *func_call; + StructDecl *struct_decl; + StructField *struct_field; LhsExpr *lhs_expr; Import *import; String *string; @@ -41,6 +45,8 @@ typedef enum { AST_NONE, AST_FUNCTION_DECL, AST_FUNCTION_CALL, + AST_STRUCT_DECL, + AST_STRUCT_FIELD, AST_LHS, AST_IMPORT, AST_STRING, @@ -59,6 +65,7 @@ typedef struct { AstValue value; AstType type; AstResolveStatus resolve_status; + StructDecl *resolved_type; } Ast; struct Scope { @@ -67,6 +74,11 @@ struct Scope { Scope *parent; }; +struct FileScopeReference { + Scope *scope; + Buffer canonical_path; +}; + struct Variable { BufferView name; Ast resolved_variable; @@ -82,15 +94,25 @@ struct FunctionCall { Buffer/*Ast*/ args; }; +struct StructDecl { + Scope body; +}; + +struct StructField { + BufferView name; + Variable type; +}; + struct LhsExpr { - int is_const; - BufferView type_name; + bool is_const; BufferView var_name; + Variable type; Ast rhs_expr; }; struct Import { BufferView path; + FileScopeReference *file_scope; }; struct String { @@ -125,7 +147,9 @@ BufferView ast_get_name(Ast *self); CHECK_RESULT int funcdecl_init(FunctionDecl *self, Scope *parent, ScopedAllocator *allocator); CHECK_RESULT int funccall_init(FunctionCall *self, BufferView name, ScopedAllocator *allocator); -void lhsexpr_init(LhsExpr *self, int isConst, BufferView var_name); +CHECK_RESULT int structdecl_init(StructDecl *self, Scope *parent, ScopedAllocator *allocator); +void structfield_init(StructField *self, BufferView name, BufferView type_name); +void lhsexpr_init(LhsExpr *self, bool is_const, 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); @@ -133,6 +157,7 @@ void variable_init(Variable *self, BufferView name); void binop_init(Binop *self); CHECK_RESULT int scope_init(Scope *self, Scope *parent, ScopedAllocator *allocator); +CHECK_RESULT int file_scope_reference_init(FileScopeReference *self, BufferView canonical_path, ScopedAllocator *allocator); CHECK_RESULT int scope_add_child(Scope *self, Ast *child); /* longjump to compiler env on failure */ void scope_resolve(Scope *self, AstCompilerContext *context); -- cgit v1.2.3