A bunch of new allocation related stuff.

This commit is contained in:
2025-09-10 06:59:29 +02:00
parent f4a9592f26
commit ceafd197f5
18 changed files with 852 additions and 170 deletions

View File

@@ -181,23 +181,34 @@ Compile_Result :: struct {
messages : [..]Compiler_Message;
allocator : Allocator;
// arena : Arena;
// scratch_arenas : [2]Arena;
scratch_allocators : [2]Allocator;
// string_allocator : Allocator;
}
get_scratch :: (result : *Compile_Result, conflict : Allocator = .{}) -> Scratch {
#add_context scratch_allocators : [2]Allocator;
#add_context scratch_id : int = 0;
init_context_allocators :: () {
if get_arena(context.scratch_allocators[0]) == null {
context.scratch_allocators[0] = make_arena(Megabytes(128));
context.scratch_allocators[1] = make_arena(Megabytes(128));
}
}
clear_context_allocators :: () {
if get_arena(context.scratch_allocators[0]) != null {
clear(context.scratch_allocators[0]);
clear(context.scratch_allocators[1]);
}
}
get_scratch :: (conflict : Allocator = .{}) -> Scratch {
arena := cast(*Arena)conflict.data;
if result.scratch_allocators[0].data == null {
result.scratch_allocators[0] = make_arena(Megabytes(128));
result.scratch_allocators[1] = make_arena(Megabytes(128));
if arena == get_arena(context.scratch_allocators[0]) || context.scratch_id == 0 {
context.scratch_id = 1;
return scratch_begin(*context.scratch_allocators[1]);
}
if arena == get_arena(result.scratch_allocators[0]) {
return scratch_begin(*result.scratch_allocators[1]);
}
return scratch_begin(*result.scratch_allocators[0]);
context.scratch_id = 0;
return scratch_begin(*context.scratch_allocators[0]);
}
record_error :: (result : *Compile_Result, format : string, args : .. Any) {
@@ -494,19 +505,29 @@ generate_output_data :: (result : *Compile_Result) {
}
}
compile_file :: (compiler : *Shader_Compiler, path : string) -> Compile_Result {
compile_file :: (compiler : *Shader_Compiler, path : string, allocator : Allocator = temp) -> Compile_Result {
result : Compile_Result;
new_context := context;
new_context.allocator = allocator;
push_context new_context {
init_context_allocators();
defer clear_context_allocators();
result.allocator = make_arena(Megabytes(128));
result.file = make_file(*result, path);
result.environment = compiler.environment;
lex(*result);
parse(*result);
check(*result);
codegen(*result);
generate_output_data(*result);
result.allocator = make_arena(Megabytes(128));
result.file = make_file(*result, path);
result.environment = compiler.environment;
lex(*result);
parse(*result);
check(*result);
codegen(*result);
generate_output_data(*result);
}
return result;
}