diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 04:16:41 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 04:16:41 -0300 |
| commit | 5b7124d10f9b2db8d1c5e99eacb9b6d2fffff0cc (patch) | |
| tree | dc50936490ad8636f5431da30ec3aaa38339c936 /dev/Host.zig | |
| parent | 6e8735895d04c0073eb28cc1a2f431a2ba587e9d (diff) | |
| parent | 8fb080c6208bccf9ef12eca630b0534312ae5fe7 (diff) | |
| download | pardes-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 'dev/Host.zig')
| -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); +} |
