summaryrefslogtreecommitdiff
path: root/src/zisp/value.zig
diff options
context:
space:
mode:
authorTaylan Kammer <taylan.kammer@gmail.com>2026-07-02 06:14:48 +0200
committerTaylan Kammer <taylan.kammer@gmail.com>2026-07-02 06:14:48 +0200
commit86e77fc35b3a9146a31b872643a85f8f6a486a07 (patch)
tree056a35081a7f5d87d351c710ae6f34ee7c0c5e9c /src/zisp/value.zig
parentb0043e83d3bf2f4d49bf1f153d65c48b4fabb4f6 (diff)
Exciting things are happening. - Vague Posting King
Diffstat (limited to 'src/zisp/value.zig')
-rw-r--r--src/zisp/value.zig32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/zisp/value.zig b/src/zisp/value.zig
index 9262a17..1a63349 100644
--- a/src/zisp/value.zig
+++ b/src/zisp/value.zig
@@ -19,6 +19,7 @@ pub const sval = @import("value/sval.zig");
pub const char = @import("value/char.zig");
pub const misc = @import("value/misc.zig");
+pub const pair = @import("value/pair.zig");
pub const array = @import("value/array.zig");
pub const boole = @import("value/boole.zig");
@@ -50,7 +51,7 @@ pub fn runeXsstr(v: Value) Value {
}
pub const MiscValue = enum(u8) {
- // Make f/t only differ in one bit, to make `bool?` more efficient.
+ // Make sure f/t only differ in one bit, to make `bool?` more efficient.
/// False
f = 0,
/// True
@@ -71,20 +72,39 @@ pub const eof = Value{ .misc = .{ .value = .eof } };
pub const none = Value{ .misc = .{ .value = .none } };
// zig fmt: on
-/// A plain (unpacked, untagged) pointer into the Zisp heap.
-pub const HeapPtr = *anyopaque;
+/// A plain (unpacked, untagged, uncompressed) pointer into the main heap.
+pub const HeapPtr = *align(8) anyopaque;
-/// Values for the lowest 4 bits of a heap pointer, indicating the heap type.
+/// Values for the 8 type bits on main heap pointers.
pub const HeapType = enum(u8) {
+ /// Pair (car, cdr)
+ pair,
/// Array of various types: see `ArrayPtr`.
array,
+ pub fn ObjType(self: HeapType) type {
+ return switch (self) {
+ .pair => pair.Pair,
+ .array => array.ArrayHeader,
+ else => @panic("Invalid HeapType."),
+ };
+ }
+
pub fn PtrType(self: HeapType) type {
return switch (self) {
+ .pair => pair.PairPtr,
.array => array.ArrayPtr,
else => @panic("Invalid HeapType."),
};
}
+
+ pub fn of(ptr: anytype) HeapType {
+ return switch (@TypeOf(ptr)) {
+ PairPtr => .pair,
+ ArrayHeader => .array,
+ else => @panic("Unknown heap pointer."),
+ };
+ }
};
fn hi16(comptime tag: u4) u16 {
@@ -275,8 +295,8 @@ pub const Value = packed union {
}
/// Check for heap pointer (given type).
- pub fn isHptrTyp(v: Value, comptime htype: HeapType) bool {
- return v.hptr._hi == hi16_hptr and v.htptr.typ == htype;
+ pub fn isHptrTyp(v: Value, comptime typ: HeapType) bool {
+ return v.hptr._hi == hi16_hptr and v.hptr.typ == typ;
}
/// Check for istr pointer.