From 86e77fc35b3a9146a31b872643a85f8f6a486a07 Mon Sep 17 00:00:00 2001 From: Taylan Kammer Date: Thu, 2 Jul 2026 06:14:48 +0200 Subject: Exciting things are happening. - Vague Posting King --- src/zisp/value.zig | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/zisp/value.zig') 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. -- cgit v1.2.3