enum Value [src]

Fields

none = std.math.maxInt(u31)
false = first_constant + @intFromEnum(Constant.false)
true = first_constant + @intFromEnum(Constant.true)
@"0" = first_constant + @intFromEnum(Constant.@"0")
@"1" = first_constant + @intFromEnum(Constant.@"1")
_

Members

Source

pub const Value = enum(u32) { none = std.math.maxInt(u31), false = first_constant + @intFromEnum(Constant.false), true = first_constant + @intFromEnum(Constant.true), @"0" = first_constant + @intFromEnum(Constant.@"0"), @"1" = first_constant + @intFromEnum(Constant.@"1"), _, const first_constant = 1 << 30; const first_metadata = 1 << 31; pub fn unwrap(self: Value) union(enum) { instruction: Function.Instruction.Index, constant: Constant, metadata: Metadata, } { return if (@intFromEnum(self) < first_constant) .{ .instruction = @enumFromInt(@intFromEnum(self)) } else if (@intFromEnum(self) < first_metadata) .{ .constant = @enumFromInt(@intFromEnum(self) - first_constant) } else .{ .metadata = @enumFromInt(@intFromEnum(self) - first_metadata) }; } pub fn typeOfWip(self: Value, wip: *const WipFunction) Type { return switch (self.unwrap()) { .instruction => |instruction| instruction.typeOfWip(wip), .constant => |constant| constant.typeOf(wip.builder), .metadata => .metadata, }; } pub fn typeOf(self: Value, function: Function.Index, builder: *Builder) Type { return switch (self.unwrap()) { .instruction => |instruction| instruction.typeOf(function, builder), .constant => |constant| constant.typeOf(builder), .metadata => .metadata, }; } pub fn toConst(self: Value) ?Constant { return switch (self.unwrap()) { .instruction, .metadata => null, .constant => |constant| constant, }; } const FormatData = struct { value: Value, function: Function.Index, builder: *Builder, }; fn format( data: FormatData, comptime fmt_str: []const u8, fmt_opts: std.fmt.FormatOptions, writer: anytype, ) @TypeOf(writer).Error!void { switch (data.value.unwrap()) { .instruction => |instruction| try Function.Instruction.Index.format(.{ .instruction = instruction, .function = data.function, .builder = data.builder, }, fmt_str, fmt_opts, writer), .constant => |constant| try Constant.format(.{ .constant = constant, .builder = data.builder, }, fmt_str, fmt_opts, writer), .metadata => unreachable, } } pub fn fmt(self: Value, function: Function.Index, builder: *Builder) std.fmt.Formatter(format) { return .{ .data = .{ .value = self, .function = function, .builder = builder } }; } }