diff options
| author | Taylan Kammer <taylan.kammer@gmail.com> | 2026-06-22 19:05:48 +0200 |
|---|---|---|
| committer | Taylan Kammer <taylan.kammer@gmail.com> | 2026-06-22 19:05:48 +0200 |
| commit | 8308e303a88779be0d0a6249d2d79ca56eb05ed0 (patch) | |
| tree | 524e5fb474ce890fbf1e9b5311a7e7cdba33b0de /src | |
| parent | 476632d9559b1e3bacbd226df336116cac8544ea (diff) | |
Fix tests etc.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/parse.zig | 32 | ||||
| -rw-r--r-- | src/test/strings.zig | 6 | ||||
| -rw-r--r-- | src/test/values.zig | 55 | ||||
| -rw-r--r-- | src/zisp/value.zig | 6 | ||||
| -rw-r--r-- | src/zisp/value/ptr.zig | 2 |
5 files changed, 24 insertions, 77 deletions
diff --git a/src/test/parse.zig b/src/test/parse.zig index ba29333..1c930a6 100644 --- a/src/test/parse.zig +++ b/src/test/parse.zig @@ -70,14 +70,14 @@ test "parse" { test "parse2" { const val = parse( \\ ;; Testing some crazy datum comments - \\ ;~"bar"([x #"y"]{##`,'z}) #"foo" + \\ ;~"bar"([x #"y"]{##`,'z}) #\foo \\ ;; end ); - const r = value.rune.unpack(&value.pair.getCar(val)); + const r = value.rune.unpack(&value.list.getValPtr(val)[0]); try testing.expectEqualStrings("HASH", r); - const s = value.pair.getCdr(value.pair.getCdr(val)); + const s = value.list.getValPtr(val)[1]; try testing.expect(value.sstr.check(s)); const f = value.sstr.unpack(&s); @@ -89,27 +89,24 @@ test "parse3" { \\(foo ;~x ;~(x y) ;~x #bar [#x #"baz"] 'bat) ); - const car = value.pair.getCar; - const cdr = value.pair.getCdr; - - const e1 = car(val); - const e2 = car(cdr(val)); - const e3 = car(cdr(cdr(val))); - const e4 = car(cdr(cdr(cdr(val)))); + const e1 = value.list.getValPtr(val)[0]; + const e2 = value.list.getValPtr(val)[1]; + const e3 = value.list.getValPtr(val)[2]; + const e4 = value.list.getValPtr(val)[3]; try testing.expect(value.sstr.check(e1)); try testing.expect(value.rune.check(e2)); - try testing.expect(value.pair.check(e3) != null); - try testing.expect(value.pair.check(e4) != null); + try testing.expect(value.list.check(e3)); + try testing.expect(value.list.check(e4)); } test "parse4" { - const val = parse("(foo & ;~x bar ;~y)"); + const val = parse("(foo ;~x bar ;~y)"); - const s = value.sstr.unpack(&value.pair.getCar(val)); + const s = value.sstr.unpack(&value.list.getValPtr(val)[0]); try testing.expectEqualStrings("foo", s); - const f = value.sstr.unpack(&value.pair.getCdr(val)); + const f = value.sstr.unpack(&value.list.getValPtr(val)[1]); try testing.expectEqualStrings("bar", f); } @@ -126,10 +123,7 @@ test "print2" { var w = std.Io.Writer.fixed(&buf); const v = parse("#{foo bar['x]}"); try zisp.io.print(&w, v); - try testing.expectEqualStrings( - "(#HASH #BRACE foo (#JOIN bar #SQUARE (#QUOTE & x)))", - buf[0..w.end], - ); + try testing.expectEqualStrings("#{foo bar['x]}", buf[0..w.end]); } fn parseAndPrint(str: []const u8) !void { diff --git a/src/test/strings.zig b/src/test/strings.zig index 09aa988..f0cdde9 100644 --- a/src/test/strings.zig +++ b/src/test/strings.zig @@ -13,13 +13,13 @@ test "istr" { const s1 = "foo bar baz"; const v1 = try istr.getOrNew(s1); const v1_len: usize = @intCast(fx.unpack(istr.getLen(v1))); - try testing.expectEqualStrings(s1, istr.assert(v1).str()); + try testing.expectEqualStrings(s1, istr.getBytes(v1)); try testing.expectEqual(s1.len, v1_len); const s2 = @embedFile("data/string.txt"); const v2 = try istr.getOrNew(s2); const v2_len: usize = @intCast(fx.unpack(istr.getLen(v2))); - try testing.expectEqualStrings(s2, istr.assert(v2).str()); + try testing.expectEqualStrings(s2, istr.getBytes(v2)); try testing.expectEqual(s2.len, v2_len); // Check that modifying a slice doesn't affect the string. @@ -27,5 +27,5 @@ test "istr" { var s3 = "test".*; const v3 = try istr.getOrNew(&s3); s3[0] = 'x'; - try testing.expectEqualStrings("test", istr.assert(v3).str()); + try testing.expectEqualStrings("test", istr.getBytes(v3)); } diff --git a/src/test/values.zig b/src/test/values.zig index a276b2e..32af6cb 100644 --- a/src/test/values.zig +++ b/src/test/values.zig @@ -9,7 +9,7 @@ pub const lib = @import("../zisp/lib.zig"); pub const value = @import("../zisp/value.zig"); pub const Zptr = value.Zptr; -pub const PtrTag = value.PtrTag; +pub const HeapType = value.HeapType; pub const Value = value.Value; test "double" { @@ -68,37 +68,15 @@ test "snan" { test "ptr" { const ptr = value.ptr; + const tag = HeapType.array; const val: Zptr = @ptrFromInt(256); - const tag = PtrTag.pair; const p = ptr.pack(tag, @ptrCast(val)); try testing.expect(ptr.check(p)); - const pv, const pt = ptr.unpack(p); - try testing.expectEqual(val, pv); + const pt, const pv = ptr.unpack(p); try testing.expectEqual(tag, pt); - - var w = ptr.makeWeak(p); - try testing.expect(ptr.check(w)); - try testing.expect(ptr.checkWeak(w)); - try testing.expect(value.t.eq(ptr.predWeak(w))); - try testing.expect(value.f.eq(ptr.predWeakNull(w))); - - const wv, const wt = ptr.unpack(w); - try testing.expectEqual(val, wv); - try testing.expectEqual(tag, wt); - - const wv2, const wt2 = ptr.unpack(ptr.getWeak(w)); - try testing.expectEqual(val, wv2); - try testing.expectEqual(tag, wt2); - - ptr.setWeakNull(&w); - try testing.expect(ptr.check(w)); - try testing.expect(ptr.checkWeak(w)); - try testing.expect(ptr.isWeakNull(w)); - try testing.expect(value.t.eq(ptr.predWeak(w))); - try testing.expect(value.t.eq(ptr.predWeakNull(w))); - try testing.expect(value.f.eq(ptr.getWeak(w))); + try testing.expectEqual(val, pv); } test "rune" { @@ -224,28 +202,3 @@ test "misc" { const eof = value.eof; try testing.expect(value.boole.unpack(value.misc.isEof(eof))); } - -test "pair" { - const v1 = value.fixnum.pack(1); - const v2 = value.fixnum.pack(2); - - const v3 = value.fixnum.pack(3); - const v4 = value.fixnum.pack(4); - - const p = value.pair.cons(v1, v2); - try testing.expect(value.pair.check(p) != null); - try testing.expect(value.boole.unpack(value.pair.pred(p))); - - const car = value.pair.getCar(p); - const cdr = value.pair.getCdr(p); - try testing.expectEqual(1, value.fixnum.unpack(car)); - try testing.expectEqual(2, value.fixnum.unpack(cdr)); - - value.pair.setCar(p, v3); - value.pair.setCdr(p, v4); - - const car2 = value.pair.getCar(p); - const cdr2 = value.pair.getCdr(p); - try testing.expectEqual(3, value.fixnum.unpack(car2)); - try testing.expectEqual(4, value.fixnum.unpack(cdr2)); -} diff --git a/src/zisp/value.zig b/src/zisp/value.zig index 2ae0524..fc815bd 100644 --- a/src/zisp/value.zig +++ b/src/zisp/value.zig @@ -272,13 +272,13 @@ pub const Value = packed union { /// if this isn't a pointer at all. Could be useful for a dispatch table. /// Note that unlike getPtr(), this can actually return a null pointer as /// such, not conflating it with the "not a heap pointer" case. - pub fn getPtrAny(v: Value) ?struct { ?Zptr, HeapType } { + pub fn getPtrAny(v: Value) ?struct { HeapType, ?Zptr } { const hi16_bits: u16 = @intCast(v.bits >> 48); if (hi16_bits != hi16_tag_ptr) return null; - const ht: u4 = @truncate(hi16_bits); + const ht: u4 = @intCast(v.bits << 16 >> 60); const pval: u48 = @intCast(v.bits << 20 >> 16); - return .{ @ptrFromInt(pval), @enumFromInt(ht) }; + return .{ @enumFromInt(ht), @ptrFromInt(pval) }; } /// Checks if the value is a list pointer. diff --git a/src/zisp/value/ptr.zig b/src/zisp/value/ptr.zig index 3a6995b..8a3ca18 100644 --- a/src/zisp/value/ptr.zig +++ b/src/zisp/value/ptr.zig @@ -27,7 +27,7 @@ pub fn pack(comptime ht: HeapType, ptr: ht.PtrType()) Value { return .{ .ptr = .{ .index = index, .htype = ht } }; } -pub fn unpack(v: Value) struct { Zptr, HeapType } { +pub fn unpack(v: Value) struct { HeapType, ?Zptr } { assert(v); return v.getPtrAny() orelse unreachable; } |
