aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
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 /src/parser.c
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 'src/parser.c')
-rw-r--r--src/parser.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/parser.c b/src/parser.c
index 68d0648..b61a968 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -33,10 +33,9 @@ int parser_thread_data_init(ParserThreadData *self) {
return scoped_allocator_init(&self->allocator);
}
-int parser_thread_data_deinit(ParserThreadData *self) {
+void parser_thread_data_deinit(ParserThreadData *self) {
ignore_result_int(amal_thread_deinit(&self->thread));
scoped_allocator_deinit(&self->allocator);
- return 0;
}
int parser_thread_data_start(ParserThreadData *self, AmalThreadCallbackFunc callback_func, void *userdata) {
@@ -62,10 +61,11 @@ int parser_init(Parser *self, amal_compiler *compiler, ScopedAllocator *allocato
self->error_context = ERROR_CONTEXT_NONE;
return_if_error(structdecl_init(&self->struct_decl, &compiler->root_scope, allocator));
self->struct_decl.body.parser = self;
- return_if_error(lhsexpr_init(&self->file_decl, bool_true, bool_true, bool_true, create_buffer_view_null(), self->allocator));
+ lhsexpr_init(&self->file_decl, bool_true, bool_true, bool_true, create_buffer_view_null());
return_if_error(ast_create(self->allocator, &self->struct_decl, AST_STRUCT_DECL, &self->file_decl.rhs_expr));
self->current_scope = &self->struct_decl.body;
self->has_func_parent = bool_false;
+ am_memset(&self->bytecode, 0, sizeof(self->bytecode));
return PARSER_OK;
}
@@ -202,7 +202,7 @@ static CHECK_RESULT LhsExpr* parser_parse_declaration_lhs(Parser *self) {
if(is_extern && self->has_func_parent) {
self->error = tokenizer_create_error(&self->tokenizer,
tokenizer_get_code_reference_index(&self->tokenizer, self->tokenizer.value.identifier.data),
- "Only declarations in structs can be extern");
+ "Only declarations in global structs can be extern");
throw(PARSER_UNEXPECTED_TOKEN);
}
@@ -210,7 +210,7 @@ static CHECK_RESULT LhsExpr* parser_parse_declaration_lhs(Parser *self) {
if(is_pub && self->has_func_parent) {
self->error = tokenizer_create_error(&self->tokenizer,
tokenizer_get_code_reference_index(&self->tokenizer, self->tokenizer.value.identifier.data),
- "Only declarations in structs can be public");
+ "Only declarations in global structs can be public");
throw(PARSER_UNEXPECTED_TOKEN);
}
@@ -233,7 +233,7 @@ static CHECK_RESULT LhsExpr* parser_parse_declaration_lhs(Parser *self) {
throw_if_error(tokenizer_accept(&self->tokenizer, TOK_IDENTIFIER));
var_name = self->tokenizer.value.identifier;
throw_if_error(scoped_allocator_alloc(self->allocator, sizeof(LhsExpr), (void**)&result));
- throw_if_error(lhsexpr_init(result, is_extern, is_pub, is_const, var_name, self->allocator));
+ lhsexpr_init(result, is_extern, is_pub, is_const, var_name);
ignore_result_int(parser_parse_var_type_def(self, &result->type));
return result;