authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-08 20:04:40-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-15 03:07:51-04:00
log81664f17d5ec4382057bc3d2c8774d8804791a04
tree944f5df8addce217e221c0c867b3b9781cce6048
parente36e9323f4c4ce66013ba4774ff0145fc9cad34d

codegen: implement global enum_numbered


2 files changed, 9 insertions(+), 7 deletions(-)

src/codegen.zig+9-5
...@@ -1189,12 +1189,16 @@ pub fn genTypedValue(...@@ -1189,12 +1189,16 @@ pub fn genTypedValue(
1189 .enum_simple => {1189 .enum_simple => {
1190 return GenResult.mcv(.{ .immediate = field_index.data });1190 return GenResult.mcv(.{ .immediate = field_index.data });
1191 },1191 },
1192 .enum_full, .enum_nonexhaustive => {1192 .enum_numbered, .enum_full, .enum_nonexhaustive => {
1193 const enum_full = typed_value.ty.cast(Type.Payload.EnumFull).?.data;1193 const enum_values = if (typed_value.ty.castTag(.enum_numbered)) |pl|
1194 if (enum_full.values.count() != 0) {1194 pl.data.values
1195 const tag_val = enum_full.values.keys()[field_index.data];1195 else
1196 typed_value.ty.cast(Type.Payload.EnumFull).?.data.values;
1197 if (enum_values.count() != 0) {
1198 const tag_val = enum_values.keys()[field_index.data];
1199 var buf: Type.Payload.Bits = undefined;
1196 return genTypedValue(bin_file, src_loc, .{1200 return genTypedValue(bin_file, src_loc, .{
1197 .ty = enum_full.tag_ty,1201 .ty = typed_value.ty.intTagType(&buf),
1198 .val = tag_val,1202 .val = tag_val,
1199 }, owner_decl_index);1203 }, owner_decl_index);
1200 } else {1204 } else {
test/behavior/union.zig-2
...@@ -362,7 +362,6 @@ const MultipleChoice = union(enum(u32)) {...@@ -362,7 +362,6 @@ const MultipleChoice = union(enum(u32)) {
362 D = 1000,362 D = 1000,
363};363};
364test "simple union(enum(u32))" {364test "simple union(enum(u32))" {
365 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
366 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;365 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
367 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;366 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
368 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO367 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
...@@ -641,7 +640,6 @@ test "tagged union with all void fields but a meaningful tag" {...@@ -641,7 +640,6 @@ test "tagged union with all void fields but a meaningful tag" {
641}640}
642641
643test "union(enum(u32)) with specified and unspecified tag values" {642test "union(enum(u32)) with specified and unspecified tag values" {
644 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
645 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;643 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
646 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;644 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
647 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO645 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO