summaryrefslogtreecommitdiff
path: root/src/zisp/value
diff options
context:
space:
mode:
Diffstat (limited to 'src/zisp/value')
-rw-r--r--src/zisp/value/array.zig20
-rw-r--r--src/zisp/value/pair.zig2
-rw-r--r--src/zisp/value/ptr.zig15
3 files changed, 18 insertions, 19 deletions
diff --git a/src/zisp/value/array.zig b/src/zisp/value/array.zig
index 6be3c9c..ad04ce2 100644
--- a/src/zisp/value/array.zig
+++ b/src/zisp/value/array.zig
@@ -81,22 +81,24 @@ pub const ArrayHeader = packed struct(u64) {
},
},
- fn bufU64(self: *@This()) [*]u64 {
+ const Self = @This();
+
+ fn bufU64(self: *Self) [*]u64 {
return @ptrCast(self);
}
- fn bufContent(self: *@This()) [*]u8 {
+ fn bufContent(self: *Self) [*]u8 {
std.debug.assert(!self.is_ptr);
return @ptrCast(self.bufU64() + 1);
}
- fn bufPointer(self: *@This()) [*]u8 {
+ fn bufPointer(self: *Self) [*]u8 {
std.debug.assert(self.is_ptr);
std.debug.assert(self.len_or_ptr == 0);
return @ptrFromInt(self.bufU64()[1]);
}
- fn eltSize(self: *@This()) u16 {
+ fn eltSize(self: *Self) u16 {
std.debug.assert(!self.is_ptr);
return switch (self.type) {
.str => 1,
@@ -104,18 +106,18 @@ pub const ArrayHeader = packed struct(u64) {
};
}
- fn size(self: *@This()) usize {
+ fn size(self: *Self) usize {
std.debug.assert(!self.is_ptr);
return self.len_or_ptr * self.eltSize();
}
- fn arrPointer(self: *@This()) ?ArrayPtr {
+ fn arrPointer(self: *Self) ?ArrayPtr {
std.debug.assert(self.is_ptr);
const p = self.len_or_ptr;
return if (p != 0) @ptrFromInt(p) else null;
}
- fn sliceInfo(self: *@This()) [2]u64 {
+ fn sliceInfo(self: *Self) [2]u64 {
std.debug.assert(self.is_slice);
const ptr = self.len_or_ptr;
const buf = self.bufU64();
@@ -126,7 +128,7 @@ pub const ArrayHeader = packed struct(u64) {
}
}
- pub fn bufU8(self: *@This()) [*]u8 {
+ pub fn bufU8(self: *Self) [*]u8 {
if (self.is_ptr) {
if (self.arrPointer()) |a| {
return a.bufContent();
@@ -138,7 +140,7 @@ pub const ArrayHeader = packed struct(u64) {
}
}
- pub fn str(self: *@This()) []const u8 {
+ pub fn str(self: *Self) []const u8 {
if (self.is_slice) {
const buf = self.bufU8();
const start, const end = self.sliceInfo();
diff --git a/src/zisp/value/pair.zig b/src/zisp/value/pair.zig
index 4ae38a3..09e50f2 100644
--- a/src/zisp/value/pair.zig
+++ b/src/zisp/value/pair.zig
@@ -6,7 +6,7 @@ const ptr = @import("ptr.zig");
const PairPool = gc.PairPool;
const Value = value.Value;
-pub const PairPtr = *align(8) Pair;
+pub const PairPtr = *align(@alignOf(value.Zptr)) Pair;
pub const Pair = struct {
car: Value,
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