From: Brendan Hansen Date: Tue, 15 Dec 2020 15:28:25 +0000 (-0600) Subject: fixed heap resize bug; added to fun visualization X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=26a475d8907905a04f048af12ef203001497498d;p=onyx.git fixed heap resize bug; added to fun visualization --- diff --git a/core/alloc.onyx b/core/alloc.onyx index 8e2f2f29..8c46aa5f 100644 --- a/core/alloc.onyx +++ b/core/alloc.onyx @@ -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 43b00639..3a0f7f9d 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyx.c b/src/onyx.c index 05f3b2c5..ff2a5e39 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -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);