mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-12 04:46:15 +00:00
unicode: fix lookup table generation
This commit is contained in:
@@ -21,6 +21,9 @@ pub fn init(b: *std.Build, uucode_tables: std.Build.LazyPath) !UnicodeTables {
|
|||||||
.omit_frame_pointer = false,
|
.omit_frame_pointer = false,
|
||||||
.unwind_tables = .sync,
|
.unwind_tables = .sync,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// TODO: x86_64 self-hosted crashes
|
||||||
|
.use_llvm = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const symbols_exe = b.addExecutable(.{
|
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,
|
.omit_frame_pointer = false,
|
||||||
.unwind_tables = .sync,
|
.unwind_tables = .sync,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// TODO: x86_64 self-hosted crashes
|
||||||
|
.use_llvm = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (b.lazyDependency("uucode", .{
|
if (b.lazyDependency("uucode", .{
|
||||||
|
@@ -24,13 +24,9 @@ pub fn eql(a: Properties, b: Properties) bool {
|
|||||||
// Needed for lut.Generator
|
// Needed for lut.Generator
|
||||||
pub fn format(
|
pub fn format(
|
||||||
self: Properties,
|
self: Properties,
|
||||||
comptime layout: []const u8,
|
writer: *std.Io.Writer,
|
||||||
opts: std.fmt.FormatOptions,
|
|
||||||
writer: anytype,
|
|
||||||
) !void {
|
) !void {
|
||||||
_ = layout;
|
try writer.print(
|
||||||
_ = opts;
|
|
||||||
try std.fmt.format(writer,
|
|
||||||
\\.{{
|
\\.{{
|
||||||
\\ .width= {},
|
\\ .width= {},
|
||||||
\\ .grapheme_boundary_class= .{s},
|
\\ .grapheme_boundary_class= .{s},
|
||||||
|
@@ -54,12 +54,14 @@ pub fn Generator(
|
|||||||
defer blocks_map.deinit();
|
defer blocks_map.deinit();
|
||||||
|
|
||||||
// Our stages
|
// Our stages
|
||||||
var stage1 = std.ArrayList(u16).init(alloc);
|
var stage1: std.ArrayList(u16) = .empty;
|
||||||
defer stage1.deinit();
|
var stage2: std.ArrayList(u16) = .empty;
|
||||||
var stage2 = std.ArrayList(u16).init(alloc);
|
var stage3: std.ArrayList(Elem) = .empty;
|
||||||
defer stage2.deinit();
|
defer {
|
||||||
var stage3 = std.ArrayList(Elem).init(alloc);
|
stage1.deinit(alloc);
|
||||||
defer stage3.deinit();
|
stage2.deinit(alloc);
|
||||||
|
stage3.deinit(alloc);
|
||||||
|
}
|
||||||
|
|
||||||
var block: Block = undefined;
|
var block: Block = undefined;
|
||||||
var block_len: u16 = 0;
|
var block_len: u16 = 0;
|
||||||
@@ -74,7 +76,7 @@ pub fn Generator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const idx = stage3.items.len;
|
const idx = stage3.items.len;
|
||||||
try stage3.append(elem);
|
try stage3.append(alloc, elem);
|
||||||
break :block_idx idx;
|
break :block_idx idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -96,11 +98,11 @@ pub fn Generator(
|
|||||||
u16,
|
u16,
|
||||||
stage2.items.len,
|
stage2.items.len,
|
||||||
) orelse return error.Stage2TooLarge;
|
) 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
|
// Map stage1 => stage2 and reset our block
|
||||||
try stage1.append(gop.value_ptr.*);
|
try stage1.append(alloc, gop.value_ptr.*);
|
||||||
block_len = 0;
|
block_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,11 +111,11 @@ pub fn Generator(
|
|||||||
assert(stage2.items.len <= std.math.maxInt(u16));
|
assert(stage2.items.len <= std.math.maxInt(u16));
|
||||||
assert(stage3.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);
|
errdefer alloc.free(stage1_owned);
|
||||||
const stage2_owned = try stage2.toOwnedSlice();
|
const stage2_owned = try stage2.toOwnedSlice(alloc);
|
||||||
errdefer alloc.free(stage2_owned);
|
errdefer alloc.free(stage2_owned);
|
||||||
const stage3_owned = try stage3.toOwnedSlice();
|
const stage3_owned = try stage3.toOwnedSlice(alloc);
|
||||||
errdefer alloc.free(stage3_owned);
|
errdefer alloc.free(stage3_owned);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
@@ -145,7 +147,7 @@ pub fn Tables(comptime Elem: type) type {
|
|||||||
/// Writes the lookup table as Zig to the given writer. The
|
/// Writes the lookup table as Zig to the given writer. The
|
||||||
/// written file exports three constants: stage1, stage2, and
|
/// written file exports three constants: stage1, stage2, and
|
||||||
/// stage3. These can be used to rebuild the lookup table in Zig.
|
/// 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(
|
try writer.print(
|
||||||
\\//! This file is auto-generated. Do not edit.
|
\\//! This file is auto-generated. Do not edit.
|
||||||
\\
|
\\
|
||||||
@@ -168,7 +170,13 @@ pub fn Tables(comptime Elem: type) type {
|
|||||||
\\
|
\\
|
||||||
\\pub const stage3: [{}]Elem = .{{
|
\\pub const stage3: [{}]Elem = .{{
|
||||||
, .{self.stage3.len});
|
, .{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(
|
try writer.writeAll(
|
||||||
\\};
|
\\};
|
||||||
\\ };
|
\\ };
|
||||||
|
@@ -84,7 +84,11 @@ pub fn main() !void {
|
|||||||
defer alloc.free(t.stage1);
|
defer alloc.free(t.stage1);
|
||||||
defer alloc.free(t.stage2);
|
defer alloc.free(t.stage2);
|
||||||
defer alloc.free(t.stage3);
|
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.
|
// Uncomment when manually debugging to see our table sizes.
|
||||||
// std.log.warn("stage1={} stage2={} stage3={}", .{
|
// std.log.warn("stage1={} stage2={} stage3={}", .{
|
||||||
|
@@ -30,7 +30,11 @@ pub fn main() !void {
|
|||||||
defer alloc.free(t.stage1);
|
defer alloc.free(t.stage1);
|
||||||
defer alloc.free(t.stage2);
|
defer alloc.free(t.stage2);
|
||||||
defer alloc.free(t.stage3);
|
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.
|
// Uncomment when manually debugging to see our table sizes.
|
||||||
// std.log.warn("stage1={} stage2={} stage3={}", .{
|
// std.log.warn("stage1={} stage2={} stage3={}", .{
|
||||||
|
Reference in New Issue
Block a user