diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-03-15 18:17:50 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 5a93c32a59775cd1be4b4f450e8230016b434366 (patch) | |
tree | b89f3f7c8b07176aa5ae783319d9e613a42db703 /include | |
parent | d4ca9de33906972fa06bd2b7e38cbc2b4d3574c2 (diff) |
Resolve variable references
Diffstat (limited to 'include')
-rw-r--r-- | include/ast.h | 18 | ||||
-rw-r--r-- | include/compiler.h | 2 | ||||
-rw-r--r-- | include/parser.h | 1 |
3 files changed, 12 insertions, 9 deletions
diff --git a/include/ast.h b/include/ast.h index ae9b6b3..6077d5d 100644 --- a/include/ast.h +++ b/include/ast.h @@ -64,6 +64,12 @@ typedef struct { struct Scope { Buffer ast_objects; HashMap/*(key=BufferView, value=Ast)*/ named_objects; + Scope *parent; +}; + +struct Variable { + BufferView name; + Ast resolved_variable; }; struct FunctionDecl { @@ -72,7 +78,7 @@ struct FunctionDecl { }; struct FunctionCall { - BufferView name; + Variable func; Buffer/*Ast*/ args; }; @@ -99,11 +105,6 @@ struct Number { bool is_integer; }; -struct Variable { - BufferView name; - Ast resolved_variable; -}; - struct Binop { Ast lhs; Ast rhs; @@ -115,13 +116,14 @@ struct Binop { typedef struct { jmp_buf env; Parser *parser; + Scope *scope; } AstCompilerContext; Ast ast_none(); void ast_init(Ast *self, void *value, AstType type); BufferView ast_get_name(Ast *self); -CHECK_RESULT int funcdecl_init(FunctionDecl *self, ScopedAllocator *allocator); +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); void import_init(Import *self, BufferView path); @@ -130,7 +132,7 @@ 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_init(Scope *self, Scope *parent, 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); diff --git a/include/compiler.h b/include/compiler.h index 69d0254..32a5eab 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -15,7 +15,7 @@ struct amal_compiler { ScopedAllocator allocator; ScopedAllocator main_thread_allocator; - Buffer parsers; + Buffer/*<Parser*>*/ parsers; Buffer queued_files; ParserThreadData *threads; int usable_thread_count; diff --git a/include/parser.h b/include/parser.h index 20f02fe..84d46bd 100644 --- a/include/parser.h +++ b/include/parser.h @@ -35,6 +35,7 @@ typedef enum { struct Parser { Tokenizer tokenizer; Scope scope; + Scope *current_scope; ScopedAllocator *allocator; /* borrowed. Copied from @compiler for faster access to allocator */ amal_compiler *compiler; bool started; |