diff options
Diffstat (limited to 'src/Kind.zig')
| -rw-r--r-- | src/Kind.zig | 48 |
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); } |
