hot reload working

This commit is contained in:
Krzosa Karol
2025-01-26 11:54:31 +01:00
parent 7831cc51d6
commit f98c8e3dfa
31 changed files with 415 additions and 219 deletions

View File

@@ -140,8 +140,8 @@ fn void ma_set0(ma_arena_t *arena) { ma_set_len(arena, 0); }
// Scratch arena
fn ma_temp_t ma_begin_scratch_ex(ma_arena_t **conflicts, int conflict_count) {
ma_arena_t *unoccupied = 0;
for (int i = 0; i < lengthof(tcx.scratch); i += 1) {
ma_arena_t *from_pool = tcx.scratch + i;
for (int i = 0; i < lengthof(tcx->scratch); i += 1) {
ma_arena_t *from_pool = tcx->scratch + i;
unoccupied = from_pool;
for (int conflict_i = 0; conflict_i < conflict_count; conflict_i += 1) {
ma_arena_t *from_conflict = conflicts[conflict_i];
@@ -162,7 +162,7 @@ fn ma_temp_t ma_begin_scratch_ex(ma_arena_t **conflicts, int conflict_count) {
}
fn ma_temp_t ma_begin_scratch(void) {
ma_temp_t result = ma_begin_temp(tcx.scratch + 0);
ma_temp_t result = ma_begin_temp(tcx->scratch + 0);
return result;
}

15
src/core/core_ctx.c Normal file
View File

@@ -0,0 +1,15 @@
gb_thread thread_ctx_t global_thread_context = {
.log = {
.break_on_fatal = true,
.break_on_error = true,
.break_on_warning = true,
.log_proc = default_log_proc,
}
};
fn void core_init(void) {
tcx = &global_thread_context;
tcx->temp = ma_create(ma_default_reserve_size);
ma_init(&tcx->perm, ma_default_reserve_size);
os_core_init();
}

View File

@@ -7,17 +7,10 @@ struct thread_ctx_t {
// to functions that allocate pernament memory. temp and scratch very nicely create reusable code
// perm is basically gb state so it would be nice to annotate which functions are reusable
// and which functions have state
ma_arena_t _perm;
ma_arena_t perm;
void *data[32];
logger_t log;
};
gb_thread thread_ctx_t tcx = {
.log = {
.break_on_fatal = true,
.break_on_error = true,
.break_on_warning = true,
.log_proc = default_log_proc,
}
};
gb_thread thread_ctx_t *tcx;

View File

@@ -47,4 +47,5 @@
#include "core_hash_table.c"
#ifndef DONT_INCLUDE_GENERATED_MATH
#include "core_math.gen.c"
#endif
#endif
#include "core_ctx.c"

View File

@@ -1,7 +1,7 @@
fn void log_basef(log_level_t level, s8_t file_and_line, const char *str, ...) {
ma_temp_t scratch = ma_begin_scratch();
S8_FMT(scratch.arena, str, string);
tcx.log.log_proc(level, file_and_line, string);
tcx->log.log_proc(level, file_and_line, string);
ma_end_scratch(scratch);
}
@@ -15,11 +15,11 @@ fn void default_log_proc(log_level_t level, s8_t file_and_line, s8_t string) {
} break;
case log_level_warning: {
os_console_log(s8_printf(scratch.arena, "%S: warning: %S\n", file_and_line, string).str);
if (tcx.log.break_on_warning) debug_break();
if (tcx->log.break_on_warning) debug_break();
} break;
case log_level_error: {
os_console_log(s8_printf(scratch.arena, "%S: error: %S\n", file_and_line, string).str);
if (tcx.log.break_on_error) debug_break();
if (tcx->log.break_on_error) debug_break();
} break;
case log_level_fatal: {
os_error_box(s8_printf(scratch.arena, "%S: fatal error: %S\n", file_and_line, string).str);

View File

@@ -33,5 +33,5 @@ fn f64 os_parse_float(char *str) {
return strtod(str, NULL);
}
fn void core_init(void) {
fn void os_core_init(void) {
}

View File

@@ -36,7 +36,7 @@ fn f64 os_parse_float(char *str) {
return wasm_parse_float((isize)str, str_len((char *)str));
}
fn void core_init(void) {
fn void os_core_init(void) {
isize page_size = kib(64);
isize page_count = __builtin_wasm_memory_size(0);
u8 *memory = (u8 *)&__heap_base;

View File

@@ -1,5 +1,5 @@
fn void *os_vmem_reserve(usize size) {
void *result = (uint8_t *)VirtualAlloc(0, size, MEM_RESERVE, PAGE_READWRITE);
void *result = VirtualAlloc(0, size, MEM_RESERVE, PAGE_READWRITE);
return result;
}
@@ -33,5 +33,5 @@ fn f64 os_parse_float(char *str) {
return strtod(str, NULL);
}
fn void core_init(void) {
fn void os_core_init(void) {
}

View File

@@ -151,6 +151,7 @@ void test_intern_table(void) {
int main(int argc, char **argv) {
core_init();
printf("PLATFORM_WASM = %d\n", PLATFORM_WASM);
printf("PLATFORM_WINDOWS = %d\n", PLATFORM_WINDOWS);
printf("PLATFORM_LINUX = %d\n", PLATFORM_LINUX);