From: Brendan Hansen Date: Wed, 21 Sep 2022 15:38:10 +0000 (-0500) Subject: added `onyx check` X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=80de02fd93c369036fed5e2bd424d56ad557f114;p=onyx.git added `onyx check` --- diff --git a/.githooks/pre-commit b/.githooks/pre-commit index e99cf869..7efa6b25 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -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 diff --git a/compiler/include/astnodes.h b/compiler/include/astnodes.h index 01003252..c0cfc53f 100644 --- a/compiler/include/astnodes.h +++ b/compiler/include/astnodes.h @@ -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, diff --git a/compiler/src/onyx.c b/compiler/src/onyx.c index 9433df38..0f3790ba 100644 --- a/compiler/src/onyx.c +++ b/compiler/src/onyx.c @@ -34,6 +34,7 @@ static const char* docstring = "Onyx compiler version " VERSION "\n" "\n" "Usage:\n" "\tonyx compile [-o ] [--verbose] \n" + "\tonyx check [--verbose] \n" #ifdef ENABLE_RUN_WITH_WASMER "\tonyx run -- \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) { diff --git a/interpreter/src/debug/debug_runtime_values.c b/interpreter/src/debug/debug_runtime_values.c index a1ebb063..0c283161 100644 --- a/interpreter/src/debug/debug_runtime_values.c +++ b/interpreter/src/debug/debug_runtime_values.c @@ -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; diff --git a/shared/lib/linux_x86_64/lib/libovmwasm.so b/shared/lib/linux_x86_64/lib/libovmwasm.so index 27198c91..c836f358 100755 Binary files a/shared/lib/linux_x86_64/lib/libovmwasm.so and b/shared/lib/linux_x86_64/lib/libovmwasm.so differ diff --git a/tests/aoc-2020/day17.onyx b/tests/aoc-2020/day17.onyx index 4b165812..af534ca8 100644 --- a/tests/aoc-2020/day17.onyx +++ b/tests/aoc-2020/day17.onyx @@ -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 {