summaryrefslogtreecommitdiff
path: root/src/zisp/value/istr.zig
diff options
context:
space:
mode:
authorTaylan Kammer <taylan.kammer@gmail.com>2026-05-31 01:02:58 +0200
committerTaylan Kammer <taylan.kammer@gmail.com>2026-05-31 01:02:58 +0200
commit79f4d5ae23c44924f413f9d7a1113d2280611ec5 (patch)
treed00735af778cfa3a52959ebd51eb1161a20a0565 /src/zisp/value/istr.zig
parenta21c485635f74c6fb86db630110fa4ddebc8c0c0 (diff)
Make the code compile.
Diffstat (limited to 'src/zisp/value/istr.zig')
-rw-r--r--src/zisp/value/istr.zig23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/zisp/value/istr.zig b/src/zisp/value/istr.zig
index dec3b09..8f70725 100644
--- a/src/zisp/value/istr.zig
+++ b/src/zisp/value/istr.zig
@@ -3,6 +3,8 @@ const std = @import("std");
const gc = @import("../gc.zig");
const value = @import("../value.zig");
+const Alloc = std.mem.Allocator;
+
const Value = value.Value;
// Zig API
@@ -22,25 +24,26 @@ pub const Istr = *align(8) packed union {
return @ptrCast(self);
}
- pub fn new(alloc: *Allocator, hash: u64, s: []const u8) Istr {
- const istr: Istr = @ptrCast(alloc.alloc(u8, 8 + s.len));
- istr.hash = hash;
- istr.putStr(s);
- return istr;
- }
-
pub fn putStr(self: *@This(), s: []const u8) void {
std.debug.assert(s.len <= 255);
- @memcpy(istr.bufU8()[8 .. 8 + s.len], s);
+ @memcpy(self.bufU8()[8 .. 8 + s.len], s);
}
pub fn str(self: *@This()) []const u8 {
const buf = self.bufU8();
- const len = self.meta.len;
- return buf[8 .. 8 + len];
+ return buf[8 .. 8 + self.meta.len];
}
};
+pub fn new(alloc: Alloc, hash: u64, s: []const u8) !Istr {
+ const aln = std.mem.Alignment.of(Istr);
+ const ptr = try alloc.alignedAlloc(u8, aln, 8 + s.len);
+ const istr: Istr = @ptrCast(ptr);
+ istr.hash = hash;
+ istr.putStr(s);
+ return istr;
+}
+
pub fn check(v: Value) ?Istr {
if (v.getPtr(.istr)) |p| {
return @ptrCast(p);