aboutsummaryrefslogtreecommitdiff
path: root/src/mem.hff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-13 20:53:39 +0200
committerlemon <lsof@mailbox.org>2022-08-13 20:53:39 +0200
commitddcca62a276c528a4390c8e3d58403b865f81869 (patch)
tree3d563e173a18095501f61f3b30e39cf62b4ff521 /src/mem.hff
parenta4ddca68662f4bc0531763357b4bc00b6c50b456 (diff)
ok..
Diffstat (limited to 'src/mem.hff')
-rw-r--r--src/mem.hff23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/mem.hff b/src/mem.hff
index 9fee910..84064f3 100644
--- a/src/mem.hff
+++ b/src/mem.hff
@@ -1,6 +1,11 @@
+import "libc.hff";
import "all.hff";
def ARENA_SIZE = 16 * 1024;
+defmacro ALIGNUP(x,a) [ (((x) + ((a) - 1)) & -(a)) ]
+extern fn xmalloc(n usize) *void;
+extern fn xcalloc(n usize, m usize) *void;
+extern fn xrealloc(p *void, n usize) *void;
struct ArenaRegion {
prev *ArenaRegion,
@@ -24,28 +29,18 @@ struct Arena {
a.r.idx += n;
return ptr;
} else {
- let rp = xmalloc(sizeof ArenaRegion);
- *rp = a.r;
+ let rp *ArenaRegion = xmalloc(sizeof ArenaRegion);
+ *rp = *a.r;
let r = ArenaRegion { .prev: rp };
return allocf(a, n);
}
}
}
-struct Mallocator {
- fn allocf(*void, n usize) *void {
- return xmalloc(n);
- }
-
- fn freef(*void, ptr *void) void {
- free(ptr);
- }
-}
-
struct Allocator {
a *void,
- allocf *fn(a *void, n usize) *void,
- freef *fn(a *void, ptr *void) void,
+ allocf *fn(*void, usize) *void,
+ freef *fn(*void, *void) void,
fn alloc(self *Allocator, n usize) *void {
if self.allocf {