summaryrefslogtreecommitdiff
path: root/src/zisp/gc.zig
blob: b2fcc4641b0cceaa04bad76a505b9355a41bd31e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const builtin = @import("builtin");
const std = @import("std");

const Alloc = std.mem.Allocator;

const value = @import("value.zig");

pub const ListPool = @import("gc/ListPool.zig");
pub const IstrSet = @import("gc/IstrSet.zig");

var main_alloc: Alloc = undefined;
var main_list_pool: ListPool = 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 ListPool.init(alloc),
        try IstrSet.init(alloc),
    );
}

pub fn initCustom(
    alloc: Alloc,
    list_pool: ListPool,
    istr_set: IstrSet,
) void {
    main_alloc = alloc;
    main_list_pool = list_pool;
    main_istr_set = istr_set;
}

pub fn mainListPool() *ListPool {
    init() catch @panic("OOM"); // TODO this is only here for the test suite
    return &main_list_pool;
}

pub fn mainIstrSet() *IstrSet {
    init() catch @panic("OOM"); // TODO this is only here for the test suite
    return &main_istr_set;
}