From 8375b71f75c8b8567bc7d97867716c4911dace65 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 18 Jan 2022 18:10:15 -0700 Subject: Sema: implement declarations for `@typeInfo` In the behavior test listings, I had to move type_info.zig test import to a section that did not include the x86 backend because it got to the point where adding another test to the file, even if it was an empty test that just returned immediately, caused a runtime failure when executing the test binary. Anyway, type info for opaques is implemented, and the declarations slice is shared between it, enums, and unions. Still TODO is the `data` field of a `Declaration`. I want to consider removing it from the data returned from `@typeInfo` and introducing `@declInfo` or similar for this data. This would avoid the complexity of a lazy mechanism. --- src/value.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/value.zig') diff --git a/src/value.zig b/src/value.zig index 1836a14ce0..c043bc9364 100644 --- a/src/value.zig +++ b/src/value.zig @@ -768,7 +768,12 @@ pub const Value = extern union { return allocator.dupe(u8, adjusted_bytes); }, .enum_literal => return allocator.dupe(u8, val.castTag(.enum_literal).?.data), - .repeated => @panic("TODO implement toAllocatedBytes for this Value tag"), + .repeated => { + const byte = @intCast(u8, val.castTag(.repeated).?.data.toUnsignedInt()); + const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen())); + std.mem.set(u8, result, byte); + return result; + }, .decl_ref => { const decl = val.castTag(.decl_ref).?.data; const decl_val = try decl.value(); @@ -776,7 +781,15 @@ pub const Value = extern union { }, .the_only_possible_value => return &[_]u8{}, .slice => return toAllocatedBytes(val.castTag(.slice).?.data.ptr, ty, allocator), - else => unreachable, + else => { + const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen())); + var elem_value_buf: ElemValueBuffer = undefined; + for (result) |*elem, i| { + const elem_val = val.elemValueBuffer(i, &elem_value_buf); + elem.* = @intCast(u8, elem_val.toUnsignedInt()); + } + return result; + }, } } -- cgit v1.2.3