| ... | @@ -1365,6 +1365,17 @@ pub const Value = extern union { | ... | @@ -1365,6 +1365,17 @@ pub const Value = extern union { |
| 1365 | if (val.isDeclRef()) return error.ReinterpretDeclRef; | 1365 | if (val.isDeclRef()) return error.ReinterpretDeclRef; |
| 1366 | return val.writeToMemory(Type.usize, mod, buffer); | 1366 | return val.writeToMemory(Type.usize, mod, buffer); |
| 1367 | }, | 1367 | }, |
| | 1368 | .Optional => { |
| | 1369 | assert(ty.isPtrLikeOptional()); |
| | 1370 | var buf: Type.Payload.ElemType = undefined; |
| | 1371 | const child = ty.optionalChild(&buf); |
| | 1372 | const opt_val = val.optionalValue(); |
| | 1373 | if (opt_val) |some| { |
| | 1374 | return some.writeToMemory(child, mod, buffer); |
| | 1375 | } else { |
| | 1376 | return writeToMemory(Value.zero, Type.usize, mod, buffer); |
| | 1377 | } |
| | 1378 | }, |
| 1368 | else => @panic("TODO implement writeToMemory for more types"), | 1379 | else => @panic("TODO implement writeToMemory for more types"), |
| 1369 | } | 1380 | } |
| 1370 | } | 1381 | } |
| ... | @@ -1471,6 +1482,17 @@ pub const Value = extern union { | ... | @@ -1471,6 +1482,17 @@ pub const Value = extern union { |
| 1471 | if (val.isDeclRef()) return error.ReinterpretDeclRef; | 1482 | if (val.isDeclRef()) return error.ReinterpretDeclRef; |
| 1472 | return val.writeToPackedMemory(Type.usize, mod, buffer, bit_offset); | 1483 | return val.writeToPackedMemory(Type.usize, mod, buffer, bit_offset); |
| 1473 | }, | 1484 | }, |
| | 1485 | .Optional => { |
| | 1486 | assert(ty.isPtrLikeOptional()); |
| | 1487 | var buf: Type.Payload.ElemType = undefined; |
| | 1488 | const child = ty.optionalChild(&buf); |
| | 1489 | const opt_val = val.optionalValue(); |
| | 1490 | if (opt_val) |some| { |
| | 1491 | return some.writeToPackedMemory(child, mod, buffer, bit_offset); |
| | 1492 | } else { |
| | 1493 | return writeToPackedMemory(Value.zero, Type.usize, mod, buffer, bit_offset); |
| | 1494 | } |
| | 1495 | }, |
| 1474 | else => @panic("TODO implement writeToPackedMemory for more types"), | 1496 | else => @panic("TODO implement writeToPackedMemory for more types"), |
| 1475 | } | 1497 | } |
| 1476 | } | 1498 | } |
| ... | @@ -1579,6 +1601,12 @@ pub const Value = extern union { | ... | @@ -1579,6 +1601,12 @@ pub const Value = extern union { |
| 1579 | assert(!ty.isSlice()); // No well defined layout. | 1601 | assert(!ty.isSlice()); // No well defined layout. |
| 1580 | return readFromMemory(Type.usize, mod, buffer, arena); | 1602 | return readFromMemory(Type.usize, mod, buffer, arena); |
| 1581 | }, | 1603 | }, |
| | 1604 | .Optional => { |
| | 1605 | assert(ty.isPtrLikeOptional()); |
| | 1606 | var buf: Type.Payload.ElemType = undefined; |
| | 1607 | const child = ty.optionalChild(&buf); |
| | 1608 | return readFromMemory(child, mod, buffer, arena); |
| | 1609 | }, |
| 1582 | else => @panic("TODO implement readFromMemory for more types"), | 1610 | else => @panic("TODO implement readFromMemory for more types"), |
| 1583 | } | 1611 | } |
| 1584 | } | 1612 | } |
| ... | @@ -1670,6 +1698,12 @@ pub const Value = extern union { | ... | @@ -1670,6 +1698,12 @@ pub const Value = extern union { |
| 1670 | assert(!ty.isSlice()); // No well defined layout. | 1698 | assert(!ty.isSlice()); // No well defined layout. |
| 1671 | return readFromPackedMemory(Type.usize, mod, buffer, bit_offset, arena); | 1699 | return readFromPackedMemory(Type.usize, mod, buffer, bit_offset, arena); |
| 1672 | }, | 1700 | }, |
| | 1701 | .Optional => { |
| | 1702 | assert(ty.isPtrLikeOptional()); |
| | 1703 | var buf: Type.Payload.ElemType = undefined; |
| | 1704 | const child = ty.optionalChild(&buf); |
| | 1705 | return readFromPackedMemory(child, mod, buffer, bit_offset, arena); |
| | 1706 | }, |
| 1673 | else => @panic("TODO implement readFromPackedMemory for more types"), | 1707 | else => @panic("TODO implement readFromPackedMemory for more types"), |
| 1674 | } | 1708 | } |
| 1675 | } | 1709 | } |