diff options
| author | 2024-02-26 12:24:42 -0400 | |
|---|---|---|
| committer | 2024-02-26 12:24:42 -0400 | |
| commit | 836a4b6e63ac4bd7beb406cb20edf23f0bd342a9 (patch) | |
| tree | 5f806a29594a9cb227aaa4d131209e10ff25aeee /codegen/gbp.zig | |
| parent | Replaced ccc_map with table. 20ms faster (diff) | |
| download | zg-836a4b6e63ac4bd7beb406cb20edf23f0bd342a9.tar.gz zg-836a4b6e63ac4bd7beb406cb20edf23f0bd342a9.tar.xz zg-836a4b6e63ac4bd7beb406cb20edf23f0bd342a9.zip | |
Using separate data struct model.
Diffstat (limited to 'codegen/gbp.zig')
| -rw-r--r-- | codegen/gbp.zig | 68 |
1 files changed, 18 insertions, 50 deletions
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 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | ||
| 2 | 3 | ||
| 3 | const Indic = enum { | 4 | const Indic = enum { |
| 4 | none, | 5 | none, |
| @@ -226,56 +227,23 @@ pub fn main() !void { | |||
| 226 | _ = args_iter.skip(); | 227 | _ = args_iter.skip(); |
| 227 | const output_path = args_iter.next() orelse @panic("No output file arg!"); | 228 | const output_path = args_iter.next() orelse @panic("No output file arg!"); |
| 228 | 229 | ||
| 230 | const compressor = std.compress.deflate.compressor; | ||
| 229 | var out_file = try std.fs.cwd().createFile(output_path, .{}); | 231 | var out_file = try std.fs.cwd().createFile(output_path, .{}); |
| 230 | defer out_file.close(); | 232 | defer out_file.close(); |
| 231 | var out_buf = std.io.bufferedWriter(out_file.writer()); | 233 | var out_comp = try compressor(allocator, out_file.writer(), .{ .level = .best_compression }); |
| 232 | const writer = out_buf.writer(); | 234 | defer out_comp.deinit(); |
| 233 | 235 | const writer = out_comp.writer(); | |
| 234 | const prop_code = | 236 | |
| 235 | \\const std = @import("std"); | 237 | const endian = builtin.cpu.arch.endian(); |
| 236 | \\ | 238 | try writer.writeInt(u16, @intCast(stage1.items.len), endian); |
| 237 | \\pub const Indic = enum { | 239 | for (stage1.items) |i| try writer.writeInt(u16, i, endian); |
| 238 | \\ none, | 240 | |
| 239 | \\ | 241 | try writer.writeInt(u16, @intCast(stage2.items.len), endian); |
| 240 | \\ Consonant, | 242 | for (stage2.items) |i| try writer.writeInt(u16, i, endian); |
| 241 | \\ Extend, | 243 | |
| 242 | \\ Linker, | 244 | const props_bytes = stage3.keys(); |
| 243 | \\}; | 245 | try writer.writeInt(u16, @intCast(props_bytes.len), endian); |
| 244 | \\ | 246 | try writer.writeAll(props_bytes); |
| 245 | \\pub const Gbp = enum { | 247 | |
| 246 | \\ none, | 248 | try out_comp.flush(); |
| 247 | \\ Control, | ||
| 248 | \\ CR, | ||
| 249 | \\ Extend, | ||
| 250 | \\ L, | ||
| 251 | \\ LF, | ||
| 252 | \\ LV, | ||
| 253 | \\ LVT, | ||
| 254 | \\ Prepend, | ||
| 255 | \\ Regional_Indicator, | ||
| 256 | \\ SpacingMark, | ||
| 257 | \\ T, | ||
| 258 | \\ V, | ||
| 259 | \\ ZWJ, | ||
| 260 | \\}; | ||
| 261 | \\ | ||
| 262 | ; | ||
| 263 | |||
| 264 | try writer.writeAll(prop_code); | ||
| 265 | |||
| 266 | try writer.print("const Stage2Int = std.math.IntFittingRange(0, {});\n", .{stage2.items.len}); | ||
| 267 | try writer.print("pub const stage_1 = [{}]Stage2Int{{", .{stage1.items.len}); | ||
| 268 | for (stage1.items) |v| try writer.print("{},", .{v}); | ||
| 269 | try writer.writeAll("};\n"); | ||
| 270 | |||
| 271 | try writer.print("const Stage3Int = std.math.IntFittingRange(0, {});\n", .{stage3_len}); | ||
| 272 | try writer.print("pub const stage_2 = [{}]Stage3Int{{", .{stage2.items.len}); | ||
| 273 | for (stage2.items) |v| try writer.print("{},", .{v}); | ||
| 274 | try writer.writeAll("};\n"); | ||
| 275 | |||
| 276 | try writer.print("pub const stage_3 = [{}]u8{{", .{stage3_len}); | ||
| 277 | for (stage3.keys()) |v| try writer.print("{},", .{v}); | ||
| 278 | try writer.writeAll("};\n"); | ||
| 279 | |||
| 280 | try out_buf.flush(); | ||
| 281 | } | 249 | } |