added: `--show-all-errors`; fixed: step by instruction
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 15 Apr 2023 03:31:27 +0000 (22:31 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 15 Apr 2023 03:31:27 +0000 (22:31 -0500)
compiler/include/astnodes.h
compiler/src/checker.c
compiler/src/errors.c
compiler/src/onyx.c
compiler/src/wasm_emit.c
core/encoding/osad.onyx
core/io/reader.onyx
core/io/stdio.onyx
interpreter/src/debug/debug_thread.c

index 37a2ee3c567433cdbf8d526f4f562c4da6d7982e..b622186d5eac67270d83b3c002e0a467f5a36eac 100644 (file)
@@ -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;
index d5dd147c352ed9444e077e0679373e65c312fc80..90b5e5b455ff926faff43c4738fa757f760e77e5 100644 (file)
@@ -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.");
                         }
                     }
 
index 70180f35962d87725e4313e216c6e85d5c29898e..6bfaa80aec484a728a59b91d410781fdc5342362 100644 (file)
@@ -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 };
index c5755bca3c6886f96b29358cd89279120b706546..28c79a5d8baa15b2535cc82c4d5e07f52beb0faf 100644 (file)
@@ -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]);
             }
index 463e7b7e434950b6b1ebcf96778558c5d441f6c5..7d2e8bcef40bbccbb294c75efd0db186b60ecf79 100644 (file)
@@ -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.");
index 6fa05f590c96e804f6fdf8c2d9cbe2fd3b200554..ca4d84a95e9361d88e289a77615e6d159e3af22d 100644 (file)
@@ -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;
     }
 }
index 66130e3c01b54de33c0ae614e11f04bdd9f5c6cb..f1f0bf1bae870c501399c258a748f7b589b72821 100644 (file)
@@ -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;
index 34fe387e779bb95c30b64f279fcae8cb1a217eec..1ecaba0a0354a1032e096b3d40fddc7bb4b39a42 100644 (file)
@@ -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;
+                }
+            })
+        );
     }
 }
 
index 02d34633baf79a69e9300c5642ca5a04cb39cf94..fc0f1aa2171142d2057d48051384af205cbafa1e 100644 (file)
@@ -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);
         }
     }