diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 00:30:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 01:12:53 -0300 |
| commit | 2bbcc0a9aca11a418b8e51fd5d3158f2bc632d4b (patch) | |
| tree | beff90286c8cbccab11bcf3037037a75a0aca48a /dev | |
| parent | 3a3601f984d25f1e03cee3ac47da7eeb2548e511 (diff) | |
| download | pardes-2bbcc0a9aca11a418b8e51fd5d3158f2bc632d4b.tar.gz pardes-2bbcc0a9aca11a418b8e51fd5d3158f2bc632d4b.zip | |
tape: the calls out to the host by the Host table's own names, step 6a (the design of reports/pardes-handle-69-design.md, P33): Host gains what a call names, gives and gets, derived from its table (Fn, Args, Ret, has, mask, call), the tape one method, p.tape.host(p, .tty_taken, .{.at(id)}), whose absent arm is the caller's after orelse, and the 7 calls made straight on the table (hostForegroundName, hostTtyTaken, hostKillJob, Adopt, Upgrade, clockNow, askAhead) go through it; hostCall is the one body (the wrappers forward to it until 6c deletes them), its text in place; 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 'dev')
| -rw-r--r-- | dev/Host.zig | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/dev/Host.zig b/dev/Host.zig index a23c9ef5..cb7aefe1 100644 --- a/dev/Host.zig +++ b/dev/Host.zig @@ -1,6 +1,8 @@ +const std = @import("std"); const pardes = @import("core"); const host_io = @import("host_io.zig"); const Lsp = host_io.Lsp; +const Host = @This(); ctx: ?*anyopaque = null, vtable: *const VTable = &.{}, @@ -64,3 +66,47 @@ pub const VTable = struct { /// absent, it runs on the loop. job: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, serial: u32, token: u32) void = null, }; + +// What a call names, gives and gets, derived from the table: the core calls +// out through its tape, `p.tape.host(p, .pty_write, .{ pane, bytes })`. + +/// One of the table's functions, by its field's name: `.pty_write`. The +/// tape numbers a call by it (the table's order). +pub const Fn = std.meta.FieldEnum(VTable); + +/// What `f` is given after `ctx`, in order. +pub fn Args(comptime f: Fn) type { + const params = @typeInfo(Of(f)).@"fn".param_types; + var types: [params.len - 1]type = undefined; + for (params[1..], &types) |P, *T| T.* = P.?; + return @Tuple(&types); +} + +/// What `f` answers. +pub fn Ret(comptime f: Fn) type { + return @typeInfo(Of(f)).@"fn".return_type.?; +} + +fn Of(comptime f: Fn) type { + return @typeInfo(@typeInfo(@FieldType(VTable, @tagName(f))).optional.child).pointer.child; +} + +/// Whether this host has `f`. +pub fn has(h: Host, comptime f: Fn) bool { + return @field(h.vtable.*, @tagName(f)) != null; +} + +/// Which functions it has, a bit each in the table's order. +pub fn mask(h: Host) u64 { + var m: u64 = 0; + inline for (@typeInfo(VTable).@"struct".field_names, 0..) |name, i| { + if (@field(h.vtable.*, name) != null) m |= @as(u64, 1) << i; + } + return m; +} + +/// `f(args)` of this host; null: it has no such function. +pub inline fn call(h: Host, comptime f: Fn, args: Args(f)) ?Ret(f) { + const func = @field(h.vtable.*, @tagName(f)) orelse return null; + return @call(.auto, func, .{h.ctx} ++ args); +} |
