summaryrefslogtreecommitdiff
path: root/src/zisp/value
diff options
context:
space:
mode:
Diffstat (limited to 'src/zisp/value')
-rw-r--r--src/zisp/value/hptr.zig (renamed from src/zisp/value/ptr.zig)0
-rw-r--r--src/zisp/value/istr.zig30
2 files changed, 9 insertions, 21 deletions
diff --git a/src/zisp/value/ptr.zig b/src/zisp/value/hptr.zig
index 8a3ca18..8a3ca18 100644
--- a/src/zisp/value/ptr.zig
+++ b/src/zisp/value/hptr.zig
diff --git a/src/zisp/value/istr.zig b/src/zisp/value/istr.zig
index 528280a..c0928ef 100644
--- a/src/zisp/value/istr.zig
+++ b/src/zisp/value/istr.zig
@@ -38,35 +38,24 @@ fn assertValidIstr(s: []const u8) void {
}
}
-pub fn new(alloc: Alloc, s: []const u8) !IstrPtr {
- const algn = std.mem.Alignment.of(IstrPtr);
- const size = @sizeOf(IstrHead) + s.len;
- const istr: IstrPtr = @ptrCast(try alloc.alignedAlloc(u8, algn, size));
- istr.putStr(s);
- return istr;
+pub fn new(s: []const u8) !Value {
+ const istr = gc.allocIstr(s.len);
+ @memcpy(istr)
}
-pub fn getOrNew(s: []const u8) !IstrPtr {
+pub fn getOrNew(s: []const u8) !Value {
return getOrNewInPool(gc.mainIstrPool(), s);
}
-pub fn getOrNewInPool(pool: *IstrPool, s: []const u8) !IstrPtr {
+pub fn getOrNewInPool(pool: *IstrPool, s: []const u8) !Value {
assertValidIstr(s);
return try pool.getOrNew(s);
}
-pub fn pack(istr: IstrPtr) Value {
- const ptr = @intFromPtr(istr);
- return .{ .istr = .{ .ptr = @intCast(ptr) } };
-}
-
-pub fn unpack(v: Value) IstrPtr {
- return @ptrFromInt(v.istr.ptr);
-}
-
pub fn getBytes(v: Value) []const u8 {
assert(v);
- return unpack(v).bytes();
+ const ptr = gc.istrPtrFromIdx(v.istr.idx);
+ return ptr[0..v.istr.len];
}
// Zisp API
@@ -77,8 +66,7 @@ pub fn pred(v: Value) Value {
pub fn getLen(v: Value) Value {
assert(v);
- const istr: IstrPtr = @ptrFromInt(v.istr.ptr);
- return value.fixnum.pack(istr.len);
+ return value.fixnum.pack(v.istr.len);
}
// TODO: Zisp representation of IstrPool & ability to intern in given IstrPool
@@ -86,5 +74,5 @@ pub fn getLen(v: Value) Value {
pub fn intern(v: Value) Value {
const istr = assert(v);
const pool = gc.mainIstrPool();
- return pack(pool.getOrPut(istr));
+ return pool.getOrPut(istr);
}