From bb0f82283c1bc59ca46edca3bcba4af9be11f1a1 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 31 Dec 2021 16:10:32 -0600 Subject: [PATCH] ranked error messages to not overwhelm the user --- include/errors.h | 11 +++++++++- src/astnodes.c | 10 ++++----- src/builtins.c | 28 ++++++++++++------------ src/checker.c | 50 ++++++++++++++++++++++--------------------- src/errors.c | 22 ++++++++++++++++++- src/onyx.c | 8 +++---- src/parser.c | 32 +++++++++++++-------------- src/polymorph.h | 12 +++++------ src/symres.c | 50 +++++++++++++++++++++---------------------- src/types.c | 20 +++++++---------- src/utils.c | 6 +++--- src/wasm_emit.c | 30 +++++++++++++------------- src/wasm_intrinsics.h | 22 +++++++++---------- 13 files changed, 163 insertions(+), 138 deletions(-) diff --git a/include/errors.h b/include/errors.h index 6d85fe6b..9df95def 100644 --- a/include/errors.h +++ b/include/errors.h @@ -6,8 +6,17 @@ #include +typedef enum OnyxErrorRank { + Error_Undefined = 0, + Error_Other = 1, + Error_Warning = 2, + Error_Waiting_On = 3, + Error_Critical = 4, +} OnyxErrorRank; + typedef struct OnyxError { OnyxFilePos pos; + OnyxErrorRank rank; char *text; } OnyxError; @@ -25,7 +34,7 @@ extern OnyxErrors msgs; void onyx_errors_init(bh_arr(bh_file_contents)* files); void onyx_submit_error(OnyxError error); -void onyx_report_error(OnyxFilePos pos, char * format, ...); +void onyx_report_error(OnyxFilePos pos, OnyxErrorRank rank, char * format, ...); void onyx_submit_warning(OnyxError error); void onyx_report_warning(OnyxFilePos pos, char* format, ...); void onyx_errors_print(); diff --git a/src/astnodes.c b/src/astnodes.c index 9961813e..a6365880 100644 --- a/src/astnodes.c +++ b/src/astnodes.c @@ -441,7 +441,7 @@ b32 convert_numlit_to_type(AstNumLit* num, Type* to_type) { } } - onyx_report_error(num->token->pos, "Unsigned integer constant with value '%l' does not fit into %d-bits.", + onyx_report_error(num->token->pos, Error_Critical, "Unsigned integer constant with value '%l' does not fit into %d-bits.", num->value.l, type->Basic.size * 8); @@ -468,7 +468,7 @@ b32 convert_numlit_to_type(AstNumLit* num, Type* to_type) { } break; } - onyx_report_error(num->token->pos, "Integer constant with value '%l' does not fit into %d-bits.", + onyx_report_error(num->token->pos, Error_Critical, "Integer constant with value '%l' does not fit into %d-bits.", num->value.l, type->Basic.size * 8); } @@ -478,7 +478,7 @@ b32 convert_numlit_to_type(AstNumLit* num, Type* to_type) { if (type->Basic.size == 4) { // TODO(Brendan): Check these boundary conditions if (bh_abs(num->value.l) >= (1 << 23)) { - onyx_report_error(num->token->pos, "Integer '%l' does not fit in 32-bit float exactly.", num->value.l); + onyx_report_error(num->token->pos, Error_Critical, "Integer '%l' does not fit in 32-bit float exactly.", num->value.l); return 0; } @@ -489,7 +489,7 @@ b32 convert_numlit_to_type(AstNumLit* num, Type* to_type) { if (type->Basic.size == 8) { // TODO(Brendan): Check these boundary conditions if (bh_abs(num->value.l) >= (1ull << 52)) { - onyx_report_error(num->token->pos, "Integer '%l' does not fit in 64-bit float exactly.", num->value.l); + onyx_report_error(num->token->pos, Error_Critical, "Integer '%l' does not fit in 64-bit float exactly.", num->value.l); return 0; } @@ -587,7 +587,7 @@ TypeMatch unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) { token_toggle_end(node->token); if (closest) { - onyx_report_error(node->token->pos, "'%b' does not exist in '%s'. Did you mean '%s'?", + onyx_report_error(node->token->pos, Error_Critical, "'%b' does not exist in '%s'. Did you mean '%s'?", node->token->text, node->token->length, type_get_name(type), closest); diff --git a/src/builtins.c b/src/builtins.c index ec6f217d..f18712b2 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -383,73 +383,73 @@ void initialize_builtins(bh_allocator a) { builtin_string_type = (AstType *) symbol_raw_resolve(p->scope, "str"); if (builtin_string_type == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'str' struct not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'str' struct not found in builtin package."); return; } builtin_cstring_type = (AstType *) symbol_raw_resolve(p->scope, "cstr"); if (builtin_cstring_type == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'cstr' type not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'cstr' type not found in builtin package."); return; } builtin_range_type = (AstType *) symbol_raw_resolve(p->scope, "range"); if (builtin_range_type == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'range' struct not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'range' struct not found in builtin package."); return; } builtin_vararg_type = (AstType *) symbol_raw_resolve(p->scope, "vararg"); if (builtin_range_type == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'vararg' struct not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'vararg' struct not found in builtin package."); return; } builtin_context_variable = (AstTyped *) symbol_raw_resolve(p->scope, "context"); if (builtin_context_variable == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'context' variable not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'context' variable not found in builtin package."); return; } builtin_allocator_type = (AstType *) symbol_raw_resolve(p->scope, "Allocator"); if (builtin_allocator_type == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'Allocator' struct not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'Allocator' struct not found in builtin package."); return; } builtin_iterator_type = (AstType *) symbol_raw_resolve(p->scope, "Iterator"); if (builtin_iterator_type == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'Iterator' struct not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'Iterator' struct not found in builtin package."); return; } builtin_callsite_type = (AstType *) symbol_raw_resolve(p->scope, "CallSite"); if (builtin_callsite_type == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'CallSite' struct not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'CallSite' struct not found in builtin package."); return; } builtin_any_type = (AstType *) symbol_raw_resolve(p->scope, "any"); if (builtin_any_type == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'any' struct not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'any' struct not found in builtin package."); return; } builtin_code_type = (AstType *) symbol_raw_resolve(p->scope, "Code"); if (builtin_code_type == NULL) { - onyx_report_error((OnyxFilePos) { 0 }, "'Code' struct not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'Code' struct not found in builtin package."); return; } builtin_initialize_data_segments = (AstFunction *) symbol_raw_resolve(p->scope, "__initialize_data_segments"); if (builtin_initialize_data_segments == NULL || builtin_initialize_data_segments->kind != Ast_Kind_Function) { - onyx_report_error((OnyxFilePos) { 0 }, "'__initialize_data_segments' procedure not found in builtin package."); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'__initialize_data_segments' procedure not found in builtin package."); return; } builtin_run_init_procedures = (AstFunction *) symbol_raw_resolve(p->scope, "__run_init_procedures"); if (builtin_run_init_procedures == NULL || builtin_run_init_procedures->kind != Ast_Kind_Function) { - onyx_report_error((OnyxFilePos) { 0 }, "'__run_init_procedures"); + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "'__run_init_procedures"); return; } @@ -476,7 +476,7 @@ void introduce_build_options(bh_allocator a) { AstType* Runtime_Type = (AstType *) symbol_raw_resolve(p->scope, "Runtime"); if (Runtime_Type == NULL) { - onyx_report_error((OnyxFilePos) {0}, "'Runtime' type not found in package runtime."); + onyx_report_error((OnyxFilePos) {0}, Error_Critical, "'Runtime' type not found in package runtime."); return; } @@ -503,7 +503,7 @@ void introduce_build_options(bh_allocator a) { AstType* OS_Type = (AstType *) symbol_raw_resolve(p->scope, "OS"); if (OS_Type == NULL) { - onyx_report_error((OnyxFilePos) {0}, "'OS' type not found in package runtime."); + onyx_report_error((OnyxFilePos) {0}, Error_Critical, "'OS' type not found in package runtime."); return; } diff --git a/src/checker.c b/src/checker.c index 8f25ee7e..b9edd1a0 100644 --- a/src/checker.c +++ b/src/checker.c @@ -13,7 +13,7 @@ #define YIELD(loc, msg) do { \ if (context.cycle_detected) { \ - onyx_report_error(loc, msg); \ + onyx_report_error(loc, Error_Waiting_On, msg); \ return Check_Error; \ } else { \ return Check_Yield_Macro; \ @@ -22,7 +22,7 @@ #define YIELD_(loc, msg, ...) do { \ if (context.cycle_detected) { \ - onyx_report_error(loc, msg, __VA_ARGS__); \ + onyx_report_error(loc, Error_Waiting_On, msg, __VA_ARGS__); \ return Check_Error; \ } else { \ return Check_Yield_Macro; \ @@ -30,12 +30,12 @@ } while (0) #define ERROR(loc, msg) do { \ - onyx_report_error(loc, msg); \ + onyx_report_error(loc, Error_Critical, msg); \ return Check_Error; \ } while (0) #define ERROR_(loc, msg, ...) do { \ - onyx_report_error(loc, msg, __VA_ARGS__); \ + onyx_report_error(loc, Error_Critical, msg, __VA_ARGS__); \ return Check_Error; \ } while (0) @@ -310,7 +310,7 @@ static b32 add_case_to_switch_statement(AstSwitch* switchnode, u64 case_value, A switchnode->max_case = bh_max(switchnode->max_case, case_value); if (bh_imap_has(&switchnode->case_map, case_value)) { - onyx_report_error(pos, "Multiple cases for values '%d'.", case_value); + onyx_report_error(pos, Error_Critical, "Multiple cases for values '%d'.", case_value); return 1; } @@ -632,7 +632,7 @@ CheckStatus check_call(AstCall** pcall) { i32 index; if ((index = shgeti(intrinsic_table, intr_name)) == -1) { - onyx_report_error(callee->token->pos, "Intrinsic not supported, '%s'.", intr_name); + onyx_report_error(callee->token->pos, Error_Critical, "Intrinsic not supported, '%s'.", intr_name); token_toggle_end(callee->intrinsic_name); return Check_Error; } @@ -670,7 +670,7 @@ CheckStatus check_call(AstCall** pcall) { } static void report_bad_binaryop(AstBinaryOp* binop) { - onyx_report_error(binop->token->pos, "Binary operator '%s' not understood for arguments of type '%s' and '%s'.", + onyx_report_error(binop->token->pos, Error_Critical, "Binary operator '%s' not understood for arguments of type '%s' and '%s'.", binaryop_string[binop->operation], node_get_type_name(binop->left), node_get_type_name(binop->right)); @@ -978,6 +978,8 @@ CheckStatus check_binaryop(AstBinaryOp** pbinop) { if (binop->left->kind == Ast_Kind_Unary_Field_Access || binop->right->kind == Ast_Kind_Unary_Field_Access) { TYPE_CHECK(&binop->left, binop->right->type) { TYPE_CHECK(&binop->right, binop->left->type) { + // TODO: This should report a better error about the Unary_Field_Access not be able to be resolved given whatever type. + // - brendanfh 2021/12/31 report_bad_binaryop(binop); return Check_Error; } @@ -1170,7 +1172,7 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) { if ((sl->flags & Ast_Flag_Has_Been_Checked) == 0) { char* err_msg = NULL; if (!fill_in_arguments(&sl->args, (AstNode *) sl, &err_msg)) { - onyx_report_error(sl->token->pos, err_msg); + onyx_report_error(sl->token->pos, Error_Critical, err_msg); bh_arr_each(AstTyped *, value, sl->args.values) { if (*value == NULL) { @@ -1178,7 +1180,7 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) { StructMember smem; type_lookup_member_by_idx(sl->type, member_idx, &smem); - onyx_report_error(sl->token->pos, + onyx_report_error(sl->token->pos, Error_Critical, "Value not given for %d%s member, '%s', for type '%s'.", member_idx + 1, bh_num_suffix(member_idx + 1), smem.name, type_get_name(sl->type)); @@ -1707,7 +1709,7 @@ CheckStatus check_expression(AstTyped** pexpr) { case Ast_Kind_Param: if (expr->type == NULL) { - onyx_report_error(expr->token->pos, "Parameter with bad type."); + onyx_report_error(expr->token->pos, Error_Critical, "Parameter with bad type."); retval = Check_Error; } break; @@ -1726,7 +1728,7 @@ CheckStatus check_expression(AstTyped** pexpr) { case Ast_Kind_Global: if (expr->type == NULL) { - onyx_report_error(expr->token->pos, "Global with unknown type."); + onyx_report_error(expr->token->pos, Error_Critical, "Global with unknown type."); retval = Check_Error; } break; @@ -1820,7 +1822,7 @@ CheckStatus check_expression(AstTyped** pexpr) { default: retval = Check_Error; - onyx_report_error(expr->token->pos, "UNEXPECTED INTERNAL COMPILER ERROR"); + onyx_report_error(expr->token->pos, Error_Critical, "UNEXPECTED INTERNAL COMPILER ERROR"); DEBUG_HERE; break; } @@ -2011,7 +2013,7 @@ CheckStatus check_overloaded_function(AstOverloadedFunction* func) { if ( node->kind != Ast_Kind_Function && node->kind != Ast_Kind_Polymorphic_Proc && node->kind != Ast_Kind_Macro) { - onyx_report_error(node->token->pos, "Overload option not procedure or macro. Got '%s'", + onyx_report_error(node->token->pos, Error_Critical, "Overload option not procedure or macro. Got '%s'", onyx_ast_node_kind_string(node->kind)); bh_imap_free(&all_overloads); @@ -2089,7 +2091,7 @@ CheckStatus check_struct_defaults(AstStructType* s_node) { resolve_expression_type(*meta); if (((*meta)->flags & Ast_Flag_Comptime) == 0) { - onyx_report_error((*meta)->token->pos, "#tag expressions are expected to be compile-time known."); + onyx_report_error((*meta)->token->pos, Error_Critical, "#tag expressions are expected to be compile-time known."); return Check_Error; } } @@ -2115,7 +2117,7 @@ CheckStatus check_struct_defaults(AstStructType* s_node) { resolve_expression_type(*meta); if (((*meta)->flags & Ast_Flag_Comptime) == 0) { - onyx_report_error((*meta)->token->pos, "#tag expressions are expected to be compile-time known."); + onyx_report_error((*meta)->token->pos, Error_Critical, "#tag expressions are expected to be compile-time known."); return Check_Error; } } @@ -2254,7 +2256,7 @@ CheckStatus check_memres(AstMemRes* memres) { if (memres->initial_value != NULL) { if (memres->threadlocal) { - onyx_report_error(memres->token->pos, "'#thread_local' variables cannot have an initializer at the moment."); + onyx_report_error(memres->token->pos, Error_Critical, "'#thread_local' variables cannot have an initializer at the moment."); return Check_Error; } @@ -2461,7 +2463,7 @@ CheckStatus check_process_directive(AstNode* directive) { } } - onyx_report_error(fa->token->pos, "'%b' is not a member of '%s'.", + onyx_report_error(fa->token->pos, Error_Critical, "'%b' is not a member of '%s'.", fa->token->text, fa->token->length, st->name); return Check_Error; @@ -2469,7 +2471,7 @@ CheckStatus check_process_directive(AstNode* directive) { } default: { - onyx_report_error(tag->token->pos, "Cannot tag this."); + onyx_report_error(tag->token->pos, Error_Critical, "Cannot tag this."); return Check_Error; } } @@ -2627,8 +2629,8 @@ CheckStatus check_constraint_context(ConstraintContext *cc, Scope *scope, OnyxFi strncat(constraint_map, "'", 511); } - onyx_report_error(constraint->exprs[constraint->expr_idx]->token->pos, "Failed to satisfy constraint where %s.", constraint_map); - onyx_report_error(constraint->token->pos, "Here is where the interface was used."); + onyx_report_error(constraint->exprs[constraint->expr_idx]->token->pos, Error_Critical, "Failed to satisfy constraint where %s.", constraint_map); + onyx_report_error(constraint->token->pos, Error_Critical, "Here is where the interface was used."); return Check_Error; @@ -2705,9 +2707,9 @@ CheckStatus check_polyquery(AstPolyQuery *query) { if (query->successful_symres || solved_something) continue; if (query->error_on_fail || context.cycle_detected) { - onyx_report_error(query->token->pos, "Error solving for polymorphic variable '%b'.", param->poly_sym->token->text, param->poly_sym->token->length); - if (err_msg != NULL) onyx_report_error(query->token->pos, "%s", err_msg); - if (query->error_loc) onyx_report_error(query->error_loc->pos, "Here is where the call is located."); // :ErrorMessage + onyx_report_error(query->token->pos, Error_Critical, "Error solving for polymorphic variable '%b'.", param->poly_sym->token->text, param->poly_sym->token->length); + if (err_msg != NULL) onyx_report_error(query->token->pos, Error_Critical, "%s", err_msg); + if (query->error_loc) onyx_report_error(query->error_loc->pos, Error_Critical, "Here is where the call is located."); // :ErrorMessage } return Check_Failed; @@ -2768,7 +2770,7 @@ void check_entity(Entity* ent) { case Entity_Type_File_Contents: if (context.options->no_file_contents) { - onyx_report_error(ent->expr->token->pos, "#file_contents is disabled for this compilation."); + onyx_report_error(ent->expr->token->pos, Error_Critical, "#file_contents is disabled for this compilation."); } break; diff --git a/src/errors.c b/src/errors.c index 71fa50d1..6fdf2806 100644 --- a/src/errors.c +++ b/src/errors.c @@ -45,6 +45,12 @@ static void print_detailed_message(OnyxError* err, bh_file_contents* fc) { if (colored_printing) bh_printf("\033[0m"); } +static i32 errors_sort(const void* v1, const void* v2) { + OnyxError* e1 = (OnyxError *) v1; + OnyxError* e2 = (OnyxError *) v2; + return e2->rank - e1->rank; +} + void onyx_errors_print() { // NOTE: If the format of the error messages is ever changed, // update onyx_compile.vim and onyx.sublime-build to match @@ -53,7 +59,12 @@ void onyx_errors_print() { // // - brendanfh 2020/09/03 + qsort(errors.errors, bh_arr_length(errors.errors), sizeof(OnyxError), errors_sort); + + OnyxErrorRank last_rank = errors.errors[0].rank; bh_arr_each(OnyxError, err, errors.errors) { + if (last_rank != err->rank) break; + if (err->pos.filename) { bh_file_contents file_contents = { 0 }; bh_arr_each(bh_file_contents, fc, *errors.file_contents) { @@ -68,6 +79,8 @@ void onyx_errors_print() { } else { bh_printf("(%l,%l) %s\n", err->pos.line, err->pos.column, err->text); } + + last_rank = err->rank; } } @@ -85,7 +98,7 @@ void onyx_submit_error(OnyxError error) { bh_arr_push(errors.errors, error); } -void onyx_report_error(OnyxFilePos pos, char * format, ...) { +void onyx_report_error(OnyxFilePos pos, OnyxErrorRank rank, char * format, ...) { va_list vargs; va_start(vargs, format); @@ -94,6 +107,7 @@ void onyx_report_error(OnyxFilePos pos, char * format, ...) { OnyxError err = { .pos = pos, + .rank = rank, .text = bh_strdup(errors.msg_alloc, msg), }; @@ -121,9 +135,14 @@ void onyx_report_warning(OnyxFilePos pos, char* format, ...) { OnyxError err = { .pos = pos, + .rank = Error_Warning, .text = msg, }; + bh_arr_push(errors.errors, err); + + /* + bh_file_contents file_contents = { 0 }; bh_arr_each(bh_file_contents, fc, *errors.file_contents) { if (!strcmp(fc->filename, pos.filename)) { @@ -133,4 +152,5 @@ void onyx_report_warning(OnyxFilePos pos, char* format, ...) { } print_detailed_message(&err, &file_contents); + */ } diff --git a/src/onyx.c b/src/onyx.c index 60327a1a..6d8793ea 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -297,7 +297,7 @@ static b32 process_source_file(char* filename, OnyxFilePos error_pos) { bh_file_error err = bh_file_open(&file, filename); if (err != BH_FILE_ERROR_NONE) { if (context.cycle_detected) { - onyx_report_error(error_pos, "Failed to open file %s", filename); + onyx_report_error(error_pos, Error_Critical, "Failed to open file %s", filename); } return 0; } @@ -371,9 +371,9 @@ static b32 process_entity(Entity* ent) { switch (before_state) { case Entity_State_Error: if (ent->type != Entity_Type_Error) { - onyx_report_error(ent->expr->token->pos, "Error entity unexpected. This is definitely a compiler bug"); + onyx_report_error(ent->expr->token->pos, Error_Critical, "Error entity unexpected. This is definitely a compiler bug"); } else { - onyx_report_error(ent->error->token->pos, "Static error occured: '%b'", ent->error->error_msg->text, ent->error->error_msg->length); + onyx_report_error(ent->error->token->pos, Error_Critical, "Static error occured: '%b'", ent->error->error_msg->text, ent->error->error_msg->length); } break; @@ -463,8 +463,6 @@ static void dump_cycles() { context.cycle_detected = 1; Entity* ent; - onyx_report_error((OnyxFilePos) { 0 }, "Cycle detected. Dumping all stuck processing units."); - while (1) { ent = entity_heap_top(&context.entities); entity_heap_remove_top(&context.entities); diff --git a/src/parser.c b/src/parser.c index 6d55e323..a3013564 100644 --- a/src/parser.c +++ b/src/parser.c @@ -129,7 +129,7 @@ static OnyxToken* expect_token(OnyxParser* parser, TokenType token_type) { consume_token(parser); if (token->type != token_type) { - onyx_report_error(token->pos, "expected token '%s', got '%s'.", token_name(token_type), token_name(token->type)); + onyx_report_error(token->pos, Error_Critical, "expected token '%s', got '%s'.", token_name(token_type), token_name(token->type)); parser->hit_unexpected_token = 1; // :LinearTokenDependent parser->curr = &parser->tokenizer->tokens[bh_arr_length(parser->tokenizer->tokens) - 1]; @@ -505,7 +505,7 @@ static AstTyped* parse_factor(OnyxParser* parser) { do_block->type_node = (AstType *) &basic_type_auto_return; if (parser->curr->type != '{') { - onyx_report_error(parser->curr->pos, "Expected '{' after 'do', got '%s'.", token_name(parser->curr->type)); + onyx_report_error(parser->curr->pos, Error_Critical, "Expected '{' after 'do', got '%s'.", token_name(parser->curr->type)); retval = NULL; break; } @@ -576,7 +576,7 @@ static AstTyped* parse_factor(OnyxParser* parser) { char_lit->value.i = (u32) dest; if (length != 1) { - onyx_report_error(char_lit->token->pos, "Expected only a single character in character literal."); + onyx_report_error(char_lit->token->pos, Error_Critical, "Expected only a single character in character literal."); } retval = (AstTyped *) char_lit; @@ -695,13 +695,13 @@ static AstTyped* parse_factor(OnyxParser* parser) { break; } - onyx_report_error(parser->curr->pos, "Invalid directive in expression."); + onyx_report_error(parser->curr->pos, Error_Critical, "Invalid directive in expression."); return NULL; } default: no_match: - onyx_report_error(parser->curr->pos, "Unexpected token '%s'.", token_name(parser->curr->type)); + onyx_report_error(parser->curr->pos, Error_Critical, "Unexpected token '%s'.", token_name(parser->curr->type)); return NULL; } @@ -1171,7 +1171,7 @@ static AstSwitch* parse_switch_stmt(OnyxParser* parser) { switch_node->default_case = parse_block(parser, 1, NULL); if (parser->curr->type != '}') { - onyx_report_error(parser->curr->pos, "The #default case must be the last case in a switch statement.\n"); + onyx_report_error(parser->curr->pos, Error_Critical, "The #default case must be the last case in a switch statement.\n"); } break; } @@ -1588,7 +1588,7 @@ static void parse_polymorphic_variable(OnyxParser* parser, AstType*** next_inser bh_arr(AstPolyParam) pv = NULL; if (parser->polymorph_context.poly_params == NULL) - onyx_report_error(parser->curr->pos, "Polymorphic variable not valid here."); + onyx_report_error(parser->curr->pos, Error_Critical, "Polymorphic variable not valid here."); else pv = *parser->polymorph_context.poly_params; @@ -1832,7 +1832,7 @@ static AstType* parse_type(OnyxParser* parser) { } default: - onyx_report_error(parser->curr->pos, "unexpected token '%b'.", parser->curr->text, parser->curr->length); + onyx_report_error(parser->curr->pos, Error_Critical, "unexpected token '%b'.", parser->curr->text, parser->curr->length); consume_token(parser); break; } @@ -1923,7 +1923,7 @@ static AstStructType* parse_struct(OnyxParser* parser) { OnyxToken* directive_token = expect_token(parser, '#'); OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol); - onyx_report_error(directive_token->pos, "unknown directive '#%b'.", symbol_token->text, symbol_token->length); + onyx_report_error(directive_token->pos, Error_Critical, "unknown directive '#%b'.", symbol_token->text, symbol_token->length); } } @@ -2023,8 +2023,8 @@ static AstStructType* parse_struct(OnyxParser* parser) { // them out of discussion for now. Initialized members should be treated special and // deserve their own line. if (bh_arr_length(member_list_temp) > 1) { - if (member_is_used) onyx_report_error((member_list_temp[0] - 1)->pos, "'use' is only allowed for a single struct member declaration. Try splitting this compound declaration into multiple lines."); - if (initial_value) onyx_report_error(initial_value->token->pos, "Intialized values are only allowed on single struct member declarations. Try splitting this compound initializer into multiple lines."); + if (member_is_used) onyx_report_error((member_list_temp[0] - 1)->pos, Error_Critical, "'use' is only allowed for a single struct member declaration. Try splitting this compound declaration into multiple lines."); + if (initial_value) onyx_report_error(initial_value->token->pos, Error_Critical, "Intialized values are only allowed on single struct member declarations. Try splitting this compound initializer into multiple lines."); } bh_arr_each(OnyxToken *, member_name, member_list_temp) { @@ -2365,7 +2365,7 @@ static AstFunction* parse_function_definition(OnyxParser* parser, OnyxToken* tok OnyxToken* directive_token = expect_token(parser, '#'); OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol); - onyx_report_error(directive_token->pos, "unknown directive '#%b'.", symbol_token->text, symbol_token->length); + onyx_report_error(directive_token->pos, Error_Critical, "unknown directive '#%b'.", symbol_token->text, symbol_token->length); } } @@ -2596,7 +2596,7 @@ static AstEnumType* parse_enum_declaration(OnyxParser* parser) { OnyxToken* directive_token = expect_token(parser, '#'); OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol); - onyx_report_error(directive_token->pos, "unknown directive '#%b'.", symbol_token->text, symbol_token->length); + onyx_report_error(directive_token->pos, Error_Critical, "unknown directive '#%b'.", symbol_token->text, symbol_token->length); } } @@ -2709,7 +2709,7 @@ static AstMacro* parse_macro(OnyxParser* parser) { return macro; } - onyx_report_error(parser->curr->pos, "'macro' expects to be followed by a producure definition."); + onyx_report_error(parser->curr->pos, Error_Critical, "'macro' expects to be followed by a producure definition."); return NULL; } @@ -3026,7 +3026,7 @@ static void parse_top_level_statement(OnyxParser* parser) { if (op == Binary_Op_Subscript) expect_token(parser, ']'); // #operator [] ... needs to consume the other ']' if (op == Binary_Op_Count) { - onyx_report_error(parser->curr->pos, "Invalid binary operator."); + onyx_report_error(parser->curr->pos, Error_Critical, "Invalid binary operator."); } else { operator->operator = op; } @@ -3109,7 +3109,7 @@ static void parse_top_level_statement(OnyxParser* parser) { OnyxToken* directive_token = expect_token(parser, '#'); OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol); - onyx_report_error(directive_token->pos, "unknown directive '#%b'.", symbol_token->text, symbol_token->length); + onyx_report_error(directive_token->pos, Error_Critical, "unknown directive '#%b'.", symbol_token->text, symbol_token->length); return; } } diff --git a/src/polymorph.h b/src/polymorph.h index 2cbfa349..a5a4db39 100644 --- a/src/polymorph.h +++ b/src/polymorph.h @@ -746,7 +746,7 @@ AstNode* polymorphic_proc_try_solidify(AstPolyProc* pp, bh_arr(AstPolySolution) if (found_match) { valid_argument_count++; } else { - onyx_report_error(tkn->pos, "'%b' is not a type variable of '%b'.", + onyx_report_error(tkn->pos, Error_Critical, "'%b' is not a type variable of '%b'.", sln->poly_sym->token->text, sln->poly_sym->token->length, pp->token->text, pp->token->length); return (AstNode *) pp; @@ -900,7 +900,7 @@ Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySoluti } if (bh_arr_length(slns) != bh_arr_length(ps_type->poly_params)) { - onyx_report_error(pos, "Wrong number of arguments for '%s'. Expected %d, got %d", + onyx_report_error(pos, Error_Critical, "Wrong number of arguments for '%s'. Expected %d, got %d", ps_type->name, bh_arr_length(ps_type->poly_params), bh_arr_length(slns)); @@ -921,10 +921,10 @@ Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySoluti if (sln->kind != expected_kind) { if (expected_kind == PSK_Type) - onyx_report_error(pos, "Expected type expression for %d%s argument.", i + 1, bh_num_suffix(i + 1)); + onyx_report_error(pos, Error_Critical, "Expected type expression for %d%s argument.", i + 1, bh_num_suffix(i + 1)); if (expected_kind == PSK_Value) - onyx_report_error(pos, "Expected value expression of type '%s' for %d%s argument.", + onyx_report_error(pos, Error_Critical, "Expected value expression of type '%s' for %d%s argument.", type_get_name(ps_type->poly_params[i].type), i + 1, bh_num_suffix(i + 1)); @@ -935,7 +935,7 @@ Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySoluti resolve_expression_type(sln->value); if ((sln->value->flags & Ast_Flag_Comptime) == 0) { - onyx_report_error(pos, + onyx_report_error(pos, Error_Critical, "Expected compile-time known argument for '%b'.", sln->poly_sym->token->text, sln->poly_sym->token->length); @@ -943,7 +943,7 @@ Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySoluti } if (!types_are_compatible(sln->value->type, ps_type->poly_params[i].type)) { - onyx_report_error(pos, "Expected compile-time argument of type '%s', got '%s'.", + onyx_report_error(pos, Error_Critical, "Expected compile-time argument of type '%s', got '%s'.", type_get_name(ps_type->poly_params[i].type), type_get_name(sln->value->type)); return NULL; diff --git a/src/symres.c b/src/symres.c index e5c2a340..5b611cd3 100644 --- a/src/symres.c +++ b/src/symres.c @@ -80,7 +80,7 @@ static SymresStatus symres_symbol(AstNode** symbol_node) { char *closest = find_closest_symbol_in_scope_and_parents(curr_scope, token->text); token_toggle_end(token); - onyx_report_error(token->pos, + onyx_report_error(token->pos, Error_Critical, "Unable to resolve symbol '%b'. Did you mean '%s'?", token->text, token->length, @@ -147,7 +147,7 @@ static SymresStatus symres_type(AstType** type) { SYMRES(field_access, (AstFieldAccess **) type); if (!node_is_type((AstNode *) *type)) - onyx_report_error((*type)->token->pos, "Field access did not result in a type. (%s)", onyx_ast_node_kind_string((*type)->kind)); + onyx_report_error((*type)->token->pos, Error_Critical, "Field access did not result in a type. (%s)", onyx_ast_node_kind_string((*type)->kind)); break; } @@ -298,13 +298,13 @@ static SymresStatus symres_field_access(AstFieldAccess** fa) { token_toggle_end((*fa)->token); if (closest) { - onyx_report_error((*fa)->token->pos, "'%b' was not found in package '%s'. Did you mean '%s'?", + onyx_report_error((*fa)->token->pos, Error_Critical, "'%b' was not found in package '%s'. Did you mean '%s'?", (*fa)->token->text, (*fa)->token->length, ((AstPackage *) (*fa)->expr)->package->name, closest); } else { - onyx_report_error((*fa)->token->pos, "'%b' was not found in package '%s'. Perhaps it is defined in a file that wasn't loaded?", + onyx_report_error((*fa)->token->pos, Error_Critical, "'%b' was not found in package '%s'. Perhaps it is defined in a file that wasn't loaded?", (*fa)->token->text, (*fa)->token->length, ((AstPackage *) (*fa)->expr)->package->name); @@ -317,7 +317,7 @@ static SymresStatus symres_field_access(AstFieldAccess** fa) { } else if (force_a_lookup) { if (context.cycle_detected) { - onyx_report_error((*fa)->token->pos, "'%b' does not exist here. This is a bad error message.", + onyx_report_error((*fa)->token->pos, Error_Critical, "'%b' does not exist here. This is a bad error message.", (*fa)->token->text, (*fa)->token->length); return Symres_Error; @@ -350,7 +350,7 @@ static SymresStatus symres_pipe(AstBinaryOp** pipe) { SYMRES(expression, &(*pipe)->left); if (call_node->kind != Ast_Kind_Call) { - onyx_report_error((*pipe)->token->pos, "Pipe operator expected call on right side."); + onyx_report_error((*pipe)->token->pos, Error_Critical, "Pipe operator expected call on right side."); return Symres_Error; } @@ -379,7 +379,7 @@ static SymresStatus symres_pipe(AstBinaryOp** pipe) { static SymresStatus symres_method_call(AstBinaryOp** mcall) { AstCall* call_node = (AstCall *) (*mcall)->right; if (call_node->kind != Ast_Kind_Call) { - onyx_report_error((*mcall)->token->pos, "'->' expected procedure call on right side."); + onyx_report_error((*mcall)->token->pos, Error_Critical, "'->' expected procedure call on right side."); return Symres_Error; } @@ -668,7 +668,7 @@ static SymresStatus symres_use(AstUse* use) { AstNode* thing = symbol_resolve(package->package->scope, qu->symbol_name); if (thing == NULL) { // :SymresStall if (report_unresolved_symbols) { - onyx_report_error(qu->symbol_name->pos, + onyx_report_error(qu->symbol_name->pos, Error_Critical, "The symbol '%b' was not found in this package.", qu->symbol_name->text, qu->symbol_name->length); return Symres_Error; @@ -706,7 +706,7 @@ static SymresStatus symres_use(AstUse* use) { bh_arr_each(QualifiedUse, qu, use->only) { AstNode* thing = symbol_resolve(st->scope, qu->symbol_name); if (thing == NULL) { - onyx_report_error(qu->symbol_name->pos, + onyx_report_error(qu->symbol_name->pos, Error_Critical, "The symbol '%b' was not found in this scope.", qu->symbol_name->text, qu->symbol_name->length); return Symres_Error; @@ -746,7 +746,7 @@ static SymresStatus symres_use(AstUse* use) { } cannot_use: - onyx_report_error(use->token->pos, "Cannot use this because its type is unknown."); + onyx_report_error(use->token->pos, Error_Critical, "Cannot use this because its type is unknown."); return Symres_Error; } @@ -768,7 +768,7 @@ static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid) { } if (!solid->poly_proc || solid->poly_proc->kind != Ast_Kind_Polymorphic_Proc) { - onyx_report_error(solid->token->pos, "Expected polymorphic procedure in #solidify directive."); + onyx_report_error(solid->token->pos, Error_Critical, "Expected polymorphic procedure in #solidify directive."); return Symres_Error; } @@ -948,7 +948,7 @@ SymresStatus symres_function_header(AstFunction* func) { AstType* return_type = (AstType *) strip_aliases((AstNode *) func->return_type); if (return_type->kind == Ast_Kind_Symbol) return Symres_Yield_Macro; - onyx_report_error(func->token->pos, "Return type is not a type."); + onyx_report_error(func->token->pos, Error_Critical, "Return type is not a type."); } if (func->constraints.constraints != NULL) { @@ -1011,11 +1011,11 @@ SymresStatus symres_function(AstFunction* func) { param->use_processed = 1; } else if (param->local->type != NULL) { - onyx_report_error(param->local->token->pos, "Can only 'use' structures or pointers to structures."); + onyx_report_error(param->local->token->pos, Error_Critical, "Can only 'use' structures or pointers to structures."); } else { // :ExplicitTyping - onyx_report_error(param->local->token->pos, "Cannot deduce type of parameter '%b'; Try adding it explicitly.", + onyx_report_error(param->local->token->pos, Error_Critical, "Cannot deduce type of parameter '%b'; Try adding it explicitly.", param->local->token->text, param->local->token->length); } @@ -1054,7 +1054,7 @@ static SymresStatus symres_package(AstPackage* package) { return Symres_Success; } else { if (report_unresolved_symbols) { - onyx_report_error(package->token->pos, + onyx_report_error(package->token->pos, Error_Critical, "Package '%s' not found in included source files.", package->package_name); return Symres_Error; @@ -1101,7 +1101,7 @@ static SymresStatus symres_enum(AstEnumType* enum_node) { } else if (type_is_integer(n_value->type)) { next_assign_value = n_value->value.l; } else { - onyx_report_error((*value)->token->pos, "expected numeric integer literal for enum initialization, got '%s'", type_get_name(n_value->type)); + onyx_report_error((*value)->token->pos, Error_Critical, "expected numeric integer literal for enum initialization, got '%s'", type_get_name(n_value->type)); return Symres_Error; } @@ -1113,7 +1113,7 @@ static SymresStatus symres_enum(AstEnumType* enum_node) { } if (context.cycle_detected) { - onyx_report_error((*value)->token->pos, "Expected compile time known value for enum initialization."); + onyx_report_error((*value)->token->pos, Error_Critical, "Expected compile time known value for enum initialization."); return Symres_Error; } @@ -1208,7 +1208,7 @@ static SymresStatus symres_process_directive(AstNode* directive) { if (add_overload->overloaded_function == NULL) return Symres_Error; // NOTE: Error message will already be generated if (add_overload->overloaded_function->kind != Ast_Kind_Overloaded_Function) { - onyx_report_error(add_overload->token->pos, "#add_overload directive did not resolve to an overloaded function."); + onyx_report_error(add_overload->token->pos, Error_Critical, "#add_overload directive did not resolve to an overloaded function."); } else { AstOverloadedFunction* ofunc = (AstOverloadedFunction *) add_overload->overloaded_function; @@ -1226,12 +1226,12 @@ static SymresStatus symres_process_directive(AstNode* directive) { AstFunction* overload = get_function_from_node((AstNode *) operator->overload); if (overload == NULL) { - onyx_report_error(operator->token->pos, "This cannot be used as an operator overload."); + onyx_report_error(operator->token->pos, Error_Critical, "This cannot be used as an operator overload."); return Symres_Error; } if (operator->operator != Binary_Op_Subscript_Equals && bh_arr_length(overload->params) != 2) { - onyx_report_error(operator->token->pos, "Expected exactly 2 arguments for binary operator overload."); + onyx_report_error(operator->token->pos, Error_Critical, "Expected exactly 2 arguments for binary operator overload."); return Symres_Error; } @@ -1244,7 +1244,7 @@ static SymresStatus symres_process_directive(AstNode* directive) { SYMRES(expression, &export->export); if (export->export->kind == Ast_Kind_Polymorphic_Proc) { - onyx_report_error(export->token->pos, "Cannot export a polymorphic function."); + onyx_report_error(export->token->pos, Error_Critical, "Cannot export a polymorphic function."); return Symres_Error; } @@ -1255,12 +1255,12 @@ static SymresStatus symres_process_directive(AstNode* directive) { if (func->is_exported) { if (func->is_foreign) { - onyx_report_error(export->token->pos, "Cannot export a foreign function."); + onyx_report_error(export->token->pos, Error_Critical, "Cannot export a foreign function."); return Symres_Error; } if (func->is_intrinsic) { - onyx_report_error(export->token->pos, "Cannot export an intrinsic function."); + onyx_report_error(export->token->pos, Error_Critical, "Cannot export an intrinsic function."); return Symres_Error; } } @@ -1373,7 +1373,7 @@ static SymresStatus symres_foreign_block(AstForeignBlock *fb) { Entity *ent = *pent; if (ent->type == Entity_Type_Function_Header) { if (ent->function->body->next != NULL) { - onyx_report_error(ent->function->token->pos, "Procedures declared in a #foreign block should not have bodies."); + onyx_report_error(ent->function->token->pos, Error_Critical, "Procedures declared in a #foreign block should not have bodies."); return Symres_Error; } @@ -1402,7 +1402,7 @@ static SymresStatus symres_include(AstInclude* include) { SYMRES(expression, &include->name_node); if (include->name_node->kind != Ast_Kind_StrLit) { - onyx_report_error(include->token->pos, "Expected compile-time known string literal here. Got '%s'.", onyx_ast_node_kind_string(include->name_node->kind)); + onyx_report_error(include->token->pos, Error_Critical, "Expected compile-time known string literal here. Got '%s'.", onyx_ast_node_kind_string(include->name_node->kind)); return Symres_Error; } diff --git a/src/types.c b/src/types.c index ce1ad2a5..fb4068bc 100644 --- a/src/types.c +++ b/src/types.c @@ -319,7 +319,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { // NOTE: Currently, the count_expr has to be an I32 literal if (a_node->count_expr->type->kind != Type_Kind_Basic || a_node->count_expr->type->Basic.kind != Basic_Kind_I32) { - onyx_report_error(type_node->token->pos, "Array type expects type 'i32' for size, got '%s'.", + onyx_report_error(type_node->token->pos, Error_Critical, "Array type expects type 'i32' for size, got '%s'.", type_get_name(a_node->count_expr->type)); return NULL; } @@ -383,7 +383,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { mem_alignment = type_alignment_of((*member)->type); if (mem_alignment <= 0) { - onyx_report_error((*member)->token->pos, "Invalid member type: %s. Has alignment %d", type_get_name((*member)->type), mem_alignment); + onyx_report_error((*member)->token->pos, Error_Critical, "Invalid member type: %s. Has alignment %d", type_get_name((*member)->type), mem_alignment); return NULL; } @@ -392,7 +392,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { token_toggle_end((*member)->token); if (shgeti(s_type->Struct.members, (*member)->token->text) != -1) { - onyx_report_error((*member)->token->pos, "Duplicate struct member, '%s'.", (*member)->token->text); + onyx_report_error((*member)->token->pos, Error_Critical, "Duplicate struct member, '%s'.", (*member)->token->text); return NULL; } @@ -421,13 +421,13 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { } if (used_type->kind != Type_Kind_Struct) { - onyx_report_error((*member)->token->pos, "Can only use things of structure, or pointer to structure type."); + onyx_report_error((*member)->token->pos, Error_Critical, "Can only use things of structure, or pointer to structure type."); return NULL; } bh_arr_each(StructMember*, psmem, used_type->Struct.memarr) { if (shgeti(s_type->Struct.members, (*psmem)->name) != -1) { - onyx_report_error((*member)->token->pos, "Used name '%s' conflicts with existing struct member.", (*psmem)->name); + onyx_report_error((*member)->token->pos, Error_Critical, "Used name '%s' conflicts with existing struct member.", (*psmem)->name); return NULL; } @@ -538,10 +538,6 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { return ((AstTypeRawAlias *) type_node)->to; case Ast_Kind_Poly_Struct_Type: { - //onyx_report_error(type_node->token->pos, - // "This structure is polymorphic, which means you need to provide arguments to it to make it a concrete structure. " - // "This error message is probably in the wrong place, so look through your code for uses of this struct."); - if (type_node->type_id != 0) return NULL; Type* p_type = type_create(Type_Kind_PolyStruct, alloc, 0); @@ -561,8 +557,8 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { // If it is an unresolved field access or symbol, just return because an error will be printed elsewhere. if (pc_type->callee->kind == Ast_Kind_Field_Access || pc_type->callee->kind == Ast_Kind_Symbol) return NULL; - onyx_report_error(pc_type->token->pos, "Cannot instantiate a concrete type off of a non-polymorphic type."); - onyx_report_error(pc_type->callee->token->pos, "Here is the type trying to be instantiated. (%s)", onyx_ast_node_kind_string(pc_type->callee->kind)); + onyx_report_error(pc_type->token->pos, Error_Critical, "Cannot instantiate a concrete type off of a non-polymorphic type."); + onyx_report_error(pc_type->callee->token->pos, Error_Critical, "Here is the type trying to be instantiated. (%s)", onyx_ast_node_kind_string(pc_type->callee->kind)); return NULL; } @@ -651,7 +647,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { Type *base_type = type_build_from_ast(alloc, distinct->base_type); if (base_type == NULL) return NULL; if (base_type->kind != Type_Kind_Basic) { - onyx_report_error(distinct->token->pos, "Distinct types can only be made out of primitive types. '%s' is not a primitive type.", type_get_name(base_type)); + onyx_report_error(distinct->token->pos, Error_Critical, "Distinct types can only be made out of primitive types. '%s' is not a primitive type.", type_get_name(base_type)); return NULL; } diff --git a/src/utils.c b/src/utils.c index 898d29b0..06e863bd 100644 --- a/src/utils.c +++ b/src/utils.c @@ -109,7 +109,7 @@ b32 symbol_raw_introduce(Scope* scope, char* name, OnyxFilePos pos, AstNode* sym if (index != -1) { AstNode *node = scope->symbols[index].value; if (node != symbol) { - onyx_report_error(pos, "Redeclaration of symbol '%s'.", name); + onyx_report_error(pos, Error_Critical, "Redeclaration of symbol '%s'.", name); return 0; } return 1; @@ -465,7 +465,7 @@ void report_unable_to_match_overload(AstCall* call) { } } - onyx_report_error(call->token->pos, "Unable to match overloaded function with provided argument types: (%s)", arg_str); + onyx_report_error(call->token->pos, Error_Critical, "Unable to match overloaded function with provided argument types: (%s)", arg_str); bh_free(global_scratch_allocator, arg_str); } @@ -518,7 +518,7 @@ void expand_macro(AstCall** pcall, AstFunction* template) { Type *param_type = template->params[i].local->type; if (param_type == any_type || (param_type->kind == Type_Kind_VarArgs && param_type->VarArgs.elem == any_type)) { - onyx_report_error(macro->token->pos, "Currently, macros do not support arguments of type 'any' or '..any'."); + onyx_report_error(macro->token->pos, Error_Critical, "Currently, macros do not support arguments of type 'any' or '..any'."); } symbol_introduce(argument_scope, template->params[i].local->token, value); diff --git a/src/wasm_emit.c b/src/wasm_emit.c index 799a1ecd..de253c6e 100644 --- a/src/wasm_emit.c +++ b/src/wasm_emit.c @@ -409,7 +409,7 @@ EMIT_FUNC(structured_jump, AstJump* jump) { if (bh_arr_last(code).type != WI_JUMP) WID(WI_JUMP, labelidx); } else { - onyx_report_error(jump->token->pos, "Invalid structured jump."); + onyx_report_error(jump->token->pos, Error_Critical, "Invalid structured jump."); } *pcode = code; @@ -662,7 +662,7 @@ EMIT_FUNC(store_instruction, Type* type, u32 offset) { } else if (is_basic && (type->Basic.flags & Basic_Flag_SIMD)) { WID(WI_V128_STORE, ((WasmInstructionData) { alignment, offset })); } else { - onyx_report_error((OnyxFilePos) { 0 }, + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "Failed to generate store instruction for type '%s'.", type_get_name(type)); } @@ -723,7 +723,7 @@ EMIT_FUNC(load_instruction, Type* type, u32 offset) { WID(instr, ((WasmInstructionData) { alignment, offset })); if (instr == WI_NOP) { - onyx_report_error((OnyxFilePos) { 0 }, + onyx_report_error((OnyxFilePos) { 0 }, Error_Critical, "Failed to generate load instruction for type '%s'.", type_get_name(type)); } @@ -1131,7 +1131,7 @@ EMIT_FUNC(for, AstFor* for_node) { case For_Loop_DynArr: WI(WI_DROP); WI(WI_DROP); WI(WI_DROP); case For_Loop_Slice: emit_for_slice(mod, &code, for_node, iter_local); break; case For_Loop_Iterator: emit_for_iterator(mod, &code, for_node, iter_local); break; - default: onyx_report_error(for_node->token->pos, "Invalid for loop type. You should probably not be seeing this..."); + default: onyx_report_error(for_node->token->pos, Error_Critical, "Invalid for loop type. You should probably not be seeing this..."); } local_free(mod->local_alloc, (AstTyped *) var); @@ -1641,7 +1641,7 @@ EMIT_FUNC(call, AstCall* call) { bh_arr(AstArgument *) arg_arr = (bh_arr(AstArgument *)) call->args.values; \ fori (i, 0, count) { \ if (arg_arr[i]->value->kind != Ast_Kind_NumLit) { \ - onyx_report_error(arg_arr[i]->token->pos, \ + onyx_report_error(arg_arr[i]->token->pos, Error_Critical, \ "SIMD constants expect compile time constants as parameters. The %d%s parameter was not.", \ i, bh_num_suffix(i)); \ *pcode = code; \ @@ -1655,7 +1655,7 @@ EMIT_FUNC(call, AstCall* call) { #define SIMD_EXTRACT_LANE_INSTR(instr, arg_arr) \ emit_expression(mod, &code, arg_arr[0]->value);\ if (arg_arr[1]->value->kind != Ast_Kind_NumLit) { \ - onyx_report_error(arg_arr[1]->token->pos, "SIMD lane instructions expect a compile time lane number."); \ + onyx_report_error(arg_arr[1]->token->pos, Error_Critical, "SIMD lane instructions expect a compile time lane number."); \ *pcode = code; \ return; \ } \ @@ -1664,7 +1664,7 @@ EMIT_FUNC(call, AstCall* call) { #define SIMD_REPLACE_LANE_INSTR(instr, arg_arr) { \ emit_expression(mod, &code, arg_arr[0]->value);\ if (arg_arr[1]->value->kind != Ast_Kind_NumLit) { \ - onyx_report_error(arg_arr[1]->token->pos, "SIMD lane instructions expect a compile time lane number."); \ + onyx_report_error(arg_arr[1]->token->pos, Error_Critical, "SIMD lane instructions expect a compile time lane number."); \ *pcode = code; \ return; \ } \ @@ -1788,7 +1788,7 @@ EMIT_FUNC(intrinsic_call, AstCall* call) { bh_arr(AstArgument *) arg_arr = (bh_arr(AstArgument *)) call->args.values; fori (i, 0, 4) { if (arg_arr[i]->value->kind != Ast_Kind_NumLit) { - onyx_report_error(arg_arr[i]->token->pos, + onyx_report_error(arg_arr[i]->token->pos, Error_Critical, "SIMD constants expect compile time constants as parameters. The %d%s parameter was not.", i, bh_num_suffix(i)); *pcode = code; @@ -1805,7 +1805,7 @@ EMIT_FUNC(intrinsic_call, AstCall* call) { bh_arr(AstArgument *) arg_arr = (bh_arr(AstArgument *)) call->args.values; fori (i, 0, 2) { if (arg_arr[i]->value->kind != Ast_Kind_NumLit) { - onyx_report_error(arg_arr[i]->token->pos, + onyx_report_error(arg_arr[i]->token->pos, Error_Critical, "SIMD constants expect compile time constants as parameters. The %d%s parameter was not.", i, bh_num_suffix(i)); *pcode = code; @@ -1828,7 +1828,7 @@ EMIT_FUNC(intrinsic_call, AstCall* call) { fori (i, 0, 16) { if (arg_arr[i + 2]->value->kind != Ast_Kind_NumLit) { - onyx_report_error(arg_arr[i + 2]->token->pos, + onyx_report_error(arg_arr[i + 2]->token->pos, Error_Critical, "SIMD constants expect compile time constants as parameters. The %d%s parameter was not.", i, bh_num_suffix(i)); *pcode = code; @@ -2548,7 +2548,7 @@ EMIT_FUNC(location_return_offset, AstTyped* expr, u64* offset_return) { } default: { - onyx_report_error(expr->token->pos, "Unable to generate locate for '%s'.", onyx_ast_node_kind_string(expr->kind)); + onyx_report_error(expr->token->pos, Error_Critical, "Unable to generate location for '%s'.", onyx_ast_node_kind_string(expr->kind)); break; } } @@ -2845,7 +2845,7 @@ EMIT_FUNC(expression, AstTyped* expr) { WasmType backing_type = onyx_type_to_wasm_type(ev->type); if (backing_type == WASM_TYPE_INT32) WID(WI_I32_CONST, num->value.i); else if (backing_type == WASM_TYPE_INT64) WID(WI_I64_CONST, num->value.l); - else onyx_report_error(ev->token->pos, "Invalid backing type for enum."); + else onyx_report_error(ev->token->pos, Error_Critical, "Invalid backing type for enum."); break; } @@ -3140,7 +3140,7 @@ EMIT_FUNC(zero_value_for_type, Type* type, OnyxToken* where) { else { WasmType wt = onyx_type_to_wasm_type(type); if (wt == WASM_TYPE_VOID) { - onyx_report_error(where->pos, "Cannot produce a zero-value for this type."); + onyx_report_error(where->pos, Error_Critical, "Cannot produce a zero-value for this type."); } emit_zero_value(mod, &code, wt); } @@ -3450,7 +3450,7 @@ static void emit_string_literal(OnyxWasmModule* mod, AstStrLit* strlit) { static void emit_raw_data(OnyxWasmModule* mod, ptr data, AstTyped* node) { if (!emit_raw_data_(mod, data, node)) { - onyx_report_error(node->token->pos, + onyx_report_error(node->token->pos, Error_Critical, "Cannot generate constant data for '%s'.", onyx_ast_node_kind_string(node->kind)); } @@ -3673,7 +3673,7 @@ static void emit_file_contents(OnyxWasmModule* mod, AstFileContents* fc) { bh_align(offset, 16); if (!bh_file_exists(fc->filename)) { - onyx_report_error(fc->filename_token->pos, + onyx_report_error(fc->filename_token->pos, Error_Critical, "Unable to open file for reading, '%s'.", fc->filename); return; diff --git a/src/wasm_intrinsics.h b/src/wasm_intrinsics.h index 1d2b229a..9f4ccba4 100644 --- a/src/wasm_intrinsics.h +++ b/src/wasm_intrinsics.h @@ -143,7 +143,7 @@ EMIT_FUNC(initialize_type, Type* type, OnyxToken* where) { } default: - onyx_report_error(where->pos, + onyx_report_error(where->pos, Error_Critical, "Unable to initialize type, '%s'. The reason for this is largely due to the compiler not knowing what the initial value should be.", type_get_name(type)); break; @@ -171,7 +171,7 @@ EMIT_FUNC(intrinsic_atomic_wait, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic wait, '%s'. Only i32 and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic wait, '%s'. Only i32 and i64 are supported.", type_get_name(type)); } EMIT_FUNC_NO_ARGS(intrinsic_atomic_notify) { @@ -208,7 +208,7 @@ EMIT_FUNC(intrinsic_atomic_load, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic load, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic load, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); } EMIT_FUNC(intrinsic_atomic_store, Type* type, OnyxToken* where) { @@ -233,7 +233,7 @@ EMIT_FUNC(intrinsic_atomic_store, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic store, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic store, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); } EMIT_FUNC(intrinsic_atomic_add, Type* type, OnyxToken* where) { @@ -258,7 +258,7 @@ EMIT_FUNC(intrinsic_atomic_add, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic add, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic add, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); } EMIT_FUNC(intrinsic_atomic_sub, Type* type, OnyxToken* where) { @@ -283,7 +283,7 @@ EMIT_FUNC(intrinsic_atomic_sub, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic sub, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic sub, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); } EMIT_FUNC(intrinsic_atomic_and, Type* type, OnyxToken* where) { @@ -308,7 +308,7 @@ EMIT_FUNC(intrinsic_atomic_and, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic and, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic and, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); } EMIT_FUNC(intrinsic_atomic_or, Type* type, OnyxToken* where) { @@ -333,7 +333,7 @@ EMIT_FUNC(intrinsic_atomic_or, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic or, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic or, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); } EMIT_FUNC(intrinsic_atomic_xor, Type* type, OnyxToken* where) { @@ -358,7 +358,7 @@ EMIT_FUNC(intrinsic_atomic_xor, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic xor, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic xor, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); } EMIT_FUNC(intrinsic_atomic_xchg, Type* type, OnyxToken* where) { @@ -383,7 +383,7 @@ EMIT_FUNC(intrinsic_atomic_xchg, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic xchg, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic xchg, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); } EMIT_FUNC(intrinsic_atomic_cmpxchg, Type* type, OnyxToken* where) { @@ -408,7 +408,7 @@ EMIT_FUNC(intrinsic_atomic_cmpxchg, Type* type, OnyxToken* where) { return; bad_type: - onyx_report_error(where->pos, "Bad type for atomic cmpxchg, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); + onyx_report_error(where->pos, Error_Critical, "Bad type for atomic cmpxchg, '%s'. Only u8, u16, u32, i32, u64, and i64 are supported.", type_get_name(type)); } EMIT_FUNC_NO_ARGS(initialize_data_segments_body) { -- 2.25.1