From 2eb8860b2ca05c426f3962661441aaee13d3be44 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 19:09:26 -0300 Subject: web: the browser shell builds again and loads a dump of a native build: a theme by its name, a field compiled out passed over, no disk asked; touch.dump replaces the hand-written ZON fixture Fixed for wasm32-freestanding: counts as usize, no threads, stb_image, tape or host stat there. touch.mjs follows the renderer's 13 tag-layer fields, helix's retuned colours and the tag column. Co-Authored-By: Claude Opus 5.5 --- src/walk.zig | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/walk.zig') diff --git a/src/walk.zig b/src/walk.zig index 328557a7..6f9cc34b 100644 --- a/src/walk.zig +++ b/src/walk.zig @@ -843,6 +843,10 @@ fn allocOf(comptime T: type, comptime name: []const u8) ?[]const u8 { return null; } +fn countOf(n: u64) DecodeError!usize { + return std.math.cast(usize, n) orelse error.BadDump; +} + /// An allocation a load made: what a reference to it finds, and what a /// failed load frees. const Made = struct { bytes: []u8, alignment: std.mem.Alignment, gpa: std.mem.Allocator, dead: bool = false }; @@ -931,6 +935,11 @@ pub fn Load(comptime roots: []const type) type { return std.mem.bytesToValue(T, try l.take(@sizeOf(T))); } + /// A count, as this machine counts (a wasm32 one has 32 bits). + fn count(l: *Self) DecodeError!usize { + return countOf(try l.scalar(u64)); + } + fn name(l: *Self) DecodeError![]const u8 { return l.take(try l.scalar(u16)); } @@ -962,9 +971,9 @@ pub fn Load(comptime roots: []const type) type { }, .optional, .one, .slice, .prefix, .error_union => t.child = try l.scalar(u32), .@"struct", .@"union" => { - const count = try l.scalar(u32); - if (count > l.bytes.len) return error.BadDump; - const list = try a.alloc(SrcField, count); + const nfields = try l.scalar(u32); + if (nfields > l.bytes.len) return error.BadDump; + const list = try a.alloc(SrcField, nfields); for (list) |*f| f.* = .{ .name = try l.name(), .ty = try l.scalar(u32) }; t.fields = list; }, @@ -1073,6 +1082,14 @@ pub fn Load(comptime roots: []const type) type { out.* = .{ .raw = raw }; return; } + // A field this build compiles out (a PDF slot where there is no + // MuPDF): passed over, said only when it held something. + if (comptime kindOf(Canon(T)) == .void) if (!l.same and l.src[ty].kind != .void) { + const held = l.src[ty].kind != .optional or (l.at < l.bytes.len and l.bytes[l.at] != 0); + try l.skip(ty); + if (held) l.note("{s}: not in this build", .{l.field}); + return; + }; if (!try l.kindMatches(T, ty)) return error.Incompatible; const s = l.src[ty]; if (comptime isList(T)) { @@ -1194,8 +1211,7 @@ pub fn Load(comptime roots: []const type) type { } else out.* = try l.errorNamed(@typeInfo(T).error_union.error_set); }, .custom => { - const n = try l.scalar(u64); - const bytes = try l.take(n); + const bytes = try l.take(try l.count()); T.dumpRead(out, l.gpa, bytes) catch |err| { if (err == error.OutOfMemory) return error.OutOfMemory; l.note("{s}: {t}", .{ l.field, err }); @@ -1204,7 +1220,7 @@ pub fn Load(comptime roots: []const type) type { if (comptime @hasDecl(T, "dumpFree")) try l.customs.append(l.own, .{ .ptr = out, .gpa = l.gpa, .free = @ptrCast(&T.dumpFree) }); }, .bitset => { - const bits = try l.scalar(u64); + const bits = try l.count(); out.* = try .initEmpty(l.gpa, bits); const words = (bits + @bitSizeOf(usize) - 1) / @bitSizeOf(usize); if (words > 0) @memcpy(std.mem.sliceAsBytes(out.masks[0..words]), try l.take(words * @sizeOf(usize))); @@ -1232,7 +1248,7 @@ pub fn Load(comptime roots: []const type) type { fn slice(l: *Self, comptime E: type, s: SrcType) DecodeError![]E { if (try l.ref()) |again| return @as([*]E, @ptrCast(@alignCast(again.ptr)))[0 .. again.len / @max(1, @sizeOf(E))]; - const n = try l.scalar(u64); + const n = try l.count(); if (n == 0) return &.{}; if (n > l.bytes.len) return error.BadDump; const many = try l.gpa.alloc(E, n); @@ -1264,7 +1280,7 @@ pub fn Load(comptime roots: []const type) type { // cannot be read is left out, not the array. const droppable = comptime @typeInfo(E) == .optional and @typeInfo(@typeInfo(E).optional.child) == .pointer; var failed = false; - for (0..n) |i| { + for (0..try countOf(n)) |i| { if (i >= keep) { try l.skip(ty); continue; @@ -1394,8 +1410,8 @@ pub fn Load(comptime roots: []const type) type { .error_union => if ((try l.take(1))[0] != 0) try l.skip(s.child) else { _ = try l.name(); }, - .custom => _ = try l.take(try l.scalar(u64)), - .bitset => _ = try l.take((try l.scalar(u64) + 63) / 64 * 8), + .custom => _ = try l.take(try l.count()), + .bitset => _ = try l.take((try l.count() + 63) / 64 * 8), } } @@ -1407,7 +1423,7 @@ pub fn Load(comptime roots: []const type) type { _ = try l.take(@intCast(n * size)); return; } - for (0..n) |_| try l.skip(ty); + for (0..try countOf(n)) |_| try l.skip(ty); } }; } -- cgit v1.3