//! A program that needs the kernel four times: open, read, close, write. //! The debugger's context, and the kernel's side of each call as the lens. //! //! How it moves (design/motion.md): no effect before its cause. Each call //! has its own caption, up a second before the line fires; the registers //! that carry it are framed one at a time; the arrow goes down through //! the line, and only then does the kernel's side take the call: its //! name, its rows, its card. The bytes are copied two frames apart; the //! arrow comes back; `rax` is struck. A call is as long as what it does. const anim = @import("anim"); const canim = @import("canim"); const recordings = @import("recordings"); pub const background = canim.background; pub const scene = anim.Live(frame, struct {}); /// What the narrator says before each of main's calls, in order. const lines = [_][]const u8{ "`open`: a name goes down, and a small number comes back.\nThat number is the file from now on.", "`read`: the kernel copies the file's bytes into `buf`,\nand says how many.", "`close`: the number is handed back.", "`write`: the same bytes go the other way,\nfrom `buf` to file number 1, the output.", }; fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.hello); // From main's first line to its last: its first lines walked under the // first caption, then a call a phrase. var at = canim.cursor(s, rec, rec.call("main", 0).enter); at.journey(.line, rec.lineMoment(10, at.first)); const split = canim.layout.split.subject; at.levels = .{ .source_rows = 10 }; const ctx = canim.context(s, at, .{ .split = split, .syscalls = true }); // The lens: the kernel's side of each call. const kernel = canim.crossing(s, .{ .cursor = at, .stage = ctx.stage, .focus = true }); var says: canim.Narrator = .{}; const t = canim.theme.time; const joins = ctx.ties(s); canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, kernel, joins }); says.line(s, "A program cannot open a file or reach the screen itself.\nIt asks the kernel, and waits."); at.walk(s, .line, rec.lineMoment(6, at.first)); // One call a phrase: its caption while nothing moves, then the crossing. for (lines) |line| { says.line(s, line); canim.syscalls.step(at, s, .line); s.wait(t.phrase_rest); } says.close(s); }