Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

Tag

Interner.Tag
pub const Tag = enum(u8)

File

Code

pub const Tag = enum(u8) {
    /// `data` is `u16`
    int_ty,
    /// `data` is `u16`
    float_ty,
    /// `data` is `u16`
    complex_ty,
    /// `data` is index to `Array`
    array_ty,
    /// `data` is index to `Vector`
    vector_ty,
    /// `data` is `u32`
    u32,
    /// `data` is `i32`
    i32,
    /// `data` is `Int`
    int_positive,
    /// `data` is `Int`
    int_negative,
    /// `data` is `f16`
    f16,
    /// `data` is `f32`
    f32,
    /// `data` is `F64`
    f64,
    /// `data` is `F80`
    f80,
    /// `data` is `F128`
    f128,
    /// `data` is `CF16`
    cf16,
    /// `data` is `CF32`
    cf32,
    /// `data` is `CF64`
    cf64,
    /// `data` is `CF80`
    cf80,
    /// `data` is `CF128`
    cf128,
    /// `data` is `Bytes`
    bytes,
    /// `data` is `Record`
    record_ty,
    /// `data` is Pointer
    pointer,

    pub const Array = struct {
        len0: u32,
        len1: u32,
        child: Ref,

        pub fn getLen(a: Array) u64 {
            return (PackedU64{
                .a = a.len0,
                .b = a.len1,
            }).get();
        }
    };

    pub const Vector = struct {
        len: u32,
        child: Ref,
    };

    pub const Pointer = struct {
        node: u32,
        offset: Ref,
    };

    pub const Int = struct {
        limbs_index: u32,
        limbs_len: u32,

        /// Big enough to fit any non-BigInt value
        pub const BigIntSpace = struct {
            /// The +1 is headroom so that operations such as incrementing once
            /// or decrementing once are possible without using an allocator.
            limbs: [(@sizeOf(u64) / @sizeOf(std.math.big.Limb)) + 1]std.math.big.Limb,
        };
    };

    pub const F64 = struct {
        piece0: u32,
        piece1: u32,

        pub fn get(self: F64) f64 {
            const int_bits = @as(u64, self.piece0) | (@as(u64, self.piece1) << 32);
            return @bitCast(int_bits);
        }

        fn pack(val: f64) F64 {
            const bits = @as(u64, @bitCast(val));
            return .{
                .piece0 = @as(u32, @truncate(bits)),
                .piece1 = @as(u32, @truncate(bits >> 32)),
            };
        }
    };

    pub const F80 = struct {
        piece0: u32,
        piece1: u32,
        piece2: u32, // u16 part, top bits

        pub fn get(self: F80) f80 {
            const int_bits = @as(u80, self.piece0) |
                (@as(u80, self.piece1) << 32) |
                (@as(u80, self.piece2) << 64);
            return @bitCast(int_bits);
        }

        fn pack(val: f80) F80 {
            const bits = @as(u80, @bitCast(val));
            return .{
                .piece0 = @as(u32, @truncate(bits)),
                .piece1 = @as(u32, @truncate(bits >> 32)),
                .piece2 = @as(u16, @truncate(bits >> 64)),
            };
        }
    };

    pub const F128 = struct {
        piece0: u32,
        piece1: u32,
        piece2: u32,
        piece3: u32,

        pub fn get(self: F128) f128 {
            const int_bits = @as(u128, self.piece0) |
                (@as(u128, self.piece1) << 32) |
                (@as(u128, self.piece2) << 64) |
                (@as(u128, self.piece3) << 96);
            return @bitCast(int_bits);
        }

        fn pack(val: f128) F128 {
            const bits = @as(u128, @bitCast(val));
            return .{
                .piece0 = @as(u32, @truncate(bits)),
                .piece1 = @as(u32, @truncate(bits >> 32)),
                .piece2 = @as(u32, @truncate(bits >> 64)),
                .piece3 = @as(u32, @truncate(bits >> 96)),
            };
        }
    };

    pub const CF16 = struct {
        piece0: u32,

        pub fn get(self: CF16) [2]f16 {
            const real: f16 = @bitCast(@as(u16, @truncate(self.piece0 >> 16)));
            const imag: f16 = @bitCast(@as(u16, @truncate(self.piece0)));
            return .{
                real,
                imag,
            };
        }

        fn pack(val: [2]f16) CF16 {
            const real: u16 = @bitCast(val[0]);
            const imag: u16 = @bitCast(val[1]);
            return .{
                .piece0 = (@as(u32, real) << 16) | @as(u32, imag),
            };
        }
    };

    pub const CF32 = struct {
        piece0: u32,
        piece1: u32,

        pub fn get(self: CF32) [2]f32 {
            return .{
                @bitCast(self.piece0),
                @bitCast(self.piece1),
            };
        }

        fn pack(val: [2]f32) CF32 {
            return .{
                .piece0 = @bitCast(val[0]),
                .piece1 = @bitCast(val[1]),
            };
        }
    };

    pub const CF64 = struct {
        piece0: u32,
        piece1: u32,
        piece2: u32,
        piece3: u32,

        pub fn get(self: CF64) [2]f64 {
            return .{
                (F64{ .piece0 = self.piece0, .piece1 = self.piece1 }).get(),
                (F64{ .piece0 = self.piece2, .piece1 = self.piece3 }).get(),
            };
        }

        fn pack(val: [2]f64) CF64 {
            const real = F64.pack(val[0]);
            const imag = F64.pack(val[1]);
            return .{
                .piece0 = real.piece0,
                .piece1 = real.piece1,
                .piece2 = imag.piece0,
                .piece3 = imag.piece1,
            };
        }
    };

    /// TODO pack into 5 pieces
    pub const CF80 = struct {
        piece0: u32,
        piece1: u32,
        piece2: u32, // u16 part, top bits
        piece3: u32,
        piece4: u32,
        piece5: u32, // u16 part, top bits

        pub fn get(self: CF80) [2]f80 {
            return .{
                (F80{ .piece0 = self.piece0, .piece1 = self.piece1, .piece2 = self.piece2 }).get(),
                (F80{ .piece0 = self.piece3, .piece1 = self.piece4, .piece2 = self.piece5 }).get(),
            };
        }

        fn pack(val: [2]f80) CF80 {
            const real = F80.pack(val[0]);
            const imag = F80.pack(val[1]);
            return .{
                .piece0 = real.piece0,
                .piece1 = real.piece1,
                .piece2 = real.piece2,
                .piece3 = imag.piece0,
                .piece4 = imag.piece1,
                .piece5 = imag.piece2,
            };
        }
    };

    pub const CF128 = struct {
        piece0: u32,
        piece1: u32,
        piece2: u32,
        piece3: u32,
        piece4: u32,
        piece5: u32,
        piece6: u32,
        piece7: u32,

        pub fn get(self: CF128) [2]f128 {
            return .{
                (F128{ .piece0 = self.piece0, .piece1 = self.piece1, .piece2 = self.piece2, .piece3 = self.piece3 }).get(),
                (F128{ .piece0 = self.piece4, .piece1 = self.piece5, .piece2 = self.piece6, .piece3 = self.piece7 }).get(),
            };
        }

        fn pack(val: [2]f128) CF128 {
            const real = F128.pack(val[0]);
            const imag = F128.pack(val[1]);
            return .{
                .piece0 = real.piece0,
                .piece1 = real.piece1,
                .piece2 = real.piece2,
                .piece3 = real.piece3,
                .piece4 = imag.piece0,
                .piece5 = imag.piece1,
                .piece6 = imag.piece2,
                .piece7 = imag.piece3,
            };
        }
    };

    pub const Bytes = struct {
        strings_index: u32,
        len: u32,
    };

    pub const Record = struct {
        elements_len: u32,
        // trailing
        // [elements_len]Ref
    };
}