fixed heap resize bug; added to fun visualization
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 15 Dec 2020 15:28:25 +0000 (09:28 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 15 Dec 2020 15:28:25 +0000 (09:28 -0600)
core/alloc.onyx
onyx
src/onyx.c

index 8e2f2f293ca890d3cf0336596d863029856d673b..8c46aa5fe1d5fd9c9ac7c955da2fa3ca9c6e21da 100644 (file)
@@ -103,8 +103,18 @@ heap_resize :: proc (ptr: rawptr, new_size: u32, align: u32) -> rawptr {
 
     // If we are at the end of the allocation space, just extend it
     if hb_ptr.size + cast(u32) ptr >= cast(u32) heap_state.next_alloc {
+        if new_size >= heap_state.remaining_space {
+            new_pages :: ((new_size - heap_state.remaining_space) >> 16) + 1;
+            if memory_grow(new_pages) == -1 {
+                // out of memory
+                return null;
+            }
+            heap_state.remaining_space += new_pages << 16;
+        }
+
         hb_ptr.size = new_size + sizeof heap_block;
         heap_state.next_alloc = cast(rawptr) (cast(u32) ptr + hb_ptr.size);
+        heap_state.remaining_space -= new_size - old_size;
         return ptr;
     }
 
diff --git a/onyx b/onyx
index 43b006393b823542b5d16324f9879260df744cde..3a0f7f9d78c0da2657c356963e5bd9b4f7f15a39 100755 (executable)
Binary files a/onyx and b/onyx differ
index 05f3b2c52155c8a7a52dc65a35920536a94ecf02..ff2a5e39d7ff4da2ee3f77ca10ba10acbaee8f1b 100644 (file)
@@ -450,18 +450,12 @@ static b32 process_entity(CompilerState* compiler_state, Entity* ent) {
 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("\e[0K");
+        for (i32 c = 0; c < eh->state_count[i] / 10; c++) printf("\xe2\x96\x88");
         printf("\n");
     }
 }
@@ -497,14 +491,20 @@ static i32 onyx_compile(CompilerState* compiler_state) {
         printf("\e[2J");
 
     while (!bh_arr_is_empty(compiler_state->prog_info.entities.entities)) {
+        Entity ent = entity_heap_top(&compiler_state->prog_info.entities);
+
         if (compiler_state->options->fun_output) {
             output_dummy_progress_bar(compiler_state);
 
             // Slowing things down for the effect
-            usleep(500);
+            usleep(2000);
+
+            if (ent.expr->token) {
+                OnyxFilePos pos = ent.expr->token->pos;
+                printf("\e[0K%s on %s:%d:%d\n", entity_state_strings[ent.state], pos.filename, pos.line, pos.column);
+            }
         }
 
-        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);