summaryrefslogtreecommitdiff
path: root/anim/src/context.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/context.zig')
-rw-r--r--anim/src/context.zig239
1 files changed, 209 insertions, 30 deletions
diff --git a/anim/src/context.zig b/anim/src/context.zig
index d4bc94d..16278e3 100644
--- a/anim/src/context.zig
+++ b/anim/src/context.zig
@@ -348,6 +348,42 @@ pub fn frames(rec: *const Recording, i: u64, out: []Frame) []Frame {
return out[0..found.len];
}
+/// The register the newest frame's code addresses its words by
+/// (design/README.md, `slot`): its call frame information's CFA register,
+/// rbp in a body that keeps a frame pointer; rsp at its entry, in its
+/// prologue before `mov rbp, rsp`, after its `pop rbp` or `leave`, in a
+/// function that keeps none, and where the recording has no such rows.
+pub const Base = struct {
+ rbp: bool = false,
+
+ pub fn name(b: Base) []const u8 {
+ return if (b.rbp) "rbp" else "rsp";
+ }
+
+ pub fn value(b: Base, regs: zt.Regs) u64 {
+ return if (b.rbp) regs.rbp else regs.rsp;
+ }
+};
+
+pub fn frameBase(rec: *const Recording, i: u64, regs: zt.Regs) Base {
+ const func = zt.telescope.function(rec.moment(i), regs.rip) orelse return .{};
+ const size = @sizeOf(zt.Symbols.Row);
+ var row: zt.Symbols.Row = .{};
+ var o: usize = 0;
+ while (o + size <= func.rows.len) : (o += size) {
+ const r = std.mem.bytesToValue(zt.Symbols.Row, func.rows[o..][0..size]);
+ if (r.offset > regs.rip -% func.start) break;
+ row = r;
+ }
+ // DWARF's 6 is rbp; and rbp must be in the frame (under its return address).
+ return .{ .rbp = row.cfa_reg == 6 and regs.rbp >= regs.rsp };
+}
+
+/// `d` bytes from base `name` (`rbp-18`, `rbp+8`, `rbp`), as the stack's tag writes a range.
+fn fromBase(u: ui.Ui, name: []const u8, d: i64) []const u8 {
+ return if (d == 0) name else if (d > 0) u.print("{s}+{x}", .{ name, @as(u64, @intCast(d)) }) else u.print("{s}-{x}", .{ name, @as(u64, @intCast(-d)) });
+}
+
/// A frame's span on the stack: its function's name, and as a call its
/// argument where it takes one (`fib(4)`): the digits on its node.
fn spanName(u: ui.Ui, rec: *const Recording, open: []const Recording.Call, i: usize, pc: u64) []const u8 {
@@ -439,6 +475,8 @@ pub const Stack = struct {
const hold = placed.value(k.stage.hold);
const held = hold >= 0;
const held_at: u64 = if (held) rec.register(@intFromFloat(hold), "rsp") -% 8 * @as(u64, @intFromFloat(placed.value(k.stage.hold_free))) else 0;
+ // `tied`: two `free` words over rsp, the window's headroom; offsets from the frame's base; rsp's and rbp's moves as pins travelling.
+ const tied = now.annotation == .tied;
var window = if (held) [2]u64{ held_at, held_at } else if (k.above != 0) [2]u64{ is.rsp -% @as(u64, @bitCast(@as(i64, 8 * k.above))), was.rsp -% @as(u64, @bitCast(@as(i64, 8 * k.above))) } else [2]u64{ windowAt(now, is, slots, 0), windowAt(now, was, slots, 1) };
// A window that goes farther than its own height (a continue to a
// stop deeper or shallower than a call is) does not scroll: the old
@@ -459,6 +497,11 @@ pub const Stack = struct {
// Going to the hold and coming from it, the rows scroll: the
// remaining way, in rows, from where the window would be.
const natural = windowAt(now, is, slots, 0);
+ // Under `tied`, the word the step touches, and the window over it before the touch goes there.
+ const touch: ?cursors.Touched = if (tied and !now.resting()) cursors.stackTouch(rec, now.stops[1], now.stops[0]) else null;
+ const touch_window = if (touch) |tt| if (!held and k.above == 0 and !jumped and (tt.addr < window[1] or tt.addr >= window[1] + 8 * @as(u64, slots))) windowOver(was, slots, tt.addr) else window[1] else window[1];
+ // The frame's base, before the step and after it (`whole`: rsp).
+ const bases = [2]Base{ if (tied) frameBase(rec, now.stops[1], was) else .{}, if (tied) frameBase(rec, now.stops[0], is) else .{} };
const hold_scroll: f32 = if (held) @as(f32, @floatFromInt(@as(i64, @bitCast(held_at -% natural)))) / 8 * (1 - cursors.glide(placed.value(k.stage.hold_in))) else 0;
// From rsp, or the range shown when the window is elsewhere: in
// bytes from rsp, as the catalogue writes it (`rsp+20 to rsp+48`).
@@ -471,10 +514,18 @@ pub const Stack = struct {
const words = if (slots < numbers.len) numbers[slots] else u.print("{d}", .{slots});
// The first word shown and the last.
// The range before memory lands and after: one that changes crossfades (12 f), as a role does.
- const recast = if (now.resting()) 1 else std.math.clamp(since_memory / time.quick, 0, 1);
+ // Under `tied` a walked step's labels change as its window follows, or its last pin lands (`Now.restacked`).
+ const recast = if (now.resting()) 1 else if (tied and now.walking()) std.math.clamp((now.time - now.restacked()) / time.quick, 0, 1) else std.math.clamp(since_memory / time.quick, 0, 1);
const ranges = [2]i64{ @bitCast(ways[1] -% was.rsp), @bitCast(ways[0] -% is.rsp) };
var notes: [2][]const u8 = undefined;
- for (ranges, &notes) |r_, *note| {
+ for (ranges, &notes, [2]zt.Regs{ was, is }, bases, 0..) |r_, *note, regs, base, side| {
+ if (tied) {
+ // From the base: `fourteen words` where the window is at its headroom, else the range.
+ const from: i64 = @bitCast(ways[1 - side] -% base.value(regs));
+ const range = if (ways[1 - side] == regs.rsp -% 16 and k.above == 0) u.print("{s} words", .{words}) else u.print("{s} to {s}", .{ fromBase(u, base.name(), from), fromBase(u, base.name(), from + 8 * (@as(i64, @intCast(slots)) - 1)) });
+ note.* = u.print("{s} \u{00b7} offsets from {s} \u{00b7} the frames they belong to", .{ range, base.name() });
+ continue;
+ }
const range = if (r_ == 0) u.print("{s} words from rsp", .{words}) else u.print("{s} to {s}", .{ offset(u, r_), offset(u, r_ + 8 * (@as(i64, @intCast(slots)) - 1)) });
note.* = u.print("{s} \u{00b7} the frames they belong to", .{range});
}
@@ -484,9 +535,38 @@ pub const Stack = struct {
u.faded(1 - recast).tagNote(box.w, notes[0]);
u.faded(recast).tagNote(box.w, notes[1]);
}
- const p = cursors.glide(now.moving(.memory, 0, time.move));
+ var p = cursors.glide(now.moving(.memory, 0, time.move));
const moved = @as(f32, @floatFromInt(@as(i64, @bitCast(window[0] -% window[1])))) / 8;
- const slide: f32 = (if (jumped) 0 else moved * (1 - p)) + hold_scroll;
+ var slide: f32 = (if (jumped) 0 else moved * (1 - p)) + hold_scroll;
+ // Under `tied`, walked (design/README.md, `stack`): the rows hold while the pin travels;
+ // a word the step touches outside the window is scrolled to before the touch goes there;
+ // where the climb is longer than the room over the pin, the rows slide under it (the pin on
+ // the top row); once it has landed the window follows (`Plan.follow`).
+ const pin_sp = now.pinGone(0);
+ if (tied and !jumped and !held and k.above == 0 and now.walking() and (now.plan.follow >= 0 or now.plan.touch >= 0 or pin_sp != null)) {
+ const rows_at = struct {
+ fn at(addr: u64, base: u64) f32 {
+ return @as(f32, @floatFromInt(@as(i64, @bitCast(addr -% base)))) / 8;
+ }
+ /// The window's top (rows from `window[0]`) with the pin at `pin`: never past it.
+ fn keep(d: f32, pin: f32, n: usize) f32 {
+ return std.math.clamp(d, pin - @as(f32, @floatFromInt(n - 1)), pin);
+ }
+ };
+ var d = rows_at.at(window[1], window[0]);
+ if (touch_window != window[1]) d = std.math.lerp(d, rows_at.at(touch_window, window[0]), cursors.glide(std.math.clamp(now.time / @max(now.plan.touch, time.fire), 0, 1)));
+ const pins_at = [2]f32{ rows_at.at(was.rsp, window[0]), rows_at.at(is.rsp, window[0]) };
+ const landed_d = rows_at.keep(rows_at.at(touch_window, window[0]), pins_at[1], slots);
+ if (pin_sp) |g| d = rows_at.keep(d, std.math.lerp(pins_at[0], pins_at[1], g), slots);
+ if (now.plan.follow >= 0) {
+ const span = @min(time.tied.follow + 2.0 / 60.0 * @max(@abs(landed_d) - 1, 0), time.tied.follow_most);
+ const q = cursors.glide(std.math.clamp((now.time - now.plan.follow) / span, 0, 1));
+ if (now.time >= now.plan.follow) d = std.math.lerp(landed_d, 0, q);
+ } else d = std.math.lerp(d, 0, p);
+ slide = -d;
+ // The strip's window goes as the pane's does.
+ p = if (moved != 0) std.math.clamp(1 - slide / moved, 0, 1) else 1;
+ }
const top = body.y + m.pad;
clipBody(u, box);
defer u.unclip();
@@ -532,11 +612,13 @@ pub const Stack = struct {
const calls_is = rec.stack(u.f.scratch, now.stops[0]);
var spans: [16]Span = undefined;
var n_spans: usize = 0;
+ // Under `tied` the spans ride rsp's pin: the newest stretches or shrinks with it.
+ const p_span = pin_sp orelse p;
for (chain, 0..) |frame, i| {
const old_frame = if (i < old_chain.len) old_chain[i] else frame;
- const first = std.math.lerp(rows_of(old_frame.lo, window[0]), rows_of(frame.lo, window[0]), p) + slide;
+ const first = std.math.lerp(rows_of(old_frame.lo, window[0]), rows_of(frame.lo, window[0]), p_span) + slide;
if (first >= @as(f32, @floatFromInt(slots))) break;
- const last = if (frame.hi) |hi| std.math.lerp(if (old_frame.hi) |oh| rows_of(oh, window[0]) else rows_of(hi, window[0]), rows_of(hi, window[0]), p) + slide else std.math.inf(f32);
+ const last = if (frame.hi) |hi| std.math.lerp(if (old_frame.hi) |oh| rows_of(oh, window[0]) else rows_of(hi, window[0]), rows_of(hi, window[0]), p_span) + slide else std.math.inf(f32);
if (last < 0) continue;
const open = last >= @as(f32, @floatFromInt(slots));
const y1 = top + (@min(last, @as(f32, @floatFromInt(slots)) - 1) + 1) * m.row;
@@ -558,6 +640,8 @@ pub const Stack = struct {
const goes = struct {
fn of(n: cursors.Now, a: zt.Regs, b: zt.Regs, name: []const u8) f32 {
if (n.resting()) return 1;
+ // `tied`: as its plan travels it (`Now.pinGone`).
+ if (n.pinGone(if (std.mem.eql(u8, name, "rsp")) 0 else 1)) |g| return g;
const pin = time.pin;
const rows_far: f32 = @floatFromInt(@abs(@as(i64, @bitCast((b.named(name) orelse 0) -% (a.named(name) orelse 0)))) / 8);
const takes = @min(pin.row + pin.step_per_row * @max(rows_far - 1, 0), pin.row_max);
@@ -592,19 +676,42 @@ pub const Stack = struct {
// Who points here: a pin in the lane, landing with its link.
const names = pins(u, now, is, was, addr, travel);
var marks: rows.Marks = .{ .lead = lead, .first = now.writtenWatched(addr, 8, .memory, 0, watched_from, watched_to) };
- if (watched_from == 0 and watched_to > 0 and now.wasRead(addr, 8) and now.writeAge(addr, 8) != 0) {
+ // Under `tied` the word a `pop`, a `ret` or a `leave` reads is read too (the recordings say no read there).
+ const touched_here = if (touch) |tt| tt.addr & ~@as(u64, 7) == addr else false;
+ if (watched_from == 0 and watched_to > 0 and (now.wasRead(addr, 8) or (touched_here and !touch.?.write)) and now.writeAge(addr, 8) != 0) {
marks.read = 0;
marks.read_shows = now.reading(.memory, 0);
}
- const below_rsp: i64 = @bitCast(addr -% if (held) rsp_shown else is.rsp);
+ // A word stored with the value it held (a `push rbp` over the old saved rbp): armed, and nothing struck.
+ if (touched_here and touch.?.write and now.walking() and now.writeAge(addr, 8) != 0) {
+ const s_at = now.plan.at[1];
+ marks.first.arm = std.math.clamp((now.time - (s_at - time.strike.arm)) / time.stagger, 0, 1) * (1 - std.math.clamp((now.time - s_at) / time.quick, 0, 1));
+ }
+ const below_rsp: i64 = if (tied) @bitCast(addr -% bases[1].value(is)) else @bitCast(addr -% if (held) rsp_shown else is.rsp);
map.row(.stack, addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row });
// `free`: above rsp, not yet reached: its address at 60%, its word faint.
// A free word rsp reaches (a push, `sub rsp`) becomes a slot as memory strikes (12 f), never in a frame.
- const free_was = held and addr < was.rsp;
- const free_is = held and addr < is.rsp;
- const slot_shows: f32 = if (free_was == free_is or now.resting()) @as(f32, if (free_is) 0 else 1) else if (free_is) 1 - recast else recast;
- if (slot_shows < 1) rows.free(v.faded(1 - slot_shows), y, memory, addr, below_rsp, lead);
- if (slot_shows <= 0) continue;
+ // Under `tied` every word over rsp but a leaf's locals there (the red zone, its frame's).
+ const k_free = (addr -% roles_from) / 8;
+ // (A word a `push` is about to write has its role already, at the push's own stop: still free.)
+ const free_was = (held or tied) and addr < was.rsp and !(tied and k_free < roles[0].len and roles[0][k_free].frame != null and roles[0][k_free].role == .local);
+ const free_is = (held or tied) and addr < is.rsp and !(tied and k_free < roles[1].len and roles[1][k_free].frame != null and roles[1][k_free].role == .local);
+ // `tied`: gained or released as rsp's pin reaches it (12 f).
+ // A word the step writes over rsp (a push's, a call's, a store the line makes past the old rsp) is the frame's as its arm comes
+ // (the touch's word as the touch lands): armed, struck, and then the pin climbs over it.
+ const passed = if (touched_here and touch.?.write and now.walking() and now.plan.touch >= 0) now.time - now.plan.touch - time.tied.touch else if (tied and now.walking() and free_was and !free_is and now.writeAge(addr, 8) == 0) now.time - (now.plan.at[1] + now.writeDelay(addr, 8) - time.strike.arm) else if (pin_sp != null and !held) pinPassed(now, rows_of(was.rsp, window[0]), rows_of(is.rsp, window[0]), @as(f32, @floatFromInt(n))) else null;
+ const turned = if (passed) |ago| std.math.clamp(ago / time.quick, 0, 1) else recast;
+ const slot_shows: f32 = if (free_was == free_is or now.resting()) @as(f32, if (free_is) 0 else 1) else if (free_is) 1 - turned else turned;
+ const offset_was: ?i64 = if (tied) @as(i64, @bitCast(addr -% bases[0].value(was))) else null;
+ if (slot_shows < 1) rows.free(v.faded(1 - slot_shows), y, memory, addr, below_rsp, lead, .{ .name = "", .going = recast, .from_rsp = offset_was });
+ if (slot_shows <= 0) {
+ // `tied`: a free word is a place too (the touch of a push or a call goes to it).
+ if (tied and y >= top - 1 and y + m.row <= box.h - m.pad + 1) {
+ ties.anchor(u, .{ .word = addr }, .{ .x = theme.metric.slot.address, .y = y, .w = 120, .h = m.row });
+ ties.anchor(u, .{ .slot_pin = addr }, .{ .x = theme.metric.slot.lane, .y = y, .w = theme.metric.slot.lane_end - theme.metric.slot.lane, .h = m.row });
+ }
+ continue;
+ }
const vs = v.faded(slot_shows);
// A frame's name beside this row: the chain ends a character before it.
var room_w = map.content(box.w);
@@ -623,12 +730,11 @@ pub const Stack = struct {
const k_role = (addr -% roles_from) / 8;
var role_at: [2]@TypeOf(roleName(u, .none, 0)) = undefined;
for (&role_at, roles, [2]Recording.Moment{ now.before(), now.moment() }) |*r, of, mem| {
- const what: zt.telescope.Role = if (k_role < of.len) of[k_role].role else .none;
- r.* = roleName(u, what, (Recording.word(mem, addr, 8) catch null) orelse 1);
+ r.* = slotName(u, if (k_role < of.len) of[k_role] else .{}, (Recording.word(mem, addr, 8) catch null) orelse 1);
}
const what: zt.telescope.Role = if (k_role < roles[1].len) roles[1][k_role].role else .none;
const role = role_at[1];
- const role_was: rows.Role = .{ .name = role_at[0].name, .local = role_at[0].local, .going = recast, .from_rsp = @bitCast(addr -% was.rsp) };
+ const role_was: rows.Role = .{ .name = role_at[0].name, .local = role_at[0].local, .going = if (passed != null) turned else recast, .from_rsp = if (tied) @bitCast(addr -% bases[0].value(was)) else @bitCast(addr -% was.rsp), .offset_going = recast };
// At a run a word changes in place under an 8 f crossfade, as a register does.
const ran = runFade(now, .memory);
const word_was = Recording.word(now.before(), addr, 8) catch null;
@@ -669,18 +775,35 @@ pub const Stack = struct {
if (!ui.mapping) ties.stack_window = .{ .first = window[0], .slots = slots, .x = lane_at[0], .top = lane_at[1], .row = row_px };
// The travelling tags: both of them at one word share a pin.
var places: [2]f32 = undefined;
- for (travel, places[0..travel.len]) |name, *place| {
- const at_old = @as(f32, @floatFromInt(@as(i64, @bitCast((was.named(name) orelse 0) -% window[0])))) / 8 + slide;
+ var olds: [2]f32 = undefined;
+ const slots_f: f32 = @floatFromInt(slots);
+ for (travel, places[0..travel.len], olds[0..travel.len]) |name, *place, *old| {
+ var at_old = @as(f32, @floatFromInt(@as(i64, @bitCast((was.named(name) orelse 0) -% window[0])))) / 8 + slide;
const at_new = @as(f32, @floatFromInt(@as(i64, @bitCast((is.named(name) orelse 0) -% window[0])))) / 8 + slide;
+ // `tied`: a pin from outside the window comes in at its edge (rbp in from the window's foot).
+ if (tied) at_old = std.math.clamp(at_old, -1, slots_f);
+ old.* = at_old;
place.* = std.math.lerp(at_old, at_new, goes(now, was, is, name));
}
- for (travel, places[0..travel.len], 0..) |name, place, i| {
+ // `tied`: rsp's move on its pin as it travels, counting a row at a time, held to the advance and crossfading to the bare name (12 f).
+ const amount_shows: f32 = if (tied and now.walking() and pin_sp != null and now.time >= now.plan.pins[0]) 1 - std.math.clamp((now.time - now.plan.advance) / time.quick, 0, 1) else 0;
+ for (travel, places[0..travel.len], olds[0..travel.len], 0..) |name, place, old, i| {
if (i == 1 and @abs(places[0] - place) < 0.05) continue;
- if (place < -0.5 or place > @as(f32, @floatFromInt(slots)) - 0.5) continue;
+ if (place < (if (tied) @as(f32, -1) else -0.5) or place > (if (tied) slots_f else slots_f - 0.5)) continue;
const both = i == 0 and travel.len == 2 and @abs(places[1] - place) < 0.05;
// Alone, from its place among the names it leaves to its place among those it joins.
const x = if (lone != null) std.math.lerp(pinPlace(u, pins(u, now, is, was, was.named(name) orelse 0, travel).names, name), pinPlace(u, pins(u, now, is, was, is.named(name) orelse 0, travel).names, name), goes(now, was, is, name)) else theme.metric.slot.lane;
- u.pinRow(x, top + place * m.row, if (both) &.{ "rsp", "rbp" } else &.{name}, theme.color.region.stack);
+ const names_: []const []const u8 = if (both) &.{ "rsp", "rbp" } else &.{name};
+ if (amount_shows > 0 and std.mem.eql(u8, name, "rsp")) {
+ const crossed = @abs(place - old);
+ const total_rows = cursors.wordsApart(rec, now.stops[1], now.stops[0], "rsp");
+ // Rows crossed, counted on its whole way (its start may be off the window).
+ const count = std.math.clamp(@ceil(goes(now, was, is, "rsp") * total_rows - 0.01), 1, total_rows);
+ const bytes: u64 = @intFromFloat(count * 8);
+ pinAmount(u, x, top + place * m.row, names_, if (is.rsp < was.rsp) u.print("-{x}", .{bytes}) else u.print("+{x}", .{bytes}), amount_shows);
+ // The rows it crossed, a 3-unit vermilion bracket in the outer arc lane.
+ if (crossed > 0.05) u.faded(amount_shows).bracket(theme.metric.arc.lanes[0], top + @min(place, old) * m.row + 2, top + @max(place, old) * m.row - 2, theme.mark(.write).solid, theme.metric.bracket.tie, 1, false);
+ } else u.pinRow(x, top + place * m.row, names_, theme.color.region.stack);
}
for (spans[0..n_spans]) |sp| if (sp.was) |was_name| {
rows.span(v.faded(1 - renamed), map.content(box.w), sp.y0, sp.y1, was_name, sp.newest, sp.open);
@@ -694,10 +817,11 @@ pub const Stack = struct {
/// local's name (primary, `+8` a word into it); `argc`, `argv[0]`,
/// `argv end`, `envp end`, `auxv` (dim). A return address needs none:
/// its chain is code, named. `word`: what the slot holds (0 ends argv and envp).
- fn roleName(u: ui.Ui, role: zt.telescope.Role, word: u64) struct { name: []const u8, local: bool = false } {
+ pub fn roleName(u: ui.Ui, role: zt.telescope.Role, word: u64) struct { name: []const u8, local: bool = false } {
return switch (role) {
.none, .return_address => .{ .name = "" },
- .saved => |r| .{ .name = u.print("saved {s}", .{r}) },
+ // The stack protector's copy is the `canary`, not a register saved.
+ .saved => |r| .{ .name = if (std.mem.eql(u8, r, "canary")) "canary" else u.print("saved {s}", .{r}) },
.local => |l| .{ .name = if (l.offset > 0) u.print("{s}+{x}", .{ l.name, @as(u32, @intCast(l.offset)) }) else if (l.offset == -4 and l.size == 4) u.print("{s}, high half", .{l.name}) else if (l.offset < 0) u.print("{s}, from byte {d}", .{ l.name, -l.offset }) else l.name, .local = true },
.argc => .{ .name = "argc" },
.argv => |i| .{ .name = if (word == 0) "argv end" else u.print("argv[{d}]", .{i}) },
@@ -706,6 +830,31 @@ pub const Stack = struct {
};
}
+ /// A slot's role (`roleName`), with the other locals that share its word: `i, n`.
+ pub fn slotName(u: ui.Ui, slot: zt.telescope.Slot, word: u64) @TypeOf(roleName(u, .none, 0)) {
+ if (slot.role != .local or slot.also[0] == null) return roleName(u, slot.role, word);
+ var out: []const u8 = slot.role.local.name;
+ for (slot.also) |a| if (a) |l| {
+ out = u.print("{s}, {s}", .{ out, l.name });
+ };
+ return .{ .name = out, .local = true };
+ }
+
+ /// A row pin of `names` with rsp's move on it (`amount`, `-18`, bold in
+ /// write's vermilion), `shows` of the amount; its head after it.
+ fn pinAmount(u: ui.Ui, x: f32, y: f32, names: []const []const u8, amount: []const u8, shows: f32) void {
+ const size = theme.size.mono.context;
+ const p = theme.metric.pin;
+ const shown = if (names.len == 2) u.print("{s} {s}", .{ names[0], names[1] }) else names[0];
+ const base = theme.baseline(y, m.row, size);
+ u.text(.mono_bold, size, x, base, shown, t.primary);
+ const end = x + u.width(.mono, size, shown);
+ u.faded(shows).text(.mono_bold, size, end + ui.advance(size), base, amount, theme.mark(.write).solid);
+ const hx = end + shows * (ui.advance(size) + u.width(.mono, size, amount)) + p.row_gap;
+ const mid = y + m.row / 2;
+ sk.draw.polygon(u.f, &.{ .{ hx + p.row_head[0], mid }, .{ hx, mid - p.row_head[1] / 2 }, .{ hx, mid + p.row_head[1] / 2 } }, u.at.pen(.{ .fill = ui.rgb(theme.color.region.stack) }));
+ }
+
/// Where `name` goes in a row pin of `others` and it, in the registers' order.
fn pinPlace(u: ui.Ui, others: []const []const u8, name: []const u8) f32 {
const size = theme.size.mono.context;
@@ -736,6 +885,25 @@ pub const Stack = struct {
sk.draw.polygon(u.f, &.{ .{ hx + p.row_head[0], mid }, .{ hx, mid - p.row_head[1] / 2 }, .{ hx, mid + p.row_head[1] / 2 } }, u.at.pen(.{ .fill = ui.rgb(theme.color.region.stack) }));
}
+ /// Seconds since rsp's pin, going from row `from` to row `to` of the
+ /// window, passed the middle of row `n` (negative before it): when a word
+ /// it reaches is gained, or one it leaves released. Null where it does not cross it.
+ fn pinPassed(now: cursors.Now, from: f32, to: f32, n: f32) ?f32 {
+ if (from == to) return null;
+ const q = (n + 0.5 - from) / (to - from);
+ if (q < 0 or q > 1) return null;
+ const run = now.plan.gait == .run;
+ const start: f32 = if (run) 0 else now.plan.pins[0];
+ // When its eased way reaches q.
+ var lo: f32 = 0;
+ var hi: f32 = 1;
+ for (0..16) |_| {
+ const mid = (lo + hi) / 2;
+ if ((if (run) cursors.standard(mid) else cursors.glide(mid)) < q) lo = mid else hi = mid;
+ }
+ return now.time - (start + lo * cursors.pinTime(@abs(to - from), run));
+ }
+
/// Whether a window of `slots` going from word `a` to word `b` goes
/// farther than its own height: it fades, and does not scroll.
fn far(a: u64, b: u64, slots: usize) bool {
@@ -761,9 +929,11 @@ pub const Stack = struct {
/// read there is in the window's middle.
fn windowAt(now: cursors.Now, regs: zt.Regs, slots: usize, skip: usize) u64 {
const frame_end = regs.rbp +% 16;
- if (frame_end <= regs.rsp or frame_end - regs.rsp > 8 * 64) return regs.rsp;
- const words = (frame_end - regs.rsp) / 8;
- if (words <= slots) return regs.rsp;
+ // `tied`: from its headroom, two `free` words over rsp (the room a push, a call or a `sub rsp` takes).
+ const top = if (now.annotation == .tied) regs.rsp -% 16 else regs.rsp;
+ if (frame_end <= regs.rsp or frame_end - regs.rsp > 8 * 64) return top;
+ const words = (frame_end - top) / 8;
+ if (words <= slots) return top;
for (skip..skip + 3) |age| {
if (age + 1 >= now.stops.len) break;
for ([_][]const Recording.Span{ now.rec.written(now.stops[age + 1], now.stops[age]), now.rec.read(now.stops[age + 1], now.stops[age]) }) |spans| {
@@ -771,14 +941,23 @@ pub const Stack = struct {
while (k > 0) {
k -= 1;
const a = spans[k].addr;
- if (a < regs.rsp or a >= frame_end) continue;
- const word = (a - regs.rsp) / 8;
+ if (a < top or a >= frame_end) continue;
+ const word = (a - top) / 8;
const first = @min(word -| (slots - 1) / 2, words - slots);
- return regs.rsp + 8 * first;
+ return top + 8 * first;
}
}
}
- return regs.rsp;
+ return top;
+ }
+
+ /// Under `tied`, a window of `slots` from the headroom over `regs`'s rsp
+ /// that has word `addr` in its middle: where it scrolls before a touch.
+ fn windowOver(regs: zt.Regs, slots: usize, addr: u64) u64 {
+ const top = regs.rsp -% 16;
+ if (addr < top) return addr & ~@as(u64, 7);
+ const words = (@max(regs.rbp +% 16, addr + 8) - top) / 8;
+ return top + 8 * @min(((addr - top) / 8) -| (slots - 1) / 2, words -| slots);
}
const Pins = struct { names: []const []const u8, shows: f32 };