summaryrefslogtreecommitdiff
path: root/src/zisp/value/hptr.zig
diff options
context:
space:
mode:
authorTaylan Kammer <taylan.kammer@gmail.com>2026-08-16 10:01:12 +0200
committerTaylan Kammer <taylan.kammer@gmail.com>2026-08-16 10:01:12 +0200
commite26e81aa33dc1ecc2f26de26b1d420d288a28493 (patch)
treed0c906f3b6d504870a171f57709c6e912a3fc9c4 /src/zisp/value/hptr.zig
parent0e073b94c90b78ebe156adb27ec4456e86935d42 (diff)
Implemented meta allocator.
Diffstat (limited to 'src/zisp/value/hptr.zig')
-rw-r--r--src/zisp/value/hptr.zig33
1 files changed, 33 insertions, 0 deletions
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;
+}