diff options
| author | Taylan Kammer <taylan.kammer@gmail.com> | 2026-07-01 01:26:15 +0200 |
|---|---|---|
| committer | Taylan Kammer <taylan.kammer@gmail.com> | 2026-07-01 01:26:15 +0200 |
| commit | 23b1ae89d351aabbdc8b7d6dfa362cc31165501e (patch) | |
| tree | 5ab8e43a2ef7891d203e5925aedd0ddf44489884 /src/zisp/gc.zig | |
| parent | d5259ed20eae38bb4f732d829b927dd54cfac5f5 (diff) | |
Big changes. Incomplete. Won't compile yet.
Diffstat (limited to 'src/zisp/gc.zig')
| -rw-r--r-- | src/zisp/gc.zig | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/src/zisp/gc.zig b/src/zisp/gc.zig index 0e47682..0e26aa9 100644 --- a/src/zisp/gc.zig +++ b/src/zisp/gc.zig @@ -5,21 +5,58 @@ const Alloc = std.mem.Allocator; const value = @import("value.zig"); -pub const ListPool = @import("gc/ListPool.zig"); -pub const IstrSet = @import("gc/IstrSet.zig"); +pub const CodePool = @import("gc/CodePool.zig"); +pub const IstrPool = @import("gc/IstrPool.zig"); + +const HeapPtr = value.HeapPtr; var main_alloc: Alloc = undefined; + +var code_heap_start: usize = undefined; +var main_heap_start: usize = undefined; +var istr_heap_start: usize = undefined; + var main_list_pool: ListPool = undefined; -var main_istr_set: IstrSet = undefined; +var main_istr_pool: IstrPool = undefined; + +pub fn codePtrFromIdx(idx: u32) [*]Value { + return @ptrFromInt(code_heap_start + idx * 8); +} + +pub fn heapPtrFromIdx(idx: u32) HeapPtr { + return @ptrFromInt(main_heap_start + idx * 8); +} + +pub fn istrPtrFromIdx(idx: u32) [*]const u8 { + return @ptrFromInt(istr_heap_start + idx); +} + +pub fn codeIdxFromPtr(ptr: [*]Value) u32 { + return @intCast(@intFromPtr(ptr - code_heap_start) / 8); +} + +pub fn heapIdxFromPtr(ptr: HeapPtr) u32 { + return @intCast(@intFromPtr(ptr - main_heap_start) / 8); +} + +pub fn istrIdxFromPtr(ptr: [*]const u8) u32 { + return @intCast(@intFromPtr(ptr - istr_heap_start)); +} + +// init var init_done = false; pub fn init() !void { if (init_done) return; defer init_done = true; + main_alloc = std.heap.smp_allocator; + + //code_heap_start = ...; + main_list_pool = try ListPool.init(main_alloc); - main_istr_set = try IstrSet.init(main_alloc); + main_istr_set = try IstrPool.init(main_alloc); } pub fn mainAlloc() Alloc { @@ -32,7 +69,7 @@ pub fn mainListPool() *ListPool { return &main_list_pool; } -pub fn mainIstrSet() *IstrSet { +pub fn mainIstrPool() *IstrPool { init() catch @panic("OOM"); // TODO this is only here for the test suite return &main_istr_set; } |
