diff options
Diffstat (limited to 'src/zisp/value.zig')
| -rw-r--r-- | src/zisp/value.zig | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/zisp/value.zig b/src/zisp/value.zig index 4ce6cd2..2ae0524 100644 --- a/src/zisp/value.zig +++ b/src/zisp/value.zig @@ -269,16 +269,16 @@ pub const Value = packed union { } /// Checks for a pointer and returns the value and tag separately, or null - /// if this isn't a pointer or null. Could be useful for a dispatch table. - pub fn getPtrAny(v: Value) ?struct { Zptr, HeapType } { + /// if this isn't a pointer at all. Could be useful for a dispatch table. + /// Note that unlike getPtr(), this can actually return a null pointer as + /// such, not conflating it with the "not a heap pointer" case. + pub fn getPtrAny(v: Value) ?struct { ?Zptr, HeapType } { const hi16_bits: u16 = @intCast(v.bits >> 48); if (hi16_bits != hi16_tag_ptr) return null; - const ptr_val: u48 = @intCast(v.bits << 20 >> 16); - if (ptr_val == 0) return null; - - const ht_val: u4 = @intCast(v.bits << 16 >> 60); - return .{ @ptrFromInt(ptr_val), @enumFromInt(ht_val) }; + const ht: u4 = @truncate(hi16_bits); + const pval: u48 = @intCast(v.bits << 20 >> 16); + return .{ @ptrFromInt(pval), @enumFromInt(ht) }; } /// Checks if the value is a list pointer. |
