fixing compiler bugs
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
Os :: #import "os.kl"
|
||||
SizeU :: #strict U64
|
||||
|
||||
arena_di: U64
|
||||
|
||||
ALLOCATOR_ACTION :: enum
|
||||
ALLOCATE
|
||||
RESIZE
|
||||
FREE_ALL
|
||||
|
||||
Allocator :: struct
|
||||
proc: (a: *Allocator, action: ALLOCATOR_ACTION, size: SizeU, old_pointer: *void): *void
|
||||
|
||||
Arena :: struct
|
||||
allocator: Allocator
|
||||
di: U64 // @debug_id
|
||||
memory: Os.Memory
|
||||
alignment: U64
|
||||
@@ -33,6 +41,7 @@ arena_init :: (a: *Arena)
|
||||
a.memory = Os.reserve(a.DEFAULT_RESERVE_SIZE)
|
||||
a.alignment = a.DEFAULT_ALIGNMENT
|
||||
a.di = arena_di++
|
||||
a.allocator.proc = arena_allocator_proc
|
||||
|
||||
arena_push_size :: (a: *Arena, size: SizeU): *void
|
||||
generous_size := size + a.alignment
|
||||
@@ -47,3 +56,21 @@ arena_push_size :: (a: *Arena, size: SizeU): *void
|
||||
a.len += size
|
||||
return result
|
||||
|
||||
arena_release :: (a: *Arena)
|
||||
Os.release(&a.memory)
|
||||
|
||||
arena_allocator_proc :: (a: *Allocator, action: ALLOCATOR_ACTION, size: SizeU, old_pointer: *void): *void
|
||||
arena: *Arena = a->*Arena
|
||||
if action == ALLOCATOR_ACTION.ALLOCATE
|
||||
return arena_push_size(arena, size)
|
||||
elif action == ALLOCATOR_ACTION.RESIZE
|
||||
pass
|
||||
elif action == ALLOCATOR_ACTION.FREE_ALL
|
||||
pass
|
||||
else;; assert(false, "Invalid codepath")
|
||||
return 0
|
||||
|
||||
allocate :: (a: *Allocator, size: SizeU): *void
|
||||
return a.proc(a, ALLOCATOR_ACTION.ALLOCATE, size, 0)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user