summaryrefslogtreecommitdiff
path: root/src/libzisp/value/boole.zig
blob: 623dbc224d9668dcc2a8033377075a6d13768bba (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
const Value = @import("../value.zig").Value;
const misc = @import("misc.zig");

pub const f = misc.f;
pub const t = misc.t;

// Zig API

/// Checks if the value is a boole.
pub fn check(v: Value) bool {
    return v.bits == f.bits or v.bits == t.bits;
}

pub fn assert(v: Value) void {
    if (!check(v)) {
        v.dump();
        @panic("not bool");
    }
}

pub fn pack(b: bool) Value {
    return if (b) t else f;
}

pub fn unpack(v: Value) bool {
    assert(v);
    return v.bits == t.bits;
}

// Zisp API

pub fn pred(v: Value) Value {
    return pack(check(v));
}