From 627a09b58f404b1f690d27869b15b3197207c0af Mon Sep 17 00:00:00 2001 From: Taylan Kammer Date: Mon, 8 Jun 2026 05:54:07 +0200 Subject: Code cleanup and make heap alloc 16-byte aligned. --- src/zisp/value/ptr.zig | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/zisp/value/ptr.zig') diff --git a/src/zisp/value/ptr.zig b/src/zisp/value/ptr.zig index e6f2639..ef12f79 100644 --- a/src/zisp/value/ptr.zig +++ b/src/zisp/value/ptr.zig @@ -7,6 +7,8 @@ const PtrTag = value.PtrTag; const Value = value.Value; const Zptr = value.Zptr; +const max = std.math.maxInt; + // Zig API pub fn check(v: Value) bool { @@ -31,18 +33,18 @@ pub fn assertWeak(v: Value) void { } } -pub fn _pack(comptime tag: PtrTag, ptr: tag.ptrType(), is_weak: bool) Value { +pub fn _pack(comptime tag: PtrTag, ptr: tag.ptype(), is_weak: bool) Value { const ptr_val: usize = @intFromPtr(ptr); std.debug.assert(ptr_val < std.math.maxInt(u48)); const tagged: u48 = @intCast(ptr_val | @intFromEnum(tag)); return .{ .ptr = .{ .tagged_value = tagged, .is_weak = is_weak } }; } -pub fn pack(comptime tag: PtrTag, ptr: tag.ptrType()) Value { +pub fn pack(comptime tag: PtrTag, ptr: tag.ptype()) Value { return _pack(tag, ptr, false); } -pub fn packWeak(comptime tag: PtrTag, ptr: tag.ptrType()) Value { +pub fn packWeak(comptime tag: PtrTag, ptr: tag.ptype()) Value { return _pack(tag, ptr, true); } @@ -58,12 +60,7 @@ pub fn isWeakNull(v: Value) bool { pub fn unpack(v: Value) struct { Zptr, PtrTag } { assert(v); - const tagged = v.ptr.tagged_value; - const ptr_val: u48 = tagged & ~@as(u48, 7); - const tag_val: u3 = @intCast(tagged & 7); - const ptr: Zptr = @ptrFromInt(ptr_val); - const tag: PtrTag = @enumFromInt(tag_val); - return .{ ptr, tag }; + return v.getPtrAny() orelse unreachable; } // Zisp API -- cgit v1.2.3