From 724fd5ed4fdaea8ed26fa81dd3ba085fcf1a8bc0 Mon Sep 17 00:00:00 2001 From: koniifer <koniifer@proton.me> Date: Fri, 31 Jan 2025 18:57:21 +0000 Subject: [PATCH] fix arena --- src/lily/alloc/arena.hb | 12 ++++++------ src/test/lily/lily.alloc.arena.hb | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lily/alloc/arena.hb b/src/lily/alloc/arena.hb index fa32fc0..8a76cc7 100644 --- a/src/lily/alloc/arena.hb +++ b/src/lily/alloc/arena.hb @@ -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 } -} +} \ No newline at end of file diff --git a/src/test/lily/lily.alloc.arena.hb b/src/test/lily/lily.alloc.arena.hb index fd66485..30e1aa2 100644 --- a/src/test/lily/lily.alloc.arena.hb +++ b/src/test/lily/lily.alloc.arena.hb @@ -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 -} +} \ No newline at end of file