From ff0b88fdcb86de5ed917f46a83a21282137f5a2e Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 14 Apr 2023 22:31:27 -0500 Subject: [PATCH] added: `--show-all-errors`; fixed: step by instruction --- compiler/include/astnodes.h | 1 + compiler/src/checker.c | 7 +------ compiler/src/errors.c | 2 +- compiler/src/onyx.c | 5 +++++ compiler/src/wasm_emit.c | 4 ++++ core/encoding/osad.onyx | 4 ++-- core/io/reader.onyx | 25 ++++++++++++++++++++++++- core/io/stdio.onyx | 15 +++++++++------ interpreter/src/debug/debug_thread.c | 6 +++++- 9 files changed, 52 insertions(+), 17 deletions(-) diff --git a/compiler/include/astnodes.h b/compiler/include/astnodes.h index 37a2ee3c..b622186d 100644 --- a/compiler/include/astnodes.h +++ b/compiler/include/astnodes.h @@ -1682,6 +1682,7 @@ struct CompileOptions { b32 generate_foreign_info : 1; b32 no_std : 1; b32 no_stale_code : 1; + b32 show_all_errors : 1; b32 generate_tag_file : 1; b32 generate_symbol_info_file : 1; diff --git a/compiler/src/checker.c b/compiler/src/checker.c index d5dd147c..90b5e5b4 100644 --- a/compiler/src/checker.c +++ b/compiler/src/checker.c @@ -1449,11 +1449,6 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) { // If there are no given arguments to a structure literal, it is treated as a 'zero-value', // and can be used to create a completely zeroed value of any type. if (bh_arr_length(sl->args.values) == 0 && bh_arr_length(sl->args.named_values) == 0) { - if (sl->type->kind == Type_Kind_Basic && - sl->type->Basic.kind == Basic_Kind_Void) { - ERROR(sl->token->pos, "Cannot produce a zero-value for 'void' type."); - } - AstZeroValue *zv = make_zero_value(context.ast_alloc, sl->token, sl->type); bh_arr_push(sl->args.values, (AstTyped *) zv); @@ -3352,7 +3347,7 @@ CheckStatus check_constraint(AstConstraint *constraint) { } else { onyx_errors_enable(); - YIELD(ic->expected_type_expr->token->pos, "Waiting on expected type expression to be resolved."); + YIELD_ERROR(ic->expected_type_expr->token->pos, "Waiting on expected type expression to be resolved."); } } diff --git a/compiler/src/errors.c b/compiler/src/errors.c index 70180f35..6bfaa80a 100644 --- a/compiler/src/errors.c +++ b/compiler/src/errors.c @@ -64,7 +64,7 @@ void onyx_errors_print() { OnyxErrorRank last_rank = errors.errors[0].rank; bh_arr_each(OnyxError, err, errors.errors) { - if (last_rank != err->rank) break; + if (!context.options->show_all_errors && last_rank != err->rank) break; if (err->pos.filename) { bh_file_contents file_contents = { 0 }; diff --git a/compiler/src/onyx.c b/compiler/src/onyx.c index c5755bca..28c79a5d 100644 --- a/compiler/src/onyx.c +++ b/compiler/src/onyx.c @@ -66,6 +66,7 @@ static const char *build_docstring = DOCSTRING_HEADER "Developer options:\n" "\t--no-colors Disables colors in the error message.\n" "\t--no-file-contents Disables '#file_contents' for security.\n" + "\t--show-all-errors Print all errors (can result in many consequencial errors from a single error)" "\t--print-function-mappings Prints a mapping from WASM function index to source location.\n" "\t--print-static-if-results Prints the conditional result of each #if statement. Useful for debugging.\n" "\n"; @@ -85,6 +86,7 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg .use_multi_threading = 0, .no_std = 0, .no_stale_code = 0, + .show_all_errors = 0, .runtime = Runtime_Onyx, @@ -196,6 +198,9 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg else if (!strcmp(argv[i], "--no-stale-code")) { options.no_stale_code = 1; } + else if (!strcmp(argv[i], "--show-all-errors")) { + options.show_all_errors = 1; + } else if (!strcmp(argv[i], "-I")) { bh_arr_push(options.included_folders, argv[++i]); } diff --git a/compiler/src/wasm_emit.c b/compiler/src/wasm_emit.c index 463e7b7e..7d2e8bce 100644 --- a/compiler/src/wasm_emit.c +++ b/compiler/src/wasm_emit.c @@ -3919,6 +3919,10 @@ EMIT_FUNC(zero_value_for_type, Type* type, OnyxToken* where, AstTyped *alloc_nod WID(NULL, WI_I32_CONST, mod->null_proc_func_idx); } else { + if (type == &basic_types[Basic_Kind_Void]) { + return; + } + WasmType wt = onyx_type_to_wasm_type(type); if (wt == WASM_TYPE_VOID) { onyx_report_error(where->pos, Error_Critical, "Cannot produce a zero-value for this type."); diff --git a/core/encoding/osad.onyx b/core/encoding/osad.onyx index 6fa05f59..ca4d84a9 100644 --- a/core/encoding/osad.onyx +++ b/core/encoding/osad.onyx @@ -154,7 +154,7 @@ deserialize :: (target: rawptr, type: type_expr, r: &io.Reader) -> bool { } case .Basic { - bytes, err := io.read_bytes(r, .{ target, info.size }); + err := io.read_fill_buffer(r, .{ target, info.size }); assert(err == .None, "Deserialize expected to be able to read all the bytes."); } @@ -217,7 +217,7 @@ deserialize :: (target: rawptr, type: type_expr, r: &io.Reader) -> bool { read_u32 :: macro (r: &io.Reader) -> u32 { dest: u32; - io.read_bytes(r, str.{~~&dest, 4}); + io.read_fill_buffer(r, str.{~~&dest, 4}); return dest; } } diff --git a/core/io/reader.onyx b/core/io/reader.onyx index 66130e3c..f1f0bf1b 100644 --- a/core/io/reader.onyx +++ b/core/io/reader.onyx @@ -33,6 +33,7 @@ Reader :: struct { read_byte :: read_byte; unread_byte :: unread_byte; read_bytes :: read_bytes; + read_fill_buffer :: read_fill_buffer; read_string :: read_string; read_i32 :: read_i32; read_i64 :: read_i64; @@ -190,7 +191,29 @@ read_string :: (use reader: &Reader, bytes := 1, allocator := context.allocator) buf := memory.make_slice(u8, bytes, allocator); bytes_read, err := read_bytes(reader, buf); return buf[0 .. bytes_read]; -}; +} + +read_fill_buffer :: (use reader: &Reader, bytes: [] u8) -> Error { + n := bytes.count; + if n == 0 { + if reader_get_buffered(reader) > 0 do return .None; + return reader_consume_error(reader); + } + + write_index := 0; + while n > 0 && !reader_empty(reader) { + reader_read_next_chunk(reader); + + to_write := math.min(n, end); + memory.copy(bytes.data + write_index, buffer.data, to_write); + n -= to_write; + write_index += to_write; + start += to_write; + } + + last_byte = cast(i32) bytes[write_index - 1]; + return (.None) if !reader_empty(reader) else .EOF; +} read_i32 :: (use reader: &Reader) -> i32 { n: i32 = 0; diff --git a/core/io/stdio.onyx b/core/io/stdio.onyx index 34fe387e..1ecaba0a 100644 --- a/core/io/stdio.onyx +++ b/core/io/stdio.onyx @@ -99,13 +99,16 @@ printf :: (format: str, va: ..any) { // // Prints to standard error, if available. eprintf :: (format: str, va: ..any) -> str { - flush :: (_, to_output) => { - runtime.platform.__output_error(to_output); - return true; - } - buffer: [1024] u8; - runtime.platform.__output_error(conv.format_va(buffer, format, va, .{null, flush})); + runtime.platform.__output_error( + conv.format_va(buffer, format, va, .{ + null, + (ctx: rawptr, to_output: str) -> bool { + runtime.platform.__output_error(to_output); + return true; + } + }) + ); } } diff --git a/interpreter/src/debug/debug_thread.c b/interpreter/src/debug/debug_thread.c index 02d34633..fc0f1aa2 100644 --- a/interpreter/src/debug/debug_thread.c +++ b/interpreter/src/debug/debug_thread.c @@ -96,6 +96,10 @@ static void resume_thread(debug_thread_state_t *thread) { sem_post(&thread->wait_semaphore); } +static void resume_thread_slow(debug_thread_state_t *thread) { + sem_post(&thread->wait_semaphore); +} + static u32 get_stack_frame_instruction_pointer(debug_state_t *debug, debug_thread_state_t *thread, ovm_stack_frame_t *frame) { ovm_func_t *func = frame->func; @@ -248,7 +252,7 @@ static DEBUG_COMMAND_HANDLER(debug_command_step) { if (granularity == 2) { ON_THREAD(thread_id) { (*thread)->run_count = 1; - resume_thread(*thread); + resume_thread_slow(*thread); } } -- 2.25.1