aboutsummaryrefslogtreecommitdiff
path: root/include/ast.h
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-03-09 14:14:09 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commita52fdf470aa2c164108aeccc2c83bad62208913c (patch)
tree9b4dea7aa0e53976958ac908d345f6f1914602d1 /include/ast.h
parent255aa20f6d68a71c9eedd47998480a8b14a3be36 (diff)
Start on resolving ast. Add recursive declaration check
Diffstat (limited to 'include/ast.h')
-rw-r--r--include/ast.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/include/ast.h b/include/ast.h
index 1d40a89..f0020d7 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -1,6 +1,7 @@
#ifndef AMALGAM_AST_H
#define AMALGAM_AST_H
+#include "defs.h"
#include "std/buffer_view.h"
#include "std/buffer.h"
#include "std/misc.h"
@@ -8,6 +9,8 @@
#include "std/hash_map.h"
#include "binop_type.h"
+#include <setjmp.h>
+
/* General error */
#define AST_ERR -1
#define AST_ERR_DEF_DUP -20
@@ -45,9 +48,16 @@ typedef enum {
AST_BINOP
} AstType;
+typedef enum {
+ AST_NOT_RESOLVED,
+ AST_RESOLVING,
+ AST_RESOLVED
+} AstResolveStatus;
+
typedef struct {
AstValue value;
AstType type;
+ AstResolveStatus resolve_status;
} Ast;
struct Scope {
@@ -56,17 +66,16 @@ struct Scope {
};
struct FunctionDecl {
- BufferView name;
Scope body;
};
struct FunctionCall {
BufferView name;
- Buffer args;
+ Buffer/*Ast*/ args;
};
struct LhsExpr {
- int isConst;
+ int is_const;
BufferView type_name;
BufferView var_name;
Ast rhs_expr;
@@ -90,6 +99,7 @@ struct Number {
struct Variable {
BufferView name;
+ Ast resolved_variable;
};
struct Binop {
@@ -100,7 +110,13 @@ struct Binop {
bool grouped;
};
+typedef struct {
+ jmp_buf env;
+ Parser *parser;
+} AstCompilerContext;
+
Ast ast_none();
+void ast_init(Ast *self, AstValue value, AstType type);
BufferView ast_get_name(Ast *self);
CHECK_RESULT int funcdecl_init(FunctionDecl *self, ScopedAllocator *allocator);
@@ -109,10 +125,11 @@ void lhsexpr_init(LhsExpr *self, int isConst, BufferView var_name);
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 variable_init(Variable *self, BufferView name);
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);
+void scope_resolve(Scope *self, AstCompilerContext *context);
#endif