From 470a60a3ea8723852568df2ecf7587303b250664 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 10 Mar 2019 00:45:21 +0100 Subject: Fail compilation on error --- src/compiler.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/compiler.c') diff --git a/src/compiler.c b/src/compiler.c index d3e4e80..6988b20 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -122,24 +122,30 @@ static CHECK_RESULT int amal_compiler_load_in_this_thread(amal_compiler *self, B static void* thread_callback_parse_file(void *userdata) { BufferView next_file; CompilerParserThreadUserData compiler_parser_userdata; + void *result; assert(!amal_thread_is_main()); am_memcpy(&compiler_parser_userdata, userdata, sizeof(compiler_parser_userdata)); am_free(userdata); next_file = compiler_parser_userdata.filepath; + result = (void*)AMAL_COMPILER_ERR; for(;;) { + int has_next; cleanup_if_error(amal_compiler_load_in_this_thread(compiler_parser_userdata.compiler, next_file, &compiler_parser_userdata.parser_thread_data->allocator)); cleanup_if_error(amal_mutex_lock(&compiler_parser_userdata.compiler->mutex, "thread_callback_parse_file")); - cleanup_if_error(buffer_pop(&compiler_parser_userdata.compiler->queued_files, &next_file, sizeof(next_file))); + has_next = buffer_pop(&compiler_parser_userdata.compiler->queued_files, &next_file, sizeof(next_file)); amal_mutex_tryunlock(&compiler_parser_userdata.compiler->mutex); + if(has_next != 0) + break; } + result = NULL; cleanup: compiler_parser_userdata.parser_thread_data->status = PARSER_THREAD_STATUS_IDLE; amal_mutex_tryunlock(&compiler_parser_userdata.compiler->mutex); - return NULL; + return result; } /* TODO: Handle errors (stop resolving ast in all other threads and report errors/warnings) */ @@ -147,12 +153,14 @@ static void* thread_callback_resolve_ast(void *userdata) { CompilerAstResolverThreadUserData compiler_ast_resolver_userdata; Parser *parser; AstCompilerContext compiler_context; + void *result; assert(!amal_thread_is_main()); am_memcpy(&compiler_ast_resolver_userdata, userdata, sizeof(compiler_ast_resolver_userdata)); am_free(userdata); parser = compiler_ast_resolver_userdata.parser; compiler_context.parser = parser; + result = (void*)AMAL_COMPILER_ERR; for(;;) { int result; amal_log_debug("Resolving AST for file: %.*s", parser->tokenizer.code_name.size, parser->tokenizer.code_name.data); @@ -170,11 +178,12 @@ static void* thread_callback_resolve_ast(void *userdata) { parser = buffer_get(&compiler_ast_resolver_userdata.compiler->parsers, compiler_ast_resolver_userdata.compiler->resolve_ast_index, sizeof(Parser)); amal_mutex_tryunlock(&compiler_ast_resolver_userdata.compiler->mutex); } + result = NULL; cleanup: compiler_ast_resolver_userdata.parser_thread_data->status = PARSER_THREAD_STATUS_IDLE; amal_mutex_tryunlock(&compiler_ast_resolver_userdata.compiler->mutex); - return NULL; + return result; } static CHECK_RESULT int amal_compiler_select_thread_for_work(amal_compiler *self, ThreadWorkData work_data, ParserThreadData **thread_selected) { @@ -253,9 +262,12 @@ static CHECK_RESULT int amal_compiler_load_file_join_threads(amal_compiler *self int result; void *thread_return_data; ParserThreadData *parser_thread_data; + bool work_failed; + result = AMAL_COMPILER_ERR; assert(amal_thread_is_main()); - + thread_return_data = NULL; + work_failed = bool_false; for(;;) { bool done; /* @@ -270,6 +282,11 @@ static CHECK_RESULT int amal_compiler_load_file_join_threads(amal_compiler *self if(result != 0) goto cleanup; ignore_result_int(parser_thread_data_join(parser_thread_data, &thread_return_data)); + if(thread_return_data != NULL) { + /* TODO: Somehow exit running jobs */ + amal_log_error("Failed, waiting for jobs to finish"); + work_failed = bool_true; + } } cleanup_if_error(amal_compiler_check_all_threads_done(self, &done)); @@ -279,6 +296,8 @@ static CHECK_RESULT int amal_compiler_load_file_join_threads(amal_compiler *self result = AMAL_COMPILER_OK; cleanup: + if(work_failed) + result = AMAL_COMPILER_ERR; return result; } -- cgit v1.2.3