structstd.zig.Zir.Inst.Capture[src]

Represents a single value being captured in a type declaration's closure.

Fields

tag: enum(u3) {
    /// `data` is a `u16` index into the parent closure.
    nested,
    /// `data` is a `Zir.Inst.Index` to an instruction whose value is being captured.
    instruction,
    /// `data` is a `Zir.Inst.Index` to an instruction representing an alloc whose contents is being captured.
    instruction_load,
    /// `data` is a `NullTerminatedString` to a decl name.
    decl_val,
    /// `data` is a `NullTerminatedString` to a decl name.
    decl_ref,
}
data: u29

Functions

Functionwrap[src]

pub fn wrap(cap: Unwrapped) Capture

Parameters

Source Code

Source code
pub fn wrap(cap: Unwrapped) Capture {
    return switch (cap) {
        .nested => |idx| .{
            .tag = .nested,
            .data = idx,
        },
        .instruction => |inst| .{
            .tag = .instruction,
            .data = @intCast(@intFromEnum(inst)),
        },
        .instruction_load => |inst| .{
            .tag = .instruction_load,
            .data = @intCast(@intFromEnum(inst)),
        },
        .decl_val => |str| .{
            .tag = .decl_val,
            .data = @intCast(@intFromEnum(str)),
        },
        .decl_ref => |str| .{
            .tag = .decl_ref,
            .data = @intCast(@intFromEnum(str)),
        },
    };
}

Functionunwrap[src]

pub fn unwrap(cap: Capture) Unwrapped

Parameters

cap: Capture

Source Code

Source code
pub fn unwrap(cap: Capture) Unwrapped {
    return switch (cap.tag) {
        .nested => .{ .nested = @intCast(cap.data) },
        .instruction => .{ .instruction = @enumFromInt(cap.data) },
        .instruction_load => .{ .instruction_load = @enumFromInt(cap.data) },
        .decl_val => .{ .decl_val = @enumFromInt(cap.data) },
        .decl_ref => .{ .decl_ref = @enumFromInt(cap.data) },
    };
}

Source Code

Source code
pub const Capture = packed struct(u32) {
    tag: enum(u3) {
        /// `data` is a `u16` index into the parent closure.
        nested,
        /// `data` is a `Zir.Inst.Index` to an instruction whose value is being captured.
        instruction,
        /// `data` is a `Zir.Inst.Index` to an instruction representing an alloc whose contents is being captured.
        instruction_load,
        /// `data` is a `NullTerminatedString` to a decl name.
        decl_val,
        /// `data` is a `NullTerminatedString` to a decl name.
        decl_ref,
    },
    data: u29,
    pub const Unwrapped = union(enum) {
        nested: u16,
        instruction: Zir.Inst.Index,
        instruction_load: Zir.Inst.Index,
        decl_val: NullTerminatedString,
        decl_ref: NullTerminatedString,
    };
    pub fn wrap(cap: Unwrapped) Capture {
        return switch (cap) {
            .nested => |idx| .{
                .tag = .nested,
                .data = idx,
            },
            .instruction => |inst| .{
                .tag = .instruction,
                .data = @intCast(@intFromEnum(inst)),
            },
            .instruction_load => |inst| .{
                .tag = .instruction_load,
                .data = @intCast(@intFromEnum(inst)),
            },
            .decl_val => |str| .{
                .tag = .decl_val,
                .data = @intCast(@intFromEnum(str)),
            },
            .decl_ref => |str| .{
                .tag = .decl_ref,
                .data = @intCast(@intFromEnum(str)),
            },
        };
    }
    pub fn unwrap(cap: Capture) Unwrapped {
        return switch (cap.tag) {
            .nested => .{ .nested = @intCast(cap.data) },
            .instruction => .{ .instruction = @enumFromInt(cap.data) },
            .instruction_load => .{ .instruction_load = @enumFromInt(cap.data) },
            .decl_val => .{ .decl_val = @enumFromInt(cap.data) },
            .decl_ref => .{ .decl_ref = @enumFromInt(cap.data) },
        };
    }
}