diff options
Diffstat (limited to 'src/compiler.c')
-rw-r--r-- | src/compiler.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/compiler.c b/src/compiler.c index 4e097ce..c56221b 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -104,13 +104,13 @@ typedef struct { } ThreadWorkData; static CHECK_RESULT int amal_compiler_load_in_this_thread(amal_compiler *self, BufferView filepath, ScopedAllocator *allocator) { - Parser parser; + Parser *parser; int result; result = AMAL_COMPILER_ERR; - am_memset(&parser, 0, sizeof(parser)); - return_if_error(parser_init(&parser, self, allocator)); - cleanup_if_error(parser_parse_file(&parser, filepath)); + return_if_error(scoped_allocator_alloc(&self->allocator, sizeof(Parser), (void**)&parser)); + return_if_error(parser_init(parser, self, allocator)); + return_if_error(parser_parse_file(parser, filepath)); cleanup_if_error(amal_mutex_lock(&self->mutex, "amal_compiler_load_in_this_thread")); cleanup_if_error(buffer_append(&self->parsers, &parser, sizeof(parser))); result = AMAL_COMPILER_OK; @@ -154,11 +154,15 @@ static CHECK_RESULT int thread_resolve_ast(Parser *parser) { AstCompilerContext compiler_context; int result; compiler_context.parser = parser; + compiler_context.scope = NULL; result = setjmp(compiler_context.env); + assert(!parser->scope.parent); if(result == 0) { amal_log_debug("Resolving AST for file: %.*s", parser->tokenizer.code_name.size, parser->tokenizer.code_name.data); scope_resolve(&parser->scope, &compiler_context); } + if(result == 0) + assert(!compiler_context.scope); return result; } @@ -201,10 +205,10 @@ static void* thread_callback_generic(void *userdata) { break; } cleanup_if_error(amal_mutex_lock(&compiler_userdata.compiler->mutex, "thread_callback_generic")); - if(compiler_userdata.compiler->generic_work_object_index + 1 >= (int)buffer_get_size(&compiler_userdata.compiler->parsers, Parser)) + if(compiler_userdata.compiler->generic_work_object_index + 1 >= (int)buffer_get_size(&compiler_userdata.compiler->parsers, Parser*)) break; ++compiler_userdata.compiler->generic_work_object_index; - parser = buffer_get(&compiler_userdata.compiler->parsers, compiler_userdata.compiler->generic_work_object_index, sizeof(Parser)); + parser = *(Parser**)buffer_get(&compiler_userdata.compiler->parsers, compiler_userdata.compiler->generic_work_object_index, sizeof(parser)); amal_mutex_tryunlock(&compiler_userdata.compiler->mutex); } result = NULL; @@ -333,8 +337,8 @@ static CHECK_RESULT int amal_compiler_load_file_join_threads(amal_compiler *self } static CHECK_RESULT int amal_compiler_dispatch_generic(amal_compiler *self, ThreadWorkType work_type) { - Parser *parser; - Parser *parser_end; + Parser **parser; + Parser **parser_end; parser = buffer_start(&self->parsers); parser_end = buffer_end(&self->parsers); self->generic_work_object_index = 0; @@ -342,7 +346,7 @@ static CHECK_RESULT int amal_compiler_dispatch_generic(amal_compiler *self, Thre ParserThreadData *thread_selected; ThreadWorkData thread_work_data; thread_work_data.type = work_type; - thread_work_data.value.parser = parser; + thread_work_data.value.parser = *parser; return_if_error(amal_compiler_select_thread_for_work(self, thread_work_data, &thread_selected)); /* After all threads have been used, they will handle using the remaining parsers or stop if there is an error */ if(!thread_selected) |