From ffd6bc5d230bf25957b88b37d7cfb42a57b8a26a Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 31 Dec 2022 18:02:48 +0100 Subject: [PATCH] Remove pernament arena --- base.cpp | 2 -- core_compiler.cpp | 14 +++++++------- core_main.cpp | 11 +++++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/base.cpp b/base.cpp index 96f1111..0b26fce 100644 --- a/base.cpp +++ b/base.cpp @@ -520,7 +520,6 @@ struct Thread_Ctx{ }; thread_local Thread_Ctx thread_ctx; -global Arena pernament_arena; #define REPORT_ALLOCATIONS 0 #define report_file_and_line() report__file_and_line(__FILE__, __LINE__) @@ -564,7 +563,6 @@ CORE_Static void thread_ctx_init(){ arena_init(thread_ctx.scratch, "Scratch1"_s); arena_init(thread_ctx.scratch+1, "Scratch2"_s); - arena_init(&pernament_arena, "Pernament Arena"_s); } //----------------------------------------------------------------------------- diff --git a/core_compiler.cpp b/core_compiler.cpp index 9d95529..3519dbb 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -96,10 +96,10 @@ parse_init(Parse_Ctx *ctx, Arena *perm_allocator) { } CORE_Static void -begin_compilation() { +begin_compilation(Arena *allocator) { init_ctx_time_begin = os_time(); - Parse_Ctx *ctx = allocate_struct(&pernament_arena, Parse_Ctx); - parse_init(ctx, &pernament_arena); + Parse_Ctx *ctx = allocate_struct(allocator, Parse_Ctx); + parse_init(ctx, allocator); init_ctx_time_end = os_time(); } @@ -223,9 +223,9 @@ resolve_everything_in_module(Ast_Module *module) { } CORE_Static String -compile_file_to_string(String filename) { +compile_file_to_string(Arena *arena, String filename) { total_time = os_time(); - begin_compilation(); + begin_compilation(arena); { Ast_Module *module = add_module(0, pctx->intern("Language.core"_s)); { @@ -299,12 +299,12 @@ const U32 COMPILE_AND_RUN = 0x4; const U32 COMPILE_TESTING = 0x8; CORE_Static void -compile_file(String filename, U32 compile_flags = COMPILE_NULL) { +compile_file(Arena *arena, String filename, U32 compile_flags = COMPILE_NULL) { if (is_flag_set(compile_flags, COMPILE_AND_RUN)) { log_info_no_nl("%Q - ", filename); } - String result = compile_file_to_string(filename); + String result = compile_file_to_string(arena, filename); assert(os_write_file("program.c"_s, result)); Scratch scratch; diff --git a/core_main.cpp b/core_main.cpp index 41ca13d..b1e1963 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -4,7 +4,7 @@ Fix backlog - [ ] Fix invalid error message: AlmostLinearToSRGB :: (a: Color);; return {sqrtf(a.r), sqrtf(a.g), sqrtf(a.b), a.a} - [ ] Fix untyped literal going to codegen stage, example in arms_race - [ ] Fix and decide what to do when initializing global variable using not constants C:/AProgramming/cparse/compiler/modules/Language.core:180:28: error: initializer element is not a compile-time constant -- [ ] Fix adressing void is possible, maybe make it possible to address void +- [ ] Fix adressing void is possible, mayp make it possible to address void using bytes * a.void + 10 * a.void[10] @@ -288,6 +288,9 @@ For modules it's a bit different cause they should be distributed as valid. int main(int argument_count, char **arguments){ thread_ctx_init(); + Arena arena = {}; + arena_init(&arena, "Pernament arena"_s); + Scratch scratch; Array args = {scratch}; for(int i = 1; i < argument_count; i+=1){ @@ -344,17 +347,17 @@ int main(int argument_count, char **arguments){ Array tests = os_list_dir(scratch, "tests"_s); For(examples){ if(it.is_directory) continue; - compile_file(it.absolute_path, COMPILE_AND_RUN | COMPILE_TESTING); + compile_file(&arena, it.absolute_path, COMPILE_AND_RUN | COMPILE_TESTING); } For(tests){ if(it.is_directory) continue; - compile_file(it.absolute_path, COMPILE_AND_RUN | COMPILE_TESTING); + compile_file(&arena, it.absolute_path, COMPILE_AND_RUN | COMPILE_TESTING); } } else { String program_name = string_from_cstring(arguments[1]); - compile_file(program_name, COMPILE_PRINT_STATS); + compile_file(&arena, program_name, COMPILE_PRINT_STATS); } }