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

View file

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