aboutsummaryrefslogtreecommitdiff
path: root/include/ast.h
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-07-17 19:23:16 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit84e65c63e7482590d535e86f7660a00ae8a0cecb (patch)
treec79de87b7136e96b977003db85d43e5e676bbfc1 /include/ast.h
parent85c654a102701958d3748e82ecac9c1bc4dbbcba (diff)
Start on amal program
Fix mutex issue in lhs expr which can cause a deadlock when a file has an error and throws and doesn't close the mutex and another thread waits for that mutex. The mutex can instead be removed and ignore race conditions which are uncommon. This should improve memory usage and performance.
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);