authorgravatar for 105348204+DerryAlex@users.noreply.github.comDerryAlex <105348204+DerryAlex@users.noreply.github.com> 2023-03-14 19:08:56+08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-03-14 13:08:56+02:00
logd6e48abde87400a8a4851c7ab8c918005d81d058
treec87cf804f76125ebc1979e63e705d8e127a178eb
parent9ecdcb8e300a4f6aac050e3118ceea0b7d35f899
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Implement readFromMemory/writeToMemory for ptrLikeOptional


1 files changed, 34 insertions(+), 0 deletions(-)

src/value.zig+34
......@@ -1365,6 +1365,17 @@ pub const Value = extern union {
13651365 if (val.isDeclRef()) return error.ReinterpretDeclRef;
13661366 return val.writeToMemory(Type.usize, mod, buffer);
13671367 },
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 },
13681379 else => @panic("TODO implement writeToMemory for more types"),
13691380 }
13701381 }
......@@ -1471,6 +1482,17 @@ pub const Value = extern union {
14711482 if (val.isDeclRef()) return error.ReinterpretDeclRef;
14721483 return val.writeToPackedMemory(Type.usize, mod, buffer, bit_offset);
14731484 },
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 },
14741496 else => @panic("TODO implement writeToPackedMemory for more types"),
14751497 }
14761498 }
......@@ -1579,6 +1601,12 @@ pub const Value = extern union {
15791601 assert(!ty.isSlice()); // No well defined layout.
15801602 return readFromMemory(Type.usize, mod, buffer, arena);
15811603 },
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 },
15821610 else => @panic("TODO implement readFromMemory for more types"),
15831611 }
15841612 }
......@@ -1670,6 +1698,12 @@ pub const Value = extern union {
16701698 assert(!ty.isSlice()); // No well defined layout.
16711699 return readFromPackedMemory(Type.usize, mod, buffer, bit_offset, arena);
16721700 },
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 },
16731707 else => @panic("TODO implement readFromPackedMemory for more types"),
16741708 }
16751709 }