From: Brendan Hansen Date: Tue, 15 Dec 2020 02:26:08 +0000 (-0600) Subject: added fun visualization and fixed entity state tracking X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=33556d5b7abed42429c4d6d10f48f38f81725791;p=onyx.git added fun visualization and fixed entity state tracking --- diff --git a/docs/todo b/docs/todo index 236a3fa1..d7abe558 100644 --- a/docs/todo +++ b/docs/todo @@ -64,6 +64,10 @@ Language Cohesion: WASM code; i.e. foo().bar; This should at least produce an error until the underlying issue is fixed. + [ ] Every type should have a unique id assigned to it. This would make it + easier to talk about types in a concrete way (for polymorphism and such), + and would prepare the compiler to output type information into data section. + API Expansion: There are many different places where the standard API for WASI and JS backends could be improved. Here are some of the target areas. diff --git a/onyx b/onyx index 75994f76..43b00639 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyx.c b/src/onyx.c index e65d9f5d..05f3b2c5 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -48,6 +48,7 @@ typedef struct OnyxCompileOptions { CompileAction action; u32 verbose_output : 1; + u32 fun_output : 1; bh_arr(const char *) included_folders; bh_arr(const char *) files; @@ -92,6 +93,9 @@ static OnyxCompileOptions compile_opts_parse(bh_allocator alloc, int argc, char else if (!strcmp(argv[i], "--verbose") || !strcmp(argv[i], "-V")) { options.verbose_output = 1; } + else if (!strcmp(argv[i], "--fun") || !strcmp(argv[i], "-F")) { + options.fun_output = 1; + } else if (!strcmp(argv[i], "-I")) { bh_arr_push(options.included_folders, argv[++i]); } @@ -442,6 +446,25 @@ static b32 process_entity(CompilerState* compiler_state, Entity* ent) { return changed; } +// Just having fun with some visual output - brendanfh 2020/12/14 +static void output_dummy_progress_bar(CompilerState* compiler_state) { + EntityHeap* eh = &compiler_state->prog_info.entities; + + const i32 WIDTH = 80; + + printf("\e[2;1H"); + for (i32 i = 0; i < Entity_State_Count - 1; i++) { + printf("%20s (%4d) | ", entity_state_strings[i], eh->state_count[i]); + + for (i32 c = 0; c < WIDTH; c++) { + if (c < eh->state_count[i] * 5 / WIDTH) + printf("\xe2\x96\x88"); + else + printf(" "); + } + printf("\n"); + } +} static i32 onyx_compile(CompilerState* compiler_state) { u64 start_time = bh_time_curr(); @@ -470,7 +493,17 @@ static i32 onyx_compile(CompilerState* compiler_state) { semstate.program = &compiler_state->prog_info; } + if (compiler_state->options->fun_output) + printf("\e[2J"); + while (!bh_arr_is_empty(compiler_state->prog_info.entities.entities)) { + if (compiler_state->options->fun_output) { + output_dummy_progress_bar(compiler_state); + + // Slowing things down for the effect + usleep(500); + } + Entity ent = entity_heap_top(&compiler_state->prog_info.entities); entity_heap_remove_top(&compiler_state->prog_info.entities); b32 changed = process_entity(compiler_state, &ent); diff --git a/src/onyxentities.c b/src/onyxentities.c index 428b4bb2..6b6cf892 100644 --- a/src/onyxentities.c +++ b/src/onyxentities.c @@ -72,6 +72,8 @@ void entity_heap_change_top(EntityHeap* entities, Entity new_top) { } void entity_heap_remove_top(EntityHeap* entities) { + entities->state_count[entities->entities[0].state]--; + entities->entities[0] = entities->entities[bh_arr_length(entities->entities) - 1]; bh_arr_pop(entities->entities); eh_shift_down(entities, 0);