aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-03-10 00:45:21 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit470a60a3ea8723852568df2ecf7587303b250664 (patch)
tree3129dbc6f4fe399a12a78718147b75b54139af01
parent12e05d464eb05202b00e65553d920984cb86123d (diff)
Fail compilation on error
-rw-r--r--src/compiler.c27
-rw-r--r--tests/main.amal2
2 files changed, 24 insertions, 5 deletions
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;
}
diff --git a/tests/main.amal b/tests/main.amal
index cd0fc60..990dc26 100644
--- a/tests/main.amal
+++ b/tests/main.amal
@@ -10,7 +10,7 @@ const main = fn {
const num2 = 23232;
const num3 = num1 + num2 * 30;
const num4 = (num1 + num2) * num3 * ((34 + 32) / 234.345);
- //const num4 = 23;
+ const num4 = 23;
/*
episfjpseifipesf
*/