blob: b256ea29a2d560c805607d3c67a79ad0b18939b1 (
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
47
|
const builtin = @import("builtin");
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;
}
// 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");
}
// Init
var need_init = true;
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");
}
|