added `onyx check`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 21 Sep 2022 15:38:10 +0000 (10:38 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 21 Sep 2022 15:38:10 +0000 (10:38 -0500)
.githooks/pre-commit
compiler/include/astnodes.h
compiler/src/onyx.c
interpreter/src/debug/debug_runtime_values.c
shared/lib/linux_x86_64/lib/libovmwasm.so
tests/aoc-2020/day17.onyx

index e99cf869174f6f5fc6306ed16027a7311556e97b..7efa6b250a082f58827137a1a3e058cd6ade26b3 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-! grep -Rns nocheckin src include core
\ No newline at end of file
+! grep -Rns nocheckin compiler interpretter runtime
\ No newline at end of file
index 01003252c0aa666742689f0d8862d17958ce27d9..c0cfc53f90cf51b59e50815f6fc4db3fa674b114 100644 (file)
@@ -1527,6 +1527,7 @@ struct Package {
 typedef enum CompileAction CompileAction;
 enum CompileAction {
     ONYX_COMPILE_ACTION_COMPILE,
+    ONYX_COMPILE_ACTION_CHECK,
     ONYX_COMPILE_ACTION_RUN,
     ONYX_COMPILE_ACTION_DOCUMENT,
     ONYX_COMPILE_ACTION_PRINT_HELP,
index 9433df38cec311c175a45b3fd8da0ed03cc57667..0f3790baa5acdb68b98c274312ef06b584002b8f 100644 (file)
@@ -34,6 +34,7 @@ static const char* docstring = "Onyx compiler version " VERSION "\n"
     "\n"
     "Usage:\n"
     "\tonyx compile [-o <target file>] [--verbose] <input files>\n"
+    "\tonyx check [--verbose] <input files>\n"
 #ifdef ENABLE_RUN_WITH_WASMER
     "\tonyx run <input files> -- <args>\n"
 #endif
@@ -111,6 +112,10 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
         options.action = ONYX_COMPILE_ACTION_COMPILE;
         arg_parse_start = 2;
     }
+    if (!strcmp(argv[1], "check")) {
+        options.action = ONYX_COMPILE_ACTION_CHECK;
+        arg_parse_start = 2;
+    }
     #ifdef ENABLE_RUN_WITH_WASMER
     else if (!strcmp(argv[1], "run")) {
         options.action = ONYX_COMPILE_ACTION_RUN;
@@ -501,7 +506,16 @@ static b32 process_entity(Entity* ent) {
 
         case Entity_State_Resolve_Symbols: symres_entity(ent); break;
         case Entity_State_Check_Types:     check_entity(ent);  break;
-        case Entity_State_Code_Gen:        emit_entity(ent);   break;
+
+        case Entity_State_Code_Gen: {
+            if (context.options->action == ONYX_COMPILE_ACTION_CHECK) {
+                ent->state = Entity_State_Finalized;
+                break;
+            }
+
+            emit_entity(ent);
+            break;
+        }
     }
 
     b32 changed = ent->state != before_state;
@@ -757,6 +771,10 @@ int main(int argc, char *argv[]) {
     switch (compile_opts.action) {
         case ONYX_COMPILE_ACTION_PRINT_HELP: bh_printf(docstring); return 1;
 
+        case ONYX_COMPILE_ACTION_CHECK:
+            compiler_progress = onyx_compile();
+            break;
+
         case ONYX_COMPILE_ACTION_COMPILE:
             compiler_progress = onyx_compile();
             if (compiler_progress == ONYX_COMPILER_PROGRESS_SUCCESS) {
index a1ebb063e62817513c2ee0d04c1ee0ef9163a4f7..0c28316140f9a489b86cc4f41028eff2edf04e38 100644 (file)
@@ -284,8 +284,7 @@ static u32 get_subvalues_for_type(debug_runtime_value_builder_t *builder, u32 ty
         case debug_type_kind_structure:
             return t->structure.member_count;
         
-        // TEMPORARY this will be the array elements
-        case debug_type_kind_array: return 0;
+        case debug_type_kind_array: return t->array.count;
     }
 }
 
@@ -376,6 +375,37 @@ void debug_runtime_value_build_descend(debug_runtime_value_builder_t *builder, u
         return;
     }
 
+    if (type->kind == debug_type_kind_array) {
+        builder->base_type = type->array.type;
+        builder->max_index = get_subvalues_for_type(builder, builder->base_type);
+
+        debug_type_info_t *sub_type = &builder->info->types[builder->base_type];
+
+        // Double buffering here so if there are multiple
+        // pointer descentions, the names don't get mangled.
+        static char name_buffer[2048];
+        static char tmp_buffer[2048];
+        snprintf(tmp_buffer, 2048, "[%d]", index);
+        strncpy(name_buffer, tmp_buffer, 2048);
+        builder->it_name = name_buffer;
+
+        if (builder->base_loc_kind == debug_sym_loc_register) {
+            ovm_value_t value;
+            if (!lookup_register_in_frame(builder->ovm_state, builder->ovm_frame, builder->base_loc, &value)) {
+                goto bad_case;
+            }
+
+            builder->base_loc_kind = debug_sym_loc_global;
+            builder->base_loc = value.u32 + sub_type->size * index;
+        }
+
+        else if (builder->base_loc_kind == debug_sym_loc_stack || builder->base_loc_kind == debug_sym_loc_global) {
+            builder->base_loc += sub_type->size * index;
+        }
+
+        return;
+    }
+
   bad_case:
     builder->base_loc_kind = debug_sym_loc_unknown;
     return;        
@@ -385,12 +415,12 @@ bool debug_runtime_value_build_step(debug_runtime_value_builder_t *builder) {
     if (builder->it_index >= builder->max_index) return false;
 
     debug_type_info_t *type = &builder->info->types[builder->base_type];
+    static char name_buffer[2048];
+    static char tmp_buffer[2048];
 
     if (type->kind == debug_type_kind_modifier && type->modifier.modifier_kind == debug_type_modifier_kind_pointer) {
         // Double buffering here so if there are multiple
         // pointer descentions, the names don't get mangled.
-        static char name_buffer[2048];
-        static char tmp_buffer[2048];
         snprintf(tmp_buffer, 2048, "*%s", builder->it_name);
         strncpy(name_buffer, tmp_buffer, 2048);
 
@@ -423,6 +453,34 @@ bool debug_runtime_value_build_step(debug_runtime_value_builder_t *builder) {
         }
     }
 
+    if (type->kind == debug_type_kind_array) {
+        snprintf(tmp_buffer, 2048, "[%d]", builder->it_index);
+        strncpy(name_buffer, tmp_buffer, 2048);
+        builder->it_name = name_buffer;
+        builder->it_type = type->array.type;
+        builder->it_has_children = get_subvalues_for_type(builder, builder->it_type) > 0;
+
+        debug_type_info_t *sub_type = &builder->info->types[builder->it_type];
+
+        if (builder->base_loc_kind == debug_sym_loc_register) {
+            ovm_value_t value;
+            if (lookup_register_in_frame(builder->ovm_state, builder->ovm_frame, builder->base_loc, &value)) {
+                builder->base_loc_kind = debug_sym_loc_global;
+                builder->base_loc = value.u32 + sub_type->size * builder->it_index;
+            }
+        }
+
+        if (builder->base_loc_kind == debug_sym_loc_stack) {
+            builder->it_loc_kind = debug_sym_loc_stack;
+            builder->it_loc = builder->base_loc + sub_type->size * builder->it_index;
+        }
+
+        if (builder->base_loc_kind == debug_sym_loc_global) {
+            builder->it_loc_kind = debug_sym_loc_global;
+            builder->it_loc = builder->base_loc + sub_type->size * builder->it_index;
+        }
+    }
+
 
     builder->it_index++;
     return true;
index 27198c9133125fe7b68ef47d6c514696ea179de3..c836f358e234ab997d49dc259036e6d14d373361 100755 (executable)
Binary files a/shared/lib/linux_x86_64/lib/libovmwasm.so and b/shared/lib/linux_x86_64/lib/libovmwasm.so differ
index 4b165812e61fe2a090767cf3b7406feea266b6d0..af534ca83459a40c14c32a9d4f597d446a479368 100644 (file)
@@ -13,7 +13,7 @@ CubeState :: struct {
 }
 
 #match hash.to_u32 (c: CubePos) -> u32 {
-    return 17 * c.x + 13 * c.y + 11 * c.z + 19 * c.w;
+    return 17 * c.x + 13 * c.y + 11 * c.z + 21 * c.w;
 }
 
 #operator == (a: CubePos, b: CubePos) -> bool {