summaryrefslogtreecommitdiff
path: root/core/Effect.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 04:16:41 -0300
committerGabriel Schneider <[email protected]>2026-11-20 04:16:41 -0300
commit5b7124d10f9b2db8d1c5e99eacb9b6d2fffff0cc (patch)
treedc50936490ad8636f5431da30ec3aaa38339c936 /core/Effect.zig
parent6e8735895d04c0073eb28cc1a2f431a2ba587e9d (diff)
parent8fb080c6208bccf9ef12eca630b0534312ae5fe7 (diff)
downloadpardes-5b7124d10f9b2db8d1c5e99eacb9b6d2fffff0cc.tar.gz
pardes-5b7124d10f9b2db8d1c5e99eacb9b6d2fffff0cc.zip
integration: the core's calls out to the host go through the tape's handle, on the devices once and the attach that is always a client: pardes-handle-6 (6a, 6b, 6c, 8a: p.tape.host(p, .name, .{ args }) derived from the Host table; Wrap, hostOf and wrap deleted; no line of core/ outside the tape names the host's table, held by root.zig's scan; the tape's bytes unmoved) and pardes-merge30, merged without a textual conflict; tui core-test 857/1008 (151 skipped), shell-test 1048/1051, the window builds; the coordinator's gate in the ledger (reorg/merge31)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Effect.zig')
-rw-r--r--core/Effect.zig62
1 files changed, 26 insertions, 36 deletions
diff --git a/core/Effect.zig b/core/Effect.zig
index 5e821065..cabfe8ea 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.tape.has(p, .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;