diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 01:12:56 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 01:46:46 -0300 |
| commit | 866e9ed6762f42a32907d63d783464f2c90d5b85 (patch) | |
| tree | b2a4656ce978bbec81cd6e7d9778733e04087bb2 /core/tape.zig | |
| parent | 2bbcc0a9aca11a418b8e51fd5d3158f2bc632d4b (diff) | |
| download | pardes-866e9ed6762f42a32907d63d783464f2c90d5b85.tar.gz pardes-866e9ed6762f42a32907d63d783464f2c90d5b85.zip | |
tape: Effect.perform's 20 calls out to the host and pump's 8 through the tape's one call, step 6b (reports/pardes-handle-69-design.md): each arm is p.tape.host(p, .name, .{ args }) with its absent arm after orelse (nothing, the in-process fallback, an answer at once, a message), Effect's two replaying() are the handle's, and the pump's other view presents through a four-line presentTaped so the present stays inside views.within; a new core test pumps a core twice with one host and once with another (the mask said at the first and the third, the clock, watch and present at each, a replica replaying the three units to the same digest); the tape's bytes do not move (semantics 32640d4a722b811c unmoved, cross_replay both ways)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/tape.zig')
| -rw-r--r-- | core/tape.zig | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/core/tape.zig b/core/tape.zig index b74915e5..18b5e296 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -1783,6 +1783,73 @@ test "every place that sets the global tape aside sets the core's field aside: a try std.testing.expectEqual(@as(usize, 0), wrong); } +/// The pump's own calls: a host with a clock and a frontend that shows +/// every frame; `more` has one function besides. +const Pumped = struct { + ns: u64, + fn now(ctx: ?*anyopaque) u64 { + const h: *Pumped = @ptrCast(@alignCast(ctx.?)); + h.ns += std.time.ns_per_ms; + return h.ns; + } + fn seen(_: ?*anyopaque) bool { + return true; + } + fn present(_: ?*anyopaque, _: *const pardes.Surface) bool { + return true; + } + fn poll(_: ?*anyopaque) void {} + const one: VTable = .{ .now = now, .watched = seen, .present = present }; + const more: VTable = .{ .now = now, .watched = seen, .present = present, .poll_frame = poll }; + + /// Recorded `bytes`: how many times which functions the host has was + /// said, the last said, and the calls of each function. + fn said(bytes: []const u8) struct { sets: usize = 0, mask: u64 = 0, calls: [host_fns.len]usize = @splat(0) } { + var got: @typeInfo(@TypeOf(said)).@"fn".return_type.? = .{}; + var r: walk.Reader = .{ .bytes = bytes }; + while (nextRecord(&r)) |rec| { + if (rec.kind == .set and rec.payload[0] == set_mask) { + got.sets += 1; + got.mask = std.mem.bytesToValue(u64, rec.payload[1..9]); + } + if (rec.kind == .host) { + const id = std.mem.bytesToValue(u16, rec.payload[0..2]); + if (id < host_fns.len) got.calls[id] += 1; + } + } + return got; + } +}; + +test "a core pumped twice with one host and once with another: which functions its host has is said at the first pump and the third, its clock, watch and present at each; a replica replays the three units to the same digest" { + const gpa = std.testing.allocator; + const R = pardes.replica; + var first: Pumped = .{ .ns = 0 }; + var second: Pumped = .{ .ns = 1 << 40 }; + const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24 }, .{ .ctx = &first, .vtable = &Pumped.one }, false); + defer a.deinit(); + const boot = Pumped.said(a.t.buf.items); + try std.testing.expectEqual(Host.mask(.{ .vtable = &Pumped.one }), boot.mask); + const r = try R.Replica.init(gpa, 1, try a.unit(0, 0), false); + defer r.deinit(); + const hosts = [_]Host{ .{ .ctx = &first, .vtable = &Pumped.one }, .{ .ctx = &second, .vtable = &Pumped.more } }; + for (hosts, [_]usize{ 0, 1 }, 1..) |h, sets, seq| { + a.host = h; + a.apply(.{ .resize = .{ .cols = @intCast(80 + seq), .rows = 24 } }); + const got = Pumped.said(a.t.buf.items); + try std.testing.expectEqual(sets, got.sets); + if (sets > 0) try std.testing.expectEqual(h.mask(), got.mask); + inline for (.{ .now, .watched, .present }) |f| try std.testing.expect(got.calls[@backingInt(@as(Host.Fn, f))] > 0); + try std.testing.expectEqual(@intFromBool(h.has(.poll_frame)), got.calls[@backingInt(Host.Fn.poll_frame)]); + a.seq += 1; + r.confirm(try a.unit(0, a.seq)); + } + r.settle(); + if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why}); + try std.testing.expect(r.diverged == null); + try std.testing.expectEqual(R.digestOf(a), r.digest()); +} + test "a client's frame drawn between its steps records nothing into its idle tape" { const gpa = std.testing.allocator; const p = try @import("ninep/harness.zig").withFile(gpa, "x\n"); |
