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, 13 insertions, 6 deletions
diff --git a/include/ast.h b/include/ast.h
index 34e62b8..2925f6c 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -76,6 +76,7 @@ typedef enum {
typedef struct {
LhsExpr *type;
AstResolveStatus status;
+ Parser *parser; /* Borrowed. This is the parser that is currently parsing the expression */
} AstResolveData;
typedef struct {
@@ -140,6 +141,11 @@ typedef struct {
} value;
} VariableType;
+/*
+ Note: When resolving AST, more than one thread can end up resolving the same expressions at the same time.
+ This is intentional. Instead of using mutex for every expression and locking/unlocking everytime
+ which uses more memory and affects performance, we assume such race conditions are rare and let them happen.
+*/
struct LhsExpr {
bool is_extern;
bool is_pub;
@@ -147,10 +153,6 @@ struct LhsExpr {
BufferView var_name;
VariableType type;
Ast *rhs_expr;
- /*
- TODO: Find a better way to store this. This most likely will use too much memory.
- */
- amal_mutex *mutex;
};
struct AssignmentExpr {
@@ -204,7 +206,12 @@ struct WhileStatement {
typedef struct {
jmp_buf env;
- amal_compiler *compiler;
+ amal_compiler *compiler; /* Borrowed */
+ Parser *parser; /* Borrowed. This is the parser that belongs to the thread */
+ /*
+ Borrowed. This is the current scope. Note that this scope can belong to another parser (and thread),
+ as such, @parser and scope_get_parser(@scope) parser may not be the same
+ */
Scope *scope;
} AstCompilerContext;
@@ -215,7 +222,7 @@ CHECK_RESULT int funcdecl_init(FunctionDecl *self, FunctionSignature *signature,
CHECK_RESULT int funccall_init(FunctionCall *self, BufferView name, ScopedAllocator *allocator);
CHECK_RESULT int structdecl_init(StructDecl *self, Scope *parent, ScopedAllocator *allocator);
void structfield_init(StructField *self, BufferView name, BufferView type_name);
-CHECK_RESULT int lhsexpr_init(LhsExpr *self, bool is_extern, bool is_pub, bool is_const, BufferView var_name, ScopedAllocator *allocator);
+void lhsexpr_init(LhsExpr *self, bool is_extern, bool is_pub, bool is_const, BufferView var_name);
void assignmentexpr_init(AssignmentExpr *self, Ast *lhs_expr, Ast *rhs_expr);
void import_init(Import *self, BufferView path);
CHECK_RESULT int string_init(String *self, BufferView str);