summaryrefslogtreecommitdiff
path: root/src/libzisp/value/seq.zig
blob: 3418a5a5f8de9c6bee1f86930bdc80595e9020d3 (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
48
49
50
51
52
53
54
55
56
57
const builtin = @import("builtin");
const std = @import("std");

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

const Value = value.Value;

const Endian = enum(u1) {
    little,
    big,

    const native: Endian = switch (builtin.target.cpu.arch.endian()) {
        .little => .little,
        .big => .big,
    };
};

pub const Header = packed struct(u64) {
    type: enum(u2) {
        values,
        string,
        ints,
        floats,
    },
    info: packed union {
        values: packed struct(u14) {
            weak: bool = false,
            _: u13 = 0,
        },
        string: packed struct(u14) {
            enc: enum(u4) { utf8, utf16, utf24, utf32 },
            endian: Endian = .native,
            quoted: bool,
            interned: bool,
            _: u7 = 0,
        },
        ints: packed struct(u14) {
            signed: bool,
            endian: Endian = .native,
            size: u12,
        },
        floats: packed struct(u14) {
            double: bool,
            endian: Endian = .native,
            _: u12 = 0,
        },
    },
    size: u48,

    pub fn bytes(self: *Header) []u8 {
        const hs = @sizeOf(Header);
        const ptr: [*]u8 = @ptrCast(self);
        const end = hs + self.size;
        return ptr[hs..end];
    }
};