| ... | @@ -1340,6 +1340,14 @@ pub const Value = extern union { | ... | @@ -1340,6 +1340,14 @@ pub const Value = extern union { |
| 1340 | const int = mod.global_error_set.get(val.castTag(.@"error").?.data.name).?; | 1340 | const int = mod.global_error_set.get(val.castTag(.@"error").?.data.name).?; |
| 1341 | std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian); | 1341 | std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian); |
| 1342 | }, | 1342 | }, |
| | 1343 | .Union => switch (ty.containerLayout()) { |
| | 1344 | .Auto => unreachable, |
| | 1345 | .Extern => @panic("TODO implement writeToMemory for extern unions"), |
| | 1346 | .Packed => { |
| | 1347 | const byte_count = (@intCast(usize, ty.bitSize(target)) + 7) / 8; |
| | 1348 | writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0); |
| | 1349 | }, |
| | 1350 | }, |
| 1343 | else => @panic("TODO implement writeToMemory for more types"), | 1351 | else => @panic("TODO implement writeToMemory for more types"), |
| 1344 | } | 1352 | } |
| 1345 | } | 1353 | } |
| ... | @@ -1430,6 +1438,17 @@ pub const Value = extern union { | ... | @@ -1430,6 +1438,17 @@ pub const Value = extern union { |
| 1430 | } | 1438 | } |
| 1431 | }, | 1439 | }, |
| 1432 | }, | 1440 | }, |
| | 1441 | .Union => switch (ty.containerLayout()) { |
| | 1442 | .Auto => unreachable, // Sema is supposed to have emitted a compile error already |
| | 1443 | .Extern => unreachable, // Handled in non-packed writeToMemory |
| | 1444 | .Packed => { |
| | 1445 | const field_index = ty.unionTagFieldIndex(val.unionTag(), mod); |
| | 1446 | const field_type = ty.unionFields().values()[field_index.?].ty; |
| | 1447 | const field_val = val.fieldValue(field_type, field_index.?); |
| | 1448 | |
| | 1449 | field_val.writeToPackedMemory(field_type, mod, buffer, bit_offset); |
| | 1450 | }, |
| | 1451 | }, |
| 1433 | else => @panic("TODO implement writeToPackedMemory for more types"), | 1452 | else => @panic("TODO implement writeToPackedMemory for more types"), |
| 1434 | } | 1453 | } |
| 1435 | } | 1454 | } |