fix arena

This commit is contained in:
koniifer 2025-01-31 18:57:21 +00:00 committed by Talha Qamar
parent b3fe6b4de8
commit 724fd5ed4f
2 changed files with 8 additions and 8 deletions
src
lily/alloc
test/lily

View file

@ -10,11 +10,11 @@ ArenaAllocator := struct {
size: uint, size: uint,
allocated: uint, allocated: uint,
$new := fn(): Self { new := fn(): Self {
allocated := 0 size := Target.page_size()
allocated = Target.page_size() // todo(?): spec should accept ?Self as return type
ptr := Target.alloc_zeroed(allocated) ptr := @unwrap(Target.alloc_zeroed(size))
return .(ptr, allocated, 0) return .(ptr, size, 0)
} }
deinit := fn(self: ^Self): void { deinit := fn(self: ^Self): void {
match Target.current() { match Target.current() {
@ -55,4 +55,4 @@ ArenaAllocator := struct {
} }
return null return null
} }
} }

View file

@ -5,8 +5,8 @@ lily := @use("../../lily/lib.hb")
main := fn(argc: int, argv: [][]u8): u8 { main := fn(argc: int, argv: [][]u8): u8 {
alloc := lily.alloc.ArenaAllocator.new() alloc := lily.alloc.ArenaAllocator.new()
defer alloc.deinit()
ptr_one := alloc.alloc(u8, 6) ptr_one := alloc.alloc(u8, 6)
ptr_two := alloc.alloc(u8, 179) ptr_two := alloc.alloc(u8, 179)
alloc.deinit()
return 0 return 0
} }