diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Core.zig | 3 | ||||
| -rw-r--r-- | src/Jump.zig | 8 | ||||
| -rw-r--r-- | src/Kind.zig | 30 | ||||
| -rw-r--r-- | src/replica.zig | 64 |
4 files changed, 82 insertions, 23 deletions
diff --git a/src/Core.zig b/src/Core.zig index 2e17b495..86916f9e 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -686,8 +686,7 @@ pub const RecentPlace = struct { path: []const u8, line: u32, col: u32, aline: u pub fn recentPlace(pane: *const Pane) ?RecentPlace { if (recentDot(pane)) |d| return .{ .path = d.path, .line = d.line, .col = d.col, .aline = d.aline, .acol = d.acol }; if (pane.addon) |k| if (k.path.len > 0) { - var buf: [32]u8 = undefined; - const line = Jump.firstNumber(pardes.Kind.placeOf(@constCast(k), &buf)); + const line = Jump.firstNumber(k.where_text.slice()); return .{ .path = k.path, .line = line, .col = @intFromBool(line > 0) }; }; return null; diff --git a/src/Jump.zig b/src/Jump.zig index 11c7da6e..06cf8388 100644 --- a/src/Jump.zig +++ b/src/Jump.zig @@ -51,12 +51,8 @@ const Kind = @import("Kind.zig"); fn kindPlace(pane: *Pane) ?Kind.Buf(32) { const slot = pane.addon orelse return null; if (!slot.live) return null; - var buf: [32]u8 = undefined; - const w = Kind.placeOf(slot, &buf); - if (w.len == 0) return null; - var out: Kind.Buf(32) = .{}; - out.set(w); - return out; + // As its kind's last call left it: the same on every core. + return if (slot.where_text.len == 0) null else slot.where_text; } /// A place's first number: a kind's line (a PDF's page). diff --git a/src/Kind.zig b/src/Kind.zig index 2f40c8ea..619a9c53 100644 --- a/src/Kind.zig +++ b/src/Kind.zig @@ -131,10 +131,10 @@ pub const Registry = struct { pub const Slot = struct { pub const replica = .{ // The kind's own and the authority's (its code and memory, its - // jobs' inputs, its file's hash, a placeholder's record, the place - // its kind says), and what a frame makes (the thumb, the pointer, - // whether one was drawn: a view's, never a step's). - .local = .{ "ops", "st", "gpa", "arena", "opened", "reloads", "jobs", "tokens", "record", "where_text", "thumb_at", "thumb_span", "pointer", "painted", "over", "shadow", "used" }, + // jobs' inputs, its file's hash, a placeholder's record), and what + // a frame makes (the thumb, the pointer, whether one was drawn: a + // view's, never a step's). + .local = .{ "ops", "st", "gpa", "arena", "opened", "reloads", "jobs", "tokens", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "shadow", "used" }, }; /// Its kind's code here; null in a placeholder (`live` false: its kind /// not in the registry, its record kept for the day it comes) or a @@ -166,8 +166,10 @@ pub const Slot = struct { /// Its jobs' inputs, until the host takes them (Effect.job). jobs: [4]?Job = @splat(null), tokens: u32 = 0, - /// A placeholder's: the kind's record and its `where`, kept whole. + /// A placeholder's: the kind's record, kept whole. record: ?[]u8 = null, + /// Its `where` as its kind's last call left it (the call's outcome, on + /// the tape): the place a step reads (a jump, Recent) on every core. where_text: Buf(32) = .{}, /// What the kind said refusing its open (or a load), or `<path> is not here`. refused: Buf(160) = .{}, @@ -791,15 +793,6 @@ pub fn dumpCall(slot: *Slot, f: anytype, buf: []u8) u32 { return f(slot.st, buf.ptr, @intCast(buf.len)); } -/// `where`, as the authority's kind says it (on the tape): what a step -/// keeps of it (a jump, Recent) a replica keeps alike. -pub fn placeOf(slot: *Slot, buf: *[32]u8) []const u8 { - const w = tape.value(.addon, where, .{ slot, buf }); - // A Shadow's place is the authority's last (`where` says it after). - if (slot.ops == null) slot.where_text.set(w); - return w; -} - /// Where in it the pane is, as a text its `address` takes back. pub fn where(slot: *Slot, buf: *[32]u8) []const u8 { const ops = slot.ops orelse return slot.where_text.slice(); @@ -865,6 +858,9 @@ pub const Outcome = struct { rows: []const u8 = "", /// A tick's: the start of its tag (pa_tick.prefix). prefix: []const u8 = "", + /// Its `where` after the call (a key, a view, a job's answer may move + /// it); null for a refused call. + where: ?[]const u8 = null, /// The jobs it asked for (their tokens, 0 past the last): every core /// emits them, so a replica's effects are the authority's; and those /// it cancelled, every core drops. @@ -913,7 +909,11 @@ const Call = struct { current = prev; if (checked) overBudget(cl); if (cl.quiet) return .{}; - const o = tape.value(.addon, same, .{Outcome{ .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, .jobs = cl.jobs, .cancels = cl.cancels }}); + 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; + const o = tape.value(.addon, same, .{Outcome{ .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); if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = @intCast(cl.id), .serial = pane.serial, .token = token } }); for (o.cancels) |token| if (token != 0) { for (&cl.slot.jobs) |*j| if (j.*) |job| if (job.token == token) { diff --git a/src/replica.zig b/src/replica.zig index 8b0f8c8e..330c3204 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -4265,3 +4265,67 @@ test "a replica with no code for a kind draws its pane from the authority's fram try std.testing.expect(r.diverged == null); try std.testing.expectEqual(digestOf(a), r.digest()); } + +/// A kind whose place (`where`) is the rows its last view was told: a +/// session's step that tells it moves its place, never a key's. +const Placed = struct { + const pa = pardes.Kind.c; + fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque { + const n: *u32 = @ptrCast(@alignCast(pardes.Kind.api.alloc.?(4))); + n.* = 0; + return n; + } + fn paint(_: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void {} + fn view(st: ?*anyopaque, v: [*c]const pa.pa_view) callconv(.c) void { + const n: *u32 = @ptrCast(@alignCast(st.?)); + n.* = v.*.rows; + } + fn where(st: ?*anyopaque, buf: [*c]u8, len: u32) callconv(.c) u32 { + const n: *u32 = @ptrCast(@alignCast(st.?)); + return @intCast((std.fmt.bufPrint(buf[0..len], "1:0 {d}", .{n.*}) catch return 0).len); + } + const words = [_]pa.pa_word{std.mem.zeroInit(pa.pa_word, .{ .name = "Placed", .opens = 1, .doc = "a place" })}; + const ops = std.mem.zeroInit(pardes.Kind.Ops, .{ + .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "placed".* ++ @as([10]u8, @splat(0)), .version = 1, .exts = "", .words = &words, .nwords = 1 }), + .open = open, + .paint = paint, + .view = view, + .where = where, + }); +}; + +test "a kind's place moved in a step of another view's: a replica's key that reads it guesses the authority's" { + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + defer a.deinit(); + const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + defer r.deinit(); + var words: [64]pardes.Kind.LoadedWord = undefined; + const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } })); + // The replica's view opens the kind's pane, and an Esc goes back to + // the file (Last): view 0 has the file. + const own = try a.openView(1); + r.view = own.view; + r.confirm(own.unit); + for ([_]pardes.Event{ .{ .command = "Placed" }, .{ .key = .{ .cp = pardes.Key.escape } } }) |ev| { + r.confirm(try a.take(try r.input(ev))); + r.settle(); + } + // View 0 resized, and a step of the session's own tells the kind: its + // place moves in a step whose view has the file, which reads it not. + var buf: [256]u8 = undefined; + r.confirm(try a.take(try inputOf(&buf, 2, 1, .{ .resize = .{ .cols = 80, .rows = 20 } }))); + r.confirm(try a.local(.tick)); + // The replica's Esc back to the kind's pane: its jump reads the place. + const fast = r.stats.fast; + const missed = r.stats.mispredicted; + const msg = try gpa.dupe(u8, try r.input(.{ .key = .{ .cp = pardes.Key.escape } })); + defer gpa.free(msg); + try std.testing.expectEqual(@as(usize, 1), r.applied); + r.confirm(try a.take(msg)); + r.settle(); + try std.testing.expectEqual(missed, r.stats.mispredicted); + try std.testing.expectEqual(fast + 1, r.stats.fast); + try agrees(a, r); +} |
