diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/ast.h | 10 | ||||
-rw-r--r-- | include/parser.h | 3 | ||||
-rw-r--r-- | include/std/scoped_allocator.h | 4 | ||||
-rw-r--r-- | include/std/thread.h | 13 |
4 files changed, 23 insertions, 7 deletions
diff --git a/include/ast.h b/include/ast.h index 7b16796..25d9034 100644 --- a/include/ast.h +++ b/include/ast.h @@ -2,6 +2,7 @@ #define AMALGAM_AST_H #include "defs.h" +#include "std/defs.h" #include "std/buffer_view.h" #include "std/buffer.h" #include "std/misc.h" @@ -108,6 +109,13 @@ struct LhsExpr { BufferView var_name; Variable type; Ast rhs_expr; + /* + A mutex is only available if the LhsExpr is public, because other threads (files) + can access it. It's used to prevent usage of unresolved data and also to decide which + thread has responsibility of resolving data. + TODO: Find a better way to store this. This most likely will use too much memory. + */ + amal_mutex *mutex; }; struct Import { @@ -149,7 +157,7 @@ CHECK_RESULT int funcdecl_init(FunctionDecl *self, Scope *parent, ScopedAllocato 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); -void lhsexpr_init(LhsExpr *self, bool is_pub, bool is_const, BufferView var_name); +CHECK_RESULT int lhsexpr_init(LhsExpr *self, bool is_pub, bool is_const, BufferView var_name, ScopedAllocator *allocator); 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); diff --git a/include/parser.h b/include/parser.h index 84d46bd..92e6d46 100644 --- a/include/parser.h +++ b/include/parser.h @@ -29,7 +29,8 @@ struct ParserThreadData { typedef enum { ERROR_CONTEXT_NONE, - ERROR_CONTEXT_RHS_START + ERROR_CONTEXT_RHS_STANDALONE, + ERROR_CONTEXT_NO_LHS } ErrorContext; struct Parser { diff --git a/include/std/scoped_allocator.h b/include/std/scoped_allocator.h index 9090767..d7ec1e1 100644 --- a/include/std/scoped_allocator.h +++ b/include/std/scoped_allocator.h @@ -15,7 +15,10 @@ struct ScopedAllocatorNode { struct ScopedAllocator { ScopedAllocatorNode head; ScopedAllocatorNode *current; + /* TODO: Use linked-list instead, since the elements are dynamically allocated anyways */ + /* Find another way to store mutexes */ Buffer/*<Buffer*>*/ buffers; + Buffer/*<amal_mutex*>*/ mutexes; }; CHECK_RESULT int scoped_allocator_node_init(ScopedAllocatorNode *self); @@ -25,5 +28,6 @@ CHECK_RESULT int scoped_allocator_init(ScopedAllocator *self); void scoped_allocator_deinit(ScopedAllocator *self); CHECK_RESULT int scoped_allocator_alloc(ScopedAllocator *self, usize size, void **mem); CHECK_RESULT int scoped_allocator_add_buffer(ScopedAllocator *self, Buffer *buffer); +CHECK_RESULT int scoped_allocator_create_mutex(ScopedAllocator *self, amal_mutex **mutex); #endif diff --git a/include/std/thread.h b/include/std/thread.h index 6eedb08..356ebf0 100644 --- a/include/std/thread.h +++ b/include/std/thread.h @@ -13,6 +13,8 @@ typedef void* (AmalThreadCallbackFunc)(void *userdata); #define AMAL_THREAD_ERR -1 #define AMAL_THREAD_NOT_JOINABLE -23 +/*#define AMAL_MUTEX_DEBUG*/ + struct amal_thread { pthread_t thread_id; pthread_attr_t thread_attr; @@ -28,7 +30,9 @@ typedef enum { struct amal_mutex { pthread_mutex_t mutex; + #ifdef AMAL_MUTEX_DEBUG const char *lock_identifier; + #endif bool locked; pthread_t owner_thread; }; @@ -39,6 +43,10 @@ CHECK_RESULT int amal_thread_deinit(amal_thread *self); CHECK_RESULT int amal_thread_detach(amal_thread *self); CHECK_RESULT int amal_thread_join(amal_thread *self, void **result); +bool amal_thread_is_main(); +/* Returns 0 if the number of usable threads is unknown */ +int amal_get_usable_thread_count(); + void amal_mutex_init(amal_mutex *self); void amal_mutex_deinit(amal_mutex *self); CHECK_RESULT int amal_mutex_lock(amal_mutex *self, const char *lock_identifier); @@ -46,9 +54,4 @@ CHECK_RESULT int amal_mutex_lock(amal_mutex *self, const char *lock_identifier); CHECK_RESULT int amal_mutex_unlock(amal_mutex *self); void amal_mutex_tryunlock(amal_mutex *self); -bool amal_thread_is_main(); - -/* Returns 0 if the number of usable threads is unknown */ -int amal_get_usable_thread_count(); - #endif |