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/Effect.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/Effect.zig')
| -rw-r--r-- | core/Effect.zig | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/core/Effect.zig b/core/Effect.zig index 5e821065..a6fcc0e5 100644 --- a/core/Effect.zig +++ b/core/Effect.zig @@ -116,34 +116,33 @@ pub const perform = tape.taped(performInner); fn performInner(p: *Pardes, e: Effect) void { // A Save performed on one twin is every twin's (File.syncTwins). defer panes.File.syncTwins(p); - const v = p.host.vtable; switch (e) { // The host reads the pane (its command, its shell) as it forks, // so the slot must still hold the pane the spawn was for. - .spawn => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane.index()] orelse "") else s.cwd.slice()) else { + .spawn => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else p.tape.host(p, .spawn, .{ s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane.index()] orelse "") else s.cwd.slice() }) orelse { p.fallback.spawned[s.pane.index()] = true; }, // A pane with no child is silent: nothing invents output on its // screen, and the bytes are dropped rather than transcribed. - .write => |w| if (v.pty_write) |f| f(p.host.ctx, w.pane, w.bytes.slice()), - .resize_pty => |r| if (v.pty_resize) |f| f(p.host.ctx, r.pane, r.cols, r.rows), + .write => |w| _ = p.tape.host(p, .pty_write, .{ w.pane, w.bytes.slice() }), + .resize_pty => |r| _ = p.tape.host(p, .pty_resize, .{ r.pane, r.cols, r.rows }), // A signal for a pane that closed, its slot retaken in the same // step, would reach another pane's child. - .signal_pty => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig), - .close_pty => |c| if (v.close_pty) |f| f(p.host.ctx, c.pane), + .signal_pty => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else p.tape.host(p, .pty_signal, .{ s.pane, s.sig }) orelse {}, + .close_pty => |c| _ = p.tape.host(p, .close_pty, .{c.pane}), // The view's frontend opens it, yanks and pastes, on its own // machine (View.yanks); the host here only for a view no client // draws (tape.hostCall). .open_link => |u| { p.view().links +%= 1; p.view().link = u; - if (v.open_link) |f| f(p.host.ctx, u.slice()) else p.fallback.setLink(u.slice()); + p.tape.host(p, .open_link, .{u.slice()}) orelse p.fallback.setLink(u.slice()); }, // Plan 9's plumber's, detached (host_io.startDetached); in-process // (a test), kept to look at. .start => |st| { var why_buf: [64]u8 = undefined; - const why = if (v.start) |f| f(p.host.ctx, st.line.slice(), &why_buf) else p.fallback.start(st.line.slice()); + const why = p.tape.host(p, .start, .{ st.line.slice(), &why_buf }) orelse p.fallback.start(st.line.slice()); const w = why orelse return; var words = std.mem.splitScalar(u8, st.line.slice(), 0); _ = words.next(); // its directory @@ -191,37 +190,31 @@ fn performInner(p: *Pardes, e: Effect) void { }, .write_dump => { const out = p.dump_out orelse return; - if (v.write_dump) |f| { - f(p.host.ctx, out); - } else { + p.tape.host(p, .write_dump, .{out}) orelse { _ = p.fallback.writeFile(host_io.Fallback.dump_path, out); p.setLastDump(host_io.Fallback.dump_path); - } + }; }, .set_clipboard => { p.view().yanks +%= 1; const text = p.registers.text(p.gpa, '+') orelse ""; - if (v.set_clipboard) |f| f(p.host.ctx, text) else p.fallback.setClipboard(text); + p.tape.host(p, .set_clipboard, .{text}) orelse p.fallback.setClipboard(text); }, // No desktop to ask: answer from the in-process clipboard at once, // which is the same shape as a host answering later. .read_clipboard => { p.view().pastes +%= 1; - if (v.read_clipboard) |f| f(p.host.ctx) else p.update(.{ .paste = p.fallback.clipboard.items }); + p.tape.host(p, .read_clipboard, .{}) orelse p.update(.{ .paste = p.fallback.clipboard.items }); }, - .lsp => |q| if (v.lsp) |f| - f(p.host.ctx, .{ .id = q.id, .kind = q.kind, .pane = q.pane, .offset = q.offset, .arg = q.arg.slice() }) - else + .lsp => |q| p.tape.host(p, .lsp, .{.{ .id = q.id, .kind = q.kind, .pane = q.pane, .offset = q.offset, .arg = q.arg.slice() }}) orelse p.update(.{ .lsp_resp = .{ .id = q.id, .rows = "" } }), - .pipe => |q| if (v.pipe) |f| - f(p.host.ctx, q.id) - else + .pipe => |q| p.tape.host(p, .pipe, .{q.id}) orelse p.update(.{ .pipe_resp = .{ .id = q.id, .success = false, .outputs = &.{} } }), // No workers here (a test, a board): it runs on the loop. - .search => |q| if (v.search) |f| f(p.host.ctx, q.gen) else Stream.runHere(p, q.gen, false), + .search => |q| p.tape.host(p, .search, .{q.gen}) orelse Stream.runHere(p, q.gen, false), // No windows here (a test, the tty): it stays. - .hand_over => |h| if (v.hand_over) |f| { - if (p.handover.bytes) |bytes| f(p.host.ctx, h.seq, bytes); + .hand_over => |h| if (p.host.has(.hand_over)) { + if (p.handover.bytes) |bytes| _ = p.tape.host(p, .hand_over, .{ h.seq, bytes }); } else p.update(.{ .handed = .{ .seq = h.seq, .failure = "no other windows here" } }), .edit_write => { // Each write takes the bytes `w` took when it ran: the text @@ -247,24 +240,21 @@ fn performInner(p: *Pardes, e: Effect) void { } else ctlfs.events.noteLogAs(p, .save, pane, w.path); } }, - .watch => |w| if (v.watch_file) |f| { + .watch => |w| { // What a watch is about: a real file, or a kind's (a PDF's). const path: []const u8 = if (p.panes[w.pane.index()]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else ""; - f(p.host.ctx, w.pane, path, w.on, w.mode); - } else { - p.fallback.watched[w.pane.index()] = w.on; + p.tape.host(p, .watch_file, .{ w.pane, path, w.on, w.mode }) orelse { + p.fallback.watched[w.pane.index()] = w.on; + }; }, - .theme_file => |t| if (v.watch_theme) |f| f(p.host.ctx, t.generation, t.on), - .dump_themes => |d| if (v.dump_themes) |f| f(p.host.ctx, d.pane), - .detach => |d| if (v.detach) |f| - f(p.host.ctx) - else - p.reportError(d.pane, "detach", error.NotAttached), + .theme_file => |t| _ = p.tape.host(p, .watch_theme, .{ t.generation, t.on }), + .dump_themes => |d| _ = p.tape.host(p, .dump_themes, .{d.pane}), + .detach => |d| p.tape.host(p, .detach, .{}) orelse p.reportError(d.pane, "detach", error.NotAttached), // dlopen is the same on every host, so none has a method of its // own; a replica's core holds no library (what it brought comes in // the event this taped). - .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane.index(), a.arg.slice()), - .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane.index(), j.serial, j.token), + .addon => |a| if (!p.tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane.index(), a.arg.slice()), + .job => |j| p.tape.host(p, .job, .{ j.pane, j.serial, j.token }) orelse if (!p.tape.replaying()) host_io.KindJob.runHere(p, j.pane.index(), j.serial, j.token), // the loop's own condition; a host tears down after its own loop .quit => p.endSession(), } @@ -282,7 +272,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: [] if (filesystem.localPath(path)) |local| filesystem.makeDirs(p.tape, std.Io.Dir.path.dirname(local) orelse "/"); // The in-process filesystem reports the same way a real host does, // so an OOM there leaves the pane dirty rather than looking saved. - if (p.host.vtable.write_file) |f| f(p.host.ctx, .at(id), path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory); + p.tape.host(p, .write_file, .{ .at(id), path, bytes }) orelse if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory); const pane = p.panes[id] orelse return null; if (pane.serial != serial) return null; if (p.fs.failures == failures) return pane; |
