summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 16:03:52 -0300
committerGabriel Schneider <[email protected]>2026-11-19 16:41:06 -0300
commitd0e36bb453526af64349a4eb2335b86c94bea56d (patch)
tree7481782dd321033ece1995372aaaec95830a8f0d /core
parent8fea4ab90a04acd5f20528b00342c23d42f8c83e (diff)
downloadpardes-d0e36bb453526af64349a4eb2335b86c94bea56d.tar.gz
pardes-d0e36bb453526af64349a4eb2335b86c94bea56d.zip
core: a pane's slot and a view's slot are two types, `Pane.Id` and `View.Id` (P21, pardes-ids change 1; the user, reading the tape's inputs: "why the id is an u8 though?", and "the id to be typed too"): each a distinct non-exhaustive `enum(u8)` (`pub const Id` inside `Pane` in core/panes.zig and inside `Pardes.View` in core/Core.zig, side by side with the thing whose slot it is), with the one conversion each way the boundary needs, named once: `Id.at(i)` the id of a slot the core holds (`@fromBackingInt(@intCast(i))`, so a slot past a byte panics in a safe build) and `id.index()` the slot as a `u8` (which widens to the `usize` half the core indexes with, so no caller casts); nothing uses them yet; one test at the end of core/views.zig, "a pane's id and a view's id are two types: neither is taken for the other, nor for an integer" (an enum coerces only into itself, so it shows the two are distinct, a byte each and non-exhaustive, and every slot round-trips; a probe that assigned a `View.Id` to a `Pane.Id` failed to compile with "expected type 'panes.Pane.Id', found 'Core.View.Id'"); 46 lines added in three files, no line changed; nothing a step runs is touched, so the frame and perf gate was not run on it and the semantics word does not move (313a99190b93a8c5); gate (load 5 to 10, a drat build beside): tui core-test 841/984 (143 skipped), shell-test 1020/1023, gui unit-test 1618/1622 (the perf check's BaselineHarnessMismatch, the base's 1617/1621 with it), each the base's plus this test
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
-rw-r--r--core/Core.zig15
-rw-r--r--core/panes.zig15
-rw-r--r--core/views.zig16
3 files changed, 46 insertions, 0 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 769d16cd..85087b11 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -89,6 +89,21 @@ const Pardes = @This();
/// its focus, its pointer and gestures, its jumps, its key prefixes.
pub const View = struct {
pub const replica = .{ .len = .{ .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" } } };
+ /// A view's slot in `Pardes.views`, as it crosses the core's edge: an
+ /// entry's argument or answer, the wire's welcome. A type of its own,
+ /// so a pane's slot (`Pane.Id`) is not taken for it; the core's own
+ /// view indexes (`live`, views.zig) keep their integers.
+ pub const Id = enum(u8) {
+ _,
+ /// The id of slot `k`, a slot the core holds.
+ pub fn at(k: usize) Id {
+ return @fromBackingInt(@intCast(k));
+ }
+ /// The slot, to index the core's views with.
+ pub fn index(id: Id) u8 {
+ return @backingInt(id);
+ }
+ };
screen_w: u16 = 0,
screen_h: u16 = 0,
diff --git a/core/panes.zig b/core/panes.zig
index cdc28dba..dd36839a 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -38,6 +38,21 @@ pub const Pane = struct {
// it there).
.alloc = .{ .{ "addon", "image" }, .{ "pdf", "image" }, .{ "terminal", "terminal" } },
};
+ /// A pane's slot in `Pardes.panes`, as it crosses the core's edge: an
+ /// entry's argument or answer, an event's, an effect's, a host call's.
+ /// A type of its own, so a view's slot (`View.Id`) is not taken for
+ /// it; the core's own loops and tables keep their integers.
+ pub const Id = enum(u8) {
+ _,
+ /// The id of slot `i`, a slot the core holds.
+ pub fn at(i: usize) Id {
+ return @fromBackingInt(@intCast(i));
+ }
+ /// The slot, to index the core's tables with.
+ pub fn index(id: Id) u8 {
+ return @backingInt(id);
+ }
+ };
/// The words that throw unsaved text away (builtins.zig warnModified).
pub const Discarding = enum { Exit, Restore, get, Del, Delcol };
diff --git a/core/views.zig b/core/views.zig
index 9d627a17..ee061964 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -925,3 +925,19 @@ test "a session's dump keeps its views: loaded, each where it was; revived for o
try testing.expectEqual(@as(i32, 30), one.panes[id].?.body.cur_row);
try testing.expectEqual(@as(?u8, 1), one.openView());
}
+
+test "a pane's id and a view's id are two types: neither is taken for the other, nor for an integer" {
+ // An enum coerces into nothing but itself (an enum literal into it, it
+ // into a union of it): two distinct enum types never stand for each
+ // other, so `p.toView(pane_id)` or `p.setMessage(view_id, ..)` does not
+ // compile. What is left to show is that they are two, and a byte each.
+ comptime {
+ std.debug.assert(Pane.Id != View.Id);
+ for (.{ Pane.Id, View.Id }) |T| {
+ const e = @typeInfo(T).@"enum";
+ std.debug.assert(e.tag_type == u8 and e.mode == .nonexhaustive and @sizeOf(T) == 1);
+ }
+ }
+ for (0..MAX_PANES) |i| try testing.expectEqual(i, Pane.Id.at(i).index());
+ for (0..max) |k| try testing.expectEqual(k, View.Id.at(k).index());
+}