diff options
| author | Taylan Kammer <taylan.kammer@gmail.com> | 2026-06-05 23:56:01 +0200 |
|---|---|---|
| committer | Taylan Kammer <taylan.kammer@gmail.com> | 2026-06-05 23:56:01 +0200 |
| commit | 3a66abbf1d54c441828d48a29dbed9fdde68da5b (patch) | |
| tree | 36ef28908d6db605c6c8b67956074f0014a866bb /src/zisp/gc.zig | |
| parent | 3749ae3cdadc86656faeb642d5f260240ff18c0c (diff) | |
Big code cleanup; make stuff more configurable.
Diffstat (limited to 'src/zisp/gc.zig')
| -rw-r--r-- | src/zisp/gc.zig | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/src/zisp/gc.zig b/src/zisp/gc.zig index b256ea2..7fc431d 100644 --- a/src/zisp/gc.zig +++ b/src/zisp/gc.zig @@ -3,45 +3,44 @@ const std = @import("std"); const value = @import("value.zig"); -//const PairPool = @import("gc/PairPool.zig"); -const PairPool = std.heap.MemoryPool(value.pair.Pair); // TODO -const IstrSet = @import("gc/IstrSet.zig"); - -const Value = value.Value; - -const PairPtr = value.pair.PairPtr; -const IstrPtr = value.istr.IstrPtr; - -pub const alloc = std.heap.smp_allocator; - -// Pairs - -var pair_pool: PairPool = undefined; - -pub fn makePair(v1: Value, v2: Value) PairPtr { - init(); // TODO this is only here for the test suite - const p = pair_pool.create(alloc) catch @panic("OOM"); - p.car = v1; - p.cdr = v2; - return p; +const Alloc = std.mem.Allocator; + +pub const PairPool = @import("gc/PairPool.zig"); +pub const IstrSet = @import("gc/IstrSet.zig"); + +var main_alloc: Alloc = undefined; +var main_pair_pool: PairPool = undefined; +var main_istr_set: IstrSet = undefined; + +var init_done = false; + +pub fn init() !void { + if (init_done) return; + defer init_done = true; + const alloc = std.heap.smp_allocator; + initCustom( + alloc, + try PairPool.init(alloc), + try IstrSet.init(alloc), + ); } -// Interned strings - -var istr_set: IstrSet = undefined; - -pub fn internString(s: []const u8) value.istr.IstrPtr { - init(); // TODO this is only here for the test suite - return istr_set.add(alloc, s) catch @panic("OOM"); +pub fn initCustom( + alloc: Alloc, + pair_pool: PairPool, + istr_set: IstrSet, +) void { + main_alloc = alloc; + main_pair_pool = pair_pool; + main_istr_set = istr_set; } -// Init - -var need_init = true; +pub fn mainPairPool() *PairPool { + init() catch @panic("OOM"); // TODO this is only here for the test suite + return &main_pair_pool; +} -pub fn init() void { - if (!need_init) return; - defer need_init = false; - pair_pool = PairPool.initCapacity(alloc, 64) catch @panic("OOM"); - istr_set = IstrSet.init(alloc) catch @panic("OOM"); +pub fn mainIstrSet() *IstrSet { + init() catch @panic("OOM"); // TODO this is only here for the test suite + return &main_istr_set; } |
