diff options
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/macos.zig | 12 | ||||
| -rw-r--r-- | runtime/main.zig | 2 | ||||
| -rw-r--r-- | runtime/root.zig | 4 | ||||
| -rw-r--r-- | runtime/session.zig | 41 | ||||
| -rw-r--r-- | runtime/upgrade.zig | 6 |
5 files changed, 39 insertions, 26 deletions
diff --git a/runtime/macos.zig b/runtime/macos.zig index 408915da..dc12a6fb 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -103,7 +103,7 @@ pub const Image = extern struct { paper_bg: u32, }; -pub const Runtime = extern struct { +pub const Callbacks = extern struct { userdata: ?*anyopaque = null, wakeup: ?*const fn (?*anyopaque) callconv(.c) void = null, set_clipboard: ?*const fn (?*anyopaque, [*]const u8, usize) callconv(.c) void = null, @@ -250,7 +250,7 @@ const State = struct { io: std.Io, core: *pardes.Pardes, started: bool = false, - runtime: Runtime, + runtime: Callbacks, tag_cells: [pardes.MAX_TAG_LAYERS][]Cell = @splat(&.{}), layer_cells: [pardes.MAX_PANES][]Cell = @splat(&.{}), cells: []Cell = &.{}, @@ -290,7 +290,7 @@ const State = struct { var state: ?State = null; -export fn pardes_init(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) c_int { +export fn pardes_init(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) c_int { if (state != null) return 1; // already up; deinit first initCore(runtime, cols_arg, rows_arg) catch |err| { log.err("init failed: {t}", .{err}); @@ -302,7 +302,7 @@ export fn pardes_init(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) c_ /// The shell's gpa in a Debug build, as std.start's is for the others. var debug_gpa: std.heap.DebugAllocator(.{}) = .init; -fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void { +fn initCore(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) !void { // The allocator every other shell gets from std.start: a DebugAllocator // in Debug, libc's malloc otherwise. libc's measured at least as fast as // std.heap.smp_allocator everywhere and faster on MuPDF's page-sized @@ -359,7 +359,7 @@ fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void { core.settings.workspace_tag = if (std.c.getenv("PARDES_WORKSPACE_TAG")) |v| std.mem.eql(u8, std.mem.span(v), "1") else - @import("pardes_config").workspace_tag; + @import("pardes_options").workspace_tag; core.view().frontend.native_images = true; var prompt_rcs = host_io.Shell.prepare(); @@ -2461,7 +2461,7 @@ test "pardes.h matches the Zig boundary" { try expectEqual(@sizeOf(c.pardes_image_s), @sizeOf(Image)); inline for (@typeInfo(Image).@"struct".field_names) |name| try expectEqual(@offsetOf(c.pardes_image_s, name), @offsetOf(Image, name)); - try expectEqual(@sizeOf(c.pardes_runtime_s), @sizeOf(Runtime)); + try expectEqual(@sizeOf(c.pardes_callbacks_s), @sizeOf(Callbacks)); try expectEqual(@as(u32, c.PARDES_COLOR_DEFAULT), color_default); try expectEqual(@as(u32, c.PARDES_COLOR_INDEXED), color_indexed); diff --git a/runtime/main.zig b/runtime/main.zig index 2b600d63..448dfa57 100644 --- a/runtime/main.zig +++ b/runtime/main.zig @@ -753,7 +753,7 @@ const Word = struct { /// Its group: the first key after the leader, else what it is. fn group(w: Word) []const u8 { if (std.mem.indexOf(u8, w.doc, " (addon ") != null and std.mem.endsWith(u8, w.doc, ")")) return "addon"; - if (pardes.config.Runtime.find(w.name) != null) return "setting"; + if (pardes.config.Settings.find(w.name) != null) return "setting"; if (std.meta.stringToEnum(pardes.builtins.registry.Builtin(), w.name)) |b| if (pardes.config.leader_path.get(b)) |p| switch (p[0]) { 'f' => return "file", 'c' => return "column", diff --git a/runtime/root.zig b/runtime/root.zig index ec89e734..930f3389 100644 --- a/runtime/root.zig +++ b/runtime/root.zig @@ -22,9 +22,9 @@ test { _ = ninep; // main.zig's test block collected the crash file's: a shell's build // (shell-test); the core without a terminal (core-test) never compiled it. - if (comptime @import("term_options").terminal) _ = crash; + if (comptime @import("pardes_options").terminal) _ = crash; // A window's build links the window's C (font.c over FreeType and // HarfBuzz) into each of its programs, and their allocator (ui_malloc // and the rest) is gui.zig's. - if (comptime @import("term_options").terminal and @import("pardes_config").platform == .gui) _ = @import("dev").gui; + if (comptime @import("pardes_options").terminal and @import("pardes_options").platform == .gui) _ = @import("dev").gui; } diff --git a/runtime/session.zig b/runtime/session.zig index f401c85a..3942aa83 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -2,23 +2,24 @@ //! (dev/gui `runNative`) alike, each with a frontend of its own. It holds //! the session's allocators and workers, its core (an upgrade's, a dump's //! or a new one), the prompt files its shells start with, its 9P listener -//! and its replica clients (`Peers`): a step, its unit to the clients and -//! theirs taken in, an Upgrade or a Restore between steps; and the order -//! its parts end in. Its devices (the ptys and their readers, the files -//! watched, the LSP's and the pipes' and addons' jobs, the queue they post -//! to, the session's own input) are still its frontend's (each `Shell`, -//! the services step's to make one). What a frontend does is: +//! its replica clients (`Peers`), its queue (the workers' and readers' +//! posts, `Inbox`) and its ptys (`Ptys`): a step, its unit to the clients +//! and theirs taken in, an Upgrade or a Restore between steps; and the +//! order its parts end in. Its other devices (the files watched, the LSP's +//! and the pipes' and addons' jobs, the session's own input) are still its +//! frontend's (each `Shell`). What a frontend does is: //! //! - `options(o)`: before the core: what it gives the core it starts (a //! window's size, for a dump's layout). //! - `open(l) Host`: its devices made over the session's core and parts, -//! the host the core steps with (the core's, set there); what it does -//! before the core's first effects (an upgraded terminal's panes its -//! own again, whether anyone looks). +//! the host the core steps with (the core's, set there), who wakes it +//! when the queue gets a post (`l.inbox`); what it does before the +//! core's first effects (an upgraded terminal's panes its own again, +//! whether anyone looks). //! - `close(l)`: its devices stopped, after the clients are let go and -//! before the core goes. -//! - `resumePtys(rec)`: an upgraded session's shells, its own again. -//! - `start(l)`: after the first effects: its input, its readers, the +//! before the ptys, the queue and the core go. +//! - `start(l)`: after the first effects, the ptys read: its input, its +//! readers, the //! listener's wake, a detached session's first wait (`l.watch`). //! - `sent()`: after each step's unit went to the clients. //! - `upgradeAsked()`: an Upgrade asked in the step, done (it execs). @@ -32,6 +33,7 @@ const std = @import("std"); const pardes = @import("core"); const replica = pardes.replica; const host_io = @import("dev").host_io; +const Ptys = host_io.Ptys; const file_watch = @import("dev").file_watch; const daemon = @import("daemon.zig"); const upgrade = @import("upgrade.zig"); @@ -52,6 +54,10 @@ pub fn Loop(comptime Frontend: type) type { frames: pardes.FrameStats = .{}, core: *pardes.Pardes = undefined, prompt_rcs: host_io.Shell.PromptFiles = undefined, + /// What the session's workers and readers post, for the frontend + /// to take in its wait. + inbox: host_io.Inbox = undefined, + ptys: Ptys = undefined, fs: ?*ninep_io.Listener = null, peers: replica.Peers = .{}, host: pardes.Host = undefined, @@ -83,6 +89,10 @@ pub fn Loop(comptime Frontend: type) type { l.fs = ninep_io.start(l.io, l.gpa, l.core); defer if (l.fs) |f| f.deinit(l.gpa); l.peers = .{ .gpa = l.gpa, .io = l.io, .name = daemon.name() }; + l.inbox = .{ .io = l.io, .gpa = l.gpa, .lsp_allocator = l.allocs.lsp }; + defer l.inbox.deinit(); + l.ptys = .{ .queue = &l.inbox, .prompt_rcs = &l.prompt_rcs }; + defer l.ptys.deinit(); l.host = try fe.open(&l); defer fe.close(&l); @@ -93,9 +103,10 @@ pub fn Loop(comptime Frontend: type) type { // ...and its shells, once a fresh session's own has a directory // to adopt them in. if (upgrade.resumed) |*rec| { - fe.resumePtys(rec); + l.ptys.resumeFrom(l.core, rec); l.effects(); } + l.ptys.start(l.core); try fe.start(&l); while (!l.core.quit) { @@ -140,11 +151,13 @@ pub fn Loop(comptime Frontend: type) type { } /// A Restore: the core its dump makes replaces this one, its clients - /// let go (host_io.restoreCore); the frontend's devices with it. + /// let go (host_io.restoreCore); its shells and the frontend's + /// devices with it. fn restore(l: *L, path: []const u8) void { const w = l.fe.watched(); const nc = host_io.restoreCore(l.gpa, l.core, path, &l.peers, w.fd, w.table) orelse return; l.fe.restoring(nc); + l.ptys.stop(); nc.host = l.host; if (l.fs) |f| f.reset(nc); l.core.deinit(); diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index 77928dd0..2a8d6edf 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -80,9 +80,9 @@ pub fn noticeNewer(core: *pardes.Pardes) void { if (newer()) core.setMessage(.at(core.view().active), pardes.newer_build_words); } -/// Whether to say a newer build is installed now (`noticeNewer`): the -/// tty's Host answers the core's focus step with it, so its replica -/// clients take the line from the tape. +/// Whether to say a newer build is installed now (`noticeNewer`): asked +/// by a session's own frontend at its focus-in, between steps; the line is +/// an input (setMessage) its replica clients take from the tape. pub fn newer() bool { const was = started_inode orelse return false; const now = inodeOf(exe() orelse return false) orelse return false; |
