diff options
| author | Taylan Kammer <taylan.kammer@gmail.com> | 2026-07-27 07:11:46 +0200 |
|---|---|---|
| committer | Taylan Kammer <taylan.kammer@gmail.com> | 2026-07-27 07:11:46 +0200 |
| commit | c83bdec108bc00f6a266eba31eccb894fae76e97 (patch) | |
| tree | 669aebf063283e9c20f05951223be3e7e1733beb /src/zisp/value | |
| parent | a8d40828eb6c7ace41e7102ac18dc7b406b094eb (diff) | |
Cleanup, fixes, NaN-packing improvement.
Diffstat (limited to 'src/zisp/value')
| -rw-r--r-- | src/zisp/value/istr.zig | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/src/zisp/value/istr.zig b/src/zisp/value/istr.zig index a581289..528280a 100644 --- a/src/zisp/value/istr.zig +++ b/src/zisp/value/istr.zig @@ -1,6 +1,6 @@ //! Intermediate-length String //! -//! Prefixed with a 1-byte length. Typically interned in an IstrSet. +//! Length up to 255, stored in pointer. Typically interned in an IstrPool. const std = @import("std"); @@ -9,36 +9,13 @@ const Alloc = std.mem.Allocator; const gc = @import("../gc.zig"); const value = @import("../value.zig"); -const IstrSet = gc.IstrSet; +const IstrPool = gc.IstrPool; const Value = value.Value; pub const max_len = 255; // Zig API -/// Pointer to an interned string. First byte is length. -pub const IstrPtr = *IstrHead; - -pub const IstrHead = packed struct(u8) { - len: u8, - - fn bufU8(self: *@This()) [*]u8 { - return @ptrCast(self); - } - - pub fn bytes(self: *@This()) []const u8 { - const start = @sizeOf(IstrHead); - const len: usize = self.len; - return self.bufU8()[start .. start + len]; - } - - pub fn putStr(self: *@This(), s: []const u8) void { - const start = @sizeOf(IstrHead); - self.len = @intCast(s.len); - @memcpy(self.bufU8()[start .. start + s.len], s); - } -}; - pub fn check(v: Value) bool { return v.isIstr(); } @@ -70,12 +47,12 @@ pub fn new(alloc: Alloc, s: []const u8) !IstrPtr { } pub fn getOrNew(s: []const u8) !IstrPtr { - return getOrNewInSet(gc.mainIstrSet(), s); + return getOrNewInPool(gc.mainIstrPool(), s); } -pub fn getOrNewInSet(set: *IstrSet, s: []const u8) !IstrPtr { +pub fn getOrNewInPool(pool: *IstrPool, s: []const u8) !IstrPtr { assertValidIstr(s); - return try set.getOrNew(s); + return try pool.getOrNew(s); } pub fn pack(istr: IstrPtr) Value { @@ -104,10 +81,10 @@ pub fn getLen(v: Value) Value { return value.fixnum.pack(istr.len); } -// TODO: Zisp representation of IstrSet & ability to intern in given IstrSet +// TODO: Zisp representation of IstrPool & ability to intern in given IstrPool pub fn intern(v: Value) Value { const istr = assert(v); - const set = gc.mainIstrSet(); - return pack(set.getOrPut(istr)); + const pool = gc.mainIstrPool(); + return pack(pool.getOrPut(istr)); } |
