diff options
Diffstat (limited to 'src/mem.hff')
| -rw-r--r-- | src/mem.hff | 23 |
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 { |