summaryrefslogtreecommitdiff
path: root/core/Kind.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 15:52:33 -0300
committerGabriel Schneider <[email protected]>2026-11-19 15:52:33 -0300
commit8fea4ab90a04acd5f20528b00342c23d42f8c83e (patch)
treebe264d2cd8ba57492e227d9d6a65027f3d7680c9 /core/Kind.zig
parent553a62bac675bfc0a64254718488d3c8012f533e (diff)
parentee2e79dea10c93c104b70cf1eedccd7ba85003fc (diff)
downloadpardes-8fea4ab90a04acd5f20528b00342c23d42f8c83e.tar.gz
pardes-8fea4ab90a04acd5f20528b00342c23d42f8c83e.zip
integration: the soak on the real session loop and the cli's serve thread joined, with the tape's handle through the kinds, the core's own files and the small ones: pardes-runners-d (10c's last changes) and pardes-handle-2 (the handle's steps 3 to 5 and its two rules as tests), merged without a conflict; gates in the coordinator's ledger
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Kind.zig')
-rw-r--r--core/Kind.zig60
1 files changed, 30 insertions, 30 deletions
diff --git a/core/Kind.zig b/core/Kind.zig
index 2bf8e9fb..13ef8edd 100644
--- a/core/Kind.zig
+++ b/core/Kind.zig
@@ -19,7 +19,6 @@ const builtin = @import("builtin");
pub const c = @import("pardes_addon");
const pardes = @import("root.zig");
const walk = @import("walk.zig");
-const tape = @import("tape.zig");
const surface = @import("surface.zig");
const views = @import("views.zig");
const Addon = @import("Addon.zig");
@@ -104,10 +103,10 @@ pub const Registry = struct {
nexts: u8 = 0,
ops: [max_kinds]?*const Ops = @splat(null),
- /// What the scan at start found.
- pub fn started(found: []const Loaded) Registry {
+ /// What the scan at start found, taken on `tape` (a replica's holds no code).
+ pub fn started(tape: *pardes.tape.Tape, found: []const Loaded) Registry {
var r: Registry = .{};
- for (found) |l| _ = r.take(l, "");
+ for (found) |l| _ = r.take(tape, l, "");
return r;
}
@@ -297,25 +296,25 @@ pub fn openFile(p: *Pardes, id: usize, k: u8, path: []const u8) !*Pane {
/// The slot's kind state made (`open`, then `load` with its record, or
/// `address` with its place and its words' last values): its refusal,
/// if the kind refused, in `slot.refused`. One call for both cores.
-pub fn reopen(p: ?*Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool {
+pub fn reopen(p: *Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool {
// A replica has no kind's code: what the open says is the authority's.
- if (tape.authorityOnly("a kind's open")) return false;
+ if (p.tape.authorityOnly("a kind's open")) return false;
var cl: Call = .{ .p = p, .id = id, .slot = s };
const prev = cl.begin("open");
- if (p) |core| if (core.kinds.byName(s.nameOf())) |k| {
+ if (p.kinds.byName(s.nameOf())) |k| {
// Its code: its library loaded at the first pane of its kind.
- if (s.ops == null) s.ops = Addon.need(&core.kinds, k, &cl.refused, core.opts.distrusted);
+ if (s.ops == null) s.ops = Addon.need(&p.kinds, p.tape, k, &cl.refused, p.opts.distrusted);
// Its block made afresh by this open.
- if (core.kinds.kinds[k].caps.plain) {
+ if (p.kinds.kinds[k].caps.plain) {
if (s.plain) |b| if (b.len > 0) s.gpa.free(b);
s.plain = &.{};
}
var w: std.Io.Writer = .fixed(&s.tail.bytes);
w.writeAll(" Term") catch {};
- for (core.kinds.words[0..core.kinds.nwords]) |*kw| if (kw.kind == k and kw.opens == 0) w.print(" {s}", .{kw.name.slice()}) catch {};
+ for (p.kinds.words[0..p.kinds.nwords]) |*kw| if (kw.kind == k and kw.opens == 0) w.print(" {s}", .{kw.name.slice()}) catch {};
w.writeAll(" Collapse Del") catch {};
s.tail.len = @intCast(w.buffered().len);
- };
+ }
s.opened = if (bytes) |b| std.hash.Wyhash.hash(0, b) else 0;
// Its file not read (not here): it waits for it, a placeholder.
if (s.ops != null and bytes == null and s.path.len > 0) _ = cl.refused.print("{s} is not here", .{s.path}) else if (s.ops) |ops| {
@@ -346,7 +345,7 @@ pub fn reopen(p: ?*Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool {
if (s.record) |r| s.gpa.free(r);
s.record = null;
s.live = true;
- if (p) |core| poke(core, s);
+ poke(p, s);
return true;
}
@@ -397,7 +396,7 @@ pub fn close(p: *Pardes, pane: *Pane) void {
// A client's pane of a plain kind closed in a speculation: its kind's
// own memory (its pictures) is left be, as the rollback brings the pane
// back; the session's order closes it.
- const kept = s.plain != null and s.ops != null and s.ops.?.close != null and tape.authorityOnly("a kind's close");
+ const kept = s.plain != null and s.ops != null and s.ops.?.close != null and p.tape.authorityOnly("a kind's close");
if (!kept) {
var i: usize = 0;
while (i < ready.items.len) if (ready.items[i].draw == p and ready.items[i].serial == pane.serial) ready.orderedRemove(i).drop() else {
@@ -559,7 +558,7 @@ fn colorOf(v: u32, default: surface.Color) surface.Color {
pub fn prefix(p: *const Pardes, arena: std.mem.Allocator, pane: *const Pane) ![]const u8 {
const slot = pane.addon.?;
var buf: [400]u8 = undefined;
- return arena.dupe(u8, tape.value(.addon, prefixOf, .{ p, slot, &buf }));
+ return arena.dupe(u8, p.tape.value(.addon, prefixOf, .{ p, slot, &buf }));
}
fn prefixOf(p: *const Pardes, slot: *const Slot, buf: *[400]u8) []const u8 {
@@ -584,7 +583,7 @@ fn prefixOf(p: *const Pardes, slot: *const Slot, buf: *[400]u8) []const u8 {
pub fn key(p: *Pardes, id: usize, k: pardes.Key) bool {
const slot = (p.panes[id] orelse return false).addon orelse return false;
if (!caps(p, slot).key) return false;
- if (!runsHere(slot) and tape.authorityOnly("a key into a kind's pane")) return true;
+ if (!runsHere(slot) and p.tape.authorityOnly("a key into a kind's pane")) return true;
const pk: c.pa_key = .{ .cp = k.cp, .ctrl = @intFromBool(k.ctrl), .alt = @intFromBool(k.alt), .shift = @intFromBool(k.shift), .view = p.live + 1 };
var cl: Call = .{ .p = p, .id = id, .slot = slot };
const prev = cl.begin("key");
@@ -608,7 +607,7 @@ pub fn takesKeys(p: *const Pardes, s: *const Slot) bool {
pub fn search(p: *Pardes, id: usize, pat: []const u8) ?[]const u8 {
const slot = (p.panes[id] orelse return null).addon orelse return null;
if (!caps(p, slot).search) return null;
- if (tape.authorityOnly("a kind's search")) return null;
+ if (p.tape.authorityOnly("a kind's search")) return null;
var cl: Call = .{ .p = p, .id = id, .slot = slot };
const prev = cl.begin("search");
if (slot.ops) |o| o.search.?(slot.st, pat.ptr, @intCast(pat.len));
@@ -624,7 +623,7 @@ pub fn address(p: *Pardes, id: usize, text: []const u8, said: *Buf(160)) bool {
const slot = (p.panes[id] orelse return false).addon orelse return false;
// By its caps, not its code: a replica without it calls as the authority does.
if (!caps(p, slot).address) return false;
- if (tape.authorityOnly("a kind's address")) return true;
+ if (p.tape.authorityOnly("a kind's address")) return true;
var cl: Call = .{ .p = p, .id = id, .slot = slot, .missing = said };
const prev = cl.begin("address");
if (slot.ops) |o| cl.ret = o.address.?(slot.st, text.ptr, @intCast(text.len));
@@ -641,7 +640,7 @@ pub fn takesMouse(p: *const Pardes, s: *const Slot) bool {
pub fn mouse(p: *Pardes, id: usize, m: pardes.Mouse, col: u16, row: u16) bool {
const slot = (p.panes[id] orelse return false).addon orelse return false;
if (!caps(p, slot).mouse) return false;
- if (!runsHere(slot) and tape.authorityOnly("the mouse in a kind's pane")) return true;
+ if (!runsHere(slot) and p.tape.authorityOnly("the mouse in a kind's pane")) return true;
const pm: c.pa_mouse = .{
.button = switch (m.button) {
.left => c.PA_LEFT,
@@ -684,8 +683,8 @@ pub fn step(p: *Pardes, due: bool) void {
// A kind's call is the authority's alone but a plain kind's here: a
// speculation's tick after a call into the pane waits with that call's
// input (it stopped there).
- const speculating = tape.speculating();
- if (speculating) for (p.panes) |pslot| if (pslot) |pane| if (pane.addon) |slot| if (slot.next_tick == 1 and !runsHere(slot)) return tape.poison("a kind's tick");
+ const speculating = p.tape.speculating;
+ if (speculating) for (p.panes) |pslot| if (pslot) |pane| if (pane.addon) |slot| if (slot.next_tick == 1 and !runsHere(slot)) return p.tape.poison("a kind's tick");
for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| {
if (speculating and !runsHere(slot)) continue;
if (due and caps(p, slot).view) for (0..views.max) |k| {
@@ -875,7 +874,7 @@ pub fn ctl(p: *Pardes, id: usize, line: []const u8, reply: *[160]u8) ?[]const u8
const slot = (p.panes[id] orelse return "no such pane").addon orelse return "not a kind's pane";
if (!slot.live) return "its addon is not loaded";
if (!caps(p, slot).ctl) return "its kind takes no words";
- if (tape.authorityOnly("a kind's word")) return null;
+ if (p.tape.authorityOnly("a kind's word")) return null;
var cl: Call = .{ .p = p, .id = id, .slot = slot };
const prev = cl.begin("ctl");
@memset(reply, 0);
@@ -975,19 +974,20 @@ const Call = struct {
current = prev;
if (checked) overBudget(cl);
if (cl.quiet) return .{};
+ // One that is not quiet is a step's, made with its core.
+ const t = cl.p.?.tape;
var place: [32]u8 = undefined;
// A refused open closed its state: no `where` to ask.
const at: ?[]const u8 = if (cl.refused.len == 0) where(cl.slot, &place) else null;
// Hashed while it records or replays: no client, no cost.
- const state: u64 = if (tape.on == null) 0 else if (cl.slot.plain) |b| std.hash.Wyhash.hash(0, b) else 0;
- const o = tape.value(.addon, same, .{Outcome{ .state = state, .ret = cl.ret, .text = cl.refused.slice(), .said = cl.said.slice(), .err = cl.err, .look = cl.look.slice(), .pane_name = cl.pane_name.slice(), .pane_text = cl.pane_text, .exec = cl.exec.slice(), .selected = cl.selected, .rows = cl.rows, .prefix = cl.prefix, .where = at, .jobs = cl.jobs, .cancels = cl.cancels }});
+ const state: u64 = if (t.through) 0 else if (cl.slot.plain) |b| std.hash.Wyhash.hash(0, b) else 0;
+ const o = t.value(.addon, same, .{Outcome{ .state = state, .ret = cl.ret, .text = cl.refused.slice(), .said = cl.said.slice(), .err = cl.err, .look = cl.look.slice(), .pane_name = cl.pane_name.slice(), .pane_text = cl.pane_text, .exec = cl.exec.slice(), .selected = cl.selected, .rows = cl.rows, .prefix = cl.prefix, .where = at, .jobs = cl.jobs, .cancels = cl.cancels }});
if (o.where) |w| cl.slot.where_text.set(w);
// Run here, it came out otherwise than the session's: it broke its
// promise (PA_PLAIN), and the client joins again without it.
- if (cl.slot.ops != null and cl.slot.plain != null and tape.replaying() and o.state != state) {
+ if (cl.slot.ops != null and cl.slot.plain != null and t.replaying() and o.state != state) {
if (cl.p) |p| if (p.opts.distrusted) |d| d.add(cl.slot.nameOf());
- var why: Buf(160) = .{};
- tape.diverged(why.print("addon {s}: its state after {s} is not the session's (it breaks PA_PLAIN): the session's alone now", .{ cl.slot.nameOf(), cl.name }));
+ if (t.replay) t.diverge("addon {s}: its state after {s} is not the session's (it breaks PA_PLAIN): the session's alone now", .{ cl.slot.nameOf(), cl.name });
}
cl.slot.state = o.state;
// Its last job's token the session's, on a core whose kind asked
@@ -1120,7 +1120,7 @@ pub const api: c.pa_api = .{
const asked = std.mem.indexOfScalar(u32, &cl.jobs, 0) orelse return 0;
// A client's (a plain kind's code here) runs none: its token
// alone, as the session's; the answer comes on the tape.
- const free = if (tape.replaying()) null else for (&s.jobs) |*j| {
+ const free = if (cl.p.?.tape.replaying()) null else for (&s.jobs) |*j| {
if (j.* == null) break j;
} else return 0;
const copy = if (free != null) s.gpa.dupe(u8, if (in) |b| @as([*]const u8, @ptrCast(b))[0..n] else "") catch return 0 else "";
@@ -1317,7 +1317,7 @@ pub const test_kind = struct {
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), "");
+ _ = p.kinds.take(p.tape, loadedOf(&ops, "", @splat(0), &words), "");
return p.kinds.n - 1;
}
};
@@ -1356,10 +1356,10 @@ test "a kind's head is checked before a core takes it, and a core's kinds are it
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.take(&pardes.tape.none, 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 zzzab is here already", a.take(&pardes.tape.none, loadedOf(&ops, "", @splat(1), &words), "").?);
a.drop(a.byName("zzzab").?);
try std.testing.expect(a.byName("zzzab") == null);
}