diff options
Diffstat (limited to 'include/ast.h')
-rw-r--r-- | include/ast.h | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/include/ast.h b/include/ast.h index edf225b..0c34d0b 100644 --- a/include/ast.h +++ b/include/ast.h @@ -23,7 +23,6 @@ typedef struct FunctionParameter FunctionParameter; typedef struct FunctionCall FunctionCall; typedef struct StructDecl StructDecl; typedef struct StructField StructField; -typedef struct LhsExpr LhsExpr; typedef struct AssignmentExpr AssignmentExpr; typedef struct Import Import; typedef struct String String; @@ -147,10 +146,16 @@ typedef struct { } VariableType; struct FileScopeReference { - Parser *parser; + Parser *parser; /* Borrowed, the parser that belongs to the same file as the FileScopeReference */ Buffer canonical_path; }; +struct ParserFileScopeReference { + FileScopeReference *file_scope_ref; + /* Index in the parser import list. Used by bytecode to know which import an expression belongs to */ + int import_index; +}; + struct Variable { BufferView name; ScopeNamedObject resolved_var; @@ -177,7 +182,7 @@ struct FunctionSignature { struct FunctionDecl { LhsExpr *lhs_expr; /* Borrowed from the LhsExpr that owns this FunctionDecl if it exists, otherwise NULL */ - FunctionSignature *signature; + FunctionSignature *signature; /* TODO: Make this a non-pointer type? */ Scope body; SsaFuncIndex ssa_func_index; }; @@ -188,7 +193,15 @@ struct FunctionCall { }; struct StructDecl { + /* + TODO: Instead of having a scope body, use a body with only structdecl. This improves performance + and simplifies the code. + */ Scope body; + /* The number of fields that are pointers or a type that is different on different platforms (i.e isize, usize, etc), recursive */ + u32 fields_num_pointers; + /* The total size of all fields which are of a type that have the same size on all platforms (i.e u8, i32, etc), recursive */ + u32 fields_fixed_size_bytes; }; struct StructField { @@ -232,7 +245,7 @@ struct AssignmentExpr { struct Import { BufferView path; - FileScopeReference *file_scope; + ParserFileScopeReference *file_scope; }; struct String { @@ -279,6 +292,11 @@ struct ReturnExpr { }; typedef struct { + u32 num_pointers; + u32 fixed_size; +} TypeSize; + +typedef struct { jmp_buf env; amal_compiler *compiler; /* Borrowed */ Parser *parser; /* Borrowed. This is the parser that belongs to the thread */ @@ -303,6 +321,7 @@ void function_parameter_init(FunctionParameter *self); CHECK_RESULT int funcdecl_init(FunctionDecl *self, FunctionSignature *signature, Scope *parent, ArenaAllocator *allocator); CHECK_RESULT int funccall_init(FunctionCall *self, BufferView name, ArenaAllocator *allocator); CHECK_RESULT int structdecl_init(StructDecl *self, Scope *parent, ArenaAllocator *allocator); +CHECK_RESULT int structdecl_add_field(StructDecl *self, StructField *field, ArenaAllocator *allocator); LhsExpr* structdecl_get_field_by_name(StructDecl *self, BufferView field_name); /* Copies @type */ void structfield_init(StructField *self, BufferView name, VariableType *type); @@ -318,14 +337,13 @@ CHECK_RESULT int else_if_statement_init(ElseIfStatement *self, Scope *parent, Ar CHECK_RESULT int while_statement_init(WhileStatement *self, Scope *parent, ArenaAllocator *allocator); void return_expr_init(ReturnExpr *self, Ast *rhs_expr); +TypeSize resolved_type_get_byte_size(AstResolvedType *self); + CHECK_RESULT int scope_init(Scope *self, Scope *parent, ArenaAllocator *allocator); CHECK_RESULT int file_scope_reference_init(FileScopeReference *self, BufferView canonical_path, ArenaAllocator *allocator); CHECK_RESULT int scope_add_child(Scope *self, Ast *child); + /* longjump to compiler env on failure */ void scope_resolve(Scope *self, AstCompilerContext *context); - - -CHECK_RESULT bool resolved_type_is_func_decl(Ast *self); - #endif |