summaryrefslogtreecommitdiff
path: root/src/zisp/value
diff options
context:
space:
mode:
authorTaylan Kammer <taylan.kammer@gmail.com>2026-06-06 20:22:52 +0200
committerTaylan Kammer <taylan.kammer@gmail.com>2026-06-06 20:22:52 +0200
commit0d989d4b7c5507899721ae208b4ca605b4017e37 (patch)
treea7a49ab182c000399e58112bb6d937b01d8f1998 /src/zisp/value
parentafcc02f4f4af6cd462e20e0cecb20c35f1d9c198 (diff)
Cleanup.
Diffstat (limited to 'src/zisp/value')
-rw-r--r--src/zisp/value/array.zig10
-rw-r--r--src/zisp/value/istr.zig7
-rw-r--r--src/zisp/value/pair.zig4
-rw-r--r--src/zisp/value/ptr.zig10
4 files changed, 12 insertions, 19 deletions
diff --git a/src/zisp/value/array.zig b/src/zisp/value/array.zig
index 629d31c..f8e87bf 100644
--- a/src/zisp/value/array.zig
+++ b/src/zisp/value/array.zig
@@ -168,8 +168,7 @@ pub fn newString(alloc: Alloc, s: []const u8) !Value {
std.debug.assert(s.len <= std.math.maxInt(u48));
const algn = std.mem.Alignment.of(ArrayPtr);
const size = @sizeOf(ArrayHeader) + s.len;
- const ptr = try alloc.alignedAlloc(u8, algn, size);
- const arr: ArrayPtr = @ptrCast(ptr);
+ const arr: ArrayPtr = @ptrCast(try alloc.alignedAlloc(u8, algn, size));
arr.* = .{
.len_or_ptr = @intCast(s.len),
.type = .str,
@@ -177,12 +176,9 @@ pub fn newString(alloc: Alloc, s: []const u8) !Value {
};
const buf = arr.bufContent();
@memcpy(buf[0..s.len], s);
- return value.ptr.pack(arr, .array);
+ return value.ptr.pack(.array, arr);
}
pub fn check(v: Value) ?ArrayPtr {
- if (v.getPtr(.array)) |p| {
- return @ptrCast(p);
- }
- return null;
+ return v.getPtr(.array) orelse null;
}
diff --git a/src/zisp/value/istr.zig b/src/zisp/value/istr.zig
index 551ea1e..9accd27 100644
--- a/src/zisp/value/istr.zig
+++ b/src/zisp/value/istr.zig
@@ -38,10 +38,7 @@ pub const IstrHead = packed struct(u8) {
};
pub fn check(v: Value) ?IstrPtr {
- if (v.getPtr(.istr)) |p| {
- return @ptrCast(p);
- }
- return null;
+ return v.getPtr(.istr) orelse null;
}
pub fn assert(v: Value) IstrPtr {
@@ -71,7 +68,7 @@ pub fn new(alloc: Alloc, s: []const u8) !IstrPtr {
}
pub fn pack(istr: IstrPtr) Value {
- return value.ptr.pack(@ptrCast(istr), .istr);
+ return value.ptr.pack(.istr, istr);
}
pub fn getOrNew(s: []const u8) !Value {
diff --git a/src/zisp/value/pair.zig b/src/zisp/value/pair.zig
index edc106d..f2a27a0 100644
--- a/src/zisp/value/pair.zig
+++ b/src/zisp/value/pair.zig
@@ -18,7 +18,7 @@ pub const Pair = struct {
// Zig API
pub fn check(v: Value) ?PairPtr {
- return @ptrCast(v.getPtr(.pair));
+ return v.getPtr(.pair);
}
pub fn assert(v: Value) PairPtr {
@@ -34,7 +34,7 @@ pub fn unpack(v: Value) PairPtr {
pub fn consInPool(pool: *PairPool, car: Value, cdr: Value) !Value {
const pair = try pool.cons(car, cdr);
- return ptr.pack(@ptrCast(pair), .pair);
+ return ptr.pack(.pair, pair);
}
// Zisp API
diff --git a/src/zisp/value/ptr.zig b/src/zisp/value/ptr.zig
index 8696056..e6f2639 100644
--- a/src/zisp/value/ptr.zig
+++ b/src/zisp/value/ptr.zig
@@ -31,19 +31,19 @@ pub fn assertWeak(v: Value) void {
}
}
-pub fn _pack(ptr: Zptr, tag: PtrTag, is_weak: bool) Value {
+pub fn _pack(comptime tag: PtrTag, ptr: tag.ptrType(), 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(ptr: Zptr, tag: PtrTag) Value {
- return _pack(ptr, tag, false);
+pub fn pack(comptime tag: PtrTag, ptr: tag.ptrType()) Value {
+ return _pack(tag, ptr, false);
}
-pub fn packWeak(ptr: Zptr, tag: PtrTag) Value {
- return _pack(ptr, tag, true);
+pub fn packWeak(comptime tag: PtrTag, ptr: tag.ptrType()) Value {
+ return _pack(tag, ptr, true);
}
pub fn setWeakNull(v: *Value) void {