diff --git a/src/build/UnicodeTables.zig b/src/build/UnicodeTables.zig index 9972c851a..aba3e8f24 100644 --- a/src/build/UnicodeTables.zig +++ b/src/build/UnicodeTables.zig @@ -21,6 +21,9 @@ pub fn init(b: *std.Build, uucode_tables: std.Build.LazyPath) !UnicodeTables { .omit_frame_pointer = false, .unwind_tables = .sync, }), + + // TODO: x86_64 self-hosted crashes + .use_llvm = true, }); const symbols_exe = b.addExecutable(.{ @@ -32,6 +35,9 @@ pub fn init(b: *std.Build, uucode_tables: std.Build.LazyPath) !UnicodeTables { .omit_frame_pointer = false, .unwind_tables = .sync, }), + + // TODO: x86_64 self-hosted crashes + .use_llvm = true, }); if (b.lazyDependency("uucode", .{ diff --git a/src/unicode/Properties.zig b/src/unicode/Properties.zig index b7840743a..c8c4a581c 100644 --- a/src/unicode/Properties.zig +++ b/src/unicode/Properties.zig @@ -24,13 +24,9 @@ pub fn eql(a: Properties, b: Properties) bool { // Needed for lut.Generator pub fn format( self: Properties, - comptime layout: []const u8, - opts: std.fmt.FormatOptions, - writer: anytype, + writer: *std.Io.Writer, ) !void { - _ = layout; - _ = opts; - try std.fmt.format(writer, + try writer.print( \\.{{ \\ .width= {}, \\ .grapheme_boundary_class= .{s}, diff --git a/src/unicode/lut.zig b/src/unicode/lut.zig index e10c5c0b8..da90f1ee7 100644 --- a/src/unicode/lut.zig +++ b/src/unicode/lut.zig @@ -54,12 +54,14 @@ pub fn Generator( defer blocks_map.deinit(); // Our stages - var stage1 = std.ArrayList(u16).init(alloc); - defer stage1.deinit(); - var stage2 = std.ArrayList(u16).init(alloc); - defer stage2.deinit(); - var stage3 = std.ArrayList(Elem).init(alloc); - defer stage3.deinit(); + var stage1: std.ArrayList(u16) = .empty; + var stage2: std.ArrayList(u16) = .empty; + var stage3: std.ArrayList(Elem) = .empty; + defer { + stage1.deinit(alloc); + stage2.deinit(alloc); + stage3.deinit(alloc); + } var block: Block = undefined; var block_len: u16 = 0; @@ -74,7 +76,7 @@ pub fn Generator( } const idx = stage3.items.len; - try stage3.append(elem); + try stage3.append(alloc, elem); break :block_idx idx; }; @@ -96,11 +98,11 @@ pub fn Generator( u16, stage2.items.len, ) orelse return error.Stage2TooLarge; - for (block[0..block_len]) |entry| try stage2.append(entry); + for (block[0..block_len]) |entry| try stage2.append(alloc, entry); } // Map stage1 => stage2 and reset our block - try stage1.append(gop.value_ptr.*); + try stage1.append(alloc, gop.value_ptr.*); block_len = 0; } @@ -109,11 +111,11 @@ pub fn Generator( assert(stage2.items.len <= std.math.maxInt(u16)); assert(stage3.items.len <= std.math.maxInt(u16)); - const stage1_owned = try stage1.toOwnedSlice(); + const stage1_owned = try stage1.toOwnedSlice(alloc); errdefer alloc.free(stage1_owned); - const stage2_owned = try stage2.toOwnedSlice(); + const stage2_owned = try stage2.toOwnedSlice(alloc); errdefer alloc.free(stage2_owned); - const stage3_owned = try stage3.toOwnedSlice(); + const stage3_owned = try stage3.toOwnedSlice(alloc); errdefer alloc.free(stage3_owned); return .{ @@ -145,7 +147,7 @@ pub fn Tables(comptime Elem: type) type { /// Writes the lookup table as Zig to the given writer. The /// written file exports three constants: stage1, stage2, and /// stage3. These can be used to rebuild the lookup table in Zig. - pub fn writeZig(self: *const Self, writer: anytype) !void { + pub fn writeZig(self: *const Self, writer: *std.Io.Writer) !void { try writer.print( \\//! This file is auto-generated. Do not edit. \\ @@ -168,7 +170,13 @@ pub fn Tables(comptime Elem: type) type { \\ \\pub const stage3: [{}]Elem = .{{ , .{self.stage3.len}); - for (self.stage3) |entry| try writer.print("{},", .{entry}); + for (self.stage3) |entry| { + if (@typeInfo(@TypeOf(entry)) == .@"struct" and + @hasDecl(@TypeOf(entry), "format")) + try writer.print("{f},", .{entry}) + else + try writer.print("{},", .{entry}); + } try writer.writeAll( \\}; \\ }; diff --git a/src/unicode/props_uucode.zig b/src/unicode/props_uucode.zig index ba0511ea4..6aed7d7d5 100644 --- a/src/unicode/props_uucode.zig +++ b/src/unicode/props_uucode.zig @@ -84,7 +84,11 @@ pub fn main() !void { defer alloc.free(t.stage1); defer alloc.free(t.stage2); defer alloc.free(t.stage3); - try t.writeZig(std.io.getStdOut().writer()); + + var buf: [4096]u8 = undefined; + var stdout = std.fs.File.stdout().writer(&buf); + try t.writeZig(&stdout.interface); + try stdout.end(); // Uncomment when manually debugging to see our table sizes. // std.log.warn("stage1={} stage2={} stage3={}", .{ diff --git a/src/unicode/symbols_uucode.zig b/src/unicode/symbols_uucode.zig index 3da019e81..8cbd59211 100644 --- a/src/unicode/symbols_uucode.zig +++ b/src/unicode/symbols_uucode.zig @@ -30,7 +30,11 @@ pub fn main() !void { defer alloc.free(t.stage1); defer alloc.free(t.stage2); defer alloc.free(t.stage3); - try t.writeZig(std.io.getStdOut().writer()); + + var buf: [4096]u8 = undefined; + var stdout = std.fs.File.stdout().writer(&buf); + try t.writeZig(&stdout.interface); + try stdout.end(); // Uncomment when manually debugging to see our table sizes. // std.log.warn("stage1={} stage2={} stage3={}", .{