fixing casts unit tests
All checks were successful
Build / build (push) Successful in 1m36s
Test / build (push) Successful in 5m39s

This commit is contained in:
2026-01-18 00:30:15 +01:00
parent 8b0b0a72ae
commit 8bdea7b1fc
3 changed files with 98 additions and 42 deletions

View File

@@ -185,15 +185,7 @@ pub const Value = union(Type) {
}
};
const Self = @This();
name: ?[]const u8,
decorations: std.ArrayList(Decoration),
parent: ?*const Self,
variant: ?union(Variant) {
pub const VariantData = union(Variant) {
String: []const u8,
Extension: struct {},
Type: union(Type) {
@@ -265,7 +257,17 @@ variant: ?union(Variant) {
Label: struct {
source_location: usize,
},
},
};
const Self = @This();
name: ?[]const u8,
decorations: std.ArrayList(Decoration),
parent: ?*const Self,
variant: ?VariantData,
pub fn init() Self {
return .{
@@ -305,7 +307,7 @@ pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
}
pub fn getValueTypeWord(self: *Self) RuntimeError!SpvWord {
return switch (self.variant orelse return RuntimeError.InvalidSpirV) {
return switch ((try self.getVariant()).*) {
.Variable => |v| v.type_word,
.Constant => |c| c.type_word,
.AccessChain => |*a| a.target,
@@ -315,7 +317,7 @@ pub fn getValueTypeWord(self: *Self) RuntimeError!SpvWord {
}
pub fn getValueType(self: *Self) RuntimeError!Type {
return switch (self.variant orelse return RuntimeError.InvalidSpirV) {
return switch ((try self.getVariant()).*) {
.Variable => |v| v.type,
.Constant => |c| c.type,
.FunctionParameter => |p| p.type,
@@ -324,7 +326,7 @@ pub fn getValueType(self: *Self) RuntimeError!Type {
}
pub fn getValue(self: *Self) RuntimeError!*Value {
return switch (self.variant orelse return RuntimeError.InvalidSpirV) {
return switch ((try self.getVariant()).*) {
.Variable => |*v| &v.value,
.Constant => |*c| &c.value,
.AccessChain => |*a| &a.value,
@@ -333,6 +335,14 @@ pub fn getValue(self: *Self) RuntimeError!*Value {
};
}
pub inline fn getVariant(self: *Self) RuntimeError!*VariantData {
return &(self.variant orelse return RuntimeError.InvalidSpirV);
}
pub inline fn getConstVariant(self: *const Self) RuntimeError!*const VariantData {
return &(self.variant orelse return RuntimeError.InvalidSpirV);
}
/// Performs a deep copy
pub fn dupe(self: *const Self, allocator: std.mem.Allocator) RuntimeError!Self {
return .{