Update lottes hybrid

This commit is contained in:
2025-11-05 20:43:42 -05:00
parent a7d17a8b70
commit 3bb46692e1
4 changed files with 414 additions and 411 deletions

View File

@@ -185,7 +185,7 @@ typedef def_struct(Slice_Str8) { Str8* ptr; U8 len; };
debug_trap(); \ debug_trap(); \
} \ } \
} while(0) } while(0)
void assert_handler(UTF8*R_ condition, UTF8*R_ file, UTF8*R_ function, S4 line, UTF8*R_ msg, ... ); internal void assert_handler(UTF8*R_ condition, UTF8*R_ file, UTF8*R_ function, S4 line, UTF8*R_ msg, ... );
#else #else
#define debug_trap() #define debug_trap()
#define assert_trap(cond) #define assert_trap(cond)
@@ -406,12 +406,12 @@ typedef def_struct(FArena) {
}; };
finline FArena farena_make (Slice_Mem mem); finline FArena farena_make (Slice_Mem mem);
finline void farena_init (FArena_R arena, Slice_Mem byte); finline void farena_init (FArena_R arena, Slice_Mem byte);
Slice_Mem farena__push (FArena_R arena, U8 amount, U8 type_width, Opts_farena*R_ opts); internal Slice_Mem farena__push (FArena_R arena, U8 amount, U8 type_width, Opts_farena*R_ opts);
finline void farena_reset (FArena_R arena); finline void farena_reset (FArena_R arena);
finline void farena_rewind(FArena_R arena, AllocatorSP save_point); finline void farena_rewind(FArena_R arena, AllocatorSP save_point);
finline AllocatorSP farena_save (FArena arena); finline AllocatorSP farena_save (FArena arena);
void farena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out_R out); internal void farena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out_R out);
#define ainfo_farena(arena) (AllocatorInfo){ .proc = farena_allocator_proc, .data = u8_(& arena) } #define ainfo_farena(arena) (AllocatorInfo){ .proc = farena_allocator_proc, .data = u8_(& arena) }
#define farena_push_mem(arena, amount, ...) farena__push(arena, amount, 1, opt_args(Opts_farena, lit(stringify(B1)), __VA_ARGS__)) #define farena_push_mem(arena, amount, ...) farena__push(arena, amount, 1, opt_args(Opts_farena, lit(stringify(B1)), __VA_ARGS__))
@@ -435,7 +435,7 @@ typedef def_struct(Opts_vmem) {
B4 no_large_pages; B4 no_large_pages;
A4_B1 _PAD_; A4_B1 _PAD_;
}; };
void os_init(void); internal void os_init (void);
finline OS_SystemInfo* os_system_info(void); finline OS_SystemInfo* os_system_info(void);
finline B4 os__vmem_commit (U8 vm, U8 size, Opts_vmem*R_ opts); finline B4 os__vmem_commit (U8 vm, U8 size, Opts_vmem*R_ opts);
@@ -467,17 +467,17 @@ typedef def_struct(Opts_varena_make) {
VArenaFlags flags; VArenaFlags flags;
A4_B1 _PAD_; A4_B1 _PAD_;
}; };
VArena* varena__make(Opts_varena_make*R_ opts); internal VArena* varena__make(Opts_varena_make*R_ opts);
#define varena_make(...) varena__make(opt_args(Opts_varena_make, __VA_ARGS__)) #define varena_make(...) varena__make(opt_args(Opts_varena_make, __VA_ARGS__))
Slice_Mem varena__push (VArena_R arena, U8 amount, U8 type_width, Opts_varena*R_ opts); internal Slice_Mem varena__push (VArena_R arena, U8 amount, U8 type_width, Opts_varena*R_ opts);
finline void varena_release(VArena_R arena); finline void varena_release(VArena_R arena);
finline void varena_rewind (VArena_R arena, AllocatorSP save_point); finline void varena_rewind (VArena_R arena, AllocatorSP save_point);
void varena_reset (VArena_R arena); internal void varena_reset (VArena_R arena);
Slice_Mem varena__shrink(VArena_R arena, Slice_Mem old_allocation, U8 requested_size); internal Slice_Mem varena__shrink(VArena_R arena, Slice_Mem old_allocation, U8 requested_size);
finline AllocatorSP varena_save (VArena_R arena); finline AllocatorSP varena_save (VArena_R arena);
void varena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out_R out); internal void varena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out_R out);
#define ainfo_varena(varena) (AllocatorInfo) { .proc = & varena_allocator_proc, .data = u8_(varena) } #define ainfo_varena(varena) (AllocatorInfo) { .proc = & varena_allocator_proc, .data = u8_(varena) }
#define varena_push_mem(arena, amount, ...) varena__push(arena, amount, 1, opt_args(Opts_varena, lit(stringify(B1)), __VA_ARGS__)) #define varena_push_mem(arena, amount, ...) varena__push(arena, amount, 1, opt_args(Opts_varena, lit(stringify(B1)), __VA_ARGS__))
@@ -505,14 +505,14 @@ typedef def_struct(Arena) {
A4_B1 _PAD_; A4_B1 _PAD_;
}; };
typedef Opts_varena_make Opts_arena_make; typedef Opts_varena_make Opts_arena_make;
Arena* arena__make (Opts_arena_make*R_ opts); internal Arena* arena__make (Opts_arena_make*R_ opts);
Slice_Mem arena__push (Arena_R arena, U8 amount, U8 type_width, Opts_arena*R_ opts); internal Slice_Mem arena__push (Arena_R arena, U8 amount, U8 type_width, Opts_arena*R_ opts);
finline void arena_release(Arena_R arena); finline void arena_release(Arena_R arena);
finline void arena_reset (Arena_R arena); finline void arena_reset (Arena_R arena);
void arena_rewind (Arena_R arena, AllocatorSP save_point); internal void arena_rewind (Arena_R arena, AllocatorSP save_point);
finline AllocatorSP arena_save (Arena_R arena); finline AllocatorSP arena_save (Arena_R arena);
void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out_R out); internal void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out_R out);
#define ainfo_arena(arena) (AllocatorInfo){ .proc = & arena_allocator_proc, .data = u8_(arena) } #define ainfo_arena(arena) (AllocatorInfo){ .proc = & arena_allocator_proc, .data = u8_(arena) }
#define arena_make(...) arena__make(opt_args(Opts_arena_make, __VA_ARGS__)) #define arena_make(...) arena__make(opt_args(Opts_arena_make, __VA_ARGS__))
@@ -568,7 +568,7 @@ typedef def_farray(Str8, 2);
typedef def_Slice(A2_Str8); typedef def_Slice(A2_Str8);
typedef def_KTL_Slot(Str8); typedef def_KTL_Slot(Str8);
typedef def_KTL(Str8); typedef def_KTL(Str8);
void ktl_populate_slice_a2_str8(KTL_Str8*R_ kt, AllocatorInfo backing, Slice_A2_Str8 values); finline void ktl_populate_slice_a2_str8(KTL_Str8*R_ kt, AllocatorInfo backing, Slice_A2_Str8 values);
#pragma endregion KTL #pragma endregion KTL
#pragma region Key Table 1-Layer Chained-Chunked-Cells (KT1CX) #pragma region Key Table 1-Layer Chained-Chunked-Cells (KT1CX)
@@ -623,11 +623,11 @@ typedef def_struct(KT1CX_Info) {
AllocatorInfo backing_table; AllocatorInfo backing_table;
AllocatorInfo backing_cells; AllocatorInfo backing_cells;
}; };
void kt1cx_init (KT1CX_Info info, KT1CX_InfoMeta m, KT1CX_Byte*R_ result); internal void kt1cx_init (KT1CX_Info info, KT1CX_InfoMeta m, KT1CX_Byte*R_ result);
void kt1cx_clear (KT1CX_Byte kt, KT1CX_ByteMeta meta); internal void kt1cx_clear (KT1CX_Byte kt, KT1CX_ByteMeta meta);
finline U8 kt1cx_slot_id(KT1CX_Byte kt, U8 key, KT1CX_ByteMeta meta); finline U8 kt1cx_slot_id(KT1CX_Byte kt, U8 key, KT1CX_ByteMeta meta);
U8 kt1cx_get (KT1CX_Byte kt, U8 key, KT1CX_ByteMeta meta); internal U8 kt1cx_get (KT1CX_Byte kt, U8 key, KT1CX_ByteMeta meta);
U8 kt1cx_set (KT1CX_Byte kt, U8 key, Slice_Mem value, AllocatorInfo backing_cells, KT1CX_ByteMeta meta); internal U8 kt1cx_set (KT1CX_Byte kt, U8 key, Slice_Mem value, AllocatorInfo backing_cells, KT1CX_ByteMeta meta);
#define kt1cx_assert(kt) do { \ #define kt1cx_assert(kt) do { \
slice_assert(kt.table); \ slice_assert(kt.table); \
@@ -643,13 +643,13 @@ finline U1 integer_symbols(U1 value) {
} }
finline char* str8_to_cstr_capped(Str8 content, Slice_Mem mem); finline char* str8_to_cstr_capped(Str8 content, Slice_Mem mem);
Str8 str8_from_u32(AllocatorInfo ainfo, U4 num, U4 radix, U4 min_digits, U4 digit_group_separator); internal Str8 str8_from_u32(AllocatorInfo ainfo, U4 num, U4 radix, U4 min_digits, U4 digit_group_separator);
finline Str8 str8__fmt_backed(AllocatorInfo tbl_backing, AllocatorInfo buf_backing, Str8 fmt_template, Slice_A2_Str8*R_ entries); finline Str8 str8__fmt_backed(AllocatorInfo tbl_backing, AllocatorInfo buf_backing, Str8 fmt_template, Slice_A2_Str8*R_ entries);
#define str8_fmt_backed(tbl_backing, buf_backing, fmt_template, ...) \ #define str8_fmt_backed(tbl_backing, buf_backing, fmt_template, ...) \
str8__fmt_backed(tbl_backing, buf_backing, lit(fmt_template), slice_arg_from_array(A2_Str8, __VA_ARGS__)) str8__fmt_backed(tbl_backing, buf_backing, lit(fmt_template), slice_arg_from_array(A2_Str8, __VA_ARGS__))
Str8 str8__fmt(Str8 fmt_template, Slice_A2_Str8*R_ entries); internal Str8 str8__fmt(Str8 fmt_template, Slice_A2_Str8*R_ entries);
#define str8_fmt(fmt_template, ...) str8__fmt(lit(fmt_template), slice_arg_from_array(A2_Str8, __VA_ARGS__)) #define str8_fmt(fmt_template, ...) str8__fmt(lit(fmt_template), slice_arg_from_array(A2_Str8, __VA_ARGS__))
#define Str8Cache_CELL_DEPTH 4 #define Str8Cache_CELL_DEPTH 4
@@ -672,7 +672,7 @@ typedef def_struct(Opts_str8cache_init) {
U8 cell_pool_size; U8 cell_pool_size;
U8 table_size; U8 table_size;
}; };
void str8cache__init(Str8Cache_R cache, Opts_str8cache_init*R_ opts); internal void str8cache__init(Str8Cache_R cache, Opts_str8cache_init*R_ opts);
finline Str8Cache str8cache__make( Opts_str8cache_init*R_ opts); finline Str8Cache str8cache__make( Opts_str8cache_init*R_ opts);
#define str8cache_init(cache, ...) str8cache__init(cache, opt_args(Opts_str8cache_init, __VA_ARGS__)) #define str8cache_init(cache, ...) str8cache__init(cache, opt_args(Opts_str8cache_init, __VA_ARGS__))
@@ -698,7 +698,7 @@ finline Str8Gen str8gen_make( AllocatorInfo backing);
finline Str8 str8_from_str8gen(Str8Gen gen) { return (Str8){ cast(UTF8_R, gen.ptr), gen.len}; } finline Str8 str8_from_str8gen(Str8Gen gen) { return (Str8){ cast(UTF8_R, gen.ptr), gen.len}; }
finline void str8gen_append_str8(Str8Gen_R gen, Str8 str); finline void str8gen_append_str8(Str8Gen_R gen, Str8 str);
void str8gen__append_fmt(Str8Gen_R gen, Str8 fmt_template, Slice_A2_Str8*R_ tokens); internal void str8gen__append_fmt(Str8Gen_R gen, Str8 fmt_template, Slice_A2_Str8*R_ tokens);
#define str8gen_append_fmt(gen, fmt_template, ...) str8gen__append_fmt(gen, lit(fmt_template), slice_arg_from_array(A2_Str8, __VA_ARGS__)) #define str8gen_append_fmt(gen, fmt_template, ...) str8gen__append_fmt(gen, lit(fmt_template), slice_arg_from_array(A2_Str8, __VA_ARGS__))
#pragma endregion String Operations #pragma endregion String Operations
@@ -712,8 +712,8 @@ typedef def_struct(Opts_read_file_contents) {
B4 zero_backing; B4 zero_backing;
A4_B1 _PAD_; A4_B1 _PAD_;
}; };
void api_file_read_contents(FileOpInfo_R result, Str8 path, Opts_read_file_contents opts); internal void api_file_read_contents(FileOpInfo_R result, Str8 path, Opts_read_file_contents opts);
void file_write_str8 (Str8 path, Str8 content); internal void file_write_str8 (Str8 path, Str8 content);
finline FileOpInfo file__read_contents(Str8 path, Opts_read_file_contents*R_ opts); finline FileOpInfo file__read_contents(Str8 path, Opts_read_file_contents*R_ opts);
#define file_read_contents(path, ...) file__read_contents(path, opt_args(Opts_read_file_contents, __VA_ARGS__)) #define file_read_contents(path, ...) file__read_contents(path, opt_args(Opts_read_file_contents, __VA_ARGS__))
@@ -756,8 +756,8 @@ typedef def_struct(Opts_watl_lex) {
B1 failon_slice_constraint_fail; B1 failon_slice_constraint_fail;
A4_B1 _PAD_; A4_B1 _PAD_;
}; };
void api_watl_lex(WATL_LexInfo_R info, Str8 source, Opts_watl_lex*R_ opts); internal void api_watl_lex(WATL_LexInfo_R info, Str8 source, Opts_watl_lex*R_ opts);
WATL_LexInfo watl__lex ( Str8 source, Opts_watl_lex*R_ opts); finline WATL_LexInfo watl__lex ( Str8 source, Opts_watl_lex*R_ opts);
#define watl_lex(source, ...) watl__lex(source, opt_args(Opts_watl_lex, __VA_ARGS__)) #define watl_lex(source, ...) watl__lex(source, opt_args(Opts_watl_lex, __VA_ARGS__))
typedef Str8 WATL_Node; typedef def_ptr_set(WATL_Node); typedef Str8 WATL_Node; typedef def_ptr_set(WATL_Node);
@@ -788,11 +788,11 @@ typedef def_struct(Opts_watl_parse) {
B4 failon_slice_constraint_fail; B4 failon_slice_constraint_fail;
A4_B1 _PAD_; A4_B1 _PAD_;
}; };
void api_watl_parse(WATL_ParseInfo_R info, Slice_WATL_Tok tokens, Opts_watl_parse*R_ opts); internal void api_watl_parse(WATL_ParseInfo_R info, Slice_WATL_Tok tokens, Opts_watl_parse*R_ opts);
WATL_ParseInfo watl__parse ( Slice_WATL_Tok tokens, Opts_watl_parse*R_ opts); finline WATL_ParseInfo watl__parse ( Slice_WATL_Tok tokens, Opts_watl_parse*R_ opts);
#define watl_parse(tokens, ...) watl__parse(tokens, opt_args(Opts_watl_parse, __VA_ARGS__)) #define watl_parse(tokens, ...) watl__parse(tokens, opt_args(Opts_watl_parse, __VA_ARGS__))
Str8 watl_dump_listing(AllocatorInfo buffer, Slice_WATL_Line lines); internal Str8 watl_dump_listing(AllocatorInfo buffer, Slice_WATL_Line lines);
#pragma endregion WATL #pragma endregion WATL
#pragma endregion Header #pragma endregion Header
@@ -824,8 +824,7 @@ void mem_rewind(AllocatorInfo ainfo, AllocatorSP save_point) {
finline finline
AllocatorSP mem_save_point(AllocatorInfo ainfo) { AllocatorSP mem_save_point(AllocatorInfo ainfo) {
assert(ainfo.proc != nullptr); assert(ainfo.proc != nullptr);
AllocatorProc_Out out; AllocatorProc_Out out; ainfo.proc((AllocatorProc_In){.data = ainfo.data, .op = AllocatorOp_SavePoint}, & out);
ainfo.proc((AllocatorProc_In){.data = ainfo.data, .op = AllocatorOp_SavePoint}, & out);
return out.save_point; return out.save_point;
} }
finline finline
@@ -838,8 +837,7 @@ Slice_Mem mem__alloc(AllocatorInfo ainfo, U8 size, Opts_mem_alloc*R_ opts) {
.requested_size = size, .requested_size = size,
.alignment = opts->alignment, .alignment = opts->alignment,
}; };
AllocatorProc_Out out; AllocatorProc_Out out; ainfo.proc(in, & out);
ainfo.proc(in, & out);
return out.allocation; return out.allocation;
} }
finline finline
@@ -853,8 +851,7 @@ Slice_Mem mem__grow(AllocatorInfo ainfo, Slice_Mem mem, U8 size, Opts_mem_grow*R
.alignment = opts->alignment, .alignment = opts->alignment,
.old_allocation = mem .old_allocation = mem
}; };
AllocatorProc_Out out; AllocatorProc_Out out; ainfo.proc(in, & out);
ainfo.proc(in, & out);
return (Slice_Mem){ out.allocation.ptr, opts->give_actual ? out.allocation.len : in.requested_size }; return (Slice_Mem){ out.allocation.ptr, opts->give_actual ? out.allocation.len : in.requested_size };
} }
finline finline
@@ -868,8 +865,7 @@ Slice_Mem mem__resize(AllocatorInfo ainfo, Slice_Mem mem, U8 size, Opts_mem_resi
.alignment = opts->alignment, .alignment = opts->alignment,
.old_allocation = mem, .old_allocation = mem,
}; };
AllocatorProc_Out out; AllocatorProc_Out out; ainfo.proc(in, & out);
ainfo.proc(in, & out);
return (Slice_Mem){ out.allocation.ptr, opts->give_actual ? out.allocation.len : in.requested_size }; return (Slice_Mem){ out.allocation.ptr, opts->give_actual ? out.allocation.len : in.requested_size };
} }
finline finline
@@ -883,8 +879,7 @@ Slice_Mem mem__shrink(AllocatorInfo ainfo, Slice_Mem mem, U8 size, Opts_mem_shri
.alignment = opts->alignment, .alignment = opts->alignment,
.old_allocation = mem .old_allocation = mem
}; };
AllocatorProc_Out out; AllocatorProc_Out out; ainfo.proc(in, & out);
ainfo.proc(in, & out);
return out.allocation; return out.allocation;
} }
#pragma endregion Allocator Interface #pragma endregion Allocator Interface
@@ -898,7 +893,7 @@ void farena_init(FArena_R arena, Slice_Mem mem) {
arena->used = 0; arena->used = 0;
} }
finline FArena farena_make(Slice_Mem mem) { FArena a; farena_init(& a, mem); return a; } finline FArena farena_make(Slice_Mem mem) { FArena a; farena_init(& a, mem); return a; }
inline internal inline
Slice_Mem farena__push(FArena_R arena, U8 amount, U8 type_width, Opts_farena*R_ opts) { Slice_Mem farena__push(FArena_R arena, U8 amount, U8 type_width, Opts_farena*R_ opts) {
assert(opts != nullptr); assert(opts != nullptr);
if (amount == 0) { return (Slice_Mem){}; } if (amount == 0) { return (Slice_Mem){}; }
@@ -909,7 +904,7 @@ Slice_Mem farena__push(FArena_R arena, U8 amount, U8 type_width, Opts_farena*R_
arena->used += to_commit; arena->used += to_commit;
return (Slice_Mem){ptr, desired}; return (Slice_Mem){ptr, desired};
} }
inline internal inline
Slice_Mem farena__grow(FArena_R arena, Slice_Mem old_allocation, U8 requested_size, U8 alignment, B4 should_zero) { Slice_Mem farena__grow(FArena_R arena, Slice_Mem old_allocation, U8 requested_size, U8 alignment, B4 should_zero) {
// Check if the allocation is at the end of the arena // Check if the allocation is at the end of the arena
U8 alloc_end = old_allocation.ptr + old_allocation.len; U8 alloc_end = old_allocation.ptr + old_allocation.len;
@@ -927,11 +922,10 @@ Slice_Mem farena__grow(FArena_R arena, Slice_Mem old_allocation, U8 requested_si
return (Slice_Mem){0}; return (Slice_Mem){0};
} }
arena->used += aligned_grow; arena->used += aligned_grow;
Slice_Mem result = (Slice_Mem){ old_allocation.ptr, aligned_grow + requested_size };
mem_zero(old_allocation.ptr + old_allocation.len, grow_amount * cast(U8, should_zero)); mem_zero(old_allocation.ptr + old_allocation.len, grow_amount * cast(U8, should_zero));
return result; return (Slice_Mem){ old_allocation.ptr, aligned_grow + requested_size };
} }
inline internal inline
Slice_Mem farena__shrink(FArena_R arena, Slice_Mem old_allocation, U8 requested_size, U8 alignment) Slice_Mem farena__shrink(FArena_R arena, Slice_Mem old_allocation, U8 requested_size, U8 alignment)
{ {
// Check if the allocation is at the end of the arena // Check if the allocation is at the end of the arena
@@ -957,6 +951,7 @@ finline
AllocatorSP farena_save (FArena arena) { AllocatorSP farena_save (FArena arena) {
return (AllocatorSP){ .type_sig = & farena_allocator_proc, .slot = arena.used }; return (AllocatorSP){ .type_sig = & farena_allocator_proc, .slot = arena.used };
} }
internal
void farena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out*R_ out) void farena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out*R_ out)
{ {
assert(out != nullptr); assert(out != nullptr);
@@ -1057,7 +1052,7 @@ typedef def_struct(OS_Windows_State) { OS_SystemInfo system_info; };
global OS_Windows_State os__windows_info; global OS_Windows_State os__windows_info;
finline OS_SystemInfo* os_system_info(void) { return & os__windows_info.system_info; } finline OS_SystemInfo* os_system_info(void) { return & os__windows_info.system_info; }
inline internal inline
void os__enable_large_pages(void) { void os__enable_large_pages(void) {
MS_HANDLE token; MS_HANDLE token;
if (OpenProcessToken(GetCurrentProcess(), MS_TOKEN_ADJUST_PRIVILEGES | MS_TOKEN_QUERY, &token)) if (OpenProcessToken(GetCurrentProcess(), MS_TOKEN_ADJUST_PRIVILEGES | MS_TOKEN_QUERY, &token))
@@ -1074,7 +1069,7 @@ void os__enable_large_pages(void) {
CloseHandle(token); CloseHandle(token);
} }
} }
inline internal inline
void os_init(void) { void os_init(void) {
os__enable_large_pages(); os__enable_large_pages();
OS_SystemInfo*R_ info = & os__windows_info.system_info; OS_SystemInfo*R_ info = & os__windows_info.system_info;
@@ -1096,12 +1091,12 @@ finline B4 os__vmem_commit(U8 vm, U8 size, Opts_vmem*R_ opts) {
B4 result = (VirtualAlloc(cast(MS_LPVOID, vm), size, MS_MEM_COMMIT, MS_PAGE_READWRITE) != 0); B4 result = (VirtualAlloc(cast(MS_LPVOID, vm), size, MS_MEM_COMMIT, MS_PAGE_READWRITE) != 0);
return result; return result;
} }
inline void os_vmem_release(U8 vm, U8 size) { VirtualFree(cast(MS_LPVOID, vm), 0, MS_MEM_RESERVE); } internal inline void os_vmem_release(U8 vm, U8 size) { VirtualFree(cast(MS_LPVOID, vm), 0, MS_MEM_RESERVE); }
#pragma endregion OS #pragma endregion OS
#pragma region VArena (Virutal Address Space Arena) #pragma region VArena (Virutal Address Space Arena)
finline U8 varena_header_size(void) { return align_pow2(size_of(VArena), MEMORY_ALIGNMENT_DEFAULT); } finline U8 varena_header_size(void) { return align_pow2(size_of(VArena), MEMORY_ALIGNMENT_DEFAULT); }
inline internal inline
VArena* varena__make(Opts_varena_make*R_ opts) { VArena* varena__make(Opts_varena_make*R_ opts) {
assert(opts != nullptr); assert(opts != nullptr);
if (opts->reserve_size == 0) { opts->reserve_size = mega(64); } if (opts->reserve_size == 0) { opts->reserve_size = mega(64); }
@@ -1123,7 +1118,7 @@ VArena* varena__make(Opts_varena_make*R_ opts) {
}; };
return vm; return vm;
} }
inline internal inline
Slice_Mem varena__push(VArena_R vm, U8 amount, U8 type_width, Opts_varena*R_ opts) { Slice_Mem varena__push(VArena_R vm, U8 amount, U8 type_width, Opts_varena*R_ opts) {
assert(vm != nullptr); assert(vm != nullptr);
assert(amount != 0); assert(amount != 0);
@@ -1146,11 +1141,11 @@ Slice_Mem varena__push(VArena_R vm, U8 amount, U8 type_width, Opts_varena*R_ opt
vm->committed += next_commit_size; vm->committed += next_commit_size;
} }
} }
vm->commit_used = to_be_used;
U8 current_offset = vm->reserve_start + vm->commit_used; U8 current_offset = vm->reserve_start + vm->commit_used;
vm->commit_used = to_be_used;
return (Slice_Mem){.ptr = current_offset, .len = requested_size}; return (Slice_Mem){.ptr = current_offset, .len = requested_size};
} }
inline internal inline
Slice_Mem varena__grow(VArena_R vm, Slice_Mem old_allocation, U8 requested_size, U8 alignment, B4 should_zero) { Slice_Mem varena__grow(VArena_R vm, Slice_Mem old_allocation, U8 requested_size, U8 alignment, B4 should_zero) {
U8 grow_amount = requested_size - old_allocation.len; U8 grow_amount = requested_size - old_allocation.len;
if (grow_amount == 0) { return old_allocation; } // Growing when not the last allocation not allowed if (grow_amount == 0) { return old_allocation; } // Growing when not the last allocation not allowed
@@ -1160,7 +1155,7 @@ Slice_Mem varena__grow(VArena_R vm, Slice_Mem old_allocation, U8 requested_size,
return (Slice_Mem){ old_allocation.ptr, old_allocation.len + allocation.len }; return (Slice_Mem){ old_allocation.ptr, old_allocation.len + allocation.len };
} }
finline void varena_release(VArena_R arena) { os_vmem_release(u8_(arena), arena->reserve); } finline void varena_release(VArena_R arena) { os_vmem_release(u8_(arena), arena->reserve); }
inline internal inline
Slice_Mem varena__shrink(VArena_R vm, Slice_Mem old_allocation, U8 requested_size) { Slice_Mem varena__shrink(VArena_R vm, Slice_Mem old_allocation, U8 requested_size) {
U8 shrink_amount = old_allocation.len - requested_size; U8 shrink_amount = old_allocation.len - requested_size;
if (lt_s(shrink_amount, 0)) { return old_allocation; } if (lt_s(shrink_amount, 0)) { return old_allocation; }
@@ -1175,6 +1170,7 @@ void varena_rewind(VArena_R vm, AllocatorSP sp) {
vm->commit_used = max(sp.slot, sizeof(VArena)); vm->commit_used = max(sp.slot, sizeof(VArena));
} }
finline AllocatorSP varena_save(VArena_R vm) { return (AllocatorSP){varena_allocator_proc, vm->commit_used}; } finline AllocatorSP varena_save(VArena_R vm) { return (AllocatorSP){varena_allocator_proc, vm->commit_used}; }
internal
void varena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out) void varena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
{ {
VArena_R vm = cast(VArena_R, in.data); VArena_R vm = cast(VArena_R, in.data);
@@ -1218,7 +1214,7 @@ void varena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
#pragma region Arena (Chained Arena) #pragma region Arena (Chained Arena)
finline U8 arena_header_size(void) { return align_pow2(size_of(Arena), MEMORY_ALIGNMENT_DEFAULT); } finline U8 arena_header_size(void) { return align_pow2(size_of(Arena), MEMORY_ALIGNMENT_DEFAULT); }
inline internal inline
Arena* arena__make(Opts_arena_make*R_ opts) { Arena* arena__make(Opts_arena_make*R_ opts) {
assert(opts != nullptr); assert(opts != nullptr);
U8 header_size = arena_header_size(); U8 header_size = arena_header_size();
@@ -1233,6 +1229,7 @@ Arena* arena__make(Opts_arena_make*R_ opts) {
}; };
return arena; return arena;
} }
internal inline
Slice_Mem arena__push(Arena_R arena, U8 amount, U8 type_width, Opts_arena* opts) { Slice_Mem arena__push(Arena_R arena, U8 amount, U8 type_width, Opts_arena* opts) {
assert(arena != nullptr); assert(arena != nullptr);
assert(opts != nullptr); assert(opts != nullptr);
@@ -1264,6 +1261,50 @@ Slice_Mem arena__push(Arena_R arena, U8 amount, U8 type_width, Opts_arena* opts)
active->pos = pos_pst; active->pos = pos_pst;
return vresult; return vresult;
} }
internal inline
Slice_Mem arena__grow(Arena_R arena, Slice_Mem old_allocation, U8 requested_size, U8 alignment, B4 should_zero) {
Arena_R active = arena->current;
U8 alloc_end = old_allocation.ptr + old_allocation.len;
U8 arena_end = u8_(active) + active->pos;
if (alloc_end == arena_end)
{
U8 grow_amount = requested_size - old_allocation.len;
U8 aligned_grow = align_pow2(grow_amount, alignment ? alignment : MEMORY_ALIGNMENT_DEFAULT);
if (active->pos + aligned_grow <= active->backing->reserve)
{
Slice_Mem vresult = varena_push_mem(active->backing, aligned_grow, .alignment = alignment);
if (vresult.ptr != null)
{
active->pos += aligned_grow;
mem_zero(old_allocation.ptr + old_allocation.len, grow_amount * (U8)should_zero);
return (Slice_Mem){old_allocation.ptr, aligned_grow + old_allocation.len};
}
}
}
#pragma diagnostic push
#pragma clang diagnostic ignored "-Wnrvo"
Slice_Mem new_alloc = arena__push(arena, requested_size, 1, &(Opts_arena){.alignment = alignment});
if (new_alloc.ptr == null) { return (Slice_Mem){0}; }
mem_copy(new_alloc.ptr, old_allocation.ptr, old_allocation.len);
mem_zero(new_alloc.ptr + old_allocation.len, (requested_size - old_allocation.len) * (U8)should_zero);
return new_alloc;
#pragma diagnostic pop
}
internal inline
Slice_Mem arena__shrink(Arena_R arena, Slice_Mem old_allocation, U8 requested_size, U8 alignment) {
Arena_R active = arena->current;
U8 alloc_end = old_allocation.ptr + old_allocation.len;
U8 arena_end = u8_(active) + active->pos;
if (alloc_end != arena_end) {
return (Slice_Mem){old_allocation.ptr, requested_size};
}
U8 aligned_original = align_pow2(old_allocation.len, MEMORY_ALIGNMENT_DEFAULT);
U8 aligned_new = align_pow2(requested_size, alignment ? alignment : MEMORY_ALIGNMENT_DEFAULT);
U8 pos_reduction = aligned_original - aligned_new;
active->pos -= pos_reduction;
varena__shrink(active->backing, old_allocation, requested_size);
return (Slice_Mem){old_allocation.ptr, requested_size};
}
finline finline
void arena_release(Arena_R arena) { void arena_release(Arena_R arena) {
assert(arena != nullptr); assert(arena != nullptr);
@@ -1275,6 +1316,7 @@ void arena_release(Arena_R arena) {
} }
} }
finline void arena_reset(Arena_R arena) { arena_rewind(arena, (AllocatorSP){.type_sig = arena_allocator_proc, .slot = 0}); } finline void arena_reset(Arena_R arena) { arena_rewind(arena, (AllocatorSP){.type_sig = arena_allocator_proc, .slot = 0}); }
internal inline
void arena_rewind(Arena_R arena, AllocatorSP save_point) { void arena_rewind(Arena_R arena, AllocatorSP save_point) {
assert(arena != nullptr); assert(arena != nullptr);
assert(save_point.type_sig == arena_allocator_proc); assert(save_point.type_sig == arena_allocator_proc);
@@ -1291,6 +1333,7 @@ void arena_rewind(Arena_R arena, AllocatorSP save_point) {
varena_rewind(curr->backing, (AllocatorSP){varena_allocator_proc, curr->pos + size_of(VArena)}); varena_rewind(curr->backing, (AllocatorSP){varena_allocator_proc, curr->pos + size_of(VArena)});
} }
finline AllocatorSP arena_save(Arena_R arena) { return (AllocatorSP){arena_allocator_proc, arena->base_pos + arena->current->pos}; } finline AllocatorSP arena_save(Arena_R arena) { return (AllocatorSP){arena_allocator_proc, arena->base_pos + arena->current->pos}; }
internal
void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out*R_ out) void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out*R_ out)
{ {
assert(out != nullptr); assert(out != nullptr);
@@ -1309,52 +1352,12 @@ void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out*R_ out)
case AllocatorOp_Grow: case AllocatorOp_Grow:
case AllocatorOp_Grow_NoZero: { case AllocatorOp_Grow_NoZero: {
Arena_R active = arena->current; Slice_Mem result = arena__grow(arena, in.old_allocation, in.requested_size, in.alignment, in.op - AllocatorOp_Grow_NoZero);
U8 alloc_end = in.old_allocation.ptr + in.old_allocation.len; out->allocation = result;
U8 arena_end = u8_(active) + active->pos;
if (alloc_end == arena_end)
{
U8 grow_amount = in.requested_size - in.old_allocation.len;
U8 aligned_grow = align_pow2(grow_amount, in.alignment ? in.alignment : MEMORY_ALIGNMENT_DEFAULT);
if (active->pos + aligned_grow <= active->backing->reserve)
{
Slice_Mem vresult = varena_push_mem(active->backing, aligned_grow, .alignment = in.alignment);
if (vresult.ptr != null)
{
active->pos += aligned_grow;
out->allocation = (Slice_Mem){in.old_allocation.ptr, in.requested_size};
mem_zero(in.old_allocation.ptr + in.old_allocation.len, grow_amount * in.op - AllocatorOp_Grow_NoZero);
break;
}
}
}
Slice_Mem new_alloc = arena__push(arena, in.requested_size, 1, &(Opts_arena){.alignment = in.alignment});
if (new_alloc.ptr == null) {
out->allocation = (Slice_Mem){0};
break;
}
mem_copy(new_alloc.ptr, in.old_allocation.ptr, in.old_allocation.len);
mem_zero(new_alloc.ptr + in.old_allocation.len, (in.requested_size - in.old_allocation.len) * in.op - AllocatorOp_Grow_NoZero);
out->allocation = new_alloc;
} }
break; break;
case AllocatorOp_Shrink:
case AllocatorOp_Shrink: { out->allocation = arena__shrink(arena, in.old_allocation, in.requested_size, in.alignment);
Arena_R active = arena->current;
U8 alloc_end = in.old_allocation.ptr + in.old_allocation.len;
U8 arena_end = u8_(active) + active->pos;
if (alloc_end != arena_end) {
out->allocation = (Slice_Mem){in.old_allocation.ptr, in.requested_size};
break;
}
//SSIZE shrink_amount = in.old_allocation.len - in.requested_size;
U8 aligned_original = align_pow2(in.old_allocation.len, MEMORY_ALIGNMENT_DEFAULT);
U8 aligned_new = align_pow2(in.requested_size, in.alignment ? in.alignment : MEMORY_ALIGNMENT_DEFAULT);
U8 pos_reduction = aligned_original - aligned_new;
active->pos -= pos_reduction;
varena__shrink(active->backing, in.old_allocation, in.requested_size);
out->allocation = (Slice_Mem){in.old_allocation.ptr, in.requested_size};
}
break; break;
case AllocatorOp_Rewind: arena_rewind(arena, in.save_point); break; case AllocatorOp_Rewind: arena_rewind(arena, in.save_point); break;
@@ -1377,7 +1380,7 @@ void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out*R_ out)
#pragma endregion Arena #pragma endregion Arena
#pragma region Key Table Linear (KTL) #pragma region Key Table Linear (KTL)
inline finline
void ktl_populate_slice_a2_str8(KTL_Str8*R_ kt, AllocatorInfo backing, Slice_A2_Str8 values) { void ktl_populate_slice_a2_str8(KTL_Str8*R_ kt, AllocatorInfo backing, Slice_A2_Str8 values) {
assert(kt != nullptr); assert(kt != nullptr);
if (values.len == 0) return; if (values.len == 0) return;
@@ -1390,7 +1393,7 @@ void ktl_populate_slice_a2_str8(KTL_Str8*R_ kt, AllocatorInfo backing, Slice_A2_
#pragma endregion KTL #pragma endregion KTL
#pragma region Key Table 1-Layer Chained-Chunked_Cells (KT1CX) #pragma region Key Table 1-Layer Chained-Chunked_Cells (KT1CX)
inline internal inline
void kt1cx_init(KT1CX_Info info, KT1CX_InfoMeta m, KT1CX_Byte*R_ result) { void kt1cx_init(KT1CX_Info info, KT1CX_InfoMeta m, KT1CX_Byte*R_ result) {
assert(result != nullptr); assert(result != nullptr);
assert(info.backing_cells.proc != nullptr); assert(info.backing_cells.proc != nullptr);
@@ -1402,7 +1405,7 @@ void kt1cx_init(KT1CX_Info info, KT1CX_InfoMeta m, KT1CX_Byte*R_ result) {
result->table = mem_alloc(info.backing_table, m.table_size * m.cell_size); slice_assert(result->table); result->table = mem_alloc(info.backing_table, m.table_size * m.cell_size); slice_assert(result->table);
result->table.len = m.table_size; // Setting to the table number of elements instead of byte length. result->table.len = m.table_size; // Setting to the table number of elements instead of byte length.
} }
inline internal inline
void kt1cx_clear(KT1CX_Byte kt, KT1CX_ByteMeta m) { void kt1cx_clear(KT1CX_Byte kt, KT1CX_ByteMeta m) {
U8 cell_cursor = kt.table.ptr; U8 cell_cursor = kt.table.ptr;
U8 table_len = kt.table.len * m.cell_size; U8 table_len = kt.table.len * m.cell_size;
@@ -1425,9 +1428,9 @@ void kt1cx_clear(KT1CX_Byte kt, KT1CX_ByteMeta m) {
} }
finline finline
U8 kt1cx_slot_id(KT1CX_Byte kt, U8 key, KT1CX_ByteMeta m) { U8 kt1cx_slot_id(KT1CX_Byte kt, U8 key, KT1CX_ByteMeta m) {
U8 hash_index = key % kt.table.len; return key % kt.table.len;
return hash_index;
} }
inline
U8 kt1cx_get(KT1CX_Byte kt, U8 key, KT1CX_ByteMeta m) { U8 kt1cx_get(KT1CX_Byte kt, U8 key, KT1CX_ByteMeta m) {
U8 hash_index = kt1cx_slot_id(kt, key, m); U8 hash_index = kt1cx_slot_id(kt, key, m);
U8 cell_offset = hash_index * m.cell_size; U8 cell_offset = hash_index * m.cell_size;
@@ -1454,7 +1457,7 @@ U8 kt1cx_get(KT1CX_Byte kt, U8 key, KT1CX_ByteMeta m) {
} }
} }
} }
inline internal
U8 kt1cx_set(KT1CX_Byte kt, U8 key, Slice_Mem value, AllocatorInfo backing_cells, KT1CX_ByteMeta m) { U8 kt1cx_set(KT1CX_Byte kt, U8 key, Slice_Mem value, AllocatorInfo backing_cells, KT1CX_ByteMeta m) {
U8 hash_index = kt1cx_slot_id(kt, key, m); U8 hash_index = kt1cx_slot_id(kt, key, m);
U8 cell_offset = hash_index * m.cell_size; U8 cell_offset = hash_index * m.cell_size;
@@ -1504,6 +1507,7 @@ char* str8_to_cstr_capped(Str8 content, Slice_Mem mem) {
u1_r(mem.ptr)[copy_len] = '\0'; u1_r(mem.ptr)[copy_len] = '\0';
return cast(char*, mem.ptr); return cast(char*, mem.ptr);
} }
internal
Str8 str8_from_u32(AllocatorInfo ainfo, U4 num, U4 radix, U4 min_digits, U4 digit_group_separator) Str8 str8_from_u32(AllocatorInfo ainfo, U4 num, U4 radix, U4 min_digits, U4 digit_group_separator)
{ {
Str8 result = {0}; Str8 result = {0};
@@ -1663,17 +1667,16 @@ finline
Str8 str8__fmt_backed(AllocatorInfo tbl_backing, AllocatorInfo buf_backing, Str8 fmt_template, Slice_A2_Str8*R_ entries) { Str8 str8__fmt_backed(AllocatorInfo tbl_backing, AllocatorInfo buf_backing, Str8 fmt_template, Slice_A2_Str8*R_ entries) {
KTL_Str8 kt; kt1l_populate_slice_a2_str8(& kt, tbl_backing, entries[0] ); KTL_Str8 kt; kt1l_populate_slice_a2_str8(& kt, tbl_backing, entries[0] );
U8 buf_size = kilo(64); Slice_Mem buffer = mem_alloc(buf_backing, buf_size); U8 buf_size = kilo(64); Slice_Mem buffer = mem_alloc(buf_backing, buf_size);
Str8 result = str8__fmt_ktl(buf_backing, & buffer, kt, fmt_template); return str8__fmt_ktl(buf_backing, & buffer, kt, fmt_template);
return result;
} }
finline
Str8 str8__fmt(Str8 fmt_template, Slice_A2_Str8*R_ entries) { Str8 str8__fmt(Str8 fmt_template, Slice_A2_Str8*R_ entries) {
local_persist B1 tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem)); local_persist B1 tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem));
local_persist B1 buf_mem[kilo(64)]; local_persist B1 buf_mem[kilo(64)];
KTL_Str8 kt = {0}; ktl_populate_slice_a2_str8(& kt, ainfo_farena(tbl_arena), entries[0] ); KTL_Str8 kt = {0}; ktl_populate_slice_a2_str8(& kt, ainfo_farena(tbl_arena), entries[0] );
Str8 result = str8__fmt_ktl((AllocatorInfo){0}, & slice_fmem(buf_mem), kt, fmt_template); return str8__fmt_ktl((AllocatorInfo){0}, & slice_fmem(buf_mem), kt, fmt_template);
return result;
} }
inline internal inline
void str8cache__init(Str8Cache_R cache, Opts_str8cache_init*R_ opts) { void str8cache__init(Str8Cache_R cache, Opts_str8cache_init*R_ opts) {
assert(cache != nullptr); assert(cache != nullptr);
assert(opts != nullptr); assert(opts != nullptr);
@@ -1761,8 +1764,7 @@ finline
Str8 cache_str8(Str8Cache_R cache, Str8 str) { Str8 cache_str8(Str8Cache_R cache, Str8 str) {
assert(cache != nullptr); assert(cache != nullptr);
U8 key = 0; hash64_fnv1a(& key, slice_mem_s(str)); U8 key = 0; hash64_fnv1a(& key, slice_mem_s(str));
Str8_R result = str8cache_set(cache->kt, key, str, cache->str_reserve, cache->cell_reserve); return str8cache_set(cache->kt, key, str, cache->str_reserve, cache->cell_reserve)[0];
return result[0];
} }
finline finline
void str8gen_init(Str8Gen_R gen, AllocatorInfo backing) { void str8gen_init(Str8Gen_R gen, AllocatorInfo backing) {
@@ -1784,6 +1786,7 @@ void str8gen_append_str8(Str8Gen_R gen, Str8 str){
gen->len += str.len; gen->len += str.len;
gen->cap = result.len; gen->cap = result.len;
} }
internal inline
void str8gen__append_fmt(Str8Gen_R gen, Str8 fmt_template, Slice_A2_Str8*R_ entries){ void str8gen__append_fmt(Str8Gen_R gen, Str8 fmt_template, Slice_A2_Str8*R_ entries){
local_persist B1 tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem)); local_persist B1 tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem));
KTL_Str8 kt = {0}; ktl_populate_slice_a2_str8(& kt, ainfo_farena(tbl_arena), entries[0] ); KTL_Str8 kt = {0}; ktl_populate_slice_a2_str8(& kt, ainfo_farena(tbl_arena), entries[0] );
@@ -1839,6 +1842,7 @@ FileOpInfo file__read_contents(Str8 path, Opts_read_file_contents*R_ opts) {
FileOpInfo result = {0}; api_file_read_contents(& result, path, opts[0]); FileOpInfo result = {0}; api_file_read_contents(& result, path, opts[0]);
return result; return result;
} }
internal
void api_file_read_contents(FileOpInfo_R result, Str8 path, Opts_read_file_contents opts) void api_file_read_contents(FileOpInfo_R result, Str8 path, Opts_read_file_contents opts)
{ {
assert(result != nullptr); assert(result != nullptr);
@@ -1898,6 +1902,7 @@ void api_file_read_contents(FileOpInfo_R result, Str8 path, Opts_read_file_conte
result->content.len = u8_(file_size.QuadPart); result->content.len = u8_(file_size.QuadPart);
return; return;
} }
internal
void file_write_str8(Str8 path, Str8 content) void file_write_str8(Str8 path, Str8 content)
{ {
slice_assert(path); slice_assert(path);
@@ -1972,6 +1977,7 @@ int printf_err(char const* fmt, ...) {
va_end(args); va_end(args);
return result; return result;
} }
internal inline
void assert_handler( UTF8*R_ condition, UTF8*R_ file, UTF8*R_ function, S4 line, UTF8*R_ msg, ... ) { void assert_handler( UTF8*R_ condition, UTF8*R_ file, UTF8*R_ function, S4 line, UTF8*R_ msg, ... ) {
printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line ); printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line );
if ( condition ) if ( condition )
@@ -1988,6 +1994,7 @@ void assert_handler( UTF8*R_ condition, UTF8*R_ file, UTF8*R_ function, S4 line,
#pragma endregion Debug #pragma endregion Debug
#pragma region WATL #pragma region WATL
internal
void api_watl_lex(WATL_LexInfo_R info, Str8 source, Opts_watl_lex*R_ opts) void api_watl_lex(WATL_LexInfo_R info, Str8 source, Opts_watl_lex*R_ opts)
{ {
if (source.len == 0) { return; } if (source.len == 0) { return; }
@@ -2077,7 +2084,7 @@ slice_constraint_fail:
return; return;
} }
inline WATL_LexInfo watl__lex(Str8 source, Opts_watl_lex*R_ opts) { WATL_LexInfo info = {0}; api_watl_lex(& info, source, opts); return info; } inline WATL_LexInfo watl__lex(Str8 source, Opts_watl_lex*R_ opts) { WATL_LexInfo info = {0}; api_watl_lex(& info, source, opts); return info; }
internal
void api_watl_parse(WATL_ParseInfo_R info, Slice_WATL_Tok tokens, Opts_watl_parse*R_ opts) void api_watl_parse(WATL_ParseInfo_R info, Slice_WATL_Tok tokens, Opts_watl_parse*R_ opts)
{ {
if (tokens.len == 0) { return; } if (tokens.len == 0) { return; }
@@ -2138,8 +2145,8 @@ void api_watl_parse(WATL_ParseInfo_R info, Slice_WATL_Tok tokens, Opts_watl_pars
} }
return; return;
} }
inline WATL_ParseInfo watl__parse(Slice_WATL_Tok tokens, Opts_watl_parse*R_ opts) { WATL_ParseInfo info = {0}; api_watl_parse(& info, tokens, opts); return info; } finline WATL_ParseInfo watl__parse(Slice_WATL_Tok tokens, Opts_watl_parse*R_ opts) { WATL_ParseInfo info = {0}; api_watl_parse(& info, tokens, opts); return info; }
internal
Str8 watl_dump_listing(AllocatorInfo buffer, Slice_WATL_Line lines) Str8 watl_dump_listing(AllocatorInfo buffer, Slice_WATL_Line lines)
{ {
local_persist B1 scratch[kilo(64)] = {0}; FArena sarena = farena_make(slice_fmem(scratch)); AllocatorInfo sinfo = ainfo_farena(sarena); local_persist B1 scratch[kilo(64)] = {0}; FArena sarena = farena_make(slice_fmem(scratch)); AllocatorInfo sinfo = ainfo_farena(sarena);
@@ -2159,8 +2166,7 @@ Str8 watl_dump_listing(AllocatorInfo buffer, Slice_WATL_Line lines)
for slice_iter(line[0], chunk) for slice_iter(line[0], chunk)
{ {
Str8 id; Str8 id;
switch (chunk->ptr[0]) switch (chunk->ptr[0]) {
{
case WATL_Tok_Space: id = lit("Space"); break; case WATL_Tok_Space: id = lit("Space"); break;
case WATL_Tok_Tab: id = lit("Tab"); break; case WATL_Tok_Tab: id = lit("Tab"); break;
default: id = lit("Visible"); break; default: id = lit("Visible"); break;
@@ -2180,7 +2186,6 @@ Str8 watl_dump_listing(AllocatorInfo buffer, Slice_WATL_Line lines)
#pragma endregion WATL #pragma endregion WATL
#pragma endregion Implementation #pragma endregion Implementation
int main(void) int main(void)
{ {
os_init(); os_init();

View File

@@ -2080,8 +2080,7 @@ Str8 watl_dump_listing(AllocatorInfo buffer, Slice_WATL_Line lines)
for slice_iter(* line, chunk) for slice_iter(* line, chunk)
{ {
Str8 id; Str8 id;
switch (* chunk->ptr) switch (* chunk->ptr) {
{
case WATL_Tok_Space: id = lit("Space"); break; case WATL_Tok_Space: id = lit("Space"); break;
case WATL_Tok_Tab: id = lit("Tab"); break; case WATL_Tok_Tab: id = lit("Tab"); break;
default: id = lit("Visible"); break; default: id = lit("Visible"); break;
@@ -2104,7 +2103,6 @@ Str8 watl_dump_listing(AllocatorInfo buffer, Slice_WATL_Line lines)
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 4101) #pragma warning(disable: 4101)
internal
int main(void) int main(void)
{ {
os_init(); os_init();

View File

@@ -118,8 +118,8 @@ $compiler_args += $flag_full_src_path
# $compiler_args += $flag_optimize_speed_max # $compiler_args += $flag_optimize_speed_max
# $compiler_args += $flag_optimize_fast # $compiler_args += $flag_optimize_fast
# $compiler_args += $flag_optimize_size # $compiler_args += $flag_optimize_size
# $compiler_args += $flag_optimize_intrinsics $compiler_args += $flag_optimize_intrinsics
$compiler_args += $flag_no_optimization # $compiler_args += $flag_no_optimization
# Debug setup # Debug setup
$compiler_args += ($flag_define + 'BUILD_DEBUG') $compiler_args += ($flag_define + 'BUILD_DEBUG')

View File

@@ -118,8 +118,8 @@ $compiler_args += $flag_full_src_path
# $compiler_args += $flag_optimize_speed_max # $compiler_args += $flag_optimize_speed_max
# $compiler_args += $flag_optimize_fast # $compiler_args += $flag_optimize_fast
# $compiler_args += $flag_optimize_size # $compiler_args += $flag_optimize_size
# $compiler_args += $flag_optimize_intrinsics $compiler_args += $flag_optimize_intrinsics
$compiler_args += $flag_no_optimization # $compiler_args += $flag_no_optimization
# Debug setup # Debug setup
$compiler_args += ($flag_define + 'BUILD_DEBUG') $compiler_args += ($flag_define + 'BUILD_DEBUG')