diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/bench.zig | 9 | ||||
| -rw-r--r-- | src/test/parse.zig | 36 | ||||
| -rw-r--r-- | src/test/strings.zig | 6 | ||||
| -rw-r--r-- | src/test/values.zig | 18 | ||||
| -rw-r--r-- | src/zisp/gc.zig | 6 | ||||
| -rw-r--r-- | src/zisp/value/istr.zig | 2 |
6 files changed, 44 insertions, 33 deletions
diff --git a/src/test/bench.zig b/src/test/bench.zig index a6203a3..6e21df0 100644 --- a/src/test/bench.zig +++ b/src/test/bench.zig @@ -1,12 +1,17 @@ const std = @import("std"); +const Ts = std.Io.Timestamp; + fn benchmark(name: []const u8, iters: usize, func: fn () anyerror!void) !void { - var timer = try std.time.Timer.start(); + const io = std.Io.Threaded.global_single_threaded.io(); + const clock = std.Io.Clock.cpu_thread; + const start = clock.now(io); for (0..iters) |i| { _ = i; try func(); } - const ns: f64 = @floatFromInt(timer.lap()); + const stop = clock.now(io); + const ns: f64 = @floatFromInt(start.durationTo(stop).nanoseconds); const secs = ns / 1_000_000_000; std.debug.print( "bench {s} x {}: {d:.3}s\n", diff --git a/src/test/parse.zig b/src/test/parse.zig index 78915cd..53de21d 100644 --- a/src/test/parse.zig +++ b/src/test/parse.zig @@ -42,23 +42,21 @@ test "parse short bare string" { try expect(parse("+0.1").eq(str("+0.1"))); try expect(parse("-0.1").eq(str("-0.1"))); try expect(parse("10.1").eq(str("10.1"))); - try expect(parse("|x()|").eq(str("x()"))); - try expect(parse("|{\\|}|").eq(str("{|}"))); try expect(parse("foobar").eq(str("foobar"))); try expect(parse("!$%*+-").eq(str("!$%*+-"))); - try expect(parse("/<=>?@").eq(str("/<=>?@"))); - try expect(parse("^_~000").eq(str("^_~000"))); + try expect(parse("/<=>?^").eq(str("/<=>?^"))); + try expect(parse("_~0000").eq(str("_~0000"))); } test "parse long bare string" { const str = value.istr.intern; try expect(parse("foobarbaz").eq(str("foobarbaz"))); try expect(parse(".foo.bar.baz").eq(str(".foo.bar.baz"))); + try expect(parse(":foo:bar:baz").eq(str(":foo:bar:baz"))); try expect(parse("+foo.bar.baz").eq(str("+foo.bar.baz"))); try expect(parse("-foo.bar.baz").eq(str("-foo.bar.baz"))); try expect(parse("0foo.bar.baz").eq(str("0foo.bar.baz"))); - try expect(parse("!$%*+-/<=>?@^_~").eq(str("!$%*+-/<=>?@^_~"))); - try expect(parse("|foo\\x20;bar\\x0a;baz|").eq(str("foo bar\nbaz"))); + try expect(parse("!$%*+-/<=>?^_~").eq(str("!$%*+-/<=>?^_~"))); } test "parse" { @@ -66,8 +64,8 @@ test "parse" { try testing.expect(value.sstr.check(val)); - const s = value.sstr.unpack(val); - try testing.expectEqualStrings("foo", s.slice()); + const s = value.sstr.unpack(&val); + try testing.expectEqualStrings("foo", s); } test "parse2" { @@ -77,14 +75,14 @@ test "parse2" { \\ ;; end ); - const r = value.rune.unpack(value.pair.car(val)); - try testing.expectEqualStrings("HASH", r.slice()); + const r = value.rune.unpack(&value.pair.car(val)); + try testing.expectEqualStrings("HASH", r); const s = value.pair.cdr(value.pair.cdr(val)); try testing.expect(value.sstr.check(s)); - const f = value.sstr.unpack(s); - try testing.expectEqualStrings("foo", f.slice()); + const f = value.sstr.unpack(&s); + try testing.expectEqualStrings("foo", f); } test "parse3" { @@ -109,11 +107,11 @@ test "parse3" { test "parse4" { const val = parse("(foo & ;~x bar ;~y)"); - const s = value.sstr.unpack(value.pair.car(val)); - try testing.expectEqualStrings("foo", s.slice()); + const s = value.sstr.unpack(&value.pair.car(val)); + try testing.expectEqualStrings("foo", s); - const f = value.sstr.unpack(value.pair.cdr(val)); - try testing.expectEqualStrings("bar", f.slice()); + const f = value.sstr.unpack(&value.pair.cdr(val)); + try testing.expectEqualStrings("bar", f); } test "print" { @@ -167,7 +165,8 @@ test "print7" { } fn parseBench(path: []const u8, iters: usize) !void { - var timer = try std.time.Timer.start(); + const clock = std.Io.Clock.cpu_thread; + const start = clock.now(io); for (0..iters) |i| { _ = i; const file = try std.Io.Dir.cwd().openFile(io, path, .{}); @@ -180,7 +179,8 @@ fn parseBench(path: []const u8, iters: usize) !void { if (value.eof.eq(v)) break; } } - const ns: f64 = @floatFromInt(timer.lap()); + const stop = clock.now(io); + const ns: f64 = @floatFromInt(start.durationTo(stop).nanoseconds); const secs = ns / 1_000_000_000; std.debug.print( "parse {s} x {}: {d:.3}s\n", diff --git a/src/test/strings.zig b/src/test/strings.zig index 58a460b..b8db320 100644 --- a/src/test/strings.zig +++ b/src/test/strings.zig @@ -13,13 +13,13 @@ test "istr" { const s1 = "foo bar baz"; const v1 = istr.intern(s1); const v1_len: usize = @intCast(fx.unpack(istr.len(v1))); - try testing.expectEqualStrings(s1, istr.assert(v1).bytes()); + try testing.expectEqualStrings(s1, istr.assert(v1).str()); try testing.expectEqual(s1.len, v1_len); const s2 = @embedFile("data/string.txt"); const v2 = istr.intern(s2); const v2_len: usize = @intCast(fx.unpack(istr.len(v2))); - try testing.expectEqualStrings(s2, istr.assert(v2).bytes()); + try testing.expectEqualStrings(s2, istr.assert(v2).str()); 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 = istr.intern(&s3); s3[0] = 'x'; - try testing.expectEqualStrings("test", istr.assert(v3).bytes()); + try testing.expectEqualStrings("test", istr.assert(v3).str()); } diff --git a/src/test/values.zig b/src/test/values.zig index 4a62afa..153b53f 100644 --- a/src/test/values.zig +++ b/src/test/values.zig @@ -82,13 +82,13 @@ test "rune" { const r = value.rune.pack("test"); try testing.expect(value.rune.check(r)); - const s = value.rune.unpack(r); - try testing.expectEqualStrings("test", s.slice()); + const s = value.rune.unpack(&r); + try testing.expectEqualStrings("test", s); } const SstrImpl = struct { SstrPack, SstrUnpack }; const SstrPack = *const fn ([]const u8) Value; -const SstrUnpack = *const fn (Value) value.ShortString; +const SstrUnpack = *const fn (*const Value) []const u8; test "sstr" { const impls = [_]SstrImpl{ @@ -123,17 +123,17 @@ fn testSstr(impl: SstrImpl) !void { const ss2 = pack("123"); const ss3 = pack("123456"); - const s1 = unpack(ss1); - const s2 = unpack(ss2); - const s3 = unpack(ss3); + const s1 = unpack(&ss1); + const s2 = unpack(&ss2); + const s3 = unpack(&ss3); try testing.expect(value.sstr.check(ss1)); try testing.expect(value.sstr.check(ss2)); try testing.expect(value.sstr.check(ss3)); - try testing.expectEqualStrings("1", s1.slice()); - try testing.expectEqualStrings("123", s2.slice()); - try testing.expectEqualStrings("123456", s3.slice()); + try testing.expectEqualStrings("1", s1); + try testing.expectEqualStrings("123", s2); + try testing.expectEqualStrings("123456", s3); } fn benchmarkSstr(impl: SstrImpl, id: usize, iters: usize) !void { diff --git a/src/zisp/gc.zig b/src/zisp/gc.zig index 3a3e6f7..b256ea2 100644 --- a/src/zisp/gc.zig +++ b/src/zisp/gc.zig @@ -19,6 +19,7 @@ pub const alloc = std.heap.smp_allocator; var pair_pool: PairPool = undefined; pub fn makePair(v1: Value, v2: Value) PairPtr { + init(); // TODO this is only here for the test suite const p = pair_pool.create(alloc) catch @panic("OOM"); p.car = v1; p.cdr = v2; @@ -30,12 +31,17 @@ pub fn makePair(v1: Value, v2: Value) PairPtr { var istr_set: IstrSet = undefined; pub fn internString(s: []const u8) value.istr.IstrPtr { + init(); // TODO this is only here for the test suite return istr_set.add(alloc, s) catch @panic("OOM"); } // Init +var need_init = true; + pub fn init() void { + if (!need_init) return; + defer need_init = false; pair_pool = PairPool.initCapacity(alloc, 64) catch @panic("OOM"); istr_set = IstrSet.init(alloc) catch @panic("OOM"); } diff --git a/src/zisp/value/istr.zig b/src/zisp/value/istr.zig index 504ffe7..335a57e 100644 --- a/src/zisp/value/istr.zig +++ b/src/zisp/value/istr.zig @@ -93,5 +93,5 @@ pub fn pred(v: Value) Value { pub fn len(v: Value) Value { const istr = assert(v); - return value.fixnum.pack(@intCast(istr.len())); + return value.fixnum.pack(@intCast(istr.meta.len)); } |
