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.zig37
1 files changed, 13 insertions, 24 deletions
diff --git a/src/zisp/gc.zig b/src/zisp/gc.zig
index 9cb66d1..6efa8fe 100644
--- a/src/zisp/gc.zig
+++ b/src/zisp/gc.zig
@@ -8,42 +8,33 @@ const value = @import("value.zig");
pub const ListPool = @import("gc/ListPool.zig");
pub const IstrPool = @import("gc/IstrPool.zig");
+const Value = value.Value;
const HeapPtr = value.HeapPtr;
const HeapType = value.HeapType;
-var main_alloc: Alloc = undefined;
+const i32max = std.math.maxInt(i32);
-const u32max = std.math.maxInt(u32);
+var heap: *[2 * i32max]u64 = undefined;
-var list_heap: *[u32max]Value = undefined;
-var main_heap: *[u32max]u64 = undefined;
-var istr_heap: *[u32max]u8 = undefined;
+var watermark: i32 = 0;
+
+threadlocal var tl_watermark: i32 = 0;
var main_list_pool: ListPool = undefined;
var main_istr_pool: IstrPool = undefined;
-pub fn listPtrFromIdx(idx: u32) [*]Value {
- return &list_heap[idx];
-}
-
-pub fn heapPtrFromIdx(comptime typ: HeapType, idx: u32) typ.PtrType() {
- return @ptrCast(&main_heap[idx]);
+pub fn ptrFromIdx(idx: u32) [*]Value {
+ return &heap[idx];
}
-pub fn istrPtrFromIdx(idx: u32) [*]const u8 {
- return &istr_heap[idx];
+pub fn idxFromPtr(ptr: [*]Value) u32 {
+ return @intCast(ptr - heap);
}
-pub fn listIdxFromPtr(ptr: [*]Value) u32 {
- return @intCast(ptr - list_heap);
-}
+// TODO: Actually allocate within the boundaries of the various heaps
-pub fn heapIdxFromPtr(ptr: HeapPtr) u32 {
- return @intCast(ptr - main_heap);
-}
-
-pub fn istrIdxFromPtr(ptr: [*]const u8) u32 {
- return @intCast(ptr - istr_heap);
+pub fn allocIstr(len: u8) [*]const u8 {
+ return @ptrCast(main_alloc.alloc(u8, len).ptr);
}
pub fn allocHeap(comptime typ: HeapType, len: usize) !typ.PtrType() {
@@ -76,8 +67,6 @@ pub fn init() !void {
main_alloc = std.heap.smp_allocator;
- //list_heap_start = ...;
-
main_list_pool = try ListPool.init(main_alloc);
main_istr_pool = try IstrPool.init(main_alloc);
}