summaryrefslogtreecommitdiff
path: root/anim/src/aligned.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/aligned.zig')
-rw-r--r--anim/src/aligned.zig154
1 files changed, 127 insertions, 27 deletions
diff --git a/anim/src/aligned.zig b/anim/src/aligned.zig
index a7c225d..ce2f5a0 100644
--- a/anim/src/aligned.zig
+++ b/anim/src/aligned.zig
@@ -19,15 +19,19 @@
//! first row of its run; a line with no code of its own in source order
//! after the line before it, faint, `no code of their own`.
//!
-//! `align` between them (6. Verbs): the addresses and instructions glide
-//! right into the instruction column (24 f, the bytes going), then every
+//! `align` between them (6. Verbs): the bytes go (8 f), the addresses and
+//! instructions glide right into the instruction column (24 f), then every
//! row glides to its height (36 f: the verb's 24 read too quick for rows
//! crossing a column), then the lines with no code fade in (12 f).
+//!
+//! The lines as the mocks set them, without their indentation; the pc's
+//! row says what it reads (its address and chain, mock 33's annotation).
const std = @import("std");
const sk = @import("sketch");
const anim = @import("anim");
const ui = @import("ui.zig");
const disasm = @import("disasm.zig");
+const rows = @import("rows.zig");
const Recording = @import("Recording.zig");
const theme = ui.theme;
const Rect = ui.Rect;
@@ -47,6 +51,9 @@ const col = struct {
const mnemonic = 360;
const seam_after = 48;
const instr = 156;
+ /// The pc's row's annotation, from its mnemonic: interleaved, columns (mocks 32, 36).
+ const note = 540;
+ const note_columns = 360;
};
/// The dump row's first byte (`bytes`: at 132 at least).
@@ -83,15 +90,25 @@ pub const Aligned = struct {
rows_in: anim.Value,
chrome: anim.Value,
form: anim.Value,
+ /// `stack` (6. Verbs, `align` backwards), frames: the heads' paper and
+ /// rules, the seam and the tag out (12 f), then each line glides to its
+ /// row of the source panel (36 f, `glide`) and each instruction to its
+ /// row of the disassembly, down its column first (24 f), then left into
+ /// the panel (24 f): an instruction never passes over a line. Those the
+ /// working frame's windows do not show go on past their edge, fading.
+ /// 60 f in all; the scene then brings the panels in under them and lets this go.
+ stack: anim.Value,
+ /// Where they stack to: the working frame's source and disassembly boxes.
+ to: struct { source: Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }, disasm: Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 } } = .{},
pub fn init(s: *anim.Frame, rec: *const Recording, moment: u64) Aligned {
- return .{ .rec = rec, .at = moment, .bytes = s.value(-1), .decode = s.value(-1), .rows_in = s.value(-1), .chrome = s.value(-1), .form = s.value(0) };
+ return .{ .rec = rec, .at = moment, .bytes = s.value(-1), .decode = s.value(-1), .rows_in = s.value(-1), .chrome = s.value(-1), .form = s.value(0), .stack = s.value(-1) };
}
fn sourceLine(a: *const Aligned, n: u32) []const u8 {
var it = std.mem.splitScalar(u8, a.rec.source, '\n');
var k: u32 = 1;
- while (it.next()) |l| : (k += 1) if (k == n) return std.mem.trimEnd(u8, l, " \r");
+ while (it.next()) |l| : (k += 1) if (k == n) return std.mem.trim(u8, l, " \t\r");
return "";
}
@@ -177,14 +194,32 @@ pub const Aligned = struct {
if (built.rows.len == 0) return;
const m = a.rec.moment(a.at);
const form = placed.value(a.form);
- const across = glide(form / 24);
- const down = glide((form - 24) / 36);
- const bare = clamp01((form - 60) / 12);
- const seam = col.text + built.longest + col.seam_after;
+ // The bytes first (interleaved alone has them), then the columns glide: never over them.
+ const bytes_go = clamp01(form / 8);
+ const across = glide((form - 8) / 24);
+ const down = glide((form - 32) / 36);
+ const bare = clamp01((form - 68) / 12);
+ // The seam 48 after the longest line, or after a second run's line and its note; the
+ // mnemonics after the longest instruction's bytes (mock 32's 360 holds five).
+ var seam = col.text + built.longest + col.seam_after;
+ var most: usize = 0;
+ for (built.rows) |r| {
+ if (r.kind == .head and r.again) seam = @max(seam, col.text + lineWidth(a, r.line) + again_gap + u.width(.sans, theme.size.sans.micro, again_note) + 24);
+ if (r.insn) |insn| most = @max(most, insn.len);
+ }
+ const mnemonic = @max(col.mnemonic, col.bytes + @as(f32, @floatFromInt(3 * most)) * adv + 12);
const rows_in = placed.value(a.rows_in);
- const chrome = clamp01(placed.value(a.chrome) / 12);
- const tag_in = clamp01((placed.value(a.chrome) - 12) / 12);
+ const st = placed.value(a.stack);
+ const kept = 1 - clamp01(st / 12);
+ const going = glide((st - 12) / 36);
+ const down_first = glide((st - 12) / 24);
+ const then_left = glide((st - 36) / 24);
+ const chrome = clamp01(placed.value(a.chrome) / 12) * kept;
+ const tag_in = clamp01((placed.value(a.chrome) - 12) / 12) * kept;
const v = u.moved(a.box.x, a.box.y);
+ // Nothing under the stage (y 888): rows `stack` takes past the disassembly's foot fade there, not over the caption.
+ v.clip(.{ .x = -a.box.x, .y = -a.box.y, .w = theme.canvas.width, .h = theme.canvas.stage.y + theme.canvas.stage.h });
+ defer v.unclip();
const body = tag + pad;
var counts = [2]f32{ 0, 0 };
for (built.rows) |r| counts = .{ @max(counts[0], r.at[0] + 1), @max(counts[1], r.at[1] + 1) };
@@ -200,22 +235,53 @@ pub const Aligned = struct {
}
if (chrome > 0) v.faded(chrome).frame(.{ .x = 0, .y = 0, .w = a.box.w, .h = h }, theme.color.rule, theme.stroke.rule);
// The seam, with the columns.
- if (down > 0) v.faded(down).fill(.{ .x = seam, .y = tag, .w = theme.stroke.rule, .h = h - tag }, theme.color.rule);
+ if (down > 0) v.faded(down * kept).fill(.{ .x = seam, .y = tag, .w = theme.stroke.rule, .h = h - tag }, theme.color.rule);
+ // Where `stack` takes them: the source's window and the disassembly's, as those panels have them.
+ const src_first: f32 = @floatFromInt(a.rec.shownFirst(@intCast(theme.layout.rowsIn(a.to.source.h)), a.rec.shown[a.at]));
+ const dis_room = theme.layout.rowsIn(a.to.disasm.h);
+ // The panels' columns right of the line numbers move by as much as the widest file's numbers need.
+ const widen = rows.numberRoom(a.rec.most_lines);
+ const dis_rows = if (st >= 0) disasm.listingAt(u, a.rec, a.at, a.rec.register(a.at, "rip"), dis_room, (dis_room -| 1) / 2).rows else &.{};
for (built.rows, 0..) |r, k| {
- const y = body + pitch * std.math.lerp(r.at[0], r.at[1], down);
+ var y = body + pitch * std.math.lerp(r.at[0], r.at[1], down);
const order: f32 = @floatFromInt(k);
// At a run: rows top down, 2 f apart, 8 f each; the pc's row is the decoded one.
// The pc's row is the decoded one, once it has travelled to its place (48).
var shows: f32 = if (k == built.pc) @as(f32, if (placed.value(a.decode) >= 48) 1 else 0) else clamp01((rows_in - 2 * order) / 8);
if (r.kind == .bare_line) shows = @min(shows, bare);
+ // `stack`: its row in the working frame's panel (box-relative), and whether that window shows it.
+ var to_x: f32 = 0;
+ var to_y: f32 = 0;
+ if (st >= 0) {
+ var inside = true;
+ if (r.kind == .insn) {
+ var n: ?usize = null;
+ for (dis_rows, 0..) |d, i| if (d.addr == r.insn.?.addr) {
+ n = i;
+ };
+ // Past the window: where it would be, going on from its last row.
+ const at_row: f32 = if (n) |i| @floatFromInt(i) else @as(f32, @floatFromInt(dis_rows.len)) + order - @as(f32, @floatFromInt(built.pc));
+ inside = n != null;
+ to_x = a.to.disasm.x - a.box.x;
+ to_y = a.to.disasm.y - a.box.y + body + pitch * at_row;
+ } else {
+ const at_row = @as(f32, @floatFromInt(r.line)) - src_first;
+ inside = !r.again and at_row >= 0 and at_row < @as(f32, @floatFromInt(theme.layout.rowsIn(a.to.source.h)));
+ to_x = a.to.source.x - a.box.x;
+ to_y = a.to.source.y - a.box.y + body + pitch * at_row;
+ }
+ if (!inside) shows *= 1 - (if (r.kind == .insn) then_left else going);
+ }
if (shows <= 0) continue;
const rv = v.faded(shows);
+ if (r.kind == .insn and st >= 0) y = std.math.lerp(y, to_y, down_first);
const base = theme.baseline(y, pitch, size);
switch (r.kind) {
.head, .bare_line => {
// Interleaved: a head across the panel; columns: the line in its cell, level with its run.
- const head_y = if (r.kind == .head) y else body + pitch * r.at[1];
+ var head_y = if (r.kind == .head) y else body + pitch * r.at[1];
+ if (st >= 0) head_y = std.math.lerp(head_y, to_y, going);
const hb = theme.baseline(head_y, pitch, size);
const paper_w = std.math.lerp(a.box.w - 4, seam - 2, down);
if (r.kind == .head and !r.again and chrome > 0) rv.faded(chrome).fill(.{ .x = 2, .y = head_y, .w = paper_w, .h = pitch }, theme.color.raised);
@@ -223,36 +289,47 @@ pub const Aligned = struct {
const faint = r.again or r.kind == .bare_line;
const number = rv.print("{d}", .{r.line});
const is_pc = !r.again and built.rows[built.pc].line == r.line and r.kind == .head;
- if (is_pc) rv.fill(.{ .x = col.place_end - @as(f32, @floatFromInt(number.len)) * adv - 4, .y = head_y + 1, .w = @as(f32, @floatFromInt(number.len)) * adv + 6, .h = pitch - 2 }, theme.mark(.current).solid);
- rv.text(.mono, size, col.place_end - @as(f32, @floatFromInt(number.len)) * adv, hb, number, if (is_pc) t.ink else t.faint);
- rv.text(.mono, size, col.text, hb, a.sourceLine(r.line), if (faint) t.faint else t.primary);
- if (r.again) rv.text(.sans, theme.size.sans.micro, std.math.lerp(col.mnemonic + 4, col.text + built.longest - 140, down), hb, "again: its second run", t.dim);
- if (r.kind == .bare_line and r.first) rv.text(.sans, theme.size.sans.micro, seam + col.instr, hb, "no code of their own", t.dim);
+ // `stack`: the number to the source's number column, the text to its text column at its indent.
+ const n_end = std.math.lerp(col.place_end, to_x + theme.metric.context.line_number_end + widen, going);
+ const t_x = std.math.lerp(col.text, to_x + theme.metric.context.line_text + widen + @as(f32, @floatFromInt(indentOf(a, r.line))) * adv, going);
+ if (is_pc) rv.fill(.{ .x = n_end - @as(f32, @floatFromInt(number.len)) * adv - 4, .y = head_y + 1, .w = @as(f32, @floatFromInt(number.len)) * adv + 6, .h = pitch - 2 }, theme.mark(.current).solid);
+ rv.text(.mono, size, n_end - @as(f32, @floatFromInt(number.len)) * adv, hb, number, if (is_pc) t.ink else t.faint);
+ rv.text(.mono, size, t_x, hb, a.sourceLine(r.line), if (faint) t.faint else t.primary);
+ if (r.again) rv.faded(kept).text(.sans, theme.size.sans.micro, std.math.lerp(mnemonic + 4, col.text + lineWidth(a, r.line) + again_gap, down), hb, again_note, t.dim);
+ if (r.kind == .bare_line and r.first) rv.faded(kept).text(.sans, theme.size.sans.micro, seam + col.instr, hb, "no code of their own", t.dim);
},
.insn => {
const insn = r.insn.?;
- const ix = std.math.lerp(0, seam, across);
+ // `stack`: the row's left edge to the disassembly's.
+ const ix = std.math.lerp(std.math.lerp(0, seam, across), to_x, then_left);
+ const right = std.math.lerp(a.box.w, to_x + a.to.disasm.w, then_left);
if (k == built.pc) {
const wash = rv.faded(clamp01((placed.value(a.decode) - 48) / 12));
- wash.current(.{ .x = ix + 2, .y = y, .w = a.box.w - ix - 4, .h = pitch }, theme.metric.plaque.pc, 0);
- sk.draw.polygon(f, &.{ wash.at.xf.apply(.{ ix + 20, y + pitch / 2 }), wash.at.xf.apply(.{ ix + 10, y + 6 }), wash.at.xf.apply(.{ ix + 10, y + pitch - 6 }) }, wash.at.pen(.{ .fill = ui.rgb(theme.mark(.current).on_solid) }));
+ wash.current(.{ .x = ix + 2, .y = y, .w = right - ix - 4, .h = pitch }, theme.metric.plaque.pc, 0);
+ sk.draw.polygon(f, &.{ .{ ix + 20, y + pitch / 2 }, .{ ix + 10, y + 6 }, .{ ix + 10, y + pitch - 6 } }, wash.at.pen(.{ .fill = ui.rgb(theme.mark(.current).on_solid) }));
}
const digits: f32 = @floatFromInt(ui.digits(insn.addr));
- _ = rv.address(ix + col.place_end - digits * adv, base, insn.addr, .{ .ink = ui.rgb(theme.color.region.code_) });
+ // (`stack`: ranged right in its column to the disassembly's address column, from 40.)
+ _ = rv.address(std.math.lerp(std.math.lerp(0, seam, across) + col.place_end - digits * adv, to_x + theme.metric.insn.address, then_left), base, insn.addr, .{ .ink = ui.rgb(theme.color.region.code_) });
// Its bytes, as the recording read them: interleaved only.
- if (across < 1) rv.faded(1 - across).text(.mono, size, col.bytes, base, hexBytes(rv, m, insn), t.dim);
- disasm.bareRow(rv.moved(std.math.lerp(col.mnemonic - theme.metric.insn.mnemonic, seam + col.instr + 24 - theme.metric.insn.mnemonic, across), 0), insn, y);
+ if (bytes_go < 1) rv.faded(1 - bytes_go).text(.mono, size, col.bytes, base, hexBytes(rv, m, insn), t.dim);
+ const mx = std.math.lerp(std.math.lerp(mnemonic, seam + col.instr + 24, across), to_x + theme.metric.insn.mnemonic + widen, then_left);
+ disasm.bareRow(rv.moved(mx - theme.metric.insn.mnemonic, 0), insn, y);
+ // The pc's row: what it reads, its address and the chain from it, once decoded.
+ if (k == built.pc) if (a.rec.insn_touches[a.at][0]) |touch| {
+ _ = rows.chain(rv.faded(clamp01((placed.value(a.decode) - 48) / 12) * kept), mx + std.math.lerp(col.note, col.note_columns, across), y, m, touch.addr, a.box.w - 24, .{});
+ };
},
}
}
- a.drawBytesRow(v, m, placed, built);
+ a.drawBytesRow(v, m, placed, built, mnemonic);
}
/// III1 and the decode (III2): the code's sixteen bytes as a dump row,
/// in code's ink 2 f apart; the pc's instruction's bytes framed; then
/// they gather, its text fades in beside them, and the row travels to
/// its place in the panel.
- fn drawBytesRow(a: *const Aligned, v: ui.Ui, m: Recording.Moment, placed: anim.Placed, built: anytype) void {
+ fn drawBytesRow(a: *const Aligned, v: ui.Ui, m: Recording.Moment, placed: anim.Placed, built: anytype, mnemonic: f32) void {
const clock = placed.value(a.bytes);
if (clock < 0) return;
const d = placed.value(a.decode);
@@ -300,10 +377,33 @@ pub const Aligned = struct {
if (framed > 0) rv.read(.{ .x = bx(first), .y = y, .w = bx(first + insn.len - 1) - bx(first) + 2 * adv, .h = pitch }, framed);
// Its text beside the bytes, at the panel's columns from them (12 f).
const text_in = clamp01((d - 12) / 12);
- if (text_in > 0) disasm.bareRow(rv.faded(text_in).moved(target_x - col.bytes + col.mnemonic - theme.metric.insn.mnemonic, 0), insn, y);
+ if (text_in > 0) disasm.bareRow(rv.faded(text_in).moved(target_x - col.bytes + mnemonic - theme.metric.insn.mnemonic, 0), insn, y);
}
};
+const again_note = "again: its second run";
+const again_gap = 36;
+
+/// How far line `n` is indented in the file (its leading spaces; a tab as four).
+fn indentOf(a: *const Aligned, n: u32) usize {
+ var it = std.mem.splitScalar(u8, a.rec.source, '\n');
+ var k: u32 = 1;
+ while (it.next()) |l| : (k += 1) if (k == n) {
+ var w: usize = 0;
+ for (l) |ch| switch (ch) {
+ ' ' => w += 1,
+ '\t' => w += 4,
+ else => break,
+ };
+ return w;
+ };
+ return 0;
+}
+
+fn lineWidth(a: *const Aligned, n: u32) f32 {
+ return @as(f32, @floatFromInt(a.sourceLine(n).len)) * adv;
+}
+
fn hexBytes(u: ui.Ui, m: Recording.Moment, insn: disasm.Insn) []const u8 {
var bytes: [16]u8 = undefined;
var known: [16]bool = undefined;