blob: c1c70935bc89bfcd1ec6c4956f209fc8c75bf5f0 (
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
|
const std = @import("std");
const value = @import("../value.zig");
const gc = @import("../gc.zig");
const ptr = @import("ptr.zig");
const seq = @import("seq.zig");
const Value = value.Value;
// Zig API
pub fn check(v: Value) ?*seq.Header {
if (v.getPtr(.seq)) |p| {
const h: *seq.Header = @ptrCast(p);
if (h.type == .string and h.info.string.interned) {
return h;
}
}
return null;
}
pub fn assert(v: Value) *seq.Header {
return check(v) orelse {
v.dump();
@panic("not istr");
};
}
pub fn intern(str: []const u8) Value {
return gc.internString(str);
}
// Zisp API
pub fn pred(v: Value) Value {
return value.boole.pack(check(v) != null);
}
pub fn len(v: Value) Value {
const l = assert(v).size;
std.debug.assert(l <= value.fixnum.max);
return value.fixnum.pack(@intCast(l));
}
|