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.zig71
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;
}