From 836a4b6e63ac4bd7beb406cb20edf23f0bd342a9 Mon Sep 17 00:00:00 2001 From: Jose Colon Rodriguez Date: Mon, 26 Feb 2024 12:24:42 -0400 Subject: Using separate data struct model. --- codegen/gbp.zig | 68 +++++++++++++++------------------------------------------ 1 file changed, 18 insertions(+), 50 deletions(-) (limited to 'codegen/gbp.zig') diff --git a/codegen/gbp.zig b/codegen/gbp.zig index 3bd9a4d..39e0da3 100644 --- a/codegen/gbp.zig +++ b/codegen/gbp.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const Indic = enum { none, @@ -226,56 +227,23 @@ pub fn main() !void { _ = args_iter.skip(); const output_path = args_iter.next() orelse @panic("No output file arg!"); + const compressor = std.compress.deflate.compressor; var out_file = try std.fs.cwd().createFile(output_path, .{}); defer out_file.close(); - var out_buf = std.io.bufferedWriter(out_file.writer()); - const writer = out_buf.writer(); - - const prop_code = - \\const std = @import("std"); - \\ - \\pub const Indic = enum { - \\ none, - \\ - \\ Consonant, - \\ Extend, - \\ Linker, - \\}; - \\ - \\pub const Gbp = enum { - \\ none, - \\ Control, - \\ CR, - \\ Extend, - \\ L, - \\ LF, - \\ LV, - \\ LVT, - \\ Prepend, - \\ Regional_Indicator, - \\ SpacingMark, - \\ T, - \\ V, - \\ ZWJ, - \\}; - \\ - ; - - try writer.writeAll(prop_code); - - try writer.print("const Stage2Int = std.math.IntFittingRange(0, {});\n", .{stage2.items.len}); - try writer.print("pub const stage_1 = [{}]Stage2Int{{", .{stage1.items.len}); - for (stage1.items) |v| try writer.print("{},", .{v}); - try writer.writeAll("};\n"); - - try writer.print("const Stage3Int = std.math.IntFittingRange(0, {});\n", .{stage3_len}); - try writer.print("pub const stage_2 = [{}]Stage3Int{{", .{stage2.items.len}); - for (stage2.items) |v| try writer.print("{},", .{v}); - try writer.writeAll("};\n"); - - try writer.print("pub const stage_3 = [{}]u8{{", .{stage3_len}); - for (stage3.keys()) |v| try writer.print("{},", .{v}); - try writer.writeAll("};\n"); - - try out_buf.flush(); + var out_comp = try compressor(allocator, out_file.writer(), .{ .level = .best_compression }); + defer out_comp.deinit(); + const writer = out_comp.writer(); + + const endian = builtin.cpu.arch.endian(); + try writer.writeInt(u16, @intCast(stage1.items.len), endian); + for (stage1.items) |i| try writer.writeInt(u16, i, endian); + + try writer.writeInt(u16, @intCast(stage2.items.len), endian); + for (stage2.items) |i| try writer.writeInt(u16, i, endian); + + const props_bytes = stage3.keys(); + try writer.writeInt(u16, @intCast(props_bytes.len), endian); + try writer.writeAll(props_bytes); + + try out_comp.flush(); } -- cgit v1.2.3