summaryrefslogtreecommitdiff
path: root/src/Core.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 02:31:55 -0300
committerGabriel Schneider <[email protected]>2026-11-06 04:04:25 -0300
commit9c66cdc9049b49f128336dcf5046e2bb1321e281 (patch)
tree7ff664677eb7291558f71a8f824d0ce6a922779a /src/Core.zig
parenta6f294ef5b50aeb5b69e486838378654e318ed04 (diff)
downloadpardes-9c66cdc9049b49f128336dcf5046e2bb1321e281.tar.gz
pardes-9c66cdc9049b49f128336dcf5046e2bb1321e281.zip
kinds #5, ABI 2 and the seam: src/kinds/pardes_addon.h is ABI 2 as architecture §16.9 has it (pa_window 24 bytes and no art bytes, pa_placement 80 with at, from and dirty_y/dirty_h and no stride, pa_word 32 with no size and PA_WORD, tick(st, now_ns, flags) with PA_FOCUSED, PA_OK and the conventions, the dump and load rules, pa_put with attrs, pa_copy and PA_POD, whose fragment gcc -Werror refused as written and is ternaries here) and fake.c and image's table speak it; tick is called at its deadline and once after open, a taken key or click, a word, a job's answer, a load and a change of PA_FOCUSED (the pane has the keyboard in some view, its window focused), nextWake folds the deadlines, and a Debug build hashes the kind's allocations across paint and panics naming it; paint runs once a frame, the slot keeps its prefix and whether it placed a picture, the tag is that prefix, the core's art words when it did and the path, and a frame that changes it owes a step to lay the tag out again; Addon load and reload are an addon effect the host performs (memfd, BLAKE3, dlopen, the head checks and init, the bytes a process holds shared and counted) answered by an addon event carrying what the library brings as data, whose update does the collisions, the reload's validate-then-swap at a new generation and the waiting panes deterministically, while unload is the update's alone and lets the library go by effect; a kind's job is Effect.job run on the host's workers (host_io.KindJob: tui and gui on Io.concurrent, macOS and tests on the loop) answered by Event.job, stale generations dropped and a library closed after its last job; each core has its own Registry (16 kinds, their words, leaders and extensions, digested and dumped; their code a local side array a replica has none of), so a test session no longer unloads the world and Restore and -l keep the process's kinds; every call into a kind whose answer the core acts on is taped as an Outcome (its answer, refusal, message, Look, text pane) and the prefix a step reads is taped too, so a replica's core, which runs no kind's code, steps alike; a pane of a kind on a replica is a Shadow drawn from the authority's frames, painted for the peer's view and sent by Screens as row hashes with the rows that changed and each raster once a key (screen_state.Shadow), its keys going to the authority; the tail, reload and the Addon word and event are Addon.zig's, the slot's record dump.zig's, a tail word's run exec.zig's; --addon-test gains focus, blur, dump, body, ctl and the window line, its jobs done as a host does them; fake.out gains its window line, loses a body row once the tag carries the art words and lands FakeJob at once; tests rewritten: the image dump test (the replica-style load keeps the record), the Petscii/Palette/Ascii tag test in ctl.zig and test/panes.zig's image tag test (a picture decoded and shown first), fs_namespace's decode test (the job performed as a host would), Kind.zig's registry test and Addon.zig's crash-mark test, the addons suite's ABI numbers; new: a job under way across a reload (T1), a Shadow's frame codec, and a replica with no code for a kind showing its pane and passing its keys; gates: core-test 958/958 and behaviour-test 249/249 on both, unit-test 1490/1491 tui and 1533/1534 gui, pane-test 171/172, snap all 105 ok, process-test 0 of 37 failed on both, addon-test ok, hxdiff 19 and hxparity 6 mismatches by the base's names, hxgolf 0, replicas, gui-golden, monkey-gui, daemon.py main and window-clients, soak local pass, perf medium within 1% of the base
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/Core.zig')
-rw-r--r--src/Core.zig27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/Core.zig b/src/Core.zig
index 5c68a5af..bbacc536 100644
--- a/src/Core.zig
+++ b/src/Core.zig
@@ -91,6 +91,9 @@ const Pardes = @This();
gpa: std.mem.Allocator,
image_gpa: std.mem.Allocator,
+/// Its kinds of pane (Kind.zig): the compiled-in ones, then what addons
+/// brought; the data both cores hold, the code only the authority.
+kinds: pardes.Kind.Registry = .{},
pdf_gpa: std.mem.Allocator,
tree_sitter_gpa: std.mem.Allocator,
opts: Options,
@@ -460,6 +463,7 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes {
p.* = .{
.gpa = gpa,
.image_gpa = opts.image_allocator orelse gpa,
+ .kinds = .started(opts.addons),
.pdf_gpa = opts.pdf_allocator orelse gpa,
.tree_sitter_gpa = opts.tree_sitter_allocator orelse gpa,
.opts = opts,
@@ -508,7 +512,7 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes {
const opened = initial_doc: {
if (comptime pdf_enabled) if (look.isPdfPath(path))
break :initial_doc pardes.panes.Pdf.openPane(p, 0, path, opts.file_line, .last);
- if (pardes.Kind.forPath(path)) |kind|
+ if (p.kinds.forPath(path)) |kind|
break :initial_doc pardes.Kind.openFile(p, 0, kind, path);
break :initial_doc pardes.panes.File.open(p, 0, path, opts.file_line);
};
@@ -1192,7 +1196,7 @@ pub fn dropPendingWrite(p: *Pardes, id: usize) void {
pub fn postEvent(p: *Pardes, ev: Event) void {
switch (ev) {
.key => |k| std.debug.assert(k.text.len == 0),
- .output, .paste, .lsp_resp, .pipe_resp, .search, .file_changed, .command, .addon => unreachable,
+ .output, .paste, .lsp_resp, .pipe_resp, .search, .file_changed, .command, .addon, .job => unreachable,
else => {},
}
if (p.in_len == p.in_q.len) return;
@@ -1623,7 +1627,8 @@ pub fn update(p: *Pardes, ev: Event) void {
if (focused) if (p.host.vtable.newer_build) |f| if (f(p.host.ctx)) p.setMessage(p.active, newer_build_words);
},
.handed => |h| p.handover.finish(p, h.seq, h.to, h.failure),
- .addon => |a| pardes.Kind.landed(p, a.op, a.pane, a.ok, a.text),
+ .addon => |a| pardes.Addon.landed(p, a.op, a.pane, a.kind.*),
+ .job => |j| pardes.Kind.jobDone(p, j.pane, j.serial, j.token, j.gen, j.bytes),
.frontend => |f| {
p.frontend = f;
},
@@ -2166,6 +2171,8 @@ pub const Options = struct {
recent_import: ?[]const u8 = null,
startup_config_path: ?[]const u8 = null,
image_allocator: ?std.mem.Allocator = null,
+ /// What the host's scan of the addon directories found (Addon.scan).
+ addons: []const pardes.Kind.Loaded = &.{},
pdf_allocator: ?std.mem.Allocator = null,
tree_sitter_allocator: ?std.mem.Allocator = null,
/// Where each frame's Surface text is built. Hosts pass a purpose-built
@@ -2471,7 +2478,7 @@ test "Filter is ordered after Del and toggles only its terminal or +Pager pane"
try testing.expect(!first.tty_filter);
const doc_id = p.freeSlot().?;
- const doc = try pardes.Kind.open(p, doc_id, &image.kind, "/tmp/filter-inert.ppm", "");
+ const doc = try pardes.Kind.open(p, doc_id, pardes.Kind.image, "/tmp/filter-inert.ppm", "");
try testing.expect(!doc.tty_filter);
try testing.expect(p.executeBuiltinLine(doc_id, "Filter"));
try testing.expect(!doc.tty_filter);
@@ -2641,7 +2648,7 @@ test "unknown Exec from a document runs as a command pane in its directory, type
// A terminal free at a prompt in the same directory is not borrowed.
p.setCwd(0, "/tmp/pardes-image-dir");
- const image_doc = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pardes-image-dir/pic.ppm", null);
+ const image_doc = try pardes.Kind.open(p, 1, pardes.Kind.image, "/tmp/pardes-image-dir/pic.ppm", null);
try std.testing.expectEqualStrings("/tmp/pardes-image-dir", Pardes.paneDir(image_doc));
const dst = exec.execute(p, 1, "echo image-fallback") orelse return error.ExecFoundNowhereToRun;
try std.testing.expect(dst != 0 and dst != 1);
@@ -2695,7 +2702,7 @@ test "a command of several lines keeps its tag one row, and its echo does not st
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- _ = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pic.ppm", null);
+ _ = try pardes.Kind.open(p, 1, pardes.Kind.image, "/tmp/pic.ppm", null);
const two = "def greet(name):\n return name\n\nprint(greet(\"x\"))\n";
const dst = exec.execute(p, 1, two) orelse return error.NoCommandPane;
while (p.nextEffect()) |_| {}
@@ -3043,7 +3050,7 @@ test "a command pane shows how its command ended, and the next command there run
defer p.deinit();
while (p.nextEffect()) |_| {}
p.setCwd(0, "/tmp/pardes-cmd");
- _ = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pardes-cmd/pic.ppm", null);
+ _ = try pardes.Kind.open(p, 1, pardes.Kind.image, "/tmp/pardes-cmd/pic.ppm", null);
const dst = exec.execute(p, 1, "make -j8") orelse return error.NoCommandPane;
while (p.nextEffect()) |_| {}
@@ -3143,7 +3150,7 @@ test "image dump restores source bytes renderer choices and exact custom tail" {
p.panes[0] = null;
const source = "\x00embedded image bytes\xff";
- const pane = try pardes.Kind.open(p, 0, &image.kind, "/missing/restored-image.ppm", source);
+ const pane = try pardes.Kind.open(p, 0, pardes.Kind.image, "/missing/restored-image.ppm", source);
pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false };
if (pane.tag.own) |own| p.gpa.free(own);
pane.tag.own = try p.gpa.dupe(u8, " Keep Del");
@@ -3166,8 +3173,8 @@ test "image dump restores source bytes renderer choices and exact custom tail" {
try dump.dumpState(restored);
const again = try dump.load(gpa, .{ .tty_only = true }, restored.dump_out.?, null);
defer again.deinit();
- const again_slot = again.panes[0].?.addon.?;
- try std.testing.expectEqualSlices(u8, source, kept[0..image.kind.dump.?(again_slot.st, &kept, kept.len)]);
+ // Loaded as a replica loads it: a placeholder holding the record.
+ try std.testing.expectEqualSlices(u8, source, again.panes[0].?.addon.?.record.?);
}
test "a terminal its program gave back takes command lines again" {