diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-12 10:56:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | f2b02c455f2bcdfb905a015eefbb630a28b4b12e (patch) | |
| tree | c344c7ad42ec288dd5e1ebd0eb6d25f5aa2fbccc /src/Addon.zig | |
| parent | fc38c73c59f7855a4caad8aa4d3bb8e023309c13 (diff) | |
| download | pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.tar.gz pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.zip | |
addons: an addon can hand the frontend a GPU scene (ABI 3.1), and a snake drawn by shaders does; a commit's patch keeps its own +Diff pane; a real ZLS checked through the window build
ABI 3.1 appends an optional `gpu` callback and its context to pa_paint: one self-contained sketchbook SGPU v1 scene for the pane, at most 4 MiB, copied during the call, the last successful call winning. The SDL frontend runs it on its own GPU through sketchbook's executor and composites its target texture into the pane; replicas carry the scene beside the authoritative pane frame; cells and rasters stay the fallback for terminals, older hosts and frontends without an executor. addons/snake_shader is such an addon (`zig build snake-shader`, the SnakeShader word: a board that follows its pane, buffered turns, a CRT look), with test/gpu_snake.py, test/gpu_snake_interaction.py and test/gpu_upgrade.py.
Commit patches open as `+Diff-<short-hash>` and reuse only their own commit's pane, so another paged patch no longer replaces one already open.
The language-server client looks in the standard per-user bin directory, which desktop launchers often leave out of PATH, and takes an empty answer that beats the startup progress notification onto the wire; test/real_zls.py checks imports, hover, references, rename previews, diagnostics and completion against a real ZLS from a private home.
The dump's schema reader skips two fields older builds persisted, and a replica's shadow of a kind ticks when the authority's does. The reference, the guide, the building and setup notes and the changelog say so.
The working copy as it stood on 2026-11-12; message written by Claude from the diff, at the author's request.
Diffstat (limited to 'src/Addon.zig')
| -rw-r--r-- | src/Addon.zig | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/src/Addon.zig b/src/Addon.zig index cadf28d7..80d8fdd8 100644 --- a/src/Addon.zig +++ b/src/Addon.zig @@ -313,7 +313,6 @@ fn readSmall(path: [*:0]const u8) Kind.Buf(4096) { return out; } - // ---- the tail: what a library brings, and a core's tables of it ---- /// What a library brings, as the host read it off its head (or why it @@ -356,7 +355,12 @@ pub fn loadedOf(ops: *const Kind.Ops, path: []const u8, hash: [32]u8, words: *[6 .words = words[0..head_words.len], .ops = @intFromPtr(ops), .caps = .{ - .tick = ops.tick != null, .key = ops.key != null, .mouse = ops.mouse != null, .ctl = ops.ctl != null, .jobs = ops.job_run != null, .load = ops.load != null, + .tick = ops.tick != null, + .key = ops.key != null, + .mouse = ops.mouse != null, + .ctl = ops.ctl != null, + .jobs = ops.job_run != null, + .load = ops.load != null, .search = ops.search != null, .address = ops.address != null, .view = ops.view != null, @@ -483,7 +487,6 @@ fn coreWord(name: []const u8) bool { return std.meta.stringToEnum(builtins.registry.Builtin(), name) != null or builtins.absentWhy(name) != null; } - // ---- the core's half ---- /// `Addon load <path>` (relative to the pane's directory), `Addon unload @@ -602,7 +605,8 @@ fn swap(p: *Pardes, l: Loaded, why: *Why) bool { }; for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |s| if (s.live and s.is(name)) { const n = s.gpa.create(Kind.Slot) catch return fail(why, "out of memory", .{}); - n.* = .{ .ops = new_ops, .live = true, .gpa = s.gpa, .arena = .init(s.gpa), .name = s.name, .version = l.version, .gen = gen, .art = s.art, .values = s.values }; + // load receives the record's version, not the replacement library's. + n.* = .{ .ops = new_ops, .live = true, .gpa = s.gpa, .arena = .init(s.gpa), .name = s.name, .version = s.version, .gen = gen, .art = s.art, .values = s.values }; fresh[id] = n; n.path = s.gpa.dupe(u8, s.path) catch return fail(why, "out of memory", .{}); // The old state's record, by the old library. @@ -658,6 +662,44 @@ pub fn list(p: *const Pardes, out: *std.ArrayList(u8), gpa: std.mem.Allocator) ! } } +test "addon reload gives migration the old record version and saves the new version" { + const Fake = struct { + var state: u8 = 7; + fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque { + return &state; + } + fn paint(_: ?*anyopaque, _: [*c]const Kind.c.pa_window, _: [*c]Kind.c.pa_paint) callconv(.c) void {} + fn save(_: ?*anyopaque, out: [*c]u8, n: u32) callconv(.c) u32 { + if (n > 0) out[0] = state; + return 1; + } + fn load(_: ?*anyopaque, bytes: [*c]const u8, n: u32, version: u32) callconv(.c) c_int { + return if (version == 1 and n == 1 and bytes[0] == 7) Kind.c.PA_OK else 1; + } + }; + const p = try @import("ninep/testing.zig").withFile(std.testing.allocator, "x\n"); + defer p.deinit(); + var old = std.mem.zeroInit(Kind.Ops, .{ .head = std.mem.zeroInit(Kind.c.pa_head, .{ .size = @sizeOf(Kind.c.pa_head), .abi = Kind.abi, .version = 1 }), .open = Fake.open, .paint = Fake.paint, .dump = Fake.save, .load = Fake.load }); + @memcpy(old.head.name[0..7], "migrate"); + var words: [64]LoadedWord = undefined; + try std.testing.expect(p.kinds.take(loadedOf(&old, "test.so", @splat(0), &words), "") == null); + const pane = try Kind.open(p, 1, p.kinds.byName("migrate").?, null, null); + var new = old; + new.head.version = 2; + var why: Why = .{}; + try std.testing.expect(swap(p, loadedOf(&new, "test.so", @splat(1), &words), &why)); + try std.testing.expectEqual(@as(u32, 2), pane.addon.?.version); + try std.testing.expectEqual(@as(u32, 2), p.kinds.kinds[p.kinds.byName("migrate").?].version); + // A saved v1 placeholder revived by v2 must also save future records as v2. + const slot = pane.addon.?; + slot.version = 1; + slot.live = false; + slot.record = try slot.gpa.dupe(u8, &.{7}); + dump.reviveSlot(p, 1, slot); + try std.testing.expect(slot.live); + try std.testing.expectEqual(@as(u32, 2), slot.version); +} + test "a load that never finished is skipped at the next start, and every start after, until a load asks for it" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); |
