diff --git a/base.cpp b/base.cpp index 5a41468..cf41056 100644 --- a/base.cpp +++ b/base.cpp @@ -475,33 +475,11 @@ operator!=(Intern_String a, Intern_String b){ #define Iter_Named(list, it) for(auto it = iterate(list); should_we_continue(&it); advance(&it)) #define Iter(list) Iter_Named(list, it) -//----------------------------------------------------------------------------- -// Base Allocator stuff -//----------------------------------------------------------------------------- -enum Allocation_Kind{ - Allocation_Alloc, - Allocation_Resize, - Allocation_FreeAll, - Allocation_Free, - Allocation_Destroy -}; - -enum Allocator_Kind{ - Allocator_None, - Allocator_Arena, - Allocator_PersonalArena, - Allocator_OSHeap, -}; - enum Alloc_Flag{ AF_None, AF_ZeroMemory }; -struct Allocator; -typedef void *Allocator_Proc(Allocator*, Allocation_Kind, void *, size_t); -struct Allocator{Allocator_Kind kind; Allocator_Proc *proc; String debug_name;}; - //----------------------------------------------------------------------------- // Memory OS //----------------------------------------------------------------------------- @@ -520,15 +498,11 @@ function B32 os_decommit_pos(OS_Memory *m, size_t pos); global const size_t default_reserve_size = gib(4); global const size_t default_alignment = 8; global const size_t additional_commit_size = mib(1); -struct Arena:Allocator{ +struct Arena{ OS_Memory memory; size_t alignment; size_t len; - - // Personal arena memes so we can compute correct size when resizing - // Also a pointer so that we can make sure it didn't change - size_t old_size; - void *debug_prev_pointer; + String debug_string; }; function void arena_init(Arena *arena, String debug_name); @@ -580,31 +554,11 @@ arena_push_size(Arena *a, size_t size, Alloc_Flag flags = AF_None){ return result; } -force_inline void * -arena_allocator_proc(Allocator *a, Allocation_Kind kind, void *old_pointer, size_t size){ - Arena *arena = (Arena *)a; - switch(kind){ - case Allocation_Alloc: return arena_push_size(arena, size); - case Allocation_Resize:{ - void *result = arena_push_size(arena, size); - memory_copy(result, old_pointer, size); - return result; - } - case Allocation_Free : return 0; - case Allocation_FreeAll: arena_clear(arena); return 0; - case Allocation_Destroy: arena_release(arena); return 0; - } - invalid_codepath; - return 0; -} - function void arena_init(Arena *a, String debug_name){ a->memory = os_reserve(default_reserve_size); a->alignment = default_alignment; - a->debug_name = debug_name; - a->kind = Allocator_Arena; - if(!a->proc) a->proc = arena_allocator_proc; + a->debug_string = debug_name; } enum Log_Kind{Log_Kind_Normal, Log_Kind_Error, Log_Kind_Trace}; @@ -615,7 +569,6 @@ typedef void Log_Proc(Log_Kind kind, String string, char *file, int line); struct Thread_Ctx{ Arena scratch[2]; Log_Proc *log_proc; - Allocator *implicit_alloc; int thread_index; int line; @@ -640,7 +593,7 @@ struct Scratch{ size_t saved_pos; Arena *arena; - Scratch(Allocator *conflict = 0){ + Scratch(Arena *conflict = 0){ if(conflict == thread_ctx.scratch){ arena = thread_ctx.scratch + 1; } @@ -653,7 +606,6 @@ struct Scratch{ arena_pop_pos(arena, saved_pos); } force_inline operator Arena*(){ return arena; } - force_inline operator Allocator*(){ return arena; } // @Note: Disable copy constructors, cause it caused lots of confusing errors // Where it passed scratch instead of the arena into the constructor @@ -663,78 +615,6 @@ struct Scratch{ Scratch(Scratch &arena, Scratch &a2); }; -#define Set_Allocator(a) Scoped_Allocator JOIN(scoped_alloc, __LINE__)(a) -struct Scoped_Allocator{ - Allocator *prev_allocator; - Scoped_Allocator(Allocator *a){ - prev_allocator = thread_ctx.implicit_alloc; - thread_ctx.implicit_alloc = a; - } - ~Scoped_Allocator(){ - thread_ctx.implicit_alloc = prev_allocator; - } -}; - -//----------------------------------------------------------------------------- -// Explicit allocator -//----------------------------------------------------------------------------- -#define exp_alloc_array(a, T, size,...) (T *)exp_alloc(a, sizeof(T)*(size),##__VA_ARGS__) -#define exp_alloc_type(a, T, ...) exp_alloc_array(a, T, 1,##__VA_ARGS__) -#define exp_alloc(a, size, ...) (report_file_and_line(), exp__alloc(a, size,##__VA_ARGS__)) -#define exp_resize(a,p,size) (report_file_and_line(), exp__resize(a, p, size)) -#define exp_resize_array(a, p, T, size) (report_file_and_line(), (T *)exp_resize(a, p, sizeof(T)*(size))) -#define exp_free(a, p) (report_file_and_line(), exp__free(a, p)) -#define exp_free_all(a) (report_file_and_line(), exp__free_all(a)) -#define exp_destroy(a) (report_file_and_line(), exp__destroy(a)) - -force_inline void * -exp__alloc(Allocator *a, size_t size, Alloc_Flag flag = AF_None){ - #if REPORT_ALLOCATIONS - printf("Alloc(%s) %s:%d %u\n", a->debug_name.str, thread_ctx.file, thread_ctx.line, (U32)size); - #endif - - void *result = a->proc(a, Allocation_Alloc, 0, size); - if(flag & AF_ZeroMemory) memory_zero(result, size); - return result; -} -force_inline void * -exp__resize(Allocator *a, void *pointer, size_t size){ - #if REPORT_ALLOCATIONS - printf("Resize(%s) %s:%d %u\n", a->debug_name.str, thread_ctx.file, thread_ctx.line, (U32)size); - #endif - - return a->proc(a, Allocation_Resize, pointer, size); -} -force_inline void -exp__free(Allocator *a, void *pointer){ - #if REPORT_ALLOCATIONS - printf("Free(%s) %s:%d\n", a->debug_name.str, thread_ctx.file, thread_ctx.line); - #endif - - a->proc(a, Allocation_Free, pointer, 0); -} -force_inline void -exp__free_all(Allocator *a){ - #if REPORT_ALLOCATIONS - printf("FreeAll(%s) %s:%d\n", a->debug_name.str, thread_ctx.file, thread_ctx.line); - #endif - - a->proc(a, Allocation_FreeAll, 0, 0); -} -force_inline void -exp__destroy(Allocator *a){ - #if REPORT_ALLOCATIONS - printf("Destroy(%s) %s:%d\n", a->debug_name.str, thread_ctx.file, thread_ctx.line); - #endif - - a->proc(a, Allocation_Destroy, 0, 0); -} -force_inline Allocator * -imp_get(){ - assert(thread_ctx.implicit_alloc); - return thread_ctx.implicit_alloc; -} - function void thread_ctx_init(){ arena_init(thread_ctx.scratch, "Scratch1"_s); @@ -742,13 +622,12 @@ thread_ctx_init(){ arena_init(&pernament_arena, "Pernament Arena"_s); } - //----------------------------------------------------------------------------- // Array //----------------------------------------------------------------------------- template struct Array{ - Allocator *allocator; + Arena *allocator; T *data; S64 cap; S64 len; @@ -768,14 +647,15 @@ struct Array{ void grow(S64 required_size){ if(cap == 0){ - if(!allocator) allocator = imp_get(); S64 new_cap = max(required_size*2, (S64)16); - data = exp_alloc_array(allocator, T, new_cap); + data = arena_push_array(allocator, T, new_cap); cap = new_cap; } else if(len + required_size > cap){ U64 new_cap = max(cap * 2, len+required_size+1); - data = exp_resize_array(allocator, data, T, new_cap); + T *new_data = arena_push_array(allocator, T, new_cap); + memory_copy(new_data, data, cap*sizeof(T)); + data = new_data; cap = new_cap; } } @@ -810,28 +690,28 @@ struct Array{ *item = data[--len]; } - void init(Allocator *a, S64 size = 16){ + void init(Arena *a, S64 size = 16){ allocator = a; - data = exp_alloc_array(a, T, size); + data = arena_push_array(a, T, size); cap = size; } - Array copy(Allocator *a){ + Array copy(Arena *a){ Array result = {}; result.len = len; result.cap = len*2; result.allocator = a; - result.data = exp_alloc_array(a, T, result.cap); + result.data = arena_push_array(a, T, result.cap); memory_copy(result.data, data, sizeof(T)*result.len); return result; } - Array tight_copy(Allocator *a){ + Array tight_copy(Arena *a){ Array result = {}; result.len = len; result.cap = len; result.allocator = 0; - result.data = exp_alloc_array(a, T, len); + result.data = arena_push_array(a, T, len); memory_copy(result.data, data, sizeof(T)*len); return result; } @@ -845,7 +725,6 @@ struct Array{ force_inline T *end () { return data + len; } force_inline T &operator[](S64 i){ assert(i >= 0 && i < cap); return data[i]; } - struct Array_Iter{ Array *array; S64 i; @@ -863,7 +742,7 @@ struct Array{ template function Array -array_make(Allocator *a, S64 size = 16){ +array_make(Arena *a, S64 size = 16){ Array result = {}; result.init(a, size); return result; @@ -1088,7 +967,7 @@ intern_string(Intern_Table *t, String string){ return result; } - S64 *len_address = (S64 *)exp_alloc(t->string_allocator, string.len+1+sizeof(S64)); + S64 *len_address = (S64 *)arena_push_size(t->string_allocator, string.len+1+sizeof(S64)); *len_address = string.len; U8 *string_address = (U8 *)(len_address + 1); @@ -1113,16 +992,13 @@ test_intern_table(){ } function Arena -arena_sub(Allocator *base, size_t size, String debug_name) { +arena_sub(Arena *base, size_t size, String debug_name) { Arena result = {}; - result.memory.data = (U8 *)exp_alloc(base, size); + result.memory.data = (U8 *)arena_push_size(base, size); result.memory.commit = size; result.memory.reserve = size; result.alignment = default_alignment; result.len = 0; - result.debug_name = debug_name; - result.kind = Allocator_Arena; - if(!result.proc) result.proc = arena_allocator_proc; return result; } diff --git a/base_string.cpp b/base_string.cpp index 5afda66..bb8092e 100644 --- a/base_string.cpp +++ b/base_string.cpp @@ -84,13 +84,13 @@ string_copy(Arena *a, String string){ } function String -string_fmtv(Allocator *a, const char *str, va_list args1) { +string_fmtv(Arena *a, const char *str, va_list args1) { va_list args2; va_copy(args2, args1); S64 len = stbsp_vsnprintf(0, 0, str, args2); va_end(args2); - char *result = exp_alloc_array(a, char, len + 1); + char *result = arena_push_array(a, char, len + 1); stbsp_vsnprintf(result, len + 1, str, args1); String res = {(U8 *)result, len}; @@ -104,7 +104,7 @@ String result = string_fmtv(alloc, str, args1); \ va_end(args1) function String -string_fmt(Allocator *a, const char *str, ...) { +string_fmt(Arena *a, const char *str, ...) { STRING_FMT(a, str, result); return result; } @@ -120,7 +120,7 @@ struct String_Builder_Block{ }; struct String_Builder{ - Allocator *allocator; + Arena *allocator; String_Builder_Block *first_free; String_Builder_Block *first; String_Builder_Block *last; @@ -147,7 +147,7 @@ struct String_Builder{ block = first_free; first_free = first_free->next; } else{ - block = (String_Builder_Block *)exp_alloc(allocator, sizeof(String_Builder_Block) + size); + block = (String_Builder_Block *)arena_push_size(allocator, sizeof(String_Builder_Block) + size); } memory_zero(block, sizeof(String_Builder_Block)+1); // Also clear first byte of character data block->cap = size; @@ -203,7 +203,7 @@ struct String_Builder{ }; function String_Builder -string_builder_make(Allocator *a, S64 first_block_size = 4096){ +string_builder_make(Arena *a, S64 first_block_size = 4096){ String_Builder sb = {a}; sb.init(first_block_size); return sb; @@ -215,7 +215,7 @@ enum String_Builder_Flag{ }; function String -string_flatten(Allocator *a, String_Builder *b, String_Builder_Flag flags = String_Builder_Flag_None){ +string_flatten(Arena *a, String_Builder *b, String_Builder_Flag flags = String_Builder_Flag_None){ // @Note(Krzosa): Compute size to allocate S64 size = 1; if(is_flag_set(flags, String_Builder_Flag_AddSize)) size += sizeof(size_t); @@ -224,7 +224,7 @@ string_flatten(Allocator *a, String_Builder *b, String_Builder_Flag flags = Stri } String result = {}; - result.str = (U8 *)exp_alloc(a, size); + result.str = (U8 *)arena_push_size(a, size); if(is_flag_set(flags, String_Builder_Flag_AddSize)) { memory_copy(result.str + result.len, &size, sizeof(S64)); result.len += sizeof(S64); diff --git a/base_unicode.cpp b/base_unicode.cpp index c613c81..fa7aab1 100644 --- a/base_unicode.cpp +++ b/base_unicode.cpp @@ -159,8 +159,8 @@ utf16_to_utf32(U16 *c, S32 max_advance) { } function String32 -string16_to_string32(Allocator *allocator, String16 string){ - String32 result = {exp_alloc_array(allocator, U32, string.len+1)}; +string16_to_string32(Arena *allocator, String16 string){ + String32 result = {arena_push_array(allocator, U32, string.len+1)}; for(S64 i = 0; i < string.len;){ UTF32_Result decode = utf16_to_utf32(string.str + i, string.len - i); if(!decode.error){ @@ -175,8 +175,8 @@ string16_to_string32(Allocator *allocator, String16 string){ } function String32 -string8_to_string32(Allocator *allocator, String string){ - String32 result = {exp_alloc_array(allocator, U32, string.len+1)}; +string8_to_string32(Arena *allocator, String string){ + String32 result = {arena_push_array(allocator, U32, string.len+1)}; for(S64 i = 0; i < string.len;){ UTF32_Result decode = utf8_to_utf32(string.str + i, string.len - i); if(!decode.error){ @@ -190,8 +190,8 @@ string8_to_string32(Allocator *allocator, String string){ } function String16 -string8_to_string16(Allocator *allocator, String in){ - String16 result = {exp_alloc_array(allocator, U16, (in.len*2)+1)}; // @Note(Krzosa): Should be more then enough space +string8_to_string16(Arena *allocator, String in){ + String16 result = {arena_push_array(allocator, U16, (in.len*2)+1)}; // @Note(Krzosa): Should be more then enough space for(S64 i = 0; i < in.len;){ UTF32_Result decode = utf8_to_utf32(in.str + i, in.len - i); if(!decode.error){ @@ -212,8 +212,8 @@ string8_to_string16(Allocator *allocator, String in){ } function String -string16_to_string8(Allocator *allocator, String16 in){ - String result = {exp_alloc_array(allocator, U8, in.len*4+1)}; +string16_to_string8(Arena *allocator, String16 in){ + String result = {arena_push_array(allocator, U8, in.len*4+1)}; for(S64 i = 0; i < in.len;){ UTF32_Result decode = utf16_to_utf32(in.str + i, in.len - i); if(!decode.error){ @@ -266,8 +266,8 @@ string16_from_widechar(wchar_t *string){ } function String -string16_copy(Allocator *a, String string){ - U8 *copy = exp_alloc_array(a, U8, string.len+1); +string16_copy(Arena *a, String string){ + U8 *copy = arena_push_array(a, U8, string.len+1); memory_copy(copy, string.str, string.len); copy[string.len] = 0; return String{copy, string.len}; diff --git a/c3_big_int.cpp b/c3_big_int.cpp index 5616f40..0f636d3 100644 --- a/c3_big_int.cpp +++ b/c3_big_int.cpp @@ -3,11 +3,11 @@ // a copy of which can be found in the LICENSE file. #include -#define Set_BigInt_Allocator(x) BigInt_Allocator bigint_allocator(x) -struct BigInt_Allocator{ - Allocator *old; - BigInt_Allocator(Allocator *allocator){old = bigint_allocator; bigint_allocator = allocator;} - ~BigInt_Allocator(){bigint_allocator = old;} +#define Set_BigInt_Arena(x) BigInt_Arena bigint_allocator(x) +struct BigInt_Arena{ + Arena *old; + BigInt_Arena(Arena *allocator){old = bigint_allocator; bigint_allocator = allocator;} + ~BigInt_Arena(){bigint_allocator = old;} }; function BigInt @@ -39,7 +39,7 @@ bigint_add(const BigInt *a, const BigInt *b){ } function BigInt -bigint_copy(Allocator *allocator, BigInt *src){ +bigint_copy(Arena *allocator, BigInt *src){ BigInt dest = {}; if (src->digit_count == 0){ bigint_init_unsigned(&dest, 0); @@ -55,7 +55,7 @@ bigint_copy(Allocator *allocator, BigInt *src){ dest.digit_count = src->digit_count; count_bigint_alloc(); - dest.digits = exp_alloc_array(allocator, uint64_t, dest.digit_count, AF_ZeroMemory); + dest.digits = arena_push_array(allocator, uint64_t, dest.digit_count, AF_ZeroMemory); memcpy(dest.digits, src->digits, sizeof(uint64_t) * dest.digit_count); return dest; } @@ -1925,9 +1925,9 @@ void bigint_print(BigInt *bigint, uint64_t base) } } -const char *bigint_to_error_string(Allocator *allocator, const BigInt *bigint, uint64_t base) +const char *bigint_to_error_string(Arena *allocator, const BigInt *bigint, uint64_t base) { - Set_BigInt_Allocator(allocator); + Set_BigInt_Arena(allocator); if (bigint->digit_count == 0) { return "0"; @@ -1948,7 +1948,7 @@ const char *bigint_to_error_string(Allocator *allocator, const BigInt *bigint, u return res; } size_t len = bigint->digit_count * 64; - char *start = (char *)exp_alloc(allocator, len); + char *start = (char *)arena_push_size(allocator, len); char *buf = start; BigInt digit_bi = { 0 }; @@ -1980,7 +1980,7 @@ const char *bigint_to_error_string(Allocator *allocator, const BigInt *bigint, u } // reverse - char *out = (char *)exp_alloc(allocator, buf - start + 2); + char *out = (char *)arena_push_size(allocator, buf - start + 2); char *current = out; if (bigint->is_negative) { diff --git a/c3_big_int.h b/c3_big_int.h index cdb8c7b..ce6f2e8 100644 --- a/c3_big_int.h +++ b/c3_big_int.h @@ -18,12 +18,12 @@ enum CmpRes }; #define count_bigint_alloc() (bigint_allocator != thread_ctx.scratch ? bigint_allocation_count++ : 0) -#define malloc_arena(x) (count_bigint_alloc(), exp_alloc(bigint_allocator, x, AF_ZeroMemory)) +#define malloc_arena(x) (count_bigint_alloc(), arena_push_size(bigint_allocator, x, AF_ZeroMemory)) #define ALLOC_DIGITS(_digits) (uint64_t *)((_digits) ? malloc_arena(sizeof(uint64_t) * (_digits)) : NULL) #define FATAL_ERROR(x) compiler_error(0, x) function void compiler_error(Token *token, const char *str, ...); -const char *bigint_to_error_string(Allocator *allocator, const BigInt *bigint, uint64_t base); +const char *bigint_to_error_string(Arena *allocator, const BigInt *bigint, uint64_t base); void bigint_init_unsigned(BigInt *big_int, uint64_t value); void bigint_init_signed(BigInt *big_int, int64_t value); void bigint_init_bigint(BigInt *dest, const BigInt *src); diff --git a/core_ast.cpp b/core_ast.cpp index 15c9527..6776c5a 100644 --- a/core_ast.cpp +++ b/core_ast.cpp @@ -470,7 +470,7 @@ ast_array(Token *pos, Ast_Expr *expr){ } function Ast_Scope * -begin_decl_scope(Allocator *scratch, Token *pos){ +begin_decl_scope(Arena *scratch, Token *pos){ AST_NEW(Scope, SCOPE, pos, AST_DECL); result->file = pctx->currently_parsed_file; result->module = pctx->currently_parsed_file->module; @@ -555,7 +555,7 @@ ast_type(Token *pos, Intern_String name, Ast_Type *type){ } function Ast_Scope * -ast_decl_scope(Token *pos, Allocator *allocator, Ast_File *file){ +ast_decl_scope(Token *pos, Arena *allocator, Ast_File *file){ AST_NEW(Scope, SCOPE, pos, AST_DECL); result->file = file; diff --git a/core_compiler.cpp b/core_compiler.cpp index 06c0338..9afd846 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -99,7 +99,7 @@ parse_init(Parse_Ctx *ctx, Arena *perm_allocator){ function void begin_compilation(){ init_ctx_time_begin = os_time(); - Parse_Ctx *ctx = exp_alloc_type(&pernament_arena, Parse_Ctx, AF_ZeroMemory); + Parse_Ctx *ctx = arena_push_type(&pernament_arena, Parse_Ctx, AF_ZeroMemory); parse_init(ctx, &pernament_arena); init_ctx_time_end = os_time(); } diff --git a/core_compiler.h b/core_compiler.h index ff8078f..9785da2 100644 --- a/core_compiler.h +++ b/core_compiler.h @@ -134,7 +134,7 @@ struct Lex_Stream{ }; struct Lexer{ - Allocator *arena; + Arena *arena; Lex_Stream stream; Array tokens; Intern_Table interns; diff --git a/core_globals.cpp b/core_globals.cpp index 07d7cda..7b97f25 100644 --- a/core_globals.cpp +++ b/core_globals.cpp @@ -6,7 +6,7 @@ global String single_header_library_name = ""_s; thread_local Parse_Ctx *pctx; -Allocator *bigint_allocator; +Arena *bigint_allocator; global S64 bigint_allocation_count; global Token token_null = {SAME_SCOPE}; diff --git a/core_lexing.cpp b/core_lexing.cpp index e867a4a..53cfcdb 100644 --- a/core_lexing.cpp +++ b/core_lexing.cpp @@ -81,7 +81,7 @@ token_error(Token *t, String error_val){ function void lex_parse_u64(Lexer *lexer, Token *t, S64 base){ Scratch scratch; - Set_BigInt_Allocator(scratch); + Set_BigInt_Arena(scratch); t->kind = TK_Integer; BigInt m = bigint_u64(1); diff --git a/core_main.cpp b/core_main.cpp index a181683..b0d69f4 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -14,6 +14,7 @@ Current: Memory: - [ ] Redesign Type map to use List and reduce wasting space - [ ] Redesign lexing to minimize memory usage, we got rid of heap but in a naive way! +- [ ] Probably need to move all the global data into the context if we want to use this as library In the future diff --git a/core_typechecking.h b/core_typechecking.h index 293b789..e09713c 100644 --- a/core_typechecking.h +++ b/core_typechecking.h @@ -43,6 +43,6 @@ enum{ function Operand resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context, Ast_Scope *field_access_scope); function void resolve_decl(Ast_Decl *ast); function Ast_Decl *resolve_name(Ast_Scope *parent_scope, Token *pos, Intern_String name, Search_Flag search_flags = 0); -function String gen_string_simple_decl(Allocator *a, Ast_Type *ast, String name = {}, Ast_Scope *scope = 0, bool scope_names = true); +function String gen_string_simple_decl(Arena *a, Ast_Type *ast, String name = {}, Ast_Scope *scope = 0, bool scope_names = true); #define CASE(kind,type) case AST_##kind: { Ast_##type *node = (Ast_##type *)ast; #define BREAK() } break diff --git a/core_types.cpp b/core_types.cpp index 8983b0f..0b95713 100644 --- a/core_types.cpp +++ b/core_types.cpp @@ -58,8 +58,8 @@ force_inline B32 is_numeric(Ast_Type *type){ // Hash consed types //----------------------------------------------------------------------------- function Ast_Type * -type_new(Allocator *allocator, Ast_Type_Kind kind, size_t size, size_t align){ - Ast_Type *result = exp_alloc_type(allocator, Ast_Type, AF_ZeroMemory); +type_new(Arena *allocator, Ast_Type_Kind kind, size_t size, size_t align){ + Ast_Type *result = arena_push_type(allocator, Ast_Type, AF_ZeroMemory); result->kind = kind; result->size = size; result->align = align; @@ -69,9 +69,9 @@ type_new(Allocator *allocator, Ast_Type_Kind kind, size_t size, size_t align){ } function Ast_Type * -type_copy(Allocator *a, Ast_Type *type){ +type_copy(Arena *a, Ast_Type *type){ // @warning: This changes type id !!!! - Ast_Type *result = exp_alloc_type(a, Ast_Type); + Ast_Type *result = arena_push_type(a, Ast_Type); memory_copy(result, type, sizeof(Ast_Type)); result->type_id = pctx->type_ids++; add(pctx->perm, &pctx->all_types, result); @@ -322,7 +322,7 @@ typename_base(String_Builder *sb, Ast_Type *type){ } function String -get_typename(Allocator *a, Ast_Type *type){ +get_typename(Arena *a, Ast_Type *type){ pctx->helper_builder.addf("["); typename_base(&pctx->helper_builder, type); pctx->helper_builder.addf("]"); diff --git a/os_windows.cpp b/os_windows.cpp index a854053..f13935b 100644 --- a/os_windows.cpp +++ b/os_windows.cpp @@ -115,14 +115,14 @@ os_write_file(String filename, String filecontent){ } function String -os_read_file(Allocator *a, String name){ +os_read_file(Arena *a, String name){ String result = {0}; FILE *f = fopen((char *)name.str, "rb"); if(f){ fseek(f, 0, SEEK_END); result.len = ftell(f); fseek(f, 0, SEEK_SET); - result.str = (U8 *)exp_alloc(a, result.len + 1); + result.str = (U8 *)arena_push_size(a, result.len + 1); fread(result.str, result.len, 1, f); fclose(f); result.str[result.len] = 0; @@ -132,7 +132,7 @@ os_read_file(Allocator *a, String name){ } function String -os_get_working_dir(Allocator *a){ +os_get_working_dir(Arena *a){ wchar_t buffer[2048]; DWORD written = GetCurrentDirectoryW(2048, buffer); assert(written != 0); @@ -143,7 +143,7 @@ os_get_working_dir(Allocator *a){ } function String -os_get_exe_dir(Allocator *a){ +os_get_exe_dir(Arena *a){ wchar_t buffer[2048]; DWORD written = GetModuleFileNameW(0, buffer, 2048); assert(written != 0); @@ -158,11 +158,11 @@ os_get_exe_dir(Allocator *a){ } function String -os_get_absolute_path(Allocator *a, String path){ +os_get_absolute_path(Arena *a, String path){ Scratch scratch(a); String16 path16 = string8_to_string16(scratch, path); - wchar_t *buffer = exp_alloc_array(scratch, wchar_t, 2048); + wchar_t *buffer = arena_push_array(scratch, wchar_t, 2048); DWORD written = GetFullPathNameW((wchar_t *)path16.str, 2048, buffer, 0); if(written == 0) return {};