Move scratch to its own file. Simplify usage.
This commit is contained in:
32
module.jai
32
module.jai
@@ -186,33 +186,6 @@ Compiler_Context :: struct {
|
||||
messages : [..]Compiler_Message;
|
||||
}
|
||||
|
||||
#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 arena == get_arena(context.scratch_allocators[0]) || context.scratch_id == 0 {
|
||||
context.scratch_id = 1;
|
||||
return scratch_begin(*context.scratch_allocators[1]);
|
||||
}
|
||||
context.scratch_id = 0;
|
||||
return scratch_begin(*context.scratch_allocators[0]);
|
||||
}
|
||||
|
||||
record_error :: (result : *Compiler_Context, format : string, args : .. Any) {
|
||||
error : Compiler_Message;
|
||||
error.message_kind = .Error;
|
||||
@@ -505,8 +478,8 @@ compile_file :: (ctx : *Compiler_Context, path : string, allocator : Allocator =
|
||||
new_context := context;
|
||||
new_context.allocator = allocator;
|
||||
push_context new_context {
|
||||
init_context_allocators();
|
||||
defer clear_context_allocators();
|
||||
init_scratch();
|
||||
defer clear_scratch();
|
||||
|
||||
ctx.file = make_file(ctx, path);
|
||||
|
||||
@@ -517,3 +490,4 @@ compile_file :: (ctx : *Compiler_Context, path : string, allocator : Allocator =
|
||||
generate_output_data(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user