summaryrefslogtreecommitdiff
path: root/src/zisp/gc.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/zisp/gc.zig')
-rw-r--r--src/zisp/gc.zig22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/zisp/gc.zig b/src/zisp/gc.zig
index b36628f..9cb66d1 100644
--- a/src/zisp/gc.zig
+++ b/src/zisp/gc.zig
@@ -13,35 +13,37 @@ const HeapType = value.HeapType;
var main_alloc: Alloc = undefined;
-var list_heap_start: usize = undefined;
-var main_heap_start: usize = undefined;
-var istr_heap_start: usize = undefined;
+const u32max = std.math.maxInt(u32);
+
+var list_heap: *[u32max]Value = undefined;
+var main_heap: *[u32max]u64 = undefined;
+var istr_heap: *[u32max]u8 = undefined;
var main_list_pool: ListPool = undefined;
var main_istr_pool: IstrPool = undefined;
pub fn listPtrFromIdx(idx: u32) [*]Value {
- return @ptrFromInt(list_heap_start + idx * 8);
+ return &list_heap[idx];
}
pub fn heapPtrFromIdx(comptime typ: HeapType, idx: u32) typ.PtrType() {
- return @ptrFromInt(main_heap_start + idx * 8);
+ return @ptrCast(&main_heap[idx]);
}
pub fn istrPtrFromIdx(idx: u32) [*]const u8 {
- return @ptrFromInt(istr_heap_start + idx);
+ return &istr_heap[idx];
}
pub fn listIdxFromPtr(ptr: [*]Value) u32 {
- return @intCast(@intFromPtr(ptr - list_heap_start) / 8);
+ return @intCast(ptr - list_heap);
}
pub fn heapIdxFromPtr(ptr: HeapPtr) u32 {
- return @intCast(@intFromPtr(ptr - main_heap_start) / 8);
+ return @intCast(ptr - main_heap);
}
pub fn istrIdxFromPtr(ptr: [*]const u8) u32 {
- return @intCast(@intFromPtr(ptr - istr_heap_start));
+ return @intCast(ptr - istr_heap);
}
pub fn allocHeap(comptime typ: HeapType, len: usize) !typ.PtrType() {
@@ -92,5 +94,5 @@ pub fn mainListPool() *ListPool {
pub fn mainIstrPool() *IstrPool {
init() catch @panic("OOM"); // TODO this is only here for the test suite
- return &main_istr_set;
+ return &main_istr_pool;
}