aboutsummaryrefslogtreecommitdiff
path: root/include/ast.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/ast.h')
-rw-r--r--include/ast.h19
1 files changed, 14 insertions, 5 deletions
diff --git a/include/ast.h b/include/ast.h
index 7911a59..1d40a89 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -5,8 +5,13 @@
#include "std/buffer.h"
#include "std/misc.h"
#include "std/scoped_allocator.h"
+#include "std/hash_map.h"
#include "binop_type.h"
+/* General error */
+#define AST_ERR -1
+#define AST_ERR_DEF_DUP -20
+
typedef struct FunctionDecl FunctionDecl;
typedef struct FunctionCall FunctionCall;
typedef struct LhsExpr LhsExpr;
@@ -45,9 +50,14 @@ typedef struct {
AstType type;
} Ast;
+struct Scope {
+ Buffer ast_objects;
+ HashMap/*(key=BufferView, value=Ast)*/ named_objects;
+};
+
struct FunctionDecl {
BufferView name;
- Buffer body;
+ Scope body;
};
struct FunctionCall {
@@ -90,11 +100,8 @@ struct Binop {
bool grouped;
};
-struct Scope {
- Buffer ast_objects;
-};
-
Ast ast_none();
+BufferView ast_get_name(Ast *self);
CHECK_RESULT int funcdecl_init(FunctionDecl *self, ScopedAllocator *allocator);
CHECK_RESULT int funccall_init(FunctionCall *self, BufferView name, ScopedAllocator *allocator);
@@ -103,7 +110,9 @@ 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);
void binop_init(Binop *self);
+
CHECK_RESULT int scope_init(Scope *self, ScopedAllocator *allocator);
+CHECK_RESULT int scope_add_child(Scope *self, Ast *child);
void scope_resolve(Scope *self);
#endif