const std = @import("std"); const value = @import("../value.zig"); const gc = @import("../gc.zig"); const ptr = @import("ptr.zig"); const seq = @import("seq.zig"); const Hval = gc.Hval; const Value = value.Value; // Zig API pub fn check(v: Value) bool { return ptr.checkZispTag(v, .seq); } pub fn assert(v: Value) void { if (!check(v)) { v.dump(); @panic("not istr"); } } pub fn intern(str: []const u8, quoted: bool) Value { if (str.len > value.fixnum.max) { @panic("String length out of fixnum range."); } const header: seq.Header = .{ .type = .string, .info = .{ .string = .{ .enc = .utf8, .quoted = quoted, .interned = true, } }, .size = @intCast(str.len), }; const header_ptr = gc.intern(header, str); return ptr.pack(@ptrCast(header_ptr), .seq); } pub fn getHeader(v: Value) *seq.Header { assert(v); const header_ptr, _ = ptr.unpack(v); return gc.istrHeader(header_ptr); } pub fn getHeaderFromPtr(p: *Hval) *seq.Header { return gc.istrHeader(p); } // Zisp API pub fn pred(v: Value) Value { return value.boole.pack(check(v)); } pub fn len(v: Value) Value { const l = getHeader(v).size; if (l > value.fixnum.max) { @panic("string length out of range"); } return value.fixnum.pack(@intCast(l)); }