blob: 3a6995b221a666754896b02d6830284cb381c991 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 { Zptr, HeapType } {
assert(v);
return v.getPtrAny() orelse unreachable;
}
|