From e26e81aa33dc1ecc2f26de26b1d420d288a28493 Mon Sep 17 00:00:00 2001 From: Taylan Kammer Date: Sun, 16 Aug 2026 10:01:12 +0200 Subject: Implemented meta allocator. --- src/zisp/value/hptr.zig | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/zisp/value/hptr.zig (limited to 'src/zisp/value/hptr.zig') diff --git a/src/zisp/value/hptr.zig b/src/zisp/value/hptr.zig new file mode 100644 index 0000000..8a3ca18 --- /dev/null +++ b/src/zisp/value/hptr.zig @@ -0,0 +1,33 @@ +const std = @import("std"); + +const gc = @import("../gc.zig"); +const value = @import("../value.zig"); + +const HeapType = value.HeapType; +const Value = value.Value; +const Zptr = value.Zptr; + +const max = std.math.maxInt; + +// Zig API + +pub fn check(v: Value) bool { + return v.isPtrAny(); +} + +pub fn assert(v: Value) void { + if (!check(v)) { + v.dump(); + @panic("not pointer"); + } +} + +pub fn pack(comptime ht: HeapType, ptr: ht.PtrType()) Value { + const index: u44 = @intCast(@intFromPtr(ptr) >> 4); + return .{ .ptr = .{ .index = index, .htype = ht } }; +} + +pub fn unpack(v: Value) struct { HeapType, ?Zptr } { + assert(v); + return v.getPtrAny() orelse unreachable; +} -- cgit v1.2.3