summaryrefslogtreecommitdiff
path: root/src/Kind.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 05:19:21 -0300
committerGabriel Schneider <[email protected]>2026-11-06 05:55:49 -0300
commitc8553032ef84aec74cbb5d07d07f934eecf3d4a9 (patch)
treee47d3dd72b83e0b95d53271df9f5932dab389959 /src/Kind.zig
parentde0447471febe1253b42a32fe9a1d6cdccc9d5b9 (diff)
downloadpardes-c8553032ef84aec74cbb5d07d07f934eecf3d4a9.tar.gz
pardes-c8553032ef84aec74cbb5d07d07f934eecf3d4a9.zip
kinds #9, the core's image code gone: src/image.zig (558 lines) and the static table go, so no kind is compiled in (Registry.init, Kind.image, compiledIn, `static` in /addons and "is compiled in" with them) and a test of the core's side of a kind's pane opens Kind.test_kind (a picture of one pixel, no library); a placement's fit (NativeGeometry, containGeometry) moves to surface.zig and a PDF's fit modes to pdf_view.zig; a terminal's kitty PNG decodes in TerminalImages.zig through wuffs as before, its downscale through stb_image_resize, the one part of zstbi the core keeps (stb_image patched out of it, the wuffs_images option, tag_image and image_exts gone); the image cases load the built image.so by path: test/panes.zig's and fs_namespace's through Addon.perform, T1 through Addon load (a new behaviour case: PNG, JPEG and PPM through 9P, the art words, a refused corrupt PNG, a dump's placeholder and its picture back, which replaces the decode unit test and ctl.zig's corrupt-image case), the snapshot, process and image harnesses by linking it into each session's data directory; images.snap unchanged
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/Kind.zig')
-rw-r--r--src/Kind.zig48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/Kind.zig b/src/Kind.zig
index 241acf4b..60d86778 100644
--- a/src/Kind.zig
+++ b/src/Kind.zig
@@ -2,7 +2,7 @@
//! anything an addon (a library, Addon.zig) brings. Its records and
//! functions are the C ABI of src/kinds/pardes_addon.h (translated, the
//! one copy); this file is the core's side of it: the kinds a core has
-//! (`Registry`, compiled in or brought, with their words and extensions),
+//! (`Registry`, what libraries brought, with their words and extensions),
//! and a pane's `Slot`, the state the core keeps round the kind's own.
//!
//! The core is deterministic and a kind is only the authority's: a
@@ -47,8 +47,6 @@ comptime {
// ---- the kinds a core has ----
pub const max_kinds = 16;
-/// The kinds compiled in come first in every core: the image is kind 0.
-pub const image: u8 = 0;
/// Which of its functions a kind has: what both cores decide by.
pub const Caps = packed struct(u8) {
@@ -77,17 +75,13 @@ pub const Entry = struct {
pub fn nameOf(e: *const Entry) []const u8 {
return std.mem.sliceTo(&e.name, 0);
}
- pub fn compiledIn(e: *const Entry) bool {
- return std.mem.allEqual(u8, &e.hash, 0);
- }
};
pub const Word = struct { kind: u8, name: Buf(32) = .{}, leader: Buf(8) = .{}, arg: u8 = 0, opens: u8 = 0, doc: Buf(96) = .{} };
pub const Ext = struct { kind: u8, ext: Buf(16) = .{} };
-/// A core's kinds: the compiled-in ones every core starts with, then what
-/// libraries brought (Addon.zig), as data both cores hold alike; and each
-/// one's code here, which a replica has none of for a library's.
+/// A core's kinds: what libraries brought (Addon.zig), as data both cores
+/// hold alike; and each one's code here, which a replica has none of.
pub const Registry = struct {
pub const replica = .{
.local = .{"ops"},
@@ -101,17 +95,9 @@ pub const Registry = struct {
nexts: u8 = 0,
ops: [max_kinds]?*const Ops = @splat(null),
- /// The kinds compiled in.
- pub fn init() Registry {
- var r: Registry = .{};
- var words: [64]LoadedWord = undefined;
- _ = r.take(loadedOf(&@import("image.zig").kind, "", @splat(0), &words), "");
- return r;
- }
-
- /// The kinds compiled in and what the scan at start found.
+ /// What the scan at start found.
pub fn started(found: []const Loaded) Registry {
- var r: Registry = .init();
+ var r: Registry = .{};
for (found) |l| _ = r.take(l, "");
return r;
}
@@ -793,6 +779,25 @@ fn textPane(p: *Pardes, id: usize, slot: *const Slot, name: []const u8, text: []
@import("exec.zig").placeNew(p, id, id, free, .doc);
}
+/// A kind for tests of the core's side of a kind's pane, no library: a
+/// picture of one pixel over its body.
+pub const test_kind = struct {
+ const pixel = [4]u8{ 255, 0, 0, 255 };
+ fn picture(_: ?*anyopaque, win: [*c]const c.pa_window, out: [*c]c.pa_paint) callconv(.c) void {
+ out.*.placements[0] = std.mem.zeroInit(c.pa_placement, .{ .rgba = &pixel, .w = 1, .h = 1, .src = .{ .x = 0, .y = 0, .w = 1, .h = 1 }, .dst = .{ .x = 0, .y = 0, .w = win.*.cols, .h = win.*.rows } });
+ out.*.n = 1;
+ }
+ const ops = std.mem.zeroInit(Ops, .{ .head = std.mem.zeroInit(c.pa_head, .{ .size = @sizeOf(c.pa_head), .abi = abi, .name = "test".* ++ @as([12]u8, @splat(0)), .version = 1 }), .paint = picture });
+
+ /// Its index in `p`'s kinds, taken in at the first ask.
+ pub fn of(p: *Pardes) u8 {
+ if (p.kinds.byName("test")) |k| return k;
+ var words: [64]LoadedWord = undefined;
+ _ = p.kinds.take(loadedOf(&ops, "", @splat(0), &words), "");
+ return p.kinds.n - 1;
+ }
+};
+
// ---- small things ----
pub fn Buf(comptime n: usize) type {
@@ -824,14 +829,13 @@ test "a kind's head is checked before a core takes it, and a core's kinds are it
};
var ops = std.mem.zeroInit(Ops, .{ .head = std.mem.zeroInit(c.pa_head, .{ .size = @sizeOf(c.pa_head), .abi = abi, .version = 3 }), .paint = Fake.paint });
@memcpy(ops.head.name[0..5], "zzzab");
- var a: Registry = .init();
- var b: Registry = .init();
+ var a: Registry = .{};
+ var b: Registry = .{};
var words: [64]LoadedWord = undefined;
try std.testing.expect(a.take(loadedOf(&ops, "", @splat(1), &words), "") == null);
try std.testing.expect(a.byName("zzzab") != null);
try std.testing.expect(b.byName("zzzab") == null);
try std.testing.expectEqualStrings("refused: kind zzzab is here already", a.take(loadedOf(&ops, "", @splat(1), &words), "").?);
- try std.testing.expectEqualStrings("refused: kind image is here already", b.take(loadedOf(&@import("image.zig").kind, "", @splat(1), &words), "").?);
a.drop(a.byName("zzzab").?);
try std.testing.expect(a.byName("zzzab") == null);
}