added fun visualization and fixed entity state tracking
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 15 Dec 2020 02:26:08 +0000 (20:26 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 15 Dec 2020 02:26:08 +0000 (20:26 -0600)
docs/todo
onyx
src/onyx.c
src/onyxentities.c

index 236a3fa10e5b3d01524da5d8d9b1f9964f6b0408..d7abe558cf939f5fa193ca4341d5eb00870c3969 100644 (file)
--- 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 75994f769a929bf46e1190e1ff2799fd902fc8db..43b006393b823542b5d16324f9879260df744cde 100755 (executable)
Binary files a/onyx and b/onyx differ
index e65d9f5d260909daef59e84febc5ea45e7ee890a..05f3b2c52155c8a7a52dc65a35920536a94ecf02 100644 (file)
@@ -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);
index 428b4bb2b05394d5e1bd4e8691cf4f708ab4194b..6b6cf892534669c7b964bdc27cc73b901541bd4e 100644 (file)
@@ -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);