aboutsummaryrefslogtreecommitdiff
path: root/include/ast.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/ast.h')
-rw-r--r--include/ast.h18
1 files changed, 10 insertions, 8 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);