summaryrefslogtreecommitdiff
path: root/core/Core.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 01:12:56 -0300
committerGabriel Schneider <[email protected]>2026-11-20 01:46:46 -0300
commit866e9ed6762f42a32907d63d783464f2c90d5b85 (patch)
treeb2a4656ce978bbec81cd6e7d9778733e04087bb2 /core/Core.zig
parent2bbcc0a9aca11a418b8e51fd5d3158f2bc632d4b (diff)
downloadpardes-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/Core.zig')
-rw-r--r--core/Core.zig33
1 files changed, 19 insertions, 14 deletions
diff --git a/core/Core.zig b/core/Core.zig
index db0c5794..3fc5b192 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -1466,25 +1466,22 @@ pub fn animationActive(p: *const Pardes) bool {
}
pub fn pump(p: *Pardes, host: Host) !void {
- // By hand, not `taped`: the host is set before the enter, which wraps it, and is no input.
+ // By hand, not `taped`: the host is set before the enter, which says it if it is another, and is no input.
p.host = host;
const taped = pardes.tape.enter(p, .pump);
defer pardes.tape.leave(p, taped);
- // The host as the tape sees it, while it records.
- const h = p.host;
- const v = h.vtable;
- if (v.wait_input) |f| {
+ if (p.host.has(.wait_input)) {
// Asleep until input or until the core's next deadline
// (nextWake); 0 is no timeout at all.
// The clock read whether or not it is wanted: what a replica
// waits on is its own (a picture decoding wakes only a frame
// that draws it), and the tape has the same calls either way.
- const now = if (v.now) |clock| clock(h.ctx) else p.clock.now_ns;
+ const now = p.tape.host(p, .now, .{}) orelse p.clock.now_ns;
const timeout: u32 = if (p.nextWake()) |due| wake: {
const ms = ((due -| now) + std.time.ns_per_ms - 1) / std.time.ns_per_ms;
break :wake @intCast(std.math.clamp(ms, 1, std.math.maxInt(u32)));
} else 0;
- f(h.ctx, timeout);
+ _ = p.tape.host(p, .wait_input, .{timeout});
}
// Detached, nobody's key dismisses a message: they go on the clock,
// here in the step, where the clock read is taped (the host's wait
@@ -1492,46 +1489,54 @@ pub fn pump(p: *Pardes, host: Host) !void {
// go).
Messages.expireUnattended(p);
p.frames.mark_start = FrameStats.nowNs();
- if (v.now) |clock| p.advance(clock(h.ctx));
+ if (p.tape.host(p, .now, .{})) |now| p.advance(now);
p.settle();
// A quitting frame has already freed what it would draw.
if (p.quit) return;
- if (v.poll_frame) |f| f(h.ctx);
+ _ = p.tape.host(p, .poll_frame, .{});
// Nothing to draw: do not spend a frame, and above all do not block on
// the display for one. This is what keeps the frame rate governing
// rendering and nothing else.
// A shell with a clock draws what `advance` stepped; one without
// steps its own `.tick`s and draws while a deadline is due.
- if (!p.needs_frame and (v.now != null or !p.animationActive())) return p.frames.idle();
+ if (!p.needs_frame and (p.host.has(.now) or !p.animationActive())) return p.frames.idle();
// No one to see it: the frame stays owed (needs_frame), not drawn.
// A pty streaming into an unwatched session spent most of its time
// drawing what nobody looked at.
- if (v.watched) |f| if (!f(h.ctx)) return;
+ if (!(p.tape.host(p, .watched, .{}) orelse true)) return;
// The one view this process shows (a replica client's is its own
// process's to draw), drawn as it is if another's is live.
// Not shown by the frontend (Host.present): owed.
var skipped = false;
const shown = Views.shown(p);
if (shown != p.live) {
- if (shown) |k| skipped = !try Views.drawOne(p, k, .{ .ctx = h.ctx, .f = v.present });
+ if (shown) |k| skipped = !try Views.drawOne(p, k, .{ .ctx = p, .f = presentTaped });
} else {
_ = p.frame_arena.reset(.{ .retain_with_limit = memory.limits.frame_kept });
p.frames.mark_update = FrameStats.nowNs();
p.frames.view = if (p.panes[p.view().active]) |pane| pane.scroll() else 0;
const surface = try p.render(p.frame_arena.allocator());
p.frames.mark_render = FrameStats.nowNs();
- if (v.present) |f| skipped = !f(h.ctx, surface);
+ skipped = !(p.tape.host(p, .present, .{surface}) orelse true);
Stream.askAhead(p);
}
// Settled before post_present: a shell ticks there, and what that
// tick moves owes the next frame.
p.needs_frame = skipped;
- if (v.post_present) |f| f(h.ctx);
+ _ = p.tape.host(p, .post_present, .{});
// Still moving: the next frame is owed a period from now.
const owed = if (p.nextWake()) |due| due <= p.clock.stepped_ns + frame_ns else false;
p.frames.record(FrameStats.nowNs(), owed, skipped);
}
+/// The pump's other view presented as its own is, through the tape:
+/// `present` stays inside `views.within`, whose live view the host's
+/// `presented` reads.
+fn presentTaped(ctx: ?*anyopaque, surface: *const pardes.Surface) bool {
+ const p: *Pardes = @ptrCast(@alignCast(ctx.?));
+ return p.tape.host(p, .present, .{surface}) orelse true;
+}
+
/// What a pump does between its wait and its frame: the queued inputs
/// and the effects. Also the session at a step boundary, taken now (an
/// Upgrade's dump, upgrade.zig).