vtables, protocol
This commit is contained in:
@@ -200,6 +200,36 @@ pub const Type = union(enum) {
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns the canonical type name for this type, or null for complex types.
|
||||
/// Used for looking up impl methods on non-struct types (e.g., s32.eq).
|
||||
pub fn toName(self: Type) ?[]const u8 {
|
||||
return switch (self) {
|
||||
.signed => |w| switch (w) {
|
||||
8 => "s8",
|
||||
16 => "s16",
|
||||
32 => "s32",
|
||||
64 => "s64",
|
||||
else => null,
|
||||
},
|
||||
.unsigned => |w| switch (w) {
|
||||
8 => "u8",
|
||||
16 => "u16",
|
||||
32 => "u32",
|
||||
64 => "u64",
|
||||
else => null,
|
||||
},
|
||||
.f32 => "f32",
|
||||
.f64 => "f64",
|
||||
.boolean => "bool",
|
||||
.string_type => "string",
|
||||
.void_type => "void",
|
||||
.struct_type => |n| n,
|
||||
.enum_type => |n| n,
|
||||
.union_type => |n| n,
|
||||
else => null,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn fromTypeExpr(node: *Node) ?Type {
|
||||
if (node.data != .type_expr) return null;
|
||||
return fromName(node.data.type_expr.name);
|
||||
|
||||
Reference in New Issue
Block a user