aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ast.h18
-rw-r--r--include/compiler.h2
-rw-r--r--include/parser.h1
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;