diff options
Diffstat (limited to 'anim/scenes/sqlite.zig')
| -rw-r--r-- | anim/scenes/sqlite.zig | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/anim/scenes/sqlite.zig b/anim/scenes/sqlite.zig index db0e6d9..e19a7be 100644 --- a/anim/scenes/sqlite.zig +++ b/anim/scenes/sqlite.zig @@ -56,20 +56,22 @@ fn leaf(arena: std.mem.Allocator, page: []const u8) []const Field { std.debug.assert(page[0] == 0x0d); const cells = std.mem.readInt(u16, page[3..5], .big); var out: std.ArrayList(Field) = .empty; + // Read as the caption names them: the page's type, then the rest of its + // header (3 cells), then the cell pointers, then each cell. out.appendSlice(arena, &.{ .{ .at = 0, .len = 1, .mark = 0 }, - .{ .at = 1, .len = 2, .reads = .bytes, .big = true, .mark = 0 }, - .{ .at = 3, .len = 2, .big = true, .mark = 0 }, - .{ .at = 5, .len = 2, .reads = .bytes, .big = true, .mark = 0 }, - .{ .at = 7, .len = 1, .reads = .bytes, .mark = 0 }, + .{ .at = 1, .len = 2, .reads = .bytes, .big = true, .mark = 1 }, + .{ .at = 3, .len = 2, .big = true, .mark = 1 }, + .{ .at = 5, .len = 2, .reads = .bytes, .big = true, .mark = 1 }, + .{ .at = 7, .len = 1, .reads = .bytes, .mark = 1 }, }) catch @panic("OOM"); - for (0..cells) |k| out.append(arena, .{ .at = 8 + 2 * k, .len = 2, .big = true, .mark = 1 }) catch @panic("OOM"); + for (0..cells) |k| out.append(arena, .{ .at = 8 + 2 * k, .len = 2, .big = true, .mark = 2 }) catch @panic("OOM"); for (0..cells) |k| { const at: usize = std.mem.readInt(u16, page[8 + 2 * k ..][0..2], .big); const size = page[at]; const header = page[at + 2]; std.debug.assert(size < 0x80 and page[at + 1] < 0x80 and header == 2); - const mark: u8 = @intCast(2 + k); + const mark: u8 = @intCast(3 + k); out.appendSlice(arena, &.{ .{ .at = at, .len = 1, .reads = .bytes, .mark = mark }, .{ .at = at + 1, .len = 1, .mark = mark }, @@ -135,7 +137,7 @@ fn frame(s: *anim.Frame) void { std.debug.assert(bytes.len == 4096 and bytes[0] == 0x0d and bytes[4] == 3); std.debug.assert(std.mem.eql(u8, bytes[8..14], &.{ 0x0f, 0xf7, 0x0f, 0xef, 0x0f, 0xe6 })); std.debug.assert(rec.register(handed, "rsi") == write.args[1]); - const page_marks = s.new([_]anim.Value{ s.value(0), s.value(0), s.value(0), s.value(0), s.value(0) }); + const page_marks = s.new([_]anim.Value{ s.value(0), s.value(0), s.value(0), s.value(0), s.value(0), s.value(0) }); const page = canim.add(s, canim.hexdump.Dump{ .cursor = at, .stage = ctx.stage, @@ -144,7 +146,9 @@ fn frame(s: *anim.Frame) void { .marks = page_marks, .since = handed, }); - const joins = ctx.ties(s); + // rdi, the table's cursor, opened as the caption names it; rsi, the row, linked to the view's row it points at. + const btcursor = canim.loupe(s, .{ .cursor = at, .stage = ctx.stage, .from = .{ .register = "rdi" } }); + const joins, const row_link = ctx.tiesWith(s, "rsi", 1.0); var says: canim.Narrator = .{}; const fade = struct { @@ -178,9 +182,17 @@ fn frame(s: *anim.Frame) void { fade.in(s, row); says.line(s, "`sqlite3VdbeExec`, the bytecode's loop, calls the B-tree: `rdi` is\nthe table's cursor, `rsi` the row: rowid 1, a record of 7 bytes."); - // Each field as the caption reaches it: the rowid, then the record's length. + // As the caption names them: rdi's cursor opened under it (a beat of + // its own), then rsi linked to the row; then each field: the rowid, the record's length. + const named = s.cursor; + btcursor.open(s); + row_link.play(s); + s.cursor = named + t.loupe.open + row_link.total(); + btcursor.close(s); + // Spread over the caption's reading: never more than 2 s still. + s.wait(1.4); mark.in(s, row_marks[0]); - s.wait(2 * t.beat); + s.wait(2.0); mark.in(s, row_marks[1]); says.line(s, "Two more continues, the same call: rowid 2, then 3, records\nof 6 and 7 bytes. The rows are in memory, not yet on disk."); @@ -203,16 +215,18 @@ fn frame(s: *anim.Frame) void { const crossing = canim.syscalls.Plan.of(write); at.step(s, back, crossing.step(), crossing.total); - says.line(s, "Page 2 as the kernel took it: `0d`, a table's leaf; 3 cells;\ntheir offsets, `0ff7 0fef 0fe6`, each a row at the page's end."); - mark.in(s, page_marks[0]); - s.wait(3 * t.beat); - mark.in(s, page_marks[1]); - says.line(s, "Each cell: its length, its rowid, the record's header, the text.\n'alpha' went in first and sits last: cells fill from the end."); - mark.out(s, page_marks[0..2]); + // Each field as the caption reaches it, 2 s apart: the picture is never still longer. + says.line(s, "Page 2 as the kernel took it: `0d`, a table's leaf; 3 cells,\nat `0ff7 0fef 0fe6`: each a row at the page's end."); + for (page_marks[0..3], 0..) |v, k| { + s.wait(if (k == 0) 0.4 else 2.0); + mark.in(s, v); + } + says.line(s, "Each cell: its length, rowid, header and text. 'alpha'\nwent in first and sits last: cells fill from the end."); + mark.out(s, page_marks[0..3]); // The rows from the page's end: the first one in, then the next two. - for (page_marks[2..]) |v| { + for (page_marks[3..], 0..) |v, k| { + s.wait(if (k == 0) 0.4 else 2.0); mark.in(s, v); - s.wait(2 * t.beat); } says.close(s); } |
