code
stringlengths 38
801k
| repo_path
stringlengths 6
263
|
---|---|
test "range destructuring" {
expectOutput(
\\const start:end:step = 1:2:3
\\return start+end+step
, "6");
}
test "continue" {
expectOutput(
\\let i = 0
\\while (i < 1)
\\ i += 1
\\ continue
, "()");
expectOutput(
\\for (let i in 0:1)
\\ continue
, "()");
}
test "std.gc" {
if (std.builtin.os.tag == .windows) {
// TODO this gives a different result on windows
return error.SkipZigTest;
}
expectOutput(
\\const {collect} = import("std.gc")
\\const json = import("std.json")
\\
\\const makeGarbage = fn()
\\ json.stringify({"a": [2, "foo", ()]})
\\
\\for (0:5) makeGarbage()
\\return collect()
,
\\42
);
}
test "std.json" {
expectOutput(
\\const json = import("std.json")
\\return json.parse("{\"a\":[2,\"foo\",null]}")
,
\\{"a": [2, "foo", ()]}
);
expectOutput(
\\const json = import("std.json")
\\return json.stringify({"a": [2, "foo", ()]})
,
\\"{\"a\":[2,\"foo\",null]}"
);
}
test "boolean short-circuit" {
expectOutput(
\\const foo = fn() true
\\const bar = fn() error("should not be evaluated")
\\return foo() or bar()
,
\\true
);
expectOutput(
\\const foo = fn() false
\\const bar = fn() error("should not be evaluated")
\\return foo() and bar()
,
\\false
);
}
test "match" {
expectOutput(
\\const getNum = fn (arg)
\\ return match (arg)
\\ 1, 2 => 69
\\ 12 => 42
\\ 10004 => 17
\\ _ => 0
\\
\\let arr = []
\\arr ++ getNum(1)
\\arr ++ getNum(2)
\\arr ++ getNum(12)
\\arr ++ getNum(10004)
\\arr ++ getNum(9)
\\return arr
,
\\[69, 69, 42, 17, 0]
);
expectOutput(
\\const getNum = fn() 42
\\
\\match (getNum())
\\ 1 => error
\\ let val => return val
,
\\42
);
}
test "try catch" {
expectOutput(
\\const fails_on_1 = fn(arg) if (arg == 1) error(69)
\\const fails_on_2 = fn(arg) if (arg == 2) error(42)
\\const fails_on_3 = fn(arg) if (arg == 3) error(17)
\\
\\const foo = fn(arg)
\\ try
\\ fails_on_1(arg)
\\ fails_on_2(arg)
\\ fails_on_3(arg)
\\ catch (let err)
\\ return err
\\
\\ return 99
\\
\\return for (let i in 0:4) foo(i)
,
\\[99, 69, 42, 17]
);
}
test "string join" {
expectOutput(
\\return ",".join([1 as str, "bar", [2] as str])
,
\\"1,bar,[2]"
);
}
test "format string" {
expectOutput(
\\return f"foo{255:X}bar"
,
\\"fooFFbar"
);
expectOutput(
\\return "foo{X}bar".format((255,))
,
\\"fooFFbar"
);
}
test "concatting" {
expectOutput(
\\let x = "foo"
\\return x ++ "bar" ++ "baz"
,
\\"foobarbaz"
);
expectOutput(
\\let x = []
\\return x ++ 1 ++ "bar" ++ 2
,
\\[1, "bar", 2]
);
expectOutput(
\\return [[1] as str]
,
\\["[1]"]
);
expectOutput(
\\let x = "foo"
\\x ++ "bar" ++ "baz"
\\return x
,
\\"foobarbaz"
);
}
test "comma decimals" {
expectOutput(
\\return 0,5 + 0,2;
,
\\0.7
);
}
test "range" {
expectOutput(
\\return for (let i in 0:7:2) i
,
\\[0, 2, 4, 6]
);
expectOutput(
\\return 1 in 0:2
,
\\true
);
expectOutput(
\\return 1 in 0:2:2
,
\\false
);
}
test "list comprehension as function argument" {
expectOutput(
\\const map = {1: 2, 3: 4, 5: 6}
\\return (fn(l)l)(for (let (k, v) in map) {key: k, val: v})
,
\\[{"key": 1, "val": 2}, {"key": 3, "val": 4}, {"key": 5, "val": 6}]
);
}
test "map iterator" {
expectOutput(
\\const map = {1: 2, 3: 4, 5: 6}
\\let sum = 0
\\for (let (k, v) in map)
\\ sum += k
\\ sum *= v
\\return sum
,
\\150
);
}
test "list comprehension" {
expectOutput(
\\return for (const c in "hello") c
,
\\["h", "e", "l", "l", "o"]
);
expectOutput(
\\let i = 0
\\return while (i < 10)
\\ i += 1
\\ i
,
\\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
);
}
test "list.append" {
expectOutput(
\\let list = [1, 2]
\\list.append(3)
\\return list
,
\\[1, 2, 3]
);
}
test "std.map" {
expectOutput(
\\let val = {foo: 2, bar: 3, 0: 515, [1]: [2]}
\\const map = import("std.map")
\\const {assert} = import("std.debug")
\\const keys = map.keys(val)
\\assert(keys is list and keys.len == 4)
\\const values = map.values(val)
\\assert(values is list and values.len == 4)
\\const entries = map.entries(val)
\\assert(entries is list and entries.len == 4)
\\const entry = entries[0]
\\assert(entry is map and map.size(entry) == 2)
,
\\()
);
}
test "collections copy hold values" {
expectOutput(
\\let x = [0]
\\let y = [x]
\\x[0] = 1
\\return y
,
\\[[0]]
);
expectOutput(
\\const foo = [1]
\\const bar = fn(list) list[0] = 2
\\bar(foo)
\\return foo
,
\\[1]
);
}
test "tagged values" {
expectOutput(
\\return @something{foo: 69}
,
\\@something{"foo": 69}
);
expectOutput(
\\const foo = @foo
\\const bar = @bar
\\return foo == bar
,
\\false
);
expectOutput(
\\const foo = @foo[1]
\\const bar = @foo[1]
\\return foo == bar
,
\\true
);
expectOutput(
\\const foo = @foo[1, 2]
\\const @foo[bar, baz] = foo
\\return bar + baz
,
\\3
);
}
test "error map" {
expectOutput(
\\const foo = error{a: 2}
\\const error{a: bar} = foo
\\return bar * 2
,
\\4
);
}
test "call bog function" {
expectCallOutput(
\\return {
\\ foo: 2,
\\ doTheTest: fn(num) this.foo + num
\\}
, .{1},
\\3
);
}
test "containers do not overwrite memoized values" {
expectOutput(
\\let x = [true]
\\x[0] = 1
\\return true
,
\\true
);
}
test "this" {
expectOutput(
\\let x = {
\\ a: 69,
\\ y: 420,
\\ foo: fn() (
\\ [0][0] # last_get is now referencing this list
\\ return this.a * this.y
\\ ),
\\
\\}
\\return x.foo()
,
\\28980
);
}
test "closures" {
expectOutput(
\\let x = 2
\\const foo = fn() x + 5
\\return foo()
,
\\7
);
expectOutput(
\\let x = 2
\\const foo = fn()
\\ return fn()
\\ return x + 5
\\
\\const bar = foo()
\\return bar()
,
\\7
);
}
test "map" {
expectOutput(
\\let y = 2
\\const map = {1: 2, y}
\\map["foo"] = "bar"
\\return map
,
\\{1: 2, "y": 2, "foo": "bar"}
);
expectOutput(
\\let y = 2
\\const map = {1: 2, x: y}
\\const {x} = map
\\const {x: foo} = map
\\return x == foo
,
\\true
);
}
test "property access of list" {
expectOutput(
\\const list = [1, true, "hello"]
\\return list.len
,
\\3
);
expectOutput(
\\let y = [1,2,3]
\\y[-1] = 4
\\y["len"]
\\return y
,
\\[1, 2, 4]
);
}
test "string for iter" {
expectOutput(
\\let sum = 0
\\for (let c in "hellö wörld")
\\ if (c == "h") sum += 1
\\ else if (c == "e") sum += 2
\\ else if (c == "l") sum += 3
\\ else if (c == "ö") sum += 4
\\ else if (c == "w") sum += 5
\\ else if (c == "d") sum += 6
\\
\\return sum
,
\\31
);
}
test "for loops" {
expectOutput(
\\let sum = 0
\\for (let x in [1, 2, 3])
\\ sum += x
\\
\\return sum
,
\\6
);
expectOutput(
\\let sum = 0
\\for (let (x,y) in [(1, 2), (2, 3), (5, 6)])
\\ sum += x * y
\\
\\return sum
,
\\38
);
}
test "error destructure" {
expectOutput(
\\const err = fn() error(2)
\\
\\let error(y) = err()
\\return y + 2
,
\\4
);
}
test "while let" {
expectOutput(
\\const getSome = fn(val) if (val != 0) val - 1
\\
\\let val = 10
\\while (let newVal = getSome(val))
\\ val = newVal
\\return val
,
\\0
);
}
test "if let" {
expectOutput(
\\const maybeInc = fn(val)
\\ if (let y = val)
\\ return y + 4
\\ return 2
\\
\\return maybeInc(()) + maybeInc(4)
,
\\10
);
}
test "fibonacci" {
expectOutput(
\\const fib = fn(n)
\\ if (n < 2) return n
\\ return fib(n - 1) + fib(n-2)
\\
\\return fib(10)
,
\\55
);
}
test "const value not modified by function" {
expectOutput(
\\const x = 2
\\const inc = fn(n) n += 1
\\inc(x)
\\return x
,
\\2
);
}
test "in" {
expectOutput(
\\let y = [1, 2, 3]
\\if (not true in y)
\\ y[-2] = false
\\return y == [1, false, 3]
,
\\true
);
}
test "get/set" {
expectOutput(
\\let y = [1, 2, 3]
\\y[-2] = true
\\return y[1]
,
\\true
);
}
test "mixed num and int" {
expectOutput(
\\let y = 2
\\y /= 5
\\return y
,
\\0.4
);
expectOutput(
\\let y = 2
\\y **= 0.5
\\return y
,
\\1.4142135623730951
);
}
test "copy on assign" {
expectOutput(
\\const x = 2
\\let y = x
\\y += 2
\\return x
,
\\2
);
expectOutput(
\\let y = 2
\\const inc = fn (a) a+=2
\\inc(y)
\\return y
,
\\4
);
}
test "strings" {
expectOutput(
\\const a = "hello"
\\return if (a == "world") 2 as str else 1.5 as str
,
\\"1.5"
);
}
test "comparison" {
expectOutput(
\\let a = 0
\\while (a != 1000)
\\ a += 1
\\return a
,
\\1000
);
}
test "while loop" {
expectOutput(
\\const cond = true
\\while (cond)
\\ if (not cond)
\\ break
\\ else
\\ let x = 2
\\ break
\\return true
,
\\true
);
}
test "subscript" {
expectOutput(
\\const y = (1, 2)
\\return y[-1]
,
\\2
);
}
test "assert" {
expectOutput(
\\const assert = fn (ok) if (not ok) error(false)
\\return assert(not false)
,
\\()
);
}
test "functions" {
expectOutput(
\\const add = fn ((a,b)) a + b
\\const tuplify = fn (a,b) (a,b)
\\return add(tuplify(1, 2))
,
\\3
);
expectOutput(
\\const add = fn (a,b) a + b
\\const sub = fn (a,b) a - b
\\return sub(add(3, 4), add(1,2))
,
\\4
);
}
test "type casting" {
expectOutput(
\\return 1 as none
,
\\()
);
expectOutput(
\\return 1 as bool
,
\\true
);
expectOutput(
\\let y = 2.5
\\return y as int
,
\\2
);
expectOutput(
\\let x = 2.5 as int
\\let y = x as num
\\return y
,
\\2
);
}
test "type checking" {
expectOutput(
\\return 1 is int
,
\\true
);
expectOutput(
\\return 1 is num
,
\\false
);
expectOutput(
\\return (1,) is tuple
,
\\true
);
}
test "tuple destructuring" {
// TODO should destructuring different sized tuples be an error?
expectOutput(
\\let (a, b, _, c) = (1, 2, 3, 4, 5)
\\return (a + b) * c
,
\\12
);
}
test "tuple" {
expectOutput(
\\return (1, 2, 3, 4, 22.400)
,
\\(1, 2, 3, 4, 22.4)
);
}
test "bool if" {
expectOutput(
\\const x = not false
\\return 3 + if (not x) 2 else if (x) 4 else 9
,
\\7
);
}
test "assignment" {
expectOutput(
\\let x = 2
\\let y = -3
\\x **= -y
\\return x
,
\\8
);
}
test "basic math" {
expectOutput(
\\let x = 2
\\let y = x * 5
\\let z = 90
\\return y // x * z
,
\\450
);
}
test "basic variables" {
expectOutput(
\\let x = 12
\\return x
,
\\12
);
expectOutput(
\\let x = true
\\return not x
,
\\false
);
}
test "number literals" {
expectOutput(
\\return 12
,
\\12
);
expectOutput(
\\return 0x12
,
\\18
);
expectOutput(
\\return 0o12
,
\\10
);
}
test "constant values" {
expectOutput(
\\return true
,
\\true
);
expectOutput(
\\return not true
,
\\false
);
expectOutput(
\\return -12
,
\\-12
);
}
const std = @import("std");
const mem = std.mem;
const warn = std.debug.warn;
const testing = std.testing;
const bog = @import("bog");
const Vm = bog.Vm;
fn expectCallOutput(source: []const u8, args: anytype, expected: []const u8) void {
var vm = Vm.init(std.testing.allocator, .{});
defer vm.deinit();
var module: *bog.Module = undefined;
const res = run(&module, source, &vm) catch |e| switch (e) {
else => @panic("test failure"),
error.TokenizeError, error.ParseError, error.CompileError, error.RuntimeError => {
vm.errors.render(source, std.io.getStdErr().writer()) catch {};
@panic("test failure");
},
};
defer module.deinit(std.testing.allocator);
const call_res = vm.call(res, "doTheTest", args) catch |e| switch (e) {
else => @panic("test failure"),
error.RuntimeError => {
vm.errors.render(source, std.io.getStdErr().writer()) catch {};
@panic("test failure");
},
};
var out_buf = std.ArrayList(u8).init(std.testing.allocator);
defer out_buf.deinit();
call_res.dump(out_buf.writer(), 2) catch @panic("test failure");
testing.expectEqualStrings(expected, out_buf.items);
}
fn expectOutput(source: []const u8, expected: []const u8) void {
var vm = Vm.init(std.testing.allocator, .{});
defer vm.deinit();
vm.addStd() catch unreachable;
var module: *bog.Module = undefined;
const res = run(&module, source, &vm) catch |e| switch (e) {
else => @panic("test failure"),
error.TokenizeError, error.ParseError, error.CompileError, error.RuntimeError => {
vm.errors.render(source, std.io.getStdErr().writer()) catch {};
@panic("test failure");
},
};
defer module.deinit(std.testing.allocator);
var out_buf = std.ArrayList(u8).init(std.testing.allocator);
defer out_buf.deinit();
res.dump(out_buf.writer(), 2) catch @panic("test failure");
testing.expectEqualStrings(expected, out_buf.items);
}
fn run(mp: **bog.Module, source: []const u8, vm: *Vm) !*bog.Value {
const module = try bog.compile(std.testing.allocator, source, &vm.errors);
errdefer module.deinit(std.testing.allocator);
mp.* = module;
// TODO this should happen in vm.exec but currently that would break repl
vm.ip = module.entry;
return try vm.exec(module);
} | tests/behavior.zig |
allocator: Allocator,
source: []const u8,
filename: []const u8,
const std = @import("std");
const Allocator = std.mem.Allocator;
const zigstr = @import("zigstr");
const term = @import("term.zig");
const parse = @import("parse/!mod.zig");
const Self = @This();
/// Print a code lens at the given location
pub fn printLens(self: *const Self, loc: parse.LocationSpan) !void {
if (loc.start.line == loc.end.line) {
std.debug.assert(loc.start.column <= loc.end.column);
const span_diff = loc.end.column - loc.start.column;
// one char
if (span_diff <= 1) {
try self.printLensSingleChar(loc.start);
}
// more than one character
else {
try self.printLensMultiChar(loc.start);
}
}
// end is column 1 of next line, therefore one line
else if (loc.start.line == (loc.end.line - 1) and loc.end.column == 1) {
try self.printLensMultiChar(loc.start);
}
// multiline lens
else {
// @TODO: Create method for printing a lens over multiple lines
term.println("TODO: multiline lens: {?}", .{loc});
}
}
/// Print a code lens pointing to a single character
fn printLensSingleChar(self: *const Self, loc: parse.Location) !void {
const offending_line = try self.getLine(loc.line - 1);
defer self.allocator.free(offending_line);
try self.singleLineGeneric(offending_line, loc);
// pointing caret
term.eprintln("^", .{});
}
/// Print a code lens pointing to multiple characters on a single line
fn printLensMultiChar(self: *const Self, loc: parse.Location) !void {
const offending_line = try self.getLine(loc.line - 1);
defer self.allocator.free(offending_line);
try self.singleLineGeneric(offending_line, loc);
// pointing carets
try term.stderr.writer().writeByteNTimes('^', (offending_line.len + 1) - (loc.column - 1));
term.println("", .{});
}
/// Gets the bytes of a line from a line number.
/// Caller owns memory
fn getLine(self: *const Self, line: usize) ![]const u8 {
var zstr = try zigstr.fromBytes(self.allocator, self.source);
defer zstr.deinit();
const lines = try zstr.lines(self.allocator);
defer self.allocator.free(lines);
const offending_line = lines[line];
return try self.allocator.dupe(u8, offending_line);
}
/// Common code for printing a lens for a single line
fn singleLineGeneric(self: *const Self, offending_line: []const u8, loc: parse.Location) !void {
const number_str = try std.fmt.allocPrint(self.allocator, "{}", .{loc.line});
defer self.allocator.free(number_str);
const padding = number_str.len + 1;
// in which file and where
try term.stderr.writer().writeByteNTimes(' ', padding);
term.eprintln("@ {s}:{}:{}", .{ self.filename, loc.line, loc.column });
// code lens
try term.stderr.writer().writeByteNTimes(' ', padding);
term.eprintln("|", .{});
term.eprintln("{} | {s}", .{ loc.line, offending_line });
try term.stderr.writer().writeByteNTimes(' ', padding);
term.eprint("|", .{});
try term.stderr.writer().writeByteNTimes(' ', loc.column - 1);
} | fexc/src/CodeLens.zig |
const std = @import("std");
const sample_utils = @import("sample_utils.zig");
const c = @import("c.zig").c;
const glfw = @import("glfw");
// #include "utils/SystemUtils.h"
// #include "utils/WGPUHelpers.h"
// WGPUSwapChain swapchain;
// WGPURenderPipeline pipeline;
// WGPUTextureFormat swapChainFormat;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
var allocator = &gpa.allocator;
const setup = try sample_utils.setup();
const queue = c.wgpuDeviceGetQueue(setup.device);
var descriptor = std.mem.zeroes(c.WGPUSwapChainDescriptor);
descriptor.implementation = c.machUtilsBackendBinding_getSwapChainImplementation(setup.binding);
const swap_chain = c.wgpuDeviceCreateSwapChain(setup.device, null, &descriptor);
const swap_chain_format = c.machUtilsBackendBinding_getPreferredSwapChainTextureFormat(setup.binding);
c.wgpuSwapChainConfigure(swap_chain, swap_chain_format, c.WGPUTextureUsage_RenderAttachment, 640, 480);
const vs =
\\ [[stage(vertex)]] fn main(
\\ [[builtin(vertex_index)]] VertexIndex : u32
\\ ) -> [[builtin(position)]] vec4<f32> {
\\ var pos = array<vec2<f32>, 3>(
\\ vec2<f32>( 0.0, 0.5),
\\ vec2<f32>(-0.5, -0.5),
\\ vec2<f32>( 0.5, -0.5)
\\ );
\\ return vec4<f32>(pos[VertexIndex], 0.0, 1.0);
\\ }
;
var vs_wgsl_descriptor = try allocator.create(c.WGPUShaderModuleWGSLDescriptor);
vs_wgsl_descriptor.chain.next = null;
vs_wgsl_descriptor.chain.sType = c.WGPUSType_ShaderModuleWGSLDescriptor;
vs_wgsl_descriptor.source = vs;
const vs_shader_descriptor = c.WGPUShaderModuleDescriptor{
.nextInChain = @ptrCast(*const c.WGPUChainedStruct, vs_wgsl_descriptor),
.label = "my vertex shader",
};
const vs_module = c.wgpuDeviceCreateShaderModule(setup.device, &vs_shader_descriptor);
const fs =
\\ [[stage(fragment)]] fn main() -> [[location(0)]] vec4<f32> {
\\ return vec4<f32>(1.0, 0.0, 0.0, 1.0);
\\ }
;
var fs_wgsl_descriptor = try allocator.create(c.WGPUShaderModuleWGSLDescriptor);
fs_wgsl_descriptor.chain.next = null;
fs_wgsl_descriptor.chain.sType = c.WGPUSType_ShaderModuleWGSLDescriptor;
fs_wgsl_descriptor.source = fs;
const fs_shader_descriptor = c.WGPUShaderModuleDescriptor{
.nextInChain = @ptrCast(*const c.WGPUChainedStruct, fs_wgsl_descriptor),
.label = "my fragment shader",
};
const fs_module = c.wgpuDeviceCreateShaderModule(setup.device, &fs_shader_descriptor);
// Fragment state
var blend = std.mem.zeroes(c.WGPUBlendState);
blend.color.operation = c.WGPUBlendOperation_Add;
blend.color.srcFactor = c.WGPUBlendFactor_One;
blend.color.dstFactor = c.WGPUBlendFactor_One;
blend.alpha.operation = c.WGPUBlendOperation_Add;
blend.alpha.srcFactor = c.WGPUBlendFactor_One;
blend.alpha.dstFactor = c.WGPUBlendFactor_One;
var color_target = std.mem.zeroes(c.WGPUColorTargetState);
color_target.format = swap_chain_format;
color_target.blend = &blend;
color_target.writeMask = c.WGPUColorWriteMask_All;
var fragment = std.mem.zeroes(c.WGPUFragmentState);
fragment.module = fs_module;
fragment.entryPoint = "main";
fragment.targetCount = 1;
fragment.targets = &color_target;
var pipeline_descriptor = std.mem.zeroes(c.WGPURenderPipelineDescriptor);
pipeline_descriptor.fragment = &fragment;
// Other state
pipeline_descriptor.layout = null;
pipeline_descriptor.depthStencil = null;
pipeline_descriptor.vertex.module = vs_module;
pipeline_descriptor.vertex.entryPoint = "main";
pipeline_descriptor.vertex.bufferCount = 0;
pipeline_descriptor.vertex.buffers = null;
pipeline_descriptor.multisample.count = 1;
pipeline_descriptor.multisample.mask = 0xFFFFFFFF;
pipeline_descriptor.multisample.alphaToCoverageEnabled = false;
pipeline_descriptor.primitive.frontFace = c.WGPUFrontFace_CCW;
pipeline_descriptor.primitive.cullMode = c.WGPUCullMode_None;
pipeline_descriptor.primitive.topology = c.WGPUPrimitiveTopology_TriangleList;
pipeline_descriptor.primitive.stripIndexFormat = c.WGPUIndexFormat_Undefined;
const pipeline = c.wgpuDeviceCreateRenderPipeline(setup.device, &pipeline_descriptor);
c.wgpuShaderModuleRelease(vs_module);
c.wgpuShaderModuleRelease(fs_module);
while (!setup.window.shouldClose()) {
try frame(.{
.device = setup.device,
.swap_chain = swap_chain,
.pipeline = pipeline,
.queue = queue,
});
std.time.sleep(16000);
}
}
const FrameParams = struct {
device: c.WGPUDevice,
swap_chain: c.WGPUSwapChain,
pipeline: c.WGPURenderPipeline,
queue: c.WGPUQueue,
};
fn frame(params: FrameParams) !void {
const back_buffer_view = c.wgpuSwapChainGetCurrentTextureView(params.swap_chain);
var render_pass_info = std.mem.zeroes(c.WGPURenderPassDescriptor);
var color_attachment = std.mem.zeroes(c.WGPURenderPassColorAttachment);
color_attachment.view = back_buffer_view;
color_attachment.resolveTarget = null;
color_attachment.clearColor = c.WGPUColor{ .r = 0.0, .g = 0.0, .b = 0.0, .a = 0.0 };
color_attachment.loadOp = c.WGPULoadOp_Clear;
color_attachment.storeOp = c.WGPUStoreOp_Store;
render_pass_info.colorAttachmentCount = 1;
render_pass_info.colorAttachments = &color_attachment;
render_pass_info.depthStencilAttachment = null;
const encoder = c.wgpuDeviceCreateCommandEncoder(params.device, null);
const pass = c.wgpuCommandEncoderBeginRenderPass(encoder, &render_pass_info);
c.wgpuRenderPassEncoderSetPipeline(pass, params.pipeline);
c.wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
c.wgpuRenderPassEncoderEndPass(pass);
c.wgpuRenderPassEncoderRelease(pass);
const commands = c.wgpuCommandEncoderFinish(encoder, null);
c.wgpuCommandEncoderRelease(encoder);
c.wgpuQueueSubmit(params.queue, 1, &commands);
c.wgpuCommandBufferRelease(commands);
c.wgpuSwapChainPresent(params.swap_chain);
c.wgpuTextureViewRelease(back_buffer_view);
// if (cmdBufType == CmdBufType::Terrible) {
// bool c2sSuccess = c2sBuf->Flush();
// bool s2cSuccess = s2cBuf->Flush();
// ASSERT(c2sSuccess && s2cSuccess);
// }
try glfw.pollEvents();
} | gpu/src/dawn/hello_triangle.zig |
const std = @import("std");
const mem = std.mem;
const stdout = std.io.getStdOut();
const print = stdout.writer().print;
const pdump = @import("src/pdump.zig").pdump;
const Hasher = @import("src/swap.zig").Hasher;
// const Sha256 = std.crypto.hash.sha2.Sha256;
// We will simulate this by having 512 bytes of data, with the prefix
// at the start, and adding 4 bytes of data to be hashed at the end.
pub fn main() !void {
// The Sha256 run through all of the unchanging data.
const prefix = [4]u8{ 0, 0, 0, 0 };
var hseed = Hasher.init(&prefix);
var slow: u32 = 0;
var fast: u32 = update(&hseed, slow);
fast = update(&hseed, fast);
var steps: usize = 1;
while (true) : (steps += 1) {
// try print("slow: ", .{});
var slow2 = update(&hseed, slow);
if (slow2 == fast) {
try print("Collide1: {x} at {}\n", .{ slow2, steps });
try print("{x} and {x}\n", .{ slow, fast });
break;
}
// try print("fast: ", .{});
var fast2 = update(&hseed, fast);
if (slow2 == fast2) {
try print("Collide2: {x} at {}\n", .{ slow2, steps });
try print("{x} and {x}\n", .{ slow, fast });
break;
}
if (slow == fast2) {
try print("Collide2b: {x} at {}\n", .{ slow2, steps });
try print("{x} and {x}\n", .{ slow, fast });
break;
}
// try print("fast: ", .{});
var fast3 = update(&hseed, fast2);
// if (slow2 == fast3) {
// try print("Collide3: {x} at {}\n", .{ slow2, steps });
// try print("{x} and {x}\n", .{ slow, fast2 });
// break;
// }
slow = slow2;
fast = fast3;
if (steps % (1 << 20 - 1) == 0) {
try print("Steps: {}\n", .{steps});
}
}
}
// Generate a Sha256 hash in-process run through the prefix, and the
// first 512 bytes of data.
fn genHashStart() Hasher.T {
var result = Hasher.init(.{});
var buf: [512]u8 = undefined;
mem.set(u8, buf, 0);
buf[0] = 1; // Default prefix.
result.update(buf);
return result;
}
// Advance to the next hash.
fn update(hasher: *Hasher.T, value: u32) u32 {
// Copy the hash state, and compute the next hash.
var hh = hasher.*;
hh.update(mem.asBytes(&value));
var final: [Hasher.digest_length]u8 = undefined;
hh.final(&final);
var result: u32 = undefined;
mem.copy(u8, mem.asBytes(&result), final[0..4]);
// print("{x} -> {x}\n", .{ value, result }) catch {};
return result;
} | collide.zig |
const std = @import("std");
const Scanner = struct {
const Self = @This();
source_code: []const u8,
start: usize,
current: usize,
line: usize,
};
var scanner: Scanner = undefined;
pub const TokenTag = enum {
left_paren,
right_paren,
left_brace,
right_brace,
comma,
dot,
minus,
plus,
semicolon,
slash,
star,
bang,
bang_equal,
equal,
equal_equal,
greater,
greater_equal,
less,
less_equal,
identifier,
string,
number,
and_,
class,
else_,
false_,
for_,
fun,
if_,
nil,
or_,
print,
return_,
super,
this,
true_,
var_,
while_,
error_,
eof,
};
pub const Token = struct {
tag: TokenTag,
span: []const u8,
line: usize,
};
pub fn init(source_code: []const u8) void {
scanner.source_code = source_code;
scanner.start = 0;
scanner.current = 0;
scanner.line = 1;
}
pub fn nextToken() Token {
skipWhitespace();
scanner.start = scanner.current;
if (isAtEnd()) return makeToken(.eof);
var c = advance();
if (isAlpha(c)) return identifier();
if (isDigit(c)) return number();
switch (c) {
'(' => return makeToken(.left_paren),
')' => return makeToken(.right_paren),
'{' => return makeToken(.left_brace),
'}' => return makeToken(.right_brace),
';' => return makeToken(.semicolon),
',' => return makeToken(.comma),
'.' => return makeToken(.dot),
'-' => return makeToken(.minus),
'+' => return makeToken(.plus),
'/' => return makeToken(.slash),
'*' => return makeToken(.star),
'!' => return makeToken(if (match('=')) .bang_equal else .bang),
'>' => return makeToken(if (match('=')) .greater_equal else .greater),
'<' => return makeToken(if (match('=')) .less_equal else .less),
'=' => return makeToken(if (match('=')) .equal_equal else .equal),
'"' => return string(),
else => {},
}
return errorToken("Unexpected character.");
}
fn identifier() Token {
while (isAlpha(peek()) or isDigit(peek())) _ = advance();
return makeToken(identifierTag());
}
fn identifierTag() TokenTag {
const ident = scanner.source_code[scanner.start..scanner.current];
switch (ident[0]) {
'a' => return checkKeyword(ident[1..], "nd", .and_),
'c' => return checkKeyword(ident[1..], "lass", .class),
'e' => return checkKeyword(ident[1..], "lse", .else_),
'f' => {
if (ident.len > 1) {
switch (ident[1]) {
'a' => return checkKeyword(ident[2..], "lse", .false_),
'o' => return checkKeyword(ident[2..], "r", .for_),
'u' => return checkKeyword(ident[2..], "n", .fun),
else => {},
}
}
},
'i' => return checkKeyword(ident[1..], "f", .if_),
'n' => return checkKeyword(ident[1..], "il", .nil),
'o' => return checkKeyword(ident[1..], "r", .or_),
'p' => return checkKeyword(ident[1..], "rint", .print),
'r' => return checkKeyword(ident[1..], "eturn", .return_),
's' => return checkKeyword(ident[1..], "uper", .super),
't' => {
if (ident.len > 1) {
switch (ident[1]) {
'h' => return checkKeyword(ident[2..], "is", .this),
'r' => return checkKeyword(ident[2..], "ue", .true_),
else => {},
}
}
},
'v' => return checkKeyword(ident[1..], "ar", .var_),
'w' => return checkKeyword(ident[1..], "hile", .while_),
else => {},
}
return .identifier;
}
fn checkKeyword(rest: []const u8, target: []const u8, tag: TokenTag) TokenTag {
if (std.mem.eql(u8, rest, target)) {
return tag;
} else {
return .identifier;
}
}
fn number() Token {
while (isDigit(peek())) _ = advance();
const next = peek();
if (next != null and next.? == '.' and isDigit(peekNext())) {
// Consume the '.'
_ = advance();
while (isDigit(peek())) _ = advance();
}
return makeToken(.number);
}
fn string() Token {
var next = peek();
while (next != null and next.? != '"') : (next = peek()) {
if (next.? == '\n') scanner.line += 1;
_ = advance();
}
if (next == null) return errorToken("Undetermined string literal.");
// Consume closing quote
_ = advance();
return makeToken(.string);
}
fn advance() u8 {
const result = scanner.source_code[scanner.current];
scanner.current += 1;
return result;
}
fn match(expected: u8) bool {
if (isAtEnd()) return false;
if (scanner.source_code[scanner.current] != expected) return false;
scanner.current += 1;
return true;
}
fn peek() ?u8 {
if (isAtEnd()) return null;
return scanner.source_code[scanner.current];
}
fn peekNext() ?u8 {
if (scanner.current + 1 >= scanner.source_code.len) return null;
return scanner.source_code[scanner.current + 1];
}
fn isAtEnd() bool {
return scanner.current >= scanner.source_code.len;
}
fn makeToken(tag: TokenTag) Token {
return Token{
.tag = tag,
.span = scanner.source_code[scanner.start..scanner.current],
.line = scanner.line,
};
}
fn errorToken(message: []const u8) Token {
return Token{
.tag = .error_,
.span = message,
.line = scanner.line,
};
}
fn skipWhitespace() void {
while (true) {
var c = peek();
if (c == null) return;
switch (c.?) {
' ', '\r', '\t' => _ = advance(),
'\n' => {
scanner.line += 1;
_ = advance();
},
'/' => {
if (peekNext() != null and peekNext().? == '/') {
while (peek() != null and peek().? != '\n') _ = advance();
} else {
return;
}
},
else => return,
}
}
}
fn isDigit(c: ?u8) bool {
return c != null and c.? >= '0' and c.? <= '9';
}
fn isAlpha(c: ?u8) bool {
return c != null and ((c.? >= 'a' and c.? <= 'z') or
(c.? >= 'A' and c.? <= 'Z') or
c.? == '_');
} | src/scanner.zig |
const sg = @import("sokol").gfx;
const sapp = @import("sokol").app;
const sgapp = @import("sokol").app_gfx_glue;
const stm = @import("sokol").time;
const saudio = @import("sokol").audio;
const assert = @import("std").debug.assert;
const math = @import("std").math;
// debugging and config options
const AudioVolume = 0.5;
const DbgSkipIntro = false; // set to true to skip intro gamestate
const DbgSkipPrelude = false; // set to true to skip prelude at start of gameloop
const DbgStartRound = 0; // set to any starting round <= 255
const DbgShowMarkers = false; // set to true to display debug markers
const DbgEscape = false; // set to true to end game round with Escape
const DbgDoubleSpeed = false; // set to true to speed up game
const DbgGodMode = false; // set to true to make Pacman invulnerable
// misc constants
const TickDurationNS = if (DbgDoubleSpeed) 8_333_333 else 16_666_667;
const MaxFrameTimeNS = 33_333_333.0; // max duration of a frame in nanoseconds
const TickToleranceNS = 1_000_000; // max time tolerance of a game tick in nanoseconds
const FadeTicks = 30; // fade in/out duration in game ticks
const NumDebugMarkers = 16;
const NumLives = 3;
const NumGhosts = 4;
const NumDots = 244;
const NumPills = 4;
const AntePortasX = 14*TileWidth; // x/y position of ghost hour entry
const AntePortasY = 14*TileHeight + TileHeight/2;
const FruitActiveTicks = 10 * 60; // number of ticks the bonus fruit is shown
const GhostEatenFreezeTicks = 60; // number of ticks the game freezes after Pacman eats a ghost
const PacmanEatenTicks = 60; // number of ticks the game freezes after Pacman gets eaten
const PacmanDeathTicks = 150; // number of ticks to show the Pacman death sequence before starting a new round
const GameOverTicks = 3*60; // number of ticks to show the Game Over message
const RoundWonTicks = 4*60; // number of ticks to wait after a round was won
// rendering system constants
const TileWidth = 8; // width/height of a background tile in pixels
const TileHeight = 8;
const SpriteWidth = 16; // width/height of a sprite in pixels
const SpriteHeight = 16;
const DisplayTilesX = 28; // display width/height in number of tiles
const DisplayTilesY = 36;
const DisplayPixelsX = DisplayTilesX * TileWidth;
const DisplayPixelsY = DisplayTilesY * TileHeight;
const TileTextureWidth = 256 * TileWidth;
const TileTextureHeight = TileHeight + SpriteHeight;
const NumSprites = 8;
const MaxVertices = ((DisplayTilesX*DisplayTilesY) + NumSprites + NumDebugMarkers) * 6;
// sound system constants
const NumVoices = 3;
const NumSounds = 3;
const NumSamples = 128;
// common tile codes
const TileCodeSpace = 0x40;
const TileCodeDot = 0x10;
const TileCodePill = 0x14;
const TileCodeGhost = 0xB0;
const TileCodeLife = 0x20; // 0x20..0x23
const TileCodeCherries = 0x90; // 0x90..0x93
const TileCodeStrawberry = 0x94; // 0x94..0x97
const TileCodePeach = 0x98; // 0x98..0x9B
const TileCodeBell = 0x9C; // 0x9C..0x9F
const TileCodeApple = 0xA0; // 0xA0..0xA3
const TileCodeGrapes = 0xA4; // 0xA4..0xA7
const TileCodeGalaxian = 0xA8; // 0xA8..0xAB
const TileCodeKey = 0xAC; // 0xAC..0xAF
const TileCodeDoor = 0xCF; // the ghost-house door
// common sprite tile codes
const SpriteCodeInvisible = 30;
const SpriteCodeScore200 = 40;
const SpriteCodeScore400 = 41;
const SpriteCodeScore800 = 42;
const SpriteCodeScore1600 = 43;
const SpriteCodeCherries = 0;
const SpriteCodeStrawberry = 1;
const SpriteCodePeach = 2;
const SpriteCodeBell = 3;
const SpriteCodeApple = 4;
const SpriteCodeGrapes = 5;
const SpriteCodeGalaxian = 6;
const SpriteCodeKey = 7;
const SpriteCodePacmanClosedMouth = 48;
// common color codes
const ColorCodeBlank = 0x00;
const ColorCodeDefault = 0x0F;
const ColorCodeDot = 0x10;
const ColorCodePacman = 0x09;
const ColorCodeBlinky = 0x01;
const ColorCodePinky = 0x03;
const ColorCodeInky = 0x05;
const ColorCodeClyde = 0x07;
const ColorCodeFrightened = 0x11;
const ColorCodeFrightenedBlinking = 0x12;
const ColorCodeGhostScore = 0x18;
const ColorCodeEyes = 0x19;
const ColorCodeCherries = 0x14;
const ColorCodeStrawberry = 0x0F;
const ColorCodePeach = 0x15;
const ColorCodeBell = 0x16;
const ColorCodeApple = 0x14;
const ColorCodeGrapes = 0x17;
const ColorCodeGalaxian = 0x09;
const ColorCodeKey = 0x16;
const ColorCodeWhiteBorder = 0x1F;
const ColorCodeFruitScore = 0x03;
// flags for Game.freeze
const FreezePrelude: u8 = (1<<0);
const FreezeReady: u8 = (1<<1);
const FreezeEatGhost: u8 = (1<<2);
const FreezeDead: u8 = (1<<3);
const FreezeWon: u8 = (1<<4);
// a 2D vector for pixel- and tile-coordinates
const ivec2 = @Vector(2,i16);
// the game can be either in intro- or game-mode
const GameMode = enum {
Intro,
Game,
};
// movement directions
const Dir = enum(u8) {
Right,
Down,
Left,
Up,
};
// bonus fruit types
const Fruit = enum {
None,
Cherries,
Strawberry,
Peach,
Apple,
Grapes,
Galaxian,
Bell,
Key,
};
// the four ghost types
const GhostType = enum(u8) {
Blinky,
Pinky,
Inky,
Clyde,
};
// the AI state a ghost is currently in
const GhostState = enum {
None,
Chase, // currently chasing Pacman
Scatter, // currently heading towards the corner scatter targets
Frightened, // frightened after Pacman has eaten an energizer pill
Eyes, // eaten by Pacman and heading back to the ghost house
House, // currently inside the ghost house
LeaveHouse, // currently leaving the ghost house
EnterHouse, // currently entering the ghost house
};
// common ghost and Pacman state
const Actor = struct {
dir: Dir = .Right,
pos: ivec2 = ivec2{0,0},
anim_tick: u32 = 0,
};
// Ghost state
const Ghost = struct {
actor: Actor = .{},
type: GhostType = .Blinky,
next_dir: Dir = .Right,
target_pos: ivec2 = ivec2{0,0},
state: GhostState = .None,
frightened: Trigger = .{},
eaten: Trigger = .{},
dot_counter: u16 = 0,
dot_limit: u16 = 0,
};
// Pacman state
const Pacman = struct {
actor: Actor = .{},
};
// a time trigger holds a tick at which to start an action
const Trigger = struct {
const DisabledTicks = 0xFF_FF_FF_FF;
tick: u32 = DisabledTicks,
};
// a 'hardware sprite' struct
const Sprite = struct {
enabled: bool = false,
tile: u8 = 0,
color: u8 = 0,
flipx: bool = false,
flipy: bool = false,
pos: ivec2 = ivec2{0,0},
};
// a 'debug marker' for visualizing ghost targets
const DebugMarker = struct {
enabled: bool = false,
tile: u8 = 0,
color: u8 = 0,
tile_pos: ivec2 = ivec2{0,0},
};
// vertex-structure for rendering background tiles and sprites
const Vertex = packed struct {
x: f32, y: f32, // 2D-pos
u: f32, v: f32, // texcoords
attr: u32, // color code and opacity
};
// callback function signature for procedural sounds
const SoundFunc = fn(usize) void;
// a sound effect description
const SoundDesc = struct {
func: ?SoundFunc = null, // optional pointer to sound effect callback if this is a procedural sound
dump: ?[]const u32 = null, // optional register dump data slice
voice: [NumVoices]bool = [_]bool{false} ** NumVoices,
};
// a sound 'hardware voice' (of a Namco WSG emulation)
const Voice = struct {
counter: u20 = 0, // a 20-bit wrap around frequency counter
frequency: u20 = 0, // a 20-bit frequency
waveform: u3 = 0, // a 3-bit waveform index into wavetable ROM dump
volume: u4 = 0, // a 4-bit volume
sample_acc: f32 = 0.0,
sample_div: f32 = 0.0,
};
// a sound effect struct
const Sound = struct {
cur_tick: u32 = 0, // current 60Hz tick counter
func: ?SoundFunc = null, // optional callback for procedural sounds
dump: ?[]const u32 = null, // optional register dump data
num_ticks: u32 = 0, // sound effect length in ticks (only for register dump sounds)
stride: u32 = 0, // register data stride for multivoice dumps (1,2 or 3)
voice: [NumVoices]bool = [_]bool{false} ** NumVoices,
};
// all mutable state is in a single nested global
const State = struct {
game_mode: GameMode = .Intro,
timing: struct {
tick: u32 = 0,
laptime_store: u64 = 0,
tick_accum: i32 = 0,
} = .{},
input: struct {
enabled: bool = false,
up: bool = false,
down: bool = false,
left: bool = false,
right: bool = false,
esc: bool = false,
anykey: bool = false,
} = .{},
intro: struct {
started: Trigger = .{},
} = .{},
game: struct {
pacman: Pacman = .{},
ghosts: [NumGhosts]Ghost = [_]Ghost{.{}} ** NumGhosts,
xorshift: u32 = 0x12345678, // xorshift random-number-generator state
score: u32 = 0,
hiscore: u32 = 0,
num_lives: u8 = 0,
round: u8 = 0,
freeze: u8 = 0, // combination of Freeze* flags
num_dots_eaten: u8 = 0,
num_ghosts_eaten: u8 = 0,
active_fruit: Fruit = .None,
global_dot_counter_active: bool = false,
global_dot_counter: u16 = 0,
started: Trigger = .{},
ready_started: Trigger = .{},
round_started: Trigger = .{},
round_won: Trigger = .{},
game_over: Trigger = .{},
dot_eaten: Trigger = .{},
pill_eaten: Trigger = .{},
ghost_eaten: Trigger = .{},
pacman_eaten: Trigger = .{},
fruit_eaten: Trigger = .{},
force_leave_house: Trigger = .{},
fruit_active: Trigger = .{},
} = .{},
audio: struct {
voices: [NumVoices]Voice = [_]Voice{.{}} ** NumVoices,
sounds: [NumSounds]Sound = [_]Sound{.{}} ** NumSounds,
voice_tick_accum: i32 = 0,
voice_tick_period: i32 = 0,
sample_duration_ns: i32 = 0,
sample_accum: i32 = 0,
num_samples: u32 = 0,
// sample_buffer is separate in UndefinedData
} = .{},
gfx: struct {
// fade in/out
fadein: Trigger = .{},
fadeout: Trigger = .{},
fade: u8 = 0xFF,
// 'hardware sprites' (meh, array default initialization sure looks awkward...)
sprites: [NumSprites]Sprite = [_]Sprite{.{}} ** NumSprites,
debug_markers: [NumDebugMarkers]DebugMarker = [_]DebugMarker{.{}} ** NumDebugMarkers,
// number of valid vertices in data.vertices
num_vertices: u32 = 0,
// sokol-gfx objects
pass_action: sg.PassAction = .{},
offscreen: struct {
vbuf: sg.Buffer = .{},
tile_img: sg.Image = .{},
palette_img: sg.Image = .{},
render_target: sg.Image = .{},
pip: sg.Pipeline = .{},
pass: sg.Pass = .{},
bind: sg.Bindings = .{},
} = .{},
display: struct {
quad_vbuf: sg.Buffer = .{},
pip: sg.Pipeline = .{},
bind: sg.Bindings = .{},
} = .{},
} = .{},
};
var state: State = .{};
// keep the big undefined data out of the state struct, mixing initialized
// and uninitialized data bloats the executable size
const UndefinedData = struct {
tile_ram: [DisplayTilesY][DisplayTilesX]u8 = undefined,
color_ram: [DisplayTilesY][DisplayTilesX]u8 = undefined,
vertices: [MaxVertices]Vertex = undefined,
tile_pixels: [TileTextureHeight][TileTextureWidth]u8 = undefined,
color_palette: [256]u32 = undefined,
sample_buffer: [NumSamples]f32 = undefined,
};
var data: UndefinedData = .{};
// level specifications
const LevelSpec = struct {
bonus_fruit: Fruit,
bonus_score: u32,
fright_ticks: u32,
};
const MaxLevelSpec = 21;
const LevelSpecTable = [MaxLevelSpec]LevelSpec {
.{ .bonus_fruit=.Cherries, .bonus_score=10, .fright_ticks=6*60 },
.{ .bonus_fruit=.Strawberry, .bonus_score=30, .fright_ticks=5*60, },
.{ .bonus_fruit=.Peach, .bonus_score=50, .fright_ticks=4*60, },
.{ .bonus_fruit=.Peach, .bonus_score=50, .fright_ticks=3*60, },
.{ .bonus_fruit=.Apple, .bonus_score=70, .fright_ticks=2*60, },
.{ .bonus_fruit=.Apple, .bonus_score=70, .fright_ticks=5*60, },
.{ .bonus_fruit=.Grapes, .bonus_score=100, .fright_ticks=2*60, },
.{ .bonus_fruit=.Grapes, .bonus_score=100, .fright_ticks=2*60, },
.{ .bonus_fruit=.Galaxian, .bonus_score=200, .fright_ticks=1*60, },
.{ .bonus_fruit=.Galaxian, .bonus_score=200, .fright_ticks=5*60, },
.{ .bonus_fruit=.Bell, .bonus_score=300, .fright_ticks=2*60, },
.{ .bonus_fruit=.Bell, .bonus_score=300, .fright_ticks=1*60, },
.{ .bonus_fruit=.Key, .bonus_score=500, .fright_ticks=1*60, },
.{ .bonus_fruit=.Key, .bonus_score=500, .fright_ticks=3*60, },
.{ .bonus_fruit=.Key, .bonus_score=500, .fright_ticks=1*60, },
.{ .bonus_fruit=.Key, .bonus_score=500, .fright_ticks=1*60, },
.{ .bonus_fruit=.Key, .bonus_score=500, .fright_ticks=1, },
.{ .bonus_fruit=.Key, .bonus_score=500, .fright_ticks=1*60, },
.{ .bonus_fruit=.Key, .bonus_score=500, .fright_ticks=1, },
.{ .bonus_fruit=.Key, .bonus_score=500, .fright_ticks=1, },
.{ .bonus_fruit=.Key, .bonus_score=500, .fright_ticks=1, },
};
//--- grab bag of helper functions ---------------------------------------------
// a xorshift random number generator
fn xorshift32() u32 {
var x = state.game.xorshift;
x ^= x<<13;
x ^= x>>17;
x ^= x<<5;
state.game.xorshift = x;
return x;
}
// test if two ivec2 are equal
fn equal(v0: ivec2, v1: ivec2) bool {
return (v0[0] == v1[0]) and (v0[1] == v1[1]);
}
// test if two ivec2 are nearly equal
fn nearEqual(v0: ivec2, v1: ivec2, tolerance: i16) bool {
const d = v1 - v0;
// use our own sloppy abs(), math.absInt() can return a runtime error
const a: ivec2 = .{
if (d[0] < 0) -d[0] else d[0],
if (d[1] < 0) -d[1] else d[1]
};
return (a[0] <= tolerance) and (a[1] <= tolerance);
}
// squared distance between two ivec2
fn squaredDistance(v0: ivec2, v1: ivec2) i16 {
const d = v1 - v0;
return d[0]*d[0] + d[1]*d[1];
}
// return the pixel difference from a pixel position to the next tile midpoint
fn distToTileMid(pixel_pos: ivec2) ivec2 {
return .{ TileWidth/2 - @mod(pixel_pos[0], TileWidth), TileHeight/2 - @mod(pixel_pos[1], TileHeight) };
}
// convert a pixel position into a tile position
fn pixelToTilePos(pixel_pos: ivec2) ivec2 {
return .{ @divTrunc(pixel_pos[0], TileWidth), @divTrunc(pixel_pos[1], TileHeight) };
}
// return true if a tile position is valid (inside visible area)
fn validTilePos(tile_pos: ivec2) bool {
return (tile_pos[0] >= 0) and (tile_pos[0] < DisplayTilesX) and (tile_pos[1] >= 0) and (tile_pos[1] < DisplayTilesY);
}
// return tile pos clamped to playfield borders
fn clampedTilePos(tile_pos: ivec2) ivec2 {
return .{
math.clamp(tile_pos[0], 0, DisplayTilesX-1),
math.clamp(tile_pos[1], 3, DisplayTilesY-3)
};
}
// set time trigger to next tick
fn start(t: *Trigger) void {
t.tick = state.timing.tick + 1;
}
// set time trigger to a future tick
fn startAfter(t: *Trigger, ticks: u32) void {
t.tick = state.timing.tick + ticks;
}
// disable a trigger
fn disable(t: *Trigger) void {
t.tick = Trigger.DisabledTicks;
}
// check if trigger is triggered in current game tick
fn now(t: Trigger) bool {
return t.tick == state.timing.tick;
}
// return number of ticks since a time trigger was triggered
fn since(t: Trigger) u32 {
if (state.timing.tick >= t.tick) {
return state.timing.tick - t.tick;
}
else {
return Trigger.DisabledTicks;
}
}
// check if a time trigger is between begin and end tick
fn between(t: Trigger, begin: u32, end: u32) bool {
assert(begin < end);
if (t.tick != Trigger.DisabledTicks) {
const ticks = since(t);
return (ticks >= begin) and (ticks < end);
}
else {
return false;
}
}
// check if a time trigger was triggered exactly N ticks ago
fn afterOnce(t: Trigger, ticks: u32) bool {
return since(t) == ticks;
}
// check if a time trigger was triggered more than N ticks ago
fn after(t: Trigger, ticks: u32) bool {
const s = since(t);
if (s != Trigger.DisabledTicks) {
return s >= ticks;
}
else {
return false;
}
}
// same as between(t, 0, ticks)
fn before(t: Trigger, ticks: u32) bool {
const s = since(t);
if (s != Trigger.DisabledTicks) {
return s < ticks;
}
else {
return false;
}
}
// enable/disable input
fn inputEnable() void {
state.input.enabled = true;
}
fn inputDisable() void {
state.input = .{};
}
// get current input state as movement direction
fn inputDir(default_dir: Dir) Dir {
if (state.input.enabled) {
if (state.input.up) { return .Up; }
else if (state.input.down) { return .Down; }
else if (state.input.left) { return .Left; }
else if (state.input.right) { return .Right; }
}
return default_dir;
}
// return opposite direction
fn reverseDir(dir: Dir) Dir {
return switch (dir) {
.Right => .Left,
.Down => .Up,
.Left => .Right,
.Up => .Down,
};
}
// return a vector for a given direction
fn dirToVec(dir: Dir) ivec2 {
return switch (dir) {
.Right => .{ 1, 0 },
.Down => .{ 0, 1 },
.Left => .{ -1, 0 },
.Up => .{ 0, -1 }
};
}
// return the tile code for a fruit
fn fruitTileCode(fruit: Fruit) u8 {
return switch (fruit) {
.None => TileCodeSpace,
.Cherries => TileCodeCherries,
.Strawberry => TileCodeStrawberry,
.Peach => TileCodePeach,
.Apple => TileCodeApple,
.Grapes => TileCodeGrapes,
.Galaxian => TileCodeGalaxian,
.Bell => TileCodeBell,
.Key => TileCodeKey,
};
}
// return the color code for a fruit
fn fruitColorCode(fruit: Fruit) u8 {
return switch (fruit) {
.None => ColorCodeBlank,
.Cherries => ColorCodeCherries,
.Strawberry => ColorCodeStrawberry,
.Peach => ColorCodePeach,
.Apple => ColorCodeApple,
.Grapes => ColorCodeGrapes,
.Galaxian => ColorCodeGalaxian,
.Bell => ColorCodeBell,
.Key => ColorCodeKey,
};
}
// return the sprite tile code for a fruit
fn fruitSpriteCode(fruit: Fruit) u8 {
return switch (fruit) {
.None => SpriteCodeInvisible,
.Cherries => SpriteCodeCherries,
.Strawberry => SpriteCodeStrawberry,
.Peach => SpriteCodePeach,
.Apple => SpriteCodeApple,
.Grapes => SpriteCodeGrapes,
.Galaxian => SpriteCodeGalaxian,
.Bell => SpriteCodeBell,
.Key => SpriteCodeKey,
};
}
// convert an actor pos (origin at center) to a sprite pos (origin at topleft)
fn actorToSpritePos(actorPos: ivec2) ivec2 {
return .{ actorPos[0] - SpriteWidth/2, actorPos[1] - SpriteHeight/2 };
}
// get pointer to ghost by type
fn ghostPtr(t: GhostType) *Ghost {
return &state.game.ghosts[@enumToInt(t)];
}
// shortcut: get pointers to ghosts by name
fn blinky() *Ghost {
return ghostPtr(.Blinky);
}
fn pinky() *Ghost {
return ghostPtr(.Pinky);
}
fn inky() *Ghost {
return ghostPtr(.Inky);
}
fn clyde() *Ghost {
return ghostPtr(.Clyde);
}
// target position (pixels) when heading back to ghost house
// (same as startingPos except Blinky's)
fn ghostHouseTargetPos(t: GhostType) ivec2 {
return switch (t) {
.Blinky => .{ 14*8, 17*8 + 4 },
.Pinky => .{ 14*8, 17*8 + 4 },
.Inky => .{ 12*8, 17*8 + 4 },
.Clyde => .{ 16*8, 17*8 + 4 },
};
}
// ghost scatter target positions in tile coords
fn scatterTargetPos(t: GhostType) ivec2 {
return switch (t) {
.Blinky => .{ 25, 0 },
.Pinky => .{ 2, 0 },
.Inky => .{ 27, 34 },
.Clyde => .{ 0, 34 },
};
}
// get level spec for the current game round
fn levelSpec(round: u32) LevelSpec {
var i = round;
if (i >= MaxLevelSpec) {
i = MaxLevelSpec - 1;
}
return LevelSpecTable[i];
}
// check if a tile position is blocking (wall or ghost house door)
fn isBlockingTile(tile_pos: ivec2) bool {
return gfxTileAt(tile_pos) >= 0xC0;
}
// check if a tile position contains a dot
fn isDot(tile_pos: ivec2) bool {
return gfxTileAt(tile_pos) == TileCodeDot;
}
// check if a tile position contains an energizer pill
fn isPill(tile_pos: ivec2) bool {
return gfxTileAt(tile_pos) == TileCodePill;
}
// check if a tile position is inside the teleport tunnel
fn isTunnel(tile_pos: ivec2) bool {
return (tile_pos[1] == 17) and ((tile_pos[0] <= 5) or (tile_pos[0] >= 22));
}
// check if a tile position is inside one of the two "red zones" where
// ghost are not allowed to move upward
fn isRedZone(tile_pos: ivec2) bool {
return (tile_pos[0] >= 11) and (tile_pos[0] <= 16) and ((tile_pos[1] ==14) or (tile_pos[1] == 26));
}
// test if movement from a pixel position to a wanted position is possible,
// allow_cornering is Pacman's feature to take a diagonal shortcut around corners
fn canMove(pixel_pos: ivec2, wanted_dir: Dir, allow_cornering: bool) bool {
const dist_mid = distToTileMid(pixel_pos);
const dir_vec = dirToVec(wanted_dir);
// distance to midpoint in move direction and perpendicular direction
const move_dist_mid = if (dir_vec[1] != 0) dist_mid[1] else dist_mid[0];
const perp_dist_mid = if (dir_vec[1] != 0) dist_mid[0] else dist_mid[1];
// look one tile ahead in movement direction
const tile_pos = pixelToTilePos(pixel_pos);
const check_pos = clampedTilePos(tile_pos + dir_vec);
const is_blocked = isBlockingTile(check_pos);
if ((!allow_cornering and (0 != perp_dist_mid)) or (is_blocked and (0 == move_dist_mid))) {
// way is blocked
return false;
}
else {
// way is free
return true;
}
}
// compute a new pixel position along a direction (without blocking check)
fn move(pixel_pos: ivec2, dir: Dir, allow_cornering: bool) ivec2 {
const dir_vec = dirToVec(dir);
var pos = pixel_pos + dir_vec;
// if cornering allowed, drag the position towards the center-line
if (allow_cornering) {
const dist_mid = distToTileMid(pos);
if (dir_vec[0] != 0) {
if (dist_mid[1] < 0) { pos[1] -= 1; }
else if (dist_mid[1] > 0) { pos[1] += 1; }
}
else if (dir_vec[1] != 0) {
if (dist_mid[0] < 0) { pos[0] -= 1; }
else if (dist_mid[0] > 0) { pos[0] += 1; }
}
}
// wrap x position around (only possible inside teleport tunnel)
if (pos[0] < 0) {
pos[0] = DisplayPixelsX - 1;
}
else if (pos[0] >= DisplayPixelsX) {
pos[0] = 0;
}
return pos;
}
// shortcuts to get sprite pointers by name
fn spritePacman() *Sprite {
return &state.gfx.sprites[0];
}
fn spriteGhost(ghost_type: GhostType) *Sprite {
return &state.gfx.sprites[@enumToInt(ghost_type) + 1];
}
fn spriteBlinky() *Sprite {
return &state.gfx.sprites[1];
}
fn spritePinky() *Sprite {
return &state.gfx.sprites[2];
}
fn spriteInky() *Sprite {
return &state.gfx.sprites[3];
}
fn spriteClyde() *Sprite {
return &state.gfx.sprites[4];
}
fn spriteFruit() *Sprite {
return &state.gfx.sprites[5];
}
// set sprite image to animated pacman
fn spriteImagePacman(dir: Dir, tick: u32) void {
const tiles = [2][4]u8 {
[_]u8 { 44, 46, 48, 46 }, // horizontal (needs flipx)
[_]u8 { 45, 47, 48, 47 } // vertical (needs flipy)
};
const phase = (tick / 4) & 3;
var spr = spritePacman();
spr.enabled = true;
spr.tile = tiles[@enumToInt(dir) & 1][phase];
spr.color = ColorCodePacman;
spr.flipx = (dir == .Left);
spr.flipy = (dir == .Up);
}
// set sprite image to Pacman death sequence
fn spriteImagePacmanDeath(tick: u32) void {
// the death animation tile sequence starts at sprite tile number 52 and ends at 63
const tile: u32 = math.clamp(52 + (tick / 8), 0, 63);
var spr = spritePacman();
spr.tile = @intCast(u8, tile);
spr.flipx = false;
spr.flipy = false;
}
// set sprite image to animated ghost
fn spriteImageGhost(ghost_type: GhostType, dir: Dir, tick: u32) void {
const tiles = [4][2]u8 {
[_]u8 { 32, 33 }, // right
[_]u8 { 34, 35 }, // down
[_]u8 { 36, 37 }, // left
[_]u8 { 38, 39 }, // up
};
const phase = (tick / 8) & 1;
var spr = spriteGhost(ghost_type);
spr.tile = tiles[@enumToInt(dir)][phase];
spr.color = ColorCodeBlinky + @enumToInt(ghost_type)*2;
}
// set sprite image to frightened ghost
fn spriteImageGhostFrightened(ghost_type: GhostType, tick: u32, blinking_tick: u32) void {
const tiles = [2]u8 { 28, 29 };
const phase = (tick / 4) & 1;
var spr = spriteGhost(ghost_type);
spr.tile = tiles[phase];
if (tick > blinking_tick) {
// towards end of frightened period, start blinking
spr.color = if (0 != (tick & 0x10)) ColorCodeFrightened else ColorCodeFrightenedBlinking;
}
else {
spr.color = ColorCodeFrightened;
}
}
// set sprite to ghost eyes, these are the normal ghost sprite
// images but with a different color code which makes
// only the eyes visible
fn spriteImageGhostEyes(ghost_type: GhostType, dir: Dir) void {
const tiles = [4]u8 { 32, 34, 36, 38 };
var spr = spriteGhost(ghost_type);
spr.tile = tiles[@enumToInt(dir)];
spr.color = ColorCodeEyes;
}
//--- gameplay system ----------------------------------------------------------
// the central game tick function, called at 60Hz
fn gameTick() void {
// initialize game-state once
if (now(state.game.started)) {
// debug: skip predule
const prelude_ticks_per_sec = if (DbgSkipPrelude) 1 else 60;
start(&state.gfx.fadein);
startAfter(&state.game.ready_started, 2*prelude_ticks_per_sec);
soundPrelude();
gameInit();
}
// initialize new round (after eating all dots or losing a life)
if (now(state.game.ready_started)) {
gameRoundInit();
// after 2 seconds, start the interactive game loop
startAfter(&state.game.round_started, 2*60 + 10);
}
if (now(state.game.round_started)) {
state.game.freeze &= ~FreezeReady;
// clear the READY! message
gfxColorText(.{11,20}, ColorCodeDot, " ");
soundWeeooh();
}
// activate/deactivate bonus fruit
if (now(state.game.fruit_active)) {
state.game.active_fruit = levelSpec(state.game.round).bonus_fruit;
}
else if (afterOnce(state.game.fruit_active, FruitActiveTicks)) {
state.game.active_fruit = .None;
}
// stop frightened sound and start weeooh sound
if (afterOnce(state.game.pill_eaten, levelSpec(state.game.round).fright_ticks)) {
soundWeeooh();
}
// if game is frozen because Pacman ate a ghost, unfreeze after a while
if (0 != (state.game.freeze & FreezeEatGhost)) {
if (afterOnce(state.game.ghost_eaten, GhostEatenFreezeTicks)) {
state.game.freeze &= ~FreezeEatGhost;
}
}
// play pacman-death sound
if (afterOnce(state.game.pacman_eaten, PacmanEatenTicks)) {
soundDead();
}
// update Pacman and ghost state
if (0 == state.game.freeze) {
gameUpdateActors();
}
// update the dynamic background tiles and sprite images
gameUpdateTiles();
gameUpdateSprites();
// update hiscore if broken
if (state.game.score > state.game.hiscore) {
state.game.hiscore = state.game.score;
}
// check for end-round condition
if (now(state.game.round_won)) {
state.game.freeze |= FreezeWon;
startAfter(&state.game.ready_started, RoundWonTicks);
}
if (now(state.game.game_over)) {
gfxColorText(.{9,20}, 1, "GAME OVER");
inputDisable();
startAfter(&state.gfx.fadeout, GameOverTicks);
startAfter(&state.intro.started, GameOverTicks + FadeTicks);
}
if (DbgEscape) {
if (state.input.esc) {
inputDisable();
start(&state.gfx.fadeout);
startAfter(&state.intro.started, FadeTicks);
}
}
// render debug markers (current ghost targets)
if (DbgShowMarkers) {
for (state.game.ghosts) |*ghost, i| {
const tile: u8 = switch (ghost.state) {
.None => 'N',
.Chase => 'C',
.Scatter => 'S',
.Frightened => 'F',
.Eyes => 'E',
.House => 'H',
.LeaveHouse => 'L',
.EnterHouse => 'E',
};
state.gfx.debug_markers[i] = .{
.enabled = true,
.tile = tile,
.color = @intCast(u8, ColorCodeBlinky + 2*i),
.tile_pos = clampedTilePos(ghost.target_pos)
};
}
}
}
// the central Pacman- and ghost-behaviour function, called once per game tick
fn gameUpdateActors() void {
// Pacman "AI"
if (gamePacmanShouldMove()) {
var actor = &state.game.pacman.actor;
const wanted_dir = inputDir(actor.dir);
const allow_cornering = true;
// look ahead to check if wanted direction is blocked
if (canMove(actor.pos, wanted_dir, allow_cornering)) {
actor.dir = wanted_dir;
}
// move into the selected direction
if (canMove(actor.pos, actor.dir, allow_cornering)) {
actor.pos = move(actor.pos, actor.dir, allow_cornering);
actor.anim_tick += 1;
}
// eat dot or energizer pill?
const pacman_tile_pos = pixelToTilePos(actor.pos);
if (isDot(pacman_tile_pos)) {
gfxTile(pacman_tile_pos, TileCodeSpace);
state.game.score += 1;
start(&state.game.dot_eaten);
start(&state.game.force_leave_house);
gameUpdateDotsEaten();
gameUpdateGhostHouseDotCounters();
}
if (isPill(pacman_tile_pos)) {
gfxTile(pacman_tile_pos, TileCodeSpace);
state.game.score += 5;
start(&state.game.pill_eaten);
state.game.num_ghosts_eaten = 0;
for (state.game.ghosts) |*ghost| {
start(&ghost.frightened);
}
gameUpdateDotsEaten();
soundFrightened();
}
// check if Pacman eats the bonus fruit
if (state.game.active_fruit != .None) {
const test_pos = pixelToTilePos(actor.pos + ivec2{TileWidth/2,0});
if (equal(test_pos, .{14,20})) {
start(&state.game.fruit_eaten);
state.game.score += levelSpec(state.game.round).bonus_score;
gfxFruitScore(state.game.active_fruit);
state.game.active_fruit = .None;
soundEatFruit();
}
}
// check if Pacman collides with a ghost
for (state.game.ghosts) |*ghost| {
const ghost_tile_pos = pixelToTilePos(ghost.actor.pos);
if (equal(ghost_tile_pos, pacman_tile_pos)) {
switch (ghost.state) {
.Frightened => {
// Pacman eats ghost
ghost.state = .Eyes;
start(&ghost.eaten);
start(&state.game.ghost_eaten);
state.game.num_ghosts_eaten += 1;
// increase score by 20, 40, 80, 160
// FIXME Zig: "10 * (1 << state.game.num_ghosts_eaten)" is quite awkward in Zig
state.game.score += 10 * math.pow(u32, 2, state.game.num_ghosts_eaten);
state.game.freeze |= FreezeEatGhost;
soundEatGhost();
},
.Chase, .Scatter => {
// ghost eats Pacman
if (!DbgGodMode) {
soundClear();
start(&state.game.pacman_eaten);
state.game.freeze |= FreezeDead;
// if Pacman has any lives left, start a new round, otherwise start the game over sequence
if (state.game.num_lives > 0) {
startAfter(&state.game.ready_started, PacmanEatenTicks + PacmanDeathTicks);
}
else {
startAfter(&state.game.game_over, PacmanEatenTicks + PacmanDeathTicks);
}
}
},
else => {}
}
}
}
}
// ghost AIs
for (state.game.ghosts) |*ghost| {
// handle ghost state transitions
gameUpdateGhostState(ghost);
// update the ghosts target position
gameUpdateGhostTarget(ghost);
// finally, move the ghost towards its target position
const num_move_ticks = gameGhostSpeed(ghost);
var i: u32 = 0;
while (i < num_move_ticks): (i += 1) {
const force_move = gameUpdateGhostDir(ghost);
const allow_cornering = false;
if (force_move or canMove(ghost.actor.pos, ghost.actor.dir, allow_cornering)) {
ghost.actor.pos = move(ghost.actor.pos, ghost.actor.dir, allow_cornering);
ghost.actor.anim_tick += 1;
}
}
}
}
// this function takes care of switching ghosts into a new state, this is one
// of two important functions of the ghost AI (the other being the target selection
// function below)
fn gameUpdateGhostState(ghost: *Ghost) void {
var new_state = ghost.state;
switch (ghost.state) {
.Eyes => {
// When in eye state (heading back to the ghost house), check if the
// target position in front of the ghost house has been reached, then
// switch into ENTERHOUSE state. Since ghosts in eye state move faster
// than one pixel per tick, do a fuzzy comparison with the target pos
if (nearEqual(ghost.actor.pos, .{ AntePortasX, AntePortasY}, 1)) {
new_state = .EnterHouse;
}
},
.EnterHouse => {
// Ghosts that enter the ghost house during the gameplay loop immediately
// leave the house again after reaching their target position inside the house.
if (nearEqual(ghost.actor.pos, ghostHouseTargetPos(ghost.type), 1)) {
new_state = .LeaveHouse;
}
},
.House => {
// Ghosts only remain in the "house state" after a new game round
// has been started. The conditions when ghosts leave the house
// are a bit complicated, best to check the Pacman Dossier for the details.
if (afterOnce(state.game.force_leave_house, 4*60)) {
// if Pacman hasn't eaten dots for 4 seconds, the next ghost
// is forced out of the house
// FIXME: time is reduced to 3 seconds after round 5
new_state = .LeaveHouse;
start(&state.game.force_leave_house);
}
else if (state.game.global_dot_counter_active) {
// if Pacman has lost a life this round, the global dot counter is used
const dot_counter_limit: u32 = switch (ghost.type) {
.Blinky => 0,
.Pinky => 7,
.Inky => 17,
.Clyde => 32,
};
if (state.game.global_dot_counter == dot_counter_limit) {
new_state = .LeaveHouse;
// NOTE that global dot counter is deactivated if (and only if) Clyde
// is in the house and the dot counter reaches 32
if (ghost.type == .Clyde) {
state.game.global_dot_counter_active = false;
}
}
}
else if (ghost.dot_counter == ghost.dot_limit) {
// in the normal case, check the ghost's personal dot counter
new_state = .LeaveHouse;
}
},
.LeaveHouse => {
// ghosts immediately switch to scatter mode after leaving the ghost house
if (ghost.actor.pos[1] == AntePortasY) {
new_state = .Scatter;
}
},
else => {
// all other states: switch between frightened, scatter and chase states
if (before(ghost.frightened, levelSpec(state.game.round).fright_ticks)) {
new_state = .Frightened;
}
else {
const t = since(state.game.round_started);
if (t < 7*60) { new_state = .Scatter; }
else if (t < 27*60) { new_state = .Chase; }
else if (t < 34*60) { new_state = .Scatter; }
else if (t < 54*60) { new_state = .Chase; }
else if (t < 59*60) { new_state = .Scatter; }
else if (t < 79*60) { new_state = .Chase; }
else if (t < 84*60) { new_state = .Scatter; }
else { new_state = .Chase; }
}
}
}
// handle state transitions
if (new_state != ghost.state) {
switch (ghost.state) {
.LeaveHouse => {
// after leaving the house, head to the left
ghost.next_dir = .Left;
ghost.actor.dir = .Left;
},
.EnterHouse => {
// a ghost that was eaten is immune to frighten until Pacman eats another pill
disable(&ghost.frightened);
},
.Frightened => {
// don't reverse direction when leaving frightened state
},
.Scatter, .Chase => {
// any transition from scatter and chase mode causes a reversal of direction
ghost.next_dir = reverseDir(ghost.actor.dir);
},
else => {}
}
ghost.state = new_state;
}
}
// update the ghost's target position, this is the other important function
// of the ghost's AI
fn gameUpdateGhostTarget(ghost: *Ghost) void {
switch (ghost.state) {
.Scatter => {
// when in scatter mode, each ghost heads to its own scatter
// target position in the playfield corners
ghost.target_pos = scatterTargetPos(ghost.type);
},
.Chase => {
// when in chase mode, each ghost has its own particular
// chase behaviour (see the Pacman Dossier for details)
const pm = &state.game.pacman.actor;
const pm_pos = pixelToTilePos(pm.pos);
const pm_dir = dirToVec(pm.dir);
switch (ghost.type) {
.Blinky => {
// Blinky directly chases Pacman
ghost.target_pos = pm_pos;
},
.Pinky => {
// Pinky target is 4 tiles ahead of Pacman
// FIXME: does not reproduce 'diagonal overflow'
ghost.target_pos = pm_pos + pm_dir * ivec2{4,4};
},
.Inky => {
// Inky targets an extrapolated pos along a line two tiles
// ahead of Pacman through Blinky
const blinky_pos = pixelToTilePos(blinky().actor.pos);
const d = (pm_pos + pm_dir * ivec2{2,2}) - blinky_pos;
ghost.target_pos = blinky_pos + d * ivec2{2,2};
},
.Clyde => {
// if Clyde is far away from Pacman, he chases Pacman,
// but if close he moves towards the scatter target
if (squaredDistance(pixelToTilePos(ghost.actor.pos), pm_pos) > 64) {
ghost.target_pos = pm_pos;
}
else {
ghost.target_pos = scatterTargetPos(.Clyde);
}
}
}
},
.Frightened => {
// in frightened state just select a random target position
// this has the effect that ghosts in frightened state
// move in a random direction at each intersection
ghost.target_pos = .{
@intCast(i16, xorshift32() % DisplayTilesX),
@intCast(i16, xorshift32() % DisplayTilesY)
};
},
.Eyes => {
// move towards the ghost house door
ghost.target_pos = .{ 13, 14 };
},
else => {}
}
}
// compute the next ghost direction, return true if resulting movement
// should always happen regardless of current ghost position or blocking
// tiles (this special case is used for movement inside the ghost house)
fn gameUpdateGhostDir(ghost: *Ghost) bool {
switch (ghost.state) {
.House => {
// inside ghost house, just move up and down
if (ghost.actor.pos[1] <= 17*TileHeight) {
ghost.next_dir = .Down;
}
else if (ghost.actor.pos[1] >= 18*TileHeight) {
ghost.next_dir = .Up;
}
ghost.actor.dir = ghost.next_dir;
// force movement
return true;
},
.LeaveHouse => {
// navigate ghost out of the ghost house
const pos = ghost.actor.pos;
if (pos[0] == AntePortasX) {
if (pos[1] > AntePortasY) {
ghost.next_dir = .Up;
}
}
else {
const mid_y: i16 = 17*TileHeight + TileHeight/2;
if (pos[1] > mid_y) {
ghost.next_dir = .Up;
}
else if (pos[1] < mid_y) {
ghost.next_dir = .Down;
}
else {
ghost.next_dir = if (pos[0] > AntePortasX) .Left else .Right;
}
}
ghost.actor.dir = ghost.next_dir;
// force movement
return true;
},
.EnterHouse => {
// navigate towards the ghost house target pos
const pos = ghost.actor.pos;
const tile_pos = pixelToTilePos(pos);
const tgt_pos = ghostHouseTargetPos(ghost.type);
if (tile_pos[1] == 14) {
if (pos[0] != AntePortasX) {
ghost.next_dir = if (pos[0] > AntePortasX) .Left else .Right;
}
else {
ghost.next_dir = .Down;
}
}
else if (pos[1] == tgt_pos[1]) {
ghost.next_dir = if (pos[0] > tgt_pos[0]) .Left else .Right;
}
ghost.actor.dir = ghost.next_dir;
// force movement
return true;
},
else => {
// scatter/chase/frightened: just head towards the current target point
const dist_to_mid = distToTileMid(ghost.actor.pos);
if ((dist_to_mid[0] == 0) and (dist_to_mid[1] == 0)) {
// new direction is the previously computed next direction
ghost.actor.dir = ghost.next_dir;
// compute new next-direction
const dir_vec = dirToVec(ghost.actor.dir);
const lookahead_pos = pixelToTilePos(ghost.actor.pos) + dir_vec;
// try each direction and take the one that's closest to the target pos
const dirs = [_]Dir { .Up, .Left, .Down, .Right };
var min_dist: i16 = 32000;
for (dirs) |dir| {
// if ghost is in one of the two 'red zones', forbid upward movement
// (see Pacman Dossier "Areas To Exploit")
if (isRedZone(lookahead_pos) and (dir == .Up) and (ghost.state != .Eyes)) {
continue;
}
const test_pos = clampedTilePos(lookahead_pos + dirToVec(dir));
if ((reverseDir(dir) != ghost.actor.dir) and !isBlockingTile(test_pos)) {
const cur_dist = squaredDistance(test_pos, ghost.target_pos);
if (cur_dist < min_dist) {
min_dist = cur_dist;
ghost.next_dir = dir;
}
}
}
}
// moving with blocking-check
return false;
}
}
}
// Return true if Pacman should move in current game tick. When eating dots,
// Pacman is slightly slower then ghosts, otherwise slightly faster
fn gamePacmanShouldMove() bool {
if (now(state.game.dot_eaten)) {
// eating a dot causes Pacman to stop for 1 tick
return false;
}
else if (since(state.game.pill_eaten) < 3) {
// eating an energizer pill causes Pacman to stop for 3 ticks
return false;
}
else {
return 0 != (state.timing.tick % 8);
}
}
// return number of pixels a ghost should move this tick, this can't be a simple
// move/don't move boolean return value, because ghosts in eye state move faster
// than one pixel per tick
fn gameGhostSpeed(ghost: *const Ghost) u32 {
switch (ghost.state) {
.House, .LeaveHouse, .Frightened => {
// inside house and when frightened at half speed
return state.timing.tick & 1;
},
.Eyes, .EnterHouse => {
// estimated 1.5x when in eye state, Pacman Dossier is silent on this
return if (0 != (state.timing.tick & 1)) 1 else 2;
},
else => {
if (isTunnel(pixelToTilePos(ghost.actor.pos))) {
// move drastically slower when inside tunnel
return if (0 != ((state.timing.tick * 2) % 4)) 1 else 0;
}
else {
// otherwise move just a bit slower than Pacman
return if (0 != state.timing.tick % 7) 1 else 0;
}
}
}
}
// called when a dot or pill has been eaten, checks if a round has been won
// (all dots and pills eaten), whether to show the bonus fruit, and finally
// plays the dot-eaten sound effect
fn gameUpdateDotsEaten() void {
state.game.num_dots_eaten += 1;
switch (state.game.num_dots_eaten) {
NumDots => {
// all dots eaten, round won
start(&state.game.round_won);
soundClear();
},
70, 170 => {
// at 70 and 170 dots, show the bonus fruit
start(&state.game.fruit_active);
},
else => {}
}
soundEatDot(state.game.num_dots_eaten);
}
// Update the dot counters used to decide whether ghosts must leave the house.
//
// This is called each time Pacman eats a dot.
//
// Each ghost has a dot limit which is reset at the start of a round. Each time
// Pacman eats a dot, the highest priority ghost in the ghost house counts
// down its dot counter.
//
// When the ghost's dot counter reaches zero the ghost leaves the house
// and the next highest-priority dot counter starts counting.
//
// If a life is lost, the personal dot counters are deactivated and instead
// a global dot counter is used.
//
// If pacman doesn't eat dots for a while, the next ghost is forced out of the
// house using a timer.
//
fn gameUpdateGhostHouseDotCounters() void {
// if the new round was started because Pacman lost a life, use the global
// dot counter (this mode will be deactivated again after all ghosts left the
// house)
if (state.game.global_dot_counter_active) {
state.game.global_dot_counter += 1;
}
else {
// otherwise each ghost has his own personal dot counter to decide
// when to leave the ghost house, the dot counter is only increments
// for the first ghost below the dot limit
for (state.game.ghosts) |*ghost| {
if (ghost.dot_counter < ghost.dot_limit) {
ghost.dot_counter += 1;
break;
}
}
}
}
// common time trigger initialization at start of a game round
fn gameInitTriggers() void {
disable(&state.game.round_won);
disable(&state.game.game_over);
disable(&state.game.dot_eaten);
disable(&state.game.pill_eaten);
disable(&state.game.ghost_eaten);
disable(&state.game.pacman_eaten);
disable(&state.game.fruit_eaten);
disable(&state.game.force_leave_house);
disable(&state.game.fruit_active);
}
// intialize a new game
fn gameInit() void {
inputEnable();
gameInitTriggers();
state.game.round = DbgStartRound;
state.game.freeze = FreezePrelude;
state.game.num_lives = NumLives;
state.game.global_dot_counter_active = false;
state.game.global_dot_counter = 0;
state.game.num_dots_eaten = 0;
state.game.score = 0;
// draw the playfield and PLAYER ONE READY! message
gfxClear(TileCodeSpace, ColorCodeDot);
gfxColorText(.{9,0}, ColorCodeDefault, "HIGH SCORE");
gameInitPlayfield();
gfxColorText(.{9,14}, 5, "PLAYER ONE");
gfxColorText(.{11,20}, 9, "READY!");
}
// initialize the playfield background tiles
fn gameInitPlayfield() void {
gfxClearPlayfieldToColor(ColorCodeDot);
// decode the playfield data from an ASCII map
const tiles =
\\0UUUUUUUUUUUU45UUUUUUUUUUUU1
\\L............rl............R
\\L.ebbf.ebbbf.rl.ebbbf.ebbf.R
\\LPr l.r l.rl.r l.r lPR
\\L.guuh.guuuh.gh.guuuh.guuh.R
\\L..........................R
\\L.ebbf.ef.ebbbbbbf.ef.ebbf.R
\\L.guuh.rl.guuyxuuh.rl.guuh.R
\\L......rl....rl....rl......R
\\2BBBBf.rzbbf rl ebbwl.eBBBB3
\\ L.rxuuh gh guuyl.R
\\ L.rl rl.R
\\ L.rl mjs--tjn rl.R
\\UUUUUh.gh i q gh.gUUUUU
\\ . i q .
\\BBBBBf.ef i q ef.eBBBBB
\\ L.rl okkkkkkp rl.R
\\ L.rl rl.R
\\ L.rl ebbbbbbf rl.R
\\0UUUUh.gh guuyxuuh gh.gUUUU1
\\L............rl............R
\\L.ebbf.ebbbf.rl.ebbbf.ebbf.R
\\L.guyl.guuuh.gh.guuuh.rxuh.R
\\LP..rl....... .......rl..PR
\\6bf.rl.ef.ebbbbbbf.ef.rl.eb8
\\7uh.gh.rl.guuyxuuh.rl.gh.gu9
\\L......rl....rl....rl......R
\\L.ebbbbwzbbf.rl.ebbwzbbbbf.R
\\L.guuuuuuuuh.gh.guuuuuuuuh.R
\\L..........................R
\\2BBBBBBBBBBBBBBBBBBBBBBBBBB3
;
// map ASCII to tile codes
var t = [_]u8{TileCodeDot} ** 128;
t[' ']=0x40; t['0']=0xD1; t['1']=0xD0; t['2']=0xD5; t['3']=0xD4; t['4']=0xFB;
t['5']=0xFA; t['6']=0xD7; t['7']=0xD9; t['8']=0xD6; t['9']=0xD8; t['U']=0xDB;
t['L']=0xD3; t['R']=0xD2; t['B']=0xDC; t['b']=0xDF; t['e']=0xE7; t['f']=0xE6;
t['g']=0xEB; t['h']=0xEA; t['l']=0xE8; t['r']=0xE9; t['u']=0xE5; t['w']=0xF5;
t['x']=0xF2; t['y']=0xF3; t['z']=0xF4; t['m']=0xED; t['n']=0xEC; t['o']=0xEF;
t['p']=0xEE; t['j']=0xDD; t['i']=0xD2; t['k']=0xDB; t['q']=0xD3; t['s']=0xF1;
t['t']=0xF0; t['-']=TileCodeDoor; t['P']=TileCodePill;
var y: i16 = 3;
var i: usize = 0;
while (y < DisplayTilesY-2): (y += 1) {
var x: i16 = 0;
while (x < DisplayTilesX): ({ x += 1; i += 1; }) {
gfxTile(.{x,y}, t[tiles[i] & 127]);
}
// skip newline
if (tiles[i] == '\r') {
i += 1;
}
if (tiles[i] == '\n') {
i += 1;
}
}
// ghost house door color
gfxColor(.{13,15}, 0x18);
gfxColor(.{14,15}, 0x18);
}
// initialize a new game round
fn gameRoundInit() void {
gfxClearSprites();
// clear the PLAYER ONE text
gfxColorText(.{9,14}, ColorCodeDot, " ");
// if a new round was started because Pacman had won (eaten all dots),
// redraw the playfield and reset the global dot counter
if (state.game.num_dots_eaten == NumDots) {
state.game.round += 1;
state.game.num_dots_eaten = 0;
state.game.global_dot_counter_active = false;
gameInitPlayfield();
}
else {
// if the previous round was lost, use the global dot counter
// to detect when ghosts should leave the ghost house instead
// of the per-ghost dot counter
if (state.game.num_lives != NumLives) {
state.game.global_dot_counter_active = true;
state.game.global_dot_counter = 0;
}
state.game.num_lives -= 1;
}
assert(state.game.num_lives >= 0);
state.game.active_fruit = .None;
state.game.freeze = FreezeReady;
state.game.xorshift = 0x12345678;
state.game.num_ghosts_eaten = 0;
gameInitTriggers();
gfxColorText(.{11,20}, 9, "READY!");
// the force-house trigger forces ghosts out of the house if Pacman
// hasn't been eating dots for a while
start(&state.game.force_leave_house);
// Pacman starts running to the left
state.game.pacman = .{
.actor = .{
.dir = .Left,
.pos = .{ 14*8, 26*8+4 }
}
};
// Blinky starts outside the ghost house, looking to the left and in scatter mode
blinky().* = .{
.actor = .{
.dir = .Left,
.pos = .{ 14*8, 14*8 + 4 },
},
.type = .Blinky,
.next_dir = .Left,
.state = .Scatter
};
// Pinky starts in the middle slot of the ghost house, heading down
pinky().* = .{
.actor = .{
.dir = .Down,
.pos = .{ 14*8, 17*8 + 4 },
},
.type = .Pinky,
.next_dir = .Down,
.state = .House,
};
// Inky starts in the left slot of the ghost house, moving up
inky().* = .{
.actor = .{
.dir = .Up,
.pos = .{ 12*8, 17*8 + 4 },
},
.type = .Inky,
.next_dir = .Up,
.state = .House,
.dot_limit = 30,
};
// Clyde starts in the righ slot of the ghost house, moving up
clyde().* = .{
.actor = .{
.dir = .Up,
.pos = .{ 16*8, 17*8 + 4 },
},
.type = .Clyde,
.next_dir = .Up,
.state = .House,
.dot_limit = 60
};
// reset sprites
spritePacman().* = .{ .enabled = true, .color = ColorCodePacman };
spriteBlinky().* = .{ .enabled = true, .color = ColorCodeBlinky };
spritePinky().* = .{ .enabled = true, .color = ColorCodePinky };
spriteInky().* = .{ .enabled = true, .color = ColorCodeInky };
spriteClyde().* = .{ .enabled = true, .color = ColorCodeClyde };
}
// update dynamic background tiles
fn gameUpdateTiles() void {
// print score and hiscore
gfxColorScore(.{6,1}, ColorCodeDefault, state.game.score);
if (state.game.hiscore > 0) {
gfxColorScore(.{16,1}, ColorCodeDefault, state.game.hiscore);
}
// update the energizer pill state (blinking/non-blinking)
const pill_pos = [NumPills]ivec2 { .{1,6}, .{26,6}, .{1,26}, .{26,26} };
for (pill_pos) |pos| {
if (0 != state.game.freeze) {
gfxColor(pos, ColorCodeDot);
}
else {
gfxColor(pos, if (0 != (state.timing.tick & 8)) ColorCodeDot else ColorCodeBlank);
}
}
// clear the fruit-eaten score after Pacman has eaten a bonus fruit
if (afterOnce(state.game.fruit_eaten, 2*60)) {
gfxFruitScore(.None);
}
// remaining lives in bottom-left corner
{
var i: i16 = 0;
while (i < NumLives): (i += 1) {
const color: u8 = if (i < state.game.num_lives) ColorCodePacman else ColorCodeBlank;
gfxColorTileQuad(.{2+2*i,34}, color, TileCodeLife);
}
}
// bonus fruits in bottom-right corner
{
var i: i32 = @intCast(i32,state.game.round) - 7 + 1;
var x: i16 = 24;
while (i <= state.game.round): (i += 1) {
if (i >= 0) {
const fruit = levelSpec(@intCast(u32,i)).bonus_fruit;
gfxColorTileQuad(.{x,34}, fruitColorCode(fruit), fruitTileCode(fruit));
x -= 2;
}
}
}
// if game round was won, render the entire playfield as blinking blue/white
if (after(state.game.round_won, 1*60)) {
if (0 != (since(state.game.round_won) & 0x10)) {
gfxClearPlayfieldToColor(ColorCodeDot);
}
else {
gfxClearPlayfieldToColor(ColorCodeWhiteBorder);
}
}
}
// update sprite images
fn gameUpdateSprites() void {
// update Pacman sprite
{
var spr = spritePacman();
if (spr.enabled) {
const actor = &state.game.pacman.actor;
spr.pos = actorToSpritePos(actor.pos);
if (0 != (state.game.freeze & FreezeEatGhost)) {
// hide Pacman shortly after he's eaten a ghost
spr.tile = SpriteCodeInvisible;
}
else if (0 != (state.game.freeze & (FreezePrelude|FreezeReady))) {
// special case game frozen at start of round, show "closed mouth" Pacman
spr.tile = SpriteCodePacmanClosedMouth;
}
else if (0 != (state.game.freeze & (FreezeDead))) {
// play the Pacman death animation after a short pause
if (after(state.game.pacman_eaten, PacmanEatenTicks)) {
spriteImagePacmanDeath(since(state.game.pacman_eaten) - PacmanEatenTicks);
}
}
else {
// regular Pacman animation
spriteImagePacman(actor.dir, actor.anim_tick);
}
}
}
// update ghost sprites
// FIXME: Zig doesn't allow a const pointer in the loop?
for (state.game.ghosts) |*ghost, i| {
var spr = spriteGhost(ghost.type);
if (spr.enabled) {
spr.pos = actorToSpritePos(ghost.actor.pos);
// if Pacman has just died, hide ghosts
if (0 != (state.game.freeze & FreezeDead)) {
if (after(state.game.pacman_eaten, PacmanEatenTicks)) {
spr.tile = SpriteCodeInvisible;
}
}
// if Pacman has won the round, hide the ghosts
else if (0 != (state.game.freeze & FreezeWon)) {
spr.tile = SpriteCodeInvisible;
}
else switch (ghost.state) {
.Eyes => {
if (before(ghost.eaten, GhostEatenFreezeTicks)) {
// if the ghost was *just* eaten by Pacman, the ghost's sprite
// is replaced with a score number for a short time
// (200 for the first ghost, followed by 400, 800 and 1600)
spr.tile = SpriteCodeScore200 + state.game.num_ghosts_eaten - 1;
spr.color = ColorCodeGhostScore;
}
else {
// afterwards the ghost's eyes are shown, heading back to the ghost house
spriteImageGhostEyes(ghost.type, ghost.next_dir);
}
},
.EnterHouse => {
// show ghost eyes while entering the ghost house
spriteImageGhostEyes(ghost.type, ghost.next_dir);
},
.Frightened => {
// when inside the ghost house, show the normal ghost images
// (FIXME: ghost's inside the ghost house also show the
// frightened appearance when Pacman has eaten an energizer pill)
const fright_ticks = levelSpec(state.game.round).fright_ticks;
spriteImageGhostFrightened(ghost.type, since(ghost.frightened), if (fright_ticks > 60) (fright_ticks - 60) else 0);
},
else => {
// show the regular ghost sprite image, the ghost's
// 'next_dir' is used to visualize the direction the ghost
// is heading to, this has the effect that ghosts already look
// into the direction they will move into one tile ahead
spriteImageGhost(ghost.type, ghost.next_dir, ghost.actor.anim_tick);
}
}
}
}
// hide or display the currently active bonus fruit
if (state.game.active_fruit == .None) {
spriteFruit().enabled = false;
}
else {
spriteFruit().* = .{
.enabled = true,
.pos = .{ 13 * TileWidth, 19 * TileHeight + TileHeight/2 },
.tile = fruitSpriteCode(state.game.active_fruit),
.color = fruitColorCode(state.game.active_fruit)
};
}
}
// render the intro screen
fn introTick() void {
// on state enter, enable input and draw initial text
if (now(state.intro.started)) {
soundClear();
gfxClearSprites();
start(&state.gfx.fadein);
inputEnable();
gfxClear(TileCodeSpace, ColorCodeDefault);
gfxText(.{3,0}, "1UP HIGH SCORE 2UP");
gfxColorScore(.{6,1}, ColorCodeDefault, 0);
if (state.game.hiscore > 0) {
gfxColorScore(.{16,1}, ColorCodeDefault, state.game.hiscore);
}
gfxText(.{7,5}, "CHARACTER / NICKNAME");
gfxText(.{3,35}, "CREDIT 0");
}
// draw the animated 'ghost... name... nickname' lines
var delay: u32 = 0;
const names = [_][]const u8 { "-SHADOW", "-SPEEDY", "-BASHFUL", "-POKEY" };
const nicknames = [_][]const u8 { "BLINKY", "PINKY", "INKY", "CLYDE" };
for (names) |name, i| {
const color: u8 = 2 * @intCast(u8,i) + 1;
const y: i16 = 3 * @intCast(i16,i) + 6;
// 2*3 tiles ghost image
delay += 30;
if (afterOnce(state.intro.started, delay)) {
gfxColorTile(.{4,y+0}, color, TileCodeGhost+0); gfxColorTile(.{5,y+0}, color, TileCodeGhost+1);
gfxColorTile(.{4,y+1}, color, TileCodeGhost+2); gfxColorTile(.{5,y+1}, color, TileCodeGhost+3);
gfxColorTile(.{4,y+2}, color, TileCodeGhost+4); gfxColorTile(.{5,y+2}, color, TileCodeGhost+5);
}
// after 1 second, the name of the ghost
delay += 60;
if (afterOnce(state.intro.started, delay)) {
gfxColorText(.{7,y+1}, color, name);
}
// after 0.5 seconds, the nickname of the ghost
delay += 30;
if (afterOnce(state.intro.started, delay)) {
gfxColorText(.{17,y+1}, color, nicknames[i]);
}
}
// . 10 PTS
// o 50 PTS
delay += 60;
if (afterOnce(state.intro.started, delay)) {
gfxColorTile(.{10,24}, ColorCodeDot, TileCodeDot);
gfxText(.{12,24}, "10 \x5D\x5E\x5F");
gfxColorTile(.{10,26}, ColorCodeDot, TileCodePill);
gfxText(.{12,26}, "50 \x5D\x5E\x5F");
}
// blinking "press any key" text
delay += 60;
if (after(state.intro.started, delay)) {
if (0 != (since(state.intro.started) & 0x20)) {
gfxColorText(.{3,31}, 3, " ");
}
else {
gfxColorText(.{3,31}, 3, "PRESS ANY KEY TO START!");
}
}
// if a key is pressed, advance to game state
if (state.input.anykey) {
inputDisable();
start(&state.gfx.fadeout);
startAfter(&state.game.started, FadeTicks);
}
}
//--- rendering system ---------------------------------------------------------
fn gfxInit() void {
sg.setup(.{
.buffer_pool_size = 2,
.image_pool_size = 3,
.shader_pool_size = 2,
.pipeline_pool_size = 2,
.pass_pool_size = 1,
.context = sgapp.context()
});
gfxDecodeTiles();
gfxDecodeColorPalette();
gfxCreateResources();
}
fn gfxShutdown() void {
sg.shutdown();
}
fn gfxClear(tile_code: u8, color_code: u8) void {
var y: u32 = 0;
while (y < DisplayTilesY): (y += 1) {
var x: u32 = 0;
while (x < DisplayTilesX): (x += 1) {
data.tile_ram[y][x] = tile_code;
data.color_ram[y][x] = color_code;
}
}
}
fn gfxClearPlayfieldToColor(color_code: u8) void {
var y: usize = 3;
while (y < (DisplayTilesY-2)): (y += 1) {
var x: usize = 0;
while (x < DisplayTilesX): (x += 1) {
data.color_ram[y][x] = color_code;
}
}
}
fn gfxTileAt(pos: ivec2) u8 {
return data.tile_ram[@intCast(usize,pos[1])][@intCast(usize,pos[0])];
}
fn gfxTile(pos: ivec2, tile_code: u8) void {
data.tile_ram[@intCast(usize,pos[1])][@intCast(usize,pos[0])] = tile_code;
}
fn gfxColor(pos: ivec2, color_code: u8) void {
data.color_ram[@intCast(usize,pos[1])][@intCast(usize,pos[0])] = color_code;
}
fn gfxColorTile(pos: ivec2, color_code: u8, tile_code: u8) void {
gfxTile(pos, tile_code);
gfxColor(pos, color_code);
}
fn gfxToNamcoChar(c: u8) u8 {
return switch (c) {
' ' => 64,
'/' => 58,
'-' => 59,
'"' => 38,
'!' => 'Z'+1,
else => c
};
}
fn gfxChar(pos: ivec2, chr: u8) void {
gfxTile(pos, gfxToNamcoChar(chr));
}
fn gfxColorChar(pos: ivec2, color_code: u8, chr: u8) void {
gfxChar(pos, chr);
gfxColor(pos, color_code);
}
fn gfxColorText(pos: ivec2, color_code: u8, text: []const u8) void {
var p = pos;
for (text) |chr| {
if (p[0] < DisplayTilesX) {
gfxColorChar(p, color_code, chr);
p[0] += 1;
}
else {
break;
}
}
}
fn gfxText(pos: ivec2, text: []const u8) void {
var p = pos;
for (text) |chr| {
if (p[0] < DisplayTilesX) {
gfxChar(p, chr);
p[0] += 1;
}
else {
break;
}
}
}
// print colored score number into tile+color buffers from right to left(!),
// scores are /10, the last printed number is always 0,
// a zero-score will print as '00' (this is the same as on
// the Pacman arcade machine)
fn gfxColorScore(pos: ivec2, color_code: u8, score: u32) void {
var p = pos;
var s = score;
gfxColorChar(p, color_code, '0');
p[0] -= 1;
var digit: u32 = 0;
while (digit < 8): (digit += 1) {
// FIXME: should this narrowing cast not be necessary?
const chr: u8 = @intCast(u8, s % 10) + '0';
if (validTilePos(p)) {
gfxColorChar(p, color_code, chr);
p[0] -= 1;
s /= 10;
if (0 == s) {
break;
}
}
}
}
// draw a colored tile-quad arranged as:
// |t+1|t+0|
// |t+3|t+2|
//
// This is (for instance) used to render the current "lives" and fruit
// symbols at the lower border.
//
fn gfxColorTileQuad(pos: ivec2, color_code: u8, tile_code: u8) void {
var yy: i16 = 0;
while (yy < 2): (yy += 1) {
var xx: i16 = 0;
while (xx < 2): (xx += 1) {
const t: u8 = tile_code + @intCast(u8,yy)*2 + (1 - @intCast(u8,xx));
gfxColorTile(pos + ivec2{xx,yy}, color_code, t);
}
}
}
// draw the fruit bonus score tiles (when Pacman has eaten the bonus fruit)
fn gfxFruitScore(fruit: Fruit) void {
const color_code: u8 = if (fruit == .None) ColorCodeDot else ColorCodeFruitScore;
const tiles: [4]u8 = switch (fruit) {
.None => .{ 0x40, 0x40, 0x40, 0x40 },
.Cherries => .{ 0x40, 0x81, 0x85, 0x40 },
.Strawberry => .{ 0x40, 0x82, 0x85, 0x40 },
.Peach => .{ 0x40, 0x83, 0x85, 0x40 },
.Apple => .{ 0x40, 0x84, 0x85, 0x40 },
.Grapes => .{ 0x40, 0x86, 0x8D, 0x8E },
.Galaxian => .{ 0x87, 0x88, 0x8D, 0x8E },
.Bell => .{ 0x89, 0x8A, 0x8D, 0x8E },
.Key => .{ 0x8B, 0x8C, 0x8D, 0x8E },
};
var i: usize = 0;
while (i < 4): (i += 1) {
gfxColorTile(.{12+@intCast(i16,i),20}, color_code, tiles[i]);
}
}
fn gfxClearSprites() void {
for (state.gfx.sprites) |*spr| {
spr.* = .{};
}
}
// adjust viewport so that aspect ratio is always correct
fn gfxAdjustViewport(canvas_width: f32, canvas_height: f32) void {
assert((canvas_width > 0) and (canvas_height > 0));
const canvas_aspect = canvas_width / canvas_height;
const playfield_aspect = @intToFloat(f32, DisplayTilesX) / DisplayTilesY;
const border = 10.0;
if (playfield_aspect < canvas_aspect) {
const vp_y: f32 = border;
const vp_h: f32 = canvas_height - 2*border;
const vp_w: f32 = (canvas_height * playfield_aspect) - 2*border;
const vp_x: f32 = (canvas_width - vp_w) * 0.5;
sg.applyViewportf(vp_x, vp_y, vp_w, vp_h, true);
}
else {
const vp_x: f32 = border;
const vp_w: f32 = canvas_width - 2*border;
const vp_h: f32 = (canvas_width / playfield_aspect) - 2*border;
const vp_y: f32 = (canvas_height - vp_h) * 0.5;
sg.applyViewportf(vp_x, vp_y, vp_w, vp_h, true);
}
}
fn gfxFrame() void {
// handle fade-in/out
gfxUpdateFade();
// render tile- and sprite-vertices and upload into vertex buffer
state.gfx.num_vertices = 0;
gfxAddPlayfieldVertices();
gfxAddSpriteVertices();
gfxAddDebugMarkerVertices();
if (state.gfx.fade > 0) {
gfxAddFadeVertices();
}
sg.updateBuffer(state.gfx.offscreen.vbuf, .{ .ptr=&data.vertices, .size=state.gfx.num_vertices * @sizeOf(Vertex) });
// render tiles and sprites into offscreen render target
sg.beginPass(state.gfx.offscreen.pass, state.gfx.pass_action);
sg.applyPipeline(state.gfx.offscreen.pip);
sg.applyBindings(state.gfx.offscreen.bind);
sg.draw(0, state.gfx.num_vertices, 1);
sg.endPass();
// upscale-render the offscreen render target into the display framebuffer
const canvas_width = sapp.widthf();
const canvas_height = sapp.heightf();
sg.beginDefaultPassf(state.gfx.pass_action, canvas_width, canvas_height);
gfxAdjustViewport(canvas_width, canvas_height);
sg.applyPipeline(state.gfx.display.pip);
sg.applyBindings(state.gfx.display.bind);
sg.draw(0, 4, 1);
sg.endPass();
sg.commit();
}
fn gfxAddVertex(x: f32, y: f32, u: f32, v: f32, color_code: u32, opacity: u32) void {
var vtx: *Vertex = &data.vertices[state.gfx.num_vertices];
state.gfx.num_vertices += 1;
vtx.x = x;
vtx.y = y;
vtx.u = u;
vtx.v = v;
vtx.attr = (opacity<<8)|color_code;
}
fn gfxAddTileVertices(x: u32, y: u32, tile_code: u32, color_code: u32) void {
const dx = 1.0 / @intToFloat(f32, DisplayTilesX);
const dy = 1.0 / @intToFloat(f32, DisplayTilesY);
const dtx = @intToFloat(f32, TileWidth) / TileTextureWidth;
const dty = @intToFloat(f32, TileHeight) / TileTextureHeight;
const x0 = @intToFloat(f32, x) * dx;
const x1 = x0 + dx;
const y0 = @intToFloat(f32, y) * dy;
const y1 = y0 + dy;
const tx0 = @intToFloat(f32, tile_code) * dtx;
const tx1 = tx0 + dtx;
const ty0: f32 = 0.0;
const ty1 = dty;
// x0,y0
// +-----+
// | * |
// | * |
// +-----+
// x1,y1
gfxAddVertex(x0, y0, tx0, ty0, color_code, 0xFF);
gfxAddVertex(x1, y0, tx1, ty0, color_code, 0xFF);
gfxAddVertex(x1, y1, tx1, ty1, color_code, 0xFF);
gfxAddVertex(x0, y0, tx0, ty0, color_code, 0xFF);
gfxAddVertex(x1, y1, tx1, ty1, color_code, 0xFF);
gfxAddVertex(x0, y1, tx0, ty1, color_code, 0xFF);
}
fn gfxUpdateFade() void {
if (before(state.gfx.fadein, FadeTicks)) {
const t = @intToFloat(f32, since(state.gfx.fadein)) / FadeTicks;
state.gfx.fade = @floatToInt(u8, 255.0 * (1.0 - t));
}
if (afterOnce(state.gfx.fadein, FadeTicks)) {
state.gfx.fade = 0;
}
if (before(state.gfx.fadeout, FadeTicks)) {
const t = @intToFloat(f32, since(state.gfx.fadeout)) / FadeTicks;
state.gfx.fade = @floatToInt(u8, 255.0 * t);
}
if (afterOnce(state.gfx.fadeout, FadeTicks)) {
state.gfx.fade = 255;
}
}
fn gfxAddPlayfieldVertices() void {
var y: u32 = 0;
while (y < DisplayTilesY): (y += 1) {
var x: u32 = 0;
while (x < DisplayTilesX): (x += 1) {
const tile_code = data.tile_ram[y][x];
const color_code = data.color_ram[y][x] & 0x1F;
gfxAddTileVertices(x, y, tile_code, color_code);
}
}
}
fn gfxAddSpriteVertices() void {
const dx = 1.0 / @intToFloat(f32, DisplayPixelsX);
const dy = 1.0 / @intToFloat(f32, DisplayPixelsY);
const dtx = @intToFloat(f32, SpriteWidth) / TileTextureWidth;
const dty = @intToFloat(f32, SpriteHeight) / TileTextureHeight;
for (state.gfx.sprites) |*spr| {
if (spr.enabled) {
const xx0 = @intToFloat(f32, spr.pos[0]) * dx;
const xx1 = xx0 + dx*SpriteWidth;
const yy0 = @intToFloat(f32, spr.pos[1]) * dy;
const yy1 = yy0 + dy*SpriteHeight;
const x0 = if (spr.flipx) xx1 else xx0;
const x1 = if (spr.flipx) xx0 else xx1;
const y0 = if (spr.flipy) yy1 else yy0;
const y1 = if (spr.flipy) yy0 else yy1;
const tx0 = @intToFloat(f32, spr.tile) * dtx;
const tx1 = tx0 + dtx;
const ty0 = @intToFloat(f32, TileHeight) / TileTextureHeight;
const ty1 = ty0 + dty;
gfxAddVertex(x0, y0, tx0, ty0, spr.color, 0xFF);
gfxAddVertex(x1, y0, tx1, ty0, spr.color, 0xFF);
gfxAddVertex(x1, y1, tx1, ty1, spr.color, 0xFF);
gfxAddVertex(x0, y0, tx0, ty0, spr.color, 0xFF);
gfxAddVertex(x1, y1, tx1, ty1, spr.color, 0xFF);
gfxAddVertex(x0, y1, tx0, ty1, spr.color, 0xFF);
}
}
}
fn gfxAddDebugMarkerVertices() void {
for (state.gfx.debug_markers) |*dbg| {
if (dbg.enabled) {
gfxAddTileVertices(@intCast(u32, dbg.tile_pos[0]), @intCast(u32, dbg.tile_pos[1]), dbg.tile, dbg.color);
}
}
}
fn gfxAddFadeVertices() void {
// sprite tile 64 is a special opaque sprite
const dtx = @intToFloat(f32, SpriteWidth) / TileTextureWidth;
const dty = @intToFloat(f32, SpriteHeight) / TileTextureHeight;
const tx0 = 64 * dtx;
const tx1 = tx0 + dtx;
const ty0 = @intToFloat(f32, TileHeight) / TileTextureHeight;
const ty1 = ty0 + dty;
const fade = state.gfx.fade;
gfxAddVertex(0.0, 0.0, tx0, ty0, 0, fade);
gfxAddVertex(1.0, 0.0, tx1, ty0, 0, fade);
gfxAddVertex(1.0, 1.0, tx1, ty1, 0, fade);
gfxAddVertex(0.0, 0.0, tx0, ty0, 0, fade);
gfxAddVertex(1.0, 1.0, tx1, ty1, 0, fade);
gfxAddVertex(0.0, 1.0, tx0, ty1, 0, fade);
}
// 8x4 tile decoder (taken from: https://github.com/floooh/chips/blob/master/systems/namco.h)
//
// This decodes 2-bit-per-pixel tile data from Pacman ROM dumps into
// 8-bit-per-pixel texture data (without doing the RGB palette lookup,
// this happens during rendering in the pixel shader).
//
// The Pacman ROM tile layout isn't exactly strightforward, both 8x8 tiles
// and 16x16 sprites are built from 8x4 pixel blocks layed out linearly
// in memory, and to add to the confusion, since Pacman is an arcade machine
// with the display 90 degree rotated, all the ROM tile data is counter-rotated.
//
// Tile decoding only happens once at startup from ROM dumps into a texture.
//
fn gfxDecodeTile8x4(
tile_code: u32, // the source tile code
src: []const u8, // encoded source tile data
src_stride: u32, // stride and offset in encoded tile data
src_offset: u32,
dst_x: u32, // x/y position in target texture
dst_y: u32)
void {
var x: u32 = 0;
while (x < TileWidth): (x += 1) {
const ti = tile_code * src_stride + src_offset + (7 - x);
var y: u3 = 0;
while (y < (TileHeight/2)): (y += 1) {
const p_hi: u8 = (src[ti] >> (7 - y)) & 1;
const p_lo: u8 = (src[ti] >> (3 - y)) & 1;
const p: u8 = (p_hi << 1) | p_lo;
data.tile_pixels[dst_y + y][dst_x + x] = p;
}
}
}
// decode an 8x8 tile into the tile texture upper 8 pixels
const TileRom = @embedFile("roms/pacman_tiles.rom");
fn gfxDecodeTile(tile_code: u32) void {
const x = tile_code * TileWidth;
const y0 = 0;
const y1 = TileHeight / 2;
gfxDecodeTile8x4(tile_code, TileRom, 16, 8, x, y0);
gfxDecodeTile8x4(tile_code, TileRom, 16, 0, x, y1);
}
// decode a 16x16 sprite into the tile textures lower 16 pixels
const SpriteRom = @embedFile("roms/pacman_sprites.rom");
fn gfxDecodeSprite(sprite_code: u32) void {
const x0 = sprite_code * SpriteWidth;
const x1 = x0 + TileWidth;
const y0 = TileHeight;
const y1 = y0 + (TileHeight / 2);
const y2 = y1 + (TileHeight / 2);
const y3 = y2 + (TileHeight / 2);
gfxDecodeTile8x4(sprite_code, SpriteRom, 64, 40, x0, y0);
gfxDecodeTile8x4(sprite_code, SpriteRom, 64, 8, x1, y0);
gfxDecodeTile8x4(sprite_code, SpriteRom, 64, 48, x0, y1);
gfxDecodeTile8x4(sprite_code, SpriteRom, 64, 16, x1, y1);
gfxDecodeTile8x4(sprite_code, SpriteRom, 64, 56, x0, y2);
gfxDecodeTile8x4(sprite_code, SpriteRom, 64, 24, x1, y2);
gfxDecodeTile8x4(sprite_code, SpriteRom, 64, 32, x0, y3);
gfxDecodeTile8x4(sprite_code, SpriteRom, 64, 0, x1, y3);
}
// decode the Pacman tile- and sprite-ROM-dumps into an 8-bpp linear texture
fn gfxDecodeTiles() void {
var tile_code: u32 = 0;
while (tile_code < 256): (tile_code += 1) {
gfxDecodeTile(tile_code);
}
var sprite_code: u32 = 0;
while (sprite_code < 64): (sprite_code += 1) {
gfxDecodeSprite(sprite_code);
}
// write a special 16x16 block which will be used for the fade effect
var y: u32 = TileHeight;
while (y < TileTextureHeight): (y += 1) {
var x: u32 = 64 * SpriteWidth;
while (x < (65 * SpriteWidth)): (x += 1) {
data.tile_pixels[y][x] = 1;
}
}
}
// decode the Pacman color palette into a palette texture, on the original
// hardware, color lookup happens in two steps, first through 256-entry
// palette which indirects into a 32-entry hardware-color palette
// (of which only 16 entries are used on the Pacman hardware)
//
fn gfxDecodeColorPalette() void {
// Expand the 8-bit palette ROM items into RGBA8 items.
// The 8-bit palette item bits are packed like this:
//
// | 7| 6| 5| 4| 3| 2| 1| 0|
// |B1|B0|G2|G1|G0|R2|R1|R0|
//
// Intensities for the 3 bits are: 0x97 + 0x47 + 0x21
const color_rom = @embedFile("roms/pacman_hwcolors.rom");
var hw_colors: [32]u32 = undefined;
for (hw_colors) |*pt, i| {
const rgb = color_rom[i];
const r: u32 = ((rgb>>0)&1)*0x21 + ((rgb>>1)&1)*0x47 + ((rgb>>2)&1)*0x97;
const g: u32 = ((rgb>>3)&1)*0x21 + ((rgb>>4)&1)*0x47 + ((rgb>>5)&1)*0x97;
const b: u32 = ((rgb>>6)&1)*0x47 + ((rgb>>7)&1)*0x97;
pt.* = 0xFF_00_00_00 | (b<<16) | (g<<8) | r;
}
// build 256-entry from indirection palette ROM
const palette_rom = @embedFile("roms/pacman_palette.rom");
for (data.color_palette) |*pt, i| {
pt.* = hw_colors[palette_rom[i] & 0xF];
// first color in each color block is transparent
if ((i & 3) == 0) {
pt.* &= 0x00_FF_FF_FF;
}
}
}
fn gfxCreateResources() void {
// pass action for clearing background to black
state.gfx.pass_action.colors[0] = .{
.action = .CLEAR,
.value = .{ .r=0, .g=0, .b=0, .a=1 }
};
// create a dynamic vertex buffer for the tile and sprite quads
state.gfx.offscreen.vbuf = sg.makeBuffer(.{
.usage = .STREAM,
.size = @sizeOf(@TypeOf(data.vertices))
});
// create a quad-vertex-buffer for rendering the offscreen render target to the display
const quad_verts = [_]f32{ 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0 };
state.gfx.display.quad_vbuf = sg.makeBuffer(.{
.data = sg.asRange(quad_verts),
});
// create pipeline and shader for rendering into offscreen render target
// NOTE: initializating structs with embedded arrays isn't great yet in Zig
// because arrays aren't "filled up" with default items.
{
var shd_desc: sg.ShaderDesc = .{};
shd_desc.attrs[0] = .{ .name = "pos", .sem_name = "POSITION" };
shd_desc.attrs[1] = .{ .name = "uv_in", .sem_name = "TEXCOORD", .sem_index = 0 };
shd_desc.attrs[2] = .{ .name = "data_in", .sem_name = "TEXCOORD", .sem_index = 1 };
shd_desc.fs.images[0] = .{ .name = "tile_tex", .image_type = ._2D };
shd_desc.fs.images[1] = .{ .name = "pal_tex", .image_type = ._2D };
shd_desc.vs.source = switch(sg.queryBackend()) {
.D3D11 => @embedFile("shaders/offscreen_vs.hlsl"),
.GLCORE33 => @embedFile("shaders/offscreen_vs.v330.glsl"),
.METAL_MACOS => @embedFile("shaders/offscreen_vs.metal"),
else => unreachable,
};
shd_desc.fs.source = switch(sg.queryBackend()) {
.D3D11 => @embedFile("shaders/offscreen_fs.hlsl"),
.GLCORE33 => @embedFile("shaders/offscreen_fs.v330.glsl"),
.METAL_MACOS => @embedFile("shaders/offscreen_fs.metal"),
else => unreachable,
};
var pip_desc: sg.PipelineDesc = .{
.shader = sg.makeShader(shd_desc),
.depth = .{
.pixel_format = .NONE,
},
};
pip_desc.layout.attrs[0].format = .FLOAT2;
pip_desc.layout.attrs[1].format = .FLOAT2;
pip_desc.layout.attrs[2].format = .UBYTE4N;
pip_desc.colors[0].pixel_format = .RGBA8;
pip_desc.colors[0].blend = .{
.enabled = true,
.src_factor_rgb = .SRC_ALPHA,
.dst_factor_rgb = .ONE_MINUS_SRC_ALPHA
};
state.gfx.offscreen.pip = sg.makePipeline(pip_desc);
}
// create pipeline and shader for rendering into display
{
var shd_desc: sg.ShaderDesc = .{};
shd_desc.attrs[0] = .{ .name = "pos", .sem_name = "POSITION" };
shd_desc.fs.images[0] = .{ .name = "tex", .image_type = ._2D };
shd_desc.vs.source = switch(sg.queryBackend()) {
.D3D11 => @embedFile("shaders/display_vs.hlsl"),
.GLCORE33 => @embedFile("shaders/display_vs.v330.glsl"),
.METAL_MACOS => @embedFile("shaders/display_vs.metal"),
else => unreachable
};
shd_desc.fs.source = switch(sg.queryBackend()) {
.D3D11 => @embedFile("shaders/display_fs.hlsl"),
.GLCORE33 => @embedFile("shaders/display_fs.v330.glsl"),
.METAL_MACOS => @embedFile("shaders/display_fs.metal"),
else => unreachable
};
var pip_desc: sg.PipelineDesc = .{
.shader = sg.makeShader(shd_desc),
.primitive_type = .TRIANGLE_STRIP,
};
pip_desc.layout.attrs[0].format = .FLOAT2;
state.gfx.display.pip = sg.makePipeline(pip_desc);
}
// create a render-target image with a fixed upscale ratio
state.gfx.offscreen.render_target = sg.makeImage(.{
.render_target = true,
.width = DisplayPixelsX * 2,
.height = DisplayPixelsY * 2,
.pixel_format = .RGBA8,
.min_filter = .LINEAR,
.mag_filter = .LINEAR,
.wrap_u = .CLAMP_TO_EDGE,
.wrap_v = .CLAMP_TO_EDGE
});
// a pass object for rendering into the offscreen render target
{
var pass_desc: sg.PassDesc = .{};
pass_desc.color_attachments[0].image = state.gfx.offscreen.render_target;
state.gfx.offscreen.pass = sg.makePass(pass_desc);
}
// create the decoded tile+sprite texture
{
var img_desc: sg.ImageDesc = .{
.width = TileTextureWidth,
.height = TileTextureHeight,
.pixel_format = .R8,
.min_filter = .NEAREST,
.mag_filter = .NEAREST,
.wrap_u = .CLAMP_TO_EDGE,
.wrap_v = .CLAMP_TO_EDGE,
};
img_desc.data.subimage[0][0] = sg.asRange(data.tile_pixels);
state.gfx.offscreen.tile_img = sg.makeImage(img_desc);
}
// create the color-palette texture
{
var img_desc: sg.ImageDesc = .{
.width = 256,
.height = 1,
.pixel_format = .RGBA8,
.min_filter = .NEAREST,
.mag_filter = .NEAREST,
.wrap_u = .CLAMP_TO_EDGE,
.wrap_v = .CLAMP_TO_EDGE,
};
img_desc.data.subimage[0][0] = sg.asRange(data.color_palette);
state.gfx.offscreen.palette_img = sg.makeImage(img_desc);
}
// setup resource binding structs
state.gfx.offscreen.bind.vertex_buffers[0] = state.gfx.offscreen.vbuf;
state.gfx.offscreen.bind.fs_images[0] = state.gfx.offscreen.tile_img;
state.gfx.offscreen.bind.fs_images[1] = state.gfx.offscreen.palette_img;
state.gfx.display.bind.vertex_buffers[0] = state.gfx.display.quad_vbuf;
state.gfx.display.bind.fs_images[0] = state.gfx.offscreen.render_target;
}
//--- audio system -------------------------------------------------------------
fn soundInit() void {
saudio.setup(.{});
// compute sample duration in nanoseconds
const samples_per_sec: i32 = saudio.sampleRate();
state.audio.sample_duration_ns = @divTrunc(1_000_000_000, samples_per_sec);
// compute number of 96kHz ticks per sample tick (the Namco sound
// generator runs at 96kHz), times 1000 for increased precision
state.audio.voice_tick_period = @divTrunc(96_000_000, samples_per_sec);
}
fn soundShutdown() void {
saudio.shutdown();
}
// update the Namco sound generator emulation, must be called at 96Khz
const WaveTableRom = @embedFile("roms/pacman_wavetable.rom");
fn soundVoiceTick() void {
for (state.audio.voices) |*voice| {
voice.counter +%= voice.frequency; // NOTE: add with wraparound
// lookup current 4-bit sample from waveform index and
// topmost 5 bits of the frequency counter
const wave_index: u8 = (@intCast(u8,voice.waveform) << 5) | @intCast(u8, voice.counter >> 15);
// sample is (-8..+7) * 16 -> -128 .. +127
const sample: i32 = (@intCast(i32, WaveTableRom[wave_index] & 0xF) - 8) * @intCast(i32, voice.volume);
voice.sample_acc += @intToFloat(f32, sample);
voice.sample_div += 128.0;
}
}
// the per-sample tick function must be called with the playback sample rate (e.g. 44.1kHz)
fn soundSampleTick() void {
var sm: f32 = 0.0;
for (state.audio.voices) |*voice| {
if (voice.sample_div > 0.0) {
sm += voice.sample_acc / voice.sample_div;
voice.sample_acc = 0.0;
voice.sample_div = 0.0;
}
}
data.sample_buffer[state.audio.num_samples] = sm * 0.33333 * AudioVolume;
state.audio.num_samples += 1;
if (state.audio.num_samples == NumSamples) {
_ = saudio.push(&data.sample_buffer[0], NumSamples);
state.audio.num_samples = 0;
}
}
// the sound systems per-frame function
fn soundFrame(frame_time_ns: i32) void {
// for each sample to generate...
state.audio.sample_accum -= frame_time_ns;
while (state.audio.sample_accum < 0) {
state.audio.sample_accum += state.audio.sample_duration_ns;
// tick the sound generator at 96kHz
state.audio.voice_tick_accum -= state.audio.voice_tick_period;
while (state.audio.voice_tick_accum < 0) {
state.audio.voice_tick_accum += 1000;
soundVoiceTick();
}
// generate new sample into local sample buffer, and push to sokol-audio if buffer full
soundSampleTick();
}
}
// the sound system's 60Hz tick function which takes care of sound-effect playback
fn soundTick() void {
for (state.audio.sounds) |*sound, sound_slot| {
if (sound.func) |func| {
// this is a procedural sound effect
func(sound_slot);
}
else if (sound.dump) |dump| {
// this is a register dump sound effect
if (sound.cur_tick == sound.num_ticks) {
soundStop(sound_slot);
continue;
}
// decode register dump values into voice registers
var dump_index = sound.cur_tick * sound.stride;
for (state.audio.voices) |*voice, i| {
if (sound.voice[i]) {
const val: u32 = dump[dump_index];
dump_index += 1;
// FIXME Zig: intCasts shouldn't be necessary here, because the '&'
// ensures that the result fits?
// 20 bits frequency
voice.frequency = @intCast(u20, val & ((1<<20)-1));
// 3 bits waveform
voice.waveform = @intCast(u3, (val>>24) & 7);
// 4 bits volume
voice.volume = @intCast(u4, (val>>28) & 15);
}
}
}
sound.cur_tick += 1;
}
}
// clear all active sound effects and start outputting silence
fn soundClear() void {
for (state.audio.voices) |*voice| {
voice.* = .{};
}
for (state.audio.sounds) |*sound| {
sound.* = .{};
}
}
// stop a sound effect
fn soundStop(sound_slot: usize) void {
for (state.audio.voices) |*voice, i| {
if (state.audio.sounds[sound_slot].voice[i]) {
voice.* = .{};
}
}
state.audio.sounds[sound_slot] = .{};
}
// start a sound effect
fn soundStart(sound_slot: usize, desc: SoundDesc) void {
var sound = &state.audio.sounds[sound_slot];
sound.* = .{};
sound.voice = desc.voice;
sound.func = desc.func;
sound.dump = desc.dump;
if (sound.dump) |dump| {
for (sound.voice) |voice_active| {
if (voice_active) {
sound.stride += 1;
}
}
assert(sound.stride > 0);
sound.num_ticks = @intCast(u32, dump.len) / sound.stride;
}
}
// start procedural sound effect to eat dot (there's two separate
// sound effects for eating dots, one going up and one going down)
fn soundEatDot(dots_eaten: u32) void {
if (0 != (dots_eaten & 1)) {
soundStart(2, .{
.func = soundFuncEatDot1,
.voice = .{ false, false, true }
});
}
else {
soundStart(2, .{
.func = soundFuncEatDot2,
.voice = .{ false, false, true }
});
}
}
// start sound effect for playing the prelude song, this is a register dump effect
fn soundPrelude() void {
soundStart(0, .{
.dump = SoundDumpPrelude[0..],
.voice = .{ true, true, false }
});
}
// start the Pacman dying sound effect
fn soundDead() void {
soundStart(2, .{
.dump = SoundDumpDead[0..],
.voice = .{ false, false, true }
});
}
// start sound effect to eat a ghost
fn soundEatGhost() void {
soundStart(2, .{
.func = soundFuncEatGhost,
.voice = .{ false, false, true }
});
}
// start sound effect for eating the bonus fruit
fn soundEatFruit() void {
soundStart(2, .{
.func = soundFuncEatFruit,
.voice = .{ false, false, true }
});
}
// start the "weeooh" sound effect which plays in the background
fn soundWeeooh() void {
soundStart(1, .{
.func = soundFuncWeeooh,
.voice = .{ false, true, false }
});
}
// start the frightened sound (replaces the weeooh sound after energizer pill eaten)
fn soundFrightened() void {
soundStart(1, .{
.func = soundFuncFrightened,
.voice = .{ false, true, false }
});
}
// procedural sound effect callback functions
fn soundFuncEatDot1(slot: usize) void {
const sound = &state.audio.sounds[slot];
var voice = &state.audio.voices[2];
if (sound.cur_tick == 0) {
voice.volume = 12;
voice.waveform = 2;
voice.frequency = 0x1500;
}
else if (sound.cur_tick == 5) {
soundStop(slot);
}
else {
voice.frequency -= 0x300;
}
}
fn soundFuncEatDot2(slot: usize) void {
const sound = &state.audio.sounds[slot];
var voice = &state.audio.voices[2];
if (sound.cur_tick == 0) {
voice.volume = 12;
voice.waveform = 2;
voice.frequency = 0x700;
}
else if (sound.cur_tick == 5) {
soundStop(slot);
}
else {
voice.frequency += 0x300;
}
}
fn soundFuncEatGhost(slot: usize) void {
const sound = &state.audio.sounds[slot];
var voice = &state.audio.voices[2];
if (sound.cur_tick == 0) {
voice.volume = 12;
voice.waveform = 5;
voice.frequency = 0;
}
else if (sound.cur_tick == 32) {
soundStop(slot);
}
else {
voice.frequency += 20;
}
}
fn soundFuncEatFruit(slot: usize) void {
const sound = &state.audio.sounds[slot];
var voice = &state.audio.voices[2];
if (sound.cur_tick == 0) {
voice.volume = 15;
voice.waveform = 6;
voice.frequency = 0x1600;
}
else if (sound.cur_tick == 23) {
soundStop(slot);
}
else if (sound.cur_tick < 11) {
voice.frequency -= 0x200;
}
else {
voice.frequency += 0x200;
}
}
fn soundFuncWeeooh(slot: usize) void {
const sound = &state.audio.sounds[slot];
var voice = &state.audio.voices[1];
if (sound.cur_tick == 0) {
voice.volume = 6;
voice.waveform = 6;
voice.frequency = 0x1000;
}
else if ((sound.cur_tick % 24) < 12) {
voice.frequency += 0x200;
}
else {
voice.frequency -= 0x200;
}
}
fn soundFuncFrightened(slot: usize) void {
const sound = &state.audio.sounds[slot];
var voice = &state.audio.voices[1];
if (sound.cur_tick == 0) {
voice.volume = 10;
voice.waveform = 4;
voice.frequency = 0x180;
}
else if ((sound.cur_tick % 8) == 0) {
voice.frequency = 0x180;
}
else {
voice.frequency += 0x180;
}
}
//--- sokol-app callbacks ------------------------------------------------------
export fn init() void {
stm.setup();
gfxInit();
soundInit();
if (DbgSkipIntro) {
start(&state.game.started);
}
else {
start(&state.intro.started);
}
}
export fn frame() void {
// run the game at a fixed tick rate regardless of frame rate
var frame_time_ns = stm.ns(stm.laptime(&state.timing.laptime_store));
// clamp max frame duration (so the timing isn't messed up when stepping in debugger)
if (frame_time_ns > MaxFrameTimeNS) {
frame_time_ns = MaxFrameTimeNS;
}
state.timing.tick_accum += @floatToInt(i32, frame_time_ns);
while (state.timing.tick_accum > -TickToleranceNS) {
state.timing.tick_accum -= TickDurationNS;
state.timing.tick += 1;
// call the per-tick sound update function
soundTick();
// check for game mode change
if (now(state.intro.started)) {
state.game_mode = .Intro;
}
if (now(state.game.started)) {
state.game_mode = .Game;
}
// call the top-level game mode tick function
switch (state.game_mode) {
.Intro => introTick(),
.Game => gameTick(),
}
}
gfxFrame();
soundFrame(@floatToInt(i32, frame_time_ns));
}
export fn input(ev: ?*const sapp.Event) void {
const event = ev.?;
if ((event.type == .KEY_DOWN) or (event.type == .KEY_UP)) {
const key_pressed = event.type == .KEY_DOWN;
if (state.input.enabled) {
state.input.anykey = key_pressed;
switch (event.key_code) {
.W, .UP, => state.input.up = key_pressed,
.S, .DOWN, => state.input.down = key_pressed,
.A, .LEFT, => state.input.left = key_pressed,
.D, .RIGHT, => state.input.right = key_pressed,
.ESCAPE => state.input.esc = key_pressed,
else => {}
}
}
}
}
export fn cleanup() void {
soundShutdown();
gfxShutdown();
}
pub fn main() void {
sapp.run(.{
.init_cb = init,
.frame_cb = frame,
.event_cb = input,
.cleanup_cb = cleanup,
.width = 2 * DisplayPixelsX,
.height = 2 * DisplayPixelsY,
.window_title = "pacman.zig"
});
}
//-- Sound Effect Register Dumps -----------------------------------------------
// Each line is a 'register dump' for one 60Hz tick. Each 32-bit number
// encodes the per-voice values for frequency, waveform and volume:
//
// 31 0 bit
// |vvvv-www----ffffffffffffffffffff|
// | | |
// | | +-- 20 bits frequency
// | +-- 3 bits waveform
// +-- 4 bits volume
const SoundDumpPrelude = [490]u32 {
0xE20002E0, 0xF0001700,
0xD20002E0, 0xF0001700,
0xC20002E0, 0xF0001700,
0xB20002E0, 0xF0001700,
0xA20002E0, 0xF0000000,
0x920002E0, 0xF0000000,
0x820002E0, 0xF0000000,
0x720002E0, 0xF0000000,
0x620002E0, 0xF0002E00,
0x520002E0, 0xF0002E00,
0x420002E0, 0xF0002E00,
0x320002E0, 0xF0002E00,
0x220002E0, 0xF0000000,
0x120002E0, 0xF0000000,
0x020002E0, 0xF0000000,
0xE2000000, 0xF0002280,
0xD2000000, 0xF0002280,
0xC2000000, 0xF0002280,
0xB2000000, 0xF0002280,
0xA2000000, 0xF0000000,
0x92000000, 0xF0000000,
0x82000000, 0xF0000000,
0x72000000, 0xF0000000,
0xE2000450, 0xF0001D00,
0xD2000450, 0xF0001D00,
0xC2000450, 0xF0001D00,
0xB2000450, 0xF0001D00,
0xA2000450, 0xF0000000,
0x92000450, 0xF0000000,
0x82000450, 0xF0000000,
0x72000450, 0xF0000000,
0xE20002E0, 0xF0002E00,
0xD20002E0, 0xF0002E00,
0xC20002E0, 0xF0002E00,
0xB20002E0, 0xF0002E00,
0xA20002E0, 0xF0002280,
0x920002E0, 0xF0002280,
0x820002E0, 0xF0002280,
0x720002E0, 0xF0002280,
0x620002E0, 0xF0000000,
0x520002E0, 0xF0000000,
0x420002E0, 0xF0000000,
0x320002E0, 0xF0000000,
0x220002E0, 0xF0000000,
0x120002E0, 0xF0000000,
0x020002E0, 0xF0000000,
0xE2000000, 0xF0001D00,
0xD2000000, 0xF0001D00,
0xC2000000, 0xF0001D00,
0xB2000000, 0xF0001D00,
0xA2000000, 0xF0001D00,
0x92000000, 0xF0001D00,
0x82000000, 0xF0001D00,
0x72000000, 0xF0001D00,
0xE2000450, 0xF0000000,
0xD2000450, 0xF0000000,
0xC2000450, 0xF0000000,
0xB2000450, 0xF0000000,
0xA2000450, 0xF0000000,
0x92000450, 0xF0000000,
0x82000450, 0xF0000000,
0x72000450, 0xF0000000,
0xE2000308, 0xF0001840,
0xD2000308, 0xF0001840,
0xC2000308, 0xF0001840,
0xB2000308, 0xF0001840,
0xA2000308, 0xF0000000,
0x92000308, 0xF0000000,
0x82000308, 0xF0000000,
0x72000308, 0xF0000000,
0x62000308, 0xF00030C0,
0x52000308, 0xF00030C0,
0x42000308, 0xF00030C0,
0x32000308, 0xF00030C0,
0x22000308, 0xF0000000,
0x12000308, 0xF0000000,
0x02000308, 0xF0000000,
0xE2000000, 0xF0002480,
0xD2000000, 0xF0002480,
0xC2000000, 0xF0002480,
0xB2000000, 0xF0002480,
0xA2000000, 0xF0000000,
0x92000000, 0xF0000000,
0x82000000, 0xF0000000,
0x72000000, 0xF0000000,
0xE2000490, 0xF0001EC0,
0xD2000490, 0xF0001EC0,
0xC2000490, 0xF0001EC0,
0xB2000490, 0xF0001EC0,
0xA2000490, 0xF0000000,
0x92000490, 0xF0000000,
0x82000490, 0xF0000000,
0x72000490, 0xF0000000,
0xE2000308, 0xF00030C0,
0xD2000308, 0xF00030C0,
0xC2000308, 0xF00030C0,
0xB2000308, 0xF00030C0,
0xA2000308, 0xF0002480,
0x92000308, 0xF0002480,
0x82000308, 0xF0002480,
0x72000308, 0xF0002480,
0x62000308, 0xF0000000,
0x52000308, 0xF0000000,
0x42000308, 0xF0000000,
0x32000308, 0xF0000000,
0x22000308, 0xF0000000,
0x12000308, 0xF0000000,
0x02000308, 0xF0000000,
0xE2000000, 0xF0001EC0,
0xD2000000, 0xF0001EC0,
0xC2000000, 0xF0001EC0,
0xB2000000, 0xF0001EC0,
0xA2000000, 0xF0001EC0,
0x92000000, 0xF0001EC0,
0x82000000, 0xF0001EC0,
0x72000000, 0xF0001EC0,
0xE2000490, 0xF0000000,
0xD2000490, 0xF0000000,
0xC2000490, 0xF0000000,
0xB2000490, 0xF0000000,
0xA2000490, 0xF0000000,
0x92000490, 0xF0000000,
0x82000490, 0xF0000000,
0x72000490, 0xF0000000,
0xE20002E0, 0xF0001700,
0xD20002E0, 0xF0001700,
0xC20002E0, 0xF0001700,
0xB20002E0, 0xF0001700,
0xA20002E0, 0xF0000000,
0x920002E0, 0xF0000000,
0x820002E0, 0xF0000000,
0x720002E0, 0xF0000000,
0x620002E0, 0xF0002E00,
0x520002E0, 0xF0002E00,
0x420002E0, 0xF0002E00,
0x320002E0, 0xF0002E00,
0x220002E0, 0xF0000000,
0x120002E0, 0xF0000000,
0x020002E0, 0xF0000000,
0xE2000000, 0xF0002280,
0xD2000000, 0xF0002280,
0xC2000000, 0xF0002280,
0xB2000000, 0xF0002280,
0xA2000000, 0xF0000000,
0x92000000, 0xF0000000,
0x82000000, 0xF0000000,
0x72000000, 0xF0000000,
0xE2000450, 0xF0001D00,
0xD2000450, 0xF0001D00,
0xC2000450, 0xF0001D00,
0xB2000450, 0xF0001D00,
0xA2000450, 0xF0000000,
0x92000450, 0xF0000000,
0x82000450, 0xF0000000,
0x72000450, 0xF0000000,
0xE20002E0, 0xF0002E00,
0xD20002E0, 0xF0002E00,
0xC20002E0, 0xF0002E00,
0xB20002E0, 0xF0002E00,
0xA20002E0, 0xF0002280,
0x920002E0, 0xF0002280,
0x820002E0, 0xF0002280,
0x720002E0, 0xF0002280,
0x620002E0, 0xF0000000,
0x520002E0, 0xF0000000,
0x420002E0, 0xF0000000,
0x320002E0, 0xF0000000,
0x220002E0, 0xF0000000,
0x120002E0, 0xF0000000,
0x020002E0, 0xF0000000,
0xE2000000, 0xF0001D00,
0xD2000000, 0xF0001D00,
0xC2000000, 0xF0001D00,
0xB2000000, 0xF0001D00,
0xA2000000, 0xF0001D00,
0x92000000, 0xF0001D00,
0x82000000, 0xF0001D00,
0x72000000, 0xF0001D00,
0xE2000450, 0xF0000000,
0xD2000450, 0xF0000000,
0xC2000450, 0xF0000000,
0xB2000450, 0xF0000000,
0xA2000450, 0xF0000000,
0x92000450, 0xF0000000,
0x82000450, 0xF0000000,
0x72000450, 0xF0000000,
0xE2000450, 0xF0001B40,
0xD2000450, 0xF0001B40,
0xC2000450, 0xF0001B40,
0xB2000450, 0xF0001B40,
0xA2000450, 0xF0001D00,
0x92000450, 0xF0001D00,
0x82000450, 0xF0001D00,
0x72000450, 0xF0001D00,
0x62000450, 0xF0001EC0,
0x52000450, 0xF0001EC0,
0x42000450, 0xF0001EC0,
0x32000450, 0xF0001EC0,
0x22000450, 0xF0000000,
0x12000450, 0xF0000000,
0x02000450, 0xF0000000,
0xE20004D0, 0xF0001EC0,
0xD20004D0, 0xF0001EC0,
0xC20004D0, 0xF0001EC0,
0xB20004D0, 0xF0001EC0,
0xA20004D0, 0xF0002080,
0x920004D0, 0xF0002080,
0x820004D0, 0xF0002080,
0x720004D0, 0xF0002080,
0x620004D0, 0xF0002280,
0x520004D0, 0xF0002280,
0x420004D0, 0xF0002280,
0x320004D0, 0xF0002280,
0x220004D0, 0xF0000000,
0x120004D0, 0xF0000000,
0x020004D0, 0xF0000000,
0xE2000568, 0xF0002280,
0xD2000568, 0xF0002280,
0xC2000568, 0xF0002280,
0xB2000568, 0xF0002280,
0xA2000568, 0xF0002480,
0x92000568, 0xF0002480,
0x82000568, 0xF0002480,
0x72000568, 0xF0002480,
0x62000568, 0xF0002680,
0x52000568, 0xF0002680,
0x42000568, 0xF0002680,
0x32000568, 0xF0002680,
0x22000568, 0xF0000000,
0x12000568, 0xF0000000,
0x02000568, 0xF0000000,
0xE20005C0, 0xF0002E00,
0xD20005C0, 0xF0002E00,
0xC20005C0, 0xF0002E00,
0xB20005C0, 0xF0002E00,
0xA20005C0, 0xF0002E00,
0x920005C0, 0xF0002E00,
0x820005C0, 0xF0002E00,
0x720005C0, 0xF0002E00,
0x620005C0, 0x00000E80,
0x520005C0, 0x00000E80,
0x420005C0, 0x00000E80,
0x320005C0, 0x00000E80,
0x220005C0, 0x00000E80,
0x120005C0, 0x00000E80,
};
const SoundDumpDead = [90]u32 {
0xF1001F00,
0xF1001E00,
0xF1001D00,
0xF1001C00,
0xF1001B00,
0xF1001C00,
0xF1001D00,
0xF1001E00,
0xF1001F00,
0xF1002000,
0xF1002100,
0xE1001D00,
0xE1001C00,
0xE1001B00,
0xE1001A00,
0xE1001900,
0xE1001800,
0xE1001900,
0xE1001A00,
0xE1001B00,
0xE1001C00,
0xE1001D00,
0xE1001E00,
0xD1001B00,
0xD1001A00,
0xD1001900,
0xD1001800,
0xD1001700,
0xD1001600,
0xD1001700,
0xD1001800,
0xD1001900,
0xD1001A00,
0xD1001B00,
0xD1001C00,
0xC1001900,
0xC1001800,
0xC1001700,
0xC1001600,
0xC1001500,
0xC1001400,
0xC1001500,
0xC1001600,
0xC1001700,
0xC1001800,
0xC1001900,
0xC1001A00,
0xB1001700,
0xB1001600,
0xB1001500,
0xB1001400,
0xB1001300,
0xB1001200,
0xB1001300,
0xB1001400,
0xB1001500,
0xB1001600,
0xB1001700,
0xB1001800,
0xA1001500,
0xA1001400,
0xA1001300,
0xA1001200,
0xA1001100,
0xA1001000,
0xA1001100,
0xA1001200,
0x80000800,
0x80001000,
0x80001800,
0x80002000,
0x80002800,
0x80003000,
0x80003800,
0x80004000,
0x80004800,
0x80005000,
0x80005800,
0x00000000,
0x80000800,
0x80001000,
0x80001800,
0x80002000,
0x80002800,
0x80003000,
0x80003800,
0x80004000,
0x80004800,
0x80005000,
0x80005800,
}; | src/pacman.zig |
const std = @import("std");
const vk = @import("../../vk.zig");
const RGResource = @import("render_graph_resource.zig").RGResource;
const RenderGraph = @import("render_graph.zig").RenderGraph;
const SyncPoint = @import("resources/sync_point.zig").SyncPoint;
const ResourceList = std.ArrayList(*RGResource);
const PassList = std.ArrayList(*RGPass);
pub const RGPass = struct {
const PassFunction = fn (render_pass: *RGPass) void;
const RenderFunction = fn (render_pass: *RGPass, command_buffer: vk.CommandBuffer, frame_index: u32) void;
name: []const u8,
writes_to: ResourceList,
reads_from: ResourceList,
initFn: PassFunction,
deinitFn: PassFunction,
renderFn: RenderFunction,
load_op: vk.AttachmentLoadOp,
initial_layout: vk.ImageLayout,
final_layout: vk.ImageLayout,
sync_point: SyncPoint,
pipeline_start: vk.PipelineStageFlags = .{ .top_of_pipe_bit = true },
pipeline_end: vk.PipelineStageFlags = .{ .bottom_of_pipe_bit = true },
pub fn init(self: *RGPass, comptime name: []const u8, allocator: std.mem.Allocator, initFn: PassFunction, deinitFn: PassFunction, renderFn: RenderFunction) void {
self.name = name;
self.initFn = initFn;
self.deinitFn = deinitFn;
self.renderFn = renderFn;
self.writes_to = ResourceList.init(allocator);
self.reads_from = ResourceList.init(allocator);
self.load_op = .clear;
self.initial_layout = .@"undefined";
self.final_layout = .present_src_khr;
self.sync_point.rg_resource.init(name ++ "'s Sync Point", allocator);
self.appendReadResource(&self.sync_point.rg_resource);
}
pub fn deinit(self: *RGPass) void {
self.sync_point.rg_resource.deinit();
self.writes_to.deinit();
self.reads_from.deinit();
}
fn appendResource(self: *RGPass, list: *ResourceList, res_list: *PassList, res: *RGResource) void {
list.append(res) catch unreachable;
res_list.append(self) catch unreachable;
}
pub fn appendWriteResource(self: *RGPass, res: *RGResource) void {
self.appendResource(&self.writes_to, &res.writers, res);
}
pub fn appendReadResource(self: *RGPass, res: *RGResource) void {
self.appendResource(&self.reads_from, &res.readers, res);
}
fn removeResource(self: *RGPass, list: *ResourceList, res_list: *PassList, res: *RGResource) void {
for (list.items) |r, ind| {
if (r == res) {
_ = list.swapRemove(ind);
break;
}
}
for (res_list.items) |p, ind| {
if (p == self) {
_ = res_list.swapRemove(ind);
break;
}
}
}
pub fn removeWriteResource(self: *RGPass, res: *RGResource) void {
self.removeResource(&self.writes_to, &res.writers, res);
}
pub fn removeReadResource(self: *RGPass, res: *RGResource) void {
self.removeResource(&self.reads_from, &res.readers, res);
}
}; | src/renderer/render_graph/render_graph_pass.zig |
const std = @import("std");
const zCord = @import("zCord");
const analBuddy = @import("analysis-buddy");
const format = @import("format.zig");
const util = @import("util.zig");
const WorkContext = @This();
allocator: *std.mem.Allocator,
zcord_client: zCord.Client,
github_auth_token: ?[]const u8,
prng: std.rand.DefaultPrng,
prepared_anal: analBuddy.PrepareResult,
last_reload: usize,
timer: std.time.Timer,
ask_mailbox: util.Mailbox(Ask, 16),
ask_thread: std.Thread,
var reload_counter: usize = 0;
pub fn reload() void {
reload_counter += 1;
}
pub const Ask = struct {
text: *util.PoolString,
channel_id: zCord.Snowflake(.channel),
source_msg_id: zCord.Snowflake(.message),
};
pub fn create(allocator: *std.mem.Allocator, zcord_client: zCord.Client, ziglib: []const u8, github_auth_token: ?[]const u8) !*WorkContext {
const result = try allocator.create(WorkContext);
errdefer allocator.destroy(result);
result.allocator = allocator;
result.zcord_client = zcord_client;
result.github_auth_token = github_auth_token;
result.prng = std.rand.DefaultPrng.init(@bitCast(u64, std.time.timestamp()));
result.prepared_anal = try analBuddy.prepare(allocator, ziglib);
errdefer result.prepared_anal.deinit();
result.last_reload = reload_counter;
result.timer = try std.time.Timer.start();
result.ask_mailbox = .{};
result.ask_thread = try std.Thread.spawn(.{}, askHandler, .{result});
return result;
}
pub fn askHandler(self: *WorkContext) void {
while (true) {
const ask = self.ask_mailbox.get();
self.askOne(ask) catch |err| {
std.debug.print("{s}\n", .{err});
};
}
}
pub fn askOne(self: *WorkContext, ask: Ask) !void {
const swh = util.Swhash(16);
const ask_text = ask.text.array.slice();
defer ask.text.destroy();
switch (swh.match(ask_text)) {
swh.case("status") => {
const RUSAGE_SELF = 0;
const rusage = std.os.getrusage(RUSAGE_SELF);
//const rusage = std.os.getrusage(std.os.system.RUSAGE_SELF);
const cpu_sec = (rusage.utime.tv_sec + rusage.stime.tv_sec) * 1000;
const cpu_us = @divFloor(rusage.utime.tv_usec + rusage.stime.tv_usec, 1000);
var buf: [0x1000]u8 = undefined;
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "",
.description = &.{
std.fmt.bufPrint(
&buf,
\\```
\\Uptime: {}
\\CPU time: {}
\\Max RSS: {:.3}
\\```
,
.{
format.time(@intCast(i64, self.timer.read() / std.time.ns_per_ms)),
format.time(cpu_sec + cpu_us),
std.fmt.fmtIntSizeBin(@intCast(u64, rusage.maxrss)),
},
) catch unreachable,
},
});
return;
},
swh.case("zen") => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "For Great Justice",
.description = &.{
\\```
\\A. Communicate intent precisely.
\\B. Edge cases matter.
\\C. Favor reading code over writing code.
\\D. Only one obvious way to do things.
\\E. Runtime crashes are better than bugs.
\\F. Compile errors are better than runtime crashes.
\\G. Incremental improvements.
\\H. Avoid local maximums.
\\I. Reduce the amount one must remember.
\\J. Focus on code rather than style.
\\K. Resource allocation may fail; resource deallocation must succeed.
\\L. Memory is a resource.
\\M. Together we serve the users.
\\```
},
});
return;
},
swh.case("zenlang"),
swh.case("v"),
swh.case("vlang"),
=> {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "bruh",
});
return;
},
swh.case("u0") => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "Zig's billion dollar mistake™",
.description = &.{"https://github.com/ziglang/zig/issues/1530#issuecomment-422113755"},
});
return;
},
swh.case("tater") => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "",
.image = "https://memegenerator.net/img/instances/41913604.jpg",
});
return;
},
swh.case("5076"), swh.case("ziglang/zig#5076") => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.color = .green,
.title = "ziglang/zig — issue #5076",
.description = &.{
\\~~[syntax: drop the `const` keyword in global scopes](https://github.com/ziglang/zig/issues/5076)~~
\\https://www.youtube.com/watch?v=880uR25pP5U
},
});
return;
},
swh.case("submodule"), swh.case("submodules") => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "git submodules are the devil — _andrewrk_",
.description = &.{"https://github.com/ziglang/zig-bootstrap/issues/17#issuecomment-609980730"},
});
return;
},
swh.case("2.718"), swh.case("2.71828") => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "",
.image = "https://camo.githubusercontent.com/7f0d955df2205a170bf1582105c319ec6b00ec5c/68747470733a2f2f692e696d67666c69702e636f6d2f34646d7978702e6a7067",
});
return;
},
swh.case("bruh") => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "",
.image = "https://user-images.githubusercontent.com/106511/86198112-6718ba00-bb46-11ea-92fd-d006b462c5b1.jpg",
});
return;
},
swh.case("dab") => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "I promised I would dab and say “bruh” — _andrewrk_",
.description = &.{"https://vimeo.com/492676992"},
.image = "https://user-images.githubusercontent.com/219422/138796179-983cfd79-646e-4293-b46b-412ef0485101.jpg",
});
return;
},
swh.case("stage1") => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "",
.image = "https://user-images.githubusercontent.com/219422/138794956-0f355d35-f99a-462c-a363-8b58f4e38c0e.png",
});
return;
},
else => {},
}
if (std.mem.startsWith(u8, ask_text, "run")) {
const run = parseRun(ask_text) catch |e| switch (e) {
error.InvalidInput => {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "Error - expected format:",
.description = &.{
\\%%run \`\`\`
\\// write your code here
\\\`\`\`
},
});
return;
},
};
const has_fns = std.mem.indexOf(u8, run, "fn ") != null;
const has_import_std = std.mem.indexOf(u8, run, "@import(\"std\")") != null;
const msg_id = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = "*Run pending...*",
.description = &.{},
});
const import_std = "const std = @import(\"std\");\n";
const fn_main = "pub fn main() anyerror!void {\n";
const fn_main_end = " }\n";
const b = comptime util.boolMatcher(2);
const segments = switch (b(.{ has_import_std, has_fns })) {
b(.{ false, false }) => &[_][]const u8{ import_std, fn_main, run, fn_main_end },
b(.{ false, true }) => &[_][]const u8{ import_std, run },
b(.{ true, false }) => &[_][]const u8{ fn_main, run, fn_main_end },
b(.{ true, true }) => &[_][]const u8{run},
};
var stdout_buffer: [1024]u8 = undefined;
var stderr_buffer: [1024]u8 = undefined;
const ran = self.requestRun(segments, stdout_buffer[3..1021], stderr_buffer[3..1000]) catch |e| {
const output = switch (e) {
error.TooManyRequests => "***Too many requests***",
else => "***Unknown error***",
};
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .edit = msg_id },
.title = "Run error",
.description = &.{output},
});
return e;
};
const all_fields = [_]EmbedField{
.{ .name = "stdout", .value = wrapString(ran.stdout, "```") },
.{ .name = "stderr", .value = wrapString(ran.stderr, "```") },
};
const fields = switch (b(.{ ran.stdout.len > 0, ran.stderr.len > 0 })) {
b(.{ false, false }) => &[0]EmbedField{},
b(.{ true, false }) => all_fields[0..1],
b(.{ false, true }) => all_fields[1..],
b(.{ true, true }) => all_fields[0..],
};
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .edit = msg_id },
.title = "Run Results",
.description = if (fields.len == 0) &[_][]const u8{"***No Output***"} else &.{},
.fields = fields,
});
return;
}
if (try self.maybeGithubIssue(ask_text)) |issue| {
const is_pull_request = std.mem.indexOf(u8, issue.html_url.constSlice(), "/pull/") != null;
const label = if (is_pull_request) "pull" else "issue";
const repo = if (std.mem.indexOfScalar(u8, ask_text, '#')) |pound|
ask_text[0..pound]
else
"ziglang/zig";
var title_buf: [0x1000]u8 = undefined;
const title = try std.fmt.bufPrint(&title_buf, "{s} — {s} #{d}", .{
repo,
label,
issue.number,
});
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = title,
.description = &.{
"[",
issue.title.constSlice(),
"](",
issue.html_url.constSlice(),
")",
},
.color = if (is_pull_request) HexColor.blue else HexColor.green,
});
} else if (try self.maybeXKCD(ask_text)) |comic| {
var url_buf: [0x100]u8 = undefined;
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = comic.title.constSlice(),
.description = &.{
"[",
comic.alt.constSlice(),
"](",
try std.fmt.bufPrint(&url_buf, "https://xkcd.com/{d}", .{comic.num}),
")",
},
.image = comic.img.constSlice(),
.color = .blue,
});
} else {
var arena = std.heap.ArenaAllocator.init(self.allocator);
defer arena.deinit();
if (self.last_reload != reload_counter) {
try self.prepared_anal.reloadCached(&arena);
self.last_reload = reload_counter;
}
if (try self.prepared_anal.analyse(&arena, ask_text)) |match| {
_ = try self.sendDiscordMessage(.{
.channel_id = ask.channel_id,
.target_msg_id = .{ .reply = ask.source_msg_id },
.title = ask_text,
.description = &.{std.mem.trim(u8, match, " \t\r\n")},
.color = .red,
});
}
}
}
// This breaks out of the passed-in buffer and prepends/postpends with wrapper text.
// Thar be dragons 🐉
fn wrapString(buffer: []u8, wrapper: []const u8) []u8 {
const start_ptr = buffer.ptr - wrapper.len;
const frame = start_ptr[0 .. buffer.len + 2 * wrapper.len];
std.mem.copy(u8, frame[0..], wrapper);
std.mem.copy(u8, frame[buffer.len + wrapper.len ..], wrapper);
return frame;
}
fn parseRun(ask: []const u8) ![]const u8 {
const langs = std.ComptimeStringMap(void, .{
.{ "c", {} },
.{ "go", {} },
.{ "rs", {} },
.{ "rust", {} },
.{ "batman", {} },
.{ "typescript", {} },
.{ "ts", {} },
.{ "kotlin", {} },
});
// we implement a rudimentary tokenizer
var b_num: u8 = 0;
var start_idx: usize = 0;
var end_idx: usize = 0;
var state: enum { start, maybe_text_lang, text } = .start;
for (ask) |c, i| {
// skip run
if (i < 4) continue;
switch (state) {
.start => switch (c) {
'`' => {
b_num += 1;
if (b_num == 3) {
b_num = 0;
state = .maybe_text_lang;
start_idx = i + 1;
}
},
' ', '\t', '\n' => continue,
else => return error.InvalidInput,
},
.maybe_text_lang => {
switch (c) {
'a'...'z',
'A'...'Z',
=> continue,
else => {
state = .text;
const maybe_lang = ask[start_idx..i];
if (langs.has(maybe_lang)) {
// Skip this "token" since it's the highlight language
start_idx = i + 1;
}
if (c == '`') {
b_num += 1;
}
},
}
},
.text => switch (c) {
'`' => {
b_num += 1;
if (b_num == 3) {
end_idx = i - 2;
break;
}
},
else => continue,
},
}
}
if (start_idx == 0) return error.InvalidInput;
if (end_idx == 0) return error.InvalidInput;
if (start_idx >= end_idx) return error.InvalidInput;
return ask[start_idx..end_idx];
}
test "parseRun" {
try std.testing.expectEqualStrings("never", try parseRun("run ```never```"));
try std.testing.expectEqualStrings("gonna", try parseRun("run ```gonna```"));
try std.testing.expectEqualStrings("give", try parseRun("run ```give```"));
try std.testing.expectEqualStrings("you", try parseRun("run ```you```"));
try std.testing.expectEqualStrings("up", try parseRun("run ```up```"));
try std.testing.expectEqualStrings("nail", try parseRun("run ```rust nail```"));
try std.testing.expectEqualStrings("away", try parseRun("run ```go away```"));
try std.testing.expectEqualStrings("insert pun", try parseRun("run ```typescript insert pun```"));
}
fn maybeGithubIssue(self: WorkContext, ask: []const u8) !?GithubIssue {
if (std.fmt.parseInt(u32, ask, 10)) |_| {
return try self.requestGithubIssue("ziglang/zig", ask);
} else |_| {}
const slash = std.mem.indexOfScalar(u8, ask, '/') orelse return null;
const pound = std.mem.indexOfScalar(u8, ask, '#') orelse return null;
if (slash > pound) return null;
return try self.requestGithubIssue(ask[0..pound], ask[pound + 1 ..]);
}
fn maybeXKCD(self: WorkContext, ask: []const u8) !?XKCDComic {
if (ask.len < 6) return null;
const commandName = "xkcd";
if (std.mem.eql(u8, commandName[0..], ask[0..4])) {
var xkcdNumber: u32 = try std.fmt.parseInt(u32, ask[5..], 10);
return try self.requestXKCDComic(xkcdNumber);
}
return null;
}
const EmbedField = struct { name: []const u8, value: []const u8 };
pub fn sendDiscordMessage(self: WorkContext, args: struct {
channel_id: zCord.Snowflake(.channel),
target_msg_id: union(enum) {
edit: zCord.Snowflake(.message),
reply: zCord.Snowflake(.message),
},
title: []const u8,
color: HexColor = HexColor.black,
description: []const []const u8 = &.{},
fields: []const EmbedField = &.{},
image: ?[]const u8 = null,
}) !zCord.Snowflake(.message) {
var path_buf: [0x100]u8 = undefined;
const method: zCord.https.Request.Method = switch (args.target_msg_id) {
.edit => .PATCH,
.reply => .POST,
};
const path = switch (args.target_msg_id) {
.edit => |msg_id| try std.fmt.bufPrint(&path_buf, "/api/v6/channels/{d}/messages/{d}", .{ args.channel_id, msg_id }),
.reply => try std.fmt.bufPrint(&path_buf, "/api/v6/channels/{d}/messages", .{args.channel_id}),
};
// Zig has difficulty resolving these peer types
const image: ?struct { url: []const u8 } = if (args.image) |url| .{ .url = url } else null;
const message_reference: ?struct { message_id: zCord.Snowflake(.message) } = switch (args.target_msg_id) {
.reply => |msg_id| .{ .message_id = msg_id },
else => null,
};
const embed = .{
.title = args.title,
.color = @enumToInt(args.color),
.description = format.concat(args.description),
.fields = args.fields,
.image = image,
};
var req = try self.zcord_client.sendRequest(self.allocator, method, path, .{
.content = "",
.tts = false,
.embed = embed,
.message_reference = message_reference,
});
defer req.deinit();
const resp_code = req.response_code.?;
if (resp_code.group() == .success) {
try req.completeHeaders();
var stream = zCord.json.stream(req.client.reader());
const root = try stream.root();
if (try root.objectMatchOne("id")) |match| {
return try zCord.Snowflake(.message).consumeJsonElement(match.value);
}
return error.IdNotFound;
} else switch (resp_code) {
.client_too_many_requests => {
try req.completeHeaders();
var stream = zCord.json.stream(req.client.reader());
const root = try stream.root();
if (try root.objectMatchOne("retry_after")) |match| {
const sec = try match.value.number(f64);
// Don't bother trying for awhile
std.time.sleep(@floatToInt(u64, sec * std.time.ns_per_s));
}
return error.TooManyRequests;
},
else => {
std.debug.print("{} - {s}\n", .{ @enumToInt(resp_code), @tagName(resp_code) });
return error.UnknownRequestError;
},
}
}
pub fn requestRun(self: WorkContext, src: [][]const u8, stdout_buf: []u8, stderr_buf: []u8) !RunResult {
var req = try zCord.https.Request.init(.{
.allocator = self.allocator,
.host = "emkc.org",
.method = .POST,
.path = "/api/v1/piston/execute",
});
defer req.deinit();
try req.client.writeHeaderValue("Content-Type", "application/json");
const resp_code = try req.sendPrint("{}", .{
format.json(.{
.language = "zig",
.source = format.concat(src),
.stdin = "",
.args = [0][]const u8{},
}),
});
if (resp_code.group() != .success) {
switch (resp_code) {
.client_too_many_requests => return error.TooManyRequests,
else => {
std.debug.print("{} - {s}\n", .{ @enumToInt(resp_code), @tagName(resp_code) });
return error.UnknownRequestError;
},
}
}
try req.completeHeaders();
var stream = zCord.json.stream(req.client.reader());
const root = try stream.root();
var result = RunResult{
.stdout = stdout_buf[0..0],
.stderr = stderr_buf[0..0],
};
while (try root.objectMatch(enum { stdout, stderr })) |match| switch (match.key) {
.stdout => {
result.stdout = match.value.stringBuffer(stdout_buf) catch |err| switch (err) {
error.StreamTooLong => stdout_buf,
else => |e| return e,
};
_ = try match.value.finalizeToken();
},
.stderr => {
result.stderr = match.value.stringBuffer(stderr_buf) catch |err| switch (err) {
error.StreamTooLong => stderr_buf,
else => |e| return e,
};
_ = try match.value.finalizeToken();
},
};
return result;
}
const XKCDComic = struct { num: u32, title: std.BoundedArray(u8, 0x100), img: std.BoundedArray(u8, 0x100), alt: std.BoundedArray(u8, 0x100) };
const GithubIssue = struct { number: u32, title: std.BoundedArray(u8, 0x100), html_url: std.BoundedArray(u8, 0x100) };
const RunResult = struct {
stdout: []u8,
stderr: []u8,
};
// from https://gist.github.com/thomasbnt/b6f455e2c7d743b796917fa3c205f812
const HexColor = enum(u24) {
black = 0,
aqua = 0x1ABC9C,
green = 0x2ECC71,
blue = 0x3498DB,
red = 0xE74C3C,
gold = 0xF1C40F,
_,
pub fn init(raw: u32) HexColor {
return @intToEnum(HexColor, raw);
}
};
pub fn requestGithubIssue(self: WorkContext, repo: []const u8, issue: []const u8) !GithubIssue {
var path: [0x100]u8 = undefined;
var req = try zCord.https.Request.init(.{
.allocator = self.allocator,
.host = "api.github.com",
.method = .GET,
.path = try std.fmt.bufPrint(&path, "/repos/{s}/issues/{s}", .{ repo, issue }),
});
defer req.deinit();
try req.client.writeHeaderValue("Accept", "application/json");
if (self.github_auth_token) |github_auth_token| {
try req.client.writeHeaderFormat("Authorization", "token {s}", .{github_auth_token});
}
const resp_code = try req.sendEmptyBody();
if (resp_code.group() != .success) {
std.debug.print("{} - {s}\n", .{ @enumToInt(resp_code), @tagName(resp_code) });
return error.UnknownRequestError;
}
try req.completeHeaders();
var stream = zCord.json.stream(req.client.reader());
const root = try stream.root();
return try root.pathMatch(GithubIssue);
}
pub fn requestXKCDComic(self: WorkContext, number: u32) !XKCDComic {
var path: [0x100]u8 = undefined;
var req = try zCord.https.Request.init(.{
.allocator = self.allocator,
.host = "xkcd.com",
.method = .GET,
.path = try std.fmt.bufPrint(&path, "/{d}/info.0.json", .{number}),
});
defer req.deinit();
try req.client.writeHeaderValue("Accept", "application/json");
try req.client.writeHeaderValue("Content-Type", "application/json");
const resp_code = try req.sendEmptyBody();
if (resp_code.group() != .success) {
std.debug.print("{} - {s}\n", .{ @enumToInt(resp_code), @tagName(resp_code) });
return error.UnknownRequestError;
}
try req.completeHeaders();
var stream = zCord.json.stream(req.client.reader());
const root = try stream.root();
return try root.pathMatch(XKCDComic);
} | src/WorkContext.zig |
const std = @import("std");
const Allocator = std.mem.Allocator;
const mem = std.mem;
const trait = std.meta.trait;
const asn1 = @import("asn1.zig");
// zig fmt: off
// http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
// @TODO add backing integer, values
pub const CurveId = enum {
sect163k1, sect163r1, sect163r2, sect193r1,
sect193r2, sect233k1, sect233r1, sect239k1,
sect283k1, sect283r1, sect409k1, sect409r1,
sect571k1, sect571r1, secp160k1, secp160r1,
secp160r2, secp192k1, secp192r1, secp224k1,
secp224r1, secp256k1, secp256r1, secp384r1,
secp521r1,brainpoolP256r1, brainpoolP384r1,
brainpoolP512r1, curve25519, curve448,
};
// zig fmt: on
pub const PublicKey = union(enum) {
/// RSA public key
rsa: struct {
//Positive std.math.big.int.Const numbers.
modulus: []const usize,
exponent: []const usize,
},
/// Elliptic curve public key
ec: struct {
id: CurveId,
/// Public curve point (uncompressed format)
curve_point: []const u8,
},
pub fn deinit(self: @This(), alloc: *Allocator) void {
switch (self) {
.rsa => |rsa| {
alloc.free(rsa.modulus);
alloc.free(rsa.exponent);
},
.ec => |ec| alloc.free(ec.curve_point),
}
}
};
pub fn DecodeDERError(comptime Reader: type) type {
return Reader.Error || error{
MalformedPEM,
MalformedDER,
EndOfStream,
OutOfMemory,
};
}
pub const TrustAnchor = struct {
/// Subject distinguished name
dn: []const u8,
/// A "CA" anchor is deemed fit to verify signatures on certificates.
/// A "non-CA" anchor is accepted only for direct trust (server's certificate
/// name and key match the anchor).
is_ca: bool = false,
public_key: PublicKey,
const CaptureState = struct {
self: *TrustAnchor,
allocator: *Allocator,
dn_allocated: bool = false,
pk_allocated: bool = false,
};
fn initSubjectDn(state: *CaptureState, tag_byte: u8, length: usize, reader: anytype) !void {
const dn_mem = try state.allocator.alloc(u8, length);
errdefer state.allocator.free(dn_mem);
try reader.readNoEof(dn_mem);
state.self.dn = dn_mem;
state.dn_allocated = true;
}
fn processExtension(state: *CaptureState, tag_byte: u8, length: usize, reader: anytype) !void {
const object_id = try asn1.der.parse_value(state.allocator, reader);
defer object_id.deinit(state.allocator);
if (object_id != .object_identifier) return error.DoesNotMatchSchema;
if (object_id.object_identifier.len != 4)
return;
const data = object_id.object_identifier.data;
// Basic constraints extension
if (data[0] != 2 or data[1] != 5 or data[2] != 29 or data[3] != 15)
return;
const basic_constraints = try asn1.der.parse_value(state.allocator, reader);
defer basic_constraints.deinit(state.allocator);
if (basic_constraints != .bool)
return error.DoesNotMatchSchema;
state.self.is_ca = basic_constraints.bool;
}
fn initExtensions(state: *CaptureState, tag_byte: u8, length: usize, reader: anytype) !void {
const schema = .{
.sequence_of,
.{ .capture, 0, .sequence },
};
const captures = .{
state, processExtension,
};
try asn1.der.parse_schema(schema, captures, reader);
}
fn initPublicKeyInfo(state: *CaptureState, tag_byte: u8, length: usize, reader: anytype) !void {
// @TODO Use reader.isBytes instead of parsing and a bunch of checks here.
// Or read and a couple of mem.eqls (read tag, check its seq, read min amnt of bytes, check, read rest, check else error)
const seq = try asn1.der.parse_value(state.allocator, reader);
defer seq.deinit(state.allocator);
if (seq != .sequence or seq.sequence.len != 2 or seq.sequence[0] != .object_identifier)
return error.DoesNotMatchSchema;
const oid_len = seq.sequence[0].object_identifier.len;
if (oid_len != 6 and oid_len != 7)
return error.DoesNotMatchSchema;
const data = seq.sequence[0].object_identifier.data;
if (oid_len == 7 and data[0] == 1 and data[1] == 2 and data[2] == 840 and data[3] == 113549 and
data[4] == 1 and data[5] == 1 and data[6] == 1)
{
if (seq.sequence[1] != .@"null")
return error.DoesNotMatchSchema;
// RSA key
{
// BitString next!
if ((try reader.readByte()) != 0x03)
return error.DoesNotMatchSchema;
_ = try asn1.der.parse_length(reader);
const bit_string_unused_bits = try reader.readByte();
if (bit_string_unused_bits != 0)
return error.DoesNotMatchSchema;
if ((try reader.readByte()) != 0x30)
return error.DoesNotMatchSchema;
_ = try asn1.der.parse_length(reader);
// @TODO Parse into []const u8s instead
// Modulus
const modulus = try asn1.der.parse_value(state.allocator, reader);
errdefer modulus.deinit(state.allocator);
if (modulus != .int or !modulus.int.positive) return error.DoesNotMatchSchema;
// Exponent
const exponent = try asn1.der.parse_value(state.allocator, reader);
errdefer exponent.deinit(state.allocator);
if (exponent != .int or !exponent.int.positive) return error.DoesNotMatchSchema;
state.self.public_key = .{
.rsa = .{
.modulus = modulus.int.limbs,
.exponent = exponent.int.limbs,
},
};
state.pk_allocated = true;
}
return;
}
if (oid_len == 6 and data[0] == 1 and data[1] == 2 and data[2] == 840 and data[3] == 10045 and
data[4] == 2 and data[5] == 1)
{
// We only support named curves, for which the parameter
// field is an OID.
if (seq.sequence[1] != .object_identifier)
return error.DoesNotMatchSchema;
const curve_oid = seq.sequence[1].object_identifier;
const curve_data = curve_oid.data[0..curve_oid.len];
// EC key
if (curve_data.len != 7 and curve_data.len != 5)
return error.DoesNotMatchSchema;
if (curve_data.len == 5 and curve_data[0] == 1 and curve_data[1] == 3 and curve_data[2] == 132 and
curve_data[3] == 0)
{
if (curve_data[4] == 34)
state.self.public_key = .{ .ec = .{ .id = .secp384r1, .curve_point = undefined } }
else if (curve_data[4] == 35)
state.self.public_key = .{ .ec = .{ .id = .secp521r1, .curve_point = undefined } }
else
return error.DoesNotMatchSchema;
} else if (curve_data.len == 7 and curve_data[0] == 1 and curve_data[1] == 2 and curve_data[2] == 840 and
curve_data[3] == 10045 and curve_data[4] == 3 and curve_data[5] == 1 and curve_data[6] == 7)
{
state.self.public_key = .{ .ec = .{ .id = .secp256r1, .curve_point = undefined } };
} else {
return error.DoesNotMatchSchema;
}
const ec_bit_string = try asn1.der.parse_value(state.allocator, reader);
errdefer ec_bit_string.deinit(state.allocator);
if (ec_bit_string != .bit_string or ec_bit_string.bit_string.bit_len % 8 != 0)
return error.DoesNotMatchSchema;
state.self.public_key.ec.curve_point = ec_bit_string.bit_string.data;
state.pk_allocated = true;
return;
}
return error.DoesNotMatchSchema;
}
/// Initialize a trusted anchor from distinguished encoding rules (DER) encoded data
pub fn create(allocator: *Allocator, der_reader: anytype) DecodeDERError(@TypeOf(der_reader))!@This() {
var self: @This() = undefined;
self.is_ca = false;
// https://tools.ietf.org/html/rfc5280#page-117
const schema = .{
.sequence, .{
// tbsCertificate
.{
.sequence,
.{
.{ .context_specific, 0 }, // version
.{.int}, // serialNumber
.{.sequence}, // signature
.{.sequence}, // issuer
.{.sequence}, // validity,
.{ .capture, 0, .sequence }, // subject
.{ .capture, 1, .sequence }, // subjectPublicKeyInfo
.{ .optional, .context_specific, 1 }, // issuerUniqueID
.{ .optional, .context_specific, 2 }, // subjectUniqueID
.{ .capture, 2, .optional, .context_specific, 3 }, // extensions
},
},
// signatureAlgorithm
.{.sequence},
// signatureValue
.{.bit_string},
},
};
var capture_state = CaptureState{
.self = &self,
.allocator = allocator,
};
const captures = .{
&capture_state, initSubjectDn,
&capture_state, initPublicKeyInfo,
&capture_state, initExtensions,
};
errdefer {
if (capture_state.dn_allocated)
allocator.free(self.dn);
if (capture_state.pk_allocated)
self.public_key.deinit(allocator);
}
asn1.der.parse_schema(schema, captures, der_reader) catch |err| switch (err) {
error.InvalidLength,
error.InvalidTag,
error.InvalidContainerLength,
error.DoesNotMatchSchema,
=> return error.MalformedDER,
else => |e| return e,
};
return self;
}
pub fn deinit(self: @This(), alloc: *Allocator) void {
alloc.free(self.dn);
self.public_key.deinit(alloc);
}
pub fn format(self: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
try writer.print(
\\CERTIFICATE
\\-----------
\\IS CA: {}
\\Subject distinguished name (encoded):
\\{X}
\\Public key:
\\
, .{ self.is_ca, self.dn });
switch (self.public_key) {
.rsa => |mod_exp| {
const modulus = std.math.big.int.Const{ .positive = true, .limbs = mod_exp.modulus };
const exponent = std.math.big.int.Const{ .positive = true, .limbs = mod_exp.exponent };
try writer.print(
\\RSA
\\modulus: {}
\\exponent: {}
\\
, .{
modulus,
exponent,
});
},
.ec => |ec| {
try writer.print(
\\EC (Curve: {})
\\point: {}
\\
, .{
ec.id,
ec.curve_point,
});
},
}
try writer.writeAll(
\\-----------
\\
);
}
};
pub const TrustAnchorChain = struct {
data: std.ArrayList(TrustAnchor),
pub fn from_pem(allocator: *Allocator, pem_reader: anytype) DecodeDERError(@TypeOf(pem_reader))!@This() {
var self = @This(){ .data = std.ArrayList(TrustAnchor).init(allocator) };
errdefer self.deinit();
var it = pemCertificateIterator(pem_reader);
while (try it.next()) |cert_reader| {
var buffered = std.io.bufferedReader(cert_reader);
const anchor = try TrustAnchor.create(allocator, buffered.reader());
errdefer anchor.deinit(allocator);
// This read forces the cert reader to find the `-----END`
// @TODO Should work without this read, investigate
_ = cert_reader.readByte() catch |err| switch (err) {
error.EndOfStream => {
try self.data.append(anchor);
break;
},
else => |e| return e,
};
return error.MalformedDER;
}
return self;
}
pub fn deinit(self: @This()) void {
const alloc = self.data.allocator;
for (self.data.items) |ta| ta.deinit(alloc);
self.data.deinit();
}
};
fn PEMSectionReader(comptime Reader: type) type {
const ReadError = Reader.Error || error{MalformedPEM};
const S = struct {
pub fn read(self: *PEMCertificateIterator(Reader), buffer: []u8) ReadError!usize {
const end = "-----END ";
var end_letters_matched: ?usize = null;
var out_idx: usize = 0;
if (self.waiting_chars_len > 0) {
const rest_written = std.math.min(self.waiting_chars_len, buffer.len);
while (out_idx < rest_written) : (out_idx += 1) {
buffer[out_idx] = self.waiting_chars[out_idx];
}
self.waiting_chars_len -= rest_written;
if (self.waiting_chars_len != 0) {
std.mem.copy(u8, self.waiting_chars[0..], self.waiting_chars[rest_written..]);
}
if (out_idx == buffer.len) {
return out_idx;
}
}
var base64_buf: [4]u8 = undefined;
var base64_idx: usize = 0;
while (true) {
var byte = self.reader.readByte() catch |err| switch (err) {
error.EndOfStream => {
if (self.skip_to_newline_exit) {
self.state = .none;
return 0;
}
return error.MalformedPEM;
},
else => |e| return e,
};
if (self.skip_to_newline_exit) {
if (byte == '\n') {
self.skip_to_newline_exit = false;
self.state = .none;
return 0;
}
continue;
}
if (byte == '\n' or byte == '\r') {
self.empty_line = true;
continue;
}
defer self.empty_line = false;
if (end_letters_matched) |*matched| {
if (end[matched.*] == byte) {
matched.* += 1;
if (matched.* == end.len) {
self.skip_to_newline_exit = true;
if (out_idx > 0)
return out_idx
else
continue;
}
continue;
} else return error.MalformedPEM;
} else if (self.empty_line and end[0] == byte) {
end_letters_matched = 1;
continue;
}
base64_buf[base64_idx] = byte;
base64_idx += 1;
if (base64_idx == base64_buf.len) {
base64_idx = 0;
const out_len = std.base64.standard_decoder.calcSize(&base64_buf) catch
return error.MalformedPEM;
const rest_chars = if (out_len > buffer.len - out_idx)
out_len - (buffer.len - out_idx)
else
0;
const buf_chars = out_len - rest_chars;
var res_buffer: [3]u8 = undefined;
std.base64.standard_decoder_unsafe.decode(res_buffer[0..out_len], &base64_buf);
var i: u3 = 0;
while (i < buf_chars) : (i += 1) {
buffer[out_idx] = res_buffer[i];
out_idx += 1;
}
if (rest_chars > 0) {
mem.copy(u8, &self.waiting_chars, res_buffer[i..]);
self.waiting_chars_len = @intCast(u2, rest_chars);
}
if (out_idx == buffer.len)
return out_idx;
}
}
}
};
return std.io.Reader(*PEMCertificateIterator(Reader), ReadError, S.read);
}
fn PEMCertificateIterator(comptime Reader: type) type {
return struct {
pub const SectionReader = PEMSectionReader(Reader);
pub const NextError = SectionReader.Error || error{EndOfStream};
reader: Reader,
// Internal state for the iterator and the current reader.
skip_to_newline_exit: bool = false,
empty_line: bool = false,
waiting_chars: [4]u8 = undefined,
waiting_chars_len: u2 = 0,
state: enum {
none,
in_section_name,
in_cert,
in_other,
} = .none,
pub fn next(self: *@This()) NextError!?SectionReader {
const end = "-----END ";
const begin = "-----BEGIN ";
const certificate = "CERTIFICATE";
const x509_certificate = "X.509 CERTIFICATE";
var line_empty = true;
var end_letters_matched: ?usize = null;
var begin_letters_matched: ?usize = null;
var certificate_letters_matched: ?usize = null;
var x509_certificate_letters_matched: ?usize = null;
var skip_to_newline = false;
var return_after_skip = false;
var base64_buf: [4]u8 = undefined;
var base64_buf_idx: usize = 0;
// Called next before reading all of the previous cert.
if (self.state == .in_cert) {
self.waiting_chars_len = 0;
}
while (true) {
var last_byte = false;
const byte = self.reader.readByte() catch |err| switch (err) {
error.EndOfStream => blk: {
if (line_empty and self.state == .none) {
return null;
} else {
last_byte = true;
break :blk '\n';
}
},
else => |e| return e,
};
if (skip_to_newline) {
if (last_byte)
return null;
if (byte == '\n') {
if (return_after_skip) {
return SectionReader{ .context = self };
}
skip_to_newline = false;
line_empty = true;
}
continue;
} else if (byte == '\r' or byte == '\n') {
line_empty = true;
continue;
}
defer line_empty = byte == '\n' or (line_empty and byte == ' ');
switch (self.state) {
.none => {
if (begin_letters_matched) |*matched| {
if (begin[matched.*] != byte)
return error.MalformedPEM;
matched.* += 1;
if (matched.* == begin.len) {
self.state = .in_section_name;
line_empty = true;
begin_letters_matched = null;
}
} else if (begin[0] == byte) {
begin_letters_matched = 1;
} else if (mem.indexOfScalar(u8, &std.ascii.spaces, byte) != null) {
if (last_byte) return null;
} else return error.MalformedPEM;
},
.in_section_name => {
if (certificate_letters_matched) |*matched| {
if (certificate[matched.*] != byte) {
self.state = .in_other;
skip_to_newline = true;
continue;
}
matched.* += 1;
if (matched.* == certificate.len) {
self.state = .in_cert;
certificate_letters_matched = null;
skip_to_newline = true;
return_after_skip = true;
}
} else if (x509_certificate_letters_matched) |*matched| {
if (x509_certificate[matched.*] != byte) {
self.state = .in_other;
skip_to_newline = true;
continue;
}
matched.* += 1;
if (matched.* == x509_certificate.len) {
self.state = .in_cert;
x509_certificate_letters_matched = null;
skip_to_newline = true;
return_after_skip = true;
}
} else if (line_empty and certificate[0] == byte) {
certificate_letters_matched = 1;
} else if (line_empty and x509_certificate[0] == byte) {
x509_certificate_letters_matched = 1;
} else if (line_empty) {
self.state = .in_other;
skip_to_newline = true;
} else unreachable;
},
.in_other, .in_cert => {
if (end_letters_matched) |*matched| {
if (end[matched.*] != byte) {
end_letters_matched = null;
skip_to_newline = true;
continue;
}
matched.* += 1;
if (matched.* == end.len) {
self.state = .none;
end_letters_matched = null;
skip_to_newline = true;
}
} else if (line_empty and end[0] == byte) {
end_letters_matched = 1;
}
},
}
}
}
};
}
/// Iterator of io.Reader that each decode one certificate from the PEM reader.
/// Readers do not have to be fully consumed until end of stream, but they must be
/// read from in order.
/// Iterator.SectionReader is the type of the io.Reader, Iterator.NextError is the error
/// set of the next() function.
pub fn pemCertificateIterator(reader: anytype) PEMCertificateIterator(@TypeOf(reader)) {
return .{ .reader = reader };
}
pub const NameElement = struct {
// Encoded OID without tag
oid: asn1.ObjectIdentifier,
// Destination buffer
buf: []u8,
status: enum {
not_found,
found,
errored,
},
};
const github_pem = @embedFile("../test/github.pem");
const github_der = @embedFile("../test/github.der");
fn expected_pem_certificate_chain(bytes: []const u8, certs: []const []const u8) !void {
var fbs = std.io.fixedBufferStream(bytes);
var it = pemCertificateIterator(fbs.reader());
var idx: usize = 0;
while (try it.next()) |cert_reader| : (idx += 1) {
const result_bytes = try cert_reader.readAllAlloc(std.testing.allocator, std.math.maxInt(usize));
defer std.testing.allocator.free(result_bytes);
std.testing.expectEqualSlices(u8, certs[idx], result_bytes);
}
if (idx != certs.len) {
std.debug.panic("Read {} certificates, wanted {}", .{ idx, certs.len });
}
std.testing.expect((try it.next()) == null);
}
fn expected_pem_certificate(bytes: []const u8, cert_bytes: []const u8) !void {
try expected_pem_certificate_chain(bytes, &[1][]const u8{cert_bytes});
}
test "pemCertificateIterator" {
try expected_pem_certificate(github_pem, github_der);
try expected_pem_certificate(
\\-----BEGIN BOGUS-----
\\-----END BOGUS-----
\\
++
github_pem,
github_der,
);
try expected_pem_certificate_chain(
github_pem ++
\\
\\-----BEGIN BOGUS-----
\\-----END BOGUS-----
\\
++ github_pem,
&[2][]const u8{ github_der, github_der },
);
try expected_pem_certificate_chain(
\\-----BEGIN BOGUS-----
\\-----END BOGUS-----
\\
,
&[0][]const u8{},
);
// Try reading byte by byte from a cert reader
{
var fbs = std.io.fixedBufferStream(github_pem ++ "\n" ++ github_pem);
var it = pemCertificateIterator(fbs.reader());
// Read a couple of bytes from the first reader, then skip to the next
{
const first_reader = (try it.next()) orelse return error.NoCertificate;
var first_few: [8]u8 = undefined;
const bytes = try first_reader.readAll(&first_few);
std.testing.expectEqual(first_few.len, bytes);
std.testing.expectEqualSlices(u8, github_der[0..bytes], &first_few);
}
const next_reader = (try it.next()) orelse return error.NoCertificate;
var idx: usize = 0;
while (true) : (idx += 1) {
const byte = next_reader.readByte() catch |err| switch (err) {
error.EndOfStream => break,
else => |e| return e,
};
if (github_der[idx] != byte) {
std.debug.panic("index {}: expected 0x{X}, found 0x{X}", .{ idx, github_der[idx], byte });
}
}
std.testing.expectEqual(github_der.len, idx);
std.testing.expect((try it.next()) == null);
}
}
test "TrustAnchorChain" {
var fbs = std.io.fixedBufferStream(github_pem);
const chain = try TrustAnchorChain.from_pem(std.testing.allocator, fbs.reader());
defer chain.deinit();
} | src/x509.zig |
usingnamespace @import("raylib-zig.zig");
pub extern fn InitWindow(width: c_int, height: c_int, title: [*c]const u8) void;
pub extern fn WindowShouldClose() bool;
pub extern fn CloseWindow() void;
pub extern fn IsWindowReady() bool;
pub extern fn IsWindowMinimized() bool;
pub extern fn IsWindowResized() bool;
pub extern fn IsWindowHidden() bool;
pub extern fn IsWindowFullscreen() bool;
pub extern fn ToggleFullscreen() void;
pub extern fn UnhideWindow() void;
pub extern fn HideWindow() void;
pub extern fn SetWindowIcon(image: Image) void;
pub extern fn SetWindowTitle(title: [*c]const u8) void;
pub extern fn SetWindowPosition(x: c_int, y: c_int) void;
pub extern fn SetWindowMonitor(monitor: c_int) void;
pub extern fn SetWindowMinSize(width: c_int, height: c_int) void;
pub extern fn SetWindowSize(width: c_int, height: c_int) void;
pub extern fn GetWindowHandle() [*c]const void;
pub extern fn GetScreenWidth() c_int;
pub extern fn GetScreenHeight() c_int;
pub extern fn GetMonitorCount() c_int;
pub extern fn GetMonitorWidth(monitor: c_int) c_int;
pub extern fn GetMonitorHeight(monitor: c_int) c_int;
pub extern fn GetMonitorPhysicalWidth(monitor: c_int) c_int;
pub extern fn GetMonitorPhysicalHeight(monitor: c_int) c_int;
pub extern fn GetWindowPosition() Vector2;
pub extern fn GetMonitorName(monitor: c_int) [*c]const u8;
pub extern fn GetClipboardText() [*c]const u8;
pub extern fn SetClipboardText(text: [*c]const u8) void;
pub extern fn ShowCursor() void;
pub extern fn HideCursor() void;
pub extern fn IsCursorHidden() bool;
pub extern fn EnableCursor() void;
pub extern fn DisableCursor() void;
pub extern fn ClearBackground(color: Color) void;
pub extern fn BeginDrawing() void;
pub extern fn EndDrawing() void;
pub extern fn BeginMode2D(camera: Camera2D) void;
pub extern fn EndMode2D() void;
pub extern fn BeginMode3D(camera: Camera3D) void;
pub extern fn EndMode3D() void;
pub extern fn BeginTextureMode(target: RenderTexture2D) void;
pub extern fn EndTextureMode() void;
pub extern fn BeginScissorMode(x: c_int, y: c_int, width: c_int, height: c_int) void;
pub extern fn EndScissorMode() void;
pub extern fn GetMouseRay(mousePosition: Vector2, camera: Camera) Ray;
pub extern fn GetCameraMatrix(camera: Camera) Matrix;
pub extern fn GetCameraMatrix2D(camera: Camera2D) Matrix;
pub extern fn GetWorldToScreen(position: Vector3, camera: Camera) Vector2;
pub extern fn GetWorldToScreenEx(position: Vector3, camera: Camera, width: c_int, height: c_int) Vector2;
pub extern fn GetWorldToScreen2D(position: Vector2, camera: Camera2D) Vector2;
pub extern fn GetScreenToWorld2D(position: Vector2, camera: Camera2D) Vector2;
pub extern fn SetTargetFPS(fps: c_int) void;
pub extern fn GetFPS() c_int;
pub extern fn GetFrameTime() f32;
pub extern fn GetTime() double;
pub extern fn ColorToInt(color: Color) c_int;
pub extern fn ColorNormalize(color: Color) Vector4;
pub extern fn ColorFromNormalized(normalized: Vector4) Color;
pub extern fn ColorToHSV(color: Color) Vector3;
pub extern fn ColorFromHSV(hsv: Vector3) Color;
pub extern fn GetColor(hexValue: c_int) Color;
pub extern fn Fade(color: Color, alpha: f32) Color;
pub extern fn SetConfigFlags(flags: c_uint) void;
pub extern fn SetTraceLogLevel(logType: c_int) void;
pub extern fn SetTraceLogExit(logType: c_int) void;
pub extern fn SetTraceLogCallback(callback: TraceLogCallback) void;
pub extern fn TraceLog(logType: c_int, text: [*c]const u8, ...) void;
pub extern fn TakeScreenshot(fileName: [*c]const u8) void;
pub extern fn GetRandomValue(min: c_int, max: c_int) c_int;
pub extern fn LoadFileData(fileName: [*c]const u8, bytesRead: [*c]const c_uint) [*c]const u8;
pub extern fn SaveFileData(fileName: [*c]const u8, data: [*c]const void, bytesToWrite: c_uint) void;
pub extern fn LoadFileText(fileName: [*c]const u8) [*c]const u8;
pub extern fn SaveFileText(fileName: [*c]const u8, text: [*c]const u8) void;
pub extern fn FileExists(fileName: [*c]const u8) bool;
pub extern fn IsFileExtension(fileName: [*c]const u8, ext: [*c]const u8) bool;
pub extern fn DirectoryExists(dirPath: [*c]const u8) bool;
pub extern fn GetExtension(fileName: [*c]const u8) [*c]const u8;
pub extern fn GetFileName(filePath: [*c]const u8) [*c]const u8;
pub extern fn GetFileNameWithoutExt(filePath: [*c]const u8) [*c]const u8;
pub extern fn GetDirectoryPath(filePath: [*c]const u8) [*c]const u8;
pub extern fn GetPrevDirectoryPath(dirPath: [*c]const u8) [*c]const u8;
pub extern fn GetWorkingDirectory() [*c]const u8;
pub extern fn GetDirectoryFiles(dirPath: [*c]const u8, count: [*c]const c_int) [*c][*c]const u8;
pub extern fn ClearDirectoryFiles() void;
pub extern fn ChangeDirectory(dir: [*c]const u8) bool;
pub extern fn IsFileDropped() bool;
pub extern fn GetDroppedFiles(count: [*c]const c_int) [*c][*c]const u8;
pub extern fn ClearDroppedFiles() void;
pub extern fn GetFileModTime(fileName: [*c]const u8) c_long;
pub extern fn CompressData(data: [*c]const u8, dataLength: c_int, compDataLength: [*c]const c_int) [*c]const u8;
pub extern fn DecompressData(compData: [*c]const u8, compDataLength: c_int, dataLength: [*c]const c_int) [*c]const u8;
pub extern fn SaveStorageValue(position: c_uint, value: c_int) void;
pub extern fn LoadStorageValue(position: c_uint) c_int;
pub extern fn OpenURL(url: [*c]const u8) void;
pub extern fn IsKeyPressed(key: KeyboardKey) bool;
pub extern fn IsKeyDown(key: KeyboardKey) bool;
pub extern fn IsKeyReleased(key: KeyboardKey) bool;
pub extern fn IsKeyUp(key: KeyboardKey) bool;
pub extern fn SetExitKey(key: KeyboardKey) void;
pub extern fn GetKeyPressed() c_int;
pub extern fn IsGamepadAvailable(gamepad: c_int) bool;
pub extern fn IsGamepadName(gamepad: c_int, name: [*c]const u8) bool;
pub extern fn GetGamepadName(gamepad: c_int) [*c]const u8;
pub extern fn IsGamepadButtonPressed(gamepad: c_int, button: MouseButton) bool;
pub extern fn IsGamepadButtonDown(gamepad: c_int, button: MouseButton) bool;
pub extern fn IsGamepadButtonReleased(gamepad: c_int, button: MouseButton) bool;
pub extern fn IsGamepadButtonUp(gamepad: c_int, button: MouseButton) bool;
pub extern fn GetGamepadButtonPressed() c_int;
pub extern fn GetGamepadAxisCount(gamepad: c_int) c_int;
pub extern fn GetGamepadAxisMovement(gamepad: c_int, axis: c_int) f32;
pub extern fn IsMouseButtonPressed(button: MouseButton) bool;
pub extern fn IsMouseButtonDown(button: MouseButton) bool;
pub extern fn IsMouseButtonReleased(button: MouseButton) bool;
pub extern fn IsMouseButtonUp(button: MouseButton) bool;
pub extern fn GetMouseX() c_int;
pub extern fn GetMouseY() c_int;
pub extern fn GetMousePosition() Vector2;
pub extern fn SetMousePosition(x: c_int, y: c_int) void;
pub extern fn SetMouseOffset(offsetX: c_int, offsetY: c_int) void;
pub extern fn SetMouseScale(scaleX: f32, scaleY: f32) void;
pub extern fn GetMouseWheelMove() c_int;
pub extern fn GetTouchX() c_int;
pub extern fn GetTouchY() c_int;
pub extern fn GetTouchPosition(index: c_int) Vector2;
pub extern fn SetGesturesEnabled(gestureFlags: c_uint) void;
pub extern fn IsGestureDetected(gesture: c_int) bool;
pub extern fn GetGestureDetected() c_int;
pub extern fn GetTouchPointsCount() c_int;
pub extern fn GetGestureHoldDuration() f32;
pub extern fn GetGestureDragVector() Vector2;
pub extern fn GetGestureDragAngle() f32;
pub extern fn GetGesturePinchVector() Vector2;
pub extern fn GetGesturePinchAngle() f32;
pub extern fn SetCameraMode(camera: Camera, mode: CameraMode) void;
pub extern fn UpdateCamera(camera: [*c]const Camera) void;
pub extern fn SetCameraPanControl(panKey: c_int) void;
pub extern fn SetCameraAltControl(altKey: c_int) void;
pub extern fn SetCameraSmoothZoomControl(szKey: c_int) void;
pub extern fn SetCameraMoveControls(frontKey: c_int, backKey: c_int, rightKey: c_int, leftKey: c_int, upKey: c_int, downKey: c_int) void;
pub extern fn DrawPixel(posX: c_int, posY: c_int, color: Color) void;
pub extern fn DrawPixelV(position: Vector2, color: Color) void;
pub extern fn DrawLine(startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: Color) void;
pub extern fn DrawLineV(startPos: Vector2, endPos: Vector2, color: Color) void;
pub extern fn DrawLineEx(startPos: Vector2, endPos: Vector2, thick: f32, color: Color) void;
pub extern fn DrawLineBezier(startPos: Vector2, endPos: Vector2, thick: f32, color: Color) void;
pub extern fn DrawLineStrip(points: [*c]const Vector2, numPoints: c_int, color: Color) void;
pub extern fn DrawCircle(centerX: c_int, centerY: c_int, radius: f32, color: Color) void;
pub extern fn DrawCircleSector(center: Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void;
pub extern fn DrawCircleSectorLines(center: Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void;
pub extern fn DrawCircleGradient(centerX: c_int, centerY: c_int, radius: f32, color1: Color, color2: Color) void;
pub extern fn DrawCircleV(center: Vector2, radius: f32, color: Color) void;
pub extern fn DrawCircleLines(centerX: c_int, centerY: c_int, radius: f32, color: Color) void;
pub extern fn DrawEllipse(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: Color) void;
pub extern fn DrawEllipseLines(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: Color) void;
pub extern fn DrawRing(center: Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void;
pub extern fn DrawRingLines(center: Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void;
pub extern fn DrawRectangle(posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void;
pub extern fn DrawRectangleV(position: Vector2, size: Vector2, color: Color) void;
pub extern fn DrawRectangleRec(rec: Rectangle, color: Color) void;
pub extern fn DrawRectanglePro(rec: Rectangle, origin: Vector2, rotation: f32, color: Color) void;
pub extern fn DrawRectangleGradientV(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: Color, color2: Color) void;
pub extern fn DrawRectangleGradientH(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: Color, color2: Color) void;
pub extern fn DrawRectangleGradientEx(rec: Rectangle, col1: Color, col2: Color, col3: Color, col4: Color) void;
pub extern fn DrawRectangleLines(posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void;
pub extern fn DrawRectangleLinesEx(rec: Rectangle, lineThick: c_int, color: Color) void;
pub extern fn DrawRectangleRounded(rec: Rectangle, roundness: f32, segments: c_int, color: Color) void;
pub extern fn DrawRectangleRoundedLines(rec: Rectangle, roundness: f32, segments: c_int, lineThick: c_int, color: Color) void;
pub extern fn DrawTriangle(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) void;
pub extern fn DrawTriangleLines(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) void;
pub extern fn DrawTriangleFan(points: [*c]const Vector2, numPoints: c_int, color: Color) void;
pub extern fn DrawTriangleStrip(points: [*c]const Vector2, pointsCount: c_int, color: Color) void;
pub extern fn DrawPoly(center: Vector2, sides: c_int, radius: f32, rotation: f32, color: Color) void;
pub extern fn DrawPolyLines(center: Vector2, sides: c_int, radius: f32, rotation: f32, color: Color) void;
pub extern fn CheckCollisionRecs(rec1: Rectangle, rec2: Rectangle) bool;
pub extern fn CheckCollisionCircles(center1: Vector2, radius1: f32, center2: Vector2, radius2: f32) bool;
pub extern fn CheckCollisionCircleRec(center: Vector2, radius: f32, rec: Rectangle) bool;
pub extern fn GetCollisionRec(rec1: Rectangle, rec2: Rectangle) Rectangle;
pub extern fn CheckCollisionPointRec(point: Vector2, rec: Rectangle) bool;
pub extern fn CheckCollisionPointCircle(point: Vector2, center: Vector2, radius: f32) bool;
pub extern fn CheckCollisionPointTriangle(point: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) bool;
pub extern fn LoadImage(fileName: [*c]const u8) Image;
pub extern fn LoadImageEx(pixels: [*c]const Color, width: c_int, height: c_int) Image;
pub extern fn LoadImagePro(data: [*c]const void, width: c_int, height: c_int, format: c_int) Image;
pub extern fn LoadImageRaw(fileName: [*c]const u8, width: c_int, height: c_int, format: c_int, headerSize: c_int) Image;
pub extern fn UnloadImage(image: Image) void;
pub extern fn ExportImage(image: Image, fileName: [*c]const u8) void;
pub extern fn ExportImageAsCode(image: Image, fileName: [*c]const u8) void;
pub extern fn GetImageData(image: Image) [*c]const Color;
pub extern fn GetImageDataNormalized(image: Image) [*c]const Vector4;
pub extern fn GenImageColor(width: c_int, height: c_int, color: Color) Image;
pub extern fn GenImageGradientV(width: c_int, height: c_int, top: Color, bottom: Color) Image;
pub extern fn GenImageGradientH(width: c_int, height: c_int, left: Color, right: Color) Image;
pub extern fn GenImageGradientRadial(width: c_int, height: c_int, density: f32, inner: Color, outer: Color) Image;
pub extern fn GenImageChecked(width: c_int, height: c_int, checksX: c_int, checksY: c_int, col1: Color, col2: Color) Image;
pub extern fn GenImageWhiteNoise(width: c_int, height: c_int, factor: f32) Image;
pub extern fn GenImagePerlinNoise(width: c_int, height: c_int, offsetX: c_int, offsetY: c_int, scale: f32) Image;
pub extern fn GenImageCellular(width: c_int, height: c_int, tileSize: c_int) Image;
pub extern fn ImageCopy(image: Image) Image;
pub extern fn ImageFromImage(image: Image, rec: Rectangle) Image;
pub extern fn ImageText(text: [*c]const u8, fontSize: c_int, color: Color) Image;
pub extern fn ImageTextEx(font: Font, text: [*c]const u8, fontSize: f32, spacing: f32, tint: Color) Image;
pub extern fn ImageToPOT(image: [*c]const Image, fillColor: Color) void;
pub extern fn ImageFormat(image: [*c]const Image, newFormat: c_int) void;
pub extern fn ImageAlphaMask(image: [*c]const Image, alphaMask: Image) void;
pub extern fn ImageAlphaClear(image: [*c]const Image, color: Color, threshold: f32) void;
pub extern fn ImageAlphaCrop(image: [*c]const Image, threshold: f32) void;
pub extern fn ImageAlphaPremultiply(image: [*c]const Image) void;
pub extern fn ImageCrop(image: [*c]const Image, crop: Rectangle) void;
pub extern fn ImageResize(image: [*c]const Image, newWidth: c_int, newHeight: c_int) void;
pub extern fn ImageResizeNN(image: [*c]const Image, newWidth: c_int, newHeight: c_int) void;
pub extern fn ImageResizeCanvas(image: [*c]const Image, newWidth: c_int, newHeight: c_int, offsetX: c_int, offsetY: c_int, color: Color) void;
pub extern fn ImageMipmaps(image: [*c]const Image) void;
pub extern fn ImageDither(image: [*c]const Image, rBpp: c_int, gBpp: c_int, bBpp: c_int, aBpp: c_int) void;
pub extern fn ImageFlipVertical(image: [*c]const Image) void;
pub extern fn ImageFlipHorizontal(image: [*c]const Image) void;
pub extern fn ImageRotateCW(image: [*c]const Image) void;
pub extern fn ImageRotateCCW(image: [*c]const Image) void;
pub extern fn ImageColorTint(image: [*c]const Image, color: Color) void;
pub extern fn ImageColorInvert(image: [*c]const Image) void;
pub extern fn ImageColorGrayscale(image: [*c]const Image) void;
pub extern fn ImageColorContrast(image: [*c]const Image, contrast: f32) void;
pub extern fn ImageColorBrightness(image: [*c]const Image, brightness: c_int) void;
pub extern fn ImageColorReplace(image: [*c]const Image, color: Color, replace: Color) void;
pub extern fn ImageExtractPalette(image: Image, maxPaletteSize: c_int, extractCount: [*c]const c_int) [*c]const Color;
pub extern fn GetImageAlphaBorder(image: Image, threshold: f32) Rectangle;
pub extern fn ImageClearBackground(dst: [*c]const Image, color: Color) void;
pub extern fn ImageDrawPixel(dst: [*c]const Image, posX: c_int, posY: c_int, color: Color) void;
pub extern fn ImageDrawPixelV(dst: [*c]const Image, position: Vector2, color: Color) void;
pub extern fn ImageDrawLine(dst: [*c]const Image, startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: Color) void;
pub extern fn ImageDrawLineV(dst: [*c]const Image, start: Vector2, end: Vector2, color: Color) void;
pub extern fn ImageDrawCircle(dst: [*c]const Image, centerX: c_int, centerY: c_int, radius: c_int, color: Color) void;
pub extern fn ImageDrawCircleV(dst: [*c]const Image, center: Vector2, radius: c_int, color: Color) void;
pub extern fn ImageDrawRectangle(dst: [*c]const Image, posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void;
pub extern fn ImageDrawRectangleV(dst: [*c]const Image, position: Vector2, size: Vector2, color: Color) void;
pub extern fn ImageDrawRectangleRec(dst: [*c]const Image, rec: Rectangle, color: Color) void;
pub extern fn ImageDrawRectangleLines(dst: [*c]const Image, rec: Rectangle, thick: c_int, color: Color) void;
pub extern fn ImageDraw(dst: [*c]const Image, src: Image, srcRec: Rectangle, dstRec: Rectangle, tint: Color) void;
pub extern fn ImageDrawText(dst: [*c]const Image, position: Vector2, text: [*c]const u8, fontSize: c_int, color: Color) void;
pub extern fn ImageDrawTextEx(dst: [*c]const Image, position: Vector2, font: Font, text: [*c]const u8, fontSize: f32, spacing: f32, color: Color) void;
pub extern fn LoadTexture(fileName: [*c]const u8) Texture2D;
pub extern fn LoadTextureFromImage(image: Image) Texture2D;
pub extern fn LoadTextureCubemap(image: Image, layoutType: c_int) TextureCubemap;
pub extern fn LoadRenderTexture(width: c_int, height: c_int) RenderTexture2D;
pub extern fn UnloadTexture(texture: Texture2D) void;
pub extern fn UnloadRenderTexture(target: RenderTexture2D) void;
pub extern fn UpdateTexture(texture: Texture2D, pixels: [*c]const void) void;
pub extern fn GetTextureData(texture: Texture2D) Image;
pub extern fn GetScreenData() Image;
pub extern fn GenTextureMipmaps(texture: [*c]const Texture2D) void;
pub extern fn SetTextureFilter(texture: Texture2D, filterMode: c_int) void;
pub extern fn SetTextureWrap(texture: Texture2D, wrapMode: c_int) void;
pub extern fn DrawTexture(texture: Texture2D, posX: c_int, posY: c_int, tint: Color) void;
pub extern fn DrawTextureV(texture: Texture2D, position: Vector2, tint: Color) void;
pub extern fn DrawTextureEx(texture: Texture2D, position: Vector2, rotation: f32, scale: f32, tint: Color) void;
pub extern fn DrawTextureRec(texture: Texture2D, sourceRec: Rectangle, position: Vector2, tint: Color) void;
pub extern fn DrawTextureQuad(texture: Texture2D, tiling: Vector2, offset: Vector2, quad: Rectangle, tint: Color) void;
pub extern fn DrawTexturePro(texture: Texture2D, sourceRec: Rectangle, destRec: Rectangle, origin: Vector2, rotation: f32, tint: Color) void;
pub extern fn DrawTextureNPatch(texture: Texture2D, nPatchInfo: NPatchInfo, destRec: Rectangle, origin: Vector2, rotation: f32, tint: Color) void;
pub extern fn GetPixelDataSize(width: c_int, height: c_int, format: c_int) c_int;
pub extern fn GetFontDefault() Font;
pub extern fn LoadFont(fileName: [*c]const u8) Font;
pub extern fn LoadFontEx(fileName: [*c]const u8, fontSize: c_int, fontChars: [*c]const c_int, charsCount: c_int) Font;
pub extern fn LoadFontFromImage(image: Image, key: Color, firstChar: c_int) Font;
pub extern fn LoadFontData(fileName: [*c]const u8, fontSize: c_int, fontChars: [*c]const c_int, charsCount: c_int, type: c_int) [*c]const CharInfo;
pub extern fn GenImageFontAtlas(chars: [*c]const CharInfo, recs: [*c][*c]const Rectangle, charsCount: c_int, fontSize: c_int, padding: c_int, packMethod: c_int) Image;
pub extern fn UnloadFont(font: Font) void;
pub extern fn DrawFPS(posX: c_int, posY: c_int) void;
pub extern fn DrawText(text: [*c]const u8, posX: c_int, posY: c_int, fontSize: c_int, color: Color) void;
pub extern fn DrawTextEx(font: Font, text: [*c]const u8, position: Vector2, fontSize: f32, spacing: f32, tint: Color) void;
pub extern fn DrawTextRec(font: Font, text: [*c]const u8, rec: Rectangle, fontSize: f32, spacing: f32, wordWrap: bool, tint: Color) void;
pub extern fn DrawTextRecEx(font: Font, text: [*c]const u8, rec: Rectangle, fontSize: f32, spacing: f32, wordWrap: bool, tint: Color, selectStart: c_int, selectLength: c_int, selectTint: Color, selectBackTint: Color) void;
pub extern fn DrawTextCodepoint(font: Font, codepoint: c_int, position: Vector2, scale: f32, tint: Color) void;
pub extern fn MeasureText(text: [*c]const u8, fontSize: c_int) c_int;
pub extern fn MeasureTextEx(font: Font, text: [*c]const u8, fontSize: f32, spacing: f32) Vector2;
pub extern fn GetGlyphIndex(font: Font, codepoint: c_int) c_int;
pub extern fn TextCopy(dst: [*c]const u8, src: [*c]const u8) c_int;
pub extern fn TextIsEqual(text1: [*c]const u8, text2: [*c]const u8) bool;
pub extern fn TextLength(text: [*c]const u8) c_uint;
pub extern fn TextFormat(text: [*c]const u8, ...) [*c]const u8;
pub extern fn TextSubtext(text: [*c]const u8, position: c_int, length: c_int) [*c]const u8;
pub extern fn TextReplace(text: [*c]const u8, replace: [*c]const u8, by: [*c]const u8) [*c]const u8;
pub extern fn TextInsert(text: [*c]const u8, insert: [*c]const u8, position: c_int) [*c]const u8;
pub extern fn TextJoin(textList: [*c][*c]const u8, count: c_int, delimiter: [*c]const u8) [*c]const u8;
pub extern fn TextSplit(text: [*c]const u8, delimiter: u8, count: [*c]const c_int) [*c][*c]const u8;
pub extern fn TextAppend(text: [*c]const u8, append: [*c]const u8, position: [*c]const c_int) void;
pub extern fn TextFindIndex(text: [*c]const u8, find: [*c]const u8) c_int;
pub extern fn TextToUpper(text: [*c]const u8) [*c]const u8;
pub extern fn TextToLower(text: [*c]const u8) [*c]const u8;
pub extern fn TextToPascal(text: [*c]const u8) [*c]const u8;
pub extern fn TextToInteger(text: [*c]const u8) c_int;
pub extern fn TextToUtf8(codepoints: [*c]const c_int, length: c_int) [*c]const u8;
pub extern fn GetCodepoints(text: [*c]const u8, count: [*c]const c_int) [*c]const c_int;
pub extern fn GetCodepointsCount(text: [*c]const u8) c_int;
pub extern fn GetNextCodepoint(text: [*c]const u8, bytesProcessed: [*c]const c_int) c_int;
pub extern fn CodepointToUtf8(codepoint: c_int, byteLength: [*c]const c_int) [*c]const u8;
pub extern fn DrawLine3D(startPos: Vector3, endPos: Vector3, color: Color) void;
pub extern fn DrawPoint3D(position: Vector3, color: Color) void;
pub extern fn DrawCircle3D(center: Vector3, radius: f32, rotationAxis: Vector3, rotationAngle: f32, color: Color) void;
pub extern fn DrawCube(position: Vector3, width: f32, height: f32, length: f32, color: Color) void;
pub extern fn DrawCubeV(position: Vector3, size: Vector3, color: Color) void;
pub extern fn DrawCubeWires(position: Vector3, width: f32, height: f32, length: f32, color: Color) void;
pub extern fn DrawCubeWiresV(position: Vector3, size: Vector3, color: Color) void;
pub extern fn DrawCubeTexture(texture: Texture2D, position: Vector3, width: f32, height: f32, length: f32, color: Color) void;
pub extern fn DrawSphere(centerPos: Vector3, radius: f32, color: Color) void;
pub extern fn DrawSphereEx(centerPos: Vector3, radius: f32, rings: c_int, slices: c_int, color: Color) void;
pub extern fn DrawSphereWires(centerPos: Vector3, radius: f32, rings: c_int, slices: c_int, color: Color) void;
pub extern fn DrawCylinder(position: Vector3, radiusTop: f32, radiusBottom: f32, height: f32, slices: c_int, color: Color) void;
pub extern fn DrawCylinderWires(position: Vector3, radiusTop: f32, radiusBottom: f32, height: f32, slices: c_int, color: Color) void;
pub extern fn DrawPlane(centerPos: Vector3, size: Vector2, color: Color) void;
pub extern fn DrawRay(ray: Ray, color: Color) void;
pub extern fn DrawGrid(slices: c_int, spacing: f32) void;
pub extern fn DrawGizmo(position: Vector3) void;
pub extern fn LoadModel(fileName: [*c]const u8) Model;
pub extern fn LoadModelFromMesh(mesh: Mesh) Model;
pub extern fn UnloadModel(model: Model) void;
pub extern fn LoadMeshes(fileName: [*c]const u8, meshCount: [*c]const c_int) [*c]const Mesh;
pub extern fn ExportMesh(mesh: Mesh, fileName: [*c]const u8) void;
pub extern fn UnloadMesh(mesh: Mesh) void;
pub extern fn LoadMaterials(fileName: [*c]const u8, materialCount: [*c]const c_int) [*c]const Material;
pub extern fn LoadMaterialDefault() Material;
pub extern fn UnloadMaterial(material: Material) void;
pub extern fn SetMaterialTexture(material: [*c]const Material, mapType: c_int, texture: Texture2D) void;
pub extern fn SetModelMeshMaterial(model: [*c]const Model, meshId: c_int, materialId: c_int) void;
pub extern fn LoadModelAnimations(fileName: [*c]const u8, animsCount: [*c]const c_int) [*c]const ModelAnimation;
pub extern fn UpdateModelAnimation(model: Model, anim: ModelAnimation, frame: c_int) void;
pub extern fn UnloadModelAnimation(anim: ModelAnimation) void;
pub extern fn IsModelAnimationValid(model: Model, anim: ModelAnimation) bool;
pub extern fn GenMeshPoly(sides: c_int, radius: f32) Mesh;
pub extern fn GenMeshPlane(width: f32, length: f32, resX: c_int, resZ: c_int) Mesh;
pub extern fn GenMeshCube(width: f32, height: f32, length: f32) Mesh;
pub extern fn GenMeshSphere(radius: f32, rings: c_int, slices: c_int) Mesh;
pub extern fn GenMeshHemiSphere(radius: f32, rings: c_int, slices: c_int) Mesh;
pub extern fn GenMeshCylinder(radius: f32, height: f32, slices: c_int) Mesh;
pub extern fn GenMeshTorus(radius: f32, size: f32, radSeg: c_int, sides: c_int) Mesh;
pub extern fn GenMeshKnot(radius: f32, size: f32, radSeg: c_int, sides: c_int) Mesh;
pub extern fn GenMeshHeightmap(heightmap: Image, size: Vector3) Mesh;
pub extern fn GenMeshCubicmap(cubicmap: Image, cubeSize: Vector3) Mesh;
pub extern fn MeshBoundingBox(mesh: Mesh) BoundingBox;
pub extern fn MeshTangents(mesh: [*c]const Mesh) void;
pub extern fn MeshBinormals(mesh: [*c]const Mesh) void;
pub extern fn DrawModel(model: Model, position: Vector3, scale: f32, tint: Color) void;
pub extern fn DrawModelEx(model: Model, position: Vector3, rotationAxis: Vector3, rotationAngle: f32, scale: Vector3, tint: Color) void;
pub extern fn DrawModelWires(model: Model, position: Vector3, scale: f32, tint: Color) void;
pub extern fn DrawModelWiresEx(model: Model, position: Vector3, rotationAxis: Vector3, rotationAngle: f32, scale: Vector3, tint: Color) void;
pub extern fn DrawBoundingBox(box: BoundingBox, color: Color) void;
pub extern fn DrawBillboard(camera: Camera, texture: Texture2D, center: Vector3, size: f32, tint: Color) void;
pub extern fn DrawBillboardRec(camera: Camera, texture: Texture2D, sourceRec: Rectangle, center: Vector3, size: f32, tint: Color) void;
pub extern fn CheckCollisionSpheres(centerA: Vector3, radiusA: f32, centerB: Vector3, radiusB: f32) bool;
pub extern fn CheckCollisionBoxes(box1: BoundingBox, box2: BoundingBox) bool;
pub extern fn CheckCollisionBoxSphere(box: BoundingBox, center: Vector3, radius: f32) bool;
pub extern fn CheckCollisionRaySphere(ray: Ray, center: Vector3, radius: f32) bool;
pub extern fn CheckCollisionRaySphereEx(ray: Ray, center: Vector3, radius: f32, collisionPoint: [*c]const Vector3) bool;
pub extern fn CheckCollisionRayBox(ray: Ray, box: BoundingBox) bool;
pub extern fn GetCollisionRayModel(ray: Ray, model: Model) RayHitInfo;
pub extern fn GetCollisionRayTriangle(ray: Ray, p1: Vector3, p2: Vector3, p3: Vector3) RayHitInfo;
pub extern fn GetCollisionRayGround(ray: Ray, groundHeight: f32) RayHitInfo;
pub extern fn LoadShader(vsFileName: [*c]const u8, fsFileName: [*c]const u8) Shader;
pub extern fn LoadShaderCode(vsCode: [*c]const u8, fsCode: [*c]const u8) Shader;
pub extern fn UnloadShader(shader: Shader) void;
pub extern fn GetShaderDefault() Shader;
pub extern fn GetTextureDefault() Texture2D;
pub extern fn GetShapesTexture() Texture2D;
pub extern fn GetShapesTextureRec() Rectangle;
pub extern fn SetShapesTexture(texture: Texture2D, source: Rectangle) void;
pub extern fn GetShaderLocation(shader: Shader, uniformName: [*c]const u8) c_int;
pub extern fn SetShaderValue(shader: Shader, uniformLoc: c_int, value: [*c]const void, uniformType: c_int) void;
pub extern fn SetShaderValueV(shader: Shader, uniformLoc: c_int, value: [*c]const void, uniformType: c_int, count: c_int) void;
pub extern fn SetShaderValueMatrix(shader: Shader, uniformLoc: c_int, mat: Matrix) void;
pub extern fn SetShaderValueTexture(shader: Shader, uniformLoc: c_int, texture: Texture2D) void;
pub extern fn SetMatrixProjection(proj: Matrix) void;
pub extern fn SetMatrixModelview(view: Matrix) void;
pub extern fn GetMatrixModelview() Matrix;
pub extern fn GetMatrixProjection() Matrix;
pub extern fn GenTextureCubemap(shader: Shader, map: Texture2D, size: c_int) Texture2D;
pub extern fn GenTextureIrradiance(shader: Shader, cubemap: Texture2D, size: c_int) Texture2D;
pub extern fn GenTexturePrefilter(shader: Shader, cubemap: Texture2D, size: c_int) Texture2D;
pub extern fn GenTextureBRDF(shader: Shader, size: c_int) Texture2D;
pub extern fn BeginShaderMode(shader: Shader) void;
pub extern fn EndShaderMode() void;
pub extern fn BeginBlendMode(mode: c_int) void;
pub extern fn EndBlendMode() void;
pub extern fn InitVrSimulator() void;
pub extern fn CloseVrSimulator() void;
pub extern fn UpdateVrTracking(camera: [*c]const Camera) void;
pub extern fn SetVrConfiguration(info: VrDeviceInfo, distortion: Shader) void;
pub extern fn IsVrSimulatorReady() bool;
pub extern fn ToggleVrMode() void;
pub extern fn BeginVrDrawing() void;
pub extern fn EndVrDrawing() void;
pub extern fn InitAudioDevice() void;
pub extern fn CloseAudioDevice() void;
pub extern fn IsAudioDeviceReady() bool;
pub extern fn SetMasterVolume(volume: f32) void;
pub extern fn LoadWave(fileName: [*c]const u8) Wave;
pub extern fn LoadSound(fileName: [*c]const u8) Sound;
pub extern fn LoadSoundFromWave(wave: Wave) Sound;
pub extern fn UpdateSound(sound: Sound, data: [*c]const void, samplesCount: c_int) void;
pub extern fn UnloadWave(wave: Wave) void;
pub extern fn UnloadSound(sound: Sound) void;
pub extern fn ExportWave(wave: Wave, fileName: [*c]const u8) void;
pub extern fn ExportWaveAsCode(wave: Wave, fileName: [*c]const u8) void;
pub extern fn PlaySound(sound: Sound) void;
pub extern fn StopSound(sound: Sound) void;
pub extern fn PauseSound(sound: Sound) void;
pub extern fn ResumeSound(sound: Sound) void;
pub extern fn PlaySoundMulti(sound: Sound) void;
pub extern fn StopSoundMulti() void;
pub extern fn GetSoundsPlaying() c_int;
pub extern fn IsSoundPlaying(sound: Sound) bool;
pub extern fn SetSoundVolume(sound: Sound, volume: f32) void;
pub extern fn SetSoundPitch(sound: Sound, pitch: f32) void;
pub extern fn WaveFormat(wave: [*c]const Wave, sampleRate: c_int, sampleSize: c_int, channels: c_int) void;
pub extern fn WaveCopy(wave: Wave) Wave;
pub extern fn WaveCrop(wave: [*c]const Wave, initSample: c_int, finalSample: c_int) void;
pub extern fn GetWaveData(wave: Wave) [*c]const f32;
pub extern fn LoadMusicStream(fileName: [*c]const u8) Music;
pub extern fn UnloadMusicStream(music: Music) void;
pub extern fn PlayMusicStream(music: Music) void;
pub extern fn UpdateMusicStream(music: Music) void;
pub extern fn StopMusicStream(music: Music) void;
pub extern fn PauseMusicStream(music: Music) void;
pub extern fn ResumeMusicStream(music: Music) void;
pub extern fn IsMusicPlaying(music: Music) bool;
pub extern fn SetMusicVolume(music: Music, volume: f32) void;
pub extern fn SetMusicPitch(music: Music, pitch: f32) void;
pub extern fn SetMusicLoopCount(music: Music, count: c_int) void;
pub extern fn GetMusicTimeLength(music: Music) f32;
pub extern fn GetMusicTimePlayed(music: Music) f32;
pub extern fn InitAudioStream(sampleRate: c_uint, sampleSize: c_uint, channels: c_uint) AudioStream;
pub extern fn UpdateAudioStream(stream: AudioStream, data: [*c]const void, samplesCount: c_int) void;
pub extern fn CloseAudioStream(stream: AudioStream) void;
pub extern fn IsAudioStreamProcessed(stream: AudioStream) bool;
pub extern fn PlayAudioStream(stream: AudioStream) void;
pub extern fn PauseAudioStream(stream: AudioStream) void;
pub extern fn ResumeAudioStream(stream: AudioStream) void;
pub extern fn IsAudioStreamPlaying(stream: AudioStream) bool;
pub extern fn StopAudioStream(stream: AudioStream) void;
pub extern fn SetAudioStreamVolume(stream: AudioStream, volume: f32) void;
pub extern fn SetAudioStreamPitch(stream: AudioStream, pitch: f32) void;
pub extern fn SetAudioStreamBufferSizeDefault(size: c_int) void; | raylib-zig/raylib-wa.zig |
const sf = @import("../sfml.zig");
pub const Text = struct {
const Self = @This();
// Constructor/destructor
/// Inits an empty text
pub fn init() !Self {
var text = sf.c.sfText_create();
if (text == null)
return sf.Error.nullptrUnknownReason;
return Self{ .ptr = text.? };
}
/// Inits a text with content
pub fn initWithText(string: [:0]const u8, font: sf.Font, character_size: usize) !Self {
var text = sf.c.sfText_create();
if (text == null)
return sf.Error.nullptrUnknownReason;
sf.c.sfText_setFont(text, font.ptr);
sf.c.sfText_setCharacterSize(text, @intCast(c_uint, character_size));
sf.c.sfText_setString(text, string);
return Self{ .ptr = text.? };
}
/// Destroys a text
pub fn deinit(self: Self) void {
sf.c.sfText_destroy(self.ptr);
}
// Getters/setters
/// Sets the font of this text
pub fn setFont(self: Self, font: sf.Font) void {
sf.c.sfText_setFont(self.ptr, font.ptr);
}
/// Gets the character size of this text
pub fn getCharacterSize(self: Self) usize {
return @intCast(usize, sf.c.sfText_getCharacterSize(self.ptr));
}
/// Sets the character size of this text
pub fn setCharacterSize(self: Self, character_size: usize) void {
sf.c.sfText_setCharacterSize(self.ptr, @intCast(c_uint, character_size));
}
/// Gets the fill color of this text
pub fn getFillColor(self: Self) sf.Color {
return sf.Color.fromCSFML(sf.c.sfText_getFillColor(self.ptr));
}
/// Sets the fill color of this text
pub fn setFillColor(self: Self, color: sf.Color) void {
sf.c.sfText_setFillColor(self.ptr, color.toCSFML());
}
/// Gets the outline color of this text
pub fn getOutlineColor(self: Self) sf.Color {
return sf.Color.fromCSFML(sf.c.sfText_getOutlineColor(self.ptr));
}
/// Sets the outline color of this text
pub fn setOutlineColor(self: Self, color: sf.Color) void {
sf.c.sfText_setOutlineColor(self.ptr, color.toCSFML());
}
/// Gets the outline thickness of this text
pub fn getOutlineThickness(self: Self) f32 {
return sf.c.sfText_getOutlineThickness(self.ptr);
}
/// Sets the outline thickness of this text
pub fn setOutlineThickness(self: Self, thickness: f32) void {
sf.c.sfText_setOutlineThickness(self.ptr, thickness);
}
/// Gets the position of this text
pub fn getPosition(self: Self) sf.Vector2f {
return sf.Vector2f.fromCSFML(sf.c.sfText_getPosition(self.ptr));
}
/// Sets the position of this text
pub fn setPosition(self: Self, pos: sf.Vector2f) void {
sf.c.sfText_setPosition(self.ptr, pos.toCSFML());
}
/// Adds the offset to this text
pub fn move(self: Self, offset: sf.Vector2f) void {
sf.c.sfText_move(self.ptr, offset.toCSFML());
}
/// Gets the origin of this text
pub fn getOrigin(self: Self) sf.Vector2f {
return sf.Vector2f.fromCSFML(sf.c.sfText_getOrigin(self.ptr));
}
/// Sets the origin of this text
pub fn setOrigin(self: Self, origin: sf.Vector2f) void {
sf.c.sfText_setOrigin(self.ptr, origin.toCSFML());
}
/// Gets the rotation of this text
pub fn getRotation(self: Self) f32 {
return sf.c.sfText_getRotation(self.ptr);
}
/// Sets the rotation of this text
pub fn setRotation(self: Self, angle: f32) void {
sf.c.sfText_setRotation(self.ptr, angle);
}
/// Rotates this text by a given amount
pub fn rotate(self: Self, angle: f32) void {
sf.c.sfText_rotate(self.ptr, angle);
}
/// Gets the scale of this text
pub fn getScale(self: Self) sf.Vector2f {
return sf.Vector2f.fromCSFML(sf.c.sfText_getScale(self.ptr));
}
/// Sets the scale of this text
pub fn setScale(self: Self, factor: sf.Vector2f) void {
sf.c.sfText_setScale(self.ptr, factor.toCSFML());
}
/// Scales this text
pub fn scale(self: Self, factor: sf.Vector2f) void {
sf.c.sfText_scale(self.ptr, factor.toCSFML());
}
/// return the position of the index-th character
pub fn findCharacterPos(self: Self, index: usize) sf.Vector2f {
return sf.Vector2f.fromCSFML(sf.c.sfText_findCharacterPos(self.ptr));
}
/// Gets the letter spacing factor
pub fn getLetterSpacing(self: Self) f32 {
return sf.c.sfText_getLetterSpacing(self.ptr);
}
/// Sets the letter spacing factor
pub fn setLetterSpacing(self: Self, spacing_factor: f32) void {
sf.c.sfText_setLetterSpacing(self.ptr, spacing_factor);
}
/// Gets the line spacing factor
pub fn getLineSpacing(self: Self) f32 {
return sf.c.sfText_getLineSpacing(self.ptr);
}
/// Sets the line spacing factor
pub fn setLineSpacing(self: Self, spacing_factor: f32) void {
sf.c.sfText_setLineSpacing(self.ptr, spacing_factor);
}
/// Gets the local bounding rectangle of the text
pub fn getLocalBounds(self: Self) sf.FloatRect {
return sf.FloatRect.fromCSFML(sf.c.sfText_getLocalBounds(self.ptr));
}
/// Gets the global bounding rectangle of the text
pub fn getGlobalBounds(self: Self) sf.FloatRect {
return sf.FloatRect.fromCSFML(sf.c.sfText_getGlobalBounds(self.ptr));
}
pub const getTransform = @compileError("Function is not implemented yet.");
pub const getInverseTransform = @compileError("Function is not implemented yet.");
/// Pointer to the csfml font
ptr: *sf.c.sfText,
};
test "text: sane getters and setters" {
const tst = @import("std").testing;
var text = try Text.init();
defer text.deinit();
text.setFillColor(sf.Color.Yellow);
text.setOutlineColor(sf.Color.Red);
text.setOutlineThickness(2);
text.setCharacterSize(10);
text.setRotation(15);
text.setPosition(.{ .x = 1, .y = 2 });
text.setOrigin(.{ .x = 20, .y = 25 });
text.setScale(.{ .x = 2, .y = 2 });
text.rotate(5);
text.move(.{ .x = -5, .y = 5 });
text.scale(.{ .x = 2, .y = 3 });
//getfillcolor
//getoutlinecolor
tst.expectEqual(@as(f32, 2), text.getOutlineThickness());
tst.expectEqual(@as(usize, 10), text.getCharacterSize());
tst.expectEqual(@as(f32, 20), text.getRotation());
tst.expectEqual(sf.Vector2f{ .x = -4, .y = 7 }, text.getPosition());
tst.expectEqual(sf.Vector2f{ .x = 20, .y = 25 }, text.getOrigin());
tst.expectEqual(sf.Vector2f{ .x = 4, .y = 6 }, text.getScale());
_ = text.getLocalBounds();
_ = text.getGlobalBounds();
} | src/sfml/graphics/text.zig |
const std = @import("std");
usingnamespace std.os.windows;
pub const WNDPROC = ?extern fn (HWND, UINT, WPARAM, LPARAM) LRESULT;
pub const HWND = HANDLE;
pub const LPARAM = i64;
pub const WPARAM = u64;
pub const LRESULT = i64;
pub const WNDCLASS = extern struct {
style: UINT,
wndProc: WNDPROC,
cbClsExtra: c_int,
cbWndExtra: c_int,
hInstance: ?HANDLE,
hIcon: ?HANDLE,
hCursor: ?HANDLE,
hbrBackground: ?HANDLE,
lpszMenuName: ?LPCTSTR,
lpszClassName: LPCTSTR,
};
const POINT = extern struct {
x: LONG,
y: LONG,
};
const MSG = extern struct {
hwnd: HWND,
message: UINT,
wParam: WPARAM,
lParam: LPARAM,
time: DWORD,
pt: POINT,
};
extern "user32" stdcallcc fn RegisterClassA(
lpWndClass: [*c]const WNDCLASS) c_ushort;
extern "user32" stdcallcc fn DefWindowProcA(
hWnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM) LRESULT;
extern "user32" stdcallcc fn CreateWindowExA(
dwExStyle: DWORD, lpClassName: LPCSTR, lpWindowName: LPCSTR,
dwStyle: DWORD, x: c_int, y: c_int, nWidth: c_int, nHeight: c_int,
hWndParent: ?HWND, hMenu: ?HANDLE, hInstance: ?HANDLE, lpParam: ?LPVOID) HWND;
export fn WndProc(hWnd: HWND, message: UINT, wParam: WPARAM, lParam: LPARAM) LRESULT {
return DefWindowProcA(hWnd, message, wParam, lParam);
}
extern "user32" stdcallcc fn PeekMessageA(
msg: *MSG,
hwnd: ?HWND,
wMsgFilterMin: UINT,
wMsgFilterMax: UINT,
wRemoveMsg: UINT) c_int;
extern "user32" stdcallcc fn TranslateMessage(msg: [*c]MSG) c_int;
extern "user32" stdcallcc fn DispatchMessageA(msg: [*c]MSG) LRESULT;
pub fn CreateWin() bool {
const wc = WNDCLASS {
.style = 0,
.wndProc = WndProc,
.cbClsExtra = 0,
.cbWndExtra = 0,
.hInstance = null,
.hIcon = null,
.hCursor = null,
.hbrBackground = null,
.lpszMenuName = null,
.lpszClassName = "My window",
};
_ = RegisterClassA(&wc);
const windowStyle: c_uint = @as(c_uint,
0x10000000 | 0xc00000 | 0x80000 | 0x40000 | 0x20000 | 0x10000);
var hWnd: HWND = CreateWindowExA(@as(DWORD, 0),
wc.lpszClassName, wc.lpszClassName,
@as(DWORD, windowStyle), @as(c_int, -2147483648),
@as(c_int, -2147483648), 200, 200,
null,
null,
null,
null);
return true;
}
pub fn UpdateWindow() void {
var msg: MSG = undefined;
const PM_REMOVE: c_uint = 1;
while (PeekMessageA(&msg, null, 0, 0, PM_REMOVE) != 0) {
_ = TranslateMessage(&msg);
_ = DispatchMessageA(&msg);
}
} | window.zig |
const std = @import("std");
const sling = @import("sling.zig");
const Font = @This();
// I'm sorry about the code youre about to read
// please take solace in the fact that is only run once
// on load. I will rewrite more zig-like later, and support more
// formats.
pub const Information = struct {
name: []const u8,
fontSize: f32,
lineHeight: f32,
bold: bool,
italic: bool,
atlasSize: sling.math.Vec2,
};
pub const Page = struct {
texture: usize = undefined,
};
pub const Character = struct {
atlas: usize,
atlasSourceRect: sling.math.Rect,
offset: sling.math.Vec2,
advance: f32,
};
information: Information = undefined,
pages: std.ArrayList(usize) = std.ArrayList(usize).init(sling.alloc),
characters: std.AutoHashMap(u8, Character) = std.AutoHashMap(u8, Character).init(sling.alloc),
/// Provide root as the base folder, for loading the accompanying pngs.
pub fn loadBmFontAscii(bytes: []const u8, root: []const u8) Font {
var self: Font = .{};
var tokens = std.mem.tokenize(u8, bytes, "\n\r ");
var consumingChars: ?usize = null;
var dictionary = std.StringHashMap([]const u8).init(sling.alloc);
var chars = std.ArrayList(std.StringHashMap([]const u8)).init(sling.alloc);
while (tokens.next()) |token| {
if (std.mem.eql(u8, token, "char")) {
if (consumingChars == null) {
consumingChars = 0;
} else {
consumingChars.? += 1;
}
chars.append(std.StringHashMap([]const u8).init(sling.alloc)) catch unreachable;
continue;
}
if (std.mem.containsAtLeast(u8, token, 1, "=")) {
var tag: []const u8 = undefined;
var value: []const u8 = undefined;
for (token) |char, i| {
if (char == '=') {
tag = token[0..i];
value = token[i + 1 ..];
break;
}
}
if (std.mem.eql(u8, tag, "file")) {
var texturePath = std.fs.path.joinZ(sling.alloc, &[_][]const u8{ root, std.mem.trim(u8, value, "\"") }) catch unreachable;
self.pages.append(sling.asset.ensure(sling.asset.Texture, texturePath)) catch unreachable;
continue;
}
if (consumingChars) |charInd| {
chars.items[charInd].put(tag, value) catch unreachable;
} else {
dictionary.put(tag, value) catch unreachable;
}
}
}
self.rawParseToFont(&dictionary, &chars);
return self;
}
fn rawParseToFont(self: *Font, meta: *std.StringHashMap([]const u8), chars: *std.ArrayList(std.StringHashMap([]const u8))) void {
defer meta.deinit();
defer chars.deinit();
if (meta.get("face")) |face| {
self.information.name = sling.alloc.dupeZ(u8, std.mem.trim(u8, face, "\"")) catch unreachable;
}
if (meta.get("size")) |size| {
self.information.fontSize = parseToFloat(size);
}
if (meta.get("scaleW")) |size| {
self.information.atlasSize.x = parseToFloat(size);
}
if (meta.get("scaleH")) |size| {
self.information.atlasSize.y = parseToFloat(size);
}
if (meta.get("bold")) |val| {
self.information.bold = parseToBool(val);
}
if (meta.get("italic")) |val| {
self.information.italic = parseToBool(val);
}
if (meta.get("lineHeight")) |val| {
self.information.lineHeight = parseToFloat(val);
}
for (chars.items) |dict| {
var char: Character = undefined;
var id = std.fmt.parseUnsigned(u32, dict.get("id").?, 10) catch unreachable;
// todo, advanced unicode points:
if (id >= std.math.maxInt(u8)) {
continue;
}
if (dict.get("page")) |val| {
char.atlas = std.fmt.parseInt(usize, val, 10) catch unreachable;
}
if (dict.get("x")) |val| {
char.atlasSourceRect.position.x = parseToFloat(val);
}
if (dict.get("y")) |val| {
char.atlasSourceRect.position.y = parseToFloat(val);
}
if (dict.get("width")) |val| {
char.atlasSourceRect.size.x = parseToFloat(val);
}
if (dict.get("height")) |val| {
char.atlasSourceRect.size.y = parseToFloat(val);
}
if (dict.get("xoffset")) |val| {
char.offset.x = parseToFloat(val);
}
if (dict.get("yoffset")) |val| {
char.offset.y = parseToFloat(val);
}
if (dict.get("xadvance")) |val| {
char.advance = parseToFloat(val);
}
self.characters.put(@intCast(u8, id), char) catch unreachable;
}
}
fn parseToFloat(value: []const u8) f32 {
if (std.mem.containsAtLeast(u8, value, 1, ".")) {
return std.fmt.parseFloat(f32, value) catch unreachable;
} else {
return @intToFloat(f32, std.fmt.parseInt(i32, value, 10) catch {
std.debug.panic("Failed to parse {s}", .{value});
});
}
}
fn parseToBool(value: []const u8) bool {
if (std.mem.eql(u8, value, "1") or std.mem.eql(u8, value, "true")) {
return true;
}
return false;
}
pub fn loadBmFontAsciiPath(path: []const u8) Font {
var bytes = std.fs.cwd().readFileAlloc(sling.alloc, path, 10_000_000) catch unreachable;
defer sling.alloc.free(bytes);
var root = std.fs.path.dirname(path).?;
return loadBmFontAscii(bytes, root);
} | src/font.zig |
const bu = @import("./bits.zig"); // bits utilities
const std = @import("std");
const assert = std.debug.assert;
const mem = std.mem;
// Input bitstream.
pub const istream_t = struct {
src: [*]const u8, // Source bytes.
end: [*]const u8, // Past-the-end byte of src.
bitpos: usize, // Position of the next bit to read.
bitpos_end: usize, // Position of past-the-end bit.
};
// Initialize an input stream to present the n bytes from src as an LSB-first bitstream.
pub inline fn istream_init(is: *istream_t, src: [*]const u8, n: usize) void {
is.src = src;
is.end = src + n;
is.bitpos = 0;
is.bitpos_end = n * 8;
}
pub const ISTREAM_MIN_BITS = (64 - 7);
// Get the next bits from the input stream. The number of bits returned is
// between ISTREAM_MIN_BITS and 64, depending on the position in the stream, or
// fewer if the end of stream is reached. The upper bits are zero-padded.
pub inline fn istream_bits(is: *const istream_t) u64 {
var next: [*]const u8 = @ptrCast([*]const u8, &is.src[is.bitpos / 8]);
var bits: u64 = 0;
var i: usize = 0;
assert(@ptrToInt(next) <= @ptrToInt(is.end)); // "Cannot read past end of stream."
if (@ptrToInt(is.end) - @ptrToInt(next) >= 8) {
// Common case: read 8 bytes in one go.
bits = bu.read64le(next);
} else {
// Read the available bytes and zero-pad.
bits = 0;
i = 0;
while (i < @ptrToInt(is.end) - @ptrToInt(next)) : (i += 1) {
bits |= @intCast(u64, next[i]) << (@intCast(u6, i) * 8);
}
}
return bits >> (@intCast(u6, is.bitpos % 8));
}
// Advance n bits in the bitstream if possible. Returns false if that many bits
// are not available in the stream.
pub inline fn istream_advance(is: *istream_t, n: usize) bool {
assert(is.bitpos <= is.bitpos_end);
if (is.bitpos_end - is.bitpos < n) {
return false;
}
is.bitpos += n;
return true;
}
// Align the input stream to the next 8-bit boundary and return a pointer to
// that byte, which may be the past-the-end-of-stream byte.
pub inline fn istream_byte_align(is: *istream_t) *const u8 {
var byte: *const u8 = undefined;
assert(is.bitpos <= is.bitpos_end); // "Not past end of stream."
is.bitpos = bu.round_up(is.bitpos, 8);
byte = &is.src[is.bitpos / 8];
assert(@ptrToInt(byte) <= @ptrToInt(is.end));
return byte;
}
pub inline fn istream_bytes_read(is: *istream_t) usize {
return bu.round_up(is.bitpos, 8) / 8;
}
// Output bitstream.
pub const ostream_t = struct {
dst: [*]u8,
end: [*]u8,
bitpos: usize,
bitpos_end: usize,
};
// Initialize an output stream to write LSB-first bits into dst[0..n-1].
pub inline fn ostream_init(os: *ostream_t, dst: [*]u8, n: usize) void {
os.dst = dst;
os.end = dst + n;
os.bitpos = 0;
os.bitpos_end = n * 8;
}
// Get the current bit position in the stream.
pub inline fn ostream_bit_pos(os: *const ostream_t) usize {
return os.bitpos;
}
// Return the number of bytes written to the output buffer.
pub inline fn ostream_bytes_written(os: *ostream_t) usize {
return bu.round_up(os.bitpos, 8) / 8;
}
// Write n bits to the output stream. Returns false if there is not enough room
// at the destination.
pub inline fn ostream_write(os: *ostream_t, bits: u64, n: usize) bool {
var p: [*]u8 = undefined;
var x: u64 = undefined;
var shift: u6 = 0;
var i: usize = 0;
assert(n <= 57);
assert(bits <= (@as(u64, 1) << @intCast(u6, n)) - 1); // "Must fit in n bits."
if (os.bitpos_end - os.bitpos < n) {
// Not enough room.
return false;
}
p = @ptrCast([*]u8, &os.dst[os.bitpos / 8]);
shift = @intCast(u6, os.bitpos % 8);
if (@ptrToInt(os.end) - @ptrToInt(p) >= 8) {
// Common case: read and write 8 bytes in one go.
x = bu.read64le(p);
x = bu.lsb(x, shift);
x |= bits << shift;
bu.write64le(p, x);
} else {
// Slow case: read/write as many bytes as are available.
x = 0;
i = 0;
while (i < @intCast(usize, @ptrToInt(os.end) - @ptrToInt(p))) : (i += 1) {
x |= @intCast(u64, p[i]) << @intCast(u6, i * 8);
}
x = bu.lsb(x, shift);
x |= bits << shift;
i = 0;
while (i < @intCast(usize, @ptrToInt(os.end) - @ptrToInt(p))) : (i += 1) {
p[i] = @truncate(u8, (x >> @intCast(u6, i * 8)));
}
}
os.bitpos += n;
return true;
}
// Align the bitstream to the next byte boundary, then write the n bytes from
// src to it. Returns false if there is not enough room in the stream.
pub inline fn ostream_write_bytes_aligned(os: *ostream_t, src: [*]const u8, n: usize) bool {
if (os.bitpos_end - bu.round_up(os.bitpos, 8) < n * 8) {
return false;
}
os.bitpos = bu.round_up(os.bitpos, 8);
const nearest_byte = os.bitpos / 8;
mem.copy(u8, os.dst[nearest_byte .. nearest_byte + n], src[0..n]);
os.bitpos += n * 8;
return true;
} | src/bitstream.zig |
const std = @import("std");
const Arena = std.heap.ArenaAllocator;
const expectEqual = std.testing.expectEqual;
const expectEqualStrings = std.testing.expectEqualStrings;
const yeti = @import("yeti");
const initCodebase = yeti.initCodebase;
const tokenize = yeti.tokenize;
const parse = yeti.parse;
const analyzeSemantics = yeti.analyzeSemantics;
const codegen = yeti.codegen;
const printWasm = yeti.printWasm;
const components = yeti.components;
const literalOf = yeti.query.literalOf;
const typeOf = yeti.query.typeOf;
const MockFileSystem = yeti.FileSystem;
const Entity = yeti.ecs.Entity;
test "tokenize mulitine function with binary op" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const module = try codebase.createEntity(.{});
const code =
\\sum_of_squares(x: u64, y: u64) u64 {
\\ x2 = x * x
\\ x2 = y * y
\\ x2 + y2
\\}
;
var tokens = try tokenize(module, code);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .left_paren);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .colon);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .comma);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .colon);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .right_paren);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .left_brace);
try expectEqual(tokens.next().?.get(components.TokenKind), .new_line);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .equal);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .times);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .new_line);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .equal);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .times);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .new_line);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .plus);
try expectEqual(tokens.next().?.get(components.TokenKind), .symbol);
try expectEqual(tokens.next().?.get(components.TokenKind), .new_line);
try expectEqual(tokens.next().?.get(components.TokenKind), .right_brace);
try expectEqual(tokens.next(), null);
}
test "greater operators" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const module = try codebase.createEntity(.{});
const code = "> >= = == : < <= >> <<";
var tokens = try tokenize(module, code);
{
const token = tokens.next().?;
try expectEqual(token.get(components.TokenKind), .greater_than);
try expectEqual(token.get(components.Span), .{
.begin = .{ .column = 0, .row = 0 },
.end = .{ .column = 1, .row = 0 },
});
}
{
const token = tokens.next().?;
try expectEqual(token.get(components.TokenKind), .greater_equal);
try expectEqual(token.get(components.Span), .{
.begin = .{ .column = 2, .row = 0 },
.end = .{ .column = 4, .row = 0 },
});
}
{
const token = tokens.next().?;
try expectEqual(token.get(components.TokenKind), .equal);
try expectEqual(token.get(components.Span), .{
.begin = .{ .column = 5, .row = 0 },
.end = .{ .column = 6, .row = 0 },
});
}
{
const token = tokens.next().?;
try expectEqual(token.get(components.TokenKind), .equal_equal);
try expectEqual(token.get(components.Span), .{
.begin = .{ .column = 7, .row = 0 },
.end = .{ .column = 9, .row = 0 },
});
}
{
const token = tokens.next().?;
try expectEqual(token.get(components.TokenKind), .colon);
try expectEqual(token.get(components.Span), .{
.begin = .{ .column = 10, .row = 0 },
.end = .{ .column = 11, .row = 0 },
});
}
{
const token = tokens.next().?;
try expectEqual(token.get(components.TokenKind), .less_than);
try expectEqual(token.get(components.Span), .{
.begin = .{ .column = 12, .row = 0 },
.end = .{ .column = 13, .row = 0 },
});
}
{
const token = tokens.next().?;
try expectEqual(token.get(components.TokenKind), .less_equal);
try expectEqual(token.get(components.Span), .{
.begin = .{ .column = 14, .row = 0 },
.end = .{ .column = 16, .row = 0 },
});
}
{
const token = tokens.next().?;
try expectEqual(token.get(components.TokenKind), .greater_greater);
try expectEqual(token.get(components.Span), .{
.begin = .{ .column = 17, .row = 0 },
.end = .{ .column = 19, .row = 0 },
});
}
{
const token = tokens.next().?;
try expectEqual(token.get(components.TokenKind), .less_less);
try expectEqual(token.get(components.Span), .{
.begin = .{ .column = 20, .row = 0 },
.end = .{ .column = 22, .row = 0 },
});
}
try expectEqual(tokens.next(), null);
}
test "parse grouping with parenthesis" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const module = try codebase.createEntity(.{});
const code =
\\start() u64 {
\\ (5 + 10) * 3
\\}
;
var tokens = try tokenize(module, code);
try parse(module, &tokens);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start");
const overloads = start.get(components.Overloads).slice();
try expectEqual(overloads.len, 1);
const body = overloads[0].get(components.Body).slice();
try expectEqual(body.len, 1);
const multiply = body[0];
try expectEqual(multiply.get(components.AstKind), .binary_op);
try expectEqual(multiply.get(components.BinaryOp), .multiply);
const multiply_arguments = multiply.get(components.Arguments).slice();
const add = multiply_arguments[0];
try expectEqual(add.get(components.AstKind), .binary_op);
try expectEqual(add.get(components.BinaryOp), .add);
const add_arguments = add.get(components.Arguments).slice();
try expectEqualStrings(literalOf(add_arguments[0]), "5");
try expectEqualStrings(literalOf(add_arguments[1]), "10");
try expectEqualStrings(literalOf(multiply_arguments[1]), "3");
}
test "analyze semantics binary op two comptime known" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const builtins = codebase.get(components.Builtins);
const types = [_][]const u8{ "i64", "i32", "i16", "i8", "u64", "u32", "u16", "u8", "f64", "f32" };
const builtin_types = [_]Entity{ builtins.I64, builtins.I32, builtins.I16, builtins.I8, builtins.U64, builtins.U32, builtins.U16, builtins.U8, builtins.F64, builtins.F32 };
const op_strings = [_][]const u8{ "+", "-", "*", "/" };
const intrinsics = [_]components.Intrinsic{ .add, .subtract, .multiply, .divide };
for (op_strings) |op_string, op_index| {
for (types) |type_of, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ x: {s} = 10
\\ y: {s} = 32
\\ x {s} y
\\}}
, .{ type_of, type_of, type_of, op_string }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
try expectEqualStrings(literalOf(start.get(components.Module).entity), "foo");
try expectEqualStrings(literalOf(start.get(components.Name).entity), "start");
try expectEqual(start.get(components.Parameters).len(), 0);
try expectEqual(start.get(components.ReturnType).entity, builtin_types[i]);
const body = start.get(components.Body).slice();
try expectEqual(body.len, 3);
const x = blk: {
const define = body[0];
try expectEqual(define.get(components.AstKind), .define);
try expectEqual(typeOf(define), builtins.Void);
try expectEqualStrings(literalOf(define.get(components.Value).entity), "10");
const local = define.get(components.Local).entity;
try expectEqual(local.get(components.AstKind), .local);
try expectEqualStrings(literalOf(local.get(components.Name).entity), "x");
try expectEqual(typeOf(local), builtin_types[i]);
break :blk local;
};
const y = blk: {
const define = body[1];
try expectEqual(define.get(components.AstKind), .define);
try expectEqual(typeOf(define), builtins.Void);
try expectEqualStrings(literalOf(define.get(components.Value).entity), "32");
const local = define.get(components.Local).entity;
try expectEqual(local.get(components.AstKind), .local);
try expectEqualStrings(literalOf(local.get(components.Name).entity), "y");
try expectEqual(typeOf(local), builtin_types[i]);
break :blk local;
};
const intrinsic = body[2];
try expectEqual(intrinsic.get(components.AstKind), .intrinsic);
try expectEqual(intrinsic.get(components.Intrinsic), intrinsics[op_index]);
try expectEqual(typeOf(intrinsic), builtin_types[i]);
const arguments = intrinsic.get(components.Arguments).slice();
try expectEqual(arguments.len, 2);
try expectEqual(arguments[0], x);
try expectEqual(arguments[1], y);
}
}
}
test "analyze semantics comparison op two comptime known" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const builtins = codebase.get(components.Builtins);
const types = [_][]const u8{ "i64", "i32", "i16", "i8", "u64", "u32", "u16", "u8", "f64", "f32" };
const builtin_types = [_]Entity{ builtins.I64, builtins.I32, builtins.I16, builtins.I8, builtins.U64, builtins.U32, builtins.U16, builtins.U8, builtins.F64, builtins.F32 };
const op_strings = [_][]const u8{ "==", "!=", "<", "<=", ">", ">=" };
const intrinsics = [_]components.Intrinsic{
.equal,
.not_equal,
.less_than,
.less_equal,
.greater_than,
.greater_equal,
};
for (op_strings) |op_string, op_index| {
for (types) |type_of, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() i32 {{
\\ x: {s} = 10
\\ y: {s} = 32
\\ x {s} y
\\}}
, .{ type_of, type_of, op_string }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
try expectEqualStrings(literalOf(start.get(components.Module).entity), "foo");
try expectEqualStrings(literalOf(start.get(components.Name).entity), "start");
try expectEqual(start.get(components.Parameters).len(), 0);
try expectEqual(start.get(components.ReturnType).entity, builtins.I32);
const body = start.get(components.Body).slice();
try expectEqual(body.len, 3);
const x = blk: {
const define = body[0];
try expectEqual(define.get(components.AstKind), .define);
try expectEqual(typeOf(define), builtins.Void);
try expectEqualStrings(literalOf(define.get(components.Value).entity), "10");
const local = define.get(components.Local).entity;
try expectEqual(local.get(components.AstKind), .local);
try expectEqualStrings(literalOf(local.get(components.Name).entity), "x");
try expectEqual(typeOf(local), builtin_types[i]);
break :blk local;
};
const y = blk: {
const define = body[1];
try expectEqual(define.get(components.AstKind), .define);
try expectEqual(typeOf(define), builtins.Void);
try expectEqualStrings(literalOf(define.get(components.Value).entity), "32");
const local = define.get(components.Local).entity;
try expectEqual(local.get(components.AstKind), .local);
try expectEqualStrings(literalOf(local.get(components.Name).entity), "y");
try expectEqual(typeOf(local), builtin_types[i]);
break :blk local;
};
const intrinsic = body[2];
try expectEqual(intrinsic.get(components.AstKind), .intrinsic);
try expectEqual(intrinsic.get(components.Intrinsic), intrinsics[op_index]);
try expectEqual(typeOf(intrinsic), builtins.I32);
const arguments = intrinsic.get(components.Arguments).slice();
try expectEqual(arguments.len, 2);
try expectEqual(arguments[0], x);
try expectEqual(arguments[1], y);
}
}
}
test "codegen binary op two literals" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const types = [_][]const u8{ "i64", "i32", "i16", "i8", "u64", "u32", "u16", "u8", "f64", "f32" };
const const_kinds = [_]components.WasmInstructionKind{ .i64_const, .i32_const, .i32_const, .i32_const, .i64_const, .i32_const, .i32_const, .i32_const, .f64_const, .f32_const };
const op_strings = [_][]const u8{ "+", "-", "*", "/" };
const results = [_][10][]const u8{
[_][]const u8{ "10", "10", "10", "10", "10", "10", "10", "10", "1.0e+01", "1.0e+01" },
[_][]const u8{ "6", "6", "6", "6", "6", "6", "6", "6", "6.0e+00", "6.0e+00" },
[_][]const u8{ "16", "16", "16", "16", "16", "16", "16", "16", "1.6e+01", "1.6e+01" },
[_][]const u8{ "4", "4", "4", "4", "4", "4", "4", "4", "4.0e+00", "4.0e+00" },
};
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ 8 {s} 2
\\}}
, .{ type_, op_string }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 1);
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), results[op_index][i]);
}
}
}
test "codegen binary op int and float literal" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti",
\\start() {
\\ 8 + 2.0
\\}
);
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 1);
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), .f32_const);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "1.0e+01");
}
test "codegen binary op float and int literal" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti",
\\start() {
\\ 8.0 + 2
\\}
);
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 1);
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), .f32_const);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "1.0e+01");
}
test "codegen arithmetic binary op two local constants" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const types = [_][]const u8{ "i64", "i32", "i16", "i8", "u64", "u32", "u16", "u8", "f64", "f32" };
const const_kinds = [_]components.WasmInstructionKind{ .i64_const, .i32_const, .i32_const, .i32_const, .i64_const, .i32_const, .i32_const, .i32_const, .f64_const, .f32_const };
const op_strings = [_][]const u8{ "+", "-", "*", "/" };
const results = [_][10][]const u8{
[_][]const u8{ "10", "10", "10", "10", "10", "10", "10", "10", "1.0e+01", "1.0e+01" },
[_][]const u8{ "6", "6", "6", "6", "6", "6", "6", "6", "6.0e+00", "6.0e+00" },
[_][]const u8{ "16", "16", "16", "16", "16", "16", "16", "16", "1.6e+01", "1.6e+01" },
[_][]const u8{ "4", "4", "4", "4", "4", "4", "4", "4", "4.0e+00", "4.0e+00" },
};
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ x: {s} = 8
\\ y: {s} = 2
\\ x {s} y
\\}}
, .{ type_, type_, type_, op_string }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 1);
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), results[op_index][i]);
}
}
}
test "codegen int binary op two local constants" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const types = [_][]const u8{ "i64", "i32", "u64", "u32" };
const const_kinds = [_]components.WasmInstructionKind{ .i64_const, .i32_const, .i64_const, .i32_const };
const op_strings = [_][]const u8{ "%", "&", "|", "^", "<<", ">>" };
const results = [_][4][]const u8{
[_][]const u8{ "0", "0", "0", "0" },
[_][]const u8{ "0", "0", "0", "0" },
[_][]const u8{ "10", "10", "10", "10" },
[_][]const u8{ "10", "10", "10", "10" },
[_][]const u8{ "32", "32", "32", "32" },
[_][]const u8{ "2", "2", "2", "2" },
};
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ x: {s} = 8
\\ y: {s} = 2
\\ x {s} y
\\}}
, .{ type_, type_, type_, op_string }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 1);
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), results[op_index][i]);
}
}
}
test "codegen int comparison op two local constants" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const types = [_][]const u8{ "i64", "i32", "i16", "i8", "u64", "u32", "u16", "u8", "f64", "f32" };
const const_kinds = [_]components.WasmInstructionKind{ .i32_const, .i32_const, .i32_const, .i32_const, .i32_const, .i32_const, .i32_const, .i32_const, .i32_const, .i32_const };
const op_strings = [_][]const u8{ "==", "!=", "<", "<=", ">", ">=" };
const results = [_][10][]const u8{
[_][]const u8{ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" },
[_][]const u8{ "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" },
[_][]const u8{ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" },
[_][]const u8{ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" },
[_][]const u8{ "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" },
[_][]const u8{ "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" },
};
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() i32 {{
\\ x: {s} = 8
\\ y: {s} = 2
\\ x {s} y
\\}}
, .{ type_, type_, op_string }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 1);
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), results[op_index][i]);
}
}
}
test "codegen int comparison op two local constants one unused" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti",
\\start() i32 {
\\ a = 8
\\ b = 2
\\ c = a == b
\\ a
\\}
);
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 3);
{
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), .i32_const);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "0");
}
{
const local_set = start_instructions[1];
try expectEqual(local_set.get(components.WasmInstructionKind), .local_set);
try expectEqualStrings(literalOf(local_set.get(components.Local).entity.get(components.Name).entity), "c");
}
{
const constant = start_instructions[2];
try expectEqual(constant.get(components.WasmInstructionKind), .i32_const);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "8");
}
}
test "codegen arithmethic binary op non constant" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const types = [_][]const u8{ "i64", "i32", "i16", "i8", "u64", "u32", "u16", "u8", "f64", "f32" };
const const_kinds = [_]components.WasmInstructionKind{ .i64_const, .i32_const, .i32_const, .i32_const, .i64_const, .i32_const, .i32_const, .i32_const, .f64_const, .f32_const };
const op_kinds = [_][10]components.WasmInstructionKind{
[_]components.WasmInstructionKind{ .i64_add, .i32_add, .i32_add_mod_16, .i32_add_mod_8, .i64_add, .i32_add, .i32_add_mod_16, .i32_add_mod_8, .f64_add, .f32_add },
[_]components.WasmInstructionKind{ .i64_sub, .i32_sub, .i32_sub_mod_16, .i32_sub_mod_8, .i64_sub, .i32_sub, .i32_sub_mod_16, .i32_sub_mod_8, .f64_sub, .f32_sub },
[_]components.WasmInstructionKind{ .i64_mul, .i32_mul, .i32_mul_mod_16, .i32_mul_mod_8, .i64_mul, .i32_mul, .i32_mul_mod_16, .i32_mul_mod_8, .f64_mul, .f32_mul },
[_]components.WasmInstructionKind{ .i64_div, .i32_div, .i32_div, .i32_div, .u64_div, .u32_div, .u32_div, .u32_div, .f64_div, .f32_div },
};
const op_strings = [_][]const u8{ "+", "-", "*", "/" };
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ id(10) {s} id(25)
\\}}
\\
\\id(x: {s}) {s} {{
\\ x
\\}}
, .{ type_, op_string, type_, type_ }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 5);
const id = blk: {
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "10");
const call = start_instructions[1];
try expectEqual(call.get(components.WasmInstructionKind), .call);
const callable = call.get(components.Callable).entity;
try expectEqualStrings(literalOf(callable.get(components.Name).entity), "id");
break :blk callable;
};
{
const constant = start_instructions[2];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "25");
const call = start_instructions[3];
try expectEqual(call.get(components.WasmInstructionKind), .call);
const callable = call.get(components.Callable).entity;
try expectEqual(callable, id);
}
const op = start_instructions[4];
try expectEqual(op.get(components.WasmInstructionKind), op_kinds[op_index][i]);
const id_instructions = id.get(components.WasmInstructions).slice();
try expectEqual(id_instructions.len, 1);
const local_get = id_instructions[0];
try expectEqual(local_get.get(components.WasmInstructionKind), .local_get);
const local = local_get.get(components.Local).entity;
try expectEqualStrings(literalOf(local), "x");
}
}
}
test "codegen int binary op non constant" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const types = [_][]const u8{ "i64", "i32", "u64", "u32" };
const const_kinds = [_]components.WasmInstructionKind{ .i64_const, .i32_const, .i64_const, .i32_const };
const op_kinds = [_][4]components.WasmInstructionKind{
[_]components.WasmInstructionKind{ .i64_and, .i32_and, .i64_and, .i32_and },
[_]components.WasmInstructionKind{ .i64_or, .i32_or, .i64_or, .i32_or },
[_]components.WasmInstructionKind{ .i64_xor, .i32_xor, .i64_xor, .i32_xor },
[_]components.WasmInstructionKind{ .i64_shl, .i32_shl, .u64_shl, .u32_shl },
[_]components.WasmInstructionKind{ .i64_shr, .i32_shr, .u64_shr, .u32_shr },
[_]components.WasmInstructionKind{ .i64_rem, .i32_rem, .u64_rem, .u32_rem },
};
const op_strings = [_][]const u8{ "&", "|", "^", "<<", ">>", "%" };
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ id(10) {s} id(25)
\\}}
\\
\\id(x: {s}) {s} {{
\\ x
\\}}
, .{ type_, op_string, type_, type_ }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 5);
const id = blk: {
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "10");
const call = start_instructions[1];
try expectEqual(call.get(components.WasmInstructionKind), .call);
const callable = call.get(components.Callable).entity;
try expectEqualStrings(literalOf(callable.get(components.Name).entity), "id");
break :blk callable;
};
{
const constant = start_instructions[2];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "25");
const call = start_instructions[3];
try expectEqual(call.get(components.WasmInstructionKind), .call);
const callable = call.get(components.Callable).entity;
try expectEqual(callable, id);
}
const op = start_instructions[4];
try expectEqual(op.get(components.WasmInstructionKind), op_kinds[op_index][i]);
const id_instructions = id.get(components.WasmInstructions).slice();
try expectEqual(id_instructions.len, 1);
const local = id_instructions[0];
try expectEqual(local.get(components.WasmInstructionKind), .local_get);
try expectEqualStrings(literalOf(local.get(components.Local).entity), "x");
}
}
}
test "codegen comparison binary op non constant" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const types = [_][]const u8{ "i64", "i32", "u64", "u32", "f64", "f32" };
const const_kinds = [_]components.WasmInstructionKind{ .i64_const, .i32_const, .i64_const, .i32_const, .f64_const, .f32_const };
const op_kinds = [_][6]components.WasmInstructionKind{
[_]components.WasmInstructionKind{ .i64_eq, .i32_eq, .i64_eq, .i32_eq, .f64_eq, .f32_eq },
[_]components.WasmInstructionKind{ .i64_ne, .i32_ne, .i64_ne, .i32_ne, .f64_ne, .f32_ne },
[_]components.WasmInstructionKind{ .i64_lt, .i32_lt, .i64_lt, .i32_lt, .f64_lt, .f32_lt },
[_]components.WasmInstructionKind{ .i64_le, .i32_le, .i64_le, .i32_le, .f64_le, .f32_le },
[_]components.WasmInstructionKind{ .i64_gt, .i32_gt, .i64_gt, .i32_gt, .f64_gt, .f32_gt },
[_]components.WasmInstructionKind{ .i64_ge, .i32_ge, .i64_ge, .i32_ge, .f64_ge, .f32_ge },
};
const op_strings = [_][]const u8{ "==", "!=", "<", "<=", ">", ">=" };
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() i32 {{
\\ id(10) {s} id(25)
\\}}
\\
\\id(x: {s}) {s} {{
\\ x
\\}}
, .{ op_string, type_, type_ }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const top_level = module.get(components.TopLevel);
const start = top_level.findString("start").get(components.Overloads).slice()[0];
const start_instructions = start.get(components.WasmInstructions).slice();
try expectEqual(start_instructions.len, 5);
const id = blk: {
const constant = start_instructions[0];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "10");
const call = start_instructions[1];
try expectEqual(call.get(components.WasmInstructionKind), .call);
const callable = call.get(components.Callable).entity;
try expectEqualStrings(literalOf(callable.get(components.Name).entity), "id");
break :blk callable;
};
{
const constant = start_instructions[2];
try expectEqual(constant.get(components.WasmInstructionKind), const_kinds[i]);
try expectEqualStrings(literalOf(constant.get(components.Constant).entity), "25");
const call = start_instructions[3];
try expectEqual(call.get(components.WasmInstructionKind), .call);
const callable = call.get(components.Callable).entity;
try expectEqual(callable, id);
}
const op = start_instructions[4];
try expectEqual(op.get(components.WasmInstructionKind), op_kinds[op_index][i]);
const id_instructions = id.get(components.WasmInstructions).slice();
try expectEqual(id_instructions.len, 1);
const local = id_instructions[0];
try expectEqual(local.get(components.WasmInstructionKind), .local_get);
try expectEqualStrings(literalOf(local.get(components.Local).entity), "x");
}
}
}
test "print wasm arithmetic binary op" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const op_strings = [_][]const u8{ "+", "-", "*", "/" };
const results = [_][6][]const u8{
[_][]const u8{ "10", "10", "10", "10", "1.0e+01", "1.0e+01" },
[_][]const u8{ "6", "6", "6", "6", "6.0e+00", "6.0e+00" },
[_][]const u8{ "16", "16", "16", "16", "1.6e+01", "1.6e+01" },
[_][]const u8{ "4", "4", "4", "4", "4.0e+00", "4.0e+00" },
};
const types = [_][]const u8{ "i64", "i32", "u64", "u32", "f64", "f32" };
const wasm_types = [_][]const u8{ "i64", "i32", "i64", "i32", "f64", "f32" };
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ x: {s} = 8
\\ y: {s} = 2
\\ x {s} y
\\}}
, .{ type_, type_, type_, op_string }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const wasm = try printWasm(module);
try expectEqualStrings(wasm, try std.fmt.allocPrint(arena.allocator(),
\\(module
\\
\\ (func $foo/start (result {s})
\\ ({s}.const {s}))
\\
\\ (export "_start" (func $foo/start)))
, .{ wasm_types[i], wasm_types[i], results[op_index][i] }));
}
}
}
test "print wasm int binary op" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const op_strings = [_][]const u8{ "%", "&", "|", "^", "<<", ">>" };
const results = [_][4][]const u8{
[_][]const u8{ "0", "0", "0", "0" },
[_][]const u8{ "0", "0", "0", "0" },
[_][]const u8{ "10", "10", "10", "10" },
[_][]const u8{ "10", "10", "10", "10" },
[_][]const u8{ "32", "32", "32", "32" },
[_][]const u8{ "2", "2", "2", "2" },
};
const types = [_][]const u8{ "i64", "i32", "u64", "u32" };
const wasm_types = [_][]const u8{ "i64", "i32", "i64", "i32" };
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ x: {s} = 8
\\ y: {s} = 2
\\ x {s} y
\\}}
, .{ type_, type_, type_, op_string }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const wasm = try printWasm(module);
try expectEqualStrings(wasm, try std.fmt.allocPrint(arena.allocator(),
\\(module
\\
\\ (func $foo/start (result {s})
\\ ({s}.const {s}))
\\
\\ (export "_start" (func $foo/start)))
, .{ wasm_types[i], wasm_types[i], results[op_index][i] }));
}
}
}
test "print wasm arithmetic binary op non constant" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const op_strings = [_][]const u8{ "+", "-", "*", "/" };
const instructions = [_][6][]const u8{
[_][]const u8{ "i64.add", "i32.add", "i64.add", "i32.add", "f64.add", "f32.add" },
[_][]const u8{ "i64.sub", "i32.sub", "i64.sub", "i32.sub", "f64.sub", "f32.sub" },
[_][]const u8{ "i64.mul", "i32.mul", "i64.mul", "i32.mul", "f64.mul", "f32.mul" },
[_][]const u8{ "i64.div_s", "i32.div_s", "i64.div_u", "i32.div_u", "f64.div", "f32.div" },
};
const types = [_][]const u8{ "i64", "i32", "u64", "u32", "f64", "f32" };
const wasm_types = [_][]const u8{ "i64", "i32", "i64", "i32", "f64", "f32" };
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ id(10) {s} id(25)
\\}}
\\
\\id(x: {s}) {s} {{
\\ x
\\}}
, .{ type_, op_string, type_, type_ }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const wasm = try printWasm(module);
try expectEqualStrings(wasm, try std.fmt.allocPrint(arena.allocator(),
\\(module
\\
\\ (func $foo/start (result {s})
\\ ({s}.const 10)
\\ (call $foo/id..x.{s})
\\ ({s}.const 25)
\\ (call $foo/id..x.{s})
\\ {s})
\\
\\ (func $foo/id..x.{s} (param $x {s}) (result {s})
\\ (local.get $x))
\\
\\ (export "_start" (func $foo/start)))
, .{
wasm_types[i],
wasm_types[i],
type_,
wasm_types[i],
type_,
instructions[op_index][i],
type_,
wasm_types[i],
wasm_types[i],
}));
}
}
}
test "print wasm arithmetic binary op non constant modulo" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const op_strings = [_][]const u8{ "+", "-", "*" };
const instructions = [_][4][]const u8{
[_][]const u8{ "i32.add", "i32.add", "i32.add", "i32.add" },
[_][]const u8{ "i32.sub", "i32.sub", "i32.sub", "i32.sub" },
[_][]const u8{ "i32.mul", "i32.mul", "i32.mul", "i32.mul" },
};
const types = [_][]const u8{ "i16", "i8", "u16", "u8" };
const wasm_types = [_][]const u8{ "i32", "i32", "i32", "i32" };
const constants = [_][]const u8{ "65535", "255", "65535", "255" };
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ id(10) {s} id(25)
\\}}
\\
\\id(x: {s}) {s} {{
\\ x
\\}}
, .{ type_, op_string, type_, type_ }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const wasm = try printWasm(module);
try expectEqualStrings(wasm, try std.fmt.allocPrint(arena.allocator(),
\\(module
\\
\\ (func $foo/start (result {s})
\\ ({s}.const 10)
\\ (call $foo/id..x.{s})
\\ ({s}.const 25)
\\ (call $foo/id..x.{s})
\\ {s}
\\ (i32.const {s})
\\ i32.and)
\\
\\ (func $foo/id..x.{s} (param $x {s}) (result {s})
\\ (local.get $x))
\\
\\ (export "_start" (func $foo/start)))
, .{
wasm_types[i],
wasm_types[i],
type_,
wasm_types[i],
type_,
instructions[op_index][i],
constants[i],
type_,
wasm_types[i],
wasm_types[i],
}));
}
}
}
test "print wasm int binary op non constant" {
var arena = Arena.init(std.heap.page_allocator);
defer arena.deinit();
var codebase = try initCodebase(&arena);
const op_strings = [_][]const u8{ "%", "&", "|", "^", "<<", ">>" };
const instructions = [_][8][]const u8{
[_][]const u8{ "i64.rem_s", "i32.rem_s", "i32.rem_s", "i32.rem_s", "i64.rem_u", "i32.rem_u", "i32.rem_u", "i32.rem_u" },
[_][]const u8{ "i64.and", "i32.and", "i32.and", "i32.and", "i64.and", "i32.and", "i32.and", "i32.and" },
[_][]const u8{ "i64.or", "i32.or", "i32.or", "i32.or", "i64.or", "i32.or", "i32.or", "i32.or" },
[_][]const u8{ "i64.xor", "i32.xor", "i32.xor", "i32.xor", "i64.xor", "i32.xor", "i32.xor", "i32.xor" },
[_][]const u8{ "i64.shl", "i32.shl", "i32.shl", "i32.shl", "i64.shl", "i32.shl", "i32.shl", "i32.shl" },
[_][]const u8{ "i64.shr_s", "i32.shr_s", "i32.shr_s", "i32.shr_s", "i64.shr_u", "i32.shr_u", "i32.shr_u", "i32.shr_u" },
};
const types = [_][]const u8{ "i64", "i32", "i16", "i8", "u64", "u32", "u16", "u8" };
const wasm_types = [_][]const u8{ "i64", "i32", "i32", "i32", "i64", "i32", "i32", "i32" };
for (op_strings) |op_string, op_index| {
for (types) |type_, i| {
var fs = try MockFileSystem.init(&arena);
_ = try fs.newFile("foo.yeti", try std.fmt.allocPrint(arena.allocator(),
\\start() {s} {{
\\ id(10) {s} id(25)
\\}}
\\
\\id(x: {s}) {s} {{
\\ x
\\}}
, .{ type_, op_string, type_, type_ }));
const module = try analyzeSemantics(codebase, fs, "foo.yeti");
try codegen(module);
const wasm = try printWasm(module);
try expectEqualStrings(wasm, try std.fmt.allocPrint(arena.allocator(),
\\(module
\\
\\ (func $foo/start (result {s})
\\ ({s}.const 10)
\\ (call $foo/id..x.{s})
\\ ({s}.const 25)
\\ (call $foo/id..x.{s})
\\ {s})
\\
\\ (func $foo/id..x.{s} (param $x {s}) (result {s})
\\ (local.get $x))
\\
\\ (export "_start" (func $foo/start)))
, .{
wasm_types[i],
wasm_types[i],
type_,
wasm_types[i],
type_,
instructions[op_index][i],
type_,
wasm_types[i],
wasm_types[i],
}));
}
}
} | src/tests/test_binary_op.zig |
const std = @import("../std.zig");
const testing = std.testing;
const math = std.math;
/// Jan 01, 1970 AD
pub const posix = 0;
/// Jan 01, 1980 AD
pub const dos = 315532800;
/// Jan 01, 2001 AD
pub const ios = 978307200;
/// Nov 17, 1858 AD
pub const openvms = -3506716800;
/// Jan 01, 1900 AD
pub const zos = -2208988800;
/// Jan 01, 1601 AD
pub const windows = -11644473600;
/// Jan 01, 1978 AD
pub const amiga = 252460800;
/// Dec 31, 1967 AD
pub const pickos = -63244800;
/// Jan 06, 1980 AD
pub const gps = 315964800;
/// Jan 01, 0001 AD
pub const clr = -62135769600;
pub const unix = posix;
pub const android = posix;
pub const os2 = dos;
pub const bios = dos;
pub const vfat = dos;
pub const ntfs = windows;
pub const ntp = zos;
pub const jbase = pickos;
pub const aros = amiga;
pub const morphos = amiga;
pub const brew = gps;
pub const atsc = gps;
pub const go = clr;
/// The type that holds the current year, i.e. 2016
pub const Year = u16;
pub const epoch_year = 1970;
pub const secs_per_day: u17 = 24 * 60 * 60;
pub fn isLeapYear(year: Year) bool {
if (@mod(year, 4) != 0)
return false;
if (@mod(year, 100) != 0)
return true;
return (0 == @mod(year, 400));
}
test "isLeapYear" {
try testing.expectEqual(false, isLeapYear(2095));
try testing.expectEqual(true, isLeapYear(2096));
try testing.expectEqual(false, isLeapYear(2100));
try testing.expectEqual(true, isLeapYear(2400));
}
pub fn getDaysInYear(year: Year) u9 {
return if (isLeapYear(year)) 366 else 365;
}
pub const YearLeapKind = enum(u1) { not_leap, leap };
pub const Month = enum(u4) {
jan = 1,
feb,
mar,
apr,
may,
jun,
jul,
aug,
sep,
oct,
nov,
dec,
/// return the numeric calendar value for the given month
/// i.e. jan=1, feb=2, etc
pub fn numeric(self: Month) u4 {
return @enumToInt(self);
}
};
/// Get the number of days in the given month
pub fn getDaysInMonth(leap_year: YearLeapKind, month: Month) u5 {
return switch (month) {
.jan => 31,
.feb => @as(u5, switch (leap_year) {
.leap => 29,
.not_leap => 28,
}),
.mar => 31,
.apr => 30,
.may => 31,
.jun => 30,
.jul => 31,
.aug => 31,
.sep => 30,
.oct => 31,
.nov => 30,
.dec => 31,
};
}
pub const YearAndDay = struct {
year: Year,
/// The number of days into the year (0 to 365)
day: u9,
pub fn calculateMonthDay(self: YearAndDay) MonthAndDay {
var month: Month = .jan;
var days_left = self.day;
const leap_kind: YearLeapKind = if (isLeapYear(self.year)) .leap else .not_leap;
while (true) {
const days_in_month = getDaysInMonth(leap_kind, month);
if (days_left < days_in_month)
break;
days_left -= days_in_month;
month = @intToEnum(Month, @enumToInt(month) + 1);
}
return .{ .month = month, .day_index = @intCast(u5, days_left) };
}
};
pub const MonthAndDay = struct {
month: Month,
day_index: u5, // days into the month (0 to 30)
};
// days since epoch Oct 1, 1970
pub const EpochDay = struct {
day: u47, // u47 = u64 - u17 (because day = sec(u64) / secs_per_day(u17)
pub fn calculateYearDay(self: EpochDay) YearAndDay {
var year_day = self.day;
var year: Year = epoch_year;
while (true) {
const year_size = getDaysInYear(year);
if (year_day < year_size)
break;
year_day -= year_size;
year += 1;
}
return .{ .year = year, .day = @intCast(u9, year_day) };
}
};
/// seconds since start of day
pub const DaySeconds = struct {
secs: u17, // max is 24*60*60 = 86400
/// the number of hours past the start of the day (0 to 11)
pub fn getHoursIntoDay(self: DaySeconds) u5 {
return @intCast(u5, @divTrunc(self.secs, 3600));
}
/// the number of minutes past the hour (0 to 59)
pub fn getMinutesIntoHour(self: DaySeconds) u6 {
return @intCast(u6, @divTrunc(@mod(self.secs, 3600), 60));
}
/// the number of seconds past the start of the minute (0 to 59)
pub fn getSecondsIntoMinute(self: DaySeconds) u6 {
return math.comptimeMod(self.secs, 60);
}
};
/// seconds since epoch Oct 1, 1970 at 12:00 AM
pub const EpochSeconds = struct {
secs: u64,
/// Returns the number of days since the epoch as an EpochDay.
/// Use EpochDay to get information about the day of this time.
pub fn getEpochDay(self: EpochSeconds) EpochDay {
return EpochDay{ .day = @intCast(u47, @divTrunc(self.secs, secs_per_day)) };
}
/// Returns the number of seconds into the day as DaySeconds.
/// Use DaySeconds to get information about the time.
pub fn getDaySeconds(self: EpochSeconds) DaySeconds {
return DaySeconds{ .secs = math.comptimeMod(self.secs, secs_per_day) };
}
};
fn testEpoch(secs: u64, expected_year_day: YearAndDay, expected_month_day: MonthAndDay, expected_day_seconds: struct {
/// 0 to 23
hours_into_day: u5,
/// 0 to 59
minutes_into_hour: u6,
/// 0 to 59
seconds_into_minute: u6,
}) !void {
const epoch_seconds = EpochSeconds{ .secs = secs };
const epoch_day = epoch_seconds.getEpochDay();
const day_seconds = epoch_seconds.getDaySeconds();
const year_day = epoch_day.calculateYearDay();
try testing.expectEqual(expected_year_day, year_day);
try testing.expectEqual(expected_month_day, year_day.calculateMonthDay());
try testing.expectEqual(expected_day_seconds.hours_into_day, day_seconds.getHoursIntoDay());
try testing.expectEqual(expected_day_seconds.minutes_into_hour, day_seconds.getMinutesIntoHour());
try testing.expectEqual(expected_day_seconds.seconds_into_minute, day_seconds.getSecondsIntoMinute());
}
test "epoch decoding" {
try testEpoch(0, .{ .year = 1970, .day = 0 }, .{
.month = .jan,
.day_index = 0,
}, .{ .hours_into_day = 0, .minutes_into_hour = 0, .seconds_into_minute = 0 });
try testEpoch(31535999, .{ .year = 1970, .day = 364 }, .{
.month = .dec,
.day_index = 30,
}, .{ .hours_into_day = 23, .minutes_into_hour = 59, .seconds_into_minute = 59 });
try testEpoch(1622924906, .{ .year = 2021, .day = 31 + 28 + 31 + 30 + 31 + 4 }, .{
.month = .jun,
.day_index = 4,
}, .{ .hours_into_day = 20, .minutes_into_hour = 28, .seconds_into_minute = 26 });
try testEpoch(1625159473, .{ .year = 2021, .day = 31 + 28 + 31 + 30 + 31 + 30 }, .{
.month = .jul,
.day_index = 0,
}, .{ .hours_into_day = 17, .minutes_into_hour = 11, .seconds_into_minute = 13 });
} | lib/std/time/epoch.zig |
const builtin = @import("builtin");
const std = @import("std");
const math = std.math;
const assert = std.debug.assert;
const normalize = @import("divdf3.zig").normalize;
pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {
// TODO: more efficient implementation
return @floatCast(f16, fmodf(x, y));
}
pub fn fmodf(x: f32, y: f32) callconv(.C) f32 {
return generic_fmod(f32, x, y);
}
pub fn fmod(x: f64, y: f64) callconv(.C) f64 {
return generic_fmod(f64, x, y);
}
/// fmodx - floating modulo large, returns the remainder of division for f80 types
/// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits
pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
@setRuntimeSafety(builtin.is_test);
const T = f80;
const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
const significandBits = math.floatMantissaBits(T);
const fractionalBits = math.floatFractionalBits(T);
const exponentBits = math.floatExponentBits(T);
const signBit = (@as(Z, 1) << (significandBits + exponentBits));
const maxExponent = ((1 << exponentBits) - 1);
var aRep = @bitCast(Z, a);
var bRep = @bitCast(Z, b);
const signA = aRep & signBit;
var expA = @intCast(i32, (@bitCast(Z, a) >> significandBits) & maxExponent);
var expB = @intCast(i32, (@bitCast(Z, b) >> significandBits) & maxExponent);
// There are 3 cases where the answer is undefined, check for:
// - fmodx(val, 0)
// - fmodx(val, NaN)
// - fmodx(inf, val)
// The sign on checked values does not matter.
// Doing (a * b) / (a * b) procudes undefined results
// because the three cases always produce undefined calculations:
// - 0 / 0
// - val * NaN
// - inf / inf
if (b == 0 or math.isNan(b) or expA == maxExponent) {
return (a * b) / (a * b);
}
// Remove the sign from both
aRep &= ~signBit;
bRep &= ~signBit;
if (aRep <= bRep) {
if (aRep == bRep) {
return 0 * a;
}
return a;
}
if (expA == 0) expA = normalize(f80, &aRep);
if (expB == 0) expB = normalize(f80, &bRep);
var highA: u64 = 0;
var highB: u64 = 0;
var lowA: u64 = @truncate(u64, aRep);
var lowB: u64 = @truncate(u64, bRep);
while (expA > expB) : (expA -= 1) {
var high = highA -% highB;
var low = lowA -% lowB;
if (lowA < lowB) {
high -%= 1;
}
if (high >> 63 == 0) {
if ((high | low) == 0) {
return 0 * a;
}
highA = 2 *% high + (low >> 63);
lowA = 2 *% low;
} else {
highA = 2 *% highA + (lowA >> 63);
lowA = 2 *% lowA;
}
}
var high = highA -% highB;
var low = lowA -% lowB;
if (lowA < lowB) {
high -%= 1;
}
if (high >> 63 == 0) {
if ((high | low) == 0) {
return 0 * a;
}
highA = high;
lowA = low;
}
while ((lowA >> fractionalBits) == 0) {
lowA = 2 *% lowA;
expA = expA - 1;
}
// Combine the exponent with the sign and significand, normalize if happened to be denormalized
if (expA < -fractionalBits) {
return @bitCast(T, signA);
} else if (expA <= 0) {
return @bitCast(T, (lowA >> @intCast(math.Log2Int(u64), 1 - expA)) | signA);
} else {
return @bitCast(T, lowA | (@as(Z, @intCast(u16, expA)) << significandBits) | signA);
}
}
/// fmodq - floating modulo large, returns the remainder of division for f128 types
/// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits
pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
@setRuntimeSafety(builtin.is_test);
var amod = a;
var bmod = b;
const aPtr_u64 = @ptrCast([*]u64, &amod);
const bPtr_u64 = @ptrCast([*]u64, &bmod);
const aPtr_u16 = @ptrCast([*]u16, &amod);
const bPtr_u16 = @ptrCast([*]u16, &bmod);
const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) {
.Little => 7,
.Big => 0,
};
const low_index = comptime switch (builtin.target.cpu.arch.endian()) {
.Little => 0,
.Big => 1,
};
const high_index = comptime switch (builtin.target.cpu.arch.endian()) {
.Little => 1,
.Big => 0,
};
const signA = aPtr_u16[exp_and_sign_index] & 0x8000;
var expA = @intCast(i32, (aPtr_u16[exp_and_sign_index] & 0x7fff));
var expB = @intCast(i32, (bPtr_u16[exp_and_sign_index] & 0x7fff));
// There are 3 cases where the answer is undefined, check for:
// - fmodq(val, 0)
// - fmodq(val, NaN)
// - fmodq(inf, val)
// The sign on checked values does not matter.
// Doing (a * b) / (a * b) procudes undefined results
// because the three cases always produce undefined calculations:
// - 0 / 0
// - val * NaN
// - inf / inf
if (b == 0 or std.math.isNan(b) or expA == 0x7fff) {
return (a * b) / (a * b);
}
// Remove the sign from both
aPtr_u16[exp_and_sign_index] = @bitCast(u16, @intCast(i16, expA));
bPtr_u16[exp_and_sign_index] = @bitCast(u16, @intCast(i16, expB));
if (amod <= bmod) {
if (amod == bmod) {
return 0 * a;
}
return a;
}
if (expA == 0) {
amod *= 0x1p120;
expA = @as(i32, aPtr_u16[exp_and_sign_index]) - 120;
}
if (expB == 0) {
bmod *= 0x1p120;
expB = @as(i32, bPtr_u16[exp_and_sign_index]) - 120;
}
// OR in extra non-stored mantissa digit
var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
var highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
var lowA: u64 = aPtr_u64[low_index];
var lowB: u64 = bPtr_u64[low_index];
while (expA > expB) : (expA -= 1) {
var high = highA -% highB;
var low = lowA -% lowB;
if (lowA < lowB) {
high -%= 1;
}
if (high >> 63 == 0) {
if ((high | low) == 0) {
return 0 * a;
}
highA = 2 *% high + (low >> 63);
lowA = 2 *% low;
} else {
highA = 2 *% highA + (lowA >> 63);
lowA = 2 *% lowA;
}
}
var high = highA -% highB;
var low = lowA -% lowB;
if (lowA < lowB) {
high -= 1;
}
if (high >> 63 == 0) {
if ((high | low) == 0) {
return 0 * a;
}
highA = high;
lowA = low;
}
while (highA >> 48 == 0) {
highA = 2 *% highA + (lowA >> 63);
lowA = 2 *% lowA;
expA = expA - 1;
}
// Overwrite the current amod with the values in highA and lowA
aPtr_u64[high_index] = highA;
aPtr_u64[low_index] = lowA;
// Combine the exponent with the sign, normalize if happend to be denormalized
if (expA <= 0) {
aPtr_u16[exp_and_sign_index] = @truncate(u16, @bitCast(u32, (expA +% 120))) | signA;
amod *= 0x1p-120;
} else {
aPtr_u16[exp_and_sign_index] = @truncate(u16, @bitCast(u32, expA)) | signA;
}
return amod;
}
inline fn generic_fmod(comptime T: type, x: T, y: T) T {
@setRuntimeSafety(false);
const bits = @typeInfo(T).Float.bits;
const uint = std.meta.Int(.unsigned, bits);
const log2uint = math.Log2Int(uint);
comptime assert(T == f32 or T == f64);
const digits = if (T == f32) 23 else 52;
const exp_bits = if (T == f32) 9 else 12;
const bits_minus_1 = bits - 1;
const mask = if (T == f32) 0xff else 0x7ff;
var ux = @bitCast(uint, x);
var uy = @bitCast(uint, y);
var ex = @intCast(i32, (ux >> digits) & mask);
var ey = @intCast(i32, (uy >> digits) & mask);
const sx = if (T == f32) @intCast(u32, ux & 0x80000000) else @intCast(i32, ux >> bits_minus_1);
var i: uint = undefined;
if (uy << 1 == 0 or math.isNan(@bitCast(T, uy)) or ex == mask)
return (x * y) / (x * y);
if (ux << 1 <= uy << 1) {
if (ux << 1 == uy << 1)
return 0 * x;
return x;
}
// normalize x and y
if (ex == 0) {
i = ux << exp_bits;
while (i >> bits_minus_1 == 0) : ({
ex -= 1;
i <<= 1;
}) {}
ux <<= @intCast(log2uint, @bitCast(u32, -ex + 1));
} else {
ux &= math.maxInt(uint) >> exp_bits;
ux |= 1 << digits;
}
if (ey == 0) {
i = uy << exp_bits;
while (i >> bits_minus_1 == 0) : ({
ey -= 1;
i <<= 1;
}) {}
uy <<= @intCast(log2uint, @bitCast(u32, -ey + 1));
} else {
uy &= math.maxInt(uint) >> exp_bits;
uy |= 1 << digits;
}
// x mod y
while (ex > ey) : (ex -= 1) {
i = ux -% uy;
if (i >> bits_minus_1 == 0) {
if (i == 0)
return 0 * x;
ux = i;
}
ux <<= 1;
}
i = ux -% uy;
if (i >> bits_minus_1 == 0) {
if (i == 0)
return 0 * x;
ux = i;
}
while (ux >> digits == 0) : ({
ux <<= 1;
ex -= 1;
}) {}
// scale result up
if (ex > 0) {
ux -%= 1 << digits;
ux |= @as(uint, @bitCast(u32, ex)) << digits;
} else {
ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1));
}
if (T == f32) {
ux |= sx;
} else {
ux |= @intCast(uint, sx) << bits_minus_1;
}
return @bitCast(T, ux);
}
test "fmod, fmodf" {
inline for ([_]type{ f32, f64 }) |T| {
const nan_val = math.nan(T);
const inf_val = math.inf(T);
try std.testing.expect(math.isNan(generic_fmod(T, nan_val, 1.0)));
try std.testing.expect(math.isNan(generic_fmod(T, 1.0, nan_val)));
try std.testing.expect(math.isNan(generic_fmod(T, inf_val, 1.0)));
try std.testing.expect(math.isNan(generic_fmod(T, 0.0, 0.0)));
try std.testing.expect(math.isNan(generic_fmod(T, 1.0, 0.0)));
try std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0));
try std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0));
try std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, 10.0));
try std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, -10.0));
try std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, 10.0));
try std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, -10.0));
}
}
test {
_ = @import("fmodq_test.zig");
_ = @import("fmodx_test.zig");
} | lib/std/special/compiler_rt/fmod.zig |
const std = @import("std");
const Condition = @import("./Condition.zig").Condition;
pub fn ArrayBlockingQueue(comptime T: type) type {
return struct {
const Self = @This();
const Fifo = std.fifo.LinearFifo(T, .Dynamic);
capacity: i32 = 0,
count: i32 = 0,
queue: Fifo,
lock: std.Mutex,
notFull: Condition,
notEmpty: Condition,
pub fn init(allocator: *std.mem.Allocator, capacity: anytype) Self {
var self: Self = undefined;
self.count = 0;
self.capacity = @as(i32, capacity);
self.queue = Fifo.init(allocator);
self.queue.ensureCapacity(capacity) catch unreachable;
self.lock = std.Mutex{};
self.notEmpty = Condition{.mutex=null};
self.notFull = Condition{.mutex=null};
return self;
}
pub fn deinit(self: *Self) void {
self.queue.deinit();
self.count = 0;
self.capacity = 0;
}
pub fn post_init(self: *Self) void {
if(self.notEmpty.mutex == null)
self.notEmpty.mutex = &self.lock;
if(self.notFull.mutex == null)
self.notFull.mutex = &self.lock;
}
pub fn put(self: *Self, item: T) void {
const lock = self.lock.acquire();
defer lock.release();
self.post_init();
while(self.count == self.capacity){
self.notFull.wait();
}
self.queue.writeItem(item) catch unreachable;
const count = self.count;
self.count = self.count + 1;
if(count == 0)
self.notEmpty.signalAll();
}
pub fn offer(self: *Self, item: T) bool {
const lock = self.lock.acquire();
defer lock.release();
self.post_init();
if(self.count == self.capacity){
return false;
}
self.queue.writeItem(item) catch unreachable;
const count = self.count;
self.count = self.count + 1;
if(count == 0)
self.notEmpty.signalAll();
return true;
}
pub fn timedOffer(self: *Self, item: T, timeout: u64,) bool {
const lock = self.lock.acquire();
defer lock.release();
self.post_init();
var t = @intCast(i64, timeout);
while(self.count == self.capacity){
if(t <= 0) {
return false;
}
t = self.notFull.timedWait(@intCast(u64, t));
}
self.queue.writeItem(item) catch unreachable;
const prev = self.count;
self.count += 1;
if(prev == 0){
self.notEmpty.signalAll();
}
return true;
}
pub fn take(self: *Self) T {
const lock = self.lock.acquire();
defer lock.release();
self.post_init();
while(self.count == 0){
self.notEmpty.wait();
}
const ret = self.queue.readItem().?;
const count = self.count;
self.count = self.count - 1;
if(count == self.capacity)
self.notFull.signalAll();
return ret;
}
pub fn takeMany(self: *Self, dst: []T) []T {
const lock = self.lock.acquire();
defer lock.release();
self.post_init();
while(self.count == 0){
self.notEmpty.wait();
}
const num = self.queue.read(dst);
const count = self.count;
std.testing.expect(count-@intCast(i32, num) >= 0);
self.count = self.count - @intCast(i32, num);
if(count == self.capacity)
self.notFull.signalAll();
return dst[0..num];
}
pub fn pollMany(self: *Self, dst: []T) []T {
const lock = self.lock.acquire();
defer lock.release();
self.post_init();
if(self.count == 0){
return dst[0..0];
}
const num = self.queue.read(dst);
const count = self.count;
std.testing.expect(count-@intCast(i32, num) >= 0);
self.count = self.count - @intCast(i32, num);
if(count == self.capacity)
self.notFull.signalAll();
return dst[0..num];
}
pub fn poll(self: *Self) ?T {
const lock = self.lock.acquire();
defer lock.release();
self.post_init();
if(self.count == 0){
return null;
}
const ret = self.queue.readItem().?;
const count = self.count;
self.count = self.count - 1;
if(count == self.capacity)
self.notFull.signalAll();
return ret;
}
pub fn timedPoll(self: *Self, timeout: u64) ?T {
const lock = self.lock.acquire();
defer lock.release();
self.post_init();
var t = @intCast(i64, timeout);
while(self.count == 0){
if(t <= 0) {
return null;
}
t = self.notEmpty.timedWait(@intCast(u64, t));
}
const ret = self.queue.readItem().?;
const prev = self.count;
self.count -= 1;
if(prev == self.capacity){
self.notFull.signalAll();
}
return ret;
}
pub fn peek(self: *Self) ?T {
const lock = self.lock.acquire();
defer lock.release();
self.post_init();
if(self.count == 0){
return null;
}
const ret = self.queue.peekItem(0);
return ret;
}
};
} | ArrayBlockingQueue.zig |
const std = @import("std");
const math = std.math;
const assert = std.debug.assert;
const warn = std.debug.warn;
pub fn Vec3(comptime T: type) type {
return struct {
const Self = @This();
pub x: T,
pub y: T,
pub z: T,
pub fn init(x: T, y: T, z: T) Self {
return Self{ .x = x, .y = y, .z = z };
}
pub fn init0() Self {
return init(0, 0, 0);
}
// What to do about TypeId.Int?
pub fn length(pSelf: *const Self) T {
return math.sqrt((pSelf.x * pSelf.x) +
(pSelf.y * pSelf.y) +
(pSelf.z * pSelf.z));
}
// What to do about TypeId.Int?
pub fn dot(pSelf: *const Self, pOther: *const Self) T {
return (pSelf.x * pOther.x) +
(pSelf.y * pOther.y) +
(pSelf.z * pOther.z);
}
// What to do about TypeId.Int?
pub fn normalize(pSelf: *Self) void {
var len = pSelf.length();
if (len > 0) {
var t = 1 / len;
pSelf.x *= t;
pSelf.y *= t;
pSelf.z *= t;
}
}
// What to do about TypeId.Int?
pub fn cross(pSelf: *const Self, pOther: *const Self) Self {
return Vec3(T).init(
(pSelf.y * pOther.z) - (pSelf.z * pOther.y),
(pSelf.z * pOther.x) - (pSelf.x * pOther.z),
(pSelf.x * pOther.y) - (pSelf.y * pOther.x),
);
}
// What to do about TypeId.Int?
pub fn neg(pSelf: *const Self) Self {
return Vec3(T).init(-pSelf.x, -pSelf.y, -pSelf.z);
}
// What to do about TypeId.Int?
pub fn eql(pSelf: *const Self, pOther: *const Self) bool {
return pSelf.x == pOther.x and
pSelf.y == pOther.y and
pSelf.z == pOther.z;
}
// What to do about TypeId.Int?
pub fn add(pSelf: *const Self, pOther: *const Self) Self {
return Vec3(T).init(
(pSelf.x + pOther.x),
(pSelf.y + pOther.y),
(pSelf.z + pOther.z),
);
}
// What to do about TypeId.Int?
pub fn sub(pSelf: *const Self, pOther: *const Self) Self {
return Vec3(T).init(
(pSelf.x - pOther.x),
(pSelf.y - pOther.y),
(pSelf.z - pOther.z),
);
}
// What to do about TypeId.Int?
pub fn mul(pSelf: *const Self, pOther: *const Self) Self {
return Vec3(T).init(
(pSelf.x * pOther.x),
(pSelf.y * pOther.y),
(pSelf.z * pOther.z),
);
}
// What to do about TypeId.Int?
pub fn div(pSelf: *const Self, pOther: *const Self) Self {
return Vec3(T).init(
(pSelf.x / pOther.x),
(pSelf.y / pOther.y),
(pSelf.z / pOther.z),
);
}
};
}
test "vec3.init" {
const vf64 = Vec3(f64).init0();
assert(vf64.x == 0);
assert(vf64.y == 0);
assert(vf64.z == 0);
const vf32 = Vec3(f32).init0();
assert(vf32.x == 0);
assert(vf32.y == 0);
assert(vf32.z == 0);
const vi32 = Vec3(i32).init0();
assert(vi32.x == 0);
assert(vi32.y == 0);
assert(vi32.z == 0);
const v1 = Vec3(f64).init(1, 2, 3);
assert(v1.x == 1);
assert(v1.y == 2);
assert(v1.z == 3);
}
test "vec3.copy" {
var v1 = Vec3(f32).init(1, 2, 3);
assert(v1.x == 1);
assert(v1.y == 2);
assert(v1.z == 3);
// Copy a vector
var v2 = v1;
assert(v2.x == 1);
assert(v2.y == 2);
assert(v2.z == 3);
// Copy via a pointer
var pV1 = &v1;
var v3 = pV1.*;
assert(v3.x == 1);
assert(v3.y == 2);
assert(v3.z == 3);
}
test "vec3.length" {
const v1 = Vec3(f32).init(2, 3, 4);
assert(v1.length() == math.sqrt(29.0));
}
test "vec3.dot" {
const v1 = Vec3(f32).init(3, 2, 1);
const v2 = Vec3(f32).init(1, 2, 3);
assert(v1.dot(&v2) == (3 * 1) + (2 * 2) + (3 * 1));
// Sqrt of the dot product of itself is the length
assert(math.sqrt(v2.dot(&v2)) == v2.length());
}
test "vec3.normalize" {
var v1 = Vec3(f32).init0();
v1.normalize();
assert(v1.x == 0);
assert(v1.y == 0);
assert(v1.z == 0);
v1 = Vec3(f32).init(1, 1, 1);
v1.normalize();
var len: f32 = math.sqrt(1.0 + 1.0 + 1.0);
assert(v1.x == 1.0 / len);
assert(v1.y == 1.0 / len);
assert(v1.z == 1.0 / len);
}
test "vec3.cross.eql.neg" {
var v1 = Vec3(f32).init(1, 0, 0); // Unit Vector X
var v2 = Vec3(f32).init(0, 1, 0); // Unit Vector Y
// Cross product of two unit vectors on X,Y yields unit vector Z
var v3 = v1.cross(&v2);
assert(v3.x == 0);
assert(v3.y == 0);
assert(v3.z == 1);
v1 = Vec3(f32).init(3, 2, 1);
v2 = Vec3(f32).init(1, 2, 3);
v3 = v1.cross(&v2);
assert(v3.x == 4);
assert(v3.y == -8);
assert(v3.z == 4);
// Changing the order yields neg.
var v4 = v2.cross(&v1);
assert(v3.x == -v4.x);
assert(v3.y == -v4.y);
assert(v3.z == -v4.z);
assert(v4.eql(&v3.neg()));
}
test "vec3.add" {
const v1 = Vec3(f32).init(3, 2, 1);
const v2 = Vec3(f32).init(1, 2, 3);
const v3 = v1.add(&v2);
assert(v3.x == 4);
assert(v3.y == 4);
assert(v3.z == 4);
}
test "vec3.sub" {
const v1 = Vec3(f32).init(3, 2, 1);
const v2 = Vec3(f32).init(1, 2, 3);
const v3 = v1.sub(&v2);
assert(v3.x == 2);
assert(v3.y == 0);
assert(v3.z == -2);
}
test "vec3.mul" {
const v1 = Vec3(f32).init(3, 2, 1);
const v2 = Vec3(f32).init(1, 2, 3);
const v3 = v1.mul(&v2);
assert(v3.x == 3);
assert(v3.y == 4);
assert(v3.z == 3);
}
test "vec3.div" {
const v1 = Vec3(f32).init(3, 2, 1);
const v2 = Vec3(f32).init(1, 2, 3);
const v3 = v1.div(&v2);
assert(v3.x == 3);
assert(v3.y == 1);
assert(v3.z == f32(1.0 / 3.0));
} | src/vec3.zig |
const std = @import("std");
const testing = std.testing;
const style = @import("ansi-term/src/style.zig");
const Style = style.Style;
const FontStyle = style.FontStyle;
const Color = style.Color;
const ansi_format = @import("ansi-term/src/format.zig");
const LsColors = @import("main.zig").LsColors;
const PathComponentIterator = @import("path_components.zig").PathComponentIterator;
pub const StyledPath = struct {
path: []const u8,
style: Style,
const Self = @This();
pub fn format(
value: Self,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) @TypeOf(writer).Error!void {
_ = fmt;
_ = options;
const sty = value.style;
try ansi_format.updateStyle(writer, sty, Style{});
try writer.writeAll(value.path);
try ansi_format.updateStyle(writer, Style{}, sty);
}
};
pub const StyledPathComponents = struct {
path: []const u8,
lsc: *LsColors,
const Self = @This();
pub fn format(
value: Self,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) @TypeOf(writer).Error!void {
_ = fmt;
_ = options;
var iter = PathComponentIterator.init(value.path);
var current_style: ?Style = Style{};
while (iter.next()) |component| {
const new_style = value.lsc.styleForPath(component.path) catch Style{};
defer current_style = new_style;
// Update style
try ansi_format.updateStyle(writer, new_style, current_style);
// Actual item name
try writer.writeAll(component.name);
}
try ansi_format.updateStyle(writer, Style{}, current_style);
}
};
test "format default styled path" {
const styled_path = StyledPath{
.path = "/usr/local/bin/zig",
.style = Style{},
};
const allocator = std.testing.allocator;
const expected = "/usr/local/bin/zig";
const actual = try std.fmt.allocPrint(allocator, "{}", .{styled_path});
defer allocator.free(actual);
try testing.expectEqualSlices(u8, expected, actual);
}
test "format bold path" {
const styled_path = StyledPath{
.path = "/usr/local/bin/zig",
.style = Style{
.font_style = FontStyle.bold,
},
};
const allocator = std.testing.allocator;
const expected = "\x1B[1m/usr/local/bin/zig\x1B[0m";
const actual = try std.fmt.allocPrint(allocator, "{}", .{styled_path});
defer allocator.free(actual);
try testing.expectEqualSlices(u8, expected, actual);
}
test "format bold and italic path" {
const styled_path = StyledPath{
.path = "/usr/local/bin/zig",
.style = Style{
.font_style = FontStyle{
.bold = true,
.italic = true,
},
},
};
const allocator = std.testing.allocator;
const expected = "\x1B[1;3m/usr/local/bin/zig\x1B[0m";
const actual = try std.fmt.allocPrint(allocator, "{}", .{styled_path});
defer allocator.free(actual);
try testing.expectEqualSlices(u8, expected, actual);
}
test "format colored path" {
const styled_path = StyledPath{
.path = "/usr/local/bin/zig",
.style = Style{
.foreground = Color.Red,
},
};
const allocator = std.testing.allocator;
const expected = "\x1B[31m/usr/local/bin/zig\x1B[0m";
const actual = try std.fmt.allocPrint(allocator, "{}", .{styled_path});
defer allocator.free(actual);
try testing.expectEqualSlices(u8, expected, actual);
} | src/styled_path.zig |
const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;
const testing = @import("std").testing;
fn test__floatuntitf(a: u128, expected: f128) !void {
const x = __floatuntitf(a);
try testing.expect(x == expected);
}
test "floatuntitf" {
try test__floatuntitf(0, 0.0);
try test__floatuntitf(1, 1.0);
try test__floatuntitf(2, 2.0);
try test__floatuntitf(20, 20.0);
try test__floatuntitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
try test__floatuntitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
try test__floatuntitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
try test__floatuntitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
try test__floatuntitf(0x7FFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFEp+59);
try test__floatuntitf(0xFFFFFFFFFFFFFFFE, 0xF.FFFFFFFFFFFFFFEp+60);
try test__floatuntitf(0xFFFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFFp+60);
try test__floatuntitf(0x8000008000000000, 0x8.000008p+60);
try test__floatuntitf(0x8000000000000800, 0x8.0000000000008p+60);
try test__floatuntitf(0x8000010000000000, 0x8.00001p+60);
try test__floatuntitf(0x8000000000001000, 0x8.000000000001p+60);
try test__floatuntitf(0x8000000000000000, 0x8p+60);
try test__floatuntitf(0x8000000000000001, 0x8.000000000000001p+60);
try test__floatuntitf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
try test__floatuntitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
try test__floatuntitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
try test__floatuntitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
try test__floatuntitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
try test__floatuntitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
try test__floatuntitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
try test__floatuntitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
try test__floatuntitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
try test__floatuntitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
try test__floatuntitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
try test__floatuntitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
try test__floatuntitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
try test__floatuntitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
try test__floatuntitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
try test__floatuntitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
try test__floatuntitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
try test__floatuntitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
try test__floatuntitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
try test__floatuntitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
try test__floatuntitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
try test__floatuntitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
try test__floatuntitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
try test__floatuntitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
try test__floatuntitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
try test__floatuntitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
try test__floatuntitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
try test__floatuntitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
try test__floatuntitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
try test__floatuntitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
try test__floatuntitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
try test__floatuntitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
try test__floatuntitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63);
try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0x0000000000000000), 0x1.FFFFFFFFFFFFFFFEp+127);
try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x1.0000000000000000p+128);
try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
}
fn make_ti(high: u64, low: u64) u128 {
var result: u128 = high;
result <<= 64;
result |= low;
return result;
} | lib/std/special/compiler_rt/floatuntitf_test.zig |
const std = @import("std");
const util = @import("util.zig");
const data = @embedFile("../data/day09.txt");
const Input = struct {
heightmap: [100][100]u8 = undefined,
dim_x: usize = undefined,
dim_y: usize = undefined,
pub fn init(input_text: []const u8, allocator: std.mem.Allocator) !@This() {
_ = allocator;
var input = Input{};
errdefer input.deinit();
var lines = std.mem.tokenize(u8, input_text, "\r\n");
var y: usize = 0;
while (lines.next()) |line| : (y += 1) {
input.dim_x = line.len;
for (line) |c, x| {
input.heightmap[y][x] = c - '0';
}
}
input.dim_y = y;
return input;
}
pub fn deinit(self: @This()) void {
_ = self;
}
pub fn cell(self: @This(), x: isize, y: isize) ?u8 {
if (x < 0 or x >= self.dim_x or y < 0 or y >= self.dim_y) {
return null;
}
return self.heightmap[@intCast(usize, y)][@intCast(usize, x)];
}
};
const Vec2 = struct {
x: isize,
y: isize,
};
const offsets = [_]Vec2{
Vec2{ .x = -1, .y = 0 },
Vec2{ .x = 1, .y = 0 },
Vec2{ .x = 0, .y = -1 },
Vec2{ .x = 0, .y = 1 },
};
fn part1(input: Input) i64 {
var risk: i64 = 0;
var y: isize = 0;
while (y < input.dim_y) : (y += 1) {
var x: isize = 0;
xloop: while (x < input.dim_x) : (x += 1) {
const c: u8 = input.cell(x, y).?;
for (offsets) |offset| {
const neighbor: ?u8 = input.cell(x + offset.x, y + offset.y);
if (neighbor) |n| {
if (n <= c) {
continue :xloop;
}
}
}
risk += c + 1;
}
}
return risk;
}
fn part2(input_original: Input) i64 {
var input = input_original;
var basin_sizes = std.ArrayList(i64).init(std.testing.allocator);
defer basin_sizes.deinit();
var y: isize = 0;
var to_visit = std.ArrayList(Vec2).initCapacity(std.testing.allocator, input.dim_x * input.dim_y) catch unreachable;
defer to_visit.deinit();
while (y < input.dim_y) : (y += 1) {
var x: isize = 0;
xloop: while (x < input.dim_x) : (x += 1) {
const c: u8 = input.cell(x, y).?;
if (c == 9) {
continue :xloop;
}
// flood-fill from here. To mark a cell as visited, change it to a 9.
var basin_size: i64 = 0;
assert(to_visit.items.len == 0);
to_visit.append(Vec2{ .x = x, .y = y }) catch unreachable;
while (to_visit.items.len > 0) {
const v = to_visit.pop();
if (input.cell(v.x, v.y)) |height| {
if (height < 9) {
input.heightmap[@intCast(usize, v.y)][@intCast(usize, v.x)] = 9;
basin_size += 1;
for (offsets) |offset| {
to_visit.append(Vec2{ .x = v.x + offset.x, .y = v.y + offset.y }) catch unreachable;
}
}
}
}
basin_sizes.append(basin_size) catch unreachable;
}
}
// sort basin sizes to pick the three largest
assert(basin_sizes.items.len >= 3);
std.sort.sort(i64, basin_sizes.items, {}, comptime std.sort.desc(i64));
return basin_sizes.items[0] * basin_sizes.items[1] * basin_sizes.items[2];
}
const test_data =
\\2199943210
\\3987894921
\\9856789892
\\8767896789
\\9899965678
;
const part1_test_solution: ?i64 = 15;
const part1_solution: ?i64 = 524;
const part2_test_solution: ?i64 = 1134;
const part2_solution: ?i64 = 1235430;
// Just boilerplate below here, nothing to see
fn testPart1() !void {
var test_input = try Input.init(test_data, std.testing.allocator);
defer test_input.deinit();
if (part1_test_solution) |solution| {
try std.testing.expectEqual(solution, part1(test_input));
}
var input = try Input.init(data, std.testing.allocator);
defer input.deinit();
if (part1_solution) |solution| {
try std.testing.expectEqual(solution, part1(input));
}
}
fn testPart2() !void {
var test_input = try Input.init(test_data, std.testing.allocator);
defer test_input.deinit();
if (part2_test_solution) |solution| {
try std.testing.expectEqual(solution, part2(test_input));
}
var input = try Input.init(data, std.testing.allocator);
defer input.deinit();
if (part2_solution) |solution| {
try std.testing.expectEqual(solution, part2(input));
}
}
pub fn main() !void {
try testPart1();
try testPart2();
}
test "part1" {
try testPart1();
}
test "part2" {
try testPart2();
}
// Useful stdlib functions
const tokenize = std.mem.tokenize;
const split = std.mem.split;
const parseInt = std.fmt.parseInt;
const min = std.math.min;
const max = std.math.max;
const print = std.debug.print;
const expect = std.testing.expect;
const assert = std.debug.assert; | src/day09.zig |
const std = @import("std");
const BitSet = std.StaticBitSet(max_size * max_size);
const max_size = 100;
test "example" {
const map = try HeightMap.new(@embedFile("9_example.txt"));
try std.testing.expectEqual(@as(usize, 1134), map.threeLargestBasinProduct());
}
pub fn main() !void {
const map = try HeightMap.new(@embedFile("9.txt"));
std.debug.print("{}\n", .{map.threeLargestBasinProduct()});
}
const HeightMap = struct {
source: []const u8,
width: usize,
height: usize,
fn new(source: []const u8) !HeightMap {
const width = std.mem.indexOfScalar(u8, source, '\n') orelse return error.InvalidHeightmap;
const last_newline = std.mem.lastIndexOfScalar(u8, source, '\n') orelse return error.InvalidHeightmap;
const height = 1 + last_newline / width;
if (width > max_size or height > max_size) return error.TooBig;
return HeightMap{ .source = source, .width = width, .height = height };
}
inline fn get(self: HeightMap, row: usize, col: usize) u8 {
const idx = (self.width + 1) * row + col; // including newlines
return self.source[idx] - '0';
}
fn isLowPoint(self: HeightMap, row: usize, col: usize) bool {
const height = self.get(row, col);
if (row > 0 and height >= self.get(row - 1, col)) return false;
if (row + 1 < self.height and height >= self.get(row + 1, col)) return false;
if (col > 0 and height >= self.get(row, col - 1)) return false;
if (col + 1 < self.width and height >= self.get(row, col + 1)) return false;
return true;
}
fn setBasinBits(self: HeightMap, bitset: *BitSet, row: usize, col: usize) void {
const height = self.get(row, col);
if (height == 9) return;
bitset.set(row * self.width + col);
if (row > 0 and self.get(row - 1, col) > height) self.setBasinBits(bitset, row - 1, col);
if (row + 1 < self.height and self.get(row + 1, col) > height) self.setBasinBits(bitset, row + 1, col);
if (col > 0 and self.get(row, col - 1) > height) self.setBasinBits(bitset, row, col - 1);
if (col + 1 < self.width and self.get(row, col + 1) > height) self.setBasinBits(bitset, row, col + 1);
}
fn threeLargestBasinProduct(self: HeightMap) usize {
var basins = [3]usize{ 0, 0, 0 }; // sorted in ascending order after insertion
var row: usize = 0;
while (row < self.height) : (row += 1) {
var col: usize = 0;
while (col < self.width) : (col += 1) {
if (self.isLowPoint(row, col)) {
var bitset = BitSet.initEmpty();
self.setBasinBits(&bitset, row, col);
const size = bitset.count();
if (size > basins[0]) {
basins[0] = size;
std.sort.sort(usize, &basins, {}, comptime std.sort.asc(usize));
}
}
}
}
return basins[0] * basins[1] * basins[2];
}
}; | shritesh+zig/9b.zig |
const std = @import("std");
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const version = std.builtin.Version{
.major = 0,
.minor = 1,
.patch = 0,
};
// For some reason a versioned shared library causes zig build to crash
// on windows.
const target_tag = target.os_tag orelse std.Target.current.os.tag;
var bundle_step = MacOSBundle.create(b, "zig-analyzer", "src/main.zig", .{
.identifier = "org.zig-analyzer",
.version = if (target_tag == .windows) null else version,
.target = target,
.mode = mode,
});
switch (target_tag) {
.windows => {
bundle_step.lib_step.linkSystemLibrary("user32");
bundle_step.lib_step.linkSystemLibrary("gdi32");
bundle_step.lib_step.linkSystemLibrary("opengl32");
},
else => {},
}
var main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
main_tests.addPackagePath("known-folders", "./libs/known-folders/known-folders.zig");
main_tests.addPackagePath("zigimg", "./libs/zigimg/zigimg.zig");
bundle_step.lib_step.addPackagePath("known-folders", "./libs/known-folders/known-folders.zig");
bundle_step.lib_step.addPackagePath("zigimg", "./libs/zigimg/zigimg.zig");
b.default_step.dependOn(&bundle_step.step);
}
const MacOSBundle = struct {
pub const Options = struct {
identifier: []const u8,
version: ?std.builtin.Version = null,
target: std.zig.CrossTarget = std.zig.CrossTarget{},
mode: ?std.builtin.Mode = null,
};
builder: *Builder,
lib_step: *std.build.LibExeObjStep,
step: std.build.Step,
name: []const u8,
options: Options,
pub fn create(builder: *Builder, name: []const u8, root_src: []const u8, options: Options) *MacOSBundle {
const self = builder.allocator.create(MacOSBundle) catch unreachable;
if (options.version) |version| {
self.lib_step = builder.addSharedLibrary(name, root_src, .{ .versioned = version });
} else {
self.lib_step = builder.addSharedLibrary(name, root_src, .{ .unversioned = {} });
}
self.builder = builder;
self.name = name;
self.step = std.build.Step.init(.Custom, "macOS .vst bundle", builder.allocator, make);
self.options = options;
if (options.mode) |mode| self.lib_step.setBuildMode(mode);
self.lib_step.setTarget(options.target);
self.lib_step.install();
self.step.dependOn(&self.lib_step.step);
return self;
}
fn make(step: *std.build.Step) !void {
const self = @fieldParentPtr(MacOSBundle, "step", step);
return switch (self.options.target.getOsTag()) {
.macos => self.makeMacOS(),
else => {},
};
}
fn makeMacOS(self: *MacOSBundle) !void {
const bundle_path = try self.getOutputDir();
const cwd = std.fs.cwd();
var bundle_dir = try cwd.makeOpenPath(bundle_path, .{});
defer bundle_dir.close();
try bundle_dir.makePath("Contents/MacOS");
const binary_path = try std.fs.path.join(self.builder.allocator, &[_][]const u8{
"Contents/MacOS",
self.name,
});
const lib_output_path = self.lib_step.getOutputPath();
try cwd.copyFile(lib_output_path, bundle_dir, binary_path, .{});
const plist_file = try bundle_dir.createFile("Contents/Info.plist", .{});
defer plist_file.close();
try self.writePlist(plist_file);
const pkginfo_file = try bundle_dir.createFile("Contents/PkgInfo", .{});
defer pkginfo_file.close();
try pkginfo_file.writeAll("BNDL????");
try self.buildObjectiveC();
try self.buildMetalShaders();
}
fn getOutputDir(self: *MacOSBundle) ![]const u8 {
const vst_path = self.builder.getInstallPath(.Prefix, "vst");
const bundle_basename = self.builder.fmt("{s}.vst", .{self.name});
return try std.fs.path.join(self.builder.allocator, &[_][]const u8{
vst_path,
bundle_basename,
});
}
fn buildObjectiveC(self: *MacOSBundle) !void {
const objc_path = try std.fs.path.join(self.builder.allocator, &[_][]const u8{
self.builder.build_root,
"src/macos/renderer.m",
});
const output_dir = try self.getOutputDir();
const output_path = try std.fs.path.join(self.builder.allocator, &[_][]const u8{
output_dir,
"Contents/MacOS/za-renderer.dynlib",
});
_ = try self.builder.exec(&[_][]const u8{
"clang",
"-shared",
"-framework",
"Foundation",
"-framework",
"AppKit",
"-framework",
"Metal",
"-framework",
"QuartzCore",
objc_path,
"-o",
output_path,
});
}
fn buildMetalShaders(self: *MacOSBundle) !void {
const src_path = try std.fs.path.join(self.builder.allocator, &[_][]const u8{
self.builder.build_root,
"src/macos/shaders.metal",
});
const output_dir = try self.getOutputDir();
const output_path = try std.fs.path.join(self.builder.allocator, &[_][]const u8{
output_dir,
"Contents/MacOS/zig-analyzer.metallib",
});
_ = try self.builder.exec(&[_][]const u8{
"xcrun",
"-sdk",
"macosx",
"metal",
"-fdebug-info-for-profiling",
"-o",
output_path,
src_path,
});
}
fn writePlist(self: *MacOSBundle, file: std.fs.File) !void {
var writer = file.writer();
const template = @embedFile("./Info.plist");
const version_string = if (self.options.version) |version|
self.builder.fmt("{}.{}.{}", .{
version.major,
version.minor,
version.patch,
})
else
"unversioned";
var replace_idx: usize = 0;
const replace = [_][]const u8{
"English",
self.name,
self.options.identifier,
self.name,
"????",
version_string,
version_string,
};
for (template) |char| {
if (char == '$' and replace_idx < replace.len) {
try writer.writeAll(replace[replace_idx]);
replace_idx += 1;
} else {
try writer.writeByte(char);
}
}
}
}; | build.zig |
const std = @import("std");
const builtin = @import("builtin");
const warn = std.debug.print;
const log = std.log;
const CAllocator = std.heap.c_allocator;
const stdout = std.io.getStdOut();
var LogAllocator = std.heap.loggingAllocator(CAllocator, stdout.outStream());
var GPAllocator = std.heap.GeneralPurposeAllocator(.{}){};
var alloc = &GPAllocator.allocator; // take the ptr in a separate step
const simple_buffer = @import("./simple_buffer.zig");
const auth = @import("./auth.zig");
const gui = @import("./gui.zig");
const net = @import("./net.zig");
const heartbeat = @import("./heartbeat.zig");
const config = @import("./config.zig");
const state = @import("./statemachine.zig");
const thread = @import("./thread.zig");
const db = @import("./db/lmdb.zig");
const dbfile = @import("./db/file.zig");
const statemachine = @import("./statemachine.zig");
const util = @import("./util.zig");
const toot_list = @import("./toot_list.zig");
const toot_lib = @import("./toot.zig");
const html_lib = @import("./html.zig");
const filter_lib = @import("./filter.zig");
var settings: config.Settings = undefined;
pub fn main() !void {
hello();
try initialize(alloc);
if (config.readfile("config.json")) |config_data| {
settings = config_data;
var dummy_payload = alloc.create(thread.CommandVerb) catch unreachable;
warn("main start guithread {}\n", .{alloc});
_ = thread.create(gui.go, dummy_payload, guiback);
_ = thread.create(heartbeat.go, dummy_payload, heartback);
while (true) {
statewalk(alloc);
log.debug("== epoll wait\n", .{});
thread.wait(); // main ipc listener
}
} else |err| {
log.err("config error: {}\n", .{err});
}
}
fn initialize(allocator: *std.mem.Allocator) !void {
try config.init(allocator);
try heartbeat.init(allocator);
try statemachine.init(allocator);
try db.init(allocator);
try dbfile.init(allocator);
try thread.init(allocator);
try gui.init(allocator, &settings);
}
fn statewalk(allocator: *std.mem.Allocator) void {
if (statemachine.state == statemachine.States.Init) {
statemachine.setState(statemachine.States.Setup); // transition
var ram = allocator.alloc(u8, 1) catch unreachable;
ram[0] = 1;
gui.schedule(gui.show_main_schedule, &ram);
for (settings.columns.items) |column| {
if (column.config.token) |token| {
_ = token;
profileget(column, allocator);
}
}
for (settings.columns.items) |column| {
gui.schedule(gui.add_column_schedule, column);
}
}
if (statemachine.state == statemachine.States.Setup) {
statemachine.setState(statemachine.States.Running); // transition
columns_net_freshen(allocator);
}
}
fn hello() void {
log.info("zootdeck {} {} tid {x}\n", .{ @tagName(builtin.os.tag), @tagName(builtin.arch), thread.self() });
}
fn columnget(column: *config.ColumnInfo, allocator: *std.mem.Allocator) void {
var verb = allocator.create(thread.CommandVerb) catch unreachable;
var httpInfo = allocator.create(config.HttpInfo) catch unreachable;
httpInfo.url = util.mastodonExpandUrl(column.filter.host(), if (column.config.token) true else false, allocator);
httpInfo.verb = .get;
httpInfo.token = null;
if (column.config.token) |tokenStr| {
httpInfo.token = tokenStr;
}
httpInfo.column = column;
httpInfo.response_code = 0;
verb.http = httpInfo;
gui.schedule(gui.update_column_netstatus_schedule, @ptrCast(*anyopaque, httpInfo));
if (thread.create(net.go, verb, netback)) {} else |err| {
warn("columnget {}", .{err});
}
}
fn profileget(column: *config.ColumnInfo, allocator: *std.mem.Allocator) void {
var verb = allocator.create(thread.CommandVerb) catch unreachable;
var httpInfo = allocator.create(config.HttpInfo) catch unreachable;
httpInfo.url = std.fmt.allocPrint(allocator, "https://{}/api/v1/accounts/verify_credentials", .{column.filter.host()}) catch unreachable;
httpInfo.verb = .get;
httpInfo.token = null;
if (column.config.token) |tokenStr| {
httpInfo.token = tokenStr;
}
httpInfo.column = column;
httpInfo.response_code = 0;
verb.http = httpInfo;
gui.schedule(gui.update_column_netstatus_schedule, @ptrCast(*anyopaque, httpInfo));
_ = thread.create(net.go, verb, profileback) catch unreachable;
}
fn photoget(toot: *toot_lib.Type, url: []const u8, allocator: *std.mem.Allocator) void {
var verb = allocator.create(thread.CommandVerb) catch unreachable;
var httpInfo = allocator.create(config.HttpInfo) catch unreachable;
httpInfo.url = url;
httpInfo.verb = .get;
httpInfo.token = null;
httpInfo.response_code = 0;
httpInfo.toot = toot;
verb.http = httpInfo;
_ = thread.create(net.go, verb, photoback) catch unreachable;
}
fn mediaget(toot: *toot_lib.Type, url: []const u8, allocator: *std.mem.Allocator) void {
var verb = allocator.create(thread.CommandVerb) catch unreachable;
verb.http = allocator.create(config.HttpInfo) catch unreachable;
verb.http.url = url;
verb.http.verb = .get;
verb.http.token = null;
verb.http.response_code = 0;
verb.http.toot = toot;
warn("mediaget toot #{} toot {*} verb.http.toot {*}\n", .{ toot.id(), toot, verb.http.toot });
_ = thread.create(net.go, verb, mediaback) catch unreachable;
}
fn oauthcolumnget(column: *config.ColumnInfo, allocator: *std.mem.Allocator) void {
var verb = allocator.create(thread.CommandVerb) catch unreachable;
var httpInfo = allocator.create(config.HttpInfo) catch unreachable;
auth.oauthClientRegister(allocator, httpInfo, column.filter.host());
httpInfo.token = null;
httpInfo.column = column;
httpInfo.response_code = 0;
httpInfo.verb = .post;
verb.http = httpInfo;
gui.schedule(gui.update_column_netstatus_schedule, @ptrCast(*anyopaque, httpInfo));
_ = thread.create(net.go, verb, oauthback) catch unreachable;
// defer thread.destroy(allocator, netthread);
}
fn oauthtokenget(column: *config.ColumnInfo, code: []const u8, allocator: *std.mem.Allocator) void {
var verb = allocator.create(thread.CommandVerb) catch unreachable;
var httpInfo = allocator.create(config.HttpInfo) catch unreachable;
auth.oauthTokenUpgrade(allocator, httpInfo, column.filter.host(), code, column.oauthClientId.?, column.oauthClientSecret.?);
httpInfo.token = null;
httpInfo.column = column;
httpInfo.response_code = 0;
httpInfo.verb = .post;
verb.http = httpInfo;
gui.schedule(gui.update_column_netstatus_schedule, @ptrCast(*anyopaque, httpInfo));
_ = thread.create(net.go, verb, oauthtokenback) catch unreachable;
}
fn oauthtokenback(command: *thread.Command) void {
warn("*oauthtokenback tid {x} {}\n", .{ thread.self(), command });
const column = command.verb.http.column;
const http = command.verb.http;
if (http.response_code >= 200 and http.response_code < 300) {
const tree = command.verb.http.tree;
//const rootJsonType = @TypeOf(tree.root);
if (true) { // todo: rootJsonType == std.json.ObjectMap) {
if (tree.root.Object.get("access_token")) |cid| {
column.config.token = cid.String;
config.writefile(settings, "config.json");
column.last_check = 0;
profileget(column, alloc);
gui.schedule(gui.update_column_config_oauth_finalize_schedule, @ptrCast(*anyopaque, column));
}
} else {
warn("*oauthtokenback json err body {}\n", .{http.body});
}
} else {
warn("*oauthtokenback net err {}\n", .{http.response_code});
}
}
fn oauthback(command: *thread.Command) void {
warn("*oauthback tid {x} {}\n", .{ thread.self(), command });
const column = command.verb.http.column;
const http = command.verb.http;
if (http.response_code >= 200 and http.response_code < 300) {
const tree = command.verb.http.tree;
const rootJsonType = @TypeOf(tree.root);
if (true) { //todo: rootJsonType == std.json.Value) {
if (tree.root.Object.get("client_id")) |cid| {
column.oauthClientId = cid.String;
}
if (tree.root.Object.get("client_secret")) |cid| {
column.oauthClientSecret = cid.String;
}
warn("*oauthback client id {} secret {}\n", .{ column.oauthClientId, column.oauthClientSecret });
gui.schedule(gui.column_config_oauth_url_schedule, @ptrCast(*anyopaque, column));
} else {
warn("*oauthback json type err {}\n{}\n", .{ rootJsonType, http.body });
}
} else {
warn("*oauthback net err {}\n", .{http.response_code});
}
}
fn netback(command: *thread.Command) void {
warn("*netback tid {x} {}\n", .{ thread.self(), command });
if (command.id == 1) {
gui.schedule(gui.update_column_netstatus_schedule, @ptrCast(*anyopaque, command.verb.http));
var column = command.verb.http.column;
column.refreshing = false;
column.last_check = config.now();
if (command.verb.http.response_code >= 200 and command.verb.http.response_code < 300) {
if (command.verb.http.body.len > 0) {
const tree = command.verb.http.tree;
if (tree.root == .Array) {
column.inError = false;
warn("netback payload is array len {}\n", .{tree.root.Array.items.len});
for (tree.root.Array.items) |jsonValue| {
const item = jsonValue.Object;
const toot = alloc.create(toot_lib.Type) catch unreachable;
toot.* = toot_lib.Type.init(item, alloc);
var id = toot.id();
warn("netback json create toot #{} {*}\n", .{ id, toot });
if (column.toots.contains(toot)) {
// dupe
} else {
var images = toot.get("media_attachments").?.Array;
column.toots.sortedInsert(toot, alloc);
var html = toot.get("content").?.String;
//var html = json_lib.jsonStrDecode(jstr, allocator) catch unreachable;
var root = html_lib.parse(html, alloc);
html_lib.search(root);
cache_update(toot, alloc);
for (images.items) |image| {
const imgUrl = image.Object.get("preview_url").?.String;
warn("toot #{} has img {}\n", .{ toot.id(), imgUrl });
mediaget(toot, imgUrl, alloc);
}
}
}
} else if (tree.root == .Object) {
if (tree.root.Object.get("error")) |err| {
warn("netback json err {} \n", .{err.String});
}
} else {
warn("!netback json unknown root tagtype {}\n", .{tree.root});
}
} else { // empty body
column.inError = true;
}
} else {
column.inError = true;
}
gui.schedule(gui.update_column_toots_schedule, @ptrCast(*anyopaque, column));
}
}
fn mediaback(command: *thread.Command) void {
const reqres = command.verb.http;
const tootpic = alloc.create(gui.TootPic) catch unreachable;
tootpic.toot = reqres.toot;
tootpic.pic = reqres.body;
warn("mediaback toot #{} tootpic.toot {*} adding 1 img\n", .{ tootpic.toot.id(), tootpic.toot });
tootpic.toot.addImg(tootpic.pic);
gui.schedule(gui.toot_media_schedule, @ptrCast(*anyopaque, tootpic));
}
fn photoback(command: *thread.Command) void {
const reqres = command.verb.http;
var account = reqres.toot.get("account").?.Object;
const acct = account.get("acct").?.String;
warn("photoback! acct {} type {} size {}\n", .{ acct, reqres.content_type, reqres.body.len });
dbfile.write(acct, "photo", reqres.body, alloc) catch unreachable;
const cAcct = util.sliceToCstr(alloc, acct);
gui.schedule(gui.update_author_photo_schedule, @ptrCast(*anyopaque, cAcct));
}
fn profileback(command: *thread.Command) void {
const reqres = command.verb.http;
if (reqres.response_code >= 200 and reqres.response_code < 300) {
reqres.column.account = reqres.tree.root.Object;
gui.schedule(gui.update_column_ui_schedule, @ptrCast(*anyopaque, reqres.column));
} else {
warn("profile fail http status {}\n", .{reqres.response_code});
}
}
fn cache_update(toot: *toot_lib.Type, allocator: *std.mem.Allocator) void {
var account = toot.get("account").?.Object;
const acct: []const u8 = account.get("acct").?.String;
const avatar_url: []const u8 = account.get("avatar").?.String;
db.write(acct, "photo_url", avatar_url, allocator) catch unreachable;
const name: []const u8 = account.get("display_name").?.String;
db.write(acct, "name", name, allocator) catch unreachable;
if (dbfile.has(acct, "photo", allocator)) {} else {
photoget(toot, avatar_url, allocator);
}
}
fn guiback(command: *thread.Command) void {
warn("*guiback tid {x} {*}\n", .{ thread.self(), command });
if (command.id == 1) {
var ram = alloc.alloc(u8, 1) catch unreachable;
ram[0] = 1;
gui.schedule(gui.show_main_schedule, &ram);
}
if (command.id == 2) { // refresh button
const column = command.verb.column;
column.inError = false;
column.refreshing = false;
column_refresh(column, alloc);
}
if (command.id == 3) { // add column
var colInfo = alloc.create(config.ColumnInfo) catch unreachable;
colInfo.reset();
colInfo.toots = toot_list.TootList.init();
colInfo.last_check = 0;
settings.columns.append(colInfo) catch unreachable;
var colConfig = alloc.create(config.ColumnConfig) catch unreachable;
colInfo.config = colConfig;
colInfo.config.title = ""[0..];
colInfo.config.filter = "mastodon.example.com"[0..];
colInfo.filter = filter_lib.parse(alloc, colInfo.config.filter);
gui.schedule(gui.add_column_schedule, @ptrCast(*anyopaque, colInfo));
config.writefile(settings, "config.json");
}
if (command.id == 4) { // save config params
const column = command.verb.column;
warn("gui col config {}\n", .{column.config.title});
column.inError = false;
column.refreshing = false;
config.writefile(settings, "config.json");
}
if (command.id == 5) { // column remove
const column = command.verb.column;
warn("gui col remove {}\n", .{column.config.title});
//var colpos: usize = undefined;
for (settings.columns.items) |col, idx| {
if (col == column) {
_ = settings.columns.orderedRemove(idx);
break;
}
}
config.writefile(settings, "config.json");
gui.schedule(gui.column_remove_schedule, @ptrCast(*anyopaque, column));
}
if (command.id == 6) { //oauth
const column = command.verb.column;
if (column.oauthClientId) {
gui.schedule(gui.column_config_oauth_url_schedule, @ptrCast(*anyopaque, column));
} else {
oauthcolumnget(column, alloc);
}
}
if (command.id == 7) { //oauth activate
const myAuth = command.verb.auth.*;
warn("oauth authorization {}\n", .{myAuth.code});
oauthtokenget(myAuth.column, myAuth.code, alloc);
}
if (command.id == 8) { //column config changed
const column = command.verb.column;
// partial reset
column.oauthClientId = null;
column.oauthClientSecret = null;
gui.schedule(gui.update_column_ui_schedule, @ptrCast(*anyopaque, column));
gui.schedule(gui.update_column_toots_schedule, @ptrCast(*anyopaque, column));
// throw out toots in the toot list not from the new host
column_refresh(column, alloc);
}
if (command.id == 9) { // imgonly button
const column = command.verb.column;
column.config.img_only = !column.config.img_only;
config.writefile(settings, "config.json");
gui.schedule(gui.update_column_toots_schedule, @ptrCast(*anyopaque, column));
}
if (command.id == 10) { // window size changed
config.writefile(settings, "config.json");
}
}
fn heartback(command: *thread.Command) void {
warn("*heartback tid {x} {}\n", .{ thread.self(), command });
columns_net_freshen(alloc);
}
fn columns_net_freshen(allocator: *std.mem.Allocator) void {
for (settings.columns.items) |column| {
var now = config.now();
const refresh = 60;
const since = now - column.last_check;
if (since > refresh) {
column_refresh(column, allocator);
} else {
//warn("col {} is fresh for {} sec\n", column.makeTitle(), refresh-since);
}
}
}
fn column_refresh(column: *config.ColumnInfo, allocator: *std.mem.Allocator) void {
if (column.refreshing) {
warn("column {} in {} Ignoring request.\n", .{ column.makeTitle(), if (column.inError) @as([]const u8, "error!") else @as([]const u8, "progress.") });
} else {
warn("column http get {}\n", .{column.makeTitle()});
column.refreshing = true;
columnget(column, allocator);
}
} | src/main.zig |
// SPDX-License-Identifier: MIT
// This file is part of the Termelot project under the MIT license.
const termelot = @import("termelot.zig");
const Position = termelot.Position;
const Rune = termelot.Rune;
const Size = termelot.Size;
/// An Event can be a KeyEvent, MouseEvent, or a new terminal size.
/// You can switch on an Event to get its type:
/// ```zig
/// switch (event) {
/// .Key => |key_event| ...
/// .Mouse => |mouse_event| ...
/// .Resize => |new_size| ...
/// }
/// ```
pub const Event = union(EventType) {
Key: KeyEvent,
Mouse: MouseEvent,
Resize: Size,
};
pub const EventType = enum {
Key,
Mouse,
Resize,
};
/// A KeyEvent is an event triggered by a key press or release.
///
/// **value**: The key that has been pressed.
/// **state**: Whether the key event is for key up or key down.
/// **modifier**: One or several modifier keys that were held when the key was pressed.
/// **repeated**: Applies to non-raw mode, where keys can be held down to be repeated.
/// When this field is true, this is a repeat of an earlier KeyEvent. KeyState is always
/// `Down` when a key is a repeat.
pub const KeyEvent = struct {
value: KeyValue,
state: KeyState,
modifier: KeyModifier,
repeated: bool,
};
/// The Rune field is used when a key is alphanumerical: a-zA-Z, 0-9, and other character
/// keys present on the keyboard. Some special characters like Tab ('\t') and space (' ')
/// will be a Rune value. F1-F12 are found in the Function field. Home, ScrollUp, ScrollDown,
/// Backspace, Return, and more are found in the Control field.
pub const KeyValue = union(KeyType) {
Rune: Rune,
Function: KeyFunction,
Control: KeyControl,
};
pub const KeyType = enum {
Rune,
Function,
Control,
};
/// A modifier is a key that has been held when another key is pressed or a mouse
/// event has occurred. This enum is a bitfield, so none, one, or any number of
/// these fields can be selected in the same enum.
/// ```zig
/// if (modifier & Modifier.Alt > 0 or modifier & Modifier.RightAlt > 0) {
/// // An alt key has been pressed ...
/// } else if (modifier == 0) {
/// // No modifier key was pressed
/// }
/// ```
pub const KeyModifier = enum(u7) {
Shift = 0b1,
Alt = 0b10,
RightAlt = 0b100,
Ctrl = 0b1000,
RightCtrl = 0b10000,
Meta = 0b100000,
Function = 0b1000000,
_,
};
/// **Down**: The key has just been pressed and has not been released yet.
/// **Released**: The key was pressed earlier and has just been released.
pub const KeyState = enum {
Down,
Released,
};
/// A function key F1-F12.
pub const KeyFunction = enum {
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
};
pub const KeyControl = enum {
Backspace,
Delete,
Return,
Escape,
Home,
End,
PageUp,
PageDown,
Up,
Down,
Left,
Right,
};
/// An event triggered by a mouse button or scroll wheel.
///
/// **position**: The mouse position in the terminal.
/// **action**: Whether the event was triggered by a Click, scroll, or other means.
/// **button**: If the action is a Click or DoubleClick, which mouse button was used.
pub const MouseEvent = struct {
position: Position,
action: MouseAction,
button: ?MouseButton,
modifier: KeyModifier,
};
pub const MouseAction = enum {
Click,
DoubleClick,
TripleClick,
ScrollUp,
ScrollDown,
HScrollLeft, // Pushing scroll wheel to the left
HScrollRight, // ... or right
};
pub const MouseButton = enum {
Primary, // Left click
Secondary, // Right click
Auxiliary, // Scroll wheel click
Fourth, // The rest are loosely defined ...
Fifth,
Sixth,
Seventh,
Eighth,
}; | src/event.zig |
const std = @import("std");
const Allocator = mem.Allocator;
const mem = std.mem;
const ast = std.zig.ast;
const Visib = @import("visib.zig").Visib;
const event = std.event;
const Value = @import("value.zig").Value;
const Token = std.zig.Token;
const errmsg = @import("errmsg.zig");
const Scope = @import("scope.zig").Scope;
const Compilation = @import("compilation.zig").Compilation;
pub const Decl = struct {
id: Id,
name: []const u8,
visib: Visib,
resolution: event.Future(Compilation.BuildError!void),
parent_scope: *Scope,
// TODO when we destroy the decl, deref the tree scope
tree_scope: *Scope.AstTree,
pub const Table = std.HashMap([]const u8, *Decl, mem.hash_slice_u8, mem.eql_slice_u8);
pub fn cast(base: *Decl, comptime T: type) ?*T {
if (base.id != @field(Id, @typeName(T))) return null;
return @fieldParentPtr(T, "base", base);
}
pub fn isExported(base: *const Decl, tree: *ast.Tree) bool {
switch (base.id) {
Id.Fn => {
const fn_decl = @fieldParentPtr(Fn, "base", base);
return fn_decl.isExported(tree);
},
else => return false,
}
}
pub fn getSpan(base: *const Decl) errmsg.Span {
switch (base.id) {
Id.Fn => {
const fn_decl = @fieldParentPtr(Fn, "base", base);
const fn_proto = fn_decl.fn_proto;
const start = fn_proto.fn_token;
const end = fn_proto.name_token orelse start;
return errmsg.Span{
.first = start,
.last = end + 1,
};
},
else => @panic("TODO"),
}
}
pub fn findRootScope(base: *const Decl) *Scope.Root {
return base.parent_scope.findRoot();
}
pub const Id = enum {
Var,
Fn,
CompTime,
};
pub const Var = struct {
base: Decl,
};
pub const Fn = struct {
base: Decl,
value: Val,
fn_proto: *ast.Node.FnProto,
// TODO https://github.com/ziglang/zig/issues/683 and then make this anonymous
pub const Val = union(enum) {
Unresolved: void,
Fn: *Value.Fn,
FnProto: *Value.FnProto,
};
pub fn externLibName(self: Fn, tree: *ast.Tree) ?[]const u8 {
return if (self.fn_proto.extern_export_inline_token) |tok_index| x: {
const token = tree.tokens.at(tok_index);
break :x switch (token.id) {
Token.Id.Extern => tree.tokenSlicePtr(token),
else => null,
};
} else null;
}
pub fn isExported(self: Fn, tree: *ast.Tree) bool {
if (self.fn_proto.extern_export_inline_token) |tok_index| {
const token = tree.tokens.at(tok_index);
return token.id == Token.Id.Keyword_export;
} else {
return false;
}
}
};
pub const CompTime = struct {
base: Decl,
};
};
pub const info_zen =
\\
\\ * Communicate intent precisely.
\\ * Edge cases matter.
\\ * Favor reading code over writing code.
\\ * Only one obvious way to do things.
\\ * Runtime crashes are better than bugs.
\\ * Compile errors are better than runtime crashes.
\\ * Incremental improvements.
\\ * Avoid local maximums.
\\ * Reduce the amount one must remember.
\\ * Minimize energy spent on coding style.
\\ * Together we serve end users.
\\
\\
;
fn cmdZen(allocator: *Allocator, args: []const []const u8) !void {
try stdout.write(info_zen);
}
const usage_internal =
\\usage: zig internal [subcommand]
\\
\\Sub-Commands:
\\ build-info Print static compiler build-info
\\
\\
;
fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
if (args.len == 0) {
try stderr.write(usage_internal);
os.exit(1);
}
const sub_commands = []Command{Command{
.name = "build-info",
.exec = cmdInternalBuildInfo,
}};
for (sub_commands) |sub_command| {
if (mem.eql(u8, sub_command.name, args[0])) {
try sub_command.exec(allocator, args[1..]);
return;
}
}
try stderr.print("unknown sub command: {}\n\n", args[0]);
try stderr.write(usage_internal);
}
fn cmdInternalBuildInfo(allocator: *Allocator, args: []const []const u8) !void {
try stdout.print(
\\ZIG_CMAKE_BINARY_DIR {}
\\ZIG_CXX_COMPILER {}
\\ZIG_LLVM_CONFIG_EXE {}
\\ZIG_LLD_INCLUDE_PATH {}
\\ZIG_LLD_LIBRARIES {}
\\ZIG_STD_FILES {}
\\ZIG_C_HEADER_FILES {}
\\ZIG_DIA_GUIDS_LIB {}
\\
,
std.cstr.toSliceConst(c.ZIG_CMAKE_BINARY_DIR),
std.cstr.toSliceConst(c.ZIG_CXX_COMPILER),
std.cstr.toSliceConst(c.ZIG_LLVM_CONFIG_EXE),
std.cstr.toSliceConst(c.ZIG_LLD_INCLUDE_PATH),
std.cstr.toSliceConst(c.ZIG_LLD_LIBRARIES),
std.cstr.toSliceConst(c.ZIG_STD_FILES),
std.cstr.toSliceConst(c.ZIG_C_HEADER_FILES),
std.cstr.toSliceConst(c.ZIG_DIA_GUIDS_LIB),
);
}
fn test__floatuntisf(a: u128, expected: f32) void {
const x = __floatuntisf(a);
testing.expect(x == expected);
}
test "floatuntisf" {
test__floatuntisf(0, 0.0);
test__floatuntisf(1, 1.0);
test__floatuntisf(2, 2.0);
test__floatuntisf(20, 20.0);
test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127);
test__floatuntisf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
test__floatuntisf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
test__floatuntisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76);
test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
}
fn trimStart(slice: []const u8, ch: u8) []const u8 {
var i: usize = 0;
const test_string = "test\"string";
for (slice) |b| {
if (b == '\xa3') break;
if (b == '\ua3d3') break;
if (b == '\Ua3d3d3') break;
if (b == '\t') break;
if (b == '\n') break;
if (b == '\\') break;
if (b == '\'') break;
if (b == '"') break;
if (b != 'n') break;
if (b != '-') break;
i += 1;
}
return slice[i..];
} | tests/examplefiles/example.zig |
const zang = @import("zang");
const common = @import("common.zig");
const c = @import("common/c.zig");
pub const AUDIO_FORMAT: zang.AudioFormat = .signed16_lsb;
pub const AUDIO_SAMPLE_RATE = 48000;
pub const AUDIO_BUFFER_SIZE = 1024;
pub const DESCRIPTION =
\\example_stereo
\\
\\A wind-like noise effect slowly oscillates between the
\\left and right speakers.
\\
\\This example is not interactive.
;
// take input (-1 to +1) and scale it to (min to max)
fn scaleWave(
span: zang.Span,
out: []f32,
in: []const f32,
tmp0: []f32,
min: f32,
max: f32,
) void {
zang.zero(span, tmp0);
zang.multiplyScalar(span, tmp0, in, (max - min) * 0.5);
zang.addScalar(span, out, tmp0, (max - min) * 0.5 + min);
}
// overwrite out with (1 - out)
fn invertWaveInPlace(span: zang.Span, out: []f32, tmp0: []f32) void {
zang.zero(span, tmp0);
zang.multiplyScalar(span, tmp0, out, -1.0);
zang.zero(span, out);
zang.addScalar(span, out, tmp0, 1.0);
}
const NoiseModule = struct {
pub const num_outputs = 2;
pub const num_temps = 3;
pub const Params = struct {
sample_rate: f32,
pan: []const f32,
min: f32,
max: f32,
cutoff_frequency: f32,
};
noise: zang.Noise,
flt: zang.Filter,
fn init() NoiseModule {
return .{
.noise = zang.Noise.init(),
.flt = zang.Filter.init(),
};
}
fn paint(
self: *NoiseModule,
span: zang.Span,
outputs: [num_outputs][]f32,
temps: [num_temps][]f32,
note_id_changed: bool,
params: Params,
) void {
// temps[0] = filtered noise
zang.zero(span, temps[0]);
zang.zero(span, temps[1]);
self.noise.paint(span, .{temps[1]}, .{}, note_id_changed, .{ .color = .white });
self.flt.paint(span, .{temps[0]}, .{}, note_id_changed, .{
.input = temps[1],
.type = .low_pass,
.cutoff = zang.constant(zang.cutoffFromFrequency(
params.cutoff_frequency,
params.sample_rate,
)),
.res = 0.4,
});
// increase volume
zang.multiplyWithScalar(span, temps[0], 4.0);
// temps[1] = pan scaled to (min to max)
zang.zero(span, temps[1]);
scaleWave(span, temps[1], params.pan, temps[2], params.min, params.max);
// left channel += temps[0] * temps[1]
zang.multiply(span, outputs[0], temps[0], temps[1]);
// temps[1] = 1 - temps[1]
invertWaveInPlace(span, temps[1], temps[2]);
// right channel += temps[0] * temps[1]
zang.multiply(span, outputs[1], temps[0], temps[1]);
}
};
pub const MainModule = struct {
pub const num_outputs = 2;
pub const num_temps = 4;
pub const output_audio = common.AudioOut{ .stereo = .{ .left = 0, .right = 1 } };
pub const output_visualize = 0;
osc: zang.SineOsc,
noisem0: NoiseModule,
noisem1: NoiseModule,
pub fn init() MainModule {
return .{
.osc = zang.SineOsc.init(),
.noisem0 = NoiseModule.init(),
.noisem1 = NoiseModule.init(),
};
}
pub fn paint(
self: *MainModule,
span: zang.Span,
outputs: [num_outputs][]f32,
temps: [num_temps][]f32,
) void {
const sample_rate = AUDIO_SAMPLE_RATE;
// temps[0] = slow oscillator representing left/right pan (-1 to +1)
zang.zero(span, temps[0]);
self.osc.paint(span, .{temps[0]}, .{}, false, .{
.sample_rate = sample_rate,
.freq = zang.constant(0.1),
.phase = zang.constant(0.0),
});
// paint two noise voices
self.noisem0.paint(span, outputs, .{ temps[1], temps[2], temps[3] }, false, .{
.sample_rate = sample_rate,
.pan = temps[0],
.min = 0.0,
.max = 0.5,
.cutoff_frequency = 320.0,
});
self.noisem1.paint(span, outputs, .{ temps[1], temps[2], temps[3] }, false, .{
.sample_rate = sample_rate,
.pan = temps[0],
.min = 0.5,
.max = 1.0,
.cutoff_frequency = 380.0,
});
}
}; | examples/example_stereo.zig |
pub const MDM_COMPRESSION = @as(u32, 1);
pub const MDM_ERROR_CONTROL = @as(u32, 2);
pub const MDM_FORCED_EC = @as(u32, 4);
pub const MDM_CELLULAR = @as(u32, 8);
pub const MDM_FLOWCONTROL_HARD = @as(u32, 16);
pub const MDM_FLOWCONTROL_SOFT = @as(u32, 32);
pub const MDM_CCITT_OVERRIDE = @as(u32, 64);
pub const MDM_SPEED_ADJUST = @as(u32, 128);
pub const MDM_TONE_DIAL = @as(u32, 256);
pub const MDM_BLIND_DIAL = @as(u32, 512);
pub const MDM_V23_OVERRIDE = @as(u32, 1024);
pub const MDM_DIAGNOSTICS = @as(u32, 2048);
pub const MDM_MASK_BEARERMODE = @as(u32, 61440);
pub const MDM_SHIFT_BEARERMODE = @as(u32, 12);
pub const MDM_MASK_PROTOCOLID = @as(u32, 983040);
pub const MDM_SHIFT_PROTOCOLID = @as(u32, 16);
pub const MDM_MASK_PROTOCOLDATA = @as(u32, 267386880);
pub const MDM_SHIFT_PROTOCOLDATA = @as(u32, 20);
pub const MDM_SHIFT_PROTOCOLINFO = @as(u32, 16);
pub const MDM_SHIFT_EXTENDEDINFO = @as(u32, 12);
pub const MDM_BEARERMODE_ANALOG = @as(u32, 0);
pub const MDM_BEARERMODE_ISDN = @as(u32, 1);
pub const MDM_BEARERMODE_GSM = @as(u32, 2);
pub const MDM_PROTOCOLID_DEFAULT = @as(u32, 0);
pub const MDM_PROTOCOLID_HDLCPPP = @as(u32, 1);
pub const MDM_PROTOCOLID_V128 = @as(u32, 2);
pub const MDM_PROTOCOLID_X75 = @as(u32, 3);
pub const MDM_PROTOCOLID_V110 = @as(u32, 4);
pub const MDM_PROTOCOLID_V120 = @as(u32, 5);
pub const MDM_PROTOCOLID_AUTO = @as(u32, 6);
pub const MDM_PROTOCOLID_ANALOG = @as(u32, 7);
pub const MDM_PROTOCOLID_GPRS = @as(u32, 8);
pub const MDM_PROTOCOLID_PIAFS = @as(u32, 9);
pub const MDM_SHIFT_HDLCPPP_SPEED = @as(u32, 0);
pub const MDM_MASK_HDLCPPP_SPEED = @as(u32, 7);
pub const MDM_HDLCPPP_SPEED_DEFAULT = @as(u32, 0);
pub const MDM_HDLCPPP_SPEED_64K = @as(u32, 1);
pub const MDM_HDLCPPP_SPEED_56K = @as(u32, 2);
pub const MDM_SHIFT_HDLCPPP_AUTH = @as(u32, 3);
pub const MDM_HDLCPPP_AUTH_DEFAULT = @as(u32, 0);
pub const MDM_HDLCPPP_AUTH_NONE = @as(u32, 1);
pub const MDM_HDLCPPP_AUTH_PAP = @as(u32, 2);
pub const MDM_HDLCPPP_AUTH_CHAP = @as(u32, 3);
pub const MDM_HDLCPPP_AUTH_MSCHAP = @as(u32, 4);
pub const MDM_SHIFT_HDLCPPP_ML = @as(u32, 6);
pub const MDM_HDLCPPP_ML_DEFAULT = @as(u32, 0);
pub const MDM_HDLCPPP_ML_NONE = @as(u32, 1);
pub const MDM_HDLCPPP_ML_2 = @as(u32, 2);
pub const MDM_SHIFT_V120_SPEED = @as(u32, 0);
pub const MDM_MASK_V120_SPEED = @as(u32, 7);
pub const MDM_V120_SPEED_DEFAULT = @as(u32, 0);
pub const MDM_V120_SPEED_64K = @as(u32, 1);
pub const MDM_V120_SPEED_56K = @as(u32, 2);
pub const MDM_SHIFT_V120_ML = @as(u32, 6);
pub const MDM_V120_ML_DEFAULT = @as(u32, 0);
pub const MDM_V120_ML_NONE = @as(u32, 1);
pub const MDM_V120_ML_2 = @as(u32, 2);
pub const MDM_SHIFT_X75_DATA = @as(u32, 0);
pub const MDM_MASK_X75_DATA = @as(u32, 7);
pub const MDM_X75_DATA_DEFAULT = @as(u32, 0);
pub const MDM_X75_DATA_64K = @as(u32, 1);
pub const MDM_X75_DATA_128K = @as(u32, 2);
pub const MDM_X75_DATA_T_70 = @as(u32, 3);
pub const MDM_X75_DATA_BTX = @as(u32, 4);
pub const MDM_SHIFT_V110_SPEED = @as(u32, 0);
pub const MDM_MASK_V110_SPEED = @as(u32, 15);
pub const MDM_V110_SPEED_DEFAULT = @as(u32, 0);
pub const MDM_V110_SPEED_1DOT2K = @as(u32, 1);
pub const MDM_V110_SPEED_2DOT4K = @as(u32, 2);
pub const MDM_V110_SPEED_4DOT8K = @as(u32, 3);
pub const MDM_V110_SPEED_9DOT6K = @as(u32, 4);
pub const MDM_V110_SPEED_12DOT0K = @as(u32, 5);
pub const MDM_V110_SPEED_14DOT4K = @as(u32, 6);
pub const MDM_V110_SPEED_19DOT2K = @as(u32, 7);
pub const MDM_V110_SPEED_28DOT8K = @as(u32, 8);
pub const MDM_V110_SPEED_38DOT4K = @as(u32, 9);
pub const MDM_V110_SPEED_57DOT6K = @as(u32, 10);
pub const MDM_SHIFT_AUTO_SPEED = @as(u32, 0);
pub const MDM_MASK_AUTO_SPEED = @as(u32, 7);
pub const MDM_AUTO_SPEED_DEFAULT = @as(u32, 0);
pub const MDM_SHIFT_AUTO_ML = @as(u32, 6);
pub const MDM_AUTO_ML_DEFAULT = @as(u32, 0);
pub const MDM_AUTO_ML_NONE = @as(u32, 1);
pub const MDM_AUTO_ML_2 = @as(u32, 2);
pub const MDM_ANALOG_RLP_ON = @as(u32, 0);
pub const MDM_ANALOG_RLP_OFF = @as(u32, 1);
pub const MDM_ANALOG_V34 = @as(u32, 2);
pub const MDM_PIAFS_INCOMING = @as(u32, 0);
pub const MDM_PIAFS_OUTGOING = @as(u32, 1);
pub const SID_3GPP_SUPSVCMODEL = Guid.initString("d7d08e07-d767-4478-b14a-eecc87ea12f7");
pub const MAXLENGTH_NAI = @as(u32, 72);
pub const MAXLENGTH_UICCDATASTORE = @as(u32, 10);
//--------------------------------------------------------------------------------
// Section: Types (18)
//--------------------------------------------------------------------------------
pub const MODEM_STATUS_FLAGS = enum(u32) {
CTS_ON = 16,
DSR_ON = 32,
RING_ON = 64,
RLSD_ON = 128,
_,
pub fn initFlags(o: struct {
CTS_ON: u1 = 0,
DSR_ON: u1 = 0,
RING_ON: u1 = 0,
RLSD_ON: u1 = 0,
}) MODEM_STATUS_FLAGS {
return @intToEnum(MODEM_STATUS_FLAGS,
(if (o.CTS_ON == 1) @enumToInt(MODEM_STATUS_FLAGS.CTS_ON) else 0)
| (if (o.DSR_ON == 1) @enumToInt(MODEM_STATUS_FLAGS.DSR_ON) else 0)
| (if (o.RING_ON == 1) @enumToInt(MODEM_STATUS_FLAGS.RING_ON) else 0)
| (if (o.RLSD_ON == 1) @enumToInt(MODEM_STATUS_FLAGS.RLSD_ON) else 0)
);
}
};
pub const MS_CTS_ON = MODEM_STATUS_FLAGS.CTS_ON;
pub const MS_DSR_ON = MODEM_STATUS_FLAGS.DSR_ON;
pub const MS_RING_ON = MODEM_STATUS_FLAGS.RING_ON;
pub const MS_RLSD_ON = MODEM_STATUS_FLAGS.RLSD_ON;
pub const CLEAR_COMM_ERROR_FLAGS = enum(u32) {
BREAK = 16,
FRAME = 8,
OVERRUN = 2,
RXOVER = 1,
RXPARITY = 4,
_,
pub fn initFlags(o: struct {
BREAK: u1 = 0,
FRAME: u1 = 0,
OVERRUN: u1 = 0,
RXOVER: u1 = 0,
RXPARITY: u1 = 0,
}) CLEAR_COMM_ERROR_FLAGS {
return @intToEnum(CLEAR_COMM_ERROR_FLAGS,
(if (o.BREAK == 1) @enumToInt(CLEAR_COMM_ERROR_FLAGS.BREAK) else 0)
| (if (o.FRAME == 1) @enumToInt(CLEAR_COMM_ERROR_FLAGS.FRAME) else 0)
| (if (o.OVERRUN == 1) @enumToInt(CLEAR_COMM_ERROR_FLAGS.OVERRUN) else 0)
| (if (o.RXOVER == 1) @enumToInt(CLEAR_COMM_ERROR_FLAGS.RXOVER) else 0)
| (if (o.RXPARITY == 1) @enumToInt(CLEAR_COMM_ERROR_FLAGS.RXPARITY) else 0)
);
}
};
pub const CE_BREAK = CLEAR_COMM_ERROR_FLAGS.BREAK;
pub const CE_FRAME = CLEAR_COMM_ERROR_FLAGS.FRAME;
pub const CE_OVERRUN = CLEAR_COMM_ERROR_FLAGS.OVERRUN;
pub const CE_RXOVER = CLEAR_COMM_ERROR_FLAGS.RXOVER;
pub const CE_RXPARITY = CLEAR_COMM_ERROR_FLAGS.RXPARITY;
pub const PURGE_COMM_FLAGS = enum(u32) {
RXABORT = 2,
RXCLEAR = 8,
TXABORT = 1,
TXCLEAR = 4,
_,
pub fn initFlags(o: struct {
RXABORT: u1 = 0,
RXCLEAR: u1 = 0,
TXABORT: u1 = 0,
TXCLEAR: u1 = 0,
}) PURGE_COMM_FLAGS {
return @intToEnum(PURGE_COMM_FLAGS,
(if (o.RXABORT == 1) @enumToInt(PURGE_COMM_FLAGS.RXABORT) else 0)
| (if (o.RXCLEAR == 1) @enumToInt(PURGE_COMM_FLAGS.RXCLEAR) else 0)
| (if (o.TXABORT == 1) @enumToInt(PURGE_COMM_FLAGS.TXABORT) else 0)
| (if (o.TXCLEAR == 1) @enumToInt(PURGE_COMM_FLAGS.TXCLEAR) else 0)
);
}
};
pub const PURGE_RXABORT = PURGE_COMM_FLAGS.RXABORT;
pub const PURGE_RXCLEAR = PURGE_COMM_FLAGS.RXCLEAR;
pub const PURGE_TXABORT = PURGE_COMM_FLAGS.TXABORT;
pub const PURGE_TXCLEAR = PURGE_COMM_FLAGS.TXCLEAR;
pub const COMM_EVENT_MASK = enum(u32) {
BREAK = 64,
CTS = 8,
DSR = 16,
ERR = 128,
EVENT1 = 2048,
EVENT2 = 4096,
PERR = 512,
RING = 256,
RLSD = 32,
RX80FULL = 1024,
RXCHAR = 1,
RXFLAG = 2,
TXEMPTY = 4,
_,
pub fn initFlags(o: struct {
BREAK: u1 = 0,
CTS: u1 = 0,
DSR: u1 = 0,
ERR: u1 = 0,
EVENT1: u1 = 0,
EVENT2: u1 = 0,
PERR: u1 = 0,
RING: u1 = 0,
RLSD: u1 = 0,
RX80FULL: u1 = 0,
RXCHAR: u1 = 0,
RXFLAG: u1 = 0,
TXEMPTY: u1 = 0,
}) COMM_EVENT_MASK {
return @intToEnum(COMM_EVENT_MASK,
(if (o.BREAK == 1) @enumToInt(COMM_EVENT_MASK.BREAK) else 0)
| (if (o.CTS == 1) @enumToInt(COMM_EVENT_MASK.CTS) else 0)
| (if (o.DSR == 1) @enumToInt(COMM_EVENT_MASK.DSR) else 0)
| (if (o.ERR == 1) @enumToInt(COMM_EVENT_MASK.ERR) else 0)
| (if (o.EVENT1 == 1) @enumToInt(COMM_EVENT_MASK.EVENT1) else 0)
| (if (o.EVENT2 == 1) @enumToInt(COMM_EVENT_MASK.EVENT2) else 0)
| (if (o.PERR == 1) @enumToInt(COMM_EVENT_MASK.PERR) else 0)
| (if (o.RING == 1) @enumToInt(COMM_EVENT_MASK.RING) else 0)
| (if (o.RLSD == 1) @enumToInt(COMM_EVENT_MASK.RLSD) else 0)
| (if (o.RX80FULL == 1) @enumToInt(COMM_EVENT_MASK.RX80FULL) else 0)
| (if (o.RXCHAR == 1) @enumToInt(COMM_EVENT_MASK.RXCHAR) else 0)
| (if (o.RXFLAG == 1) @enumToInt(COMM_EVENT_MASK.RXFLAG) else 0)
| (if (o.TXEMPTY == 1) @enumToInt(COMM_EVENT_MASK.TXEMPTY) else 0)
);
}
};
pub const EV_BREAK = COMM_EVENT_MASK.BREAK;
pub const EV_CTS = COMM_EVENT_MASK.CTS;
pub const EV_DSR = COMM_EVENT_MASK.DSR;
pub const EV_ERR = COMM_EVENT_MASK.ERR;
pub const EV_EVENT1 = COMM_EVENT_MASK.EVENT1;
pub const EV_EVENT2 = COMM_EVENT_MASK.EVENT2;
pub const EV_PERR = COMM_EVENT_MASK.PERR;
pub const EV_RING = COMM_EVENT_MASK.RING;
pub const EV_RLSD = COMM_EVENT_MASK.RLSD;
pub const EV_RX80FULL = COMM_EVENT_MASK.RX80FULL;
pub const EV_RXCHAR = COMM_EVENT_MASK.RXCHAR;
pub const EV_RXFLAG = COMM_EVENT_MASK.RXFLAG;
pub const EV_TXEMPTY = COMM_EVENT_MASK.TXEMPTY;
pub const ESCAPE_COMM_FUNCTION = enum(u32) {
CLRBREAK = 9,
CLRDTR = 6,
CLRRTS = 4,
SETBREAK = 8,
SETDTR = 5,
SETRTS = 3,
SETXOFF = 1,
SETXON = 2,
};
pub const CLRBREAK = ESCAPE_COMM_FUNCTION.CLRBREAK;
pub const CLRDTR = ESCAPE_COMM_FUNCTION.CLRDTR;
pub const CLRRTS = ESCAPE_COMM_FUNCTION.CLRRTS;
pub const SETBREAK = ESCAPE_COMM_FUNCTION.SETBREAK;
pub const SETDTR = ESCAPE_COMM_FUNCTION.SETDTR;
pub const SETRTS = ESCAPE_COMM_FUNCTION.SETRTS;
pub const SETXOFF = ESCAPE_COMM_FUNCTION.SETXOFF;
pub const SETXON = ESCAPE_COMM_FUNCTION.SETXON;
pub const MODEMDEVCAPS_DIAL_OPTIONS = enum(u32) {
BILLING = 64,
DIALTONE = 256,
QUIET = 128,
_,
pub fn initFlags(o: struct {
BILLING: u1 = 0,
DIALTONE: u1 = 0,
QUIET: u1 = 0,
}) MODEMDEVCAPS_DIAL_OPTIONS {
return @intToEnum(MODEMDEVCAPS_DIAL_OPTIONS,
(if (o.BILLING == 1) @enumToInt(MODEMDEVCAPS_DIAL_OPTIONS.BILLING) else 0)
| (if (o.DIALTONE == 1) @enumToInt(MODEMDEVCAPS_DIAL_OPTIONS.DIALTONE) else 0)
| (if (o.QUIET == 1) @enumToInt(MODEMDEVCAPS_DIAL_OPTIONS.QUIET) else 0)
);
}
};
pub const DIALOPTION_BILLING = MODEMDEVCAPS_DIAL_OPTIONS.BILLING;
pub const DIALOPTION_DIALTONE = MODEMDEVCAPS_DIAL_OPTIONS.DIALTONE;
pub const DIALOPTION_QUIET = MODEMDEVCAPS_DIAL_OPTIONS.QUIET;
pub const MODEMSETTINGS_SPEAKER_MODE = enum(u32) {
CALLSETUP = 8,
DIAL = 2,
OFF = 1,
ON = 4,
};
pub const MDMSPKR_CALLSETUP = MODEMSETTINGS_SPEAKER_MODE.CALLSETUP;
pub const MDMSPKR_DIAL = MODEMSETTINGS_SPEAKER_MODE.DIAL;
pub const MDMSPKR_OFF = MODEMSETTINGS_SPEAKER_MODE.OFF;
pub const MDMSPKR_ON = MODEMSETTINGS_SPEAKER_MODE.ON;
pub const COMMPROP_STOP_PARITY = enum(u16) {
STOPBITS_10 = 1,
STOPBITS_15 = 2,
STOPBITS_20 = 4,
PARITY_NONE = 256,
PARITY_ODD = 512,
PARITY_EVEN = 1024,
PARITY_MARK = 2048,
PARITY_SPACE = 4096,
_,
pub fn initFlags(o: struct {
STOPBITS_10: u1 = 0,
STOPBITS_15: u1 = 0,
STOPBITS_20: u1 = 0,
PARITY_NONE: u1 = 0,
PARITY_ODD: u1 = 0,
PARITY_EVEN: u1 = 0,
PARITY_MARK: u1 = 0,
PARITY_SPACE: u1 = 0,
}) COMMPROP_STOP_PARITY {
return @intToEnum(COMMPROP_STOP_PARITY,
(if (o.STOPBITS_10 == 1) @enumToInt(COMMPROP_STOP_PARITY.STOPBITS_10) else 0)
| (if (o.STOPBITS_15 == 1) @enumToInt(COMMPROP_STOP_PARITY.STOPBITS_15) else 0)
| (if (o.STOPBITS_20 == 1) @enumToInt(COMMPROP_STOP_PARITY.STOPBITS_20) else 0)
| (if (o.PARITY_NONE == 1) @enumToInt(COMMPROP_STOP_PARITY.PARITY_NONE) else 0)
| (if (o.PARITY_ODD == 1) @enumToInt(COMMPROP_STOP_PARITY.PARITY_ODD) else 0)
| (if (o.PARITY_EVEN == 1) @enumToInt(COMMPROP_STOP_PARITY.PARITY_EVEN) else 0)
| (if (o.PARITY_MARK == 1) @enumToInt(COMMPROP_STOP_PARITY.PARITY_MARK) else 0)
| (if (o.PARITY_SPACE == 1) @enumToInt(COMMPROP_STOP_PARITY.PARITY_SPACE) else 0)
);
}
};
pub const STOPBITS_10 = COMMPROP_STOP_PARITY.STOPBITS_10;
pub const STOPBITS_15 = COMMPROP_STOP_PARITY.STOPBITS_15;
pub const STOPBITS_20 = COMMPROP_STOP_PARITY.STOPBITS_20;
pub const PARITY_NONE = COMMPROP_STOP_PARITY.PARITY_NONE;
pub const PARITY_ODD = COMMPROP_STOP_PARITY.PARITY_ODD;
pub const PARITY_EVEN = COMMPROP_STOP_PARITY.PARITY_EVEN;
pub const PARITY_MARK = COMMPROP_STOP_PARITY.PARITY_MARK;
pub const PARITY_SPACE = COMMPROP_STOP_PARITY.PARITY_SPACE;
pub const MODEM_SPEAKER_VOLUME = enum(u32) {
HIGH = 2,
LOW = 0,
MEDIUM = 1,
};
pub const MDMVOL_HIGH = MODEM_SPEAKER_VOLUME.HIGH;
pub const MDMVOL_LOW = MODEM_SPEAKER_VOLUME.LOW;
pub const MDMVOL_MEDIUM = MODEM_SPEAKER_VOLUME.MEDIUM;
pub const MODEMDEVCAPS_SPEAKER_VOLUME = enum(u32) {
HIGH = 4,
LOW = 1,
MEDIUM = 2,
_,
pub fn initFlags(o: struct {
HIGH: u1 = 0,
LOW: u1 = 0,
MEDIUM: u1 = 0,
}) MODEMDEVCAPS_SPEAKER_VOLUME {
return @intToEnum(MODEMDEVCAPS_SPEAKER_VOLUME,
(if (o.HIGH == 1) @enumToInt(MODEMDEVCAPS_SPEAKER_VOLUME.HIGH) else 0)
| (if (o.LOW == 1) @enumToInt(MODEMDEVCAPS_SPEAKER_VOLUME.LOW) else 0)
| (if (o.MEDIUM == 1) @enumToInt(MODEMDEVCAPS_SPEAKER_VOLUME.MEDIUM) else 0)
);
}
};
pub const MDMVOLFLAG_HIGH = MODEMDEVCAPS_SPEAKER_VOLUME.HIGH;
pub const MDMVOLFLAG_LOW = MODEMDEVCAPS_SPEAKER_VOLUME.LOW;
pub const MDMVOLFLAG_MEDIUM = MODEMDEVCAPS_SPEAKER_VOLUME.MEDIUM;
pub const MODEMDEVCAPS_SPEAKER_MODE = enum(u32) {
CALLSETUP = 8,
DIAL = 2,
OFF = 1,
ON = 4,
_,
pub fn initFlags(o: struct {
CALLSETUP: u1 = 0,
DIAL: u1 = 0,
OFF: u1 = 0,
ON: u1 = 0,
}) MODEMDEVCAPS_SPEAKER_MODE {
return @intToEnum(MODEMDEVCAPS_SPEAKER_MODE,
(if (o.CALLSETUP == 1) @enumToInt(MODEMDEVCAPS_SPEAKER_MODE.CALLSETUP) else 0)
| (if (o.DIAL == 1) @enumToInt(MODEMDEVCAPS_SPEAKER_MODE.DIAL) else 0)
| (if (o.OFF == 1) @enumToInt(MODEMDEVCAPS_SPEAKER_MODE.OFF) else 0)
| (if (o.ON == 1) @enumToInt(MODEMDEVCAPS_SPEAKER_MODE.ON) else 0)
);
}
};
pub const MDMSPKRFLAG_CALLSETUP = MODEMDEVCAPS_SPEAKER_MODE.CALLSETUP;
pub const MDMSPKRFLAG_DIAL = MODEMDEVCAPS_SPEAKER_MODE.DIAL;
pub const MDMSPKRFLAG_OFF = MODEMDEVCAPS_SPEAKER_MODE.OFF;
pub const MDMSPKRFLAG_ON = MODEMDEVCAPS_SPEAKER_MODE.ON;
pub const MODEMDEVCAPS = extern struct {
dwActualSize: u32,
dwRequiredSize: u32,
dwDevSpecificOffset: u32,
dwDevSpecificSize: u32,
dwModemProviderVersion: u32,
dwModemManufacturerOffset: u32,
dwModemManufacturerSize: u32,
dwModemModelOffset: u32,
dwModemModelSize: u32,
dwModemVersionOffset: u32,
dwModemVersionSize: u32,
dwDialOptions: MODEMDEVCAPS_DIAL_OPTIONS,
dwCallSetupFailTimer: u32,
dwInactivityTimeout: u32,
dwSpeakerVolume: MODEMDEVCAPS_SPEAKER_VOLUME,
dwSpeakerMode: MODEMDEVCAPS_SPEAKER_MODE,
dwModemOptions: u32,
dwMaxDTERate: u32,
dwMaxDCERate: u32,
abVariablePortion: [1]u8,
};
pub const MODEMSETTINGS = extern struct {
dwActualSize: u32,
dwRequiredSize: u32,
dwDevSpecificOffset: u32,
dwDevSpecificSize: u32,
dwCallSetupFailTimer: u32,
dwInactivityTimeout: u32,
dwSpeakerVolume: MODEM_SPEAKER_VOLUME,
dwSpeakerMode: MODEMSETTINGS_SPEAKER_MODE,
dwPreferredModemOptions: u32,
dwNegotiatedModemOptions: u32,
dwNegotiatedDCERate: u32,
abVariablePortion: [1]u8,
};
pub const COMMPROP = extern struct {
wPacketLength: u16,
wPacketVersion: u16,
dwServiceMask: u32,
dwReserved1: u32,
dwMaxTxQueue: u32,
dwMaxRxQueue: u32,
dwMaxBaud: u32,
dwProvSubType: u32,
dwProvCapabilities: u32,
dwSettableParams: u32,
dwSettableBaud: u32,
wSettableData: u16,
wSettableStopParity: COMMPROP_STOP_PARITY,
dwCurrentTxQueue: u32,
dwCurrentRxQueue: u32,
dwProvSpec1: u32,
dwProvSpec2: u32,
wcProvChar: [1]u16,
};
pub const COMSTAT = extern struct {
_bitfield: u32,
cbInQue: u32,
cbOutQue: u32,
};
pub const DCB = extern struct {
DCBlength: u32,
BaudRate: u32,
_bitfield: u32,
wReserved: u16,
XonLim: u16,
XoffLim: u16,
ByteSize: u8,
Parity: u8,
StopBits: u8,
XonChar: CHAR,
XoffChar: CHAR,
ErrorChar: CHAR,
EofChar: CHAR,
EvtChar: CHAR,
wReserved1: u16,
};
pub const COMMTIMEOUTS = extern struct {
ReadIntervalTimeout: u32,
ReadTotalTimeoutMultiplier: u32,
ReadTotalTimeoutConstant: u32,
WriteTotalTimeoutMultiplier: u32,
WriteTotalTimeoutConstant: u32,
};
pub const COMMCONFIG = extern struct {
dwSize: u32,
wVersion: u16,
wReserved: u16,
dcb: DCB,
dwProviderSubType: u32,
dwProviderOffset: u32,
dwProviderSize: u32,
wcProviderData: [1]u16,
};
//--------------------------------------------------------------------------------
// Section: Functions (30)
//--------------------------------------------------------------------------------
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn ClearCommBreak(
hFile: ?HANDLE,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn ClearCommError(
hFile: ?HANDLE,
lpErrors: ?*CLEAR_COMM_ERROR_FLAGS,
lpStat: ?*COMSTAT,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn SetupComm(
hFile: ?HANDLE,
dwInQueue: u32,
dwOutQueue: u32,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn EscapeCommFunction(
hFile: ?HANDLE,
dwFunc: ESCAPE_COMM_FUNCTION,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn GetCommConfig(
hCommDev: ?HANDLE,
// TODO: what to do with BytesParamIndex 2?
lpCC: ?*COMMCONFIG,
lpdwSize: ?*u32,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn GetCommMask(
hFile: ?HANDLE,
lpEvtMask: ?*COMM_EVENT_MASK,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn GetCommProperties(
hFile: ?HANDLE,
lpCommProp: ?*COMMPROP,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn GetCommModemStatus(
hFile: ?HANDLE,
lpModemStat: ?*MODEM_STATUS_FLAGS,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn GetCommState(
hFile: ?HANDLE,
lpDCB: ?*DCB,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn GetCommTimeouts(
hFile: ?HANDLE,
lpCommTimeouts: ?*COMMTIMEOUTS,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn PurgeComm(
hFile: ?HANDLE,
dwFlags: PURGE_COMM_FLAGS,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn SetCommBreak(
hFile: ?HANDLE,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn SetCommConfig(
hCommDev: ?HANDLE,
// TODO: what to do with BytesParamIndex 2?
lpCC: ?*COMMCONFIG,
dwSize: u32,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn SetCommMask(
hFile: ?HANDLE,
dwEvtMask: COMM_EVENT_MASK,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn SetCommState(
hFile: ?HANDLE,
lpDCB: ?*DCB,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn SetCommTimeouts(
hFile: ?HANDLE,
lpCommTimeouts: ?*COMMTIMEOUTS,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn TransmitCommChar(
hFile: ?HANDLE,
cChar: CHAR,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn WaitCommEvent(
hFile: ?HANDLE,
lpEvtMask: ?*COMM_EVENT_MASK,
lpOverlapped: ?*OVERLAPPED,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows10.0.16299'
pub extern "api-ms-win-core-comm-l1-1-1" fn OpenCommPort(
uPortNumber: u32,
dwDesiredAccess: u32,
dwFlagsAndAttributes: u32,
) callconv(@import("std").os.windows.WINAPI) ?HANDLE;
// TODO: this type is limited to platform 'windows10.0.17134'
pub extern "api-ms-win-core-comm-l1-1-2" fn GetCommPorts(
lpPortNumbers: [*]u32,
uPortNumbersCount: u32,
puPortNumbersFound: ?*u32,
) callconv(@import("std").os.windows.WINAPI) u32;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn BuildCommDCBA(
lpDef: ?[*:0]const u8,
lpDCB: ?*DCB,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn BuildCommDCBW(
lpDef: ?[*:0]const u16,
lpDCB: ?*DCB,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn BuildCommDCBAndTimeoutsA(
lpDef: ?[*:0]const u8,
lpDCB: ?*DCB,
lpCommTimeouts: ?*COMMTIMEOUTS,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn BuildCommDCBAndTimeoutsW(
lpDef: ?[*:0]const u16,
lpDCB: ?*DCB,
lpCommTimeouts: ?*COMMTIMEOUTS,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn CommConfigDialogA(
lpszName: ?[*:0]const u8,
hWnd: ?HWND,
lpCC: ?*COMMCONFIG,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn CommConfigDialogW(
lpszName: ?[*:0]const u16,
hWnd: ?HWND,
lpCC: ?*COMMCONFIG,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn GetDefaultCommConfigA(
lpszName: ?[*:0]const u8,
// TODO: what to do with BytesParamIndex 2?
lpCC: ?*COMMCONFIG,
lpdwSize: ?*u32,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn GetDefaultCommConfigW(
lpszName: ?[*:0]const u16,
// TODO: what to do with BytesParamIndex 2?
lpCC: ?*COMMCONFIG,
lpdwSize: ?*u32,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn SetDefaultCommConfigA(
lpszName: ?[*:0]const u8,
// TODO: what to do with BytesParamIndex 2?
lpCC: ?*COMMCONFIG,
dwSize: u32,
) callconv(@import("std").os.windows.WINAPI) BOOL;
// TODO: this type is limited to platform 'windows5.1.2600'
pub extern "KERNEL32" fn SetDefaultCommConfigW(
lpszName: ?[*:0]const u16,
// TODO: what to do with BytesParamIndex 2?
lpCC: ?*COMMCONFIG,
dwSize: u32,
) callconv(@import("std").os.windows.WINAPI) BOOL;
//--------------------------------------------------------------------------------
// Section: Unicode Aliases (5)
//--------------------------------------------------------------------------------
const thismodule = @This();
pub usingnamespace switch (@import("../zig.zig").unicode_mode) {
.ansi => struct {
pub const BuildCommDCB = thismodule.BuildCommDCBA;
pub const BuildCommDCBAndTimeouts = thismodule.BuildCommDCBAndTimeoutsA;
pub const CommConfigDialog = thismodule.CommConfigDialogA;
pub const GetDefaultCommConfig = thismodule.GetDefaultCommConfigA;
pub const SetDefaultCommConfig = thismodule.SetDefaultCommConfigA;
},
.wide => struct {
pub const BuildCommDCB = thismodule.BuildCommDCBW;
pub const BuildCommDCBAndTimeouts = thismodule.BuildCommDCBAndTimeoutsW;
pub const CommConfigDialog = thismodule.CommConfigDialogW;
pub const GetDefaultCommConfig = thismodule.GetDefaultCommConfigW;
pub const SetDefaultCommConfig = thismodule.SetDefaultCommConfigW;
},
.unspecified => if (@import("builtin").is_test) struct {
pub const BuildCommDCB = *opaque{};
pub const BuildCommDCBAndTimeouts = *opaque{};
pub const CommConfigDialog = *opaque{};
pub const GetDefaultCommConfig = *opaque{};
pub const SetDefaultCommConfig = *opaque{};
} else struct {
pub const BuildCommDCB = @compileError("'BuildCommDCB' requires that UNICODE be set to true or false in the root module");
pub const BuildCommDCBAndTimeouts = @compileError("'BuildCommDCBAndTimeouts' requires that UNICODE be set to true or false in the root module");
pub const CommConfigDialog = @compileError("'CommConfigDialog' requires that UNICODE be set to true or false in the root module");
pub const GetDefaultCommConfig = @compileError("'GetDefaultCommConfig' requires that UNICODE be set to true or false in the root module");
pub const SetDefaultCommConfig = @compileError("'SetDefaultCommConfig' requires that UNICODE be set to true or false in the root module");
},
};
//--------------------------------------------------------------------------------
// Section: Imports (8)
//--------------------------------------------------------------------------------
const Guid = @import("../zig.zig").Guid;
const BOOL = @import("../foundation.zig").BOOL;
const CHAR = @import("../foundation.zig").CHAR;
const HANDLE = @import("../foundation.zig").HANDLE;
const HWND = @import("../foundation.zig").HWND;
const OVERLAPPED = @import("../system/io.zig").OVERLAPPED;
const PSTR = @import("../foundation.zig").PSTR;
const PWSTR = @import("../foundation.zig").PWSTR;
test {
@setEvalBranchQuota(
@import("std").meta.declarations(@This()).len * 3
);
// reference all the pub declarations
if (!@import("builtin").is_test) return;
inline for (@import("std").meta.declarations(@This())) |decl| {
if (decl.is_pub) {
_ = decl;
}
}
} | win32/devices/communication.zig |
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
const lib = b.addStaticLibrary("gravity", "src/gravity.zig");
lib.setBuildMode(mode);
lib.setTarget(target);
addcsources(lib);
lib.install();
const main_tests = b.addTest("src/gravity.zig");
main_tests.setBuildMode(mode);
main_tests.setTarget(target);
addcsources(main_tests);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
}
fn addcsources(lib: *std.build.LibExeObjStep) void {
if (lib.target.isWindows()) {
lib.linkSystemLibrary("shlwapi");
}
lib.linkLibC();
lib.addIncludeDir("deps/gravity/src/shared");
lib.addIncludeDir("deps/gravity/src/runtime");
lib.addIncludeDir("deps/gravity/src/utils");
lib.addIncludeDir("deps/gravity/src/compiler");
lib.addIncludeDir("deps/gravity/src/optionals");
lib.addCSourceFiles(&.{
"deps/gravity/src/shared/gravity_value.c",
"deps/gravity/src/shared/gravity_hash.c",
"deps/gravity/src/shared/gravity_memory.c",
"deps/gravity/src/runtime/gravity_core.c",
"deps/gravity/src/runtime/gravity_vm.c",
"deps/gravity/src/utils/gravity_debug.c",
"deps/gravity/src/utils/gravity_json.c",
"deps/gravity/src/utils/gravity_utils.c",
"deps/gravity/src/compiler/gravity_ast.c",
"deps/gravity/src/compiler/gravity_lexer.c",
"deps/gravity/src/compiler/gravity_token.c",
"deps/gravity/src/compiler/gravity_ircode.c",
"deps/gravity/src/compiler/gravity_parser.c",
"deps/gravity/src/compiler/gravity_codegen.c",
"deps/gravity/src/compiler/gravity_visitor.c",
"deps/gravity/src/compiler/gravity_compiler.c",
"deps/gravity/src/compiler/gravity_optimizer.c",
"deps/gravity/src/compiler/gravity_semacheck1.c",
"deps/gravity/src/compiler/gravity_semacheck2.c",
"deps/gravity/src/compiler/gravity_symboltable.c",
"deps/gravity/src/optionals/gravity_opt_env.c",
"deps/gravity/src/optionals/gravity_opt_file.c",
"deps/gravity/src/optionals/gravity_opt_json.c",
"deps/gravity/src/optionals/gravity_opt_math.c",
}, &.{
"-W",
"-O3",
"-fno-sanitize=undefined",
});
} | build.zig |
const std = @import("std");
const path = std.fs.path;
const Builder = std.build.Builder;
const Step = std.build.Step;
/// Utility functionality to help with compiling shaders from build.zig.
/// Invokes glslc (or another shader compiler passed to `init`) for each shader
/// added via `addShader`.
pub const ShaderCompileStep = struct {
/// Structure representing a shader to be compiled.
const Shader = struct {
/// The path to the shader, relative to the current build root.
source_path: []const u8,
/// The full output path where the compiled shader binary is placed.
full_out_path: []const u8,
};
step: Step,
builder: *Builder,
/// The command and optional arguments used to invoke the shader compiler.
glslc_cmd: []const []const u8,
/// List of shaders that are to be compiled.
shaders: std.ArrayList(Shader),
/// Create a ShaderCompilerStep for `builder`. When this step is invoked by the build
/// system, `<glcl_cmd...> <shader_source> -o <dst_addr>` is invoked for each shader.
pub fn init(builder: *Builder, glslc_cmd: []const []const u8) *ShaderCompileStep {
const self = builder.allocator.create(ShaderCompileStep) catch unreachable;
self.* = .{
.step = Step.init(.custom, "shader-compile", builder.allocator, make),
.builder = builder,
.glslc_cmd = glslc_cmd,
.shaders = std.ArrayList(Shader).init(builder.allocator),
};
return self;
}
/// Add a shader to be compiled. `src` is shader source path, relative to the project root.
/// Returns the full path where the compiled binary will be stored upon successful compilation.
/// This path can then be used to include the binary into an executable, for example by passing it
/// to @embedFile via an additional generated file.
pub fn add(self: *ShaderCompileStep, src: []const u8) []const u8 {
const full_out_path = path.join(self.builder.allocator, &[_][]const u8{
self.builder.build_root,
self.builder.cache_root,
"shaders",
src,
}) catch unreachable;
self.shaders.append(.{ .source_path = src, .full_out_path = full_out_path }) catch unreachable;
return full_out_path;
}
/// Internal build function.
fn make(step: *Step) !void {
const self = @fieldParentPtr(ShaderCompileStep, "step", step);
const cwd = std.fs.cwd();
const cmd = try self.builder.allocator.alloc([]const u8, self.glslc_cmd.len + 3);
for (self.glslc_cmd) |part, i| {
cmd[i] = part;
}
cmd[cmd.len - 2] = "-o";
for (self.shaders.items) |shader| {
const dir = path.dirname(shader.full_out_path).?;
try cwd.makePath(dir);
cmd[cmd.len - 3] = shader.source_path;
cmd[cmd.len - 1] = shader.full_out_path;
try self.builder.spawnChild(cmd);
}
}
}; | generator/build_integration.zig |
const std = @import("std");
const warn = @import("std").debug.warn;
const process = std.process;
// const operators = @import("Operators");
// comptime {
// const operator_info = @typeInfo(operators);
// inline for (operator_info.decls) |declaration| {
// @compileError("Found '" ++ @typeName(declaration) ++ "'");
// }
// }
const Arguments = struct {
numData: i32, initialValue: f32, incrementPerValue: f32, operation: []u8, operationArg1: f32
};
pub fn helpArgs(comptime T: type) void {
const type_info = @typeInfo(T);
warn("Expected:\n\tMain argument value (for as many arguments as desired)\n", .{});
warn("\nAvailable Arguments:\n", .{});
switch (type_info) {
.Struct => {
// This must be inline to function: the length can't be known at runtime. I'm not sure
// my understanding is correct; see https://github.com/ziglang/zig/issues/1435
inline for (type_info.Struct.fields) |field| {
warn("\t{}\n", .{field.name});
}
},
else => {
@compileError("Unsupported type '" ++ @typeName(T) ++ "'");
},
}
}
fn setArg(comptime T: type, comptime field: std.builtin.TypeInfo.StructField, output: *T, arg_name: []u8, arg_value: []u8) !void {
switch (@typeInfo(field.field_type)) {
.Float => {
if (std.fmt.parseFloat(field.field_type, arg_value)) |parsed_float| {
@field(output, field.name) = parsed_float;
} else |err| {
warn("Argument '{}' got input '{}' was unparsable as a {}\n", .{ arg_name, arg_value, @typeName(field.field_type) });
return err;
}
},
.Int => {
if (std.fmt.parseInt(field.field_type, arg_value, 10)) |parsed_value| {
@field(output, field.name) = parsed_value;
} else |err| {
warn("Argument '{}' got input '{}' was unparsable as a {}\n", .{ arg_name, arg_value, @typeName(field.field_type) });
return err;
}
},
.Pointer => {
// std.mem.copy(u8, @field(output, field.name), arg_value);
@field(output, field.name) = arg_value;
},
else => {
@compileError("Unsupported type '" ++ @typeName(field.field_type) ++ "' on field '" ++ field.name ++ "'");
},
}
warn("Set {} to {}\n", .{ field.name, @field(output, field.name) });
}
// Yes, this got hairy, but it would work for "any" args struct, not just the one I set up
fn setArgFromString(comptime T: type, output: *T, arg_name: []u8, arg_value: []u8) !void {
const type_info = @typeInfo(T);
switch (type_info) {
.Struct => {
inline for (type_info.Struct.fields) |field| {
if (std.mem.eql(u8, arg_name, field.name)) {
try setArg(T, field, output, arg_name, arg_value);
return;
}
}
},
else => {
@compileError("Expected Struct, got '" ++ @typeName(T) ++ "'");
},
}
}
// comptime {
// comptime var numFuncs: i32 = 0;
// if (1 == 2) {
// @compileError("Ran at compile time!");
// } else {
// numFuncs += 1;
// }
// }
pub fn main() !void {
warn("Language Tests\n", .{});
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
var args_it = process.args();
if (!args_it.skip()) @panic("expected self arg");
var args_list = std.ArrayList([]const u8).init(allocator);
var current_arg = try (args_it.next(allocator) orelse {
helpArgs(Arguments);
@panic("Requires some arguments");
});
// No need to free; arena allocator will do it for me
// defer allocator.free(first_arg);
var args: Arguments = .{
.numData = 10000,
.initialValue = 0,
.incrementPerValue = 1.0,
.operation = "",
.operationArg1 = 0.0,
};
var is_field_name = false;
var field_name = current_arg;
while (current_arg.len > 0) : ({
current_arg = try (args_it.next(allocator) orelse "");
}) {
if (is_field_name) {
try setArgFromString(Arguments, &args, field_name, current_arg);
is_field_name = false;
} else {
field_name = current_arg;
is_field_name = true;
}
}
if (is_field_name) {
helpArgs(Arguments);
@panic("Expected pairs of 'fieldName value'");
}
} | Zig/Main.zig |
const bld = @import("std").build;
const mem = @import("std").mem;
const zig = @import("std").zig;
fn macosAddSdkDirs(b: *bld.Builder, step: *bld.LibExeObjStep) !void {
const sdk_dir = try zig.system.getSDKPath(b.allocator);
const framework_dir = try mem.concat(b.allocator, u8, &[_][]const u8 { sdk_dir, "/System/Library/Frameworks" });
const usrinclude_dir = try mem.concat(b.allocator, u8, &[_][]const u8 { sdk_dir, "/usr/include"});
step.addFrameworkDir(framework_dir);
step.addIncludeDir(usrinclude_dir);
}
pub fn buildSokol(b: *bld.Builder, comptime prefix_path: []const u8) *bld.LibExeObjStep {
const lib = b.addStaticLibrary("sokol", null);
lib.linkLibC();
lib.setBuildMode(b.standardReleaseOptions());
const sokol_path = prefix_path ++ "src/sokol/c/";
const csources = [_][]const u8 {
"sokol_app_gfx.c",
"sokol_time.c",
"sokol_audio.c",
"sokol_gl.c",
"sokol_debugtext.c",
"sokol_shape.c",
};
if (lib.target.isDarwin()) {
macosAddSdkDirs(b, lib) catch unreachable;
inline for (csources) |csrc| {
lib.addCSourceFile(sokol_path ++ csrc, &[_][]const u8{"-ObjC", "-DIMPL"});
}
lib.linkFramework("MetalKit");
lib.linkFramework("Metal");
lib.linkFramework("Cocoa");
lib.linkFramework("QuartzCore");
lib.linkFramework("AudioToolbox");
} else {
inline for (csources) |csrc| {
lib.addCSourceFile(sokol_path ++ csrc, &[_][]const u8{"-DIMPL"});
}
if (lib.target.isLinux()) {
lib.linkSystemLibrary("X11");
lib.linkSystemLibrary("Xi");
lib.linkSystemLibrary("Xcursor");
lib.linkSystemLibrary("GL");
lib.linkSystemLibrary("asound");
}
}
return lib;
}
pub fn build(b: *bld.Builder) void {
const e = b.addExecutable("PROJECT SCRUMPTIOUS", "src/main.zig");
e.linkLibrary(buildSokol(b, ""));
//e.linkSystemLibrary("c");
e.addIncludeDir("src/fileformats/");
e.addCSourceFile("src/fileformats/stb_image_impl.c", &[_][]const u8{"-std=c99"});
e.addPackagePath("fileformats", "src/fileformats/glue.zig");
e.addPackagePath("sokol", "src/sokol/sokol.zig");
e.addPackagePath("ecs", "src/ecs/ecs.zig");
e.install();
b.step("run", "Run PROJECT SCRUMPTIOUS").dependOn(&e.run().step);
} | build.zig |
const std = @import("std");
const c = @import("internal/c.zig");
const internal = @import("internal/internal.zig");
const log = std.log.scoped(.git);
const git = @import("git.zig");
/// Unique identity of any object (commit, tree, blob, tag).
pub const Oid = extern struct {
id: [20]u8,
/// Minimum length (in number of hex characters, i.e. packets of 4 bits) of an oid prefix
pub const MIN_PREFIX_LEN = c.GIT_OID_MINPREFIXLEN;
/// Size (in bytes) of a hex formatted oid
pub const HEX_BUFFER_SIZE = c.GIT_OID_HEXSZ;
pub fn formatHexAlloc(self: Oid, allocator: *std.mem.Allocator) ![]const u8 {
const buf = try allocator.alloc(u8, HEX_BUFFER_SIZE);
errdefer allocator.free(buf);
return try self.formatHex(buf);
}
/// `buf` must be atleast `HEX_BUFFER_SIZE` long.
pub fn formatHex(self: Oid, buf: []u8) ![]const u8 {
if (buf.len < HEX_BUFFER_SIZE) return error.BufferTooShort;
try internal.wrapCall("git_oid_fmt", .{ buf.ptr, @ptrCast(*const c.git_oid, &self) });
return buf[0..HEX_BUFFER_SIZE];
}
pub fn formatHexAllocZ(self: Oid, allocator: *std.mem.Allocator) ![:0]const u8 {
const buf = try allocator.allocSentinel(u8, HEX_BUFFER_SIZE, 0);
errdefer allocator.free(buf);
return (try self.formatHex(buf))[0.. :0];
}
/// `buf` must be atleast `HEX_BUFFER_SIZE + 1` long.
pub fn formatHexZ(self: Oid, buf: []u8) ![:0]const u8 {
if (buf.len < (HEX_BUFFER_SIZE + 1)) return error.BufferTooShort;
try internal.wrapCall("git_oid_fmt", .{ buf.ptr, @ptrCast(*const c.git_oid, &self) });
buf[HEX_BUFFER_SIZE] = 0;
return buf[0..HEX_BUFFER_SIZE :0];
}
/// Allows partial output
pub fn formatHexCountAlloc(self: Oid, allocator: *std.mem.Allocator, length: usize) ![]const u8 {
const buf = try allocator.alloc(u8, length);
errdefer allocator.free(buf);
return try self.formatHexCount(buf, length);
}
/// Allows partial output
pub fn formatHexCount(self: Oid, buf: []u8, length: usize) ![]const u8 {
if (buf.len < length) return error.BufferTooShort;
try internal.wrapCall("git_oid_nfmt", .{ buf.ptr, length, @ptrCast(*const c.git_oid, &self) });
return buf[0..length];
}
/// Allows partial output
pub fn formatHexCountAllocZ(self: Oid, allocator: *std.mem.Allocator, length: usize) ![:0]const u8 {
const buf = try allocator.allocSentinel(u8, length, 0);
errdefer allocator.free(buf);
return (try self.formatHexCount(buf, length))[0.. :0];
}
/// Allows partial output
pub fn formatHexCountZ(self: Oid, buf: []u8, length: usize) ![:0]const u8 {
if (buf.len < (length + 1)) return error.BufferTooShort;
try internal.wrapCall("git_oid_nfmt", .{ buf.ptr, length, @ptrCast(*const c.git_oid, &self) });
buf[length] = 0;
return buf[0..length :0];
}
pub fn formatHexPathAlloc(self: Oid, allocator: *std.mem.Allocator) ![]const u8 {
const buf = try allocator.alloc(u8, HEX_BUFFER_SIZE + 1);
errdefer allocator.free(buf);
return try self.formatHexPath(buf);
}
/// `buf` must be atleast `HEX_BUFFER_SIZE + 1` long.
pub fn formatHexPath(self: Oid, buf: []u8) ![]const u8 {
if (buf.len < HEX_BUFFER_SIZE + 1) return error.BufferTooShort;
try internal.wrapCall("git_oid_pathfmt", .{ buf.ptr, @ptrCast(*const c.git_oid, &self) });
return buf[0..HEX_BUFFER_SIZE];
}
pub fn formatHexPathAllocZ(self: Oid, allocator: *std.mem.Allocator) ![:0]const u8 {
const buf = try allocator.allocSentinel(u8, HEX_BUFFER_SIZE + 1, 0);
errdefer allocator.free(buf);
return (try self.formatHexPath(buf))[0.. :0];
}
/// `buf` must be atleast `HEX_BUFFER_SIZE + 2` long.
pub fn formatHexPathZ(self: Oid, buf: []u8) ![:0]const u8 {
if (buf.len < (HEX_BUFFER_SIZE + 2)) return error.BufferTooShort;
try internal.wrapCall("git_oid_pathfmt", .{ buf.ptr, @ptrCast(*const c.git_oid, &self) });
buf[HEX_BUFFER_SIZE] = 0;
return buf[0..HEX_BUFFER_SIZE :0];
}
pub fn tryParse(str: [:0]const u8) ?Oid {
return tryParsePtr(str.ptr);
}
pub fn tryParsePtr(str: [*:0]const u8) ?Oid {
var result: Oid = undefined;
internal.wrapCall("git_oid_fromstrp", .{ @ptrCast(*c.git_oid, &result), str }) catch {
return null;
};
return result;
}
/// Parse `length` characters of a hex formatted object id into a `Oid`
///
/// If `length` is odd, the last byte's high nibble will be read in and the low nibble set to zero.
pub fn parseCount(buf: []const u8, length: usize) !Oid {
if (buf.len < length) return error.BufferTooShort;
var result: Oid = undefined;
try internal.wrapCall("git_oid_fromstrn", .{ @ptrCast(*c.git_oid, &result), buf.ptr, length });
return result;
}
/// <0 if a < b; 0 if a == b; >0 if a > b
pub fn compare(a: Oid, b: Oid) c_int {
return c.git_oid_cmp(@ptrCast(*const c.git_oid, &a), @ptrCast(*const c.git_oid, &b));
}
pub fn equal(self: Oid, other: Oid) bool {
return c.git_oid_equal(@ptrCast(*const c.git_oid, &self), @ptrCast(*const c.git_oid, &other)) == 1;
}
pub fn compareCount(self: Oid, other: Oid, count: usize) bool {
return c.git_oid_ncmp(@ptrCast(*const c.git_oid, &self), @ptrCast(*const c.git_oid, &other), count) == 0;
}
pub fn equalStr(self: Oid, str: [:0]const u8) bool {
return c.git_oid_streq(@ptrCast(*const c.git_oid, &self), str.ptr) == 0;
}
/// <0 if a < str; 0 if a == str; >0 if a > str
pub fn compareStr(a: Oid, str: [:0]const u8) c_int {
return c.git_oid_strcmp(@ptrCast(*const c.git_oid, &a), str.ptr);
}
pub fn allZeros(self: Oid) bool {
for (self.id) |i| if (i != 0) return false;
return true;
}
pub fn zero() Oid {
return .{ .id = [_]u8{0} ** 20 };
}
test {
try std.testing.expectEqual(@sizeOf(c.git_oid), @sizeOf(Oid));
try std.testing.expectEqual(@bitSizeOf(c.git_oid), @bitSizeOf(Oid));
}
comptime {
std.testing.refAllDecls(@This());
}
};
/// The OID shortener is used to process a list of OIDs in text form and return the shortest length that would uniquely identify
/// all of them.
///
/// E.g. look at the result of `git log --abbrev-commit`.
pub const OidShortener = opaque {
/// `min_length` is the minimal length for all identifiers, which will be used even if shorter OIDs would still be unique.
pub fn init(min_length: usize) !*OidShortener {
log.debug("OidShortener.init called, min_length={}", .{min_length});
if (c.git_oid_shorten_new(min_length)) |ret| {
log.debug("Oid shortener created successfully", .{});
return @ptrCast(*OidShortener, ret);
}
return error.OutOfMemory;
}
pub fn add(self: *OidShortener, str: []const u8) !c_uint {
log.debug("OidShortener.add called, str={s}", .{str});
if (str.len < Oid.HEX_BUFFER_SIZE) return error.BufferTooShort;
const ret = try internal.wrapCallWithReturn("git_oid_shorten_add", .{
@ptrCast(*c.git_oid_shorten, self),
str.ptr,
});
log.debug("shortest unique Oid length: {}", .{ret});
return @bitCast(c_uint, ret);
}
pub fn deinit(self: *OidShortener) void {
log.debug("OidShortener.deinit called", .{});
c.git_oid_shorten_free(@ptrCast(*c.git_oid_shorten, self));
log.debug("Oid shortener freed successfully", .{});
}
comptime {
std.testing.refAllDecls(@This());
}
};
comptime {
std.testing.refAllDecls(@This());
} | src/oid.zig |
const std = @import("std");
const cast = std.meta.cast;
const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels
/// The function addcarryxU28 is an addition with carry.
/// Postconditions:
/// out1 = (arg1 + arg2 + arg3) mod 2^28
/// out2 = ⌊(arg1 + arg2 + arg3) / 2^28⌋
///
/// Input Bounds:
/// arg1: [0x0 ~> 0x1]
/// arg2: [0x0 ~> 0xfffffff]
/// arg3: [0x0 ~> 0xfffffff]
/// Output Bounds:
/// out1: [0x0 ~> 0xfffffff]
/// out2: [0x0 ~> 0x1]
fn addcarryxU28(out1: *u32, out2: *u1, arg1: u1, arg2: u32, arg3: u32) callconv(.Inline) void {
@setRuntimeSafety(mode == .Debug);
const x1 = ((cast(u32, arg1) + arg2) + arg3);
const x2 = (x1 & 0xfffffff);
const x3 = cast(u1, (x1 >> 28));
out1.* = x2;
out2.* = x3;
}
/// The function subborrowxU28 is a subtraction with borrow.
/// Postconditions:
/// out1 = (-arg1 + arg2 + -arg3) mod 2^28
/// out2 = -⌊(-arg1 + arg2 + -arg3) / 2^28⌋
///
/// Input Bounds:
/// arg1: [0x0 ~> 0x1]
/// arg2: [0x0 ~> 0xfffffff]
/// arg3: [0x0 ~> 0xfffffff]
/// Output Bounds:
/// out1: [0x0 ~> 0xfffffff]
/// out2: [0x0 ~> 0x1]
fn subborrowxU28(out1: *u32, out2: *u1, arg1: u1, arg2: u32, arg3: u32) callconv(.Inline) void {
@setRuntimeSafety(mode == .Debug);
const x1 = cast(i32, (cast(i64, cast(i32, (cast(i64, arg2) - cast(i64, arg1)))) - cast(i64, arg3)));
const x2 = cast(i1, (x1 >> 28));
const x3 = cast(u32, (cast(i64, x1) & cast(i64, 0xfffffff)));
out1.* = x3;
out2.* = cast(u1, (cast(i2, 0x0) - cast(i2, x2)));
}
/// The function cmovznzU32 is a single-word conditional move.
/// Postconditions:
/// out1 = (if arg1 = 0 then arg2 else arg3)
///
/// Input Bounds:
/// arg1: [0x0 ~> 0x1]
/// arg2: [0x0 ~> 0xffffffff]
/// arg3: [0x0 ~> 0xffffffff]
/// Output Bounds:
/// out1: [0x0 ~> 0xffffffff]
fn cmovznzU32(out1: *u32, arg1: u1, arg2: u32, arg3: u32) callconv(.Inline) void {
@setRuntimeSafety(mode == .Debug);
const x1 = (~(~arg1));
const x2 = cast(u32, (cast(i64, cast(i1, (cast(i2, 0x0) - cast(i2, x1)))) & cast(i64, 0xffffffff)));
const x3 = ((x2 & arg3) | ((~x2) & arg2));
out1.* = x3;
}
/// The function carryMul multiplies two field elements and reduces the result.
/// Postconditions:
/// eval out1 mod m = (eval arg1 * eval arg2) mod m
///
/// Input Bounds:
/// arg1: [[0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000]]
/// arg2: [[0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000]]
/// Output Bounds:
/// out1: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
pub fn carryMul(out1: *[16]u32, arg1: [16]u32, arg2: [16]u32) void {
@setRuntimeSafety(mode == .Debug);
const x1 = (cast(u64, (arg1[15])) * cast(u64, (arg2[15])));
const x2 = (cast(u64, (arg1[15])) * cast(u64, (arg2[14])));
const x3 = (cast(u64, (arg1[15])) * cast(u64, (arg2[13])));
const x4 = (cast(u64, (arg1[15])) * cast(u64, (arg2[12])));
const x5 = (cast(u64, (arg1[15])) * cast(u64, (arg2[11])));
const x6 = (cast(u64, (arg1[15])) * cast(u64, (arg2[10])));
const x7 = (cast(u64, (arg1[15])) * cast(u64, (arg2[9])));
const x8 = (cast(u64, (arg1[14])) * cast(u64, (arg2[15])));
const x9 = (cast(u64, (arg1[14])) * cast(u64, (arg2[14])));
const x10 = (cast(u64, (arg1[14])) * cast(u64, (arg2[13])));
const x11 = (cast(u64, (arg1[14])) * cast(u64, (arg2[12])));
const x12 = (cast(u64, (arg1[14])) * cast(u64, (arg2[11])));
const x13 = (cast(u64, (arg1[14])) * cast(u64, (arg2[10])));
const x14 = (cast(u64, (arg1[13])) * cast(u64, (arg2[15])));
const x15 = (cast(u64, (arg1[13])) * cast(u64, (arg2[14])));
const x16 = (cast(u64, (arg1[13])) * cast(u64, (arg2[13])));
const x17 = (cast(u64, (arg1[13])) * cast(u64, (arg2[12])));
const x18 = (cast(u64, (arg1[13])) * cast(u64, (arg2[11])));
const x19 = (cast(u64, (arg1[12])) * cast(u64, (arg2[15])));
const x20 = (cast(u64, (arg1[12])) * cast(u64, (arg2[14])));
const x21 = (cast(u64, (arg1[12])) * cast(u64, (arg2[13])));
const x22 = (cast(u64, (arg1[12])) * cast(u64, (arg2[12])));
const x23 = (cast(u64, (arg1[11])) * cast(u64, (arg2[15])));
const x24 = (cast(u64, (arg1[11])) * cast(u64, (arg2[14])));
const x25 = (cast(u64, (arg1[11])) * cast(u64, (arg2[13])));
const x26 = (cast(u64, (arg1[10])) * cast(u64, (arg2[15])));
const x27 = (cast(u64, (arg1[10])) * cast(u64, (arg2[14])));
const x28 = (cast(u64, (arg1[9])) * cast(u64, (arg2[15])));
const x29 = (cast(u64, (arg1[15])) * cast(u64, (arg2[15])));
const x30 = (cast(u64, (arg1[15])) * cast(u64, (arg2[14])));
const x31 = (cast(u64, (arg1[15])) * cast(u64, (arg2[13])));
const x32 = (cast(u64, (arg1[15])) * cast(u64, (arg2[12])));
const x33 = (cast(u64, (arg1[15])) * cast(u64, (arg2[11])));
const x34 = (cast(u64, (arg1[15])) * cast(u64, (arg2[10])));
const x35 = (cast(u64, (arg1[15])) * cast(u64, (arg2[9])));
const x36 = (cast(u64, (arg1[14])) * cast(u64, (arg2[15])));
const x37 = (cast(u64, (arg1[14])) * cast(u64, (arg2[14])));
const x38 = (cast(u64, (arg1[14])) * cast(u64, (arg2[13])));
const x39 = (cast(u64, (arg1[14])) * cast(u64, (arg2[12])));
const x40 = (cast(u64, (arg1[14])) * cast(u64, (arg2[11])));
const x41 = (cast(u64, (arg1[14])) * cast(u64, (arg2[10])));
const x42 = (cast(u64, (arg1[13])) * cast(u64, (arg2[15])));
const x43 = (cast(u64, (arg1[13])) * cast(u64, (arg2[14])));
const x44 = (cast(u64, (arg1[13])) * cast(u64, (arg2[13])));
const x45 = (cast(u64, (arg1[13])) * cast(u64, (arg2[12])));
const x46 = (cast(u64, (arg1[13])) * cast(u64, (arg2[11])));
const x47 = (cast(u64, (arg1[12])) * cast(u64, (arg2[15])));
const x48 = (cast(u64, (arg1[12])) * cast(u64, (arg2[14])));
const x49 = (cast(u64, (arg1[12])) * cast(u64, (arg2[13])));
const x50 = (cast(u64, (arg1[12])) * cast(u64, (arg2[12])));
const x51 = (cast(u64, (arg1[11])) * cast(u64, (arg2[15])));
const x52 = (cast(u64, (arg1[11])) * cast(u64, (arg2[14])));
const x53 = (cast(u64, (arg1[11])) * cast(u64, (arg2[13])));
const x54 = (cast(u64, (arg1[10])) * cast(u64, (arg2[15])));
const x55 = (cast(u64, (arg1[10])) * cast(u64, (arg2[14])));
const x56 = (cast(u64, (arg1[9])) * cast(u64, (arg2[15])));
const x57 = (cast(u64, (arg1[15])) * cast(u64, (arg2[15])));
const x58 = (cast(u64, (arg1[15])) * cast(u64, (arg2[14])));
const x59 = (cast(u64, (arg1[15])) * cast(u64, (arg2[13])));
const x60 = (cast(u64, (arg1[15])) * cast(u64, (arg2[12])));
const x61 = (cast(u64, (arg1[15])) * cast(u64, (arg2[11])));
const x62 = (cast(u64, (arg1[15])) * cast(u64, (arg2[10])));
const x63 = (cast(u64, (arg1[15])) * cast(u64, (arg2[9])));
const x64 = (cast(u64, (arg1[15])) * cast(u64, (arg2[8])));
const x65 = (cast(u64, (arg1[15])) * cast(u64, (arg2[7])));
const x66 = (cast(u64, (arg1[15])) * cast(u64, (arg2[6])));
const x67 = (cast(u64, (arg1[15])) * cast(u64, (arg2[5])));
const x68 = (cast(u64, (arg1[15])) * cast(u64, (arg2[4])));
const x69 = (cast(u64, (arg1[15])) * cast(u64, (arg2[3])));
const x70 = (cast(u64, (arg1[15])) * cast(u64, (arg2[2])));
const x71 = (cast(u64, (arg1[15])) * cast(u64, (arg2[1])));
const x72 = (cast(u64, (arg1[14])) * cast(u64, (arg2[15])));
const x73 = (cast(u64, (arg1[14])) * cast(u64, (arg2[14])));
const x74 = (cast(u64, (arg1[14])) * cast(u64, (arg2[13])));
const x75 = (cast(u64, (arg1[14])) * cast(u64, (arg2[12])));
const x76 = (cast(u64, (arg1[14])) * cast(u64, (arg2[11])));
const x77 = (cast(u64, (arg1[14])) * cast(u64, (arg2[10])));
const x78 = (cast(u64, (arg1[14])) * cast(u64, (arg2[9])));
const x79 = (cast(u64, (arg1[14])) * cast(u64, (arg2[8])));
const x80 = (cast(u64, (arg1[14])) * cast(u64, (arg2[7])));
const x81 = (cast(u64, (arg1[14])) * cast(u64, (arg2[6])));
const x82 = (cast(u64, (arg1[14])) * cast(u64, (arg2[5])));
const x83 = (cast(u64, (arg1[14])) * cast(u64, (arg2[4])));
const x84 = (cast(u64, (arg1[14])) * cast(u64, (arg2[3])));
const x85 = (cast(u64, (arg1[14])) * cast(u64, (arg2[2])));
const x86 = (cast(u64, (arg1[13])) * cast(u64, (arg2[15])));
const x87 = (cast(u64, (arg1[13])) * cast(u64, (arg2[14])));
const x88 = (cast(u64, (arg1[13])) * cast(u64, (arg2[13])));
const x89 = (cast(u64, (arg1[13])) * cast(u64, (arg2[12])));
const x90 = (cast(u64, (arg1[13])) * cast(u64, (arg2[11])));
const x91 = (cast(u64, (arg1[13])) * cast(u64, (arg2[10])));
const x92 = (cast(u64, (arg1[13])) * cast(u64, (arg2[9])));
const x93 = (cast(u64, (arg1[13])) * cast(u64, (arg2[8])));
const x94 = (cast(u64, (arg1[13])) * cast(u64, (arg2[7])));
const x95 = (cast(u64, (arg1[13])) * cast(u64, (arg2[6])));
const x96 = (cast(u64, (arg1[13])) * cast(u64, (arg2[5])));
const x97 = (cast(u64, (arg1[13])) * cast(u64, (arg2[4])));
const x98 = (cast(u64, (arg1[13])) * cast(u64, (arg2[3])));
const x99 = (cast(u64, (arg1[12])) * cast(u64, (arg2[15])));
const x100 = (cast(u64, (arg1[12])) * cast(u64, (arg2[14])));
const x101 = (cast(u64, (arg1[12])) * cast(u64, (arg2[13])));
const x102 = (cast(u64, (arg1[12])) * cast(u64, (arg2[12])));
const x103 = (cast(u64, (arg1[12])) * cast(u64, (arg2[11])));
const x104 = (cast(u64, (arg1[12])) * cast(u64, (arg2[10])));
const x105 = (cast(u64, (arg1[12])) * cast(u64, (arg2[9])));
const x106 = (cast(u64, (arg1[12])) * cast(u64, (arg2[8])));
const x107 = (cast(u64, (arg1[12])) * cast(u64, (arg2[7])));
const x108 = (cast(u64, (arg1[12])) * cast(u64, (arg2[6])));
const x109 = (cast(u64, (arg1[12])) * cast(u64, (arg2[5])));
const x110 = (cast(u64, (arg1[12])) * cast(u64, (arg2[4])));
const x111 = (cast(u64, (arg1[11])) * cast(u64, (arg2[15])));
const x112 = (cast(u64, (arg1[11])) * cast(u64, (arg2[14])));
const x113 = (cast(u64, (arg1[11])) * cast(u64, (arg2[13])));
const x114 = (cast(u64, (arg1[11])) * cast(u64, (arg2[12])));
const x115 = (cast(u64, (arg1[11])) * cast(u64, (arg2[11])));
const x116 = (cast(u64, (arg1[11])) * cast(u64, (arg2[10])));
const x117 = (cast(u64, (arg1[11])) * cast(u64, (arg2[9])));
const x118 = (cast(u64, (arg1[11])) * cast(u64, (arg2[8])));
const x119 = (cast(u64, (arg1[11])) * cast(u64, (arg2[7])));
const x120 = (cast(u64, (arg1[11])) * cast(u64, (arg2[6])));
const x121 = (cast(u64, (arg1[11])) * cast(u64, (arg2[5])));
const x122 = (cast(u64, (arg1[10])) * cast(u64, (arg2[15])));
const x123 = (cast(u64, (arg1[10])) * cast(u64, (arg2[14])));
const x124 = (cast(u64, (arg1[10])) * cast(u64, (arg2[13])));
const x125 = (cast(u64, (arg1[10])) * cast(u64, (arg2[12])));
const x126 = (cast(u64, (arg1[10])) * cast(u64, (arg2[11])));
const x127 = (cast(u64, (arg1[10])) * cast(u64, (arg2[10])));
const x128 = (cast(u64, (arg1[10])) * cast(u64, (arg2[9])));
const x129 = (cast(u64, (arg1[10])) * cast(u64, (arg2[8])));
const x130 = (cast(u64, (arg1[10])) * cast(u64, (arg2[7])));
const x131 = (cast(u64, (arg1[10])) * cast(u64, (arg2[6])));
const x132 = (cast(u64, (arg1[9])) * cast(u64, (arg2[15])));
const x133 = (cast(u64, (arg1[9])) * cast(u64, (arg2[14])));
const x134 = (cast(u64, (arg1[9])) * cast(u64, (arg2[13])));
const x135 = (cast(u64, (arg1[9])) * cast(u64, (arg2[12])));
const x136 = (cast(u64, (arg1[9])) * cast(u64, (arg2[11])));
const x137 = (cast(u64, (arg1[9])) * cast(u64, (arg2[10])));
const x138 = (cast(u64, (arg1[9])) * cast(u64, (arg2[9])));
const x139 = (cast(u64, (arg1[9])) * cast(u64, (arg2[8])));
const x140 = (cast(u64, (arg1[9])) * cast(u64, (arg2[7])));
const x141 = (cast(u64, (arg1[8])) * cast(u64, (arg2[15])));
const x142 = (cast(u64, (arg1[8])) * cast(u64, (arg2[14])));
const x143 = (cast(u64, (arg1[8])) * cast(u64, (arg2[13])));
const x144 = (cast(u64, (arg1[8])) * cast(u64, (arg2[12])));
const x145 = (cast(u64, (arg1[8])) * cast(u64, (arg2[11])));
const x146 = (cast(u64, (arg1[8])) * cast(u64, (arg2[10])));
const x147 = (cast(u64, (arg1[8])) * cast(u64, (arg2[9])));
const x148 = (cast(u64, (arg1[8])) * cast(u64, (arg2[8])));
const x149 = (cast(u64, (arg1[7])) * cast(u64, (arg2[15])));
const x150 = (cast(u64, (arg1[7])) * cast(u64, (arg2[14])));
const x151 = (cast(u64, (arg1[7])) * cast(u64, (arg2[13])));
const x152 = (cast(u64, (arg1[7])) * cast(u64, (arg2[12])));
const x153 = (cast(u64, (arg1[7])) * cast(u64, (arg2[11])));
const x154 = (cast(u64, (arg1[7])) * cast(u64, (arg2[10])));
const x155 = (cast(u64, (arg1[7])) * cast(u64, (arg2[9])));
const x156 = (cast(u64, (arg1[6])) * cast(u64, (arg2[15])));
const x157 = (cast(u64, (arg1[6])) * cast(u64, (arg2[14])));
const x158 = (cast(u64, (arg1[6])) * cast(u64, (arg2[13])));
const x159 = (cast(u64, (arg1[6])) * cast(u64, (arg2[12])));
const x160 = (cast(u64, (arg1[6])) * cast(u64, (arg2[11])));
const x161 = (cast(u64, (arg1[6])) * cast(u64, (arg2[10])));
const x162 = (cast(u64, (arg1[5])) * cast(u64, (arg2[15])));
const x163 = (cast(u64, (arg1[5])) * cast(u64, (arg2[14])));
const x164 = (cast(u64, (arg1[5])) * cast(u64, (arg2[13])));
const x165 = (cast(u64, (arg1[5])) * cast(u64, (arg2[12])));
const x166 = (cast(u64, (arg1[5])) * cast(u64, (arg2[11])));
const x167 = (cast(u64, (arg1[4])) * cast(u64, (arg2[15])));
const x168 = (cast(u64, (arg1[4])) * cast(u64, (arg2[14])));
const x169 = (cast(u64, (arg1[4])) * cast(u64, (arg2[13])));
const x170 = (cast(u64, (arg1[4])) * cast(u64, (arg2[12])));
const x171 = (cast(u64, (arg1[3])) * cast(u64, (arg2[15])));
const x172 = (cast(u64, (arg1[3])) * cast(u64, (arg2[14])));
const x173 = (cast(u64, (arg1[3])) * cast(u64, (arg2[13])));
const x174 = (cast(u64, (arg1[2])) * cast(u64, (arg2[15])));
const x175 = (cast(u64, (arg1[2])) * cast(u64, (arg2[14])));
const x176 = (cast(u64, (arg1[1])) * cast(u64, (arg2[15])));
const x177 = (cast(u64, (arg1[15])) * cast(u64, (arg2[8])));
const x178 = (cast(u64, (arg1[15])) * cast(u64, (arg2[7])));
const x179 = (cast(u64, (arg1[15])) * cast(u64, (arg2[6])));
const x180 = (cast(u64, (arg1[15])) * cast(u64, (arg2[5])));
const x181 = (cast(u64, (arg1[15])) * cast(u64, (arg2[4])));
const x182 = (cast(u64, (arg1[15])) * cast(u64, (arg2[3])));
const x183 = (cast(u64, (arg1[15])) * cast(u64, (arg2[2])));
const x184 = (cast(u64, (arg1[15])) * cast(u64, (arg2[1])));
const x185 = (cast(u64, (arg1[14])) * cast(u64, (arg2[9])));
const x186 = (cast(u64, (arg1[14])) * cast(u64, (arg2[8])));
const x187 = (cast(u64, (arg1[14])) * cast(u64, (arg2[7])));
const x188 = (cast(u64, (arg1[14])) * cast(u64, (arg2[6])));
const x189 = (cast(u64, (arg1[14])) * cast(u64, (arg2[5])));
const x190 = (cast(u64, (arg1[14])) * cast(u64, (arg2[4])));
const x191 = (cast(u64, (arg1[14])) * cast(u64, (arg2[3])));
const x192 = (cast(u64, (arg1[14])) * cast(u64, (arg2[2])));
const x193 = (cast(u64, (arg1[13])) * cast(u64, (arg2[10])));
const x194 = (cast(u64, (arg1[13])) * cast(u64, (arg2[9])));
const x195 = (cast(u64, (arg1[13])) * cast(u64, (arg2[8])));
const x196 = (cast(u64, (arg1[13])) * cast(u64, (arg2[7])));
const x197 = (cast(u64, (arg1[13])) * cast(u64, (arg2[6])));
const x198 = (cast(u64, (arg1[13])) * cast(u64, (arg2[5])));
const x199 = (cast(u64, (arg1[13])) * cast(u64, (arg2[4])));
const x200 = (cast(u64, (arg1[13])) * cast(u64, (arg2[3])));
const x201 = (cast(u64, (arg1[12])) * cast(u64, (arg2[11])));
const x202 = (cast(u64, (arg1[12])) * cast(u64, (arg2[10])));
const x203 = (cast(u64, (arg1[12])) * cast(u64, (arg2[9])));
const x204 = (cast(u64, (arg1[12])) * cast(u64, (arg2[8])));
const x205 = (cast(u64, (arg1[12])) * cast(u64, (arg2[7])));
const x206 = (cast(u64, (arg1[12])) * cast(u64, (arg2[6])));
const x207 = (cast(u64, (arg1[12])) * cast(u64, (arg2[5])));
const x208 = (cast(u64, (arg1[12])) * cast(u64, (arg2[4])));
const x209 = (cast(u64, (arg1[11])) * cast(u64, (arg2[12])));
const x210 = (cast(u64, (arg1[11])) * cast(u64, (arg2[11])));
const x211 = (cast(u64, (arg1[11])) * cast(u64, (arg2[10])));
const x212 = (cast(u64, (arg1[11])) * cast(u64, (arg2[9])));
const x213 = (cast(u64, (arg1[11])) * cast(u64, (arg2[8])));
const x214 = (cast(u64, (arg1[11])) * cast(u64, (arg2[7])));
const x215 = (cast(u64, (arg1[11])) * cast(u64, (arg2[6])));
const x216 = (cast(u64, (arg1[11])) * cast(u64, (arg2[5])));
const x217 = (cast(u64, (arg1[10])) * cast(u64, (arg2[13])));
const x218 = (cast(u64, (arg1[10])) * cast(u64, (arg2[12])));
const x219 = (cast(u64, (arg1[10])) * cast(u64, (arg2[11])));
const x220 = (cast(u64, (arg1[10])) * cast(u64, (arg2[10])));
const x221 = (cast(u64, (arg1[10])) * cast(u64, (arg2[9])));
const x222 = (cast(u64, (arg1[10])) * cast(u64, (arg2[8])));
const x223 = (cast(u64, (arg1[10])) * cast(u64, (arg2[7])));
const x224 = (cast(u64, (arg1[10])) * cast(u64, (arg2[6])));
const x225 = (cast(u64, (arg1[9])) * cast(u64, (arg2[14])));
const x226 = (cast(u64, (arg1[9])) * cast(u64, (arg2[13])));
const x227 = (cast(u64, (arg1[9])) * cast(u64, (arg2[12])));
const x228 = (cast(u64, (arg1[9])) * cast(u64, (arg2[11])));
const x229 = (cast(u64, (arg1[9])) * cast(u64, (arg2[10])));
const x230 = (cast(u64, (arg1[9])) * cast(u64, (arg2[9])));
const x231 = (cast(u64, (arg1[9])) * cast(u64, (arg2[8])));
const x232 = (cast(u64, (arg1[9])) * cast(u64, (arg2[7])));
const x233 = (cast(u64, (arg1[8])) * cast(u64, (arg2[15])));
const x234 = (cast(u64, (arg1[8])) * cast(u64, (arg2[14])));
const x235 = (cast(u64, (arg1[8])) * cast(u64, (arg2[13])));
const x236 = (cast(u64, (arg1[8])) * cast(u64, (arg2[12])));
const x237 = (cast(u64, (arg1[8])) * cast(u64, (arg2[11])));
const x238 = (cast(u64, (arg1[8])) * cast(u64, (arg2[10])));
const x239 = (cast(u64, (arg1[8])) * cast(u64, (arg2[9])));
const x240 = (cast(u64, (arg1[8])) * cast(u64, (arg2[8])));
const x241 = (cast(u64, (arg1[7])) * cast(u64, (arg2[15])));
const x242 = (cast(u64, (arg1[7])) * cast(u64, (arg2[14])));
const x243 = (cast(u64, (arg1[7])) * cast(u64, (arg2[13])));
const x244 = (cast(u64, (arg1[7])) * cast(u64, (arg2[12])));
const x245 = (cast(u64, (arg1[7])) * cast(u64, (arg2[11])));
const x246 = (cast(u64, (arg1[7])) * cast(u64, (arg2[10])));
const x247 = (cast(u64, (arg1[7])) * cast(u64, (arg2[9])));
const x248 = (cast(u64, (arg1[6])) * cast(u64, (arg2[15])));
const x249 = (cast(u64, (arg1[6])) * cast(u64, (arg2[14])));
const x250 = (cast(u64, (arg1[6])) * cast(u64, (arg2[13])));
const x251 = (cast(u64, (arg1[6])) * cast(u64, (arg2[12])));
const x252 = (cast(u64, (arg1[6])) * cast(u64, (arg2[11])));
const x253 = (cast(u64, (arg1[6])) * cast(u64, (arg2[10])));
const x254 = (cast(u64, (arg1[5])) * cast(u64, (arg2[15])));
const x255 = (cast(u64, (arg1[5])) * cast(u64, (arg2[14])));
const x256 = (cast(u64, (arg1[5])) * cast(u64, (arg2[13])));
const x257 = (cast(u64, (arg1[5])) * cast(u64, (arg2[12])));
const x258 = (cast(u64, (arg1[5])) * cast(u64, (arg2[11])));
const x259 = (cast(u64, (arg1[4])) * cast(u64, (arg2[15])));
const x260 = (cast(u64, (arg1[4])) * cast(u64, (arg2[14])));
const x261 = (cast(u64, (arg1[4])) * cast(u64, (arg2[13])));
const x262 = (cast(u64, (arg1[4])) * cast(u64, (arg2[12])));
const x263 = (cast(u64, (arg1[3])) * cast(u64, (arg2[15])));
const x264 = (cast(u64, (arg1[3])) * cast(u64, (arg2[14])));
const x265 = (cast(u64, (arg1[3])) * cast(u64, (arg2[13])));
const x266 = (cast(u64, (arg1[2])) * cast(u64, (arg2[15])));
const x267 = (cast(u64, (arg1[2])) * cast(u64, (arg2[14])));
const x268 = (cast(u64, (arg1[1])) * cast(u64, (arg2[15])));
const x269 = (cast(u64, (arg1[15])) * cast(u64, (arg2[0])));
const x270 = (cast(u64, (arg1[14])) * cast(u64, (arg2[1])));
const x271 = (cast(u64, (arg1[14])) * cast(u64, (arg2[0])));
const x272 = (cast(u64, (arg1[13])) * cast(u64, (arg2[2])));
const x273 = (cast(u64, (arg1[13])) * cast(u64, (arg2[1])));
const x274 = (cast(u64, (arg1[13])) * cast(u64, (arg2[0])));
const x275 = (cast(u64, (arg1[12])) * cast(u64, (arg2[3])));
const x276 = (cast(u64, (arg1[12])) * cast(u64, (arg2[2])));
const x277 = (cast(u64, (arg1[12])) * cast(u64, (arg2[1])));
const x278 = (cast(u64, (arg1[12])) * cast(u64, (arg2[0])));
const x279 = (cast(u64, (arg1[11])) * cast(u64, (arg2[4])));
const x280 = (cast(u64, (arg1[11])) * cast(u64, (arg2[3])));
const x281 = (cast(u64, (arg1[11])) * cast(u64, (arg2[2])));
const x282 = (cast(u64, (arg1[11])) * cast(u64, (arg2[1])));
const x283 = (cast(u64, (arg1[11])) * cast(u64, (arg2[0])));
const x284 = (cast(u64, (arg1[10])) * cast(u64, (arg2[5])));
const x285 = (cast(u64, (arg1[10])) * cast(u64, (arg2[4])));
const x286 = (cast(u64, (arg1[10])) * cast(u64, (arg2[3])));
const x287 = (cast(u64, (arg1[10])) * cast(u64, (arg2[2])));
const x288 = (cast(u64, (arg1[10])) * cast(u64, (arg2[1])));
const x289 = (cast(u64, (arg1[10])) * cast(u64, (arg2[0])));
const x290 = (cast(u64, (arg1[9])) * cast(u64, (arg2[6])));
const x291 = (cast(u64, (arg1[9])) * cast(u64, (arg2[5])));
const x292 = (cast(u64, (arg1[9])) * cast(u64, (arg2[4])));
const x293 = (cast(u64, (arg1[9])) * cast(u64, (arg2[3])));
const x294 = (cast(u64, (arg1[9])) * cast(u64, (arg2[2])));
const x295 = (cast(u64, (arg1[9])) * cast(u64, (arg2[1])));
const x296 = (cast(u64, (arg1[9])) * cast(u64, (arg2[0])));
const x297 = (cast(u64, (arg1[8])) * cast(u64, (arg2[7])));
const x298 = (cast(u64, (arg1[8])) * cast(u64, (arg2[6])));
const x299 = (cast(u64, (arg1[8])) * cast(u64, (arg2[5])));
const x300 = (cast(u64, (arg1[8])) * cast(u64, (arg2[4])));
const x301 = (cast(u64, (arg1[8])) * cast(u64, (arg2[3])));
const x302 = (cast(u64, (arg1[8])) * cast(u64, (arg2[2])));
const x303 = (cast(u64, (arg1[8])) * cast(u64, (arg2[1])));
const x304 = (cast(u64, (arg1[8])) * cast(u64, (arg2[0])));
const x305 = (cast(u64, (arg1[7])) * cast(u64, (arg2[8])));
const x306 = (cast(u64, (arg1[7])) * cast(u64, (arg2[7])));
const x307 = (cast(u64, (arg1[7])) * cast(u64, (arg2[6])));
const x308 = (cast(u64, (arg1[7])) * cast(u64, (arg2[5])));
const x309 = (cast(u64, (arg1[7])) * cast(u64, (arg2[4])));
const x310 = (cast(u64, (arg1[7])) * cast(u64, (arg2[3])));
const x311 = (cast(u64, (arg1[7])) * cast(u64, (arg2[2])));
const x312 = (cast(u64, (arg1[7])) * cast(u64, (arg2[1])));
const x313 = (cast(u64, (arg1[7])) * cast(u64, (arg2[0])));
const x314 = (cast(u64, (arg1[6])) * cast(u64, (arg2[9])));
const x315 = (cast(u64, (arg1[6])) * cast(u64, (arg2[8])));
const x316 = (cast(u64, (arg1[6])) * cast(u64, (arg2[7])));
const x317 = (cast(u64, (arg1[6])) * cast(u64, (arg2[6])));
const x318 = (cast(u64, (arg1[6])) * cast(u64, (arg2[5])));
const x319 = (cast(u64, (arg1[6])) * cast(u64, (arg2[4])));
const x320 = (cast(u64, (arg1[6])) * cast(u64, (arg2[3])));
const x321 = (cast(u64, (arg1[6])) * cast(u64, (arg2[2])));
const x322 = (cast(u64, (arg1[6])) * cast(u64, (arg2[1])));
const x323 = (cast(u64, (arg1[6])) * cast(u64, (arg2[0])));
const x324 = (cast(u64, (arg1[5])) * cast(u64, (arg2[10])));
const x325 = (cast(u64, (arg1[5])) * cast(u64, (arg2[9])));
const x326 = (cast(u64, (arg1[5])) * cast(u64, (arg2[8])));
const x327 = (cast(u64, (arg1[5])) * cast(u64, (arg2[7])));
const x328 = (cast(u64, (arg1[5])) * cast(u64, (arg2[6])));
const x329 = (cast(u64, (arg1[5])) * cast(u64, (arg2[5])));
const x330 = (cast(u64, (arg1[5])) * cast(u64, (arg2[4])));
const x331 = (cast(u64, (arg1[5])) * cast(u64, (arg2[3])));
const x332 = (cast(u64, (arg1[5])) * cast(u64, (arg2[2])));
const x333 = (cast(u64, (arg1[5])) * cast(u64, (arg2[1])));
const x334 = (cast(u64, (arg1[5])) * cast(u64, (arg2[0])));
const x335 = (cast(u64, (arg1[4])) * cast(u64, (arg2[11])));
const x336 = (cast(u64, (arg1[4])) * cast(u64, (arg2[10])));
const x337 = (cast(u64, (arg1[4])) * cast(u64, (arg2[9])));
const x338 = (cast(u64, (arg1[4])) * cast(u64, (arg2[8])));
const x339 = (cast(u64, (arg1[4])) * cast(u64, (arg2[7])));
const x340 = (cast(u64, (arg1[4])) * cast(u64, (arg2[6])));
const x341 = (cast(u64, (arg1[4])) * cast(u64, (arg2[5])));
const x342 = (cast(u64, (arg1[4])) * cast(u64, (arg2[4])));
const x343 = (cast(u64, (arg1[4])) * cast(u64, (arg2[3])));
const x344 = (cast(u64, (arg1[4])) * cast(u64, (arg2[2])));
const x345 = (cast(u64, (arg1[4])) * cast(u64, (arg2[1])));
const x346 = (cast(u64, (arg1[4])) * cast(u64, (arg2[0])));
const x347 = (cast(u64, (arg1[3])) * cast(u64, (arg2[12])));
const x348 = (cast(u64, (arg1[3])) * cast(u64, (arg2[11])));
const x349 = (cast(u64, (arg1[3])) * cast(u64, (arg2[10])));
const x350 = (cast(u64, (arg1[3])) * cast(u64, (arg2[9])));
const x351 = (cast(u64, (arg1[3])) * cast(u64, (arg2[8])));
const x352 = (cast(u64, (arg1[3])) * cast(u64, (arg2[7])));
const x353 = (cast(u64, (arg1[3])) * cast(u64, (arg2[6])));
const x354 = (cast(u64, (arg1[3])) * cast(u64, (arg2[5])));
const x355 = (cast(u64, (arg1[3])) * cast(u64, (arg2[4])));
const x356 = (cast(u64, (arg1[3])) * cast(u64, (arg2[3])));
const x357 = (cast(u64, (arg1[3])) * cast(u64, (arg2[2])));
const x358 = (cast(u64, (arg1[3])) * cast(u64, (arg2[1])));
const x359 = (cast(u64, (arg1[3])) * cast(u64, (arg2[0])));
const x360 = (cast(u64, (arg1[2])) * cast(u64, (arg2[13])));
const x361 = (cast(u64, (arg1[2])) * cast(u64, (arg2[12])));
const x362 = (cast(u64, (arg1[2])) * cast(u64, (arg2[11])));
const x363 = (cast(u64, (arg1[2])) * cast(u64, (arg2[10])));
const x364 = (cast(u64, (arg1[2])) * cast(u64, (arg2[9])));
const x365 = (cast(u64, (arg1[2])) * cast(u64, (arg2[8])));
const x366 = (cast(u64, (arg1[2])) * cast(u64, (arg2[7])));
const x367 = (cast(u64, (arg1[2])) * cast(u64, (arg2[6])));
const x368 = (cast(u64, (arg1[2])) * cast(u64, (arg2[5])));
const x369 = (cast(u64, (arg1[2])) * cast(u64, (arg2[4])));
const x370 = (cast(u64, (arg1[2])) * cast(u64, (arg2[3])));
const x371 = (cast(u64, (arg1[2])) * cast(u64, (arg2[2])));
const x372 = (cast(u64, (arg1[2])) * cast(u64, (arg2[1])));
const x373 = (cast(u64, (arg1[2])) * cast(u64, (arg2[0])));
const x374 = (cast(u64, (arg1[1])) * cast(u64, (arg2[14])));
const x375 = (cast(u64, (arg1[1])) * cast(u64, (arg2[13])));
const x376 = (cast(u64, (arg1[1])) * cast(u64, (arg2[12])));
const x377 = (cast(u64, (arg1[1])) * cast(u64, (arg2[11])));
const x378 = (cast(u64, (arg1[1])) * cast(u64, (arg2[10])));
const x379 = (cast(u64, (arg1[1])) * cast(u64, (arg2[9])));
const x380 = (cast(u64, (arg1[1])) * cast(u64, (arg2[8])));
const x381 = (cast(u64, (arg1[1])) * cast(u64, (arg2[7])));
const x382 = (cast(u64, (arg1[1])) * cast(u64, (arg2[6])));
const x383 = (cast(u64, (arg1[1])) * cast(u64, (arg2[5])));
const x384 = (cast(u64, (arg1[1])) * cast(u64, (arg2[4])));
const x385 = (cast(u64, (arg1[1])) * cast(u64, (arg2[3])));
const x386 = (cast(u64, (arg1[1])) * cast(u64, (arg2[2])));
const x387 = (cast(u64, (arg1[1])) * cast(u64, (arg2[1])));
const x388 = (cast(u64, (arg1[1])) * cast(u64, (arg2[0])));
const x389 = (cast(u64, (arg1[0])) * cast(u64, (arg2[15])));
const x390 = (cast(u64, (arg1[0])) * cast(u64, (arg2[14])));
const x391 = (cast(u64, (arg1[0])) * cast(u64, (arg2[13])));
const x392 = (cast(u64, (arg1[0])) * cast(u64, (arg2[12])));
const x393 = (cast(u64, (arg1[0])) * cast(u64, (arg2[11])));
const x394 = (cast(u64, (arg1[0])) * cast(u64, (arg2[10])));
const x395 = (cast(u64, (arg1[0])) * cast(u64, (arg2[9])));
const x396 = (cast(u64, (arg1[0])) * cast(u64, (arg2[8])));
const x397 = (cast(u64, (arg1[0])) * cast(u64, (arg2[7])));
const x398 = (cast(u64, (arg1[0])) * cast(u64, (arg2[6])));
const x399 = (cast(u64, (arg1[0])) * cast(u64, (arg2[5])));
const x400 = (cast(u64, (arg1[0])) * cast(u64, (arg2[4])));
const x401 = (cast(u64, (arg1[0])) * cast(u64, (arg2[3])));
const x402 = (cast(u64, (arg1[0])) * cast(u64, (arg2[2])));
const x403 = (cast(u64, (arg1[0])) * cast(u64, (arg2[1])));
const x404 = (cast(u64, (arg1[0])) * cast(u64, (arg2[0])));
const x405 = (x397 + (x382 + (x368 + (x355 + (x343 + (x332 + (x322 + (x313 + (x141 + (x133 + (x124 + (x114 + (x103 + (x91 + (x78 + x64)))))))))))))));
const x406 = (x405 >> 28);
const x407 = cast(u32, (x405 & cast(u64, 0xfffffff)));
const x408 = (x389 + (x374 + (x360 + (x347 + (x335 + (x324 + (x314 + (x305 + (x297 + (x290 + (x284 + (x279 + (x275 + (x272 + (x270 + (x269 + (x233 + (x225 + (x217 + (x209 + (x201 + (x193 + (x185 + x177)))))))))))))))))))))));
const x409 = (x390 + (x375 + (x361 + (x348 + (x336 + (x325 + (x315 + (x306 + (x298 + (x291 + (x285 + (x280 + (x276 + (x273 + (x271 + (x241 + (x234 + (x226 + (x218 + (x210 + (x202 + (x194 + (x186 + (x178 + (x57 + x29)))))))))))))))))))))))));
const x410 = (x391 + (x376 + (x362 + (x349 + (x337 + (x326 + (x316 + (x307 + (x299 + (x292 + (x286 + (x281 + (x277 + (x274 + (x248 + (x242 + (x235 + (x227 + (x219 + (x211 + (x203 + (x195 + (x187 + (x179 + (x72 + (x58 + (x36 + x30)))))))))))))))))))))))))));
const x411 = (cast(u128, x392) + (cast(u128, x377) + cast(u128, (x363 + (x350 + (x338 + (x327 + (x317 + (x308 + (x300 + (x293 + (x287 + (x282 + (x278 + (x254 + (x249 + (x243 + (x236 + (x228 + (x220 + (x212 + (x204 + (x196 + (x188 + (x180 + (x86 + (x73 + (x59 + (x42 + (x37 + x31))))))))))))))))))))))))))))));
const x412 = (cast(u128, x393) + (cast(u128, x378) + (cast(u128, x364) + (cast(u128, x351) + cast(u128, (x339 + (x328 + (x318 + (x309 + (x301 + (x294 + (x288 + (x283 + (x259 + (x255 + (x250 + (x244 + (x237 + (x229 + (x221 + (x213 + (x205 + (x197 + (x189 + (x181 + (x99 + (x87 + (x74 + (x60 + (x47 + (x43 + (x38 + x32))))))))))))))))))))))))))))))));
const x413 = (cast(u128, x394) + (cast(u128, x379) + (cast(u128, x365) + (cast(u128, x352) + (cast(u128, x340) + (cast(u128, x329) + cast(u128, (x319 + (x310 + (x302 + (x295 + (x289 + (x263 + (x260 + (x256 + (x251 + (x245 + (x238 + (x230 + (x222 + (x214 + (x206 + (x198 + (x190 + (x182 + (x111 + (x100 + (x88 + (x75 + (x61 + (x51 + (x48 + (x44 + (x39 + x33))))))))))))))))))))))))))))))))));
const x414 = (cast(u128, x395) + (cast(u128, x380) + (cast(u128, x366) + (cast(u128, x353) + (cast(u128, x341) + (cast(u128, x330) + (cast(u128, x320) + (cast(u128, x311) + cast(u128, (x303 + (x296 + (x266 + (x264 + (x261 + (x257 + (x252 + (x246 + (x239 + (x231 + (x223 + (x215 + (x207 + (x199 + (x191 + (x183 + (x122 + (x112 + (x101 + (x89 + (x76 + (x62 + (x54 + (x52 + (x49 + (x45 + (x40 + x34))))))))))))))))))))))))))))))))))));
const x415 = (cast(u128, x396) + (cast(u128, x381) + (cast(u128, x367) + (cast(u128, x354) + (cast(u128, x342) + (cast(u128, x331) + (cast(u128, x321) + (cast(u128, x312) + (cast(u128, x304) + (cast(u128, x268) + cast(u128, (x267 + (x265 + (x262 + (x258 + (x253 + (x247 + (x240 + (x232 + (x224 + (x216 + (x208 + (x200 + (x192 + (x184 + (x132 + (x123 + (x113 + (x102 + (x90 + (x77 + (x63 + (x56 + (x55 + (x53 + (x50 + (x46 + (x41 + x35))))))))))))))))))))))))))))))))))))));
const x416 = (x398 + (x383 + (x369 + (x356 + (x344 + (x333 + (x323 + (x149 + (x142 + (x134 + (x125 + (x115 + (x104 + (x92 + (x79 + (x65 + x1))))))))))))))));
const x417 = (x399 + (x384 + (x370 + (x357 + (x345 + (x334 + (x156 + (x150 + (x143 + (x135 + (x126 + (x116 + (x105 + (x93 + (x80 + (x66 + (x8 + x2)))))))))))))))));
const x418 = (x400 + (x385 + (x371 + (x358 + (x346 + (x162 + (x157 + (x151 + (x144 + (x136 + (x127 + (x117 + (x106 + (x94 + (x81 + (x67 + (x14 + (x9 + x3))))))))))))))))));
const x419 = (x401 + (x386 + (x372 + (x359 + (x167 + (x163 + (x158 + (x152 + (x145 + (x137 + (x128 + (x118 + (x107 + (x95 + (x82 + (x68 + (x19 + (x15 + (x10 + x4)))))))))))))))))));
const x420 = (x402 + (x387 + (x373 + (x171 + (x168 + (x164 + (x159 + (x153 + (x146 + (x138 + (x129 + (x119 + (x108 + (x96 + (x83 + (x69 + (x23 + (x20 + (x16 + (x11 + x5))))))))))))))))))));
const x421 = (x403 + (x388 + (x174 + (x172 + (x169 + (x165 + (x160 + (x154 + (x147 + (x139 + (x130 + (x120 + (x109 + (x97 + (x84 + (x70 + (x26 + (x24 + (x21 + (x17 + (x12 + x6)))))))))))))))))))));
const x422 = (x404 + (x176 + (x175 + (x173 + (x170 + (x166 + (x161 + (x155 + (x148 + (x140 + (x131 + (x121 + (x110 + (x98 + (x85 + (x71 + (x28 + (x27 + (x25 + (x22 + (x18 + (x13 + x7))))))))))))))))))))));
const x423 = (cast(u128, x406) + x415);
const x424 = (x408 >> 28);
const x425 = cast(u32, (x408 & cast(u64, 0xfffffff)));
const x426 = (x423 + cast(u128, x424));
const x427 = cast(u64, (x426 >> 28));
const x428 = cast(u32, (x426 & cast(u128, 0xfffffff)));
const x429 = (x422 + x424);
const x430 = (cast(u128, x427) + x414);
const x431 = (x429 >> 28);
const x432 = cast(u32, (x429 & cast(u64, 0xfffffff)));
const x433 = (x431 + x421);
const x434 = cast(u64, (x430 >> 28));
const x435 = cast(u32, (x430 & cast(u128, 0xfffffff)));
const x436 = (cast(u128, x434) + x413);
const x437 = (x433 >> 28);
const x438 = cast(u32, (x433 & cast(u64, 0xfffffff)));
const x439 = (x437 + x420);
const x440 = cast(u64, (x436 >> 28));
const x441 = cast(u32, (x436 & cast(u128, 0xfffffff)));
const x442 = (cast(u128, x440) + x412);
const x443 = (x439 >> 28);
const x444 = cast(u32, (x439 & cast(u64, 0xfffffff)));
const x445 = (x443 + x419);
const x446 = cast(u64, (x442 >> 28));
const x447 = cast(u32, (x442 & cast(u128, 0xfffffff)));
const x448 = (cast(u128, x446) + x411);
const x449 = (x445 >> 28);
const x450 = cast(u32, (x445 & cast(u64, 0xfffffff)));
const x451 = (x449 + x418);
const x452 = cast(u64, (x448 >> 28));
const x453 = cast(u32, (x448 & cast(u128, 0xfffffff)));
const x454 = (x452 + x410);
const x455 = (x451 >> 28);
const x456 = cast(u32, (x451 & cast(u64, 0xfffffff)));
const x457 = (x455 + x417);
const x458 = (x454 >> 28);
const x459 = cast(u32, (x454 & cast(u64, 0xfffffff)));
const x460 = (x458 + x409);
const x461 = (x457 >> 28);
const x462 = cast(u32, (x457 & cast(u64, 0xfffffff)));
const x463 = (x461 + x416);
const x464 = (x460 >> 28);
const x465 = cast(u32, (x460 & cast(u64, 0xfffffff)));
const x466 = (x464 + cast(u64, x425));
const x467 = (x463 >> 28);
const x468 = cast(u32, (x463 & cast(u64, 0xfffffff)));
const x469 = (x467 + cast(u64, x407));
const x470 = cast(u32, (x466 >> 28));
const x471 = cast(u32, (x466 & cast(u64, 0xfffffff)));
const x472 = cast(u32, (x469 >> 28));
const x473 = cast(u32, (x469 & cast(u64, 0xfffffff)));
const x474 = (x428 + x470);
const x475 = (x432 + x470);
const x476 = (x472 + x474);
const x477 = cast(u1, (x476 >> 28));
const x478 = (x476 & 0xfffffff);
const x479 = (cast(u32, x477) + x435);
const x480 = cast(u1, (x475 >> 28));
const x481 = (x475 & 0xfffffff);
const x482 = (cast(u32, x480) + x438);
out1[0] = x481;
out1[1] = x482;
out1[2] = x444;
out1[3] = x450;
out1[4] = x456;
out1[5] = x462;
out1[6] = x468;
out1[7] = x473;
out1[8] = x478;
out1[9] = x479;
out1[10] = x441;
out1[11] = x447;
out1[12] = x453;
out1[13] = x459;
out1[14] = x465;
out1[15] = x471;
}
/// The function carrySquare squares a field element and reduces the result.
/// Postconditions:
/// eval out1 mod m = (eval arg1 * eval arg1) mod m
///
/// Input Bounds:
/// arg1: [[0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000]]
/// Output Bounds:
/// out1: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
pub fn carrySquare(out1: *[16]u32, arg1: [16]u32) void {
@setRuntimeSafety(mode == .Debug);
const x1 = (arg1[15]);
const x2 = (arg1[15]);
const x3 = (x1 * 0x2);
const x4 = (x2 * 0x2);
const x5 = ((arg1[15]) * 0x2);
const x6 = (arg1[14]);
const x7 = (arg1[14]);
const x8 = (x6 * 0x2);
const x9 = (x7 * 0x2);
const x10 = ((arg1[14]) * 0x2);
const x11 = (arg1[13]);
const x12 = (arg1[13]);
const x13 = (x11 * 0x2);
const x14 = (x12 * 0x2);
const x15 = ((arg1[13]) * 0x2);
const x16 = (arg1[12]);
const x17 = (arg1[12]);
const x18 = (x16 * 0x2);
const x19 = (x17 * 0x2);
const x20 = ((arg1[12]) * 0x2);
const x21 = (arg1[11]);
const x22 = (arg1[11]);
const x23 = (x21 * 0x2);
const x24 = (x22 * 0x2);
const x25 = ((arg1[11]) * 0x2);
const x26 = (arg1[10]);
const x27 = (arg1[10]);
const x28 = (x26 * 0x2);
const x29 = (x27 * 0x2);
const x30 = ((arg1[10]) * 0x2);
const x31 = (arg1[9]);
const x32 = (arg1[9]);
const x33 = (x31 * 0x2);
const x34 = (x32 * 0x2);
const x35 = ((arg1[9]) * 0x2);
const x36 = (arg1[8]);
const x37 = (arg1[8]);
const x38 = ((arg1[8]) * 0x2);
const x39 = ((arg1[7]) * 0x2);
const x40 = ((arg1[6]) * 0x2);
const x41 = ((arg1[5]) * 0x2);
const x42 = ((arg1[4]) * 0x2);
const x43 = ((arg1[3]) * 0x2);
const x44 = ((arg1[2]) * 0x2);
const x45 = ((arg1[1]) * 0x2);
const x46 = (cast(u64, (arg1[15])) * cast(u64, x1));
const x47 = (cast(u64, (arg1[14])) * cast(u64, x3));
const x48 = (cast(u64, (arg1[14])) * cast(u64, x6));
const x49 = (cast(u64, (arg1[13])) * cast(u64, x3));
const x50 = (cast(u64, (arg1[13])) * cast(u64, x8));
const x51 = (cast(u64, (arg1[13])) * cast(u64, x11));
const x52 = (cast(u64, (arg1[12])) * cast(u64, x3));
const x53 = (cast(u64, (arg1[12])) * cast(u64, x8));
const x54 = (cast(u64, (arg1[12])) * cast(u64, x13));
const x55 = (cast(u64, (arg1[12])) * cast(u64, x16));
const x56 = (cast(u64, (arg1[11])) * cast(u64, x3));
const x57 = (cast(u64, (arg1[11])) * cast(u64, x8));
const x58 = (cast(u64, (arg1[11])) * cast(u64, x13));
const x59 = (cast(u64, (arg1[10])) * cast(u64, x3));
const x60 = (cast(u64, (arg1[10])) * cast(u64, x8));
const x61 = (cast(u64, (arg1[9])) * cast(u64, x3));
const x62 = (cast(u64, (arg1[15])) * cast(u64, x1));
const x63 = (cast(u64, (arg1[14])) * cast(u64, x3));
const x64 = (cast(u64, (arg1[14])) * cast(u64, x6));
const x65 = (cast(u64, (arg1[13])) * cast(u64, x3));
const x66 = (cast(u64, (arg1[13])) * cast(u64, x8));
const x67 = (cast(u64, (arg1[13])) * cast(u64, x11));
const x68 = (cast(u64, (arg1[12])) * cast(u64, x3));
const x69 = (cast(u64, (arg1[12])) * cast(u64, x8));
const x70 = (cast(u64, (arg1[12])) * cast(u64, x13));
const x71 = (cast(u64, (arg1[12])) * cast(u64, x16));
const x72 = (cast(u64, (arg1[11])) * cast(u64, x3));
const x73 = (cast(u64, (arg1[11])) * cast(u64, x8));
const x74 = (cast(u64, (arg1[11])) * cast(u64, x13));
const x75 = (cast(u64, (arg1[10])) * cast(u64, x3));
const x76 = (cast(u64, (arg1[10])) * cast(u64, x8));
const x77 = (cast(u64, (arg1[9])) * cast(u64, x3));
const x78 = (cast(u64, (arg1[15])) * cast(u64, x2));
const x79 = (cast(u64, (arg1[14])) * cast(u64, x4));
const x80 = (cast(u64, (arg1[14])) * cast(u64, x7));
const x81 = (cast(u64, (arg1[13])) * cast(u64, x4));
const x82 = (cast(u64, (arg1[13])) * cast(u64, x9));
const x83 = (cast(u64, (arg1[13])) * cast(u64, x12));
const x84 = (cast(u64, (arg1[12])) * cast(u64, x4));
const x85 = (cast(u64, (arg1[12])) * cast(u64, x9));
const x86 = (cast(u64, (arg1[12])) * cast(u64, x14));
const x87 = (cast(u64, (arg1[12])) * cast(u64, x17));
const x88 = (cast(u64, (arg1[11])) * cast(u64, x4));
const x89 = (cast(u64, (arg1[11])) * cast(u64, x9));
const x90 = (cast(u64, (arg1[11])) * cast(u64, x14));
const x91 = (cast(u64, (arg1[11])) * cast(u64, x19));
const x92 = (cast(u64, (arg1[11])) * cast(u64, x18));
const x93 = (cast(u64, (arg1[11])) * cast(u64, x22));
const x94 = (cast(u64, (arg1[11])) * cast(u64, x21));
const x95 = (cast(u64, (arg1[10])) * cast(u64, x4));
const x96 = (cast(u64, (arg1[10])) * cast(u64, x9));
const x97 = (cast(u64, (arg1[10])) * cast(u64, x14));
const x98 = (cast(u64, (arg1[10])) * cast(u64, x13));
const x99 = (cast(u64, (arg1[10])) * cast(u64, x19));
const x100 = (cast(u64, (arg1[10])) * cast(u64, x18));
const x101 = (cast(u64, (arg1[10])) * cast(u64, x24));
const x102 = (cast(u64, (arg1[10])) * cast(u64, x23));
const x103 = (cast(u64, (arg1[10])) * cast(u64, x27));
const x104 = (cast(u64, (arg1[10])) * cast(u64, x26));
const x105 = (cast(u64, (arg1[9])) * cast(u64, x4));
const x106 = (cast(u64, (arg1[9])) * cast(u64, x9));
const x107 = (cast(u64, (arg1[9])) * cast(u64, x8));
const x108 = (cast(u64, (arg1[9])) * cast(u64, x14));
const x109 = (cast(u64, (arg1[9])) * cast(u64, x13));
const x110 = (cast(u64, (arg1[9])) * cast(u64, x19));
const x111 = (cast(u64, (arg1[9])) * cast(u64, x18));
const x112 = (cast(u64, (arg1[9])) * cast(u64, x24));
const x113 = (cast(u64, (arg1[9])) * cast(u64, x23));
const x114 = (cast(u64, (arg1[9])) * cast(u64, x29));
const x115 = (cast(u64, (arg1[9])) * cast(u64, x28));
const x116 = (cast(u64, (arg1[9])) * cast(u64, x32));
const x117 = (cast(u64, (arg1[9])) * cast(u64, x31));
const x118 = (cast(u64, (arg1[8])) * cast(u64, x4));
const x119 = (cast(u64, (arg1[8])) * cast(u64, x3));
const x120 = (cast(u64, (arg1[8])) * cast(u64, x9));
const x121 = (cast(u64, (arg1[8])) * cast(u64, x8));
const x122 = (cast(u64, (arg1[8])) * cast(u64, x14));
const x123 = (cast(u64, (arg1[8])) * cast(u64, x13));
const x124 = (cast(u64, (arg1[8])) * cast(u64, x19));
const x125 = (cast(u64, (arg1[8])) * cast(u64, x18));
const x126 = (cast(u64, (arg1[8])) * cast(u64, x24));
const x127 = (cast(u64, (arg1[8])) * cast(u64, x23));
const x128 = (cast(u64, (arg1[8])) * cast(u64, x29));
const x129 = (cast(u64, (arg1[8])) * cast(u64, x28));
const x130 = (cast(u64, (arg1[8])) * cast(u64, x34));
const x131 = (cast(u64, (arg1[8])) * cast(u64, x33));
const x132 = (cast(u64, (arg1[8])) * cast(u64, x37));
const x133 = (cast(u64, (arg1[8])) * cast(u64, x36));
const x134 = (cast(u64, (arg1[7])) * cast(u64, x4));
const x135 = (cast(u64, (arg1[7])) * cast(u64, x3));
const x136 = (cast(u64, (arg1[7])) * cast(u64, x9));
const x137 = (cast(u64, (arg1[7])) * cast(u64, x8));
const x138 = (cast(u64, (arg1[7])) * cast(u64, x14));
const x139 = (cast(u64, (arg1[7])) * cast(u64, x13));
const x140 = (cast(u64, (arg1[7])) * cast(u64, x19));
const x141 = (cast(u64, (arg1[7])) * cast(u64, x18));
const x142 = (cast(u64, (arg1[7])) * cast(u64, x24));
const x143 = (cast(u64, (arg1[7])) * cast(u64, x23));
const x144 = (cast(u64, (arg1[7])) * cast(u64, x29));
const x145 = (cast(u64, (arg1[7])) * cast(u64, x28));
const x146 = (cast(u64, (arg1[7])) * cast(u64, x34));
const x147 = (cast(u64, (arg1[7])) * cast(u64, x33));
const x148 = (cast(u64, (arg1[7])) * cast(u64, x38));
const x149 = (cast(u64, (arg1[7])) * cast(u64, (arg1[7])));
const x150 = (cast(u64, (arg1[6])) * cast(u64, x4));
const x151 = (cast(u64, (arg1[6])) * cast(u64, x3));
const x152 = (cast(u64, (arg1[6])) * cast(u64, x9));
const x153 = (cast(u64, (arg1[6])) * cast(u64, x8));
const x154 = (cast(u64, (arg1[6])) * cast(u64, x14));
const x155 = (cast(u64, (arg1[6])) * cast(u64, x13));
const x156 = (cast(u64, (arg1[6])) * cast(u64, x19));
const x157 = (cast(u64, (arg1[6])) * cast(u64, x18));
const x158 = (cast(u64, (arg1[6])) * cast(u64, x24));
const x159 = (cast(u64, (arg1[6])) * cast(u64, x23));
const x160 = (cast(u64, (arg1[6])) * cast(u64, x29));
const x161 = (cast(u64, (arg1[6])) * cast(u64, x28));
const x162 = (cast(u64, (arg1[6])) * cast(u64, x35));
const x163 = (cast(u64, (arg1[6])) * cast(u64, x38));
const x164 = (cast(u64, (arg1[6])) * cast(u64, x39));
const x165 = (cast(u64, (arg1[6])) * cast(u64, (arg1[6])));
const x166 = (cast(u64, (arg1[5])) * cast(u64, x4));
const x167 = (cast(u64, (arg1[5])) * cast(u64, x3));
const x168 = (cast(u64, (arg1[5])) * cast(u64, x9));
const x169 = (cast(u64, (arg1[5])) * cast(u64, x8));
const x170 = (cast(u64, (arg1[5])) * cast(u64, x14));
const x171 = (cast(u64, (arg1[5])) * cast(u64, x13));
const x172 = (cast(u64, (arg1[5])) * cast(u64, x19));
const x173 = (cast(u64, (arg1[5])) * cast(u64, x18));
const x174 = (cast(u64, (arg1[5])) * cast(u64, x24));
const x175 = (cast(u64, (arg1[5])) * cast(u64, x23));
const x176 = (cast(u64, (arg1[5])) * cast(u64, x30));
const x177 = (cast(u64, (arg1[5])) * cast(u64, x35));
const x178 = (cast(u64, (arg1[5])) * cast(u64, x38));
const x179 = (cast(u64, (arg1[5])) * cast(u64, x39));
const x180 = (cast(u64, (arg1[5])) * cast(u64, x40));
const x181 = (cast(u64, (arg1[5])) * cast(u64, (arg1[5])));
const x182 = (cast(u64, (arg1[4])) * cast(u64, x4));
const x183 = (cast(u64, (arg1[4])) * cast(u64, x3));
const x184 = (cast(u64, (arg1[4])) * cast(u64, x9));
const x185 = (cast(u64, (arg1[4])) * cast(u64, x8));
const x186 = (cast(u64, (arg1[4])) * cast(u64, x14));
const x187 = (cast(u64, (arg1[4])) * cast(u64, x13));
const x188 = (cast(u64, (arg1[4])) * cast(u64, x19));
const x189 = (cast(u64, (arg1[4])) * cast(u64, x18));
const x190 = (cast(u64, (arg1[4])) * cast(u64, x25));
const x191 = (cast(u64, (arg1[4])) * cast(u64, x30));
const x192 = (cast(u64, (arg1[4])) * cast(u64, x35));
const x193 = (cast(u64, (arg1[4])) * cast(u64, x38));
const x194 = (cast(u64, (arg1[4])) * cast(u64, x39));
const x195 = (cast(u64, (arg1[4])) * cast(u64, x40));
const x196 = (cast(u64, (arg1[4])) * cast(u64, x41));
const x197 = (cast(u64, (arg1[4])) * cast(u64, (arg1[4])));
const x198 = (cast(u64, (arg1[3])) * cast(u64, x4));
const x199 = (cast(u64, (arg1[3])) * cast(u64, x3));
const x200 = (cast(u64, (arg1[3])) * cast(u64, x9));
const x201 = (cast(u64, (arg1[3])) * cast(u64, x8));
const x202 = (cast(u64, (arg1[3])) * cast(u64, x14));
const x203 = (cast(u64, (arg1[3])) * cast(u64, x13));
const x204 = (cast(u64, (arg1[3])) * cast(u64, x20));
const x205 = (cast(u64, (arg1[3])) * cast(u64, x25));
const x206 = (cast(u64, (arg1[3])) * cast(u64, x30));
const x207 = (cast(u64, (arg1[3])) * cast(u64, x35));
const x208 = (cast(u64, (arg1[3])) * cast(u64, x38));
const x209 = (cast(u64, (arg1[3])) * cast(u64, x39));
const x210 = (cast(u64, (arg1[3])) * cast(u64, x40));
const x211 = (cast(u64, (arg1[3])) * cast(u64, x41));
const x212 = (cast(u64, (arg1[3])) * cast(u64, x42));
const x213 = (cast(u64, (arg1[3])) * cast(u64, (arg1[3])));
const x214 = (cast(u64, (arg1[2])) * cast(u64, x4));
const x215 = (cast(u64, (arg1[2])) * cast(u64, x3));
const x216 = (cast(u64, (arg1[2])) * cast(u64, x9));
const x217 = (cast(u64, (arg1[2])) * cast(u64, x8));
const x218 = (cast(u64, (arg1[2])) * cast(u64, x15));
const x219 = (cast(u64, (arg1[2])) * cast(u64, x20));
const x220 = (cast(u64, (arg1[2])) * cast(u64, x25));
const x221 = (cast(u64, (arg1[2])) * cast(u64, x30));
const x222 = (cast(u64, (arg1[2])) * cast(u64, x35));
const x223 = (cast(u64, (arg1[2])) * cast(u64, x38));
const x224 = (cast(u64, (arg1[2])) * cast(u64, x39));
const x225 = (cast(u64, (arg1[2])) * cast(u64, x40));
const x226 = (cast(u64, (arg1[2])) * cast(u64, x41));
const x227 = (cast(u64, (arg1[2])) * cast(u64, x42));
const x228 = (cast(u64, (arg1[2])) * cast(u64, x43));
const x229 = (cast(u64, (arg1[2])) * cast(u64, (arg1[2])));
const x230 = (cast(u64, (arg1[1])) * cast(u64, x4));
const x231 = (cast(u64, (arg1[1])) * cast(u64, x3));
const x232 = (cast(u64, (arg1[1])) * cast(u64, x10));
const x233 = (cast(u64, (arg1[1])) * cast(u64, x15));
const x234 = (cast(u64, (arg1[1])) * cast(u64, x20));
const x235 = (cast(u64, (arg1[1])) * cast(u64, x25));
const x236 = (cast(u64, (arg1[1])) * cast(u64, x30));
const x237 = (cast(u64, (arg1[1])) * cast(u64, x35));
const x238 = (cast(u64, (arg1[1])) * cast(u64, x38));
const x239 = (cast(u64, (arg1[1])) * cast(u64, x39));
const x240 = (cast(u64, (arg1[1])) * cast(u64, x40));
const x241 = (cast(u64, (arg1[1])) * cast(u64, x41));
const x242 = (cast(u64, (arg1[1])) * cast(u64, x42));
const x243 = (cast(u64, (arg1[1])) * cast(u64, x43));
const x244 = (cast(u64, (arg1[1])) * cast(u64, x44));
const x245 = (cast(u64, (arg1[1])) * cast(u64, (arg1[1])));
const x246 = (cast(u64, (arg1[0])) * cast(u64, x5));
const x247 = (cast(u64, (arg1[0])) * cast(u64, x10));
const x248 = (cast(u64, (arg1[0])) * cast(u64, x15));
const x249 = (cast(u64, (arg1[0])) * cast(u64, x20));
const x250 = (cast(u64, (arg1[0])) * cast(u64, x25));
const x251 = (cast(u64, (arg1[0])) * cast(u64, x30));
const x252 = (cast(u64, (arg1[0])) * cast(u64, x35));
const x253 = (cast(u64, (arg1[0])) * cast(u64, x38));
const x254 = (cast(u64, (arg1[0])) * cast(u64, x39));
const x255 = (cast(u64, (arg1[0])) * cast(u64, x40));
const x256 = (cast(u64, (arg1[0])) * cast(u64, x41));
const x257 = (cast(u64, (arg1[0])) * cast(u64, x42));
const x258 = (cast(u64, (arg1[0])) * cast(u64, x43));
const x259 = (cast(u64, (arg1[0])) * cast(u64, x44));
const x260 = (cast(u64, (arg1[0])) * cast(u64, x45));
const x261 = (cast(u64, (arg1[0])) * cast(u64, (arg1[0])));
const x262 = (x254 + (x240 + (x226 + (x212 + (x118 + (x106 + (x97 + x91)))))));
const x263 = (x262 >> 28);
const x264 = cast(u32, (x262 & cast(u64, 0xfffffff)));
const x265 = (x246 + (x232 + (x218 + (x204 + (x190 + (x176 + (x162 + (x148 + (x119 + (x107 + (x98 + x92)))))))))));
const x266 = (x247 + (x233 + (x219 + (x205 + (x191 + (x177 + (x163 + (x149 + (x135 + (x121 + (x109 + (x100 + (x94 + (x78 + x62))))))))))))));
const x267 = (x248 + (x234 + (x220 + (x206 + (x192 + (x178 + (x164 + (x151 + (x137 + (x123 + (x111 + (x102 + (x79 + x63)))))))))))));
const x268 = (cast(u128, x249) + cast(u128, (x235 + (x221 + (x207 + (x193 + (x179 + (x167 + (x165 + (x153 + (x139 + (x125 + (x113 + (x104 + (x81 + (x80 + (x65 + x64)))))))))))))))));
const x269 = (cast(u128, x250) + (cast(u128, x236) + cast(u128, (x222 + (x208 + (x194 + (x183 + (x180 + (x169 + (x155 + (x141 + (x127 + (x115 + (x84 + (x82 + (x68 + x66))))))))))))))));
const x270 = (cast(u128, x251) + (cast(u128, x237) + (cast(u128, x223) + cast(u128, (x209 + (x199 + (x195 + (x185 + (x181 + (x171 + (x157 + (x143 + (x129 + (x117 + (x88 + (x85 + (x83 + (x72 + (x69 + x67)))))))))))))))))));
const x271 = (cast(u128, x252) + (cast(u128, x238) + (cast(u128, x224) + (cast(u128, x215) + cast(u128, (x210 + (x201 + (x196 + (x187 + (x173 + (x159 + (x145 + (x131 + (x95 + (x89 + (x86 + (x75 + (x73 + x70))))))))))))))))));
const x272 = (cast(u128, x253) + (cast(u128, x239) + (cast(u128, x231) + (cast(u128, x225) + (cast(u128, x217) + cast(u128, (x211 + (x203 + (x197 + (x189 + (x175 + (x161 + (x147 + (x133 + (x105 + (x96 + (x90 + (x87 + (x77 + (x76 + (x74 + x71)))))))))))))))))))));
const x273 = (x255 + (x241 + (x227 + (x213 + (x134 + (x120 + (x108 + (x99 + (x93 + x46)))))))));
const x274 = (x256 + (x242 + (x228 + (x150 + (x136 + (x122 + (x110 + (x101 + x47))))))));
const x275 = (x257 + (x243 + (x229 + (x166 + (x152 + (x138 + (x124 + (x112 + (x103 + (x49 + x48))))))))));
const x276 = (x258 + (x244 + (x182 + (x168 + (x154 + (x140 + (x126 + (x114 + (x52 + x50)))))))));
const x277 = (x259 + (x245 + (x198 + (x184 + (x170 + (x156 + (x142 + (x128 + (x116 + (x56 + (x53 + x51)))))))))));
const x278 = (x260 + (x214 + (x200 + (x186 + (x172 + (x158 + (x144 + (x130 + (x59 + (x57 + x54))))))))));
const x279 = (x261 + (x230 + (x216 + (x202 + (x188 + (x174 + (x160 + (x146 + (x132 + (x61 + (x60 + (x58 + x55))))))))))));
const x280 = (cast(u128, x263) + x272);
const x281 = (x265 >> 28);
const x282 = cast(u32, (x265 & cast(u64, 0xfffffff)));
const x283 = (x280 + cast(u128, x281));
const x284 = cast(u64, (x283 >> 28));
const x285 = cast(u32, (x283 & cast(u128, 0xfffffff)));
const x286 = (x279 + x281);
const x287 = (cast(u128, x284) + x271);
const x288 = (x286 >> 28);
const x289 = cast(u32, (x286 & cast(u64, 0xfffffff)));
const x290 = (x288 + x278);
const x291 = cast(u64, (x287 >> 28));
const x292 = cast(u32, (x287 & cast(u128, 0xfffffff)));
const x293 = (cast(u128, x291) + x270);
const x294 = (x290 >> 28);
const x295 = cast(u32, (x290 & cast(u64, 0xfffffff)));
const x296 = (x294 + x277);
const x297 = cast(u64, (x293 >> 28));
const x298 = cast(u32, (x293 & cast(u128, 0xfffffff)));
const x299 = (cast(u128, x297) + x269);
const x300 = (x296 >> 28);
const x301 = cast(u32, (x296 & cast(u64, 0xfffffff)));
const x302 = (x300 + x276);
const x303 = cast(u64, (x299 >> 28));
const x304 = cast(u32, (x299 & cast(u128, 0xfffffff)));
const x305 = (cast(u128, x303) + x268);
const x306 = (x302 >> 28);
const x307 = cast(u32, (x302 & cast(u64, 0xfffffff)));
const x308 = (x306 + x275);
const x309 = cast(u64, (x305 >> 28));
const x310 = cast(u32, (x305 & cast(u128, 0xfffffff)));
const x311 = (x309 + x267);
const x312 = (x308 >> 28);
const x313 = cast(u32, (x308 & cast(u64, 0xfffffff)));
const x314 = (x312 + x274);
const x315 = (x311 >> 28);
const x316 = cast(u32, (x311 & cast(u64, 0xfffffff)));
const x317 = (x315 + x266);
const x318 = (x314 >> 28);
const x319 = cast(u32, (x314 & cast(u64, 0xfffffff)));
const x320 = (x318 + x273);
const x321 = (x317 >> 28);
const x322 = cast(u32, (x317 & cast(u64, 0xfffffff)));
const x323 = (x321 + cast(u64, x282));
const x324 = (x320 >> 28);
const x325 = cast(u32, (x320 & cast(u64, 0xfffffff)));
const x326 = (x324 + cast(u64, x264));
const x327 = cast(u32, (x323 >> 28));
const x328 = cast(u32, (x323 & cast(u64, 0xfffffff)));
const x329 = cast(u32, (x326 >> 28));
const x330 = cast(u32, (x326 & cast(u64, 0xfffffff)));
const x331 = (x285 + x327);
const x332 = (x289 + x327);
const x333 = (x329 + x331);
const x334 = cast(u1, (x333 >> 28));
const x335 = (x333 & 0xfffffff);
const x336 = (cast(u32, x334) + x292);
const x337 = cast(u1, (x332 >> 28));
const x338 = (x332 & 0xfffffff);
const x339 = (cast(u32, x337) + x295);
out1[0] = x338;
out1[1] = x339;
out1[2] = x301;
out1[3] = x307;
out1[4] = x313;
out1[5] = x319;
out1[6] = x325;
out1[7] = x330;
out1[8] = x335;
out1[9] = x336;
out1[10] = x298;
out1[11] = x304;
out1[12] = x310;
out1[13] = x316;
out1[14] = x322;
out1[15] = x328;
}
/// The function carry reduces a field element.
/// Postconditions:
/// eval out1 mod m = eval arg1 mod m
///
/// Input Bounds:
/// arg1: [[0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000]]
/// Output Bounds:
/// out1: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
pub fn carry(out1: *[16]u32, arg1: [16]u32) void {
@setRuntimeSafety(mode == .Debug);
const x1 = (arg1[7]);
const x2 = (arg1[15]);
const x3 = (x2 >> 28);
const x4 = (((x1 >> 28) + (arg1[8])) + x3);
const x5 = ((arg1[0]) + x3);
const x6 = ((x4 >> 28) + (arg1[9]));
const x7 = ((x5 >> 28) + (arg1[1]));
const x8 = ((x6 >> 28) + (arg1[10]));
const x9 = ((x7 >> 28) + (arg1[2]));
const x10 = ((x8 >> 28) + (arg1[11]));
const x11 = ((x9 >> 28) + (arg1[3]));
const x12 = ((x10 >> 28) + (arg1[12]));
const x13 = ((x11 >> 28) + (arg1[4]));
const x14 = ((x12 >> 28) + (arg1[13]));
const x15 = ((x13 >> 28) + (arg1[5]));
const x16 = ((x14 >> 28) + (arg1[14]));
const x17 = ((x15 >> 28) + (arg1[6]));
const x18 = ((x16 >> 28) + (x2 & 0xfffffff));
const x19 = ((x17 >> 28) + (x1 & 0xfffffff));
const x20 = cast(u1, (x18 >> 28));
const x21 = ((x5 & 0xfffffff) + cast(u32, x20));
const x22 = (cast(u32, cast(u1, (x19 >> 28))) + ((x4 & 0xfffffff) + cast(u32, x20)));
const x23 = (x21 & 0xfffffff);
const x24 = (cast(u32, cast(u1, (x21 >> 28))) + (x7 & 0xfffffff));
const x25 = (x9 & 0xfffffff);
const x26 = (x11 & 0xfffffff);
const x27 = (x13 & 0xfffffff);
const x28 = (x15 & 0xfffffff);
const x29 = (x17 & 0xfffffff);
const x30 = (x19 & 0xfffffff);
const x31 = (x22 & 0xfffffff);
const x32 = (cast(u32, cast(u1, (x22 >> 28))) + (x6 & 0xfffffff));
const x33 = (x8 & 0xfffffff);
const x34 = (x10 & 0xfffffff);
const x35 = (x12 & 0xfffffff);
const x36 = (x14 & 0xfffffff);
const x37 = (x16 & 0xfffffff);
const x38 = (x18 & 0xfffffff);
out1[0] = x23;
out1[1] = x24;
out1[2] = x25;
out1[3] = x26;
out1[4] = x27;
out1[5] = x28;
out1[6] = x29;
out1[7] = x30;
out1[8] = x31;
out1[9] = x32;
out1[10] = x33;
out1[11] = x34;
out1[12] = x35;
out1[13] = x36;
out1[14] = x37;
out1[15] = x38;
}
/// The function add adds two field elements.
/// Postconditions:
/// eval out1 mod m = (eval arg1 + eval arg2) mod m
///
/// Input Bounds:
/// arg1: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
/// arg2: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
/// Output Bounds:
/// out1: [[0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000]]
pub fn add(out1: *[16]u32, arg1: [16]u32, arg2: [16]u32) void {
@setRuntimeSafety(mode == .Debug);
const x1 = ((arg1[0]) + (arg2[0]));
const x2 = ((arg1[1]) + (arg2[1]));
const x3 = ((arg1[2]) + (arg2[2]));
const x4 = ((arg1[3]) + (arg2[3]));
const x5 = ((arg1[4]) + (arg2[4]));
const x6 = ((arg1[5]) + (arg2[5]));
const x7 = ((arg1[6]) + (arg2[6]));
const x8 = ((arg1[7]) + (arg2[7]));
const x9 = ((arg1[8]) + (arg2[8]));
const x10 = ((arg1[9]) + (arg2[9]));
const x11 = ((arg1[10]) + (arg2[10]));
const x12 = ((arg1[11]) + (arg2[11]));
const x13 = ((arg1[12]) + (arg2[12]));
const x14 = ((arg1[13]) + (arg2[13]));
const x15 = ((arg1[14]) + (arg2[14]));
const x16 = ((arg1[15]) + (arg2[15]));
out1[0] = x1;
out1[1] = x2;
out1[2] = x3;
out1[3] = x4;
out1[4] = x5;
out1[5] = x6;
out1[6] = x7;
out1[7] = x8;
out1[8] = x9;
out1[9] = x10;
out1[10] = x11;
out1[11] = x12;
out1[12] = x13;
out1[13] = x14;
out1[14] = x15;
out1[15] = x16;
}
/// The function sub subtracts two field elements.
/// Postconditions:
/// eval out1 mod m = (eval arg1 - eval arg2) mod m
///
/// Input Bounds:
/// arg1: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
/// arg2: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
/// Output Bounds:
/// out1: [[0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000]]
pub fn sub(out1: *[16]u32, arg1: [16]u32, arg2: [16]u32) void {
@setRuntimeSafety(mode == .Debug);
const x1 = ((0x1ffffffe + (arg1[0])) - (arg2[0]));
const x2 = ((0x1ffffffe + (arg1[1])) - (arg2[1]));
const x3 = ((0x1ffffffe + (arg1[2])) - (arg2[2]));
const x4 = ((0x1ffffffe + (arg1[3])) - (arg2[3]));
const x5 = ((0x1ffffffe + (arg1[4])) - (arg2[4]));
const x6 = ((0x1ffffffe + (arg1[5])) - (arg2[5]));
const x7 = ((0x1ffffffe + (arg1[6])) - (arg2[6]));
const x8 = ((0x1ffffffe + (arg1[7])) - (arg2[7]));
const x9 = ((0x1ffffffc + (arg1[8])) - (arg2[8]));
const x10 = ((0x1ffffffe + (arg1[9])) - (arg2[9]));
const x11 = ((0x1ffffffe + (arg1[10])) - (arg2[10]));
const x12 = ((0x1ffffffe + (arg1[11])) - (arg2[11]));
const x13 = ((0x1ffffffe + (arg1[12])) - (arg2[12]));
const x14 = ((0x1ffffffe + (arg1[13])) - (arg2[13]));
const x15 = ((0x1ffffffe + (arg1[14])) - (arg2[14]));
const x16 = ((0x1ffffffe + (arg1[15])) - (arg2[15]));
out1[0] = x1;
out1[1] = x2;
out1[2] = x3;
out1[3] = x4;
out1[4] = x5;
out1[5] = x6;
out1[6] = x7;
out1[7] = x8;
out1[8] = x9;
out1[9] = x10;
out1[10] = x11;
out1[11] = x12;
out1[12] = x13;
out1[13] = x14;
out1[14] = x15;
out1[15] = x16;
}
/// The function opp negates a field element.
/// Postconditions:
/// eval out1 mod m = -eval arg1 mod m
///
/// Input Bounds:
/// arg1: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
/// Output Bounds:
/// out1: [[0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000], [0x0 ~> 0x30000000]]
pub fn opp(out1: *[16]u32, arg1: [16]u32) void {
@setRuntimeSafety(mode == .Debug);
const x1 = (0x1ffffffe - (arg1[0]));
const x2 = (0x1ffffffe - (arg1[1]));
const x3 = (0x1ffffffe - (arg1[2]));
const x4 = (0x1ffffffe - (arg1[3]));
const x5 = (0x1ffffffe - (arg1[4]));
const x6 = (0x1ffffffe - (arg1[5]));
const x7 = (0x1ffffffe - (arg1[6]));
const x8 = (0x1ffffffe - (arg1[7]));
const x9 = (0x1ffffffc - (arg1[8]));
const x10 = (0x1ffffffe - (arg1[9]));
const x11 = (0x1ffffffe - (arg1[10]));
const x12 = (0x1ffffffe - (arg1[11]));
const x13 = (0x1ffffffe - (arg1[12]));
const x14 = (0x1ffffffe - (arg1[13]));
const x15 = (0x1ffffffe - (arg1[14]));
const x16 = (0x1ffffffe - (arg1[15]));
out1[0] = x1;
out1[1] = x2;
out1[2] = x3;
out1[3] = x4;
out1[4] = x5;
out1[5] = x6;
out1[6] = x7;
out1[7] = x8;
out1[8] = x9;
out1[9] = x10;
out1[10] = x11;
out1[11] = x12;
out1[12] = x13;
out1[13] = x14;
out1[14] = x15;
out1[15] = x16;
}
/// The function selectznz is a multi-limb conditional select.
/// Postconditions:
/// eval out1 = (if arg1 = 0 then eval arg2 else eval arg3)
///
/// Input Bounds:
/// arg1: [0x0 ~> 0x1]
/// arg2: [[0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff]]
/// arg3: [[0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff]]
/// Output Bounds:
/// out1: [[0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff], [0x0 ~> 0xffffffff]]
pub fn selectznz(out1: *[16]u32, arg1: u1, arg2: [16]u32, arg3: [16]u32) void {
@setRuntimeSafety(mode == .Debug);
var x1: u32 = undefined;
cmovznzU32(&x1, arg1, (arg2[0]), (arg3[0]));
var x2: u32 = undefined;
cmovznzU32(&x2, arg1, (arg2[1]), (arg3[1]));
var x3: u32 = undefined;
cmovznzU32(&x3, arg1, (arg2[2]), (arg3[2]));
var x4: u32 = undefined;
cmovznzU32(&x4, arg1, (arg2[3]), (arg3[3]));
var x5: u32 = undefined;
cmovznzU32(&x5, arg1, (arg2[4]), (arg3[4]));
var x6: u32 = undefined;
cmovznzU32(&x6, arg1, (arg2[5]), (arg3[5]));
var x7: u32 = undefined;
cmovznzU32(&x7, arg1, (arg2[6]), (arg3[6]));
var x8: u32 = undefined;
cmovznzU32(&x8, arg1, (arg2[7]), (arg3[7]));
var x9: u32 = undefined;
cmovznzU32(&x9, arg1, (arg2[8]), (arg3[8]));
var x10: u32 = undefined;
cmovznzU32(&x10, arg1, (arg2[9]), (arg3[9]));
var x11: u32 = undefined;
cmovznzU32(&x11, arg1, (arg2[10]), (arg3[10]));
var x12: u32 = undefined;
cmovznzU32(&x12, arg1, (arg2[11]), (arg3[11]));
var x13: u32 = undefined;
cmovznzU32(&x13, arg1, (arg2[12]), (arg3[12]));
var x14: u32 = undefined;
cmovznzU32(&x14, arg1, (arg2[13]), (arg3[13]));
var x15: u32 = undefined;
cmovznzU32(&x15, arg1, (arg2[14]), (arg3[14]));
var x16: u32 = undefined;
cmovznzU32(&x16, arg1, (arg2[15]), (arg3[15]));
out1[0] = x1;
out1[1] = x2;
out1[2] = x3;
out1[3] = x4;
out1[4] = x5;
out1[5] = x6;
out1[6] = x7;
out1[7] = x8;
out1[8] = x9;
out1[9] = x10;
out1[10] = x11;
out1[11] = x12;
out1[12] = x13;
out1[13] = x14;
out1[14] = x15;
out1[15] = x16;
}
/// The function toBytes serializes a field element to bytes in little-endian order.
/// Postconditions:
/// out1 = map (λ x, ⌊((eval arg1 mod m) mod 2^(8 * (x + 1))) / 2^(8 * x)⌋) [0..55]
///
/// Input Bounds:
/// arg1: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
/// Output Bounds:
/// out1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff]]
pub fn toBytes(out1: *[56]u8, arg1: [16]u32) void {
@setRuntimeSafety(mode == .Debug);
var x1: u32 = undefined;
var x2: u1 = undefined;
subborrowxU28(&x1, &x2, 0x0, (arg1[0]), 0xfffffff);
var x3: u32 = undefined;
var x4: u1 = undefined;
subborrowxU28(&x3, &x4, x2, (arg1[1]), 0xfffffff);
var x5: u32 = undefined;
var x6: u1 = undefined;
subborrowxU28(&x5, &x6, x4, (arg1[2]), 0xfffffff);
var x7: u32 = undefined;
var x8: u1 = undefined;
subborrowxU28(&x7, &x8, x6, (arg1[3]), 0xfffffff);
var x9: u32 = undefined;
var x10: u1 = undefined;
subborrowxU28(&x9, &x10, x8, (arg1[4]), 0xfffffff);
var x11: u32 = undefined;
var x12: u1 = undefined;
subborrowxU28(&x11, &x12, x10, (arg1[5]), 0xfffffff);
var x13: u32 = undefined;
var x14: u1 = undefined;
subborrowxU28(&x13, &x14, x12, (arg1[6]), 0xfffffff);
var x15: u32 = undefined;
var x16: u1 = undefined;
subborrowxU28(&x15, &x16, x14, (arg1[7]), 0xfffffff);
var x17: u32 = undefined;
var x18: u1 = undefined;
subborrowxU28(&x17, &x18, x16, (arg1[8]), 0xffffffe);
var x19: u32 = undefined;
var x20: u1 = undefined;
subborrowxU28(&x19, &x20, x18, (arg1[9]), 0xfffffff);
var x21: u32 = undefined;
var x22: u1 = undefined;
subborrowxU28(&x21, &x22, x20, (arg1[10]), 0xfffffff);
var x23: u32 = undefined;
var x24: u1 = undefined;
subborrowxU28(&x23, &x24, x22, (arg1[11]), 0xfffffff);
var x25: u32 = undefined;
var x26: u1 = undefined;
subborrowxU28(&x25, &x26, x24, (arg1[12]), 0xfffffff);
var x27: u32 = undefined;
var x28: u1 = undefined;
subborrowxU28(&x27, &x28, x26, (arg1[13]), 0xfffffff);
var x29: u32 = undefined;
var x30: u1 = undefined;
subborrowxU28(&x29, &x30, x28, (arg1[14]), 0xfffffff);
var x31: u32 = undefined;
var x32: u1 = undefined;
subborrowxU28(&x31, &x32, x30, (arg1[15]), 0xfffffff);
var x33: u32 = undefined;
cmovznzU32(&x33, x32, cast(u32, 0x0), 0xffffffff);
var x34: u32 = undefined;
var x35: u1 = undefined;
addcarryxU28(&x34, &x35, 0x0, x1, (x33 & 0xfffffff));
var x36: u32 = undefined;
var x37: u1 = undefined;
addcarryxU28(&x36, &x37, x35, x3, (x33 & 0xfffffff));
var x38: u32 = undefined;
var x39: u1 = undefined;
addcarryxU28(&x38, &x39, x37, x5, (x33 & 0xfffffff));
var x40: u32 = undefined;
var x41: u1 = undefined;
addcarryxU28(&x40, &x41, x39, x7, (x33 & 0xfffffff));
var x42: u32 = undefined;
var x43: u1 = undefined;
addcarryxU28(&x42, &x43, x41, x9, (x33 & 0xfffffff));
var x44: u32 = undefined;
var x45: u1 = undefined;
addcarryxU28(&x44, &x45, x43, x11, (x33 & 0xfffffff));
var x46: u32 = undefined;
var x47: u1 = undefined;
addcarryxU28(&x46, &x47, x45, x13, (x33 & 0xfffffff));
var x48: u32 = undefined;
var x49: u1 = undefined;
addcarryxU28(&x48, &x49, x47, x15, (x33 & 0xfffffff));
var x50: u32 = undefined;
var x51: u1 = undefined;
addcarryxU28(&x50, &x51, x49, x17, (x33 & 0xffffffe));
var x52: u32 = undefined;
var x53: u1 = undefined;
addcarryxU28(&x52, &x53, x51, x19, (x33 & 0xfffffff));
var x54: u32 = undefined;
var x55: u1 = undefined;
addcarryxU28(&x54, &x55, x53, x21, (x33 & 0xfffffff));
var x56: u32 = undefined;
var x57: u1 = undefined;
addcarryxU28(&x56, &x57, x55, x23, (x33 & 0xfffffff));
var x58: u32 = undefined;
var x59: u1 = undefined;
addcarryxU28(&x58, &x59, x57, x25, (x33 & 0xfffffff));
var x60: u32 = undefined;
var x61: u1 = undefined;
addcarryxU28(&x60, &x61, x59, x27, (x33 & 0xfffffff));
var x62: u32 = undefined;
var x63: u1 = undefined;
addcarryxU28(&x62, &x63, x61, x29, (x33 & 0xfffffff));
var x64: u32 = undefined;
var x65: u1 = undefined;
addcarryxU28(&x64, &x65, x63, x31, (x33 & 0xfffffff));
const x66 = (x64 << 4);
const x67 = (x60 << 4);
const x68 = (x56 << 4);
const x69 = (x52 << 4);
const x70 = (x48 << 4);
const x71 = (x44 << 4);
const x72 = (x40 << 4);
const x73 = (x36 << 4);
const x74 = cast(u8, (x34 & cast(u32, 0xff)));
const x75 = (x34 >> 8);
const x76 = cast(u8, (x75 & cast(u32, 0xff)));
const x77 = (x75 >> 8);
const x78 = cast(u8, (x77 & cast(u32, 0xff)));
const x79 = cast(u8, (x77 >> 8));
const x80 = (x73 + cast(u32, x79));
const x81 = cast(u8, (x80 & cast(u32, 0xff)));
const x82 = (x80 >> 8);
const x83 = cast(u8, (x82 & cast(u32, 0xff)));
const x84 = (x82 >> 8);
const x85 = cast(u8, (x84 & cast(u32, 0xff)));
const x86 = cast(u8, (x84 >> 8));
const x87 = cast(u8, (x38 & cast(u32, 0xff)));
const x88 = (x38 >> 8);
const x89 = cast(u8, (x88 & cast(u32, 0xff)));
const x90 = (x88 >> 8);
const x91 = cast(u8, (x90 & cast(u32, 0xff)));
const x92 = cast(u8, (x90 >> 8));
const x93 = (x72 + cast(u32, x92));
const x94 = cast(u8, (x93 & cast(u32, 0xff)));
const x95 = (x93 >> 8);
const x96 = cast(u8, (x95 & cast(u32, 0xff)));
const x97 = (x95 >> 8);
const x98 = cast(u8, (x97 & cast(u32, 0xff)));
const x99 = cast(u8, (x97 >> 8));
const x100 = cast(u8, (x42 & cast(u32, 0xff)));
const x101 = (x42 >> 8);
const x102 = cast(u8, (x101 & cast(u32, 0xff)));
const x103 = (x101 >> 8);
const x104 = cast(u8, (x103 & cast(u32, 0xff)));
const x105 = cast(u8, (x103 >> 8));
const x106 = (x71 + cast(u32, x105));
const x107 = cast(u8, (x106 & cast(u32, 0xff)));
const x108 = (x106 >> 8);
const x109 = cast(u8, (x108 & cast(u32, 0xff)));
const x110 = (x108 >> 8);
const x111 = cast(u8, (x110 & cast(u32, 0xff)));
const x112 = cast(u8, (x110 >> 8));
const x113 = cast(u8, (x46 & cast(u32, 0xff)));
const x114 = (x46 >> 8);
const x115 = cast(u8, (x114 & cast(u32, 0xff)));
const x116 = (x114 >> 8);
const x117 = cast(u8, (x116 & cast(u32, 0xff)));
const x118 = cast(u8, (x116 >> 8));
const x119 = (x70 + cast(u32, x118));
const x120 = cast(u8, (x119 & cast(u32, 0xff)));
const x121 = (x119 >> 8);
const x122 = cast(u8, (x121 & cast(u32, 0xff)));
const x123 = (x121 >> 8);
const x124 = cast(u8, (x123 & cast(u32, 0xff)));
const x125 = cast(u8, (x123 >> 8));
const x126 = cast(u8, (x50 & cast(u32, 0xff)));
const x127 = (x50 >> 8);
const x128 = cast(u8, (x127 & cast(u32, 0xff)));
const x129 = (x127 >> 8);
const x130 = cast(u8, (x129 & cast(u32, 0xff)));
const x131 = cast(u8, (x129 >> 8));
const x132 = (x69 + cast(u32, x131));
const x133 = cast(u8, (x132 & cast(u32, 0xff)));
const x134 = (x132 >> 8);
const x135 = cast(u8, (x134 & cast(u32, 0xff)));
const x136 = (x134 >> 8);
const x137 = cast(u8, (x136 & cast(u32, 0xff)));
const x138 = cast(u8, (x136 >> 8));
const x139 = cast(u8, (x54 & cast(u32, 0xff)));
const x140 = (x54 >> 8);
const x141 = cast(u8, (x140 & cast(u32, 0xff)));
const x142 = (x140 >> 8);
const x143 = cast(u8, (x142 & cast(u32, 0xff)));
const x144 = cast(u8, (x142 >> 8));
const x145 = (x68 + cast(u32, x144));
const x146 = cast(u8, (x145 & cast(u32, 0xff)));
const x147 = (x145 >> 8);
const x148 = cast(u8, (x147 & cast(u32, 0xff)));
const x149 = (x147 >> 8);
const x150 = cast(u8, (x149 & cast(u32, 0xff)));
const x151 = cast(u8, (x149 >> 8));
const x152 = cast(u8, (x58 & cast(u32, 0xff)));
const x153 = (x58 >> 8);
const x154 = cast(u8, (x153 & cast(u32, 0xff)));
const x155 = (x153 >> 8);
const x156 = cast(u8, (x155 & cast(u32, 0xff)));
const x157 = cast(u8, (x155 >> 8));
const x158 = (x67 + cast(u32, x157));
const x159 = cast(u8, (x158 & cast(u32, 0xff)));
const x160 = (x158 >> 8);
const x161 = cast(u8, (x160 & cast(u32, 0xff)));
const x162 = (x160 >> 8);
const x163 = cast(u8, (x162 & cast(u32, 0xff)));
const x164 = cast(u8, (x162 >> 8));
const x165 = cast(u8, (x62 & cast(u32, 0xff)));
const x166 = (x62 >> 8);
const x167 = cast(u8, (x166 & cast(u32, 0xff)));
const x168 = (x166 >> 8);
const x169 = cast(u8, (x168 & cast(u32, 0xff)));
const x170 = cast(u8, (x168 >> 8));
const x171 = (x66 + cast(u32, x170));
const x172 = cast(u8, (x171 & cast(u32, 0xff)));
const x173 = (x171 >> 8);
const x174 = cast(u8, (x173 & cast(u32, 0xff)));
const x175 = (x173 >> 8);
const x176 = cast(u8, (x175 & cast(u32, 0xff)));
const x177 = cast(u8, (x175 >> 8));
out1[0] = x74;
out1[1] = x76;
out1[2] = x78;
out1[3] = x81;
out1[4] = x83;
out1[5] = x85;
out1[6] = x86;
out1[7] = x87;
out1[8] = x89;
out1[9] = x91;
out1[10] = x94;
out1[11] = x96;
out1[12] = x98;
out1[13] = x99;
out1[14] = x100;
out1[15] = x102;
out1[16] = x104;
out1[17] = x107;
out1[18] = x109;
out1[19] = x111;
out1[20] = x112;
out1[21] = x113;
out1[22] = x115;
out1[23] = x117;
out1[24] = x120;
out1[25] = x122;
out1[26] = x124;
out1[27] = x125;
out1[28] = x126;
out1[29] = x128;
out1[30] = x130;
out1[31] = x133;
out1[32] = x135;
out1[33] = x137;
out1[34] = x138;
out1[35] = x139;
out1[36] = x141;
out1[37] = x143;
out1[38] = x146;
out1[39] = x148;
out1[40] = x150;
out1[41] = x151;
out1[42] = x152;
out1[43] = x154;
out1[44] = x156;
out1[45] = x159;
out1[46] = x161;
out1[47] = x163;
out1[48] = x164;
out1[49] = x165;
out1[50] = x167;
out1[51] = x169;
out1[52] = x172;
out1[53] = x174;
out1[54] = x176;
out1[55] = x177;
}
/// The function fromBytes deserializes a field element from bytes in little-endian order.
/// Postconditions:
/// eval out1 mod m = bytes_eval arg1 mod m
///
/// Input Bounds:
/// arg1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff]]
/// Output Bounds:
/// out1: [[0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000], [0x0 ~> 0x10000000]]
pub fn fromBytes(out1: *[16]u32, arg1: [56]u8) void {
@setRuntimeSafety(mode == .Debug);
const x1 = (cast(u32, (arg1[55])) << 20);
const x2 = (cast(u32, (arg1[54])) << 12);
const x3 = (cast(u32, (arg1[53])) << 4);
const x4 = (cast(u32, (arg1[52])) << 24);
const x5 = (cast(u32, (arg1[51])) << 16);
const x6 = (cast(u32, (arg1[50])) << 8);
const x7 = (arg1[49]);
const x8 = (cast(u32, (arg1[48])) << 20);
const x9 = (cast(u32, (arg1[47])) << 12);
const x10 = (cast(u32, (arg1[46])) << 4);
const x11 = (cast(u32, (arg1[45])) << 24);
const x12 = (cast(u32, (arg1[44])) << 16);
const x13 = (cast(u32, (arg1[43])) << 8);
const x14 = (arg1[42]);
const x15 = (cast(u32, (arg1[41])) << 20);
const x16 = (cast(u32, (arg1[40])) << 12);
const x17 = (cast(u32, (arg1[39])) << 4);
const x18 = (cast(u32, (arg1[38])) << 24);
const x19 = (cast(u32, (arg1[37])) << 16);
const x20 = (cast(u32, (arg1[36])) << 8);
const x21 = (arg1[35]);
const x22 = (cast(u32, (arg1[34])) << 20);
const x23 = (cast(u32, (arg1[33])) << 12);
const x24 = (cast(u32, (arg1[32])) << 4);
const x25 = (cast(u32, (arg1[31])) << 24);
const x26 = (cast(u32, (arg1[30])) << 16);
const x27 = (cast(u32, (arg1[29])) << 8);
const x28 = (arg1[28]);
const x29 = (cast(u32, (arg1[27])) << 20);
const x30 = (cast(u32, (arg1[26])) << 12);
const x31 = (cast(u32, (arg1[25])) << 4);
const x32 = (cast(u32, (arg1[24])) << 24);
const x33 = (cast(u32, (arg1[23])) << 16);
const x34 = (cast(u32, (arg1[22])) << 8);
const x35 = (arg1[21]);
const x36 = (cast(u32, (arg1[20])) << 20);
const x37 = (cast(u32, (arg1[19])) << 12);
const x38 = (cast(u32, (arg1[18])) << 4);
const x39 = (cast(u32, (arg1[17])) << 24);
const x40 = (cast(u32, (arg1[16])) << 16);
const x41 = (cast(u32, (arg1[15])) << 8);
const x42 = (arg1[14]);
const x43 = (cast(u32, (arg1[13])) << 20);
const x44 = (cast(u32, (arg1[12])) << 12);
const x45 = (cast(u32, (arg1[11])) << 4);
const x46 = (cast(u32, (arg1[10])) << 24);
const x47 = (cast(u32, (arg1[9])) << 16);
const x48 = (cast(u32, (arg1[8])) << 8);
const x49 = (arg1[7]);
const x50 = (cast(u32, (arg1[6])) << 20);
const x51 = (cast(u32, (arg1[5])) << 12);
const x52 = (cast(u32, (arg1[4])) << 4);
const x53 = (cast(u32, (arg1[3])) << 24);
const x54 = (cast(u32, (arg1[2])) << 16);
const x55 = (cast(u32, (arg1[1])) << 8);
const x56 = (arg1[0]);
const x57 = (x55 + cast(u32, x56));
const x58 = (x54 + x57);
const x59 = (x53 + x58);
const x60 = (x59 & 0xfffffff);
const x61 = cast(u8, (x59 >> 28));
const x62 = (x52 + cast(u32, x61));
const x63 = (x51 + x62);
const x64 = (x50 + x63);
const x65 = (x48 + cast(u32, x49));
const x66 = (x47 + x65);
const x67 = (x46 + x66);
const x68 = (x67 & 0xfffffff);
const x69 = cast(u8, (x67 >> 28));
const x70 = (x45 + cast(u32, x69));
const x71 = (x44 + x70);
const x72 = (x43 + x71);
const x73 = (x41 + cast(u32, x42));
const x74 = (x40 + x73);
const x75 = (x39 + x74);
const x76 = (x75 & 0xfffffff);
const x77 = cast(u8, (x75 >> 28));
const x78 = (x38 + cast(u32, x77));
const x79 = (x37 + x78);
const x80 = (x36 + x79);
const x81 = (x34 + cast(u32, x35));
const x82 = (x33 + x81);
const x83 = (x32 + x82);
const x84 = (x83 & 0xfffffff);
const x85 = cast(u8, (x83 >> 28));
const x86 = (x31 + cast(u32, x85));
const x87 = (x30 + x86);
const x88 = (x29 + x87);
const x89 = (x27 + cast(u32, x28));
const x90 = (x26 + x89);
const x91 = (x25 + x90);
const x92 = (x91 & 0xfffffff);
const x93 = cast(u8, (x91 >> 28));
const x94 = (x24 + cast(u32, x93));
const x95 = (x23 + x94);
const x96 = (x22 + x95);
const x97 = (x20 + cast(u32, x21));
const x98 = (x19 + x97);
const x99 = (x18 + x98);
const x100 = (x99 & 0xfffffff);
const x101 = cast(u8, (x99 >> 28));
const x102 = (x17 + cast(u32, x101));
const x103 = (x16 + x102);
const x104 = (x15 + x103);
const x105 = (x13 + cast(u32, x14));
const x106 = (x12 + x105);
const x107 = (x11 + x106);
const x108 = (x107 & 0xfffffff);
const x109 = cast(u8, (x107 >> 28));
const x110 = (x10 + cast(u32, x109));
const x111 = (x9 + x110);
const x112 = (x8 + x111);
const x113 = (x6 + cast(u32, x7));
const x114 = (x5 + x113);
const x115 = (x4 + x114);
const x116 = (x115 & 0xfffffff);
const x117 = cast(u8, (x115 >> 28));
const x118 = (x3 + cast(u32, x117));
const x119 = (x2 + x118);
const x120 = (x1 + x119);
out1[0] = x60;
out1[1] = x64;
out1[2] = x68;
out1[3] = x72;
out1[4] = x76;
out1[5] = x80;
out1[6] = x84;
out1[7] = x88;
out1[8] = x92;
out1[9] = x96;
out1[10] = x100;
out1[11] = x104;
out1[12] = x108;
out1[13] = x112;
out1[14] = x116;
out1[15] = x120;
} | fiat-zig/src/p448_solinas_32.zig |
const std = @import("std");
const with_trace = true;
const assert = std.debug.assert;
fn trace(comptime fmt: []const u8, args: anytype) void {
if (with_trace) std.debug.print(fmt, args);
}
const maxpackets = 32;
const Result = struct {
qe: u64,
s0: u32,
progress: u32,
targetsize: u32,
};
fn dfs(packets: []const u8, groups: [3][]const u8, best: *Result) void {
var order: [3]u8 = undefined;
var qe: u64 = 1;
{
for (groups[0]) |p| {
qe *= @intCast(u64, p);
}
var m = [3]u32{ 0, 0, 0 };
for (groups) |g, i| {
for (g) |p| {
m[i] += p;
}
}
var mleft: u32 = 0;
for (packets) |p| {
mleft += p;
}
if (m[0] > m[1]) {
if (m[1] > m[2]) {
order = [3]u8{ 2, 1, 0 };
} else if (m[0] > m[2]) {
order = [3]u8{ 1, 2, 0 };
} else {
order = [3]u8{ 1, 0, 2 };
}
} else {
if (m[0] > m[2]) {
order = [3]u8{ 2, 0, 1 };
} else if (m[1] > m[2]) {
order = [3]u8{ 0, 2, 1 };
} else {
order = [3]u8{ 0, 1, 2 };
}
}
const delta = (best.targetsize - m[order[1]]) + (best.targetsize - m[order[0]]);
if (m[order[2]] > best.targetsize or delta > mleft) {
if (best.progress > delta) {
best.progress = delta;
trace("progress: delta={} left={}\n", delta, mleft);
for (groups) |g, i| {
trace(" group{} = [", i);
for (g) |p| {
trace("{}, ", p);
}
trace("] = {}\n", m[i]);
}
}
return;
}
if (m[1] > m[2]) {
order = [3]u8{ 0, 2, 1 };
} else {
order = [3]u8{ 0, 1, 2 };
}
}
if (packets.len == 0) {
var s0 = @intCast(u32, groups[0].len);
if (s0 < best.s0 or (s0 == best.s0 and qe < best.qe)) {
best.qe = qe;
best.s0 = s0;
best.progress = 999999999;
trace("new best: {}\n", best.*);
for (groups) |g, i| {
trace(" group{} = [", i);
for (g) |p| {
trace("{}, ", p);
}
trace("]\n");
}
}
} else {
var storage: [maxpackets]u8 = undefined;
const newpackets = storage[0 .. packets.len - 1];
for (packets) |p, i| {
std.mem.copy(u8, newpackets[0..i], packets[0..i]);
std.mem.copy(u8, newpackets[i..], packets[i + 1 ..]);
if (groups[0].len > best.s0)
break;
if (groups[0].len == best.s0 and qe >= best.qe)
break;
for (order) |j| {
const g = groups[j];
if (j == 0 and g.len >= best.s0)
continue;
var newgroups: [3][]const u8 = undefined;
for (newgroups) |*ng, k| {
if (k == j) {
const newgroup = storage[packets.len .. packets.len + g.len + 1];
std.mem.copy(u8, newgroup, g);
newgroup[g.len] = p;
ng.* = newgroup;
} else {
ng.* = groups[k];
}
}
dfs(newpackets, newgroups, best);
}
}
}
}
pub fn main() anyerror!void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
// const limit = 1 * 1024 * 1024 * 1024;
// const text = try std.fs.cwd().readFileAlloc(allocator, "day24.txt", limit);
//const packets = [_]u8{1,2,3,4,5,7,8,9,10,11};
//const packets = [_]u8{11,10,9,8,7,5,4,3,2,1};
const packets = [_]u8{ 113, 109, 107, 103, 101, 97, 89, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 23, 19, 17, 13, 11, 7, 3, 2, 1 };
const totalmass = blk: {
var m: u32 = 0;
for (packets) |p| {
m += p;
}
break :blk m;
};
assert(totalmass % 3 == 0);
const emptygroup = [0]u8{};
const groups = [3][]const u8{
&emptygroup,
&emptygroup,
&emptygroup,
};
var res = Result{ .qe = 99999999999999, .s0 = 7, .progress = 999999, .targetsize = totalmass / 3 };
dfs(&packets, groups, &res);
const out = std.io.getStdOut().writer();
try out.print("res: {} \n", res);
// return error.SolutionNotFound;
} | 2015/day24.bfs.zig |
const std = @import("std");
const gk = @import("../gamekit.zig");
const rk = @import("renderkit");
const fons = @import("fontstash");
pub const FontBook = struct {
stash: *fons.Context,
texture: ?gk.gfx.Texture,
tex_filter: rk.TextureFilter,
width: i32 = 0,
height: i32 = 0,
tex_dirty: bool = false,
last_update: u32 = 0,
allocator: std.mem.Allocator,
pub const Align = fons.Align;
pub fn init(allocator: std.mem.Allocator, width: i32, height: i32, filter: rk.TextureFilter) !*FontBook {
var book = try allocator.create(FontBook);
errdefer allocator.destroy(book);
var params = fons.Params{
.width = width,
.height = height,
.flags = fons.Flags.top_left,
.user_ptr = book,
.renderCreate = renderCreate,
.renderResize = renderResize,
.renderUpdate = renderUpdate,
};
book.texture = null;
book.tex_filter = filter;
book.width = width;
book.height = height;
book.allocator = allocator;
book.stash = try fons.Context.init(¶ms);
return book;
}
pub fn deinit(self: *FontBook) void {
self.stash.deinit();
if (self.texture != null) self.texture.?.deinit();
self.allocator.destroy(self);
}
// add fonts
pub fn addFont(self: *FontBook, file: [:0]const u8) c_int {
const data = gk.fs.read(self.allocator, file) catch unreachable;
// we can let FONS free the data since we are using the c_allocator here
return fons.fonsAddFontMem(self.stash, file, @ptrCast([*c]const u8, data), @intCast(i32, data.len), 1);
}
pub fn addFontMem(self: *FontBook, name: [:0]const u8, data: []const u8, free_data: bool) c_int {
const free: c_int = if (free_data) 1 else 0;
return fons.fonsAddFontMem(self.stash, name, @ptrCast([*c]const u8, data), @intCast(i32, data.len), free);
}
// state setting
pub fn setAlign(self: *FontBook, alignment: Align) void {
fons.fonsSetAlign(self.stash, alignment);
}
pub fn setSize(self: FontBook, size: f32) void {
fons.fonsSetSize(self.stash, size);
}
pub fn setColor(self: FontBook, color: gk.math.Color) void {
fons.fonsSetColor(self.stash, color.value);
}
pub fn setSpacing(self: FontBook, spacing: f32) void {
fons.fonsSetSpacing(self.stash, spacing);
}
pub fn setBlur(self: FontBook, blur: f32) void {
fons.fonsSetBlur(self.stash, blur);
}
// state handling
pub fn pushState(self: *FontBook) void {
fons.fonsPushState(self.stash);
}
pub fn popState(self: *FontBook) void {
fons.fonsPopState(self.stash);
}
pub fn clearState(self: *FontBook) void {
fons.fonsClearState(self.stash);
}
// measure text
pub fn getTextBounds(self: *FontBook, x: f32, y: f32, str: []const u8) struct { width: f32, bounds: f32 } {
var bounds: f32 = undefined;
const width = fons.fonsTextBounds(self.stash, x, y, str.ptr, null, &bounds);
return .{ .width = width, .bounds = bounds };
}
pub fn getLineBounds(self: *FontBook, y: f32) struct { min_y: f32, max_y: f32 } {
var min_y: f32 = undefined;
var max_y: f32 = undefined;
fons.fonsLineBounds(self.stash, y, &min_y, &max_y);
return .{ .min_y = min_y, .max_y = max_y };
}
pub fn getVertMetrics(self: *FontBook) struct { ascender: f32, descender: f32, line_h: f32 } {
var ascender: f32 = undefined;
var descender: f32 = undefined;
var line_h: f32 = undefined;
fons.fonsVertMetrics(self.stash, &ascender, &descender, &line_h);
return .{ .ascender = ascender, .descender = descender, .line_h = line_h };
}
// text iter
pub fn getTextIterator(self: *FontBook, str: []const u8) fons.TextIter {
var iter = std.mem.zeroes(fons.TextIter);
const res = fons.fonsTextIterInit(self.stash, &iter, 0, 0, str.ptr, @intCast(c_int, str.len));
if (res == 0) std.log.warn("getTextIterator failed! Make sure you have added a font.\n", .{});
return iter;
}
pub fn textIterNext(self: *FontBook, iter: *fons.TextIter, quad: *fons.Quad) bool {
return fons.fonsTextIterNext(self.stash, iter, quad) == 1;
}
pub fn getQuad(self: FontBook) fons.Quad {
_ = self;
return std.mem.zeroes(fons.Quad);
}
fn renderCreate(ctx: ?*anyopaque, width: c_int, height: c_int) callconv(.C) c_int {
var self = @ptrCast(*FontBook, @alignCast(@alignOf(FontBook), ctx));
if (self.texture != null and (self.texture.?.width != @intToFloat(f32, width) or self.texture.?.height != @intToFloat(f32, height))) {
self.texture.?.deinit();
self.texture = null;
}
if (self.texture == null)
self.texture = gk.gfx.Texture.initDynamic(width, height, self.tex_filter, .clamp);
self.width = width;
self.height = height;
return 1;
}
fn renderResize(ctx: ?*anyopaque, width: c_int, height: c_int) callconv(.C) c_int {
return renderCreate(ctx, width, height);
}
fn renderUpdate(ctx: ?*anyopaque, rect: [*c]c_int, data: [*c]const u8) callconv(.C) c_int {
// TODO: only update the rect that changed
_ = rect;
var self = @ptrCast(*FontBook, @alignCast(@alignOf(FontBook), ctx));
if (!self.tex_dirty or self.last_update == gk.time.frames()) {
self.tex_dirty = true;
return 0;
}
const tex_area = @intCast(usize, self.width * self.height);
var pixels = self.allocator.alloc(u8, tex_area * 4) catch |err| {
std.log.warn("failed to allocate texture data: {}\n", .{err});
return 0;
};
defer self.allocator.free(pixels);
const source = data[0..tex_area];
for (source) |alpha, i| {
pixels[i * 4 + 0] = 255;
pixels[i * 4 + 1] = 255;
pixels[i * 4 + 2] = 255;
pixels[i * 4 + 3] = alpha;
}
self.texture.?.setData(u8, pixels);
self.tex_dirty = false;
self.last_update = gk.time.frames();
return 1;
}
}; | gamekit/graphics/fontbook.zig |
const std = @import("std");
const SDL = @import("sdl2");
const Renderer = @import("renderer.zig").Renderer;
pub const Window = struct {
sdlWindow: SDL.Window = undefined,
sdlRenderer: SDL.Renderer = undefined,
renderer: *Renderer = undefined,
outputTexture: SDL.Texture = undefined,
outputTextureRect: SDL.Rectangle = undefined,
outputTextureInfo: SDL.Texture.Info = undefined,
outputPixelBuffer: []u8 = undefined,
inMainLoop: bool = false,
pub fn init(self: *Window, width: usize, height: usize) !void {
self.sdlWindow = try SDL.createWindow(
"@eilume - Zig Simple Raytracer",
.{ .centered = {} },
.{ .centered = {} },
width,
height,
.{ .shown = true },
);
self.sdlRenderer = try SDL.createRenderer(
self.sdlWindow,
null,
.{ .accelerated = true },
);
self.outputTexture = try SDL.createTexture(self.sdlRenderer, SDL.PixelFormatEnum.rgba8888, SDL.Texture.Access.streaming, width, height);
self.outputTextureRect = SDL.Rectangle{ .x = 0, .y = 0, .width = @intCast(c_int, width), .height = @intCast(c_int, height) };
self.outputTextureInfo = try self.outputTexture.query();
}
pub fn setOutputPixelBuffer(self: *Window, outputPixelBuffer: []u8) !void {
self.outputPixelBuffer = outputPixelBuffer;
}
pub fn mainLoop(self: *Window) !void {
self.inMainLoop = true;
while (self.inMainLoop) {
try self.pollInput();
try self.renderer.render();
try self.update();
}
try self.cleanup();
}
pub fn cleanup(self: *Window) !void {
self.outputTexture.destroy();
self.sdlRenderer.destroy();
self.sdlWindow.destroy();
}
fn pollInput(self: *Window) !void {
while (SDL.pollEvent()) |event| {
switch (event) {
.quit => {
self.inMainLoop = false;
break;
},
else => {},
}
}
}
fn update(self: *Window) !void {
try self.sdlRenderer.setColorRGBA(0, 0, 0, 255);
try self.sdlRenderer.clear();
try self.updateTexture();
try self.sdlRenderer.copy(self.outputTexture, null, self.outputTextureRect);
self.sdlRenderer.present();
}
fn updateTexture(self: *Window) !void {
var pixels = try self.outputTexture.lock(null);
var index: usize = 0;
while (index < self.outputPixelBuffer.len) : (index += 1) {
pixels.pixels[index] = self.outputPixelBuffer[index];
}
// TODO: try doing a memory copy or set pointer
// This doesn't work???
// pixels.pixels = self.outputPixelBuffer.ptr;
pixels.release();
}
}; | src/window.zig |
const std = @import("std.zig");
const assert = std.debug.assert;
const testing = std.testing;
const EnumField = std.builtin.Type.EnumField;
/// Returns a struct with a field matching each unique named enum element.
/// If the enum is extern and has multiple names for the same value, only
/// the first name is used. Each field is of type Data and has the provided
/// default, which may be undefined.
pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type {
const StructField = std.builtin.Type.StructField;
var fields: []const StructField = &[_]StructField{};
for (std.meta.fields(E)) |field| {
fields = fields ++ &[_]StructField{.{
.name = field.name,
.field_type = Data,
.default_value = if (field_default) |d| &d else null,
.is_comptime = false,
.alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,
}};
}
return @Type(.{ .Struct = .{
.layout = .Auto,
.fields = fields,
.decls = &.{},
.is_tuple = false,
} });
}
/// Looks up the supplied fields in the given enum type.
/// Uses only the field names, field values are ignored.
/// The result array is in the same order as the input.
pub fn valuesFromFields(comptime E: type, comptime fields: []const EnumField) []const E {
comptime {
var result: [fields.len]E = undefined;
for (fields) |f, i| {
result[i] = @field(E, f.name);
}
return &result;
}
}
/// Returns the set of all named values in the given enum, in
/// declaration order.
pub fn values(comptime E: type) []const E {
return comptime valuesFromFields(E, @typeInfo(E).Enum.fields);
}
/// Determines the length of a direct-mapped enum array, indexed by
/// @intCast(usize, @enumToInt(enum_value)).
/// If the enum is non-exhaustive, the resulting length will only be enough
/// to hold all explicit fields.
/// If the enum contains any fields with values that cannot be represented
/// by usize, a compile error is issued. The max_unused_slots parameter limits
/// the total number of items which have no matching enum key (holes in the enum
/// numbering). So for example, if an enum has values 1, 2, 5, and 6, max_unused_slots
/// must be at least 3, to allow unused slots 0, 3, and 4.
fn directEnumArrayLen(comptime E: type, comptime max_unused_slots: comptime_int) comptime_int {
var max_value: comptime_int = -1;
const max_usize: comptime_int = ~@as(usize, 0);
const fields = std.meta.fields(E);
for (fields) |f| {
if (f.value < 0) {
@compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f.name ++ " has a negative value.");
}
if (f.value > max_value) {
if (f.value > max_usize) {
@compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f.name ++ " is larger than the max value of usize.");
}
max_value = f.value;
}
}
const unused_slots = max_value + 1 - fields.len;
if (unused_slots > max_unused_slots) {
const unused_str = std.fmt.comptimePrint("{d}", .{unused_slots});
const allowed_str = std.fmt.comptimePrint("{d}", .{max_unused_slots});
@compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ". It would have " ++ unused_str ++ " unused slots, but only " ++ allowed_str ++ " are allowed.");
}
return max_value + 1;
}
/// Initializes an array of Data which can be indexed by
/// @intCast(usize, @enumToInt(enum_value)).
/// If the enum is non-exhaustive, the resulting array will only be large enough
/// to hold all explicit fields.
/// If the enum contains any fields with values that cannot be represented
/// by usize, a compile error is issued. The max_unused_slots parameter limits
/// the total number of items which have no matching enum key (holes in the enum
/// numbering). So for example, if an enum has values 1, 2, 5, and 6, max_unused_slots
/// must be at least 3, to allow unused slots 0, 3, and 4.
/// The init_values parameter must be a struct with field names that match the enum values.
/// If the enum has multiple fields with the same value, the name of the first one must
/// be used.
pub fn directEnumArray(
comptime E: type,
comptime Data: type,
comptime max_unused_slots: comptime_int,
init_values: EnumFieldStruct(E, Data, null),
) [directEnumArrayLen(E, max_unused_slots)]Data {
return directEnumArrayDefault(E, Data, null, max_unused_slots, init_values);
}
test "std.enums.directEnumArray" {
const E = enum(i4) { a = 4, b = 6, c = 2 };
var runtime_false: bool = false;
const array = directEnumArray(E, bool, 4, .{
.a = true,
.b = runtime_false,
.c = true,
});
try testing.expectEqual([7]bool, @TypeOf(array));
try testing.expectEqual(true, array[4]);
try testing.expectEqual(false, array[6]);
try testing.expectEqual(true, array[2]);
}
/// Initializes an array of Data which can be indexed by
/// @intCast(usize, @enumToInt(enum_value)). The enum must be exhaustive.
/// If the enum contains any fields with values that cannot be represented
/// by usize, a compile error is issued. The max_unused_slots parameter limits
/// the total number of items which have no matching enum key (holes in the enum
/// numbering). So for example, if an enum has values 1, 2, 5, and 6, max_unused_slots
/// must be at least 3, to allow unused slots 0, 3, and 4.
/// The init_values parameter must be a struct with field names that match the enum values.
/// If the enum has multiple fields with the same value, the name of the first one must
/// be used.
pub fn directEnumArrayDefault(
comptime E: type,
comptime Data: type,
comptime default: ?Data,
comptime max_unused_slots: comptime_int,
init_values: EnumFieldStruct(E, Data, default),
) [directEnumArrayLen(E, max_unused_slots)]Data {
const len = comptime directEnumArrayLen(E, max_unused_slots);
var result: [len]Data = if (default) |d| [_]Data{d} ** len else undefined;
inline for (@typeInfo(@TypeOf(init_values)).Struct.fields) |f| {
const enum_value = @field(E, f.name);
const index = @intCast(usize, @enumToInt(enum_value));
result[index] = @field(init_values, f.name);
}
return result;
}
test "std.enums.directEnumArrayDefault" {
const E = enum(i4) { a = 4, b = 6, c = 2 };
var runtime_false: bool = false;
const array = directEnumArrayDefault(E, bool, false, 4, .{
.a = true,
.b = runtime_false,
});
try testing.expectEqual([7]bool, @TypeOf(array));
try testing.expectEqual(true, array[4]);
try testing.expectEqual(false, array[6]);
try testing.expectEqual(false, array[2]);
}
/// Cast an enum literal, value, or string to the enum value of type E
/// with the same name.
pub fn nameCast(comptime E: type, comptime value: anytype) E {
comptime {
const V = @TypeOf(value);
if (V == E) return value;
var name: ?[]const u8 = switch (@typeInfo(V)) {
.EnumLiteral, .Enum => @tagName(value),
.Pointer => if (std.meta.trait.isZigString(V)) value else null,
else => null,
};
if (name) |n| {
if (@hasField(E, n)) {
return @field(E, n);
}
@compileError("Enum " ++ @typeName(E) ++ " has no field named " ++ n);
}
@compileError("Cannot cast from " ++ @typeName(@TypeOf(value)) ++ " to " ++ @typeName(E));
}
}
test "std.enums.nameCast" {
const A = enum(u1) { a = 0, b = 1 };
const B = enum(u1) { a = 1, b = 0 };
try testing.expectEqual(A.a, nameCast(A, .a));
try testing.expectEqual(A.a, nameCast(A, A.a));
try testing.expectEqual(A.a, nameCast(A, B.a));
try testing.expectEqual(A.a, nameCast(A, "a"));
try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
try testing.expectEqual(B.a, nameCast(B, .a));
try testing.expectEqual(B.a, nameCast(B, A.a));
try testing.expectEqual(B.a, nameCast(B, B.a));
try testing.expectEqual(B.a, nameCast(B, "a"));
try testing.expectEqual(B.b, nameCast(B, .b));
try testing.expectEqual(B.b, nameCast(B, A.b));
try testing.expectEqual(B.b, nameCast(B, B.b));
try testing.expectEqual(B.b, nameCast(B, "b"));
}
/// A set of enum elements, backed by a bitfield. If the enum
/// is not dense, a mapping will be constructed from enum values
/// to dense indices. This type does no dynamic allocation and
/// can be copied by value.
pub fn EnumSet(comptime E: type) type {
const mixin = struct {
fn EnumSetExt(comptime Self: type) type {
const Indexer = Self.Indexer;
return struct {
/// Initializes the set using a struct of bools
pub fn init(init_values: EnumFieldStruct(E, bool, false)) Self {
var result = Self{};
comptime var i: usize = 0;
inline while (i < Self.len) : (i += 1) {
const key = comptime Indexer.keyForIndex(i);
const tag = comptime @tagName(key);
if (@field(init_values, tag)) {
result.bits.set(i);
}
}
return result;
}
};
}
};
return IndexedSet(EnumIndexer(E), mixin.EnumSetExt);
}
/// A map keyed by an enum, backed by a bitfield and a dense array.
/// If the enum is not dense, a mapping will be constructed from
/// enum values to dense indices. This type does no dynamic
/// allocation and can be copied by value.
pub fn EnumMap(comptime E: type, comptime V: type) type {
const mixin = struct {
fn EnumMapExt(comptime Self: type) type {
const Indexer = Self.Indexer;
return struct {
/// Initializes the map using a sparse struct of optionals
pub fn init(init_values: EnumFieldStruct(E, ?V, @as(?V, null))) Self {
var result = Self{};
comptime var i: usize = 0;
inline while (i < Self.len) : (i += 1) {
const key = comptime Indexer.keyForIndex(i);
const tag = comptime @tagName(key);
if (@field(init_values, tag)) |*v| {
result.bits.set(i);
result.values[i] = v.*;
}
}
return result;
}
/// Initializes a full mapping with all keys set to value.
/// Consider using EnumArray instead if the map will remain full.
pub fn initFull(value: V) Self {
var result = Self{
.bits = Self.BitSet.initFull(),
.values = undefined,
};
std.mem.set(V, &result.values, value);
return result;
}
/// Initializes a full mapping with supplied values.
/// Consider using EnumArray instead if the map will remain full.
pub fn initFullWith(init_values: EnumFieldStruct(E, V, @as(?V, null))) Self {
return initFullWithDefault(@as(?V, null), init_values);
}
/// Initializes a full mapping with a provided default.
/// Consider using EnumArray instead if the map will remain full.
pub fn initFullWithDefault(comptime default: ?V, init_values: EnumFieldStruct(E, V, default)) Self {
var result = Self{
.bits = Self.BitSet.initFull(),
.values = undefined,
};
comptime var i: usize = 0;
inline while (i < Self.len) : (i += 1) {
const key = comptime Indexer.keyForIndex(i);
const tag = comptime @tagName(key);
result.values[i] = @field(init_values, tag);
}
return result;
}
};
}
};
return IndexedMap(EnumIndexer(E), V, mixin.EnumMapExt);
}
/// An array keyed by an enum, backed by a dense array.
/// If the enum is not dense, a mapping will be constructed from
/// enum values to dense indices. This type does no dynamic
/// allocation and can be copied by value.
pub fn EnumArray(comptime E: type, comptime V: type) type {
const mixin = struct {
fn EnumArrayExt(comptime Self: type) type {
const Indexer = Self.Indexer;
return struct {
/// Initializes all values in the enum array
pub fn init(init_values: EnumFieldStruct(E, V, @as(?V, null))) Self {
return initDefault(@as(?V, null), init_values);
}
/// Initializes values in the enum array, with the specified default.
pub fn initDefault(comptime default: ?V, init_values: EnumFieldStruct(E, V, default)) Self {
var result = Self{ .values = undefined };
comptime var i: usize = 0;
inline while (i < Self.len) : (i += 1) {
const key = comptime Indexer.keyForIndex(i);
const tag = @tagName(key);
result.values[i] = @field(init_values, tag);
}
return result;
}
};
}
};
return IndexedArray(EnumIndexer(E), V, mixin.EnumArrayExt);
}
/// Pass this function as the Ext parameter to Indexed* if you
/// do not want to attach any extensions. This parameter was
/// originally an optional, but optional generic functions
/// seem to be broken at the moment.
/// TODO: Once #8169 is fixed, consider switching this param
/// back to an optional.
pub fn NoExtension(comptime Self: type) type {
_ = Self;
return NoExt;
}
const NoExt = struct {};
/// A set type with an Indexer mapping from keys to indices.
/// Presence or absence is stored as a dense bitfield. This
/// type does no allocation and can be copied by value.
pub fn IndexedSet(comptime I: type, comptime Ext: fn (type) type) type {
comptime ensureIndexer(I);
return struct {
const Self = @This();
pub usingnamespace Ext(Self);
/// The indexing rules for converting between keys and indices.
pub const Indexer = I;
/// The element type for this set.
pub const Key = Indexer.Key;
const BitSet = std.StaticBitSet(Indexer.count);
/// The maximum number of items in this set.
pub const len = Indexer.count;
bits: BitSet = BitSet.initEmpty(),
/// Returns a set containing all possible keys.
pub fn initFull() Self {
return .{ .bits = BitSet.initFull() };
}
/// Returns the number of keys in the set.
pub fn count(self: Self) usize {
return self.bits.count();
}
/// Checks if a key is in the set.
pub fn contains(self: Self, key: Key) bool {
return self.bits.isSet(Indexer.indexOf(key));
}
/// Puts a key in the set.
pub fn insert(self: *Self, key: Key) void {
self.bits.set(Indexer.indexOf(key));
}
/// Removes a key from the set.
pub fn remove(self: *Self, key: Key) void {
self.bits.unset(Indexer.indexOf(key));
}
/// Changes the presence of a key in the set to match the passed bool.
pub fn setPresent(self: *Self, key: Key, present: bool) void {
self.bits.setValue(Indexer.indexOf(key), present);
}
/// Toggles the presence of a key in the set. If the key is in
/// the set, removes it. Otherwise adds it.
pub fn toggle(self: *Self, key: Key) void {
self.bits.toggle(Indexer.indexOf(key));
}
/// Toggles the presence of all keys in the passed set.
pub fn toggleSet(self: *Self, other: Self) void {
self.bits.toggleSet(other.bits);
}
/// Toggles all possible keys in the set.
pub fn toggleAll(self: *Self) void {
self.bits.toggleAll();
}
/// Adds all keys in the passed set to this set.
pub fn setUnion(self: *Self, other: Self) void {
self.bits.setUnion(other.bits);
}
/// Removes all keys which are not in the passed set.
pub fn setIntersection(self: *Self, other: Self) void {
self.bits.setIntersection(other.bits);
}
/// Returns an iterator over this set, which iterates in
/// index order. Modifications to the set during iteration
/// may or may not be observed by the iterator, but will
/// not invalidate it.
pub fn iterator(self: *Self) Iterator {
return .{ .inner = self.bits.iterator(.{}) };
}
pub const Iterator = struct {
inner: BitSet.Iterator(.{}),
pub fn next(self: *Iterator) ?Key {
return if (self.inner.next()) |index|
Indexer.keyForIndex(index)
else
null;
}
};
};
}
/// A map from keys to values, using an index lookup. Uses a
/// bitfield to track presence and a dense array of values.
/// This type does no allocation and can be copied by value.
pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: fn (type) type) type {
comptime ensureIndexer(I);
return struct {
const Self = @This();
pub usingnamespace Ext(Self);
/// The index mapping for this map
pub const Indexer = I;
/// The key type used to index this map
pub const Key = Indexer.Key;
/// The value type stored in this map
pub const Value = V;
/// The number of possible keys in the map
pub const len = Indexer.count;
const BitSet = std.StaticBitSet(Indexer.count);
/// Bits determining whether items are in the map
bits: BitSet = BitSet.initEmpty(),
/// Values of items in the map. If the associated
/// bit is zero, the value is undefined.
values: [Indexer.count]Value = undefined,
/// The number of items in the map.
pub fn count(self: Self) usize {
return self.bits.count();
}
/// Checks if the map contains an item.
pub fn contains(self: Self, key: Key) bool {
return self.bits.isSet(Indexer.indexOf(key));
}
/// Gets the value associated with a key.
/// If the key is not in the map, returns null.
pub fn get(self: Self, key: Key) ?Value {
const index = Indexer.indexOf(key);
return if (self.bits.isSet(index)) self.values[index] else null;
}
/// Gets the value associated with a key, which must
/// exist in the map.
pub fn getAssertContains(self: Self, key: Key) Value {
const index = Indexer.indexOf(key);
assert(self.bits.isSet(index));
return self.values[index];
}
/// Gets the address of the value associated with a key.
/// If the key is not in the map, returns null.
pub fn getPtr(self: *Self, key: Key) ?*Value {
const index = Indexer.indexOf(key);
return if (self.bits.isSet(index)) &self.values[index] else null;
}
/// Gets the address of the const value associated with a key.
/// If the key is not in the map, returns null.
pub fn getPtrConst(self: *const Self, key: Key) ?*const Value {
const index = Indexer.indexOf(key);
return if (self.bits.isSet(index)) &self.values[index] else null;
}
/// Gets the address of the value associated with a key.
/// The key must be present in the map.
pub fn getPtrAssertContains(self: *Self, key: Key) *Value {
const index = Indexer.indexOf(key);
assert(self.bits.isSet(index));
return &self.values[index];
}
/// Adds the key to the map with the supplied value.
/// If the key is already in the map, overwrites the value.
pub fn put(self: *Self, key: Key, value: Value) void {
const index = Indexer.indexOf(key);
self.bits.set(index);
self.values[index] = value;
}
/// Adds the key to the map with an undefined value.
/// If the key is already in the map, the value becomes undefined.
/// A pointer to the value is returned, which should be
/// used to initialize the value.
pub fn putUninitialized(self: *Self, key: Key) *Value {
const index = Indexer.indexOf(key);
self.bits.set(index);
self.values[index] = undefined;
return &self.values[index];
}
/// Sets the value associated with the key in the map,
/// and returns the old value. If the key was not in
/// the map, returns null.
pub fn fetchPut(self: *Self, key: Key, value: Value) ?Value {
const index = Indexer.indexOf(key);
const result: ?Value = if (self.bits.isSet(index)) self.values[index] else null;
self.bits.set(index);
self.values[index] = value;
return result;
}
/// Removes a key from the map. If the key was not in the map,
/// does nothing.
pub fn remove(self: *Self, key: Key) void {
const index = Indexer.indexOf(key);
self.bits.unset(index);
self.values[index] = undefined;
}
/// Removes a key from the map, and returns the old value.
/// If the key was not in the map, returns null.
pub fn fetchRemove(self: *Self, key: Key) ?Value {
const index = Indexer.indexOf(key);
const result: ?Value = if (self.bits.isSet(index)) self.values[index] else null;
self.bits.unset(index);
self.values[index] = undefined;
return result;
}
/// Returns an iterator over the map, which visits items in index order.
/// Modifications to the underlying map may or may not be observed by
/// the iterator, but will not invalidate it.
pub fn iterator(self: *Self) Iterator {
return .{
.inner = self.bits.iterator(.{}),
.values = &self.values,
};
}
/// An entry in the map.
pub const Entry = struct {
/// The key associated with this entry.
/// Modifying this key will not change the map.
key: Key,
/// A pointer to the value in the map associated
/// with this key. Modifications through this
/// pointer will modify the underlying data.
value: *Value,
};
pub const Iterator = struct {
inner: BitSet.Iterator(.{}),
values: *[Indexer.count]Value,
pub fn next(self: *Iterator) ?Entry {
return if (self.inner.next()) |index|
Entry{
.key = Indexer.keyForIndex(index),
.value = &self.values[index],
}
else
null;
}
};
};
}
/// A dense array of values, using an indexed lookup.
/// This type does no allocation and can be copied by value.
pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type) type) type {
comptime ensureIndexer(I);
return struct {
const Self = @This();
pub usingnamespace Ext(Self);
/// The index mapping for this map
pub const Indexer = I;
/// The key type used to index this map
pub const Key = Indexer.Key;
/// The value type stored in this map
pub const Value = V;
/// The number of possible keys in the map
pub const len = Indexer.count;
values: [Indexer.count]Value,
pub fn initUndefined() Self {
return Self{ .values = undefined };
}
pub fn initFill(v: Value) Self {
var self: Self = undefined;
std.mem.set(Value, &self.values, v);
return self;
}
/// Returns the value in the array associated with a key.
pub fn get(self: Self, key: Key) Value {
return self.values[Indexer.indexOf(key)];
}
/// Returns a pointer to the slot in the array associated with a key.
pub fn getPtr(self: *Self, key: Key) *Value {
return &self.values[Indexer.indexOf(key)];
}
/// Returns a const pointer to the slot in the array associated with a key.
pub fn getPtrConst(self: *const Self, key: Key) *const Value {
return &self.values[Indexer.indexOf(key)];
}
/// Sets the value in the slot associated with a key.
pub fn set(self: *Self, key: Key, value: Value) void {
self.values[Indexer.indexOf(key)] = value;
}
/// Iterates over the items in the array, in index order.
pub fn iterator(self: *Self) Iterator {
return .{
.values = &self.values,
};
}
/// An entry in the array.
pub const Entry = struct {
/// The key associated with this entry.
/// Modifying this key will not change the array.
key: Key,
/// A pointer to the value in the array associated
/// with this key. Modifications through this
/// pointer will modify the underlying data.
value: *Value,
};
pub const Iterator = struct {
index: usize = 0,
values: *[Indexer.count]Value,
pub fn next(self: *Iterator) ?Entry {
const index = self.index;
if (index < Indexer.count) {
self.index += 1;
return Entry{
.key = Indexer.keyForIndex(index),
.value = &self.values[index],
};
}
return null;
}
};
};
}
/// Verifies that a type is a valid Indexer, providing a helpful
/// compile error if not. An Indexer maps a comptime known set
/// of keys to a dense set of zero-based indices.
/// The indexer interface must look like this:
/// ```
/// struct {
/// /// The key type which this indexer converts to indices
/// pub const Key: type,
/// /// The number of indexes in the dense mapping
/// pub const count: usize,
/// /// Converts from a key to an index
/// pub fn indexOf(Key) usize;
/// /// Converts from an index to a key
/// pub fn keyForIndex(usize) Key;
/// }
/// ```
pub fn ensureIndexer(comptime T: type) void {
comptime {
if (!@hasDecl(T, "Key")) @compileError("Indexer must have decl Key: type.");
if (@TypeOf(T.Key) != type) @compileError("Indexer.Key must be a type.");
if (!@hasDecl(T, "count")) @compileError("Indexer must have decl count: usize.");
if (@TypeOf(T.count) != usize) @compileError("Indexer.count must be a usize.");
if (!@hasDecl(T, "indexOf")) @compileError("Indexer.indexOf must be a fn(Key)usize.");
if (@TypeOf(T.indexOf) != fn (T.Key) usize) @compileError("Indexer must have decl indexOf: fn(Key)usize.");
if (!@hasDecl(T, "keyForIndex")) @compileError("Indexer must have decl keyForIndex: fn(usize)Key.");
if (@TypeOf(T.keyForIndex) != fn (usize) T.Key) @compileError("Indexer.keyForIndex must be a fn(usize)Key.");
}
}
test "std.enums.ensureIndexer" {
ensureIndexer(struct {
pub const Key = u32;
pub const count: usize = 8;
pub fn indexOf(k: Key) usize {
return @intCast(usize, k);
}
pub fn keyForIndex(index: usize) Key {
return @intCast(Key, index);
}
});
}
fn ascByValue(ctx: void, comptime a: EnumField, comptime b: EnumField) bool {
_ = ctx;
return a.value < b.value;
}
pub fn EnumIndexer(comptime E: type) type {
if (!@typeInfo(E).Enum.is_exhaustive) {
@compileError("Cannot create an enum indexer for a non-exhaustive enum.");
}
const const_fields = std.meta.fields(E);
var fields = const_fields[0..const_fields.len].*;
if (fields.len == 0) {
return struct {
pub const Key = E;
pub const count: usize = 0;
pub fn indexOf(e: E) usize {
_ = e;
unreachable;
}
pub fn keyForIndex(i: usize) E {
_ = i;
unreachable;
}
};
}
std.sort.sort(EnumField, &fields, {}, ascByValue);
const min = fields[0].value;
const max = fields[fields.len - 1].value;
const fields_len = fields.len;
if (max - min == fields.len - 1) {
return struct {
pub const Key = E;
pub const count = fields_len;
pub fn indexOf(e: E) usize {
return @intCast(usize, @enumToInt(e) - min);
}
pub fn keyForIndex(i: usize) E {
// TODO fix addition semantics. This calculation
// gives up some safety to avoid artificially limiting
// the range of signed enum values to max_isize.
const enum_value = if (min < 0) @bitCast(isize, i) +% min else i + min;
return @intToEnum(E, @intCast(std.meta.Tag(E), enum_value));
}
};
}
const keys = valuesFromFields(E, &fields);
return struct {
pub const Key = E;
pub const count = fields_len;
pub fn indexOf(e: E) usize {
for (keys) |k, i| {
if (k == e) return i;
}
unreachable;
}
pub fn keyForIndex(i: usize) E {
return keys[i];
}
};
}
test "std.enums.EnumIndexer dense zeroed" {
const E = enum(u2) { b = 1, a = 0, c = 2 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
try testing.expectEqual(E, Indexer.Key);
try testing.expectEqual(@as(usize, 3), Indexer.count);
try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
try testing.expectEqual(E.a, Indexer.keyForIndex(0));
try testing.expectEqual(E.b, Indexer.keyForIndex(1));
try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer dense positive" {
const E = enum(u4) { c = 6, a = 4, b = 5 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
try testing.expectEqual(E, Indexer.Key);
try testing.expectEqual(@as(usize, 3), Indexer.count);
try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
try testing.expectEqual(E.a, Indexer.keyForIndex(0));
try testing.expectEqual(E.b, Indexer.keyForIndex(1));
try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer dense negative" {
const E = enum(i4) { a = -6, c = -4, b = -5 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
try testing.expectEqual(E, Indexer.Key);
try testing.expectEqual(@as(usize, 3), Indexer.count);
try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
try testing.expectEqual(E.a, Indexer.keyForIndex(0));
try testing.expectEqual(E.b, Indexer.keyForIndex(1));
try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer sparse" {
const E = enum(i4) { a = -2, c = 6, b = 4 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
try testing.expectEqual(E, Indexer.Key);
try testing.expectEqual(@as(usize, 3), Indexer.count);
try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
try testing.expectEqual(E.a, Indexer.keyForIndex(0));
try testing.expectEqual(E.b, Indexer.keyForIndex(1));
try testing.expectEqual(E.c, Indexer.keyForIndex(2));
} | lib/std/enums.zig |
const std = @import("std");
const process = std.process;
const elf = std.elf;
const fs = std.fs;
const io = std.io;
const mem = std.mem;
const Allocator = std.mem.Allocator;
const ArrayList = std.ArrayList;
const HashMap = std.HashMap;
const AppError = error{
SymsSectionNotFound,
StrtabSectionNotFound,
UnexpectedEof,
};
pub fn main() !void {
// Since this is a short-lived program, we deliberately leak memory.
// In case we want to release something, use the C allocator.
const allocator = std.heap.c_allocator;
const args = try process.argsAlloc(allocator);
// The input ELF file
var input_file = try fs.File.openRead(args[1]);
defer input_file.close();
var input_stream = FileStream.new(&input_file);
var input_elf = try elf.Elf.openStream(
allocator,
&input_stream.seekable,
&input_stream.in,
);
// Read the symbol table.
// We currently assume the object file is in the little-endian format.
const syms_hdr = (try input_elf.findSection(".symtab")) orelse
return AppError.SymsSectionNotFound;
try input_file.seekTo(syms_hdr.offset);
const Sym = struct {
addr: u32,
name_offset: u32,
name: []u8,
};
const syms = try allocator.alloc(Sym, syms_hdr.size / @sizeOf(elf.Elf32_Sym));
for (syms) |*sym| {
var elf_sym: elf.Elf32_Sym = undefined;
const num_read = try input_file.read(@ptrCast([*]u8, &elf_sym)[0..@sizeOf(elf.Elf32_Sym)]);
if (num_read < @sizeOf(elf.Elf32_Sym)) {
return AppError.UnexpectedEof;
}
sym.addr = elf_sym.st_value;
sym.name_offset = elf_sym.st_name;
}
const strtab_hdr = (try input_elf.findSection(".strtab")) orelse
return AppError.SymsSectionNotFound;
for (syms) |*sym| {
sym.name = try getString(allocator, &input_elf, strtab_hdr, sym.name_offset);
}
// Create a hash set of symbol names to be exported.
var entry_sym_map = StringSet.init(allocator);
const entry_prefix = "__acle_se_";
for (syms) |*sym| {
if (mem.startsWith(u8, sym.name, entry_prefix)) {
const bare_name = sym.name[entry_prefix.len..];
_ = try entry_sym_map.put(bare_name, {});
}
}
// The output file
// (Ideally this could be stdout, but `build.zig` doesn't let us redirect it.)
const output_file = try fs.File.openWrite(args[2]);
var output_stream = output_file.outStream();
defer output_stream.file.close();
try output_stream.stream.write(".syntax unified\n");
for (syms) |*sym| {
if (!entry_sym_map.contains(sym.name)) {
continue;
}
try output_stream.stream.print(".set {}, 0x{x}\n", sym.name, sym.addr);
try output_stream.stream.print(".global {}\n", sym.name);
}
}
fn getString(allocator: *Allocator, e: *elf.Elf, strtab: *const elf.SectionHeader, at: u32) ![]u8 {
var list = ArrayList(u8).init(allocator);
errdefer list.deinit();
const name_offset = strtab.offset + at;
try e.seekable_stream.seekTo(name_offset);
while (true) {
const b = try e.in_stream.readByte();
if (b == 0) {
break;
}
try list.append(b);
}
return list.toOwnedSlice();
}
fn stringEql(a: []const u8, b: []const u8) bool {
if (a.len != b.len) return false;
if (a.ptr == b.ptr) return true;
return mem.compare(u8, a, b) == .Equal;
}
fn stringHash(s: []const u8) u32 {
return @truncate(u32, std.hash.Wyhash.hash(0, s));
}
const StringSet = HashMap([]const u8, void, stringHash, stringEql);
const AnyerrorSeekableStream = io.SeekableStream(anyerror, anyerror);
const AnyerrorInStream = io.InStream(anyerror);
const FileStream = struct {
file: *fs.File,
seekable: AnyerrorSeekableStream,
in: AnyerrorInStream,
const Self = @This();
fn new(file: *fs.File) Self {
return Self{
.file = file,
.seekable = AnyerrorSeekableStream{
.seekToFn = seekToFn,
.seekByFn = seekByFn,
.getPosFn = getPosFn,
.getEndPosFn = getEndPosFn,
},
.in = AnyerrorInStream{
.readFn = readFn,
},
};
}
fn readFn(in_stream: *AnyerrorInStream, buffer: []u8) anyerror!usize {
const self = @fieldParentPtr(FileStream, "in", in_stream);
return self.file.read(buffer);
}
fn seekToFn(seekable_stream: *AnyerrorSeekableStream, pos: u64) anyerror!void {
const self = @fieldParentPtr(FileStream, "seekable", seekable_stream);
return self.file.seekTo(pos);
}
fn seekByFn(seekable_stream: *AnyerrorSeekableStream, amt: i64) anyerror!void {
const self = @fieldParentPtr(FileStream, "seekable", seekable_stream);
return self.file.seekBy(amt);
}
fn getEndPosFn(seekable_stream: *AnyerrorSeekableStream) anyerror!u64 {
const self = @fieldParentPtr(FileStream, "seekable", seekable_stream);
return self.file.getEndPos();
}
fn getPosFn(seekable_stream: *AnyerrorSeekableStream) anyerror!u64 {
const self = @fieldParentPtr(FileStream, "seekable", seekable_stream);
return self.file.getPos();
}
}; | tools/mkimplib.zig |
const std = @import("std");
pub const Ripemd160 = struct {
bytes: [160 / 8]u8,
pub fn hash(str: []const u8) Ripemd160 {
var res: Ripemd160 = undefined;
var temp: [5]u32 = .{ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 };
var ptr = str.ptr;
{ // compress string in 16-word chunks
var i = str.len / 64;
while (i > 0) : (i -= 1) {
var chunk: [16]u32 = [_]u32{0} ** 16;
var j: usize = 0;
while (j < 16) : (j += 1) {
chunk[j] = std.mem.readIntLittle(u32, ptr[0..4]);
ptr += 4;
}
compress(&temp, chunk);
}
}
{ // compress remaining string, (str.len % 64) bytes
var chunk: [16]u32 = [_]u32{0} ** 16;
var i: usize = 0;
while (i < (str.len & 63)) : (i += 1) {
chunk[i >> 2] ^= (@intCast(u32, ptr[0]) << @intCast(u5, 8 * (i & 3)));
ptr += 1;
}
chunk[(str.len >> 2) & 15] ^= @as(u32, 1) << @intCast(u5, 8 * (str.len & 3) + 7);
if ((str.len & 63) > 55) {
compress(&temp, chunk);
chunk = [_]u32{0} ** 16;
}
chunk[14] = @intCast(u32, str.len << 3);
chunk[15] = @intCast(u32, (str.len >> 29) | (0 << 3));
compress(&temp, chunk);
}
{ // write final hash
var i: usize = 0;
while (i < 160 / 8) : (i += 4) {
std.mem.writeIntLittle(u32, @ptrCast(*[4]u8, &res.bytes[i]), temp[i >> 2]);
}
}
return res;
}
};
fn compress(hash: *[5]u32, words: [16]u32) void {
const permutations: [10][16]u5 = .{
.{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
.{ 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8 },
.{ 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12 },
.{ 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2 },
.{ 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 },
.{ 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12 },
.{ 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2 },
.{ 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13 },
.{ 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14 },
.{ 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 },
};
const shifts: [10][16]u5 = .{
.{ 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8 },
.{ 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12 },
.{ 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5 },
.{ 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12 },
.{ 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 },
.{ 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6 },
.{ 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11 },
.{ 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5 },
.{ 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8 },
.{ 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 },
};
var left: [5]u32 = undefined;
var right: [5]u32 = undefined;
std.mem.copy(u32, left[0..], hash[0..5]);
std.mem.copy(u32, right[0..], hash[0..5]);
round(bfn1, -0, 0x00000000, permutations[0], shifts[0], &left, words);
round(bfn2, -1, 0x5a827999, permutations[1], shifts[1], &left, words);
round(bfn3, -2, 0x6ed9eba1, permutations[2], shifts[2], &left, words);
round(bfn4, -3, 0x8f1bbcdc, permutations[3], shifts[3], &left, words);
round(bfn5, -4, 0xa953fd4e, permutations[4], shifts[4], &left, words);
round(bfn5, -0, 0x50a28be6, permutations[5], shifts[5], &right, words);
round(bfn4, -1, 0x5c4dd124, permutations[6], shifts[6], &right, words);
round(bfn3, -2, 0x6d703ef3, permutations[7], shifts[7], &right, words);
round(bfn2, -3, 0x7a6d76e9, permutations[8], shifts[8], &right, words);
round(bfn1, -4, 0x00000000, permutations[9], shifts[9], &right, words);
right[3] = right[3] +% left[2] +% hash[1];
hash[1] = hash[2] +% left[3] +% right[4];
hash[2] = hash[3] +% left[4] +% right[0];
hash[3] = hash[4] +% left[0] +% right[1];
hash[4] = hash[0] +% left[1] +% right[2];
hash[0] = right[3];
}
fn round(
comptime bfn: fn (u32, u32, u32) u32,
comptime off: i32,
comptime constant: u32,
comptime p: [16]u5,
comptime shifts: [16]u5,
hash: *[5]u32,
words: [16]u32,
) void {
comptime var r = off;
comptime var i: usize = 0;
inline while (i < 16) : (i += 1) {
hash[@mod(r + 0, 5)] = hash[@mod(r + 0, 5)] +% bfn(hash[@mod(r + 1, 5)], hash[@mod(r + 2, 5)], hash[@mod(r + 3, 5)]) +% words[p[i]] +% constant;
hash[@mod(r + 0, 5)] = std.math.rotl(u32, hash[@mod(r + 0, 5)], @intCast(u32, shifts[i])) +% hash[@mod(r + 4, 5)];
hash[@mod(r + 2, 5)] = std.math.rotl(u32, hash[@mod(r + 2, 5)], 10);
r -= 1;
}
}
fn bfn1(x: u32, y: u32, z: u32) u32 {
return x ^ y ^ z;
}
fn bfn2(x: u32, y: u32, z: u32) u32 {
return (x & y) | (~x & z);
}
fn bfn3(x: u32, y: u32, z: u32) u32 {
return (x | ~y) ^ z;
}
fn bfn4(x: u32, y: u32, z: u32) u32 {
return (x & z) | (y & ~z);
}
fn bfn5(x: u32, y: u32, z: u32) u32 {
return x ^ (y | ~z);
}
fn testHashEql(expected: []const u8, in: []const u8) !void {
const hash = Ripemd160.hash(in);
var hex_str: [40]u8 = undefined;
_ = try std.fmt.bufPrint(&hex_str, "{x}", .{std.fmt.fmtSliceHexLower(hash.bytes[0..])});
try std.testing.expectEqualSlices(u8, expected, hex_str[0..]);
}
test "RIPEMD-160 standard tests" {
try testHashEql("9c1185a5c5e9fc54612808977ee8f548b2258d31", "");
try testHashEql("0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", "a");
try testHashEql("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", "abc");
try testHashEql("5d0689ef49d2fae572b881b123a85ffa21595f36", "message digest");
try testHashEql("f71c27109c692c1b56bbdceb5b9d2865b3708dbc", "abcdefghijklmnopqrstuvwxyz");
try testHashEql("12a053384a9c0c88e405a06c27dcf49ada62eb2b", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
try testHashEql("b0e20b6e3116640286ed3a87a5713079b21f5189", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
try testHashEql("9b752e45573d4b39f4dbd3323cab82bf63326bfb", "1234567890" ** 8);
try testHashEql("52783243c1697bdbe16d37f97f68f08325dc1528", "a" ** 1000000);
} | lib/std/crypto/ripemd160.zig |
const std = @import("std");
const io = std.io;
pub const ogg_stream_marker = "OggS";
// From 'header_type_flag' of https://xiph.org/ogg/doc/framing.html
// Potentially useful for the below
// "TODO: validate header type flag potentially"
//const fresh_packet = 0x00;
//const first_page_of_logical_bitstream = 0x02;
/// A wrapping reader that reads (and skips past) Ogg page headers and returns the
/// data within them
pub fn OggPageReader(comptime ReaderType: type) type {
return struct {
child_reader: ReaderType,
read_state: ReadState = .header,
data_remaining: usize = 0,
const ReadState = enum {
header,
data,
};
pub const OggHeaderReadError = error{
InvalidStreamMarker,
UnknownStreamStructureVersion,
ZeroLengthPage,
};
pub const Error = error{EndOfStream} || OggHeaderReadError || ReaderType.Error;
pub const Reader = io.Reader(*Self, Error, read);
const Self = @This();
pub fn read(self: *Self, dest: []u8) Error!usize {
var num_read: usize = 0;
while (true) {
switch (self.read_state) {
.header => {
var stream_marker = try self.child_reader.readBytesNoEof(4);
if (!std.mem.eql(u8, stream_marker[0..], ogg_stream_marker)) {
return error.InvalidStreamMarker;
}
const stream_structure_version = try self.child_reader.readByte();
if (stream_structure_version != 0) {
return error.UnknownStreamStructureVersion;
}
// TODO: validate header type flag potentially
_ = try self.child_reader.readByte();
// absolute granule position + stream serial number + page sequence number + page checksum
const bytes_to_skip = 8 + 4 + 4 + 4;
try self.child_reader.skipBytes(bytes_to_skip, .{ .buf_size = bytes_to_skip });
const page_segments = try self.child_reader.readByte();
if (page_segments == 0) {
return error.ZeroLengthPage;
}
var segment_table_buf: [255]u8 = undefined;
const segment_table = segment_table_buf[0..page_segments];
try self.child_reader.readNoEof(segment_table);
// max is 255 * 255
var length: u16 = 0;
for (segment_table) |val| {
length += val;
}
if (length == 0) {
return error.ZeroLengthPage;
}
self.read_state = .data;
self.data_remaining = length;
},
.data => {
while (self.data_remaining > 0 and num_read < dest.len) {
const byte = try self.child_reader.readByte();
dest[num_read] = byte;
num_read += 1;
self.data_remaining -= 1;
}
if (num_read == dest.len) {
break;
} else {
self.read_state = .header;
}
},
}
}
return num_read;
}
pub fn reader(self: *Self) Reader {
return .{ .context = self };
}
};
}
pub fn oggPageReader(underlying_stream: anytype) OggPageReader(@TypeOf(underlying_stream)) {
return .{ .child_reader = underlying_stream };
} | src/ogg.zig |
const std = @import("std");
const fmt = std.fmt;
const io = std.io;
const mem = std.mem;
const process = std.process;
var gpa_allocator = std.heap.GeneralPurposeAllocator(.{}){};
var is_zus_paid_in_full: bool = false;
var is_second_clif: bool = false;
fn usage() !void {
const msg =
\\Usage: pit <gross_income> [-r]
\\ pit -f <file_path> [-r]
\\ pit -h,--help
\\
\\General options:
\\-f Parse gross income from text file
\\-r Apply tax relief
\\-h, --help Print this help message and exit
;
return io.getStdOut().writeAll(msg);
}
fn fatal(comptime format: []const u8, args: anytype) noreturn {
const msg = fmt.allocPrint(gpa_allocator.allocator(), "fatal: " ++ format ++ "\n", args) catch process.exit(1);
defer gpa_allocator.allocator().free(msg);
io.getStdErr().writeAll(msg) catch process.exit(1);
process.exit(1);
}
pub fn main() anyerror!void {
var arena_allocator = std.heap.ArenaAllocator.init(gpa_allocator.allocator());
defer arena_allocator.deinit();
const arena = arena_allocator.allocator();
const args = try process.argsAlloc(arena);
if (args.len == 1) {
fatal("no arguments specified", .{});
}
var input_file: ?[]const u8 = null;
var gross_income: f32 = 0;
var use_relief: bool = false;
var i: usize = 1;
while (i < args.len) : (i += 1) {
const arg = args[i];
if (mem.eql(u8, arg, "-f")) {
if (args.len == i + 1) fatal("expected argument after '-f'", .{});
input_file = args[i + 1];
i += 1;
} else if (mem.eql(u8, arg, "-r")) {
use_relief = true;
} else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
try usage();
return;
} else {
gross_income = @intToFloat(f32, try fmt.parseInt(u32, args[1], 10));
}
}
const standard_income_cost: f32 = 250.0;
var month: usize = 0;
var prev_income_sum: f32 = 0;
var prev_tax_sum: f32 = 0;
while (month < 12) : ({
month += 1;
prev_income_sum += gross_income;
}) {
const zus_due = calcZus(gross_income, prev_income_sum);
const health_ins_due = (gross_income - zus_due) * 0.09;
const tax_relief = if (use_relief) calcRelief(gross_income) else 0;
const tax_base = gross_income - zus_due - standard_income_cost - tax_relief;
const tax_due = calcTax(tax_base, prev_tax_sum);
const net_pay = gross_income - zus_due - health_ins_due - tax_due;
prev_tax_sum += tax_base;
std.log.info("{d}: gross = {d:.4}, zus = {d:.4}, health = {d:.4}, tax_relief = {d:.4}, tax_base = {d:.4}, tax_due = {d:.4}, net = {d:.4}", .{
month + 1,
gross_income,
zus_due,
health_ins_due,
tax_relief,
tax_base,
tax_due,
net_pay,
});
}
}
fn calcZus(gross_income: f32, prev_income_sum: f32) f32 {
const max_zus: f32 = 177660;
const zus_calc_base: f32 = if (prev_income_sum + gross_income > max_zus) blk: {
if (is_zus_paid_in_full)
break :blk 0;
is_zus_paid_in_full = true;
break :blk max_zus - prev_income_sum;
} else gross_income;
return zus_calc_base * (0.0976 + 0.015) + gross_income * 0.0245;
}
fn calcTax(tax_base: f32, prev_tax_sum: f32) f32 {
const clif: f32 = 120000;
const tax: f32 = if (tax_base + prev_tax_sum > clif) blk: {
if (is_second_clif)
break :blk tax_base * 0.32;
is_second_clif = true;
break :blk (clif - prev_tax_sum) * 0.17 + (tax_base - clif + prev_tax_sum) * 0.32;
} else tax_base * 0.17;
return if (tax - 425 < 0) 0 else tax - 425;
}
fn calcRelief(gross_income: f32) f32 {
const relief: f32 = blk: {
if (gross_income >= 5701 and gross_income < 8549) {
break :blk (gross_income * 0.0668 - 380.50) / 0.17;
} else if (gross_income >= 8549 and gross_income < 11141) {
break :blk (gross_income * (-0.0735) + 819.08) / 0.17;
}
break :blk 0;
};
return relief;
} | src/main.zig |
const std = @import("std");
/// Because the lexer has already validated that strings don't contain
/// any invalid characters, this function can be implemented without
/// the possibility of failure. Any failures are a bug in the lexer.
///
/// dest_buf must be at least as big as source to ensure it is large enough
/// to hold the parsed string
/// TODO: should this function be part of lex.Token instead?
pub fn parseString(source_raw: []const u8, dest_buf: []u8) []u8 {
std.debug.assert(dest_buf.len >= source_raw.len);
var source: []const u8 = source_raw[0..];
// trim the start/end delimeters
var delim_len: usize = undefined;
var is_long_string: bool = false;
var skip_first_char: bool = false;
switch (source[0]) {
'\'', '"' => delim_len = 1,
'[' => {
var num_sep: usize = 0;
while (source[1 + num_sep] == '=') : (num_sep += 1) {}
std.debug.assert(source[1 + num_sep] == '[');
delim_len = 2 + num_sep;
is_long_string = true;
// if the first line of a long string is a newline char, it gets skipped
skip_first_char = source[delim_len] == '\r' or source[delim_len] == '\n';
},
else => unreachable,
}
source = source[delim_len .. source.len - delim_len];
if (skip_first_char) source = source[1..];
// like std.io.FixedBufferStream but no need to check bounds of slice
// and can only append 1 character at a time
const SliceWriter = struct {
const Self = @This();
pos: usize = 0,
slice: []u8,
fn write(self: *Self, char: u8) void {
self.slice[self.pos] = char;
self.pos += 1;
}
fn getWritten(self: Self) []u8 {
return self.slice[0..self.pos];
}
};
const State = enum {
normal,
escaped,
escaped_numerals,
escaped_line_endings,
};
var writer = SliceWriter{ .slice = dest_buf };
var string_escape_n: u8 = 0;
var string_escape_i: std.math.IntFittingRange(0, 3) = 0;
var state: State = State.normal;
var index: usize = 0;
while (index < source.len) : (index += 1) {
const c = source[index];
switch (state) {
State.normal => switch (c) {
// Lua's string parser transforms all \r to \n
'\r' => writer.write('\n'),
'\\' => state = State.escaped,
else => writer.write(c),
},
State.escaped => switch (c) {
'0'...'9' => {
string_escape_n = c - '0';
string_escape_i = 1;
state = State.escaped_numerals;
},
'\r', '\n' => {
// escaped \r and \n get transformed to \n
writer.write('\n');
state = State.escaped_line_endings;
},
else => {
switch (c) {
'a' => writer.write('\x07'),
'b' => writer.write('\x08'),
'f' => writer.write('\x0C'),
'n' => writer.write('\n'),
'r' => writer.write('\r'),
't' => writer.write('\t'),
'v' => writer.write('\x0B'),
else => writer.write(c),
}
state = State.normal;
},
},
State.escaped_numerals => switch (c) {
'0'...'9' => {
string_escape_n = 10 * string_escape_n + (c - '0');
string_escape_i += 1;
if (string_escape_i == 3) {
writer.write(string_escape_n);
state = State.normal;
}
},
else => {
writer.write(string_escape_n);
// backtrack so that we handle the current char properly
index -= 1;
state = State.normal;
},
},
State.escaped_line_endings => switch (c) {
'\r', '\n' => {
state = State.normal;
},
else => {
// backtrack so that we handle the current char properly
index -= 1;
state = State.normal;
},
},
}
}
// we could be in a state that still needs processing here,
// since we could have hit the end of the string while unsure
// if a \ddd pattern was finished
switch (state) {
State.escaped_numerals => {
writer.write(string_escape_n);
},
State.normal,
State.escaped_line_endings,
=> {},
else => unreachable,
}
return writer.getWritten();
}
test "parseString" {
var buf_arr: [100]u8 = undefined;
var buf: []u8 = buf_arr[0..];
try std.testing.expectEqualSlices(u8, "hello", parseString("'hello'", buf));
try std.testing.expectEqualSlices(u8, "hello", parseString("\"hello\"", buf));
try std.testing.expectEqualSlices(u8, "hello", parseString("[[hello]]", buf));
try std.testing.expectEqualSlices(u8, "hello", parseString("[=[hello]=]", buf));
try std.testing.expectEqualSlices(u8, "hello", parseString("[===[hello]===]", buf));
try std.testing.expectEqualSlices(u8, "\\ \n \x0B", parseString("'\\\\ \\n \\v'", buf));
// long strings skip initial newline
try std.testing.expectEqualSlices(u8, "hello", parseString("[[\nhello]]", buf));
try std.testing.expectEqualSlices(u8, "\nhello", parseString("[[\r\rhello]]", buf));
// escaped \r gets transformed into \n
try std.testing.expectEqualSlices(u8, "\n", parseString("\"\\\r\"", buf));
// escaped newlines and newline pairs
try std.testing.expectEqualSlices(u8, "\n\\ ", parseString("\"\\\r\\\\ \"", buf));
try std.testing.expectEqualSlices(u8, "\n\\ ", parseString("\"\\\r\n\\\\ \"", buf));
try std.testing.expectEqualSlices(u8, "\n", parseString("\"\\\n\r\"", buf));
// escaped numerals
try std.testing.expectEqualSlices(u8, "\x01-\x02", parseString("\"\\1-\\2\"", buf));
}
// FIXME: this is not even close to 1:1 compatible with Lua's number parsing
// since Lua's number parsing uses strtod. This should work for most
// simple numbers, though
// TODO: should this be able to fail?
pub fn parseNumber(source: []const u8) f64 {
// TODO: use a strtod-compatible function
// Related Zig issues:
// https://github.com/ziglang/zig/issues/2207
// https://github.com/ziglang/zig/issues/2047
if (std.fmt.parseFloat(f64, source)) |number| {
return number;
} else |err| switch (err) {
error.InvalidCharacter => {},
}
if (source[0] == '0' and (source[1] == 'x' or source[1] == 'X')) {
if (std.fmt.parseUnsigned(u64, source[2..], 16)) |number| {
return @intToFloat(f64, number);
} else |err| switch (err) {
error.InvalidCharacter => unreachable,
error.Overflow => return std.math.inf(f64),
}
}
// FIXME: this is probably a bad way to handle this
return std.math.nan(f64);
}
test "parseNumber decimal" {
try std.testing.expectEqual(@as(f64, 1.0), parseNumber("1"));
try std.testing.expectEqual(@as(f64, 2000.0), parseNumber("2e3"));
try std.testing.expectEqual(@as(f64, 1234.0), parseNumber("1.234e3"));
}
test "parseNumber hex" {
try std.testing.expectEqual(@as(f64, 0x0), parseNumber("0x0"));
try std.testing.expectEqual(@as(f64, 0xf), parseNumber("0xf"));
// strtod in C99 handles hex digits
// this would overflow with the strtoul fallback
//try std.testing.expectEqual(@as(f64, 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff), parseNumber("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
// because Lua uses strtod internally, it actually can accept
// hex constants with a power exponent (denoted by p)
// FIXME: allow this pattern in the lexer once parseNumber can handle it
//try std.testing.expectEqual(@as(f64, 1020), parseNumber("0xffp2"));
} | src/parse_literal.zig |
const zfltk = @import("zfltk");
const app = zfltk.app;
const widget = zfltk.widget;
const window = zfltk.window;
const menu = zfltk.menu;
const enums = zfltk.enums;
const text = zfltk.text;
const dialog = zfltk.dialog;
pub const Message = enum(usize) {
// Can't begin with 0
New = 1,
Open,
Save,
Quit,
Cut,
Copy,
Paste,
About,
};
// To avoid exiting when hitting escape.
// Also logic can be added to prompt the user to save their work
pub fn winCb(w: widget.WidgetPtr, data: ?*c_void) callconv(.C) void {
_ = w;
_ = data;
if (app.event() == enums.Event.Close) {
app.send(Message, .Quit);
}
}
pub fn main() !void {
try app.init();
app.setScheme(.Gtk);
app.background(211, 211, 211);
var win = window.Window.new(0, 0, 800, 600, "Editor");
win.freePosition();
var mymenu = menu.MenuBar.new(0, 0, 800, 35, "");
var buf = text.TextBuffer.new();
defer buf.delete();
var editor = text.TextEditor.new(2, 37, 800 - 2, 600 - 37, "");
editor.asTextDisplay().setBuffer(&buf);
editor.asTextDisplay().setLinenumberWidth(24);
win.asGroup().end();
win.asWidget().show();
win.asWidget().setCallback(winCb, null);
mymenu.asMenu().add_emit(
"&File/New...\t",
enums.Shortcut.Ctrl | 'n',
.Normal,
Message,
.New,
);
mymenu.asMenu().add_emit(
"&File/Open...\t",
enums.Shortcut.Ctrl | 'o',
.Normal,
Message,
.Open,
);
mymenu.asMenu().add_emit(
"&File/Save...\t",
enums.Shortcut.Ctrl | 's',
.MenuDivider,
Message,
.Save,
);
mymenu.asMenu().add_emit(
"&File/Quit...\t",
enums.Shortcut.Ctrl | 'q',
.Normal,
Message,
.Quit,
);
mymenu.asMenu().add_emit(
"&Edit/Cut...\t",
enums.Shortcut.Ctrl | 'x',
.Normal,
Message,
.Cut,
);
mymenu.asMenu().add_emit(
"&Edit/Copy...\t",
enums.Shortcut.Ctrl | 'c',
.Normal,
Message,
.Copy,
);
mymenu.asMenu().add_emit(
"&Edit/Paste...\t",
enums.Shortcut.Ctrl | 'v',
.Normal,
Message,
.Paste,
);
mymenu.asMenu().add_emit(
"&Help/About...\t",
enums.Shortcut.Ctrl | 'q',
.Normal,
Message,
.About,
);
var item = mymenu.asMenu().findItem("&File/Quit...\t");
item.setLabelColor(enums.Color.Red);
while (app.wait()) {
if (app.recv(Message)) |msg| switch (msg) {
.New => buf.setText(""),
.Open => {
var dlg = dialog.NativeFileDialog.new(.BrowseFile);
dlg.setFilter("*.{txt,zig}");
dlg.show();
var fname = dlg.filename();
if (fname != null) {
_ = buf.loadFile(fname) catch unreachable;
}
},
.Save => {
var dlg = dialog.NativeFileDialog.new(.BrowseSaveFile);
dlg.setFilter("*.{txt,zig}");
dlg.show();
var fname = dlg.filename();
if (fname != null) {
_ = buf.saveFile(fname) catch unreachable;
}
},
.Quit => win.asWidget().hide(),
.Cut => editor.cut(),
.Copy => editor.copy(),
.Paste => editor.paste(),
.About => dialog.message(300, 200, "This editor was built using fltk and zig!"),
};
}
} | examples/editormsgs.zig |
//--------------------------------------------------------------------------------
// Section: Types (3)
//--------------------------------------------------------------------------------
pub const HARDWARE_COUNTER_TYPE = enum(i32) {
PMCCounter = 0,
MaxHardwareCounterType = 1,
};
pub const PMCCounter = HARDWARE_COUNTER_TYPE.PMCCounter;
pub const MaxHardwareCounterType = HARDWARE_COUNTER_TYPE.MaxHardwareCounterType;
pub const HARDWARE_COUNTER_DATA = extern struct {
Type: HARDWARE_COUNTER_TYPE,
Reserved: u32,
Value: u64,
};
pub const PERFORMANCE_DATA = extern struct {
Size: u16,
Version: u8,
HwCountersCount: u8,
ContextSwitchCount: u32,
WaitReasonBitMap: u64,
CycleTime: u64,
RetryCount: u32,
Reserved: u32,
HwCounters: [16]HARDWARE_COUNTER_DATA,
};
//--------------------------------------------------------------------------------
// Section: Functions (4)
//--------------------------------------------------------------------------------
// TODO: this type is limited to platform 'windows6.1'
pub extern "KERNEL32" fn EnableThreadProfiling(
ThreadHandle: ?HANDLE,
Flags: u32,
HardwareCounters: u64,
PerformanceDataHandle: ?*?HANDLE,
) callconv(@import("std").os.windows.WINAPI) u32;
// TODO: this type is limited to platform 'windows6.1'
pub extern "KERNEL32" fn DisableThreadProfiling(
PerformanceDataHandle: ?HANDLE,
) callconv(@import("std").os.windows.WINAPI) u32;
// TODO: this type is limited to platform 'windows6.1'
pub extern "KERNEL32" fn QueryThreadProfiling(
ThreadHandle: ?HANDLE,
Enabled: ?*BOOLEAN,
) callconv(@import("std").os.windows.WINAPI) u32;
// TODO: this type is limited to platform 'windows6.1'
pub extern "KERNEL32" fn ReadThreadProfilingData(
PerformanceDataHandle: ?HANDLE,
Flags: u32,
PerformanceData: ?*PERFORMANCE_DATA,
) callconv(@import("std").os.windows.WINAPI) u32;
//--------------------------------------------------------------------------------
// Section: Unicode Aliases (0)
//--------------------------------------------------------------------------------
const thismodule = @This();
pub usingnamespace switch (@import("../../zig.zig").unicode_mode) {
.ansi => struct {
},
.wide => struct {
},
.unspecified => if (@import("builtin").is_test) struct {
} else struct {
},
};
//--------------------------------------------------------------------------------
// Section: Imports (2)
//--------------------------------------------------------------------------------
const BOOLEAN = @import("../../foundation.zig").BOOLEAN;
const HANDLE = @import("../../foundation.zig").HANDLE;
test {
@setEvalBranchQuota(
@import("std").meta.declarations(@This()).len * 3
);
// reference all the pub declarations
if (!@import("builtin").is_test) return;
inline for (@import("std").meta.declarations(@This())) |decl| {
if (decl.is_pub) {
_ = decl;
}
}
} | win32/system/performance/hardware_counter_profiling.zig |
const std = @import("std");
const windows = @import("windows.zig");
const assert = std.debug.assert;
const dwrite = @import("dwrite.zig");
const dxgi = @import("dxgi.zig");
const UINT = windows.UINT;
const IUnknown = windows.IUnknown;
const HRESULT = windows.HRESULT;
const GUID = windows.GUID;
const WINAPI = windows.WINAPI;
const FLOAT = windows.FLOAT;
const LPCWSTR = windows.LPCWSTR;
const UINT32 = windows.UINT32;
const UINT64 = windows.UINT64;
const POINT = windows.POINT;
const RECT = windows.RECT;
pub const POINT_2F = D2D_POINT_2F;
pub const POINT_2U = D2D_POINT_2U;
pub const POINT_2L = D2D_POINT_2L;
pub const RECT_F = D2D_RECT_F;
pub const RECT_U = D2D_RECT_U;
pub const RECT_L = D2D_RECT_L;
pub const SIZE_F = D2D_SIZE_F;
pub const SIZE_U = D2D_SIZE_U;
pub const MATRIX_3X2_F = D2D_MATRIX_3X2_F;
pub const colorf = struct {
pub const OliveDrab = COLOR_F{ .r = 0.419607878, .g = 0.556862772, .b = 0.137254909, .a = 1.0 };
pub const Black = COLOR_F{ .r = 0.0, .g = 0.0, .b = 0.0, .a = 1.0 };
pub const White = COLOR_F{ .r = 1.0, .g = 1.0, .b = 1.0, .a = 1.0 };
pub const YellowGreen = COLOR_F{ .r = 0.603921592, .g = 0.803921640, .b = 0.196078449, .a = 1.0 };
pub const Yellow = COLOR_F{ .r = 1.0, .g = 1.0, .b = 0.0, .a = 1.0 };
pub const LightSkyBlue = COLOR_F{ .r = 0.529411793, .g = 0.807843208, .b = 0.980392218, .a = 1.000000000 };
pub const DarkOrange = COLOR_F{ .r = 1.000000000, .g = 0.549019635, .b = 0.000000000, .a = 1.000000000 };
};
pub const COLOR_F = extern struct {
r: FLOAT,
g: FLOAT,
b: FLOAT,
a: FLOAT,
pub const Black = COLOR_F{ .r = 0.0, .g = 0.0, .b = 0.0, .a = 1.0 };
fn toSrgb(s: FLOAT) FLOAT {
var l: FLOAT = undefined;
if (s > 0.0031308) {
l = 1.055 * (std.math.pow(FLOAT, s, (1.0 / 2.4))) - 0.055;
} else {
l = 12.92 * s;
}
return l;
}
pub fn linearToSrgb(r: FLOAT, g: FLOAT, b: FLOAT, a: FLOAT) COLOR_F {
return COLOR_F{
.r = toSrgb(r),
.g = toSrgb(g),
.b = toSrgb(b),
.a = a,
};
}
};
pub const ALPHA_MODE = enum(UINT) {
UNKNOWN = 0,
PREMULTIPLIED = 1,
STRAIGHT = 2,
IGNORE = 3,
};
pub const PIXEL_FORMAT = extern struct {
format: dxgi.FORMAT,
alphaMode: ALPHA_MODE,
};
pub const D2D_POINT_2U = extern struct {
x: UINT32,
y: UINT32,
};
pub const D2D_POINT_2F = extern struct {
x: FLOAT,
y: FLOAT,
};
pub const D2D_POINT_2L = POINT;
pub const D2D_VECTOR_2F = extern struct {
x: FLOAT,
y: FLOAT,
};
pub const D2D_VECTOR_3F = extern struct {
x: FLOAT,
y: FLOAT,
z: FLOAT,
};
pub const D2D_VECTOR_4F = extern struct {
x: FLOAT,
y: FLOAT,
z: FLOAT,
w: FLOAT,
};
pub const D2D_RECT_F = extern struct {
left: FLOAT,
top: FLOAT,
right: FLOAT,
bottom: FLOAT,
};
pub const D2D_RECT_U = extern struct {
left: UINT32,
top: UINT32,
right: UINT32,
bottom: UINT32,
};
pub const D2D_RECT_L = RECT;
pub const D2D_SIZE_F = extern struct {
width: FLOAT,
height: FLOAT,
};
pub const D2D_SIZE_U = extern struct {
width: UINT32,
height: UINT32,
};
pub const D2D_MATRIX_3X2_F = extern struct {
m: [3][2]FLOAT,
pub fn initTranslation(x: FLOAT, y: FLOAT) D2D_MATRIX_3X2_F {
return .{
.m = [_][2]FLOAT{
[2]FLOAT{ 1.0, 0.0 },
[2]FLOAT{ 0.0, 1.0 },
[2]FLOAT{ x, y },
},
};
}
pub fn initIdentity() D2D_MATRIX_3X2_F {
return .{
.m = [_][2]FLOAT{
[2]FLOAT{ 1.0, 0.0 },
[2]FLOAT{ 0.0, 1.0 },
[2]FLOAT{ 0.0, 0.0 },
},
};
}
};
pub const D2D_MATRIX_4X3_F = extern struct {
m: [4][3]FLOAT,
};
pub const D2D_MATRIX_4X4_F = extern struct {
m: [4][4]FLOAT,
};
pub const D2D_MATRIX_5X4_F = extern struct {
m: [5][4]FLOAT,
};
pub const CAP_STYLE = enum(UINT) {
FLAT = 0,
SQUARE = 1,
ROUND = 2,
TRIANGLE = 3,
};
pub const DASH_STYLE = enum(UINT) {
SOLID = 0,
DASH = 1,
DOT = 2,
DASH_DOT = 3,
DASH_DOT_DOT = 4,
CUSTOM = 5,
};
pub const LINE_JOIN = enum(UINT) {
MITER = 0,
BEVEL = 1,
ROUND = 2,
MITER_OR_BEVEL = 3,
};
pub const STROKE_STYLE_PROPERTIES = extern struct {
startCap: CAP_STYLE,
endCap: CAP_STYLE,
dashCap: CAP_STYLE,
lineJoin: LINE_JOIN,
miterLimit: FLOAT,
dashStyle: DASH_STYLE,
dashOffset: FLOAT,
};
pub const RADIAL_GRADIENT_BRUSH_PROPERTIES = extern struct {
center: POINT_2F,
gradientOriginOffset: POINT_2F,
radiusX: FLOAT,
radiusY: FLOAT,
};
pub const IResource = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetFactory: *anyopaque,
};
}
};
pub const IImage = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
image: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {};
}
};
pub const IBitmap = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
image: IImage.VTable(Self),
bitmap: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IImage.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetSize: *anyopaque,
GetPixelSize: *anyopaque,
GetPixelFormat: *anyopaque,
GetPixelDpi: *anyopaque,
CopyFromBitmap: *anyopaque,
CopyFromRenderTarget: *anyopaque,
CopyFromMemory: *anyopaque,
};
}
};
pub const GAMMA = enum(UINT) {
_2_2 = 0,
_1_0 = 1,
};
pub const EXTEND_MODE = enum(UINT) {
CLAMP = 0,
WRAP = 1,
MIRROR = 2,
};
pub const GRADIENT_STOP = extern struct {
position: FLOAT,
color: COLOR_F,
};
pub const IGradientStopCollection = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
gradsc: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetGradientStopCount: *anyopaque,
GetGradientStops: *anyopaque,
GetColorInterpolationGamma: *anyopaque,
GetExtendMode: *anyopaque,
};
}
};
pub const IBrush = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
brush: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
SetOpacity: *anyopaque,
SetTransform: *anyopaque,
GetOpacity: *anyopaque,
GetTransform: *anyopaque,
};
}
};
pub const IBitmapBrush = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
brush: IBrush.VTable(Self),
bmpbrush: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IBrush.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
SetExtendModeX: *anyopaque,
SetExtendModeY: *anyopaque,
SetInterpolationMode: *anyopaque,
SetBitmap: *anyopaque,
GetExtendModeX: *anyopaque,
GetExtendModeY: *anyopaque,
GetInterpolationMode: *anyopaque,
GetBitmap: *anyopaque,
};
}
};
pub const ISolidColorBrush = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
brush: IBrush.VTable(Self),
scbrush: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IBrush.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn SetColor(self: *T, color: *const COLOR_F) void {
self.v.scbrush.SetColor(self, color);
}
pub inline fn GetColor(self: *T) COLOR_F {
var color: COLOR_F = undefined;
_ = self.v.scbrush.GetColor(self, &color);
return color;
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
SetColor: fn (*T, *const COLOR_F) callconv(WINAPI) void,
GetColor: fn (*T, *COLOR_F) callconv(WINAPI) *COLOR_F,
};
}
};
pub const ILinearGradientBrush = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
brush: IBrush.VTable(Self),
lgbrush: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IBrush.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
SetStartPoint: *anyopaque,
SetEndPoint: *anyopaque,
GetStartPoint: *anyopaque,
GetEndPoint: *anyopaque,
GetGradientStopCollection: *anyopaque,
};
}
};
pub const IRadialGradientBrush = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
brush: IBrush.VTable(Self),
rgbrush: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IBrush.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
SetCenter: *anyopaque,
SetGradientOriginOffset: *anyopaque,
SetRadiusX: *anyopaque,
SetRadiusY: *anyopaque,
GetCenter: *anyopaque,
GetGradientOriginOffset: *anyopaque,
GetRadiusX: *anyopaque,
GetRadiusY: *anyopaque,
GetGradientStopCollection: *anyopaque,
};
}
};
pub const IStrokeStyle = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
strokestyle: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetStartCap: *anyopaque,
GetEndCap: *anyopaque,
GetDashCap: *anyopaque,
GetMiterLimit: *anyopaque,
GetLineJoin: *anyopaque,
GetDashOffset: *anyopaque,
GetDashStyle: *anyopaque,
GetDashesCount: *anyopaque,
GetDashes: *anyopaque,
};
}
};
pub const IGeometry = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
geometry: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetBounds: *anyopaque,
GetWidenedBounds: *anyopaque,
StrokeContainsPoint: *anyopaque,
FillContainsPoint: *anyopaque,
CompareWithGeometry: *anyopaque,
Simplify: *anyopaque,
Tessellate: *anyopaque,
CombineWithGeometry: *anyopaque,
Outline: *anyopaque,
ComputeArea: *anyopaque,
ComputeLength: *anyopaque,
ComputePointAtLength: *anyopaque,
Widen: *anyopaque,
};
}
};
pub const IRectangleGeometry = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
geometry: IGeometry.VTable(Self),
rectgeo: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IGeometry.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetRect: *anyopaque,
};
}
};
pub const IRoundedRectangleGeometry = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
geometry: IGeometry.VTable(Self),
roundedrectgeo: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IGeometry.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetRoundedRect: *anyopaque,
};
}
};
pub const IEllipseGeometry = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
geometry: IGeometry.VTable(Self),
ellipsegeo: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IGeometry.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetEllipse: *anyopaque,
};
}
};
pub const IGeometryGroup = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
geometry: IGeometry.VTable(Self),
geogroup: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IGeometry.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetFillMode: *anyopaque,
GetSourceGeometryCount: *anyopaque,
GetSourceGeometries: *anyopaque,
};
}
};
pub const ITransformedGeometry = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
geometry: IGeometry.VTable(Self),
transgeo: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IGeometry.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetSourceGeometry: *anyopaque,
GetTransform: *anyopaque,
};
}
};
pub const FIGURE_BEGIN = enum(UINT) {
FILLED = 0,
HOLLOW = 1,
};
pub const FIGURE_END = enum(UINT) {
OPEN = 0,
CLOSED = 1,
};
pub const BEZIER_SEGMENT = extern struct {
point1: POINT_2F,
point2: POINT_2F,
point3: POINT_2F,
};
pub const TRIANGLE = extern struct {
point1: POINT_2F,
point2: POINT_2F,
point3: POINT_2F,
};
pub const PATH_SEGMENT = UINT;
pub const PATH_SEGMENT_NONE = 0x00000000;
pub const PATH_SEGMENT_FORCE_UNSTROKED = 0x00000001;
pub const PATH_SEGMENT_FORCE_ROUND_LINE_JOIN = 0x00000002;
pub const SWEEP_DIRECTION = enum(UINT) {
COUNTER_CLOCKWISE = 0,
CLOCKWISE = 1,
};
pub const FILL_MODE = enum(UINT) {
ALTERNATE = 0,
WINDING = 1,
};
pub const ARC_SIZE = enum(UINT) {
SMALL = 0,
LARGE = 1,
};
pub const ARC_SEGMENT = extern struct {
point: POINT_2F,
size: SIZE_F,
rotationAngle: FLOAT,
sweepDirection: SWEEP_DIRECTION,
arcSize: ARC_SIZE,
};
pub const QUADRATIC_BEZIER_SEGMENT = extern struct {
point1: POINT_2F,
point2: POINT_2F,
};
pub const ISimplifiedGeometrySink = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
simgeosink: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn SetFillMode(self: *T, mode: FILL_MODE) void {
self.v.simgeosink.SetFillMode(self, mode);
}
pub inline fn SetSegmentFlags(self: *T, flags: PATH_SEGMENT) void {
self.v.simgeosink.SetSegmentFlags(self, flags);
}
pub inline fn BeginFigure(self: *T, point: POINT_2F, begin: FIGURE_BEGIN) void {
self.v.simgeosink.BeginFigure(self, point, begin);
}
pub inline fn AddLines(self: *T, points: [*]const POINT_2F, count: UINT32) void {
self.v.simgeosink.AddLines(self, points, count);
}
pub inline fn AddBeziers(self: *T, segments: [*]const BEZIER_SEGMENT, count: UINT32) void {
self.v.simgeosink.AddBeziers(self, segments, count);
}
pub inline fn EndFigure(self: *T, end: FIGURE_END) void {
self.v.simgeosink.EndFigure(self, end);
}
pub inline fn Close(self: *T) HRESULT {
return self.v.simgeosink.Close(self);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
SetFillMode: fn (*T, FILL_MODE) callconv(WINAPI) void,
SetSegmentFlags: fn (*T, PATH_SEGMENT) callconv(WINAPI) void,
BeginFigure: fn (*T, POINT_2F, FIGURE_BEGIN) callconv(WINAPI) void,
AddLines: fn (*T, [*]const POINT_2F, UINT32) callconv(WINAPI) void,
AddBeziers: fn (*T, [*]const BEZIER_SEGMENT, UINT32) callconv(WINAPI) void,
EndFigure: fn (*T, FIGURE_END) callconv(WINAPI) void,
Close: fn (*T) callconv(WINAPI) HRESULT,
};
}
};
pub const IGeometrySink = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
simgeosink: ISimplifiedGeometrySink.VTable(Self),
geosink: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace ISimplifiedGeometrySink.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn AddLine(self: *T, point: POINT_2F) void {
self.v.geosink.AddLine(self, point);
}
pub inline fn AddBezier(self: *T, segment: *const BEZIER_SEGMENT) void {
self.v.geosink.AddBezier(self, segment);
}
pub inline fn AddQuadraticBezier(self: *T, segment: *const QUADRATIC_BEZIER_SEGMENT) void {
self.v.geosink.AddQuadraticBezier(self, segment);
}
pub inline fn AddQuadraticBeziers(self: *T, segments: [*]const QUADRATIC_BEZIER_SEGMENT, count: UINT32) void {
self.v.geosink.AddQuadraticBeziers(self, segments, count);
}
pub inline fn AddArc(self: *T, segment: *const ARC_SEGMENT) void {
self.v.geosink.AddArc(self, segment);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
AddLine: fn (*T, POINT_2F) callconv(WINAPI) void,
AddBezier: fn (*T, *const BEZIER_SEGMENT) callconv(WINAPI) void,
AddQuadraticBezier: fn (*T, *const QUADRATIC_BEZIER_SEGMENT) callconv(WINAPI) void,
AddQuadraticBeziers: fn (*T, [*]const QUADRATIC_BEZIER_SEGMENT, UINT32) callconv(WINAPI) void,
AddArc: fn (*T, *const ARC_SEGMENT) callconv(WINAPI) void,
};
}
};
pub const ITessellationSink = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
tesssink: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
AddTriangles: *anyopaque,
Close: *anyopaque,
};
}
};
pub const IPathGeometry = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
geometry: IGeometry.VTable(Self),
pathgeo: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IGeometry.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn Open(self: *T, sink: *?*IGeometrySink) HRESULT {
return self.v.pathgeo.Open(self, sink);
}
pub inline fn GetSegmentCount(self: *T, count: *UINT32) HRESULT {
return self.v.pathgeo.GetSegmentCount(self, count);
}
pub inline fn GetFigureCount(self: *T, count: *UINT32) HRESULT {
return self.v.pathgeo.GetFigureCount(self, count);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
Open: fn (*T, *?*IGeometrySink) callconv(WINAPI) HRESULT,
Stream: *anyopaque,
GetSegmentCount: fn (*T, *UINT32) callconv(WINAPI) HRESULT,
GetFigureCount: fn (*T, *UINT32) callconv(WINAPI) HRESULT,
};
}
};
pub const IMesh = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
mesh: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
Open: *anyopaque,
};
}
};
pub const ILayer = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
layer: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetSize: *anyopaque,
};
}
};
pub const IDrawingStateBlock = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
stateblock: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetDescription: *anyopaque,
SetDescription: *anyopaque,
SetTextRenderingParams: *anyopaque,
GetTextRenderingParams: *anyopaque,
};
}
};
pub const BRUSH_PROPERTIES = extern struct {
opacity: FLOAT,
transform: MATRIX_3X2_F,
};
pub const ELLIPSE = extern struct {
point: POINT_2F,
radiusX: FLOAT,
radiusY: FLOAT,
};
pub const ROUNDED_RECT = extern struct {
rect: RECT_F,
radiusX: FLOAT,
radiusY: FLOAT,
};
pub const BITMAP_INTERPOLATION_MODE = enum(UINT) {
NEAREST_NEIGHBOR = 0,
LINEAR = 1,
};
pub const DRAW_TEXT_OPTIONS = UINT;
pub const DRAW_TEXT_OPTIONS_NONE = 0;
pub const DRAW_TEXT_OPTIONS_NO_SNAP = 0x1;
pub const DRAW_TEXT_OPTIONS_CLIP = 0x2;
pub const DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT = 0x4;
pub const DRAW_TEXT_OPTIONS_DISABLE_COLOR_BITMAP_SNAPPING = 0x8;
pub const TAG = UINT64;
pub const IRenderTarget = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
rendertarget: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn CreateSolidColorBrush(
self: *T,
color: *const COLOR_F,
properties: ?*const BRUSH_PROPERTIES,
brush: *?*ISolidColorBrush,
) HRESULT {
return self.v.rendertarget.CreateSolidColorBrush(self, color, properties, brush);
}
pub inline fn CreateGradientStopCollection(
self: *T,
stops: [*]const GRADIENT_STOP,
num_stops: UINT32,
gamma: GAMMA,
extend_mode: EXTEND_MODE,
stop_collection: *?*IGradientStopCollection,
) HRESULT {
return self.v.rendertarget.CreateGradientStopCollection(
self,
stops,
num_stops,
gamma,
extend_mode,
stop_collection,
);
}
pub inline fn CreateRadialGradientBrush(
self: *T,
gradient_properties: *const RADIAL_GRADIENT_BRUSH_PROPERTIES,
brush_properties: ?*const BRUSH_PROPERTIES,
stop_collection: *IGradientStopCollection,
brush: *?*IRadialGradientBrush,
) HRESULT {
return self.v.rendertarget.CreateRadialGradientBrush(
self,
gradient_properties,
brush_properties,
stop_collection,
brush,
);
}
pub inline fn DrawLine(
self: *T,
p0: POINT_2F,
p1: POINT_2F,
brush: *IBrush,
width: FLOAT,
style: ?*IStrokeStyle,
) void {
self.v.rendertarget.DrawLine(self, p0, p1, brush, width, style);
}
pub inline fn DrawRectangle(
self: *T,
rect: *const RECT_F,
brush: *IBrush,
width: FLOAT,
stroke: ?*IStrokeStyle,
) void {
self.v.rendertarget.DrawRectangle(self, rect, brush, width, stroke);
}
pub inline fn FillRectangle(self: *T, rect: *const RECT_F, brush: *IBrush) void {
self.v.rendertarget.FillRectangle(self, rect, brush);
}
pub inline fn DrawRoundedRectangle(
self: *T,
rect: *const ROUNDED_RECT,
brush: *IBrush,
width: FLOAT,
stroke: ?*IStrokeStyle,
) void {
self.v.rendertarget.DrawRoundedRectangle(self, rect, brush, width, stroke);
}
pub inline fn FillRoundedRectangle(self: *T, rect: *const ROUNDED_RECT, brush: *IBrush) void {
self.v.rendertarget.FillRoundedRectangle(self, rect, brush);
}
pub inline fn DrawEllipse(
self: *T,
ellipse: *const ELLIPSE,
brush: *IBrush,
width: FLOAT,
stroke: ?*IStrokeStyle,
) void {
self.v.rendertarget.DrawEllipse(self, ellipse, brush, width, stroke);
}
pub inline fn FillEllipse(self: *T, ellipse: *const ELLIPSE, brush: *IBrush) void {
self.v.rendertarget.FillEllipse(self, ellipse, brush);
}
pub inline fn DrawGeometry(
self: *T,
geo: *IGeometry,
brush: *IBrush,
width: FLOAT,
stroke: ?*IStrokeStyle,
) void {
self.v.rendertarget.DrawGeometry(self, geo, brush, width, stroke);
}
pub inline fn FillGeometry(self: *T, geo: *IGeometry, brush: *IBrush, opacity_brush: ?*IBrush) void {
self.v.rendertarget.FillGeometry(self, geo, brush, opacity_brush);
}
pub inline fn DrawBitmap(
self: *T,
bitmap: *IBitmap,
dst_rect: ?*const RECT_F,
opacity: FLOAT,
interpolation_mode: BITMAP_INTERPOLATION_MODE,
src_rect: ?*const RECT_F,
) void {
self.v.rendertarget.DrawBitmap(self, bitmap, dst_rect, opacity, interpolation_mode, src_rect);
}
pub inline fn DrawText(
self: *T,
string: LPCWSTR,
length: UINT,
format: *dwrite.ITextFormat,
layout_rect: *const RECT_F,
brush: *IBrush,
options: DRAW_TEXT_OPTIONS,
measuring_mode: dwrite.MEASURING_MODE,
) void {
self.v.rendertarget.DrawText(
self,
string,
length,
format,
layout_rect,
brush,
options,
measuring_mode,
);
}
pub inline fn SetTransform(self: *T, m: *const MATRIX_3X2_F) void {
self.v.rendertarget.SetTransform(self, m);
}
pub inline fn Clear(self: *T, color: ?*const COLOR_F) void {
self.v.rendertarget.Clear(self, color);
}
pub inline fn BeginDraw(self: *T) void {
self.v.rendertarget.BeginDraw(self);
}
pub inline fn EndDraw(self: *T, tag1: ?*TAG, tag2: ?*TAG) HRESULT {
return self.v.rendertarget.EndDraw(self, tag1, tag2);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
CreateBitmap: *anyopaque,
CreateBitmapFromWicBitmap: *anyopaque,
CreateSharedBitmap: *anyopaque,
CreateBitmapBrush: *anyopaque,
CreateSolidColorBrush: fn (
*T,
*const COLOR_F,
?*const BRUSH_PROPERTIES,
*?*ISolidColorBrush,
) callconv(WINAPI) HRESULT,
CreateGradientStopCollection: fn (
*T,
[*]const GRADIENT_STOP,
UINT32,
GAMMA,
EXTEND_MODE,
*?*IGradientStopCollection,
) callconv(WINAPI) HRESULT,
CreateLinearGradientBrush: *anyopaque,
CreateRadialGradientBrush: fn (
*T,
*const RADIAL_GRADIENT_BRUSH_PROPERTIES,
?*const BRUSH_PROPERTIES,
*IGradientStopCollection,
*?*IRadialGradientBrush,
) callconv(WINAPI) HRESULT,
CreateCompatibleRenderTarget: *anyopaque,
CreateLayer: *anyopaque,
CreateMesh: *anyopaque,
DrawLine: fn (
*T,
POINT_2F,
POINT_2F,
*IBrush,
FLOAT,
?*IStrokeStyle,
) callconv(WINAPI) void,
DrawRectangle: fn (*T, *const RECT_F, *IBrush, FLOAT, ?*IStrokeStyle) callconv(WINAPI) void,
FillRectangle: fn (*T, *const RECT_F, *IBrush) callconv(WINAPI) void,
DrawRoundedRectangle: fn (
*T,
*const ROUNDED_RECT,
*IBrush,
FLOAT,
?*IStrokeStyle,
) callconv(WINAPI) void,
FillRoundedRectangle: fn (*T, *const ROUNDED_RECT, *IBrush) callconv(WINAPI) void,
DrawEllipse: fn (*T, *const ELLIPSE, *IBrush, FLOAT, ?*IStrokeStyle) callconv(WINAPI) void,
FillEllipse: fn (*T, *const ELLIPSE, *IBrush) callconv(WINAPI) void,
DrawGeometry: fn (*T, *IGeometry, *IBrush, FLOAT, ?*IStrokeStyle) callconv(WINAPI) void,
FillGeometry: fn (*T, *IGeometry, *IBrush, ?*IBrush) callconv(WINAPI) void,
FillMesh: *anyopaque,
FillOpacityMask: *anyopaque,
DrawBitmap: fn (
*T,
*IBitmap,
?*const RECT_F,
FLOAT,
BITMAP_INTERPOLATION_MODE,
?*const RECT_F,
) callconv(WINAPI) void,
DrawText: fn (
*T,
LPCWSTR,
UINT,
*dwrite.ITextFormat,
*const RECT_F,
*IBrush,
DRAW_TEXT_OPTIONS,
dwrite.MEASURING_MODE,
) callconv(WINAPI) void,
DrawTextLayout: *anyopaque,
DrawGlyphRun: *anyopaque,
SetTransform: fn (*T, *const MATRIX_3X2_F) callconv(WINAPI) void,
GetTransform: *anyopaque,
SetAntialiasMode: *anyopaque,
GetAntialiasMode: *anyopaque,
SetTextAntialiasMode: *anyopaque,
GetTextAntialiasMode: *anyopaque,
SetTextRenderingParams: *anyopaque,
GetTextRenderingParams: *anyopaque,
SetTags: *anyopaque,
GetTags: *anyopaque,
PushLayer: *anyopaque,
PopLayer: *anyopaque,
Flush: *anyopaque,
SaveDrawingState: *anyopaque,
RestoreDrawingState: *anyopaque,
PushAxisAlignedClip: *anyopaque,
PopAxisAlignedClip: *anyopaque,
Clear: fn (*T, ?*const COLOR_F) callconv(WINAPI) void,
BeginDraw: fn (*T) callconv(WINAPI) void,
EndDraw: fn (*T, ?*TAG, ?*TAG) callconv(WINAPI) HRESULT,
GetPixelFormat: *anyopaque,
SetDpi: *anyopaque,
GetDpi: *anyopaque,
GetSize: *anyopaque,
GetPixelSize: *anyopaque,
GetMaximumBitmapSize: *anyopaque,
IsSupported: *anyopaque,
};
}
};
pub const IFactory = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
factory: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn CreateRectangleGeometry(self: *T, rect: *const RECT_F, geo: *?*IRectangleGeometry) HRESULT {
return self.v.factory.CreateRectangleGeometry(self, rect, geo);
}
pub inline fn CreateRoundedRectangleGeometry(
self: *T,
rect: *const ROUNDED_RECT,
geo: *?*IRoundedRectangleGeometry,
) HRESULT {
return self.v.factory.CreateRoundedRectangleGeometry(self, rect, geo);
}
pub inline fn CreateEllipseGeometry(self: *T, ellipse: *const ELLIPSE, geo: *?*IEllipseGeometry) HRESULT {
return self.v.factory.CreateEllipseGeometry(self, ellipse, geo);
}
pub inline fn CreatePathGeometry(self: *T, geo: *?*IPathGeometry) HRESULT {
return self.v.factory.CreatePathGeometry(self, geo);
}
pub inline fn CreateStrokeStyle(
self: *T,
properties: *const STROKE_STYLE_PROPERTIES,
dashes: ?[*]const FLOAT,
dashes_count: UINT32,
stroke_style: *?*IStrokeStyle,
) HRESULT {
return self.v.factory.CreateStrokeStyle(self, properties, dashes, dashes_count, stroke_style);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
ReloadSystemMetrics: *anyopaque,
GetDesktopDpi: *anyopaque,
CreateRectangleGeometry: fn (*T, *const RECT_F, *?*IRectangleGeometry) callconv(WINAPI) HRESULT,
CreateRoundedRectangleGeometry: fn (
*T,
*const ROUNDED_RECT,
*?*IRoundedRectangleGeometry,
) callconv(WINAPI) HRESULT,
CreateEllipseGeometry: fn (*T, *const ELLIPSE, *?*IEllipseGeometry) callconv(WINAPI) HRESULT,
CreateGeometryGroup: *anyopaque,
CreateTransformedGeometry: *anyopaque,
CreatePathGeometry: fn (*T, *?*IPathGeometry) callconv(WINAPI) HRESULT,
CreateStrokeStyle: fn (
*T,
*const STROKE_STYLE_PROPERTIES,
?[*]const FLOAT,
UINT32,
*?*IStrokeStyle,
) callconv(WINAPI) HRESULT,
CreateDrawingStateBlock: *anyopaque,
CreateWicBitmapRenderTarget: *anyopaque,
CreateHwndRenderTarget: *anyopaque,
CreateDxgiSurfaceRenderTarget: *anyopaque,
CreateDCRenderTarget: *anyopaque,
};
}
};
pub const FACTORY_TYPE = enum(UINT) {
SINGLE_THREADED = 0,
MULTI_THREADED = 1,
};
pub const DEBUG_LEVEL = enum(UINT) {
NONE = 0,
ERROR = 1,
WARNING = 2,
INFORMATION = 3,
};
pub const FACTORY_OPTIONS = extern struct {
debugLevel: DEBUG_LEVEL,
};
pub extern "d2d1" fn D2D1CreateFactory(
FACTORY_TYPE,
*const GUID,
?*const FACTORY_OPTIONS,
*?*anyopaque,
) callconv(WINAPI) HRESULT;
pub const IBitmap1 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
image: IImage.VTable(Self),
bitmap: IBitmap.VTable(Self),
bitmap1: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IImage.Methods(Self);
usingnamespace IBitmap.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetColorContext: *anyopaque,
GetOptions: *anyopaque,
GetSurface: *anyopaque,
Map: *anyopaque,
Unmap: *anyopaque,
};
}
};
pub const IColorContext = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
colorctx: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetColorSpace: *anyopaque,
GetProfileSize: *anyopaque,
GetProfile: *anyopaque,
};
}
};
pub const DEVICE_CONTEXT_OPTIONS = UINT;
pub const DEVICE_CONTEXT_OPTIONS_NONE = 0;
pub const DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS = 0x1;
pub const BITMAP_OPTIONS = UINT;
pub const BITMAP_OPTIONS_NONE = 0;
pub const BITMAP_OPTIONS_TARGET = 0x1;
pub const BITMAP_OPTIONS_CANNOT_DRAW = 0x2;
pub const BITMAP_OPTIONS_CPU_READ = 0x4;
pub const BITMAP_OPTIONS_GDI_COMPATIBLE = 0x8;
pub const BITMAP_PROPERTIES1 = extern struct {
pixelFormat: PIXEL_FORMAT,
dpiX: FLOAT,
dpiY: FLOAT,
bitmapOptions: BITMAP_OPTIONS,
colorContext: ?*IColorContext,
};
pub const IDeviceContext = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
rendertarget: IRenderTarget.VTable(Self),
devctx: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IRenderTarget.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn CreateBitmapFromDxgiSurface(
self: *T,
surface: *dxgi.ISurface,
properties: ?*const BITMAP_PROPERTIES1,
bitmap: *?*IBitmap1,
) HRESULT {
return self.v.devctx.CreateBitmapFromDxgiSurface(self, surface, properties, bitmap);
}
pub inline fn SetTarget(self: *T, image: ?*IImage) void {
self.v.devctx.SetTarget(self, image);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
CreateBitmap1: *anyopaque,
CreateBitmapFromWicBitmap1: *anyopaque,
CreateColorContext: *anyopaque,
CreateColorContextFromFilename: *anyopaque,
CreateColorContextFromWicColorContext: *anyopaque,
CreateBitmapFromDxgiSurface: fn (
*T,
*dxgi.ISurface,
?*const BITMAP_PROPERTIES1,
*?*IBitmap1,
) callconv(WINAPI) HRESULT,
CreateEffect: *anyopaque,
CreateGradientStopCollection1: *anyopaque,
CreateImageBrush: *anyopaque,
CreateBitmapBrush1: *anyopaque,
CreateCommandList: *anyopaque,
IsDxgiFormatSupported: *anyopaque,
IsBufferPrecisionSupported: *anyopaque,
GetImageLocalBounds: *anyopaque,
GetImageWorldBounds: *anyopaque,
GetGlyphRunWorldBounds: *anyopaque,
GetDevice: *anyopaque,
SetTarget: fn (*T, ?*IImage) callconv(WINAPI) void,
GetTarget: *anyopaque,
SetRenderingControls: *anyopaque,
GetRenderingControls: *anyopaque,
SetPrimitiveBlend: *anyopaque,
GetPrimitiveBlend: *anyopaque,
SetUnitMode: *anyopaque,
GetUnitMode: *anyopaque,
DrawGlyphRun1: *anyopaque,
DrawImage: *anyopaque,
DrawGdiMetafile: *anyopaque,
DrawBitmap1: *anyopaque,
PushLayer1: *anyopaque,
InvalidateEffectInputRectangle: *anyopaque,
GetEffectInvalidRectangleCount: *anyopaque,
GetEffectInvalidRectangles: *anyopaque,
GetEffectRequiredInputRectangles: *anyopaque,
FillOpacityMask1: *anyopaque,
};
}
};
pub const IFactory1 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
factory: IFactory.VTable(Self),
factory1: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IFactory.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDevice: *anyopaque,
CreateStrokeStyle1: *anyopaque,
CreatePathGeometry1: *anyopaque,
CreateDrawingStateBlock1: *anyopaque,
CreateGdiMetafile: *anyopaque,
RegisterEffectFromStream: *anyopaque,
RegisterEffectFromString: *anyopaque,
UnregisterEffect: *anyopaque,
GetRegisteredEffects: *anyopaque,
GetEffectProperties: *anyopaque,
};
}
};
pub const IDevice = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
device: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDeviceContext: *anyopaque,
CreatePrintControl: *anyopaque,
SetMaximumTextureMemory: *anyopaque,
GetMaximumTextureMemory: *anyopaque,
ClearResources: *anyopaque,
};
}
};
pub const IDeviceContext1 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
rendertarget: IRenderTarget.VTable(Self),
devctx: IDeviceContext.VTable(Self),
devctx1: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IRenderTarget.Methods(Self);
usingnamespace IDeviceContext.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateFilledGeometryRealization: *anyopaque,
CreateStrokedGeometryRealization: *anyopaque,
DrawGeometryRealization: *anyopaque,
};
}
};
pub const IFactory2 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
factory: IFactory.VTable(Self),
factory1: IFactory1.VTable(Self),
factory2: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IFactory.Methods(Self);
usingnamespace IFactory1.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDevice1: *anyopaque,
};
}
};
pub const IDevice1 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
device: IDevice.VTable(Self),
device1: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IDevice.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
GetRenderingPriority: *anyopaque,
SetRenderingPriority: *anyopaque,
CreateDeviceContext1: *anyopaque,
};
}
};
pub const INK_NIB_SHAPE = enum(UINT) {
ROUND = 0,
SQUARE = 1,
};
pub const INK_POINT = extern struct {
x: FLOAT,
y: FLOAT,
radius: FLOAT,
};
pub const INK_BEZIER_SEGMENT = extern struct {
point1: INK_POINT,
point2: INK_POINT,
point3: INK_POINT,
};
pub const INK_STYLE_PROPERTIES = extern struct {
nibShape: INK_NIB_SHAPE,
nibTransform: MATRIX_3X2_F,
};
pub const IInk = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
ink: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn SetStartPoint(self: *T, point: *const INK_POINT) void {
self.v.ink.SetStartPoint(self, point);
}
pub inline fn GetStartPoint(self: *T) INK_POINT {
var point: INK_POINT = undefined;
_ = self.v.ink.GetStartPoint(self, &point);
return point;
}
pub inline fn AddSegments(self: *T, segments: [*]const INK_BEZIER_SEGMENT, count: UINT32) HRESULT {
return self.v.ink.AddSegments(self, segments, count);
}
pub inline fn RemoveSegmentsAtEnd(self: *T, count: UINT32) HRESULT {
return self.v.ink.RemoveSegmentsAtEnd(self, count);
}
pub inline fn SetSegments(
self: *T,
start_segment: UINT32,
segments: [*]const INK_BEZIER_SEGMENT,
count: UINT32,
) HRESULT {
return self.v.ink.SetSegments(self, start_segment, segments, count);
}
pub inline fn SetSegmentAtEnd(self: *T, segment: *const INK_BEZIER_SEGMENT) HRESULT {
return self.v.ink.SetSegmentAtEnd(self, segment);
}
pub inline fn GetSegmentCount(self: *T) UINT32 {
return self.v.ink.GetSegmentCount(self);
}
pub inline fn GetSegments(
self: *T,
start_segment: UINT32,
segments: [*]const INK_BEZIER_SEGMENT,
count: UINT32,
) HRESULT {
return self.v.ink.GetSegments(self, start_segment, segments, count);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
SetStartPoint: fn (*T, *const INK_POINT) callconv(WINAPI) void,
GetStartPoint: fn (*T, *INK_POINT) callconv(WINAPI) *INK_POINT,
AddSegments: fn (*T, [*]const INK_BEZIER_SEGMENT, UINT32) callconv(WINAPI) HRESULT,
RemoveSegmentsAtEnd: fn (*T, UINT32) callconv(WINAPI) HRESULT,
SetSegments: fn (*T, UINT32, [*]const INK_BEZIER_SEGMENT, UINT32) callconv(WINAPI) HRESULT,
SetSegmentAtEnd: fn (*T, *const INK_BEZIER_SEGMENT) callconv(WINAPI) HRESULT,
GetSegmentCount: fn (*T) callconv(WINAPI) UINT32,
GetSegments: fn (*T, UINT32, [*]const INK_BEZIER_SEGMENT, UINT32) callconv(WINAPI) HRESULT,
StreamAsGeometry: *anyopaque,
GetBounds: *anyopaque,
};
}
};
pub const IInkStyle = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
inkstyle: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
SetNibTransform: *anyopaque,
GetNibTransform: *anyopaque,
SetNibShape: *anyopaque,
GetNibShape: *anyopaque,
};
}
};
pub const IDeviceContext2 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
rendertarget: IRenderTarget.VTable(Self),
devctx: IDeviceContext.VTable(Self),
devctx1: IDeviceContext1.VTable(Self),
devctx2: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IRenderTarget.Methods(Self);
usingnamespace IDeviceContext.Methods(Self);
usingnamespace IDeviceContext1.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn CreateInk(self: *T, start_point: *const INK_POINT, ink: *?*IInk) HRESULT {
return self.v.devctx2.CreateInk(self, start_point, ink);
}
pub inline fn CreateInkStyle(
self: *T,
properties: ?*const INK_STYLE_PROPERTIES,
ink_style: *?*IInkStyle,
) HRESULT {
return self.v.devctx2.CreateInkStyle(self, properties, ink_style);
}
pub inline fn DrawInk(self: *T, ink: *IInk, brush: *IBrush, style: ?*IInkStyle) void {
return self.v.devctx2.DrawInk(self, ink, brush, style);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
CreateInk: fn (*T, *const INK_POINT, *?*IInk) callconv(WINAPI) HRESULT,
CreateInkStyle: fn (*T, ?*const INK_STYLE_PROPERTIES, *?*IInkStyle) callconv(WINAPI) HRESULT,
CreateGradientMesh: *anyopaque,
CreateImageSourceFromWic: *anyopaque,
CreateLookupTable3D: *anyopaque,
CreateImageSourceFromDxgi: *anyopaque,
GetGradientMeshWorldBounds: *anyopaque,
DrawInk: fn (*T, *IInk, *IBrush, ?*IInkStyle) callconv(WINAPI) void,
DrawGradientMesh: *anyopaque,
DrawGdiMetafile1: *anyopaque,
CreateTransformedImageSource: *anyopaque,
};
}
};
pub const IDeviceContext3 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
rendertarget: IRenderTarget.VTable(Self),
devctx: IDeviceContext.VTable(Self),
devctx1: IDeviceContext1.VTable(Self),
devctx2: IDeviceContext2.VTable(Self),
devctx3: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IRenderTarget.Methods(Self);
usingnamespace IDeviceContext.Methods(Self);
usingnamespace IDeviceContext1.Methods(Self);
usingnamespace IDeviceContext2.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateSpriteBatch: *anyopaque,
DrawSpriteBatch: *anyopaque,
};
}
};
pub const IDeviceContext4 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
rendertarget: IRenderTarget.VTable(Self),
devctx: IDeviceContext.VTable(Self),
devctx1: IDeviceContext1.VTable(Self),
devctx2: IDeviceContext2.VTable(Self),
devctx3: IDeviceContext3.VTable(Self),
devctx4: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IRenderTarget.Methods(Self);
usingnamespace IDeviceContext.Methods(Self);
usingnamespace IDeviceContext1.Methods(Self);
usingnamespace IDeviceContext2.Methods(Self);
usingnamespace IDeviceContext3.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateSvgGlyphStyle: *anyopaque,
DrawText1: *anyopaque,
DrawTextLayout1: *anyopaque,
DrawColorBitmapGlyphRun: *anyopaque,
DrawSvgGlyphRun: *anyopaque,
GetColorBitmapGlyphImage: *anyopaque,
GetSvgGlyphImage: *anyopaque,
};
}
};
pub const IDeviceContext5 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
rendertarget: IRenderTarget.VTable(Self),
devctx: IDeviceContext.VTable(Self),
devctx1: IDeviceContext1.VTable(Self),
devctx2: IDeviceContext2.VTable(Self),
devctx3: IDeviceContext3.VTable(Self),
devctx4: IDeviceContext4.VTable(Self),
devctx5: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IRenderTarget.Methods(Self);
usingnamespace IDeviceContext.Methods(Self);
usingnamespace IDeviceContext1.Methods(Self);
usingnamespace IDeviceContext2.Methods(Self);
usingnamespace IDeviceContext3.Methods(Self);
usingnamespace IDeviceContext4.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateSvgDocument: *anyopaque,
DrawSvgDocument: *anyopaque,
CreateColorContextFromDxgiColorSpace: *anyopaque,
CreateColorContextFromSimpleColorProfile: *anyopaque,
};
}
};
pub const IDeviceContext6 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
rendertarget: IRenderTarget.VTable(Self),
devctx: IDeviceContext.VTable(Self),
devctx1: IDeviceContext1.VTable(Self),
devctx2: IDeviceContext2.VTable(Self),
devctx3: IDeviceContext3.VTable(Self),
devctx4: IDeviceContext4.VTable(Self),
devctx5: IDeviceContext5.VTable(Self),
devctx6: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IRenderTarget.Methods(Self);
usingnamespace IDeviceContext.Methods(Self);
usingnamespace IDeviceContext1.Methods(Self);
usingnamespace IDeviceContext2.Methods(Self);
usingnamespace IDeviceContext3.Methods(Self);
usingnamespace IDeviceContext4.Methods(Self);
usingnamespace IDeviceContext5.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
BlendImage: *anyopaque,
};
}
};
pub const IFactory3 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
factory: IFactory.VTable(Self),
factory1: IFactory1.VTable(Self),
factory2: IFactory2.VTable(Self),
factory3: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IFactory.Methods(Self);
usingnamespace IFactory1.Methods(Self);
usingnamespace IFactory2.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDevice2: *anyopaque,
};
}
};
pub const IFactory4 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
factory: IFactory.VTable(Self),
factory1: IFactory1.VTable(Self),
factory2: IFactory2.VTable(Self),
factory3: IFactory3.VTable(Self),
factory4: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IFactory.Methods(Self);
usingnamespace IFactory1.Methods(Self);
usingnamespace IFactory2.Methods(Self);
usingnamespace IFactory3.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDevice3: *anyopaque,
};
}
};
pub const IFactory5 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
factory: IFactory.VTable(Self),
factory1: IFactory1.VTable(Self),
factory2: IFactory2.VTable(Self),
factory3: IFactory3.VTable(Self),
factory4: IFactory4.VTable(Self),
factory5: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IFactory.Methods(Self);
usingnamespace IFactory1.Methods(Self);
usingnamespace IFactory2.Methods(Self);
usingnamespace IFactory3.Methods(Self);
usingnamespace IFactory4.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDevice4: *anyopaque,
};
}
};
pub const IFactory6 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
factory: IFactory.VTable(Self),
factory1: IFactory1.VTable(Self),
factory2: IFactory2.VTable(Self),
factory3: IFactory3.VTable(Self),
factory4: IFactory4.VTable(Self),
factory5: IFactory5.VTable(Self),
factory6: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IFactory.Methods(Self);
usingnamespace IFactory1.Methods(Self);
usingnamespace IFactory2.Methods(Self);
usingnamespace IFactory3.Methods(Self);
usingnamespace IFactory4.Methods(Self);
usingnamespace IFactory5.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDevice5: *anyopaque,
};
}
};
pub const IFactory7 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
factory: IFactory.VTable(Self),
factory1: IFactory1.VTable(Self),
factory2: IFactory2.VTable(Self),
factory3: IFactory3.VTable(Self),
factory4: IFactory4.VTable(Self),
factory5: IFactory5.VTable(Self),
factory6: IFactory6.VTable(Self),
factory7: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IFactory.Methods(Self);
usingnamespace IFactory1.Methods(Self);
usingnamespace IFactory2.Methods(Self);
usingnamespace IFactory3.Methods(Self);
usingnamespace IFactory4.Methods(Self);
usingnamespace IFactory5.Methods(Self);
usingnamespace IFactory6.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn CreateDevice6(self: *T, dxgi_device: *dxgi.IDevice, d2d_device6: *?*IDevice6) HRESULT {
return self.v.factory7.CreateDevice6(self, dxgi_device, d2d_device6);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
CreateDevice6: fn (*T, *dxgi.IDevice, *?*IDevice6) callconv(WINAPI) HRESULT,
};
}
};
pub const IDevice2 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
device: IDevice.VTable(Self),
device1: IDevice1.VTable(Self),
device2: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IDevice.Methods(Self);
usingnamespace IDevice1.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDeviceContext2: *anyopaque,
FlushDeviceContexts: *anyopaque,
GetDxgiDevice: *anyopaque,
};
}
};
pub const IDevice3 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
device: IDevice.VTable(Self),
device1: IDevice1.VTable(Self),
device2: IDevice2.VTable(Self),
device3: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IDevice.Methods(Self);
usingnamespace IDevice1.Methods(Self);
usingnamespace IDevice2.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDeviceContext3: *anyopaque,
};
}
};
pub const IDevice4 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
device: IDevice.VTable(Self),
device1: IDevice1.VTable(Self),
device2: IDevice2.VTable(Self),
device3: IDevice3.VTable(Self),
device4: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IDevice.Methods(Self);
usingnamespace IDevice1.Methods(Self);
usingnamespace IDevice2.Methods(Self);
usingnamespace IDevice3.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDeviceContext4: *anyopaque,
SetMaximumColorGlyphCacheMemory: *anyopaque,
GetMaximumColorGlyphCacheMemory: *anyopaque,
};
}
};
pub const IDevice5 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
device: IDevice.VTable(Self),
device1: IDevice1.VTable(Self),
device2: IDevice2.VTable(Self),
device3: IDevice3.VTable(Self),
device4: IDevice4.VTable(Self),
device5: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IDevice.Methods(Self);
usingnamespace IDevice1.Methods(Self);
usingnamespace IDevice2.Methods(Self);
usingnamespace IDevice3.Methods(Self);
usingnamespace IDevice4.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
_ = T;
return extern struct {};
}
pub fn VTable(comptime T: type) type {
_ = T;
return extern struct {
CreateDeviceContext5: *anyopaque,
};
}
};
pub const IDevice6 = extern struct {
const Self = @This();
v: *const extern struct {
unknown: IUnknown.VTable(Self),
resource: IResource.VTable(Self),
device: IDevice.VTable(Self),
device1: IDevice1.VTable(Self),
device2: IDevice2.VTable(Self),
device3: IDevice3.VTable(Self),
device4: IDevice4.VTable(Self),
device5: IDevice5.VTable(Self),
device6: VTable(Self),
},
usingnamespace IUnknown.Methods(Self);
usingnamespace IResource.Methods(Self);
usingnamespace IDevice.Methods(Self);
usingnamespace IDevice1.Methods(Self);
usingnamespace IDevice2.Methods(Self);
usingnamespace IDevice3.Methods(Self);
usingnamespace IDevice4.Methods(Self);
usingnamespace IDevice5.Methods(Self);
usingnamespace Methods(Self);
pub fn Methods(comptime T: type) type {
return extern struct {
pub inline fn CreateDeviceContext6(
self: *T,
options: DEVICE_CONTEXT_OPTIONS,
devctx: *?*IDeviceContext6,
) HRESULT {
return self.v.device6.CreateDeviceContext6(self, options, devctx);
}
};
}
pub fn VTable(comptime T: type) type {
return extern struct {
CreateDeviceContext6: fn (
*T,
DEVICE_CONTEXT_OPTIONS,
*?*IDeviceContext6,
) callconv(WINAPI) HRESULT,
};
}
};
pub const IID_IFactory7 = GUID{
.Data1 = 0xbdc2bdd3,
.Data2 = 0xb96c,
.Data3 = 0x4de6,
.Data4 = .{ 0xbd, 0xf7, 0x99, 0xd4, 0x74, 0x54, 0x54, 0xde },
}; | modules/platform/vendored/zwin32/src/d2d1.zig |
const std = @import("std");
const builtin = @import("builtin");
const stdx = @import("../../stdx/lib.zig");
pub const pkg = std.build.Pkg{
.name = "sdl",
.source = .{ .path = srcPath() ++ "/sdl.zig" },
.dependencies = &.{ stdx.pkg },
};
pub fn addPackage(step: *std.build.LibExeObjStep) void {
step.addPackage(pkg);
step.linkLibC();
step.addIncludeDir(srcPath() ++ "/vendor/include");
}
pub fn create(
b: *std.build.Builder,
target: std.zig.CrossTarget,
mode: std.builtin.Mode,
) !*std.build.LibExeObjStep {
const lib = b.addStaticLibrary("sdl2", null);
lib.setTarget(target);
lib.setBuildMode(mode);
const alloc = b.allocator;
// Use SDL_config_minimal.h instead of relying on configure or CMake
// and add defines to make it work for most modern platforms.
var c_flags = std.ArrayList([]const u8).init(alloc);
if (target.getOsTag() == .macos) {
try c_flags.appendSlice(&.{
// Silence warnings that are errors by default in objc source files. Noticed this in github ci.
"-Wno-deprecated-declarations",
"-Wno-unguarded-availability",
});
} else if (target.getOsTag() == .linux) {
try c_flags.append("-DSDL_VIDEO_VULKAN=1");
}
// Look at CMakeLists.txt.
var c_files = std.ArrayList([]const u8).init(alloc);
try c_files.appendSlice(&.{
// General source files.
"SDL_log.c",
"SDL_hints.c",
"SDL_error.c",
"SDL_dataqueue.c",
"SDL.c",
"SDL_assert.c",
"atomic/SDL_spinlock.c",
"atomic/SDL_atomic.c",
"audio/SDL_wave.c",
"audio/SDL_mixer.c",
"audio/SDL_audiotypecvt.c",
"audio/SDL_audiodev.c",
"audio/SDL_audiocvt.c",
"audio/SDL_audio.c",
"audio/disk/SDL_diskaudio.c",
"audio/dsp/SDL_dspaudio.c",
"audio/sndio/SDL_sndioaudio.c",
"cpuinfo/SDL_cpuinfo.c",
"dynapi/SDL_dynapi.c",
"events/SDL_windowevents.c",
"events/SDL_touch.c",
"events/SDL_quit.c",
"events/SDL_mouse.c",
"events/SDL_keyboard.c",
"events/SDL_gesture.c",
"events/SDL_events.c",
"events/SDL_dropevents.c",
"events/SDL_displayevents.c",
"events/SDL_clipboardevents.c",
"events/imKStoUCS.c",
"file/SDL_rwops.c",
"haptic/SDL_haptic.c",
"hidapi/SDL_hidapi.c",
"libm/s_tan.c",
"libm/s_sin.c",
"libm/s_scalbn.c",
"libm/s_floor.c",
"libm/s_fabs.c",
"libm/s_cos.c",
"libm/s_copysign.c",
"libm/s_atan.c",
"libm/k_tan.c",
"libm/k_rem_pio2.c",
"libm/k_cos.c",
"libm/e_sqrt.c",
"libm/e_rem_pio2.c",
"libm/e_pow.c",
"libm/e_log.c",
"libm/e_log10.c",
"libm/e_fmod.c",
"libm/e_exp.c",
"libm/e_atan2.c",
"libm/k_sin.c",
"locale/SDL_locale.c",
"misc/SDL_url.c",
"power/SDL_power.c",
"render/SDL_yuv_sw.c",
"render/SDL_render.c",
"render/SDL_d3dmath.c",
"render/vitagxm/SDL_render_vita_gxm_tools.c",
"render/vitagxm/SDL_render_vita_gxm_memory.c",
"render/vitagxm/SDL_render_vita_gxm.c",
"render/software/SDL_triangle.c",
"render/software/SDL_rotate.c",
"render/software/SDL_render_sw.c",
"render/software/SDL_drawpoint.c",
"render/software/SDL_drawline.c",
"render/software/SDL_blendpoint.c",
"render/software/SDL_blendline.c",
"render/software/SDL_blendfillrect.c",
"render/psp/SDL_render_psp.c",
"render/opengl/SDL_shaders_gl.c",
"render/opengles/SDL_render_gles.c",
"render/opengles2/SDL_shaders_gles2.c",
"render/opengles2/SDL_render_gles2.c",
"render/opengl/SDL_render_gl.c",
"render/direct3d/SDL_shaders_d3d.c",
"render/direct3d/SDL_render_d3d.c",
"render/direct3d11/SDL_shaders_d3d11.c",
"render/direct3d11/SDL_render_d3d11.c",
"sensor/SDL_sensor.c",
"stdlib/SDL_strtokr.c",
"stdlib/SDL_stdlib.c",
"stdlib/SDL_qsort.c",
"stdlib/SDL_malloc.c",
"stdlib/SDL_iconv.c",
"stdlib/SDL_getenv.c",
"stdlib/SDL_crc32.c",
"stdlib/SDL_string.c",
"thread/SDL_thread.c",
"timer/SDL_timer.c",
"video/SDL_yuv.c",
"video/SDL_vulkan_utils.c",
"video/SDL_surface.c",
"video/SDL_stretch.c",
"video/SDL_shape.c",
"video/SDL_RLEaccel.c",
"video/SDL_rect.c",
"video/SDL_pixels.c",
"video/SDL_video.c",
"video/SDL_fillrect.c",
"video/SDL_egl.c",
"video/SDL_bmp.c",
"video/SDL_clipboard.c",
"video/SDL_blit_slow.c",
"video/SDL_blit_N.c",
"video/SDL_blit_copy.c",
"video/SDL_blit_auto.c",
"video/SDL_blit_A.c",
"video/SDL_blit.c",
"video/SDL_blit_0.c",
"video/SDL_blit_1.c",
"video/yuv2rgb/yuv_rgb.c",
// SDL_JOYSTICK
"joystick/SDL_joystick.c",
"joystick/SDL_gamecontroller.c",
// Dummy
"audio/dummy/SDL_dummyaudio.c",
"sensor/dummy/SDL_dummysensor.c",
"haptic/dummy/SDL_syshaptic.c",
"joystick/dummy/SDL_sysjoystick.c",
"video/dummy/SDL_nullvideo.c",
"video/dummy/SDL_nullframebuffer.c",
"video/dummy/SDL_nullevents.c",
// Steam
"joystick/steam/SDL_steamcontroller.c",
"joystick/hidapi/SDL_hidapi_rumble.c",
"joystick/hidapi/SDL_hidapijoystick.c",
"joystick/hidapi/SDL_hidapi_xbox360w.c",
"joystick/hidapi/SDL_hidapi_switch.c",
"joystick/hidapi/SDL_hidapi_steam.c",
"joystick/hidapi/SDL_hidapi_stadia.c",
"joystick/hidapi/SDL_hidapi_ps4.c",
"joystick/hidapi/SDL_hidapi_xboxone.c",
"joystick/hidapi/SDL_hidapi_xbox360.c",
"joystick/hidapi/SDL_hidapi_gamecube.c",
"joystick/hidapi/SDL_hidapi_ps5.c",
"joystick/hidapi/SDL_hidapi_luna.c",
"joystick/virtual/SDL_virtualjoystick.c",
});
if (target.getOsTag() == .linux or target.getOsTag() == .macos) {
try c_files.appendSlice(&.{
// Threads
"thread/pthread/SDL_systhread.c",
"thread/pthread/SDL_systls.c",
"thread/pthread/SDL_syssem.c",
"thread/pthread/SDL_sysmutex.c",
"thread/pthread/SDL_syscond.c",
});
}
if (target.getOsTag() == .linux) {
try c_files.appendSlice(&.{
"core/unix/SDL_poll.c",
"core/linux/SDL_evdev.c",
"core/linux/SDL_evdev_kbd.c",
"core/linux/SDL_dbus.c",
"core/linux/SDL_ime.c",
"core/linux/SDL_udev.c",
"core/linux/SDL_threadprio.c",
// "core/linux/SDL_fcitx.c",
"core/linux/SDL_ibus.c",
"core/linux/SDL_evdev_capabilities.c",
"power/linux/SDL_syspower.c",
"haptic/linux/SDL_syshaptic.c",
"misc/unix/SDL_sysurl.c",
"timer/unix/SDL_systimer.c",
"locale/unix/SDL_syslocale.c",
"loadso/dlopen/SDL_sysloadso.c",
"filesystem/unix/SDL_sysfilesystem.c",
"video/x11/SDL_x11opengles.c",
"video/x11/SDL_x11messagebox.c",
"video/x11/SDL_x11touch.c",
"video/x11/SDL_x11mouse.c",
"video/x11/SDL_x11keyboard.c",
"video/x11/SDL_x11video.c",
"video/x11/edid-parse.c",
"video/x11/SDL_x11dyn.c",
"video/x11/SDL_x11framebuffer.c",
"video/x11/SDL_x11opengl.c",
"video/x11/SDL_x11modes.c",
"video/x11/SDL_x11shape.c",
"video/x11/SDL_x11window.c",
"video/x11/SDL_x11vulkan.c",
"video/x11/SDL_x11xfixes.c",
"video/x11/SDL_x11clipboard.c",
"video/x11/SDL_x11events.c",
"video/x11/SDL_x11xinput2.c",
"audio/alsa/SDL_alsa_audio.c",
"audio/pulseaudio/SDL_pulseaudio.c",
"joystick/linux/SDL_sysjoystick.c",
});
} else if (target.getOsTag() == .macos) {
try c_files.appendSlice(&.{
"joystick/darwin/SDL_iokitjoystick.c",
"haptic/darwin/SDL_syshaptic.c",
"video/cocoa/SDL_cocoametalview.m",
"video/cocoa/SDL_cocoaclipboard.m",
"video/cocoa/SDL_cocoashape.m",
"video/cocoa/SDL_cocoakeyboard.m",
"video/cocoa/SDL_cocoamessagebox.m",
"video/cocoa/SDL_cocoaevents.m",
"video/cocoa/SDL_cocoamouse.m",
"video/cocoa/SDL_cocoavideo.m",
"video/cocoa/SDL_cocoawindow.m",
"video/cocoa/SDL_cocoavulkan.m",
"video/cocoa/SDL_cocoaopengles.m",
"video/cocoa/SDL_cocoamodes.m",
"video/cocoa/SDL_cocoaopengl.m",
"file/cocoa/SDL_rwopsbundlesupport.m",
"render/metal/SDL_render_metal.m",
"filesystem/cocoa/SDL_sysfilesystem.m",
"audio/coreaudio/SDL_coreaudio.m",
"locale/macosx/SDL_syslocale.m",
// Currently, joystick support is disabled in SDL_config.h for macos since there were issues
// building in github ci and there is no cosmic joystick api atm.
// Once enabled, SDL_mfijoystick will have a compile error in github ci: cannot create __weak reference in file using manual reference counting
// This can be resolved by giving it "-fobjc-arc" cflag for just the one file.
// After that it turns out we'll need CoreHaptics but it's not always available and zig doesn't have a way to set weak frameworks yet:
// https://github.com/ziglang/zig/issues/10206
"joystick/iphoneos/SDL_mfijoystick.m",
"timer/unix/SDL_systimer.c",
"loadso/dlopen/SDL_sysloadso.c",
"misc/unix/SDL_sysurl.c",
"power/macosx/SDL_syspower.c",
});
} else if (target.getOsTag() == .windows) {
try c_files.appendSlice(&.{
"core/windows/SDL_xinput.c",
"core/windows/SDL_windows.c",
"core/windows/SDL_hid.c",
"misc/windows/SDL_sysurl.c",
"locale/windows/SDL_syslocale.c",
"sensor/windows/SDL_windowssensor.c",
"power/windows/SDL_syspower.c",
"video/windows/SDL_windowsmodes.c",
"video/windows/SDL_windowsclipboard.c",
"video/windows/SDL_windowsopengles.c",
"video/windows/SDL_windowsevents.c",
"video/windows/SDL_windowsvideo.c",
"video/windows/SDL_windowskeyboard.c",
"video/windows/SDL_windowsshape.c",
"video/windows/SDL_windowswindow.c",
"video/windows/SDL_windowsvulkan.c",
"video/windows/SDL_windowsmouse.c",
"video/windows/SDL_windowsopengl.c",
"video/windows/SDL_windowsframebuffer.c",
"video/windows/SDL_windowsmessagebox.c",
"joystick/windows/SDL_rawinputjoystick.c",
"joystick/windows/SDL_dinputjoystick.c",
"joystick/windows/SDL_xinputjoystick.c",
"joystick/windows/SDL_windows_gaming_input.c",
"joystick/windows/SDL_windowsjoystick.c",
"haptic/windows/SDL_windowshaptic.c",
"haptic/windows/SDL_xinputhaptic.c",
"haptic/windows/SDL_dinputhaptic.c",
"audio/winmm/SDL_winmm.c",
"audio/directsound/SDL_directsound.c",
"audio/wasapi/SDL_wasapi.c",
"audio/wasapi/SDL_wasapi_win32.c",
"timer/windows/SDL_systimer.c",
"thread/windows/SDL_sysmutex.c",
"thread/windows/SDL_systhread.c",
"thread/windows/SDL_syssem.c",
"thread/windows/SDL_systls.c",
"thread/windows/SDL_syscond_cv.c",
"thread/generic/SDL_systls.c",
"thread/generic/SDL_syssem.c",
"thread/generic/SDL_sysmutex.c",
"thread/generic/SDL_systhread.c",
"thread/generic/SDL_syscond.c",
"loadso/windows/SDL_sysloadso.c",
"filesystem/windows/SDL_sysfilesystem.c",
});
}
for (c_files.items) |file| {
const path = b.fmt("{s}/vendor/src/{s}", .{ srcPath(), file });
lib.addCSourceFile(path, c_flags.items);
}
lib.linkLibC();
// Look for our custom SDL_config.h.
lib.addIncludeDir(srcPath());
// For local CMake generated config.
// lib.addIncludeDir(fromRoot(b, "vendor/build/include"));
lib.addIncludeDir(fromRoot(b, "vendor/include"));
if (target.getOsTag() == .linux) {
lib.addIncludeDir("/usr/include");
lib.addIncludeDir("/usr/include/x86_64-linux-gnu");
lib.addIncludeDir("/usr/include/dbus-1.0");
lib.addIncludeDir("/usr/lib/x86_64-linux-gnu/dbus-1.0/include");
} else if (builtin.os.tag == .macos and target.getOsTag() == .macos) {
if (target.isNativeOs()) {
lib.linkFramework("CoreFoundation");
} else {
lib.addFrameworkDir("/System/Library/Frameworks");
lib.setLibCFile(std.build.FileSource.relative("./lib/macos.libc"));
}
}
return lib;
}
pub fn linkLib(step: *std.build.LibExeObjStep, lib: *std.build.LibExeObjStep) void {
linkDeps(step);
step.linkLibrary(lib);
}
pub fn linkLibPath(step: *std.build.LibExeObjStep, path: []const u8) void {
linkDeps(step);
step.addAssemblyFile(path);
}
pub fn linkDeps(step: *std.build.LibExeObjStep) void {
if (builtin.os.tag == .macos and step.target.getOsTag() == .macos) {
// "sdl2_config --static-libs" tells us what we need
if (!step.target.isNativeOs()) {
step.addFrameworkDir("/System/Library/Frameworks");
step.addLibPath("/usr/lib"); // To find libiconv.
}
step.linkFramework("Cocoa");
step.linkFramework("IOKit");
step.linkFramework("CoreAudio");
step.linkFramework("CoreVideo");
step.linkFramework("Carbon");
step.linkFramework("Metal");
step.linkFramework("ForceFeedback");
step.linkFramework("AudioToolbox");
step.linkFramework("GameController");
step.linkFramework("CFNetwork");
step.linkSystemLibrary("iconv");
step.linkSystemLibrary("m");
} else if (step.target.getOsTag() == .windows and step.target.getAbi() == .gnu) {
step.linkSystemLibrary("setupapi");
step.linkSystemLibrary("ole32");
step.linkSystemLibrary("oleaut32");
step.linkSystemLibrary("gdi32");
step.linkSystemLibrary("imm32");
step.linkSystemLibrary("version");
step.linkSystemLibrary("winmm");
}
}
pub const Options = struct {
lib_path: ?[]const u8 = null,
};
pub fn buildAndLink(step: *std.build.LibExeObjStep, opts: Options) void {
if (opts.lib_path) |path| {
linkLibPath(step, path);
} else {
const lib = create(step.builder, step.target, step.build_mode) catch unreachable;
linkLib(step, lib);
}
}
fn srcPath() []const u8 {
return (std.fs.path.dirname(@src().file) orelse unreachable);
}
fn fromRoot(b: *std.build.Builder, rel_path: []const u8) []const u8 {
return std.fs.path.resolve(b.allocator, &.{ srcPath(), rel_path }) catch unreachable;
} | lib/sdl/lib.zig |
const std = @import("std");
const mem = std.mem;
const Math = @This();
allocator: *mem.Allocator,
array: []bool,
lo: u21 = 43,
hi: u21 = 126705,
pub fn init(allocator: *mem.Allocator) !Math {
var instance = Math{
.allocator = allocator,
.array = try allocator.alloc(bool, 126663),
};
mem.set(bool, instance.array, false);
var index: u21 = 0;
instance.array[0] = true;
index = 17;
while (index <= 19) : (index += 1) {
instance.array[index] = true;
}
instance.array[51] = true;
instance.array[81] = true;
instance.array[83] = true;
instance.array[129] = true;
instance.array[134] = true;
instance.array[172] = true;
instance.array[204] = true;
index = 933;
while (index <= 935) : (index += 1) {
instance.array[index] = true;
}
instance.array[938] = true;
index = 965;
while (index <= 966) : (index += 1) {
instance.array[index] = true;
}
index = 969;
while (index <= 970) : (index += 1) {
instance.array[index] = true;
}
instance.array[971] = true;
index = 1499;
while (index <= 1501) : (index += 1) {
instance.array[index] = true;
}
instance.array[8171] = true;
index = 8199;
while (index <= 8201) : (index += 1) {
instance.array[index] = true;
}
instance.array[8213] = true;
instance.array[8217] = true;
instance.array[8231] = true;
index = 8246;
while (index <= 8249) : (index += 1) {
instance.array[index] = true;
}
index = 8271;
while (index <= 8273) : (index += 1) {
instance.array[index] = true;
}
instance.array[8274] = true;
instance.array[8275] = true;
index = 8287;
while (index <= 8289) : (index += 1) {
instance.array[index] = true;
}
instance.array[8290] = true;
instance.array[8291] = true;
index = 8357;
while (index <= 8369) : (index += 1) {
instance.array[index] = true;
}
instance.array[8374] = true;
index = 8378;
while (index <= 8379) : (index += 1) {
instance.array[index] = true;
}
index = 8384;
while (index <= 8388) : (index += 1) {
instance.array[index] = true;
}
instance.array[8407] = true;
instance.array[8412] = true;
index = 8415;
while (index <= 8424) : (index += 1) {
instance.array[index] = true;
}
instance.array[8426] = true;
instance.array[8429] = true;
index = 8430;
while (index <= 8434) : (index += 1) {
instance.array[index] = true;
}
instance.array[8441] = true;
instance.array[8445] = true;
instance.array[8446] = true;
index = 8449;
while (index <= 8450) : (index += 1) {
instance.array[index] = true;
}
index = 8452;
while (index <= 8454) : (index += 1) {
instance.array[index] = true;
}
index = 8456;
while (index <= 8457) : (index += 1) {
instance.array[index] = true;
}
index = 8458;
while (index <= 8461) : (index += 1) {
instance.array[index] = true;
}
index = 8465;
while (index <= 8468) : (index += 1) {
instance.array[index] = true;
}
index = 8469;
while (index <= 8473) : (index += 1) {
instance.array[index] = true;
}
index = 8474;
while (index <= 8478) : (index += 1) {
instance.array[index] = true;
}
instance.array[8480] = true;
index = 8549;
while (index <= 8553) : (index += 1) {
instance.array[index] = true;
}
index = 8554;
while (index <= 8558) : (index += 1) {
instance.array[index] = true;
}
index = 8559;
while (index <= 8560) : (index += 1) {
instance.array[index] = true;
}
index = 8561;
while (index <= 8564) : (index += 1) {
instance.array[index] = true;
}
instance.array[8565] = true;
index = 8566;
while (index <= 8567) : (index += 1) {
instance.array[index] = true;
}
instance.array[8568] = true;
index = 8569;
while (index <= 8570) : (index += 1) {
instance.array[index] = true;
}
instance.array[8571] = true;
instance.array[8572] = true;
index = 8574;
while (index <= 8578) : (index += 1) {
instance.array[index] = true;
}
instance.array[8579] = true;
index = 8581;
while (index <= 8582) : (index += 1) {
instance.array[index] = true;
}
index = 8587;
while (index <= 8588) : (index += 1) {
instance.array[index] = true;
}
index = 8593;
while (index <= 8610) : (index += 1) {
instance.array[index] = true;
}
index = 8611;
while (index <= 8612) : (index += 1) {
instance.array[index] = true;
}
index = 8613;
while (index <= 8614) : (index += 1) {
instance.array[index] = true;
}
instance.array[8615] = true;
instance.array[8616] = true;
instance.array[8617] = true;
index = 8618;
while (index <= 8624) : (index += 1) {
instance.array[index] = true;
}
instance.array[8626] = true;
index = 8633;
while (index <= 8634) : (index += 1) {
instance.array[index] = true;
}
index = 8649;
while (index <= 8916) : (index += 1) {
instance.array[index] = true;
}
instance.array[8925] = true;
instance.array[8926] = true;
instance.array[8927] = true;
instance.array[8928] = true;
index = 8949;
while (index <= 8950) : (index += 1) {
instance.array[index] = true;
}
instance.array[9041] = true;
index = 9072;
while (index <= 9096) : (index += 1) {
instance.array[index] = true;
}
index = 9097;
while (index <= 9098) : (index += 1) {
instance.array[index] = true;
}
instance.array[9100] = true;
instance.array[9125] = true;
index = 9137;
while (index <= 9142) : (index += 1) {
instance.array[index] = true;
}
instance.array[9143] = true;
index = 9589;
while (index <= 9590) : (index += 1) {
instance.array[index] = true;
}
index = 9603;
while (index <= 9611) : (index += 1) {
instance.array[index] = true;
}
instance.array[9612] = true;
index = 9617;
while (index <= 9621) : (index += 1) {
instance.array[index] = true;
}
instance.array[9622] = true;
index = 9627;
while (index <= 9628) : (index += 1) {
instance.array[index] = true;
}
index = 9631;
while (index <= 9632) : (index += 1) {
instance.array[index] = true;
}
index = 9636;
while (index <= 9640) : (index += 1) {
instance.array[index] = true;
}
instance.array[9655] = true;
instance.array[9657] = true;
index = 9660;
while (index <= 9665) : (index += 1) {
instance.array[index] = true;
}
index = 9677;
while (index <= 9684) : (index += 1) {
instance.array[index] = true;
}
index = 9690;
while (index <= 9691) : (index += 1) {
instance.array[index] = true;
}
instance.array[9749] = true;
instance.array[9751] = true;
index = 9781;
while (index <= 9784) : (index += 1) {
instance.array[index] = true;
}
index = 9794;
while (index <= 9795) : (index += 1) {
instance.array[index] = true;
}
instance.array[9796] = true;
index = 10133;
while (index <= 10137) : (index += 1) {
instance.array[index] = true;
}
instance.array[10138] = true;
instance.array[10139] = true;
index = 10140;
while (index <= 10170) : (index += 1) {
instance.array[index] = true;
}
instance.array[10171] = true;
instance.array[10172] = true;
instance.array[10173] = true;
instance.array[10174] = true;
instance.array[10175] = true;
instance.array[10176] = true;
instance.array[10177] = true;
instance.array[10178] = true;
instance.array[10179] = true;
instance.array[10180] = true;
index = 10181;
while (index <= 10196) : (index += 1) {
instance.array[index] = true;
}
index = 10453;
while (index <= 10583) : (index += 1) {
instance.array[index] = true;
}
instance.array[10584] = true;
instance.array[10585] = true;
instance.array[10586] = true;
instance.array[10587] = true;
instance.array[10588] = true;
instance.array[10589] = true;
instance.array[10590] = true;
instance.array[10591] = true;
instance.array[10592] = true;
instance.array[10593] = true;
instance.array[10594] = true;
instance.array[10595] = true;
instance.array[10596] = true;
instance.array[10597] = true;
instance.array[10598] = true;
instance.array[10599] = true;
instance.array[10600] = true;
instance.array[10601] = true;
instance.array[10602] = true;
instance.array[10603] = true;
instance.array[10604] = true;
instance.array[10605] = true;
index = 10606;
while (index <= 10668) : (index += 1) {
instance.array[index] = true;
}
instance.array[10669] = true;
instance.array[10670] = true;
instance.array[10671] = true;
instance.array[10672] = true;
index = 10673;
while (index <= 10704) : (index += 1) {
instance.array[index] = true;
}
instance.array[10705] = true;
instance.array[10706] = true;
index = 10707;
while (index <= 10964) : (index += 1) {
instance.array[index] = true;
}
index = 11013;
while (index <= 11033) : (index += 1) {
instance.array[index] = true;
}
index = 11036;
while (index <= 11041) : (index += 1) {
instance.array[index] = true;
}
instance.array[64254] = true;
instance.array[65078] = true;
instance.array[65079] = true;
instance.array[65080] = true;
index = 65081;
while (index <= 65083) : (index += 1) {
instance.array[index] = true;
}
instance.array[65085] = true;
instance.array[65248] = true;
index = 65265;
while (index <= 65267) : (index += 1) {
instance.array[index] = true;
}
instance.array[65297] = true;
instance.array[65299] = true;
instance.array[65329] = true;
instance.array[65331] = true;
instance.array[65463] = true;
index = 65470;
while (index <= 65473) : (index += 1) {
instance.array[index] = true;
}
index = 119765;
while (index <= 119849) : (index += 1) {
instance.array[index] = true;
}
index = 119851;
while (index <= 119921) : (index += 1) {
instance.array[index] = true;
}
index = 119923;
while (index <= 119924) : (index += 1) {
instance.array[index] = true;
}
instance.array[119927] = true;
index = 119930;
while (index <= 119931) : (index += 1) {
instance.array[index] = true;
}
index = 119934;
while (index <= 119937) : (index += 1) {
instance.array[index] = true;
}
index = 119939;
while (index <= 119950) : (index += 1) {
instance.array[index] = true;
}
instance.array[119952] = true;
index = 119954;
while (index <= 119960) : (index += 1) {
instance.array[index] = true;
}
index = 119962;
while (index <= 120026) : (index += 1) {
instance.array[index] = true;
}
index = 120028;
while (index <= 120031) : (index += 1) {
instance.array[index] = true;
}
index = 120034;
while (index <= 120041) : (index += 1) {
instance.array[index] = true;
}
index = 120043;
while (index <= 120049) : (index += 1) {
instance.array[index] = true;
}
index = 120051;
while (index <= 120078) : (index += 1) {
instance.array[index] = true;
}
index = 120080;
while (index <= 120083) : (index += 1) {
instance.array[index] = true;
}
index = 120085;
while (index <= 120089) : (index += 1) {
instance.array[index] = true;
}
instance.array[120091] = true;
index = 120095;
while (index <= 120101) : (index += 1) {
instance.array[index] = true;
}
index = 120103;
while (index <= 120442) : (index += 1) {
instance.array[index] = true;
}
index = 120445;
while (index <= 120469) : (index += 1) {
instance.array[index] = true;
}
instance.array[120470] = true;
index = 120471;
while (index <= 120495) : (index += 1) {
instance.array[index] = true;
}
instance.array[120496] = true;
index = 120497;
while (index <= 120527) : (index += 1) {
instance.array[index] = true;
}
instance.array[120528] = true;
index = 120529;
while (index <= 120553) : (index += 1) {
instance.array[index] = true;
}
instance.array[120554] = true;
index = 120555;
while (index <= 120585) : (index += 1) {
instance.array[index] = true;
}
instance.array[120586] = true;
index = 120587;
while (index <= 120611) : (index += 1) {
instance.array[index] = true;
}
instance.array[120612] = true;
index = 120613;
while (index <= 120643) : (index += 1) {
instance.array[index] = true;
}
instance.array[120644] = true;
index = 120645;
while (index <= 120669) : (index += 1) {
instance.array[index] = true;
}
instance.array[120670] = true;
index = 120671;
while (index <= 120701) : (index += 1) {
instance.array[index] = true;
}
instance.array[120702] = true;
index = 120703;
while (index <= 120727) : (index += 1) {
instance.array[index] = true;
}
instance.array[120728] = true;
index = 120729;
while (index <= 120736) : (index += 1) {
instance.array[index] = true;
}
index = 120739;
while (index <= 120788) : (index += 1) {
instance.array[index] = true;
}
index = 126421;
while (index <= 126424) : (index += 1) {
instance.array[index] = true;
}
index = 126426;
while (index <= 126452) : (index += 1) {
instance.array[index] = true;
}
index = 126454;
while (index <= 126455) : (index += 1) {
instance.array[index] = true;
}
instance.array[126457] = true;
instance.array[126460] = true;
index = 126462;
while (index <= 126471) : (index += 1) {
instance.array[index] = true;
}
index = 126473;
while (index <= 126476) : (index += 1) {
instance.array[index] = true;
}
instance.array[126478] = true;
instance.array[126480] = true;
instance.array[126487] = true;
instance.array[126492] = true;
instance.array[126494] = true;
instance.array[126496] = true;
index = 126498;
while (index <= 126500) : (index += 1) {
instance.array[index] = true;
}
index = 126502;
while (index <= 126503) : (index += 1) {
instance.array[index] = true;
}
instance.array[126505] = true;
instance.array[126508] = true;
instance.array[126510] = true;
instance.array[126512] = true;
instance.array[126514] = true;
instance.array[126516] = true;
index = 126518;
while (index <= 126519) : (index += 1) {
instance.array[index] = true;
}
instance.array[126521] = true;
index = 126524;
while (index <= 126527) : (index += 1) {
instance.array[index] = true;
}
index = 126529;
while (index <= 126535) : (index += 1) {
instance.array[index] = true;
}
index = 126537;
while (index <= 126540) : (index += 1) {
instance.array[index] = true;
}
index = 126542;
while (index <= 126545) : (index += 1) {
instance.array[index] = true;
}
instance.array[126547] = true;
index = 126549;
while (index <= 126558) : (index += 1) {
instance.array[index] = true;
}
index = 126560;
while (index <= 126576) : (index += 1) {
instance.array[index] = true;
}
index = 126582;
while (index <= 126584) : (index += 1) {
instance.array[index] = true;
}
index = 126586;
while (index <= 126590) : (index += 1) {
instance.array[index] = true;
}
index = 126592;
while (index <= 126608) : (index += 1) {
instance.array[index] = true;
}
index = 126661;
while (index <= 126662) : (index += 1) {
instance.array[index] = true;
}
// Placeholder: 0. Struct name, 1. Code point kind
return instance;
}
pub fn deinit(self: *Math) void {
self.allocator.free(self.array);
}
// isMath checks if cp is of the kind Math.
pub fn isMath(self: Math, cp: u21) bool {
if (cp < self.lo or cp > self.hi) return false;
const index = cp - self.lo;
return if (index >= self.array.len) false else self.array[index];
} | src/components/autogen/DerivedCoreProperties/Math.zig |
const std = @import("std");
const engine = @import("kiragine");
usingnamespace engine.kira.log;
const windowWidth = 1024;
const windowHeight = 768;
const title = "Packer";
const targetfps = 60;
var texture: engine.Texture = undefined;
const rect: engine.Rectangle = .{ .x = 500, .y = 380, .width = 32 * 3, .height = 32 * 3 };
const rect2: engine.Rectangle = .{ .x = 300, .y = 400, .width = 32 * 6, .height = 32 * 6 };
const srcrect: engine.Rectangle = .{ .x = 0, .y = 0, .width = 32, .height = 32 };
fn draw() !void {
engine.clearScreen(0.1, 0.1, 0.1, 1.0);
// Enable the texture batch with given texture
engine.enableTextureBatch2D(texture);
// Push the quad batch, it can't be mixed with any other 'cuz it's textured
try engine.pushBatch2D(engine.Renderer2DBatchTag.quads);
// Draw texture rotated
try engine.drawTextureRotated(rect2, srcrect, .{ .x = 16, .y = 16 }, engine.kira.math.deg2radf(45), engine.Colour.rgba(255, 0, 0, 255));
// Draw texture
try engine.drawTexture(rect, srcrect, engine.Colour.rgba(255, 255, 255, 255));
// Pops the current batch
try engine.popBatch2D();
// Disable the texture batch
engine.disableTextureBatch2D();
}
pub fn main() !void {
const callbacks = engine.Callbacks{
.draw = draw,
};
try engine.init(callbacks, windowWidth, windowHeight, title, targetfps, std.heap.page_allocator);
var file: std.fs.File = undefined;
var test0png = engine.kira.utils.DataPacker.Element{};
var test1png = engine.kira.utils.DataPacker.Element{};
// Pack the data into a file
{
var packer = try engine.kira.utils.DataPacker.init(std.heap.page_allocator, 1024);
defer packer.deinit();
{
file = try std.fs.cwd().openFile("assets/test.png", .{});
const testpnglen = try file.getEndPos();
const stream = file.reader();
const testpng = try stream.readAllAlloc(std.heap.page_allocator, testpnglen);
file.close();
test0png = try packer.append(testpng);
std.heap.page_allocator.free(testpng);
}
{
file = try std.fs.cwd().openFile("assets/test2.png", .{});
const testpng2len = try file.getEndPos();
const stream = file.reader();
const testpng2 = try stream.readAllAlloc(std.heap.page_allocator, testpng2len);
test1png = try packer.append(testpng2);
file.close();
std.heap.page_allocator.free(testpng2);
}
file = try std.fs.cwd().createFile("testbuf", .{});
try file.writeAll(packer.buffer[0..packer.stack]);
file.close();
}
// Read the packed data from file
file = try std.fs.cwd().openFile("testbuf", .{});
const stream = file.reader();
const buffer = try stream.readAllAlloc(std.heap.page_allocator, test1png.end);
file.close();
texture = try engine.Texture.createFromPNGMemory(buffer[test1png.start..test1png.end]);
std.heap.page_allocator.free(buffer);
try engine.open();
try engine.update();
texture.destroy();
try engine.deinit();
} | examples/packer.zig |
const Version = @import("std").builtin.Version;
pub const Word = u32;
pub const IdResultType = struct {
id: Word,
pub fn toRef(self: IdResultType) IdRef {
return .{ .id = self.id };
}
};
pub const IdResult = struct {
id: Word,
pub fn toRef(self: IdResult) IdRef {
return .{ .id = self.id };
}
pub fn toResultType(self: IdResult) IdResultType {
return .{ .id = self.id };
}
};
pub const IdRef = struct { id: Word };
pub const IdMemorySemantics = IdRef;
pub const IdScope = IdRef;
pub const LiteralInteger = Word;
pub const LiteralString = []const u8;
pub const LiteralContextDependentNumber = union(enum) {
int32: i32,
uint32: u32,
int64: i64,
uint64: u64,
float32: f32,
float64: f64,
};
pub const LiteralExtInstInteger = struct { inst: Word };
pub const LiteralSpecConstantOpInteger = struct { opcode: Opcode };
pub const PairLiteralIntegerIdRef = struct { value: LiteralInteger, label: IdRef };
pub const PairIdRefLiteralInteger = struct { target: IdRef, member: LiteralInteger };
pub const PairIdRefIdRef = [2]IdRef;
pub const version = Version{ .major = 1, .minor = 5, .patch = 4 };
pub const magic_number: Word = 0x07230203;
pub const Opcode = enum(u16) {
OpNop = 0,
OpUndef = 1,
OpSourceContinued = 2,
OpSource = 3,
OpSourceExtension = 4,
OpName = 5,
OpMemberName = 6,
OpString = 7,
OpLine = 8,
OpExtension = 10,
OpExtInstImport = 11,
OpExtInst = 12,
OpMemoryModel = 14,
OpEntryPoint = 15,
OpExecutionMode = 16,
OpCapability = 17,
OpTypeVoid = 19,
OpTypeBool = 20,
OpTypeInt = 21,
OpTypeFloat = 22,
OpTypeVector = 23,
OpTypeMatrix = 24,
OpTypeImage = 25,
OpTypeSampler = 26,
OpTypeSampledImage = 27,
OpTypeArray = 28,
OpTypeRuntimeArray = 29,
OpTypeStruct = 30,
OpTypeOpaque = 31,
OpTypePointer = 32,
OpTypeFunction = 33,
OpTypeEvent = 34,
OpTypeDeviceEvent = 35,
OpTypeReserveId = 36,
OpTypeQueue = 37,
OpTypePipe = 38,
OpTypeForwardPointer = 39,
OpConstantTrue = 41,
OpConstantFalse = 42,
OpConstant = 43,
OpConstantComposite = 44,
OpConstantSampler = 45,
OpConstantNull = 46,
OpSpecConstantTrue = 48,
OpSpecConstantFalse = 49,
OpSpecConstant = 50,
OpSpecConstantComposite = 51,
OpSpecConstantOp = 52,
OpFunction = 54,
OpFunctionParameter = 55,
OpFunctionEnd = 56,
OpFunctionCall = 57,
OpVariable = 59,
OpImageTexelPointer = 60,
OpLoad = 61,
OpStore = 62,
OpCopyMemory = 63,
OpCopyMemorySized = 64,
OpAccessChain = 65,
OpInBoundsAccessChain = 66,
OpPtrAccessChain = 67,
OpArrayLength = 68,
OpGenericPtrMemSemantics = 69,
OpInBoundsPtrAccessChain = 70,
OpDecorate = 71,
OpMemberDecorate = 72,
OpDecorationGroup = 73,
OpGroupDecorate = 74,
OpGroupMemberDecorate = 75,
OpVectorExtractDynamic = 77,
OpVectorInsertDynamic = 78,
OpVectorShuffle = 79,
OpCompositeConstruct = 80,
OpCompositeExtract = 81,
OpCompositeInsert = 82,
OpCopyObject = 83,
OpTranspose = 84,
OpSampledImage = 86,
OpImageSampleImplicitLod = 87,
OpImageSampleExplicitLod = 88,
OpImageSampleDrefImplicitLod = 89,
OpImageSampleDrefExplicitLod = 90,
OpImageSampleProjImplicitLod = 91,
OpImageSampleProjExplicitLod = 92,
OpImageSampleProjDrefImplicitLod = 93,
OpImageSampleProjDrefExplicitLod = 94,
OpImageFetch = 95,
OpImageGather = 96,
OpImageDrefGather = 97,
OpImageRead = 98,
OpImageWrite = 99,
OpImage = 100,
OpImageQueryFormat = 101,
OpImageQueryOrder = 102,
OpImageQuerySizeLod = 103,
OpImageQuerySize = 104,
OpImageQueryLod = 105,
OpImageQueryLevels = 106,
OpImageQuerySamples = 107,
OpConvertFToU = 109,
OpConvertFToS = 110,
OpConvertSToF = 111,
OpConvertUToF = 112,
OpUConvert = 113,
OpSConvert = 114,
OpFConvert = 115,
OpQuantizeToF16 = 116,
OpConvertPtrToU = 117,
OpSatConvertSToU = 118,
OpSatConvertUToS = 119,
OpConvertUToPtr = 120,
OpPtrCastToGeneric = 121,
OpGenericCastToPtr = 122,
OpGenericCastToPtrExplicit = 123,
OpBitcast = 124,
OpSNegate = 126,
OpFNegate = 127,
OpIAdd = 128,
OpFAdd = 129,
OpISub = 130,
OpFSub = 131,
OpIMul = 132,
OpFMul = 133,
OpUDiv = 134,
OpSDiv = 135,
OpFDiv = 136,
OpUMod = 137,
OpSRem = 138,
OpSMod = 139,
OpFRem = 140,
OpFMod = 141,
OpVectorTimesScalar = 142,
OpMatrixTimesScalar = 143,
OpVectorTimesMatrix = 144,
OpMatrixTimesVector = 145,
OpMatrixTimesMatrix = 146,
OpOuterProduct = 147,
OpDot = 148,
OpIAddCarry = 149,
OpISubBorrow = 150,
OpUMulExtended = 151,
OpSMulExtended = 152,
OpAny = 154,
OpAll = 155,
OpIsNan = 156,
OpIsInf = 157,
OpIsFinite = 158,
OpIsNormal = 159,
OpSignBitSet = 160,
OpLessOrGreater = 161,
OpOrdered = 162,
OpUnordered = 163,
OpLogicalEqual = 164,
OpLogicalNotEqual = 165,
OpLogicalOr = 166,
OpLogicalAnd = 167,
OpLogicalNot = 168,
OpSelect = 169,
OpIEqual = 170,
OpINotEqual = 171,
OpUGreaterThan = 172,
OpSGreaterThan = 173,
OpUGreaterThanEqual = 174,
OpSGreaterThanEqual = 175,
OpULessThan = 176,
OpSLessThan = 177,
OpULessThanEqual = 178,
OpSLessThanEqual = 179,
OpFOrdEqual = 180,
OpFUnordEqual = 181,
OpFOrdNotEqual = 182,
OpFUnordNotEqual = 183,
OpFOrdLessThan = 184,
OpFUnordLessThan = 185,
OpFOrdGreaterThan = 186,
OpFUnordGreaterThan = 187,
OpFOrdLessThanEqual = 188,
OpFUnordLessThanEqual = 189,
OpFOrdGreaterThanEqual = 190,
OpFUnordGreaterThanEqual = 191,
OpShiftRightLogical = 194,
OpShiftRightArithmetic = 195,
OpShiftLeftLogical = 196,
OpBitwiseOr = 197,
OpBitwiseXor = 198,
OpBitwiseAnd = 199,
OpNot = 200,
OpBitFieldInsert = 201,
OpBitFieldSExtract = 202,
OpBitFieldUExtract = 203,
OpBitReverse = 204,
OpBitCount = 205,
OpDPdx = 207,
OpDPdy = 208,
OpFwidth = 209,
OpDPdxFine = 210,
OpDPdyFine = 211,
OpFwidthFine = 212,
OpDPdxCoarse = 213,
OpDPdyCoarse = 214,
OpFwidthCoarse = 215,
OpEmitVertex = 218,
OpEndPrimitive = 219,
OpEmitStreamVertex = 220,
OpEndStreamPrimitive = 221,
OpControlBarrier = 224,
OpMemoryBarrier = 225,
OpAtomicLoad = 227,
OpAtomicStore = 228,
OpAtomicExchange = 229,
OpAtomicCompareExchange = 230,
OpAtomicCompareExchangeWeak = 231,
OpAtomicIIncrement = 232,
OpAtomicIDecrement = 233,
OpAtomicIAdd = 234,
OpAtomicISub = 235,
OpAtomicSMin = 236,
OpAtomicUMin = 237,
OpAtomicSMax = 238,
OpAtomicUMax = 239,
OpAtomicAnd = 240,
OpAtomicOr = 241,
OpAtomicXor = 242,
OpPhi = 245,
OpLoopMerge = 246,
OpSelectionMerge = 247,
OpLabel = 248,
OpBranch = 249,
OpBranchConditional = 250,
OpSwitch = 251,
OpKill = 252,
OpReturn = 253,
OpReturnValue = 254,
OpUnreachable = 255,
OpLifetimeStart = 256,
OpLifetimeStop = 257,
OpGroupAsyncCopy = 259,
OpGroupWaitEvents = 260,
OpGroupAll = 261,
OpGroupAny = 262,
OpGroupBroadcast = 263,
OpGroupIAdd = 264,
OpGroupFAdd = 265,
OpGroupFMin = 266,
OpGroupUMin = 267,
OpGroupSMin = 268,
OpGroupFMax = 269,
OpGroupUMax = 270,
OpGroupSMax = 271,
OpReadPipe = 274,
OpWritePipe = 275,
OpReservedReadPipe = 276,
OpReservedWritePipe = 277,
OpReserveReadPipePackets = 278,
OpReserveWritePipePackets = 279,
OpCommitReadPipe = 280,
OpCommitWritePipe = 281,
OpIsValidReserveId = 282,
OpGetNumPipePackets = 283,
OpGetMaxPipePackets = 284,
OpGroupReserveReadPipePackets = 285,
OpGroupReserveWritePipePackets = 286,
OpGroupCommitReadPipe = 287,
OpGroupCommitWritePipe = 288,
OpEnqueueMarker = 291,
OpEnqueueKernel = 292,
OpGetKernelNDrangeSubGroupCount = 293,
OpGetKernelNDrangeMaxSubGroupSize = 294,
OpGetKernelWorkGroupSize = 295,
OpGetKernelPreferredWorkGroupSizeMultiple = 296,
OpRetainEvent = 297,
OpReleaseEvent = 298,
OpCreateUserEvent = 299,
OpIsValidEvent = 300,
OpSetUserEventStatus = 301,
OpCaptureEventProfilingInfo = 302,
OpGetDefaultQueue = 303,
OpBuildNDRange = 304,
OpImageSparseSampleImplicitLod = 305,
OpImageSparseSampleExplicitLod = 306,
OpImageSparseSampleDrefImplicitLod = 307,
OpImageSparseSampleDrefExplicitLod = 308,
OpImageSparseSampleProjImplicitLod = 309,
OpImageSparseSampleProjExplicitLod = 310,
OpImageSparseSampleProjDrefImplicitLod = 311,
OpImageSparseSampleProjDrefExplicitLod = 312,
OpImageSparseFetch = 313,
OpImageSparseGather = 314,
OpImageSparseDrefGather = 315,
OpImageSparseTexelsResident = 316,
OpNoLine = 317,
OpAtomicFlagTestAndSet = 318,
OpAtomicFlagClear = 319,
OpImageSparseRead = 320,
OpSizeOf = 321,
OpTypePipeStorage = 322,
OpConstantPipeStorage = 323,
OpCreatePipeFromPipeStorage = 324,
OpGetKernelLocalSizeForSubgroupCount = 325,
OpGetKernelMaxNumSubgroups = 326,
OpTypeNamedBarrier = 327,
OpNamedBarrierInitialize = 328,
OpMemoryNamedBarrier = 329,
OpModuleProcessed = 330,
OpExecutionModeId = 331,
OpDecorateId = 332,
OpGroupNonUniformElect = 333,
OpGroupNonUniformAll = 334,
OpGroupNonUniformAny = 335,
OpGroupNonUniformAllEqual = 336,
OpGroupNonUniformBroadcast = 337,
OpGroupNonUniformBroadcastFirst = 338,
OpGroupNonUniformBallot = 339,
OpGroupNonUniformInverseBallot = 340,
OpGroupNonUniformBallotBitExtract = 341,
OpGroupNonUniformBallotBitCount = 342,
OpGroupNonUniformBallotFindLSB = 343,
OpGroupNonUniformBallotFindMSB = 344,
OpGroupNonUniformShuffle = 345,
OpGroupNonUniformShuffleXor = 346,
OpGroupNonUniformShuffleUp = 347,
OpGroupNonUniformShuffleDown = 348,
OpGroupNonUniformIAdd = 349,
OpGroupNonUniformFAdd = 350,
OpGroupNonUniformIMul = 351,
OpGroupNonUniformFMul = 352,
OpGroupNonUniformSMin = 353,
OpGroupNonUniformUMin = 354,
OpGroupNonUniformFMin = 355,
OpGroupNonUniformSMax = 356,
OpGroupNonUniformUMax = 357,
OpGroupNonUniformFMax = 358,
OpGroupNonUniformBitwiseAnd = 359,
OpGroupNonUniformBitwiseOr = 360,
OpGroupNonUniformBitwiseXor = 361,
OpGroupNonUniformLogicalAnd = 362,
OpGroupNonUniformLogicalOr = 363,
OpGroupNonUniformLogicalXor = 364,
OpGroupNonUniformQuadBroadcast = 365,
OpGroupNonUniformQuadSwap = 366,
OpCopyLogical = 400,
OpPtrEqual = 401,
OpPtrNotEqual = 402,
OpPtrDiff = 403,
OpTerminateInvocation = 4416,
OpSubgroupBallotKHR = 4421,
OpSubgroupFirstInvocationKHR = 4422,
OpSubgroupAllKHR = 4428,
OpSubgroupAnyKHR = 4429,
OpSubgroupAllEqualKHR = 4430,
OpSubgroupReadInvocationKHR = 4432,
OpTraceRayKHR = 4445,
OpExecuteCallableKHR = 4446,
OpConvertUToAccelerationStructureKHR = 4447,
OpIgnoreIntersectionKHR = 4448,
OpTerminateRayKHR = 4449,
OpTypeRayQueryKHR = 4472,
OpRayQueryInitializeKHR = 4473,
OpRayQueryTerminateKHR = 4474,
OpRayQueryGenerateIntersectionKHR = 4475,
OpRayQueryConfirmIntersectionKHR = 4476,
OpRayQueryProceedKHR = 4477,
OpRayQueryGetIntersectionTypeKHR = 4479,
OpGroupIAddNonUniformAMD = 5000,
OpGroupFAddNonUniformAMD = 5001,
OpGroupFMinNonUniformAMD = 5002,
OpGroupUMinNonUniformAMD = 5003,
OpGroupSMinNonUniformAMD = 5004,
OpGroupFMaxNonUniformAMD = 5005,
OpGroupUMaxNonUniformAMD = 5006,
OpGroupSMaxNonUniformAMD = 5007,
OpFragmentMaskFetchAMD = 5011,
OpFragmentFetchAMD = 5012,
OpReadClockKHR = 5056,
OpImageSampleFootprintNV = 5283,
OpGroupNonUniformPartitionNV = 5296,
OpWritePackedPrimitiveIndices4x8NV = 5299,
OpReportIntersectionKHR = 5334,
OpIgnoreIntersectionNV = 5335,
OpTerminateRayNV = 5336,
OpTraceNV = 5337,
OpTypeAccelerationStructureKHR = 5341,
OpExecuteCallableNV = 5344,
OpTypeCooperativeMatrixNV = 5358,
OpCooperativeMatrixLoadNV = 5359,
OpCooperativeMatrixStoreNV = 5360,
OpCooperativeMatrixMulAddNV = 5361,
OpCooperativeMatrixLengthNV = 5362,
OpBeginInvocationInterlockEXT = 5364,
OpEndInvocationInterlockEXT = 5365,
OpDemoteToHelperInvocationEXT = 5380,
OpIsHelperInvocationEXT = 5381,
OpSubgroupShuffleINTEL = 5571,
OpSubgroupShuffleDownINTEL = 5572,
OpSubgroupShuffleUpINTEL = 5573,
OpSubgroupShuffleXorINTEL = 5574,
OpSubgroupBlockReadINTEL = 5575,
OpSubgroupBlockWriteINTEL = 5576,
OpSubgroupImageBlockReadINTEL = 5577,
OpSubgroupImageBlockWriteINTEL = 5578,
OpSubgroupImageMediaBlockReadINTEL = 5580,
OpSubgroupImageMediaBlockWriteINTEL = 5581,
OpUCountLeadingZerosINTEL = 5585,
OpUCountTrailingZerosINTEL = 5586,
OpAbsISubINTEL = 5587,
OpAbsUSubINTEL = 5588,
OpIAddSatINTEL = 5589,
OpUAddSatINTEL = 5590,
OpIAverageINTEL = 5591,
OpUAverageINTEL = 5592,
OpIAverageRoundedINTEL = 5593,
OpUAverageRoundedINTEL = 5594,
OpISubSatINTEL = 5595,
OpUSubSatINTEL = 5596,
OpIMul32x16INTEL = 5597,
OpUMul32x16INTEL = 5598,
OpConstFunctionPointerINTEL = 5600,
OpFunctionPointerCallINTEL = 5601,
OpAsmTargetINTEL = 5609,
OpAsmINTEL = 5610,
OpAsmCallINTEL = 5611,
OpAtomicFMinEXT = 5614,
OpAtomicFMaxEXT = 5615,
OpAssumeTrueKHR = 5630,
OpExpectKHR = 5631,
OpDecorateString = 5632,
OpMemberDecorateString = 5633,
OpVmeImageINTEL = 5699,
OpTypeVmeImageINTEL = 5700,
OpTypeAvcImePayloadINTEL = 5701,
OpTypeAvcRefPayloadINTEL = 5702,
OpTypeAvcSicPayloadINTEL = 5703,
OpTypeAvcMcePayloadINTEL = 5704,
OpTypeAvcMceResultINTEL = 5705,
OpTypeAvcImeResultINTEL = 5706,
OpTypeAvcImeResultSingleReferenceStreamoutINTEL = 5707,
OpTypeAvcImeResultDualReferenceStreamoutINTEL = 5708,
OpTypeAvcImeSingleReferenceStreaminINTEL = 5709,
OpTypeAvcImeDualReferenceStreaminINTEL = 5710,
OpTypeAvcRefResultINTEL = 5711,
OpTypeAvcSicResultINTEL = 5712,
OpSubgroupAvcMceGetDefaultInterBaseMultiReferencePenaltyINTEL = 5713,
OpSubgroupAvcMceSetInterBaseMultiReferencePenaltyINTEL = 5714,
OpSubgroupAvcMceGetDefaultInterShapePenaltyINTEL = 5715,
OpSubgroupAvcMceSetInterShapePenaltyINTEL = 5716,
OpSubgroupAvcMceGetDefaultInterDirectionPenaltyINTEL = 5717,
OpSubgroupAvcMceSetInterDirectionPenaltyINTEL = 5718,
OpSubgroupAvcMceGetDefaultIntraLumaShapePenaltyINTEL = 5719,
OpSubgroupAvcMceGetDefaultInterMotionVectorCostTableINTEL = 5720,
OpSubgroupAvcMceGetDefaultHighPenaltyCostTableINTEL = 5721,
OpSubgroupAvcMceGetDefaultMediumPenaltyCostTableINTEL = 5722,
OpSubgroupAvcMceGetDefaultLowPenaltyCostTableINTEL = 5723,
OpSubgroupAvcMceSetMotionVectorCostFunctionINTEL = 5724,
OpSubgroupAvcMceGetDefaultIntraLumaModePenaltyINTEL = 5725,
OpSubgroupAvcMceGetDefaultNonDcLumaIntraPenaltyINTEL = 5726,
OpSubgroupAvcMceGetDefaultIntraChromaModeBasePenaltyINTEL = 5727,
OpSubgroupAvcMceSetAcOnlyHaarINTEL = 5728,
OpSubgroupAvcMceSetSourceInterlacedFieldPolarityINTEL = 5729,
OpSubgroupAvcMceSetSingleReferenceInterlacedFieldPolarityINTEL = 5730,
OpSubgroupAvcMceSetDualReferenceInterlacedFieldPolaritiesINTEL = 5731,
OpSubgroupAvcMceConvertToImePayloadINTEL = 5732,
OpSubgroupAvcMceConvertToImeResultINTEL = 5733,
OpSubgroupAvcMceConvertToRefPayloadINTEL = 5734,
OpSubgroupAvcMceConvertToRefResultINTEL = 5735,
OpSubgroupAvcMceConvertToSicPayloadINTEL = 5736,
OpSubgroupAvcMceConvertToSicResultINTEL = 5737,
OpSubgroupAvcMceGetMotionVectorsINTEL = 5738,
OpSubgroupAvcMceGetInterDistortionsINTEL = 5739,
OpSubgroupAvcMceGetBestInterDistortionsINTEL = 5740,
OpSubgroupAvcMceGetInterMajorShapeINTEL = 5741,
OpSubgroupAvcMceGetInterMinorShapeINTEL = 5742,
OpSubgroupAvcMceGetInterDirectionsINTEL = 5743,
OpSubgroupAvcMceGetInterMotionVectorCountINTEL = 5744,
OpSubgroupAvcMceGetInterReferenceIdsINTEL = 5745,
OpSubgroupAvcMceGetInterReferenceInterlacedFieldPolaritiesINTEL = 5746,
OpSubgroupAvcImeInitializeINTEL = 5747,
OpSubgroupAvcImeSetSingleReferenceINTEL = 5748,
OpSubgroupAvcImeSetDualReferenceINTEL = 5749,
OpSubgroupAvcImeRefWindowSizeINTEL = 5750,
OpSubgroupAvcImeAdjustRefOffsetINTEL = 5751,
OpSubgroupAvcImeConvertToMcePayloadINTEL = 5752,
OpSubgroupAvcImeSetMaxMotionVectorCountINTEL = 5753,
OpSubgroupAvcImeSetUnidirectionalMixDisableINTEL = 5754,
OpSubgroupAvcImeSetEarlySearchTerminationThresholdINTEL = 5755,
OpSubgroupAvcImeSetWeightedSadINTEL = 5756,
OpSubgroupAvcImeEvaluateWithSingleReferenceINTEL = 5757,
OpSubgroupAvcImeEvaluateWithDualReferenceINTEL = 5758,
OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminINTEL = 5759,
OpSubgroupAvcImeEvaluateWithDualReferenceStreaminINTEL = 5760,
OpSubgroupAvcImeEvaluateWithSingleReferenceStreamoutINTEL = 5761,
OpSubgroupAvcImeEvaluateWithDualReferenceStreamoutINTEL = 5762,
OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminoutINTEL = 5763,
OpSubgroupAvcImeEvaluateWithDualReferenceStreaminoutINTEL = 5764,
OpSubgroupAvcImeConvertToMceResultINTEL = 5765,
OpSubgroupAvcImeGetSingleReferenceStreaminINTEL = 5766,
OpSubgroupAvcImeGetDualReferenceStreaminINTEL = 5767,
OpSubgroupAvcImeStripSingleReferenceStreamoutINTEL = 5768,
OpSubgroupAvcImeStripDualReferenceStreamoutINTEL = 5769,
OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeMotionVectorsINTEL = 5770,
OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeDistortionsINTEL = 5771,
OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeReferenceIdsINTEL = 5772,
OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeMotionVectorsINTEL = 5773,
OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeDistortionsINTEL = 5774,
OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeReferenceIdsINTEL = 5775,
OpSubgroupAvcImeGetBorderReachedINTEL = 5776,
OpSubgroupAvcImeGetTruncatedSearchIndicationINTEL = 5777,
OpSubgroupAvcImeGetUnidirectionalEarlySearchTerminationINTEL = 5778,
OpSubgroupAvcImeGetWeightingPatternMinimumMotionVectorINTEL = 5779,
OpSubgroupAvcImeGetWeightingPatternMinimumDistortionINTEL = 5780,
OpSubgroupAvcFmeInitializeINTEL = 5781,
OpSubgroupAvcBmeInitializeINTEL = 5782,
OpSubgroupAvcRefConvertToMcePayloadINTEL = 5783,
OpSubgroupAvcRefSetBidirectionalMixDisableINTEL = 5784,
OpSubgroupAvcRefSetBilinearFilterEnableINTEL = 5785,
OpSubgroupAvcRefEvaluateWithSingleReferenceINTEL = 5786,
OpSubgroupAvcRefEvaluateWithDualReferenceINTEL = 5787,
OpSubgroupAvcRefEvaluateWithMultiReferenceINTEL = 5788,
OpSubgroupAvcRefEvaluateWithMultiReferenceInterlacedINTEL = 5789,
OpSubgroupAvcRefConvertToMceResultINTEL = 5790,
OpSubgroupAvcSicInitializeINTEL = 5791,
OpSubgroupAvcSicConfigureSkcINTEL = 5792,
OpSubgroupAvcSicConfigureIpeLumaINTEL = 5793,
OpSubgroupAvcSicConfigureIpeLumaChromaINTEL = 5794,
OpSubgroupAvcSicGetMotionVectorMaskINTEL = 5795,
OpSubgroupAvcSicConvertToMcePayloadINTEL = 5796,
OpSubgroupAvcSicSetIntraLumaShapePenaltyINTEL = 5797,
OpSubgroupAvcSicSetIntraLumaModeCostFunctionINTEL = 5798,
OpSubgroupAvcSicSetIntraChromaModeCostFunctionINTEL = 5799,
OpSubgroupAvcSicSetBilinearFilterEnableINTEL = 5800,
OpSubgroupAvcSicSetSkcForwardTransformEnableINTEL = 5801,
OpSubgroupAvcSicSetBlockBasedRawSkipSadINTEL = 5802,
OpSubgroupAvcSicEvaluateIpeINTEL = 5803,
OpSubgroupAvcSicEvaluateWithSingleReferenceINTEL = 5804,
OpSubgroupAvcSicEvaluateWithDualReferenceINTEL = 5805,
OpSubgroupAvcSicEvaluateWithMultiReferenceINTEL = 5806,
OpSubgroupAvcSicEvaluateWithMultiReferenceInterlacedINTEL = 5807,
OpSubgroupAvcSicConvertToMceResultINTEL = 5808,
OpSubgroupAvcSicGetIpeLumaShapeINTEL = 5809,
OpSubgroupAvcSicGetBestIpeLumaDistortionINTEL = 5810,
OpSubgroupAvcSicGetBestIpeChromaDistortionINTEL = 5811,
OpSubgroupAvcSicGetPackedIpeLumaModesINTEL = 5812,
OpSubgroupAvcSicGetIpeChromaModeINTEL = 5813,
OpSubgroupAvcSicGetPackedSkcLumaCountThresholdINTEL = 5814,
OpSubgroupAvcSicGetPackedSkcLumaSumThresholdINTEL = 5815,
OpSubgroupAvcSicGetInterRawSadsINTEL = 5816,
OpVariableLengthArrayINTEL = 5818,
OpSaveMemoryINTEL = 5819,
OpRestoreMemoryINTEL = 5820,
OpLoopControlINTEL = 5887,
OpPtrCastToCrossWorkgroupINTEL = 5934,
OpCrossWorkgroupCastToPtrINTEL = 5938,
OpReadPipeBlockingINTEL = 5946,
OpWritePipeBlockingINTEL = 5947,
OpFPGARegINTEL = 5949,
OpRayQueryGetRayTMinKHR = 6016,
OpRayQueryGetRayFlagsKHR = 6017,
OpRayQueryGetIntersectionTKHR = 6018,
OpRayQueryGetIntersectionInstanceCustomIndexKHR = 6019,
OpRayQueryGetIntersectionInstanceIdKHR = 6020,
OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR = 6021,
OpRayQueryGetIntersectionGeometryIndexKHR = 6022,
OpRayQueryGetIntersectionPrimitiveIndexKHR = 6023,
OpRayQueryGetIntersectionBarycentricsKHR = 6024,
OpRayQueryGetIntersectionFrontFaceKHR = 6025,
OpRayQueryGetIntersectionCandidateAABBOpaqueKHR = 6026,
OpRayQueryGetIntersectionObjectRayDirectionKHR = 6027,
OpRayQueryGetIntersectionObjectRayOriginKHR = 6028,
OpRayQueryGetWorldRayDirectionKHR = 6029,
OpRayQueryGetWorldRayOriginKHR = 6030,
OpRayQueryGetIntersectionObjectToWorldKHR = 6031,
OpRayQueryGetIntersectionWorldToObjectKHR = 6032,
OpAtomicFAddEXT = 6035,
OpTypeBufferSurfaceINTEL = 6086,
OpTypeStructContinuedINTEL = 6090,
OpConstantCompositeContinuedINTEL = 6091,
OpSpecConstantCompositeContinuedINTEL = 6092,
pub const OpReportIntersectionNV = Opcode.OpReportIntersectionKHR;
pub const OpTypeAccelerationStructureNV = Opcode.OpTypeAccelerationStructureKHR;
pub const OpDecorateStringGOOGLE = Opcode.OpDecorateString;
pub const OpMemberDecorateStringGOOGLE = Opcode.OpMemberDecorateString;
pub fn Operands(comptime self: Opcode) type {
return switch (self) {
.OpNop => void,
.OpUndef => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSourceContinued => struct { continued_source: LiteralString },
.OpSource => struct { source_language: SourceLanguage, version: LiteralInteger, file: ?IdRef = null, source: ?LiteralString = null },
.OpSourceExtension => struct { extension: LiteralString },
.OpName => struct { target: IdRef, name: LiteralString },
.OpMemberName => struct { type: IdRef, member: LiteralInteger, name: LiteralString },
.OpString => struct { id_result: IdResult, string: LiteralString },
.OpLine => struct { file: IdRef, line: LiteralInteger, column: LiteralInteger },
.OpExtension => struct { name: LiteralString },
.OpExtInstImport => struct { id_result: IdResult, name: LiteralString },
.OpExtInst => struct { id_result_type: IdResultType, id_result: IdResult, set: IdRef, instruction: LiteralExtInstInteger, id_ref_4: []const IdRef = &.{} },
.OpMemoryModel => struct { addressing_model: AddressingModel, memory_model: MemoryModel },
.OpEntryPoint => struct { execution_model: ExecutionModel, entry_point: IdRef, name: LiteralString, interface: []const IdRef = &.{} },
.OpExecutionMode => struct { entry_point: IdRef, mode: ExecutionMode.Extended },
.OpCapability => struct { capability: Capability },
.OpTypeVoid => struct { id_result: IdResult },
.OpTypeBool => struct { id_result: IdResult },
.OpTypeInt => struct { id_result: IdResult, width: LiteralInteger, signedness: LiteralInteger },
.OpTypeFloat => struct { id_result: IdResult, width: LiteralInteger },
.OpTypeVector => struct { id_result: IdResult, component_type: IdRef, component_count: LiteralInteger },
.OpTypeMatrix => struct { id_result: IdResult, column_type: IdRef, column_count: LiteralInteger },
.OpTypeImage => struct { id_result: IdResult, sampled_type: IdRef, dim: Dim, depth: LiteralInteger, arrayed: LiteralInteger, ms: LiteralInteger, sampled: LiteralInteger, image_format: ImageFormat, access_qualifier: ?AccessQualifier = null },
.OpTypeSampler => struct { id_result: IdResult },
.OpTypeSampledImage => struct { id_result: IdResult, image_type: IdRef },
.OpTypeArray => struct { id_result: IdResult, element_type: IdRef, length: IdRef },
.OpTypeRuntimeArray => struct { id_result: IdResult, element_type: IdRef },
.OpTypeStruct => struct { id_result: IdResult, id_ref: []const IdRef = &.{} },
.OpTypeOpaque => struct { id_result: IdResult, literal_string: LiteralString },
.OpTypePointer => struct { id_result: IdResult, storage_class: StorageClass, type: IdRef },
.OpTypeFunction => struct { id_result: IdResult, return_type: IdRef, id_ref_2: []const IdRef = &.{} },
.OpTypeEvent => struct { id_result: IdResult },
.OpTypeDeviceEvent => struct { id_result: IdResult },
.OpTypeReserveId => struct { id_result: IdResult },
.OpTypeQueue => struct { id_result: IdResult },
.OpTypePipe => struct { id_result: IdResult, qualifier: AccessQualifier },
.OpTypeForwardPointer => struct { pointer_type: IdRef, storage_class: StorageClass },
.OpConstantTrue => struct { id_result_type: IdResultType, id_result: IdResult },
.OpConstantFalse => struct { id_result_type: IdResultType, id_result: IdResult },
.OpConstant => struct { id_result_type: IdResultType, id_result: IdResult, value: LiteralContextDependentNumber },
.OpConstantComposite => struct { id_result_type: IdResultType, id_result: IdResult, constituents: []const IdRef = &.{} },
.OpConstantSampler => struct { id_result_type: IdResultType, id_result: IdResult, sampler_addressing_mode: SamplerAddressingMode, param: LiteralInteger, sampler_filter_mode: SamplerFilterMode },
.OpConstantNull => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSpecConstantTrue => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSpecConstantFalse => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSpecConstant => struct { id_result_type: IdResultType, id_result: IdResult, value: LiteralContextDependentNumber },
.OpSpecConstantComposite => struct { id_result_type: IdResultType, id_result: IdResult, constituents: []const IdRef = &.{} },
.OpSpecConstantOp => struct { id_result_type: IdResultType, id_result: IdResult, opcode: LiteralSpecConstantOpInteger },
.OpFunction => struct { id_result_type: IdResultType, id_result: IdResult, function_control: FunctionControl, function_type: IdRef },
.OpFunctionParameter => struct { id_result_type: IdResultType, id_result: IdResult },
.OpFunctionEnd => void,
.OpFunctionCall => struct { id_result_type: IdResultType, id_result: IdResult, function: IdRef, id_ref_3: []const IdRef = &.{} },
.OpVariable => struct { id_result_type: IdResultType, id_result: IdResult, storage_class: StorageClass, initializer: ?IdRef = null },
.OpImageTexelPointer => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, coordinate: IdRef, sample: IdRef },
.OpLoad => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory_access: ?MemoryAccess.Extended = null },
.OpStore => struct { pointer: IdRef, object: IdRef, memory_access: ?MemoryAccess.Extended = null },
.OpCopyMemory => struct { target: IdRef, source: IdRef, memory_access_2: ?MemoryAccess.Extended = null, memory_access_3: ?MemoryAccess.Extended = null },
.OpCopyMemorySized => struct { target: IdRef, source: IdRef, size: IdRef, memory_access_3: ?MemoryAccess.Extended = null, memory_access_4: ?MemoryAccess.Extended = null },
.OpAccessChain => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, indexes: []const IdRef = &.{} },
.OpInBoundsAccessChain => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, indexes: []const IdRef = &.{} },
.OpPtrAccessChain => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, element: IdRef, indexes: []const IdRef = &.{} },
.OpArrayLength => struct { id_result_type: IdResultType, id_result: IdResult, structure: IdRef, array_member: LiteralInteger },
.OpGenericPtrMemSemantics => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef },
.OpInBoundsPtrAccessChain => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, element: IdRef, indexes: []const IdRef = &.{} },
.OpDecorate => struct { target: IdRef, decoration: Decoration.Extended },
.OpMemberDecorate => struct { structure_type: IdRef, member: LiteralInteger, decoration: Decoration.Extended },
.OpDecorationGroup => struct { id_result: IdResult },
.OpGroupDecorate => struct { decoration_group: IdRef, targets: []const IdRef = &.{} },
.OpGroupMemberDecorate => struct { decoration_group: IdRef, targets: []const PairIdRefLiteralInteger = &.{} },
.OpVectorExtractDynamic => struct { id_result_type: IdResultType, id_result: IdResult, vector: IdRef, index: IdRef },
.OpVectorInsertDynamic => struct { id_result_type: IdResultType, id_result: IdResult, vector: IdRef, component: IdRef, index: IdRef },
.OpVectorShuffle => struct { id_result_type: IdResultType, id_result: IdResult, vector_1: IdRef, vector_2: IdRef, components: []const LiteralInteger = &.{} },
.OpCompositeConstruct => struct { id_result_type: IdResultType, id_result: IdResult, constituents: []const IdRef = &.{} },
.OpCompositeExtract => struct { id_result_type: IdResultType, id_result: IdResult, composite: IdRef, indexes: []const LiteralInteger = &.{} },
.OpCompositeInsert => struct { id_result_type: IdResultType, id_result: IdResult, object: IdRef, composite: IdRef, indexes: []const LiteralInteger = &.{} },
.OpCopyObject => struct { id_result_type: IdResultType, id_result: IdResult, operand: IdRef },
.OpTranspose => struct { id_result_type: IdResultType, id_result: IdResult, matrix: IdRef },
.OpSampledImage => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, sampler: IdRef },
.OpImageSampleImplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSampleExplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, image_operands: ImageOperands.Extended },
.OpImageSampleDrefImplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSampleDrefExplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ImageOperands.Extended },
.OpImageSampleProjImplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSampleProjExplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, image_operands: ImageOperands.Extended },
.OpImageSampleProjDrefImplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSampleProjDrefExplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ImageOperands.Extended },
.OpImageFetch => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, coordinate: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageGather => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, component: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageDrefGather => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageRead => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, coordinate: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageWrite => struct { image: IdRef, coordinate: IdRef, texel: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImage => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef },
.OpImageQueryFormat => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef },
.OpImageQueryOrder => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef },
.OpImageQuerySizeLod => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, level_of_detail: IdRef },
.OpImageQuerySize => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef },
.OpImageQueryLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef },
.OpImageQueryLevels => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef },
.OpImageQuerySamples => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef },
.OpConvertFToU => struct { id_result_type: IdResultType, id_result: IdResult, float_value: IdRef },
.OpConvertFToS => struct { id_result_type: IdResultType, id_result: IdResult, float_value: IdRef },
.OpConvertSToF => struct { id_result_type: IdResultType, id_result: IdResult, signed_value: IdRef },
.OpConvertUToF => struct { id_result_type: IdResultType, id_result: IdResult, unsigned_value: IdRef },
.OpUConvert => struct { id_result_type: IdResultType, id_result: IdResult, unsigned_value: IdRef },
.OpSConvert => struct { id_result_type: IdResultType, id_result: IdResult, signed_value: IdRef },
.OpFConvert => struct { id_result_type: IdResultType, id_result: IdResult, float_value: IdRef },
.OpQuantizeToF16 => struct { id_result_type: IdResultType, id_result: IdResult, value: IdRef },
.OpConvertPtrToU => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef },
.OpSatConvertSToU => struct { id_result_type: IdResultType, id_result: IdResult, signed_value: IdRef },
.OpSatConvertUToS => struct { id_result_type: IdResultType, id_result: IdResult, unsigned_value: IdRef },
.OpConvertUToPtr => struct { id_result_type: IdResultType, id_result: IdResult, integer_value: IdRef },
.OpPtrCastToGeneric => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef },
.OpGenericCastToPtr => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef },
.OpGenericCastToPtrExplicit => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, storage: StorageClass },
.OpBitcast => struct { id_result_type: IdResultType, id_result: IdResult, operand: IdRef },
.OpSNegate => struct { id_result_type: IdResultType, id_result: IdResult, operand: IdRef },
.OpFNegate => struct { id_result_type: IdResultType, id_result: IdResult, operand: IdRef },
.OpIAdd => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFAdd => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpISub => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFSub => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpIMul => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFMul => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUDiv => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpSDiv => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFDiv => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUMod => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpSRem => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpSMod => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFRem => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFMod => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpVectorTimesScalar => struct { id_result_type: IdResultType, id_result: IdResult, vector: IdRef, scalar: IdRef },
.OpMatrixTimesScalar => struct { id_result_type: IdResultType, id_result: IdResult, matrix: IdRef, scalar: IdRef },
.OpVectorTimesMatrix => struct { id_result_type: IdResultType, id_result: IdResult, vector: IdRef, matrix: IdRef },
.OpMatrixTimesVector => struct { id_result_type: IdResultType, id_result: IdResult, matrix: IdRef, vector: IdRef },
.OpMatrixTimesMatrix => struct { id_result_type: IdResultType, id_result: IdResult, leftmatrix: IdRef, rightmatrix: IdRef },
.OpOuterProduct => struct { id_result_type: IdResultType, id_result: IdResult, vector_1: IdRef, vector_2: IdRef },
.OpDot => struct { id_result_type: IdResultType, id_result: IdResult, vector_1: IdRef, vector_2: IdRef },
.OpIAddCarry => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpISubBorrow => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUMulExtended => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpSMulExtended => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpAny => struct { id_result_type: IdResultType, id_result: IdResult, vector: IdRef },
.OpAll => struct { id_result_type: IdResultType, id_result: IdResult, vector: IdRef },
.OpIsNan => struct { id_result_type: IdResultType, id_result: IdResult, x: IdRef },
.OpIsInf => struct { id_result_type: IdResultType, id_result: IdResult, x: IdRef },
.OpIsFinite => struct { id_result_type: IdResultType, id_result: IdResult, x: IdRef },
.OpIsNormal => struct { id_result_type: IdResultType, id_result: IdResult, x: IdRef },
.OpSignBitSet => struct { id_result_type: IdResultType, id_result: IdResult, x: IdRef },
.OpLessOrGreater => struct { id_result_type: IdResultType, id_result: IdResult, x: IdRef, y: IdRef },
.OpOrdered => struct { id_result_type: IdResultType, id_result: IdResult, x: IdRef, y: IdRef },
.OpUnordered => struct { id_result_type: IdResultType, id_result: IdResult, x: IdRef, y: IdRef },
.OpLogicalEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpLogicalNotEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpLogicalOr => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpLogicalAnd => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpLogicalNot => struct { id_result_type: IdResultType, id_result: IdResult, operand: IdRef },
.OpSelect => struct { id_result_type: IdResultType, id_result: IdResult, condition: IdRef, object_1: IdRef, object_2: IdRef },
.OpIEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpINotEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUGreaterThan => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpSGreaterThan => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUGreaterThanEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpSGreaterThanEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpULessThan => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpSLessThan => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpULessThanEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpSLessThanEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFOrdEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFUnordEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFOrdNotEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFUnordNotEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFOrdLessThan => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFUnordLessThan => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFOrdGreaterThan => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFUnordGreaterThan => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFOrdLessThanEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFUnordLessThanEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFOrdGreaterThanEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpFUnordGreaterThanEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpShiftRightLogical => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, shift: IdRef },
.OpShiftRightArithmetic => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, shift: IdRef },
.OpShiftLeftLogical => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, shift: IdRef },
.OpBitwiseOr => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpBitwiseXor => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpBitwiseAnd => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpNot => struct { id_result_type: IdResultType, id_result: IdResult, operand: IdRef },
.OpBitFieldInsert => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, insert: IdRef, offset: IdRef, count: IdRef },
.OpBitFieldSExtract => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, offset: IdRef, count: IdRef },
.OpBitFieldUExtract => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef, offset: IdRef, count: IdRef },
.OpBitReverse => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef },
.OpBitCount => struct { id_result_type: IdResultType, id_result: IdResult, base: IdRef },
.OpDPdx => struct { id_result_type: IdResultType, id_result: IdResult, p: IdRef },
.OpDPdy => struct { id_result_type: IdResultType, id_result: IdResult, p: IdRef },
.OpFwidth => struct { id_result_type: IdResultType, id_result: IdResult, p: IdRef },
.OpDPdxFine => struct { id_result_type: IdResultType, id_result: IdResult, p: IdRef },
.OpDPdyFine => struct { id_result_type: IdResultType, id_result: IdResult, p: IdRef },
.OpFwidthFine => struct { id_result_type: IdResultType, id_result: IdResult, p: IdRef },
.OpDPdxCoarse => struct { id_result_type: IdResultType, id_result: IdResult, p: IdRef },
.OpDPdyCoarse => struct { id_result_type: IdResultType, id_result: IdResult, p: IdRef },
.OpFwidthCoarse => struct { id_result_type: IdResultType, id_result: IdResult, p: IdRef },
.OpEmitVertex => void,
.OpEndPrimitive => void,
.OpEmitStreamVertex => struct { stream: IdRef },
.OpEndStreamPrimitive => struct { stream: IdRef },
.OpControlBarrier => struct { execution: IdScope, memory: IdScope, semantics: IdMemorySemantics },
.OpMemoryBarrier => struct { memory: IdScope, semantics: IdMemorySemantics },
.OpAtomicLoad => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics },
.OpAtomicStore => struct { pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicExchange => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicCompareExchange => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, equal: IdMemorySemantics, unequal: IdMemorySemantics, value: IdRef, comparator: IdRef },
.OpAtomicCompareExchangeWeak => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, equal: IdMemorySemantics, unequal: IdMemorySemantics, value: IdRef, comparator: IdRef },
.OpAtomicIIncrement => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics },
.OpAtomicIDecrement => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics },
.OpAtomicIAdd => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicISub => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicSMin => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicUMin => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicSMax => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicUMax => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicAnd => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicOr => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicXor => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpPhi => struct { id_result_type: IdResultType, id_result: IdResult, pair_id_ref_id_ref: []const PairIdRefIdRef = &.{} },
.OpLoopMerge => struct { merge_block: IdRef, continue_target: IdRef, loop_control: LoopControl.Extended },
.OpSelectionMerge => struct { merge_block: IdRef, selection_control: SelectionControl },
.OpLabel => struct { id_result: IdResult },
.OpBranch => struct { target_label: IdRef },
.OpBranchConditional => struct { condition: IdRef, true_label: IdRef, false_label: IdRef, branch_weights: []const LiteralInteger = &.{} },
.OpSwitch => struct { selector: IdRef, default: IdRef, target: []const PairLiteralIntegerIdRef = &.{} },
.OpKill => void,
.OpReturn => void,
.OpReturnValue => struct { value: IdRef },
.OpUnreachable => void,
.OpLifetimeStart => struct { pointer: IdRef, size: LiteralInteger },
.OpLifetimeStop => struct { pointer: IdRef, size: LiteralInteger },
.OpGroupAsyncCopy => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, destination: IdRef, source: IdRef, num_elements: IdRef, stride: IdRef, event: IdRef },
.OpGroupWaitEvents => struct { execution: IdScope, num_events: IdRef, events_list: IdRef },
.OpGroupAll => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, predicate: IdRef },
.OpGroupAny => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, predicate: IdRef },
.OpGroupBroadcast => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef, localid: IdRef },
.OpGroupIAdd => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupFAdd => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupFMin => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupUMin => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupSMin => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupFMax => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupUMax => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupSMax => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpReadPipe => struct { id_result_type: IdResultType, id_result: IdResult, pipe: IdRef, pointer: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpWritePipe => struct { id_result_type: IdResultType, id_result: IdResult, pipe: IdRef, pointer: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpReservedReadPipe => struct { id_result_type: IdResultType, id_result: IdResult, pipe: IdRef, reserve_id: IdRef, index: IdRef, pointer: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpReservedWritePipe => struct { id_result_type: IdResultType, id_result: IdResult, pipe: IdRef, reserve_id: IdRef, index: IdRef, pointer: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpReserveReadPipePackets => struct { id_result_type: IdResultType, id_result: IdResult, pipe: IdRef, num_packets: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpReserveWritePipePackets => struct { id_result_type: IdResultType, id_result: IdResult, pipe: IdRef, num_packets: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpCommitReadPipe => struct { pipe: IdRef, reserve_id: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpCommitWritePipe => struct { pipe: IdRef, reserve_id: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpIsValidReserveId => struct { id_result_type: IdResultType, id_result: IdResult, reserve_id: IdRef },
.OpGetNumPipePackets => struct { id_result_type: IdResultType, id_result: IdResult, pipe: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpGetMaxPipePackets => struct { id_result_type: IdResultType, id_result: IdResult, pipe: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpGroupReserveReadPipePackets => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, pipe: IdRef, num_packets: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpGroupReserveWritePipePackets => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, pipe: IdRef, num_packets: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpGroupCommitReadPipe => struct { execution: IdScope, pipe: IdRef, reserve_id: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpGroupCommitWritePipe => struct { execution: IdScope, pipe: IdRef, reserve_id: IdRef, packet_size: IdRef, packet_alignment: IdRef },
.OpEnqueueMarker => struct { id_result_type: IdResultType, id_result: IdResult, queue: IdRef, num_events: IdRef, wait_events: IdRef, ret_event: IdRef },
.OpEnqueueKernel => struct { id_result_type: IdResultType, id_result: IdResult, queue: IdRef, flags: IdRef, nd_range: IdRef, num_events: IdRef, wait_events: IdRef, ret_event: IdRef, invoke: IdRef, param: IdRef, param_size: IdRef, param_align: IdRef, local_size: []const IdRef = &.{} },
.OpGetKernelNDrangeSubGroupCount => struct { id_result_type: IdResultType, id_result: IdResult, nd_range: IdRef, invoke: IdRef, param: IdRef, param_size: IdRef, param_align: IdRef },
.OpGetKernelNDrangeMaxSubGroupSize => struct { id_result_type: IdResultType, id_result: IdResult, nd_range: IdRef, invoke: IdRef, param: IdRef, param_size: IdRef, param_align: IdRef },
.OpGetKernelWorkGroupSize => struct { id_result_type: IdResultType, id_result: IdResult, invoke: IdRef, param: IdRef, param_size: IdRef, param_align: IdRef },
.OpGetKernelPreferredWorkGroupSizeMultiple => struct { id_result_type: IdResultType, id_result: IdResult, invoke: IdRef, param: IdRef, param_size: IdRef, param_align: IdRef },
.OpRetainEvent => struct { event: IdRef },
.OpReleaseEvent => struct { event: IdRef },
.OpCreateUserEvent => struct { id_result_type: IdResultType, id_result: IdResult },
.OpIsValidEvent => struct { id_result_type: IdResultType, id_result: IdResult, event: IdRef },
.OpSetUserEventStatus => struct { event: IdRef, status: IdRef },
.OpCaptureEventProfilingInfo => struct { event: IdRef, profiling_info: IdRef, value: IdRef },
.OpGetDefaultQueue => struct { id_result_type: IdResultType, id_result: IdResult },
.OpBuildNDRange => struct { id_result_type: IdResultType, id_result: IdResult, globalworksize: IdRef, localworksize: IdRef, globalworkoffset: IdRef },
.OpImageSparseSampleImplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSparseSampleExplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, image_operands: ImageOperands.Extended },
.OpImageSparseSampleDrefImplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSparseSampleDrefExplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ImageOperands.Extended },
.OpImageSparseSampleProjImplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSparseSampleProjExplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, image_operands: ImageOperands.Extended },
.OpImageSparseSampleProjDrefImplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSparseSampleProjDrefExplicitLod => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ImageOperands.Extended },
.OpImageSparseFetch => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, coordinate: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSparseGather => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, component: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSparseDrefGather => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, d_ref: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpImageSparseTexelsResident => struct { id_result_type: IdResultType, id_result: IdResult, resident_code: IdRef },
.OpNoLine => void,
.OpAtomicFlagTestAndSet => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics },
.OpAtomicFlagClear => struct { pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics },
.OpImageSparseRead => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, coordinate: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpSizeOf => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef },
.OpTypePipeStorage => struct { id_result: IdResult },
.OpConstantPipeStorage => struct { id_result_type: IdResultType, id_result: IdResult, packet_size: LiteralInteger, packet_alignment: LiteralInteger, capacity: LiteralInteger },
.OpCreatePipeFromPipeStorage => struct { id_result_type: IdResultType, id_result: IdResult, pipe_storage: IdRef },
.OpGetKernelLocalSizeForSubgroupCount => struct { id_result_type: IdResultType, id_result: IdResult, subgroup_count: IdRef, invoke: IdRef, param: IdRef, param_size: IdRef, param_align: IdRef },
.OpGetKernelMaxNumSubgroups => struct { id_result_type: IdResultType, id_result: IdResult, invoke: IdRef, param: IdRef, param_size: IdRef, param_align: IdRef },
.OpTypeNamedBarrier => struct { id_result: IdResult },
.OpNamedBarrierInitialize => struct { id_result_type: IdResultType, id_result: IdResult, subgroup_count: IdRef },
.OpMemoryNamedBarrier => struct { named_barrier: IdRef, memory: IdScope, semantics: IdMemorySemantics },
.OpModuleProcessed => struct { process: LiteralString },
.OpExecutionModeId => struct { entry_point: IdRef, mode: ExecutionMode.Extended },
.OpDecorateId => struct { target: IdRef, decoration: Decoration.Extended },
.OpGroupNonUniformElect => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope },
.OpGroupNonUniformAll => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, predicate: IdRef },
.OpGroupNonUniformAny => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, predicate: IdRef },
.OpGroupNonUniformAllEqual => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef },
.OpGroupNonUniformBroadcast => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef, id: IdRef },
.OpGroupNonUniformBroadcastFirst => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef },
.OpGroupNonUniformBallot => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, predicate: IdRef },
.OpGroupNonUniformInverseBallot => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef },
.OpGroupNonUniformBallotBitExtract => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef, index: IdRef },
.OpGroupNonUniformBallotBitCount => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef },
.OpGroupNonUniformBallotFindLSB => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef },
.OpGroupNonUniformBallotFindMSB => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef },
.OpGroupNonUniformShuffle => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef, id: IdRef },
.OpGroupNonUniformShuffleXor => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef, mask: IdRef },
.OpGroupNonUniformShuffleUp => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef, delta: IdRef },
.OpGroupNonUniformShuffleDown => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef, delta: IdRef },
.OpGroupNonUniformIAdd => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformFAdd => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformIMul => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformFMul => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformSMin => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformUMin => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformFMin => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformSMax => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformUMax => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformFMax => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformBitwiseAnd => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformBitwiseOr => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformBitwiseXor => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformLogicalAnd => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformLogicalOr => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformLogicalXor => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, value: IdRef, clustersize: ?IdRef = null },
.OpGroupNonUniformQuadBroadcast => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef, index: IdRef },
.OpGroupNonUniformQuadSwap => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, value: IdRef, direction: IdRef },
.OpCopyLogical => struct { id_result_type: IdResultType, id_result: IdResult, operand: IdRef },
.OpPtrEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpPtrNotEqual => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpPtrDiff => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpTerminateInvocation => void,
.OpSubgroupBallotKHR => struct { id_result_type: IdResultType, id_result: IdResult, predicate: IdRef },
.OpSubgroupFirstInvocationKHR => struct { id_result_type: IdResultType, id_result: IdResult, value: IdRef },
.OpSubgroupAllKHR => struct { id_result_type: IdResultType, id_result: IdResult, predicate: IdRef },
.OpSubgroupAnyKHR => struct { id_result_type: IdResultType, id_result: IdResult, predicate: IdRef },
.OpSubgroupAllEqualKHR => struct { id_result_type: IdResultType, id_result: IdResult, predicate: IdRef },
.OpSubgroupReadInvocationKHR => struct { id_result_type: IdResultType, id_result: IdResult, value: IdRef, index: IdRef },
.OpTraceRayKHR => struct { accel: IdRef, ray_flags: IdRef, cull_mask: IdRef, sbt_offset: IdRef, sbt_stride: IdRef, miss_index: IdRef, ray_origin: IdRef, ray_tmin: IdRef, ray_direction: IdRef, ray_tmax: IdRef, payload: IdRef },
.OpExecuteCallableKHR => struct { sbt_index: IdRef, callable_data: IdRef },
.OpConvertUToAccelerationStructureKHR => struct { id_result_type: IdResultType, id_result: IdResult, accel: IdRef },
.OpIgnoreIntersectionKHR => void,
.OpTerminateRayKHR => void,
.OpTypeRayQueryKHR => struct { id_result: IdResult },
.OpRayQueryInitializeKHR => struct { rayquery: IdRef, accel: IdRef, rayflags: IdRef, cullmask: IdRef, rayorigin: IdRef, raytmin: IdRef, raydirection: IdRef, raytmax: IdRef },
.OpRayQueryTerminateKHR => struct { rayquery: IdRef },
.OpRayQueryGenerateIntersectionKHR => struct { rayquery: IdRef, hitt: IdRef },
.OpRayQueryConfirmIntersectionKHR => struct { rayquery: IdRef },
.OpRayQueryProceedKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef },
.OpRayQueryGetIntersectionTypeKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpGroupIAddNonUniformAMD => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupFAddNonUniformAMD => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupFMinNonUniformAMD => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupUMinNonUniformAMD => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupSMinNonUniformAMD => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupFMaxNonUniformAMD => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupUMaxNonUniformAMD => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpGroupSMaxNonUniformAMD => struct { id_result_type: IdResultType, id_result: IdResult, execution: IdScope, operation: GroupOperation, x: IdRef },
.OpFragmentMaskFetchAMD => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, coordinate: IdRef },
.OpFragmentFetchAMD => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, coordinate: IdRef, fragment_index: IdRef },
.OpReadClockKHR => struct { id_result_type: IdResultType, id_result: IdResult, scope: IdScope },
.OpImageSampleFootprintNV => struct { id_result_type: IdResultType, id_result: IdResult, sampled_image: IdRef, coordinate: IdRef, granularity: IdRef, coarse: IdRef, image_operands: ?ImageOperands.Extended = null },
.OpGroupNonUniformPartitionNV => struct { id_result_type: IdResultType, id_result: IdResult, value: IdRef },
.OpWritePackedPrimitiveIndices4x8NV => struct { index_offset: IdRef, packed_indices: IdRef },
.OpReportIntersectionKHR => struct { id_result_type: IdResultType, id_result: IdResult, hit: IdRef, hitkind: IdRef },
.OpIgnoreIntersectionNV => void,
.OpTerminateRayNV => void,
.OpTraceNV => struct { accel: IdRef, ray_flags: IdRef, cull_mask: IdRef, sbt_offset: IdRef, sbt_stride: IdRef, miss_index: IdRef, ray_origin: IdRef, ray_tmin: IdRef, ray_direction: IdRef, ray_tmax: IdRef, payloadid: IdRef },
.OpTypeAccelerationStructureKHR => struct { id_result: IdResult },
.OpExecuteCallableNV => struct { sbt_index: IdRef, callable_dataid: IdRef },
.OpTypeCooperativeMatrixNV => struct { id_result: IdResult, component_type: IdRef, execution: IdScope, rows: IdRef, columns: IdRef },
.OpCooperativeMatrixLoadNV => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, stride: IdRef, column_major: IdRef, memory_access: ?MemoryAccess.Extended = null },
.OpCooperativeMatrixStoreNV => struct { pointer: IdRef, object: IdRef, stride: IdRef, column_major: IdRef, memory_access: ?MemoryAccess.Extended = null },
.OpCooperativeMatrixMulAddNV => struct { id_result_type: IdResultType, id_result: IdResult, a: IdRef, b: IdRef, c: IdRef },
.OpCooperativeMatrixLengthNV => struct { id_result_type: IdResultType, id_result: IdResult, type: IdRef },
.OpBeginInvocationInterlockEXT => void,
.OpEndInvocationInterlockEXT => void,
.OpDemoteToHelperInvocationEXT => void,
.OpIsHelperInvocationEXT => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSubgroupShuffleINTEL => struct { id_result_type: IdResultType, id_result: IdResult, data: IdRef, invocationid: IdRef },
.OpSubgroupShuffleDownINTEL => struct { id_result_type: IdResultType, id_result: IdResult, current: IdRef, next: IdRef, delta: IdRef },
.OpSubgroupShuffleUpINTEL => struct { id_result_type: IdResultType, id_result: IdResult, previous: IdRef, current: IdRef, delta: IdRef },
.OpSubgroupShuffleXorINTEL => struct { id_result_type: IdResultType, id_result: IdResult, data: IdRef, value: IdRef },
.OpSubgroupBlockReadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, ptr: IdRef },
.OpSubgroupBlockWriteINTEL => struct { ptr: IdRef, data: IdRef },
.OpSubgroupImageBlockReadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, coordinate: IdRef },
.OpSubgroupImageBlockWriteINTEL => struct { image: IdRef, coordinate: IdRef, data: IdRef },
.OpSubgroupImageMediaBlockReadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, image: IdRef, coordinate: IdRef, width: IdRef, height: IdRef },
.OpSubgroupImageMediaBlockWriteINTEL => struct { image: IdRef, coordinate: IdRef, width: IdRef, height: IdRef, data: IdRef },
.OpUCountLeadingZerosINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand: IdRef },
.OpUCountTrailingZerosINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand: IdRef },
.OpAbsISubINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpAbsUSubINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpIAddSatINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUAddSatINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpIAverageINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUAverageINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpIAverageRoundedINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUAverageRoundedINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpISubSatINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUSubSatINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpIMul32x16INTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpUMul32x16INTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: IdRef, operand_2: IdRef },
.OpConstFunctionPointerINTEL => struct { id_result_type: IdResultType, id_result: IdResult, function: IdRef },
.OpFunctionPointerCallINTEL => struct { id_result_type: IdResultType, id_result: IdResult, operand_1: []const IdRef = &.{} },
.OpAsmTargetINTEL => struct { id_result_type: IdResultType, id_result: IdResult, asm_target: LiteralString },
.OpAsmINTEL => struct { id_result_type: IdResultType, id_result: IdResult, asm_type: IdRef, target: IdRef, asm_instructions: LiteralString, constraints: LiteralString },
.OpAsmCallINTEL => struct { id_result_type: IdResultType, id_result: IdResult, @"asm": IdRef, argument_0: []const IdRef = &.{} },
.OpAtomicFMinEXT => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAtomicFMaxEXT => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpAssumeTrueKHR => struct { condition: IdRef },
.OpExpectKHR => struct { id_result_type: IdResultType, id_result: IdResult, value: IdRef, expectedvalue: IdRef },
.OpDecorateString => struct { target: IdRef, decoration: Decoration.Extended },
.OpMemberDecorateString => struct { struct_type: IdRef, member: LiteralInteger, decoration: Decoration.Extended },
.OpVmeImageINTEL => struct { id_result_type: IdResultType, id_result: IdResult, image_type: IdRef, sampler: IdRef },
.OpTypeVmeImageINTEL => struct { id_result: IdResult, image_type: IdRef },
.OpTypeAvcImePayloadINTEL => struct { id_result: IdResult },
.OpTypeAvcRefPayloadINTEL => struct { id_result: IdResult },
.OpTypeAvcSicPayloadINTEL => struct { id_result: IdResult },
.OpTypeAvcMcePayloadINTEL => struct { id_result: IdResult },
.OpTypeAvcMceResultINTEL => struct { id_result: IdResult },
.OpTypeAvcImeResultINTEL => struct { id_result: IdResult },
.OpTypeAvcImeResultSingleReferenceStreamoutINTEL => struct { id_result: IdResult },
.OpTypeAvcImeResultDualReferenceStreamoutINTEL => struct { id_result: IdResult },
.OpTypeAvcImeSingleReferenceStreaminINTEL => struct { id_result: IdResult },
.OpTypeAvcImeDualReferenceStreaminINTEL => struct { id_result: IdResult },
.OpTypeAvcRefResultINTEL => struct { id_result: IdResult },
.OpTypeAvcSicResultINTEL => struct { id_result: IdResult },
.OpSubgroupAvcMceGetDefaultInterBaseMultiReferencePenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult, slice_type: IdRef, qp: IdRef },
.OpSubgroupAvcMceSetInterBaseMultiReferencePenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult, reference_base_penalty: IdRef, payload: IdRef },
.OpSubgroupAvcMceGetDefaultInterShapePenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult, slice_type: IdRef, qp: IdRef },
.OpSubgroupAvcMceSetInterShapePenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult, packed_shape_penalty: IdRef, payload: IdRef },
.OpSubgroupAvcMceGetDefaultInterDirectionPenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult, slice_type: IdRef, qp: IdRef },
.OpSubgroupAvcMceSetInterDirectionPenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult, direction_cost: IdRef, payload: IdRef },
.OpSubgroupAvcMceGetDefaultIntraLumaShapePenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult, slice_type: IdRef, qp: IdRef },
.OpSubgroupAvcMceGetDefaultInterMotionVectorCostTableINTEL => struct { id_result_type: IdResultType, id_result: IdResult, slice_type: IdRef, qp: IdRef },
.OpSubgroupAvcMceGetDefaultHighPenaltyCostTableINTEL => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSubgroupAvcMceGetDefaultMediumPenaltyCostTableINTEL => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSubgroupAvcMceGetDefaultLowPenaltyCostTableINTEL => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSubgroupAvcMceSetMotionVectorCostFunctionINTEL => struct { id_result_type: IdResultType, id_result: IdResult, packed_cost_center_delta: IdRef, packed_cost_table: IdRef, cost_precision: IdRef, payload: IdRef },
.OpSubgroupAvcMceGetDefaultIntraLumaModePenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult, slice_type: IdRef, qp: IdRef },
.OpSubgroupAvcMceGetDefaultNonDcLumaIntraPenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSubgroupAvcMceGetDefaultIntraChromaModeBasePenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult },
.OpSubgroupAvcMceSetAcOnlyHaarINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceSetSourceInterlacedFieldPolarityINTEL => struct { id_result_type: IdResultType, id_result: IdResult, source_field_polarity: IdRef, payload: IdRef },
.OpSubgroupAvcMceSetSingleReferenceInterlacedFieldPolarityINTEL => struct { id_result_type: IdResultType, id_result: IdResult, reference_field_polarity: IdRef, payload: IdRef },
.OpSubgroupAvcMceSetDualReferenceInterlacedFieldPolaritiesINTEL => struct { id_result_type: IdResultType, id_result: IdResult, forward_reference_field_polarity: IdRef, backward_reference_field_polarity: IdRef, payload: IdRef },
.OpSubgroupAvcMceConvertToImePayloadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceConvertToImeResultINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceConvertToRefPayloadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceConvertToRefResultINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceConvertToSicPayloadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceConvertToSicResultINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceGetMotionVectorsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceGetInterDistortionsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceGetBestInterDistortionsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceGetInterMajorShapeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceGetInterMinorShapeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceGetInterDirectionsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceGetInterMotionVectorCountINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceGetInterReferenceIdsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcMceGetInterReferenceInterlacedFieldPolaritiesINTEL => struct { id_result_type: IdResultType, id_result: IdResult, packed_reference_ids: IdRef, packed_reference_parameter_field_polarities: IdRef, payload: IdRef },
.OpSubgroupAvcImeInitializeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_coord: IdRef, partition_mask: IdRef, sad_adjustment: IdRef },
.OpSubgroupAvcImeSetSingleReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, ref_offset: IdRef, search_window_config: IdRef, payload: IdRef },
.OpSubgroupAvcImeSetDualReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, fwd_ref_offset: IdRef, bwd_ref_offset: IdRef, id_ref_4: IdRef, payload: IdRef },
.OpSubgroupAvcImeRefWindowSizeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, search_window_config: IdRef, dual_ref: IdRef },
.OpSubgroupAvcImeAdjustRefOffsetINTEL => struct { id_result_type: IdResultType, id_result: IdResult, ref_offset: IdRef, src_coord: IdRef, ref_window_size: IdRef, image_size: IdRef },
.OpSubgroupAvcImeConvertToMcePayloadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeSetMaxMotionVectorCountINTEL => struct { id_result_type: IdResultType, id_result: IdResult, max_motion_vector_count: IdRef, payload: IdRef },
.OpSubgroupAvcImeSetUnidirectionalMixDisableINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeSetEarlySearchTerminationThresholdINTEL => struct { id_result_type: IdResultType, id_result: IdResult, threshold: IdRef, payload: IdRef },
.OpSubgroupAvcImeSetWeightedSadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, packed_sad_weights: IdRef, payload: IdRef },
.OpSubgroupAvcImeEvaluateWithSingleReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, ref_image: IdRef, payload: IdRef },
.OpSubgroupAvcImeEvaluateWithDualReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, fwd_ref_image: IdRef, bwd_ref_image: IdRef, payload: IdRef },
.OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, ref_image: IdRef, payload: IdRef, streamin_components: IdRef },
.OpSubgroupAvcImeEvaluateWithDualReferenceStreaminINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, fwd_ref_image: IdRef, bwd_ref_image: IdRef, payload: IdRef, streamin_components: IdRef },
.OpSubgroupAvcImeEvaluateWithSingleReferenceStreamoutINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, ref_image: IdRef, payload: IdRef },
.OpSubgroupAvcImeEvaluateWithDualReferenceStreamoutINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, fwd_ref_image: IdRef, bwd_ref_image: IdRef, payload: IdRef },
.OpSubgroupAvcImeEvaluateWithSingleReferenceStreaminoutINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, ref_image: IdRef, payload: IdRef, streamin_components: IdRef },
.OpSubgroupAvcImeEvaluateWithDualReferenceStreaminoutINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, fwd_ref_image: IdRef, bwd_ref_image: IdRef, payload: IdRef, streamin_components: IdRef },
.OpSubgroupAvcImeConvertToMceResultINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeGetSingleReferenceStreaminINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeGetDualReferenceStreaminINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeStripSingleReferenceStreamoutINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeStripDualReferenceStreamoutINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeMotionVectorsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef, major_shape: IdRef },
.OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeDistortionsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef, major_shape: IdRef },
.OpSubgroupAvcImeGetStreamoutSingleReferenceMajorShapeReferenceIdsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef, major_shape: IdRef },
.OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeMotionVectorsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef, major_shape: IdRef, direction: IdRef },
.OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeDistortionsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef, major_shape: IdRef, direction: IdRef },
.OpSubgroupAvcImeGetStreamoutDualReferenceMajorShapeReferenceIdsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef, major_shape: IdRef, direction: IdRef },
.OpSubgroupAvcImeGetBorderReachedINTEL => struct { id_result_type: IdResultType, id_result: IdResult, image_select: IdRef, payload: IdRef },
.OpSubgroupAvcImeGetTruncatedSearchIndicationINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeGetUnidirectionalEarlySearchTerminationINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeGetWeightingPatternMinimumMotionVectorINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcImeGetWeightingPatternMinimumDistortionINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcFmeInitializeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_coord: IdRef, motion_vectors: IdRef, major_shapes: IdRef, minor_shapes: IdRef, direction: IdRef, pixel_resolution: IdRef, sad_adjustment: IdRef },
.OpSubgroupAvcBmeInitializeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_coord: IdRef, motion_vectors: IdRef, major_shapes: IdRef, minor_shapes: IdRef, direction: IdRef, pixel_resolution: IdRef, bidirectional_weight: IdRef, sad_adjustment: IdRef },
.OpSubgroupAvcRefConvertToMcePayloadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcRefSetBidirectionalMixDisableINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcRefSetBilinearFilterEnableINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcRefEvaluateWithSingleReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, ref_image: IdRef, payload: IdRef },
.OpSubgroupAvcRefEvaluateWithDualReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, fwd_ref_image: IdRef, bwd_ref_image: IdRef, payload: IdRef },
.OpSubgroupAvcRefEvaluateWithMultiReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, packed_reference_ids: IdRef, payload: IdRef },
.OpSubgroupAvcRefEvaluateWithMultiReferenceInterlacedINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, packed_reference_ids: IdRef, packed_reference_field_polarities: IdRef, payload: IdRef },
.OpSubgroupAvcRefConvertToMceResultINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicInitializeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_coord: IdRef },
.OpSubgroupAvcSicConfigureSkcINTEL => struct { id_result_type: IdResultType, id_result: IdResult, skip_block_partition_type: IdRef, skip_motion_vector_mask: IdRef, motion_vectors: IdRef, bidirectional_weight: IdRef, sad_adjustment: IdRef, payload: IdRef },
.OpSubgroupAvcSicConfigureIpeLumaINTEL => struct { id_result_type: IdResultType, id_result: IdResult, luma_intra_partition_mask: IdRef, intra_neighbour_availabilty: IdRef, left_edge_luma_pixels: IdRef, upper_left_corner_luma_pixel: IdRef, upper_edge_luma_pixels: IdRef, upper_right_edge_luma_pixels: IdRef, sad_adjustment: IdRef, payload: IdRef },
.OpSubgroupAvcSicConfigureIpeLumaChromaINTEL => struct { id_result_type: IdResultType, id_result: IdResult, luma_intra_partition_mask: IdRef, intra_neighbour_availabilty: IdRef, left_edge_luma_pixels: IdRef, upper_left_corner_luma_pixel: IdRef, upper_edge_luma_pixels: IdRef, upper_right_edge_luma_pixels: IdRef, left_edge_chroma_pixels: IdRef, upper_left_corner_chroma_pixel: IdRef, upper_edge_chroma_pixels: IdRef, sad_adjustment: IdRef, payload: IdRef },
.OpSubgroupAvcSicGetMotionVectorMaskINTEL => struct { id_result_type: IdResultType, id_result: IdResult, skip_block_partition_type: IdRef, direction: IdRef },
.OpSubgroupAvcSicConvertToMcePayloadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicSetIntraLumaShapePenaltyINTEL => struct { id_result_type: IdResultType, id_result: IdResult, packed_shape_penalty: IdRef, payload: IdRef },
.OpSubgroupAvcSicSetIntraLumaModeCostFunctionINTEL => struct { id_result_type: IdResultType, id_result: IdResult, luma_mode_penalty: IdRef, luma_packed_neighbor_modes: IdRef, luma_packed_non_dc_penalty: IdRef, payload: IdRef },
.OpSubgroupAvcSicSetIntraChromaModeCostFunctionINTEL => struct { id_result_type: IdResultType, id_result: IdResult, chroma_mode_base_penalty: IdRef, payload: IdRef },
.OpSubgroupAvcSicSetBilinearFilterEnableINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicSetSkcForwardTransformEnableINTEL => struct { id_result_type: IdResultType, id_result: IdResult, packed_sad_coefficients: IdRef, payload: IdRef },
.OpSubgroupAvcSicSetBlockBasedRawSkipSadINTEL => struct { id_result_type: IdResultType, id_result: IdResult, block_based_skip_type: IdRef, payload: IdRef },
.OpSubgroupAvcSicEvaluateIpeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, payload: IdRef },
.OpSubgroupAvcSicEvaluateWithSingleReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, ref_image: IdRef, payload: IdRef },
.OpSubgroupAvcSicEvaluateWithDualReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, fwd_ref_image: IdRef, bwd_ref_image: IdRef, payload: IdRef },
.OpSubgroupAvcSicEvaluateWithMultiReferenceINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, packed_reference_ids: IdRef, payload: IdRef },
.OpSubgroupAvcSicEvaluateWithMultiReferenceInterlacedINTEL => struct { id_result_type: IdResultType, id_result: IdResult, src_image: IdRef, packed_reference_ids: IdRef, packed_reference_field_polarities: IdRef, payload: IdRef },
.OpSubgroupAvcSicConvertToMceResultINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicGetIpeLumaShapeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicGetBestIpeLumaDistortionINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicGetBestIpeChromaDistortionINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicGetPackedIpeLumaModesINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicGetIpeChromaModeINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicGetPackedSkcLumaCountThresholdINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicGetPackedSkcLumaSumThresholdINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpSubgroupAvcSicGetInterRawSadsINTEL => struct { id_result_type: IdResultType, id_result: IdResult, payload: IdRef },
.OpVariableLengthArrayINTEL => struct { id_result_type: IdResultType, id_result: IdResult, lenght: IdRef },
.OpSaveMemoryINTEL => struct { id_result_type: IdResultType, id_result: IdResult },
.OpRestoreMemoryINTEL => struct { ptr: IdRef },
.OpLoopControlINTEL => struct { loop_control_parameters: []const LiteralInteger = &.{} },
.OpPtrCastToCrossWorkgroupINTEL => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef },
.OpCrossWorkgroupCastToPtrINTEL => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef },
.OpReadPipeBlockingINTEL => struct { id_result_type: IdResultType, id_result: IdResult, packet_size: IdRef, packet_alignment: IdRef },
.OpWritePipeBlockingINTEL => struct { id_result_type: IdResultType, id_result: IdResult, packet_size: IdRef, packet_alignment: IdRef },
.OpFPGARegINTEL => struct { id_result_type: IdResultType, id_result: IdResult, result: IdRef, input: IdRef },
.OpRayQueryGetRayTMinKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef },
.OpRayQueryGetRayFlagsKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef },
.OpRayQueryGetIntersectionTKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionInstanceCustomIndexKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionInstanceIdKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionGeometryIndexKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionPrimitiveIndexKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionBarycentricsKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionFrontFaceKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionCandidateAABBOpaqueKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef },
.OpRayQueryGetIntersectionObjectRayDirectionKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionObjectRayOriginKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetWorldRayDirectionKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef },
.OpRayQueryGetWorldRayOriginKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef },
.OpRayQueryGetIntersectionObjectToWorldKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpRayQueryGetIntersectionWorldToObjectKHR => struct { id_result_type: IdResultType, id_result: IdResult, rayquery: IdRef, intersection: IdRef },
.OpAtomicFAddEXT => struct { id_result_type: IdResultType, id_result: IdResult, pointer: IdRef, memory: IdScope, semantics: IdMemorySemantics, value: IdRef },
.OpTypeBufferSurfaceINTEL => struct { id_result: IdResult },
.OpTypeStructContinuedINTEL => struct { id_ref: []const IdRef = &.{} },
.OpConstantCompositeContinuedINTEL => struct { constituents: []const IdRef = &.{} },
.OpSpecConstantCompositeContinuedINTEL => struct { constituents: []const IdRef = &.{} },
};
}
};
pub const ImageOperands = packed struct {
Bias: bool align(@alignOf(u32)) = false,
Lod: bool = false,
Grad: bool = false,
ConstOffset: bool = false,
Offset: bool = false,
ConstOffsets: bool = false,
Sample: bool = false,
MinLod: bool = false,
MakeTexelAvailable: bool = false,
MakeTexelVisible: bool = false,
NonPrivateTexel: bool = false,
VolatileTexel: bool = false,
SignExtend: bool = false,
ZeroExtend: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
pub const MakeTexelAvailableKHR: ImageOperands = .{ .MakeTexelAvailable = true };
pub const MakeTexelVisibleKHR: ImageOperands = .{ .MakeTexelVisible = true };
pub const NonPrivateTexelKHR: ImageOperands = .{ .NonPrivateTexel = true };
pub const VolatileTexelKHR: ImageOperands = .{ .VolatileTexel = true };
pub const Extended = struct {
Bias: ?struct { id_ref: IdRef } = null,
Lod: ?struct { id_ref: IdRef } = null,
Grad: ?struct { id_ref_0: IdRef, id_ref_1: IdRef } = null,
ConstOffset: ?struct { id_ref: IdRef } = null,
Offset: ?struct { id_ref: IdRef } = null,
ConstOffsets: ?struct { id_ref: IdRef } = null,
Sample: ?struct { id_ref: IdRef } = null,
MinLod: ?struct { id_ref: IdRef } = null,
MakeTexelAvailable: ?struct { id_scope: IdScope } = null,
MakeTexelVisible: ?struct { id_scope: IdScope } = null,
NonPrivateTexel: bool = false,
VolatileTexel: bool = false,
SignExtend: bool = false,
ZeroExtend: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
};
};
pub const FPFastMathMode = packed struct {
NotNaN: bool align(@alignOf(u32)) = false,
NotInf: bool = false,
NSZ: bool = false,
AllowRecip: bool = false,
Fast: bool = false,
_reserved_bit_5: bool = false,
_reserved_bit_6: bool = false,
_reserved_bit_7: bool = false,
_reserved_bit_8: bool = false,
_reserved_bit_9: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
AllowContractFastINTEL: bool = false,
AllowReassocINTEL: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
};
pub const SelectionControl = packed struct {
Flatten: bool align(@alignOf(u32)) = false,
DontFlatten: bool = false,
_reserved_bit_2: bool = false,
_reserved_bit_3: bool = false,
_reserved_bit_4: bool = false,
_reserved_bit_5: bool = false,
_reserved_bit_6: bool = false,
_reserved_bit_7: bool = false,
_reserved_bit_8: bool = false,
_reserved_bit_9: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
};
pub const LoopControl = packed struct {
Unroll: bool align(@alignOf(u32)) = false,
DontUnroll: bool = false,
DependencyInfinite: bool = false,
DependencyLength: bool = false,
MinIterations: bool = false,
MaxIterations: bool = false,
IterationMultiple: bool = false,
PeelCount: bool = false,
PartialCount: bool = false,
_reserved_bit_9: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
InitiationIntervalINTEL: bool = false,
MaxConcurrencyINTEL: bool = false,
DependencyArrayINTEL: bool = false,
PipelineEnableINTEL: bool = false,
LoopCoalesceINTEL: bool = false,
MaxInterleavingINTEL: bool = false,
SpeculatedIterationsINTEL: bool = false,
NoFusionINTEL: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
pub const Extended = struct {
Unroll: bool = false,
DontUnroll: bool = false,
DependencyInfinite: bool = false,
DependencyLength: ?struct { literal_integer: LiteralInteger } = null,
MinIterations: ?struct { literal_integer: LiteralInteger } = null,
MaxIterations: ?struct { literal_integer: LiteralInteger } = null,
IterationMultiple: ?struct { literal_integer: LiteralInteger } = null,
PeelCount: ?struct { literal_integer: LiteralInteger } = null,
PartialCount: ?struct { literal_integer: LiteralInteger } = null,
_reserved_bit_9: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
InitiationIntervalINTEL: ?struct { literal_integer: LiteralInteger } = null,
MaxConcurrencyINTEL: ?struct { literal_integer: LiteralInteger } = null,
DependencyArrayINTEL: ?struct { literal_integer: LiteralInteger } = null,
PipelineEnableINTEL: ?struct { literal_integer: LiteralInteger } = null,
LoopCoalesceINTEL: ?struct { literal_integer: LiteralInteger } = null,
MaxInterleavingINTEL: ?struct { literal_integer: LiteralInteger } = null,
SpeculatedIterationsINTEL: ?struct { literal_integer: LiteralInteger } = null,
NoFusionINTEL: ?struct { literal_integer: LiteralInteger } = null,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
};
};
pub const FunctionControl = packed struct {
Inline: bool align(@alignOf(u32)) = false,
DontInline: bool = false,
Pure: bool = false,
Const: bool = false,
_reserved_bit_4: bool = false,
_reserved_bit_5: bool = false,
_reserved_bit_6: bool = false,
_reserved_bit_7: bool = false,
_reserved_bit_8: bool = false,
_reserved_bit_9: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
};
pub const MemorySemantics = packed struct {
_reserved_bit_0: bool align(@alignOf(u32)) = false,
Acquire: bool = false,
Release: bool = false,
AcquireRelease: bool = false,
SequentiallyConsistent: bool = false,
_reserved_bit_5: bool = false,
UniformMemory: bool = false,
SubgroupMemory: bool = false,
WorkgroupMemory: bool = false,
CrossWorkgroupMemory: bool = false,
AtomicCounterMemory: bool = false,
ImageMemory: bool = false,
OutputMemory: bool = false,
MakeAvailable: bool = false,
MakeVisible: bool = false,
Volatile: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
pub const OutputMemoryKHR: MemorySemantics = .{ .OutputMemory = true };
pub const MakeAvailableKHR: MemorySemantics = .{ .MakeAvailable = true };
pub const MakeVisibleKHR: MemorySemantics = .{ .MakeVisible = true };
};
pub const MemoryAccess = packed struct {
Volatile: bool align(@alignOf(u32)) = false,
Aligned: bool = false,
Nontemporal: bool = false,
MakePointerAvailable: bool = false,
MakePointerVisible: bool = false,
NonPrivatePointer: bool = false,
_reserved_bit_6: bool = false,
_reserved_bit_7: bool = false,
_reserved_bit_8: bool = false,
_reserved_bit_9: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
pub const MakePointerAvailableKHR: MemoryAccess = .{ .MakePointerAvailable = true };
pub const MakePointerVisibleKHR: MemoryAccess = .{ .MakePointerVisible = true };
pub const NonPrivatePointerKHR: MemoryAccess = .{ .NonPrivatePointer = true };
pub const Extended = struct {
Volatile: bool = false,
Aligned: ?struct { literal_integer: LiteralInteger } = null,
Nontemporal: bool = false,
MakePointerAvailable: ?struct { id_scope: IdScope } = null,
MakePointerVisible: ?struct { id_scope: IdScope } = null,
NonPrivatePointer: bool = false,
_reserved_bit_6: bool = false,
_reserved_bit_7: bool = false,
_reserved_bit_8: bool = false,
_reserved_bit_9: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
};
};
pub const KernelProfilingInfo = packed struct {
CmdExecTime: bool align(@alignOf(u32)) = false,
_reserved_bit_1: bool = false,
_reserved_bit_2: bool = false,
_reserved_bit_3: bool = false,
_reserved_bit_4: bool = false,
_reserved_bit_5: bool = false,
_reserved_bit_6: bool = false,
_reserved_bit_7: bool = false,
_reserved_bit_8: bool = false,
_reserved_bit_9: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
};
pub const RayFlags = packed struct {
OpaqueKHR: bool align(@alignOf(u32)) = false,
NoOpaqueKHR: bool = false,
TerminateOnFirstHitKHR: bool = false,
SkipClosestHitShaderKHR: bool = false,
CullBackFacingTrianglesKHR: bool = false,
CullFrontFacingTrianglesKHR: bool = false,
CullOpaqueKHR: bool = false,
CullNoOpaqueKHR: bool = false,
SkipTrianglesKHR: bool = false,
SkipAABBsKHR: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
};
pub const FragmentShadingRate = packed struct {
Vertical2Pixels: bool align(@alignOf(u32)) = false,
Vertical4Pixels: bool = false,
Horizontal2Pixels: bool = false,
Horizontal4Pixels: bool = false,
_reserved_bit_4: bool = false,
_reserved_bit_5: bool = false,
_reserved_bit_6: bool = false,
_reserved_bit_7: bool = false,
_reserved_bit_8: bool = false,
_reserved_bit_9: bool = false,
_reserved_bit_10: bool = false,
_reserved_bit_11: bool = false,
_reserved_bit_12: bool = false,
_reserved_bit_13: bool = false,
_reserved_bit_14: bool = false,
_reserved_bit_15: bool = false,
_reserved_bit_16: bool = false,
_reserved_bit_17: bool = false,
_reserved_bit_18: bool = false,
_reserved_bit_19: bool = false,
_reserved_bit_20: bool = false,
_reserved_bit_21: bool = false,
_reserved_bit_22: bool = false,
_reserved_bit_23: bool = false,
_reserved_bit_24: bool = false,
_reserved_bit_25: bool = false,
_reserved_bit_26: bool = false,
_reserved_bit_27: bool = false,
_reserved_bit_28: bool = false,
_reserved_bit_29: bool = false,
_reserved_bit_30: bool = false,
_reserved_bit_31: bool = false,
};
pub const SourceLanguage = enum(u32) {
Unknown = 0,
ESSL = 1,
GLSL = 2,
OpenCL_C = 3,
OpenCL_CPP = 4,
HLSL = 5,
};
pub const ExecutionModel = enum(u32) {
Vertex = 0,
TessellationControl = 1,
TessellationEvaluation = 2,
Geometry = 3,
Fragment = 4,
GLCompute = 5,
Kernel = 6,
TaskNV = 5267,
MeshNV = 5268,
RayGenerationKHR = 5313,
IntersectionKHR = 5314,
AnyHitKHR = 5315,
ClosestHitKHR = 5316,
MissKHR = 5317,
CallableKHR = 5318,
pub const RayGenerationNV = ExecutionModel.RayGenerationKHR;
pub const IntersectionNV = ExecutionModel.IntersectionKHR;
pub const AnyHitNV = ExecutionModel.AnyHitKHR;
pub const ClosestHitNV = ExecutionModel.ClosestHitKHR;
pub const MissNV = ExecutionModel.MissKHR;
pub const CallableNV = ExecutionModel.CallableKHR;
};
pub const AddressingModel = enum(u32) {
Logical = 0,
Physical32 = 1,
Physical64 = 2,
PhysicalStorageBuffer64 = 5348,
pub const PhysicalStorageBuffer64EXT = AddressingModel.PhysicalStorageBuffer64;
};
pub const MemoryModel = enum(u32) {
Simple = 0,
GLSL450 = 1,
OpenCL = 2,
Vulkan = 3,
pub const VulkanKHR = MemoryModel.Vulkan;
};
pub const ExecutionMode = enum(u32) {
Invocations = 0,
SpacingEqual = 1,
SpacingFractionalEven = 2,
SpacingFractionalOdd = 3,
VertexOrderCw = 4,
VertexOrderCcw = 5,
PixelCenterInteger = 6,
OriginUpperLeft = 7,
OriginLowerLeft = 8,
EarlyFragmentTests = 9,
PointMode = 10,
Xfb = 11,
DepthReplacing = 12,
DepthGreater = 14,
DepthLess = 15,
DepthUnchanged = 16,
LocalSize = 17,
LocalSizeHint = 18,
InputPoints = 19,
InputLines = 20,
InputLinesAdjacency = 21,
Triangles = 22,
InputTrianglesAdjacency = 23,
Quads = 24,
Isolines = 25,
OutputVertices = 26,
OutputPoints = 27,
OutputLineStrip = 28,
OutputTriangleStrip = 29,
VecTypeHint = 30,
ContractionOff = 31,
Initializer = 33,
Finalizer = 34,
SubgroupSize = 35,
SubgroupsPerWorkgroup = 36,
SubgroupsPerWorkgroupId = 37,
LocalSizeId = 38,
LocalSizeHintId = 39,
PostDepthCoverage = 4446,
DenormPreserve = 4459,
DenormFlushToZero = 4460,
SignedZeroInfNanPreserve = 4461,
RoundingModeRTE = 4462,
RoundingModeRTZ = 4463,
StencilRefReplacingEXT = 5027,
OutputLinesNV = 5269,
OutputPrimitivesNV = 5270,
DerivativeGroupQuadsNV = 5289,
DerivativeGroupLinearNV = 5290,
OutputTrianglesNV = 5298,
PixelInterlockOrderedEXT = 5366,
PixelInterlockUnorderedEXT = 5367,
SampleInterlockOrderedEXT = 5368,
SampleInterlockUnorderedEXT = 5369,
ShadingRateInterlockOrderedEXT = 5370,
ShadingRateInterlockUnorderedEXT = 5371,
SharedLocalMemorySizeINTEL = 5618,
RoundingModeRTPINTEL = 5620,
RoundingModeRTNINTEL = 5621,
FloatingPointModeALTINTEL = 5622,
FloatingPointModeIEEEINTEL = 5623,
MaxWorkgroupSizeINTEL = 5893,
MaxWorkDimINTEL = 5894,
NoGlobalOffsetINTEL = 5895,
NumSIMDWorkitemsINTEL = 5896,
SchedulerTargetFmaxMhzINTEL = 5903,
pub const Extended = union(ExecutionMode) {
Invocations: struct { literal_integer: LiteralInteger },
SpacingEqual,
SpacingFractionalEven,
SpacingFractionalOdd,
VertexOrderCw,
VertexOrderCcw,
PixelCenterInteger,
OriginUpperLeft,
OriginLowerLeft,
EarlyFragmentTests,
PointMode,
Xfb,
DepthReplacing,
DepthGreater,
DepthLess,
DepthUnchanged,
LocalSize: struct { x_size: LiteralInteger, y_size: LiteralInteger, z_size: LiteralInteger },
LocalSizeHint: struct { x_size: LiteralInteger, y_size: LiteralInteger, z_size: LiteralInteger },
InputPoints,
InputLines,
InputLinesAdjacency,
Triangles,
InputTrianglesAdjacency,
Quads,
Isolines,
OutputVertices: struct { vertex_count: LiteralInteger },
OutputPoints,
OutputLineStrip,
OutputTriangleStrip,
VecTypeHint: struct { vector_type: LiteralInteger },
ContractionOff,
Initializer,
Finalizer,
SubgroupSize: struct { subgroup_size: LiteralInteger },
SubgroupsPerWorkgroup: struct { subgroups_per_workgroup: LiteralInteger },
SubgroupsPerWorkgroupId: struct { subgroups_per_workgroup: IdRef },
LocalSizeId: struct { x_size: IdRef, y_size: IdRef, z_size: IdRef },
LocalSizeHintId: struct { local_size_hint: IdRef },
PostDepthCoverage,
DenormPreserve: struct { target_width: LiteralInteger },
DenormFlushToZero: struct { target_width: LiteralInteger },
SignedZeroInfNanPreserve: struct { target_width: LiteralInteger },
RoundingModeRTE: struct { target_width: LiteralInteger },
RoundingModeRTZ: struct { target_width: LiteralInteger },
StencilRefReplacingEXT,
OutputLinesNV,
OutputPrimitivesNV: struct { primitive_count: LiteralInteger },
DerivativeGroupQuadsNV,
DerivativeGroupLinearNV,
OutputTrianglesNV,
PixelInterlockOrderedEXT,
PixelInterlockUnorderedEXT,
SampleInterlockOrderedEXT,
SampleInterlockUnorderedEXT,
ShadingRateInterlockOrderedEXT,
ShadingRateInterlockUnorderedEXT,
SharedLocalMemorySizeINTEL: struct { size: LiteralInteger },
RoundingModeRTPINTEL: struct { target_width: LiteralInteger },
RoundingModeRTNINTEL: struct { target_width: LiteralInteger },
FloatingPointModeALTINTEL: struct { target_width: LiteralInteger },
FloatingPointModeIEEEINTEL: struct { target_width: LiteralInteger },
MaxWorkgroupSizeINTEL: struct { literal_integer_0: LiteralInteger, literal_integer_1: LiteralInteger, literal_integer_2: LiteralInteger },
MaxWorkDimINTEL: struct { literal_integer: LiteralInteger },
NoGlobalOffsetINTEL,
NumSIMDWorkitemsINTEL: struct { literal_integer: LiteralInteger },
SchedulerTargetFmaxMhzINTEL: struct { literal_integer: LiteralInteger },
};
};
pub const StorageClass = enum(u32) {
UniformConstant = 0,
Input = 1,
Uniform = 2,
Output = 3,
Workgroup = 4,
CrossWorkgroup = 5,
Private = 6,
Function = 7,
Generic = 8,
PushConstant = 9,
AtomicCounter = 10,
Image = 11,
StorageBuffer = 12,
CallableDataKHR = 5328,
IncomingCallableDataKHR = 5329,
RayPayloadKHR = 5338,
HitAttributeKHR = 5339,
IncomingRayPayloadKHR = 5342,
ShaderRecordBufferKHR = 5343,
PhysicalStorageBuffer = 5349,
CodeSectionINTEL = 5605,
DeviceOnlyINTEL = 5936,
HostOnlyINTEL = 5937,
pub const CallableDataNV = StorageClass.CallableDataKHR;
pub const IncomingCallableDataNV = StorageClass.IncomingCallableDataKHR;
pub const RayPayloadNV = StorageClass.RayPayloadKHR;
pub const HitAttributeNV = StorageClass.HitAttributeKHR;
pub const IncomingRayPayloadNV = StorageClass.IncomingRayPayloadKHR;
pub const ShaderRecordBufferNV = StorageClass.ShaderRecordBufferKHR;
pub const PhysicalStorageBufferEXT = StorageClass.PhysicalStorageBuffer;
};
pub const Dim = enum(u32) {
@"1D" = 0,
@"2D" = 1,
@"3D" = 2,
Cube = 3,
Rect = 4,
Buffer = 5,
SubpassData = 6,
};
pub const SamplerAddressingMode = enum(u32) {
None = 0,
ClampToEdge = 1,
Clamp = 2,
Repeat = 3,
RepeatMirrored = 4,
};
pub const SamplerFilterMode = enum(u32) {
Nearest = 0,
Linear = 1,
};
pub const ImageFormat = enum(u32) {
Unknown = 0,
Rgba32f = 1,
Rgba16f = 2,
R32f = 3,
Rgba8 = 4,
Rgba8Snorm = 5,
Rg32f = 6,
Rg16f = 7,
R11fG11fB10f = 8,
R16f = 9,
Rgba16 = 10,
Rgb10A2 = 11,
Rg16 = 12,
Rg8 = 13,
R16 = 14,
R8 = 15,
Rgba16Snorm = 16,
Rg16Snorm = 17,
Rg8Snorm = 18,
R16Snorm = 19,
R8Snorm = 20,
Rgba32i = 21,
Rgba16i = 22,
Rgba8i = 23,
R32i = 24,
Rg32i = 25,
Rg16i = 26,
Rg8i = 27,
R16i = 28,
R8i = 29,
Rgba32ui = 30,
Rgba16ui = 31,
Rgba8ui = 32,
R32ui = 33,
Rgb10a2ui = 34,
Rg32ui = 35,
Rg16ui = 36,
Rg8ui = 37,
R16ui = 38,
R8ui = 39,
R64ui = 40,
R64i = 41,
};
pub const ImageChannelOrder = enum(u32) {
R = 0,
A = 1,
RG = 2,
RA = 3,
RGB = 4,
RGBA = 5,
BGRA = 6,
ARGB = 7,
Intensity = 8,
Luminance = 9,
Rx = 10,
RGx = 11,
RGBx = 12,
Depth = 13,
DepthStencil = 14,
sRGB = 15,
sRGBx = 16,
sRGBA = 17,
sBGRA = 18,
ABGR = 19,
};
pub const ImageChannelDataType = enum(u32) {
SnormInt8 = 0,
SnormInt16 = 1,
UnormInt8 = 2,
UnormInt16 = 3,
UnormShort565 = 4,
UnormShort555 = 5,
UnormInt101010 = 6,
SignedInt8 = 7,
SignedInt16 = 8,
SignedInt32 = 9,
UnsignedInt8 = 10,
UnsignedInt16 = 11,
UnsignedInt32 = 12,
HalfFloat = 13,
Float = 14,
UnormInt24 = 15,
UnormInt101010_2 = 16,
};
pub const FPRoundingMode = enum(u32) {
RTE = 0,
RTZ = 1,
RTP = 2,
RTN = 3,
};
pub const FPDenormMode = enum(u32) {
Preserve = 0,
FlushToZero = 1,
};
pub const FPOperationMode = enum(u32) {
IEEE = 0,
ALT = 1,
};
pub const LinkageType = enum(u32) {
Export = 0,
Import = 1,
LinkOnceODR = 2,
};
pub const AccessQualifier = enum(u32) {
ReadOnly = 0,
WriteOnly = 1,
ReadWrite = 2,
};
pub const FunctionParameterAttribute = enum(u32) {
Zext = 0,
Sext = 1,
ByVal = 2,
Sret = 3,
NoAlias = 4,
NoCapture = 5,
NoWrite = 6,
NoReadWrite = 7,
};
pub const Decoration = enum(u32) {
RelaxedPrecision = 0,
SpecId = 1,
Block = 2,
BufferBlock = 3,
RowMajor = 4,
ColMajor = 5,
ArrayStride = 6,
MatrixStride = 7,
GLSLShared = 8,
GLSLPacked = 9,
CPacked = 10,
BuiltIn = 11,
NoPerspective = 13,
Flat = 14,
Patch = 15,
Centroid = 16,
Sample = 17,
Invariant = 18,
Restrict = 19,
Aliased = 20,
Volatile = 21,
Constant = 22,
Coherent = 23,
NonWritable = 24,
NonReadable = 25,
Uniform = 26,
UniformId = 27,
SaturatedConversion = 28,
Stream = 29,
Location = 30,
Component = 31,
Index = 32,
Binding = 33,
DescriptorSet = 34,
Offset = 35,
XfbBuffer = 36,
XfbStride = 37,
FuncParamAttr = 38,
FPRoundingMode = 39,
FPFastMathMode = 40,
LinkageAttributes = 41,
NoContraction = 42,
InputAttachmentIndex = 43,
Alignment = 44,
MaxByteOffset = 45,
AlignmentId = 46,
MaxByteOffsetId = 47,
NoSignedWrap = 4469,
NoUnsignedWrap = 4470,
ExplicitInterpAMD = 4999,
OverrideCoverageNV = 5248,
PassthroughNV = 5250,
ViewportRelativeNV = 5252,
SecondaryViewportRelativeNV = 5256,
PerPrimitiveNV = 5271,
PerViewNV = 5272,
PerTaskNV = 5273,
PerVertexNV = 5285,
NonUniform = 5300,
RestrictPointer = 5355,
AliasedPointer = 5356,
SIMTCallINTEL = 5599,
ReferencedIndirectlyINTEL = 5602,
ClobberINTEL = 5607,
SideEffectsINTEL = 5608,
VectorComputeVariableINTEL = 5624,
FuncParamIOKindINTEL = 5625,
VectorComputeFunctionINTEL = 5626,
StackCallINTEL = 5627,
GlobalVariableOffsetINTEL = 5628,
CounterBuffer = 5634,
UserSemantic = 5635,
UserTypeGOOGLE = 5636,
FunctionRoundingModeINTEL = 5822,
FunctionDenormModeINTEL = 5823,
RegisterINTEL = 5825,
MemoryINTEL = 5826,
NumbanksINTEL = 5827,
BankwidthINTEL = 5828,
MaxPrivateCopiesINTEL = 5829,
SinglepumpINTEL = 5830,
DoublepumpINTEL = 5831,
MaxReplicatesINTEL = 5832,
SimpleDualPortINTEL = 5833,
MergeINTEL = 5834,
BankBitsINTEL = 5835,
ForcePow2DepthINTEL = 5836,
BurstCoalesceINTEL = 5899,
CacheSizeINTEL = 5900,
DontStaticallyCoalesceINTEL = 5901,
PrefetchINTEL = 5902,
StallEnableINTEL = 5905,
FuseLoopsInFunctionINTEL = 5907,
BufferLocationINTEL = 5921,
IOPipeStorageINTEL = 5944,
FunctionFloatingPointModeINTEL = 6080,
SingleElementVectorINTEL = 6085,
VectorComputeCallableFunctionINTEL = 6087,
pub const NonUniformEXT = Decoration.NonUniform;
pub const RestrictPointerEXT = Decoration.RestrictPointer;
pub const AliasedPointerEXT = Decoration.AliasedPointer;
pub const HlslCounterBufferGOOGLE = Decoration.CounterBuffer;
pub const HlslSemanticGOOGLE = Decoration.UserSemantic;
pub const Extended = union(Decoration) {
RelaxedPrecision,
SpecId: struct { specialization_constant_id: LiteralInteger },
Block,
BufferBlock,
RowMajor,
ColMajor,
ArrayStride: struct { array_stride: LiteralInteger },
MatrixStride: struct { matrix_stride: LiteralInteger },
GLSLShared,
GLSLPacked,
CPacked,
BuiltIn: struct { built_in: BuiltIn },
NoPerspective,
Flat,
Patch,
Centroid,
Sample,
Invariant,
Restrict,
Aliased,
Volatile,
Constant,
Coherent,
NonWritable,
NonReadable,
Uniform,
UniformId: struct { execution: IdScope },
SaturatedConversion,
Stream: struct { stream_number: LiteralInteger },
Location: struct { location: LiteralInteger },
Component: struct { component: LiteralInteger },
Index: struct { index: LiteralInteger },
Binding: struct { binding_point: LiteralInteger },
DescriptorSet: struct { descriptor_set: LiteralInteger },
Offset: struct { byte_offset: LiteralInteger },
XfbBuffer: struct { xfb_buffer_number: LiteralInteger },
XfbStride: struct { xfb_stride: LiteralInteger },
FuncParamAttr: struct { function_parameter_attribute: FunctionParameterAttribute },
FPRoundingMode: struct { fprounding_mode: FPRoundingMode },
FPFastMathMode: struct { fpfast_math_mode: FPFastMathMode },
LinkageAttributes: struct { name: LiteralString, linkage_type: LinkageType },
NoContraction,
InputAttachmentIndex: struct { attachment_index: LiteralInteger },
Alignment: struct { alignment: LiteralInteger },
MaxByteOffset: struct { max_byte_offset: LiteralInteger },
AlignmentId: struct { alignment: IdRef },
MaxByteOffsetId: struct { max_byte_offset: IdRef },
NoSignedWrap,
NoUnsignedWrap,
ExplicitInterpAMD,
OverrideCoverageNV,
PassthroughNV,
ViewportRelativeNV,
SecondaryViewportRelativeNV: struct { offset: LiteralInteger },
PerPrimitiveNV,
PerViewNV,
PerTaskNV,
PerVertexNV,
NonUniform,
RestrictPointer,
AliasedPointer,
SIMTCallINTEL: struct { n: LiteralInteger },
ReferencedIndirectlyINTEL,
ClobberINTEL: struct { register: LiteralString },
SideEffectsINTEL,
VectorComputeVariableINTEL,
FuncParamIOKindINTEL: struct { kind: LiteralInteger },
VectorComputeFunctionINTEL,
StackCallINTEL,
GlobalVariableOffsetINTEL: struct { offset: LiteralInteger },
CounterBuffer: struct { counter_buffer: IdRef },
UserSemantic: struct { semantic: LiteralString },
UserTypeGOOGLE: struct { user_type: LiteralString },
FunctionRoundingModeINTEL: struct { target_width: LiteralInteger, fp_rounding_mode: FPRoundingMode },
FunctionDenormModeINTEL: struct { target_width: LiteralInteger, fp_denorm_mode: FPDenormMode },
RegisterINTEL,
MemoryINTEL: struct { memory_type: LiteralString },
NumbanksINTEL: struct { banks: LiteralInteger },
BankwidthINTEL: struct { bank_width: LiteralInteger },
MaxPrivateCopiesINTEL: struct { maximum_copies: LiteralInteger },
SinglepumpINTEL,
DoublepumpINTEL,
MaxReplicatesINTEL: struct { maximum_replicates: LiteralInteger },
SimpleDualPortINTEL,
MergeINTEL: struct { merge_key: LiteralString, merge_type: LiteralString },
BankBitsINTEL: struct { bank_bits: []const LiteralInteger = &.{} },
ForcePow2DepthINTEL: struct { force_key: LiteralInteger },
BurstCoalesceINTEL,
CacheSizeINTEL: struct { cache_size_in_bytes: LiteralInteger },
DontStaticallyCoalesceINTEL,
PrefetchINTEL: struct { prefetcher_size_in_bytes: LiteralInteger },
StallEnableINTEL,
FuseLoopsInFunctionINTEL,
BufferLocationINTEL: struct { buffer_location_id: LiteralInteger },
IOPipeStorageINTEL: struct { io_pipe_id: LiteralInteger },
FunctionFloatingPointModeINTEL: struct { target_width: LiteralInteger, fp_operation_mode: FPOperationMode },
SingleElementVectorINTEL,
VectorComputeCallableFunctionINTEL,
};
};
pub const BuiltIn = enum(u32) {
Position = 0,
PointSize = 1,
ClipDistance = 3,
CullDistance = 4,
VertexId = 5,
InstanceId = 6,
PrimitiveId = 7,
InvocationId = 8,
Layer = 9,
ViewportIndex = 10,
TessLevelOuter = 11,
TessLevelInner = 12,
TessCoord = 13,
PatchVertices = 14,
FragCoord = 15,
PointCoord = 16,
FrontFacing = 17,
SampleId = 18,
SamplePosition = 19,
SampleMask = 20,
FragDepth = 22,
HelperInvocation = 23,
NumWorkgroups = 24,
WorkgroupSize = 25,
WorkgroupId = 26,
LocalInvocationId = 27,
GlobalInvocationId = 28,
LocalInvocationIndex = 29,
WorkDim = 30,
GlobalSize = 31,
EnqueuedWorkgroupSize = 32,
GlobalOffset = 33,
GlobalLinearId = 34,
SubgroupSize = 36,
SubgroupMaxSize = 37,
NumSubgroups = 38,
NumEnqueuedSubgroups = 39,
SubgroupId = 40,
SubgroupLocalInvocationId = 41,
VertexIndex = 42,
InstanceIndex = 43,
SubgroupEqMask = 4416,
SubgroupGeMask = 4417,
SubgroupGtMask = 4418,
SubgroupLeMask = 4419,
SubgroupLtMask = 4420,
BaseVertex = 4424,
BaseInstance = 4425,
DrawIndex = 4426,
PrimitiveShadingRateKHR = 4432,
DeviceIndex = 4438,
ViewIndex = 4440,
ShadingRateKHR = 4444,
BaryCoordNoPerspAMD = 4992,
BaryCoordNoPerspCentroidAMD = 4993,
BaryCoordNoPerspSampleAMD = 4994,
BaryCoordSmoothAMD = 4995,
BaryCoordSmoothCentroidAMD = 4996,
BaryCoordSmoothSampleAMD = 4997,
BaryCoordPullModelAMD = 4998,
FragStencilRefEXT = 5014,
ViewportMaskNV = 5253,
SecondaryPositionNV = 5257,
SecondaryViewportMaskNV = 5258,
PositionPerViewNV = 5261,
ViewportMaskPerViewNV = 5262,
FullyCoveredEXT = 5264,
TaskCountNV = 5274,
PrimitiveCountNV = 5275,
PrimitiveIndicesNV = 5276,
ClipDistancePerViewNV = 5277,
CullDistancePerViewNV = 5278,
LayerPerViewNV = 5279,
MeshViewCountNV = 5280,
MeshViewIndicesNV = 5281,
BaryCoordNV = 5286,
BaryCoordNoPerspNV = 5287,
FragSizeEXT = 5292,
FragInvocationCountEXT = 5293,
LaunchIdKHR = 5319,
LaunchSizeKHR = 5320,
WorldRayOriginKHR = 5321,
WorldRayDirectionKHR = 5322,
ObjectRayOriginKHR = 5323,
ObjectRayDirectionKHR = 5324,
RayTminKHR = 5325,
RayTmaxKHR = 5326,
InstanceCustomIndexKHR = 5327,
ObjectToWorldKHR = 5330,
WorldToObjectKHR = 5331,
HitTNV = 5332,
HitKindKHR = 5333,
IncomingRayFlagsKHR = 5351,
RayGeometryIndexKHR = 5352,
WarpsPerSMNV = 5374,
SMCountNV = 5375,
WarpIDNV = 5376,
SMIDNV = 5377,
pub const SubgroupEqMaskKHR = BuiltIn.SubgroupEqMask;
pub const SubgroupGeMaskKHR = BuiltIn.SubgroupGeMask;
pub const SubgroupGtMaskKHR = BuiltIn.SubgroupGtMask;
pub const SubgroupLeMaskKHR = BuiltIn.SubgroupLeMask;
pub const SubgroupLtMaskKHR = BuiltIn.SubgroupLtMask;
pub const FragmentSizeNV = BuiltIn.FragSizeEXT;
pub const InvocationsPerPixelNV = BuiltIn.FragInvocationCountEXT;
pub const LaunchIdNV = BuiltIn.LaunchIdKHR;
pub const LaunchSizeNV = BuiltIn.LaunchSizeKHR;
pub const WorldRayOriginNV = BuiltIn.WorldRayOriginKHR;
pub const WorldRayDirectionNV = BuiltIn.WorldRayDirectionKHR;
pub const ObjectRayOriginNV = BuiltIn.ObjectRayOriginKHR;
pub const ObjectRayDirectionNV = BuiltIn.ObjectRayDirectionKHR;
pub const RayTminNV = BuiltIn.RayTminKHR;
pub const RayTmaxNV = BuiltIn.RayTmaxKHR;
pub const InstanceCustomIndexNV = BuiltIn.InstanceCustomIndexKHR;
pub const ObjectToWorldNV = BuiltIn.ObjectToWorldKHR;
pub const WorldToObjectNV = BuiltIn.WorldToObjectKHR;
pub const HitKindNV = BuiltIn.HitKindKHR;
pub const IncomingRayFlagsNV = BuiltIn.IncomingRayFlagsKHR;
};
pub const Scope = enum(u32) {
CrossDevice = 0,
Device = 1,
Workgroup = 2,
Subgroup = 3,
Invocation = 4,
QueueFamily = 5,
ShaderCallKHR = 6,
pub const QueueFamilyKHR = Scope.QueueFamily;
};
pub const GroupOperation = enum(u32) {
Reduce = 0,
InclusiveScan = 1,
ExclusiveScan = 2,
ClusteredReduce = 3,
PartitionedReduceNV = 6,
PartitionedInclusiveScanNV = 7,
PartitionedExclusiveScanNV = 8,
};
pub const KernelEnqueueFlags = enum(u32) {
NoWait = 0,
WaitKernel = 1,
WaitWorkGroup = 2,
};
pub const Capability = enum(u32) {
Matrix = 0,
Shader = 1,
Geometry = 2,
Tessellation = 3,
Addresses = 4,
Linkage = 5,
Kernel = 6,
Vector16 = 7,
Float16Buffer = 8,
Float16 = 9,
Float64 = 10,
Int64 = 11,
Int64Atomics = 12,
ImageBasic = 13,
ImageReadWrite = 14,
ImageMipmap = 15,
Pipes = 17,
Groups = 18,
DeviceEnqueue = 19,
LiteralSampler = 20,
AtomicStorage = 21,
Int16 = 22,
TessellationPointSize = 23,
GeometryPointSize = 24,
ImageGatherExtended = 25,
StorageImageMultisample = 27,
UniformBufferArrayDynamicIndexing = 28,
SampledImageArrayDynamicIndexing = 29,
StorageBufferArrayDynamicIndexing = 30,
StorageImageArrayDynamicIndexing = 31,
ClipDistance = 32,
CullDistance = 33,
ImageCubeArray = 34,
SampleRateShading = 35,
ImageRect = 36,
SampledRect = 37,
GenericPointer = 38,
Int8 = 39,
InputAttachment = 40,
SparseResidency = 41,
MinLod = 42,
Sampled1D = 43,
Image1D = 44,
SampledCubeArray = 45,
SampledBuffer = 46,
ImageBuffer = 47,
ImageMSArray = 48,
StorageImageExtendedFormats = 49,
ImageQuery = 50,
DerivativeControl = 51,
InterpolationFunction = 52,
TransformFeedback = 53,
GeometryStreams = 54,
StorageImageReadWithoutFormat = 55,
StorageImageWriteWithoutFormat = 56,
MultiViewport = 57,
SubgroupDispatch = 58,
NamedBarrier = 59,
PipeStorage = 60,
GroupNonUniform = 61,
GroupNonUniformVote = 62,
GroupNonUniformArithmetic = 63,
GroupNonUniformBallot = 64,
GroupNonUniformShuffle = 65,
GroupNonUniformShuffleRelative = 66,
GroupNonUniformClustered = 67,
GroupNonUniformQuad = 68,
ShaderLayer = 69,
ShaderViewportIndex = 70,
FragmentShadingRateKHR = 4422,
SubgroupBallotKHR = 4423,
DrawParameters = 4427,
WorkgroupMemoryExplicitLayoutKHR = 4428,
WorkgroupMemoryExplicitLayout8BitAccessKHR = 4429,
WorkgroupMemoryExplicitLayout16BitAccessKHR = 4430,
SubgroupVoteKHR = 4431,
StorageBuffer16BitAccess = 4433,
UniformAndStorageBuffer16BitAccess = 4434,
StoragePushConstant16 = 4435,
StorageInputOutput16 = 4436,
DeviceGroup = 4437,
MultiView = 4439,
VariablePointersStorageBuffer = 4441,
VariablePointers = 4442,
AtomicStorageOps = 4445,
SampleMaskPostDepthCoverage = 4447,
StorageBuffer8BitAccess = 4448,
UniformAndStorageBuffer8BitAccess = 4449,
StoragePushConstant8 = 4450,
DenormPreserve = 4464,
DenormFlushToZero = 4465,
SignedZeroInfNanPreserve = 4466,
RoundingModeRTE = 4467,
RoundingModeRTZ = 4468,
RayQueryProvisionalKHR = 4471,
RayQueryKHR = 4472,
RayTraversalPrimitiveCullingKHR = 4478,
RayTracingKHR = 4479,
Float16ImageAMD = 5008,
ImageGatherBiasLodAMD = 5009,
FragmentMaskAMD = 5010,
StencilExportEXT = 5013,
ImageReadWriteLodAMD = 5015,
Int64ImageEXT = 5016,
ShaderClockKHR = 5055,
SampleMaskOverrideCoverageNV = 5249,
GeometryShaderPassthroughNV = 5251,
ShaderViewportIndexLayerEXT = 5254,
ShaderViewportMaskNV = 5255,
ShaderStereoViewNV = 5259,
PerViewAttributesNV = 5260,
FragmentFullyCoveredEXT = 5265,
MeshShadingNV = 5266,
ImageFootprintNV = 5282,
FragmentBarycentricNV = 5284,
ComputeDerivativeGroupQuadsNV = 5288,
FragmentDensityEXT = 5291,
GroupNonUniformPartitionedNV = 5297,
ShaderNonUniform = 5301,
RuntimeDescriptorArray = 5302,
InputAttachmentArrayDynamicIndexing = 5303,
UniformTexelBufferArrayDynamicIndexing = 5304,
StorageTexelBufferArrayDynamicIndexing = 5305,
UniformBufferArrayNonUniformIndexing = 5306,
SampledImageArrayNonUniformIndexing = 5307,
StorageBufferArrayNonUniformIndexing = 5308,
StorageImageArrayNonUniformIndexing = 5309,
InputAttachmentArrayNonUniformIndexing = 5310,
UniformTexelBufferArrayNonUniformIndexing = 5311,
StorageTexelBufferArrayNonUniformIndexing = 5312,
RayTracingNV = 5340,
VulkanMemoryModel = 5345,
VulkanMemoryModelDeviceScope = 5346,
PhysicalStorageBufferAddresses = 5347,
ComputeDerivativeGroupLinearNV = 5350,
RayTracingProvisionalKHR = 5353,
CooperativeMatrixNV = 5357,
FragmentShaderSampleInterlockEXT = 5363,
FragmentShaderShadingRateInterlockEXT = 5372,
ShaderSMBuiltinsNV = 5373,
FragmentShaderPixelInterlockEXT = 5378,
DemoteToHelperInvocationEXT = 5379,
SubgroupShuffleINTEL = 5568,
SubgroupBufferBlockIOINTEL = 5569,
SubgroupImageBlockIOINTEL = 5570,
SubgroupImageMediaBlockIOINTEL = 5579,
RoundToInfinityINTEL = 5582,
FloatingPointModeINTEL = 5583,
IntegerFunctions2INTEL = 5584,
FunctionPointersINTEL = 5603,
IndirectReferencesINTEL = 5604,
AsmINTEL = 5606,
AtomicFloat32MinMaxEXT = 5612,
AtomicFloat64MinMaxEXT = 5613,
AtomicFloat16MinMaxEXT = 5616,
VectorComputeINTEL = 5617,
VectorAnyINTEL = 5619,
ExpectAssumeKHR = 5629,
SubgroupAvcMotionEstimationINTEL = 5696,
SubgroupAvcMotionEstimationIntraINTEL = 5697,
SubgroupAvcMotionEstimationChromaINTEL = 5698,
VariableLengthArrayINTEL = 5817,
FunctionFloatControlINTEL = 5821,
FPGAMemoryAttributesINTEL = 5824,
FPFastMathModeINTEL = 5837,
ArbitraryPrecisionIntegersINTEL = 5844,
UnstructuredLoopControlsINTEL = 5886,
FPGALoopControlsINTEL = 5888,
KernelAttributesINTEL = 5892,
FPGAKernelAttributesINTEL = 5897,
FPGAMemoryAccessesINTEL = 5898,
FPGAClusterAttributesINTEL = 5904,
LoopFuseINTEL = 5906,
FPGABufferLocationINTEL = 5920,
USMStorageClassesINTEL = 5935,
IOPipesINTEL = 5943,
BlockingPipesINTEL = 5945,
FPGARegINTEL = 5948,
AtomicFloat32AddEXT = 6033,
AtomicFloat64AddEXT = 6034,
LongConstantCompositeINTEL = 6089,
pub const StorageUniformBufferBlock16 = Capability.StorageBuffer16BitAccess;
pub const StorageUniform16 = Capability.UniformAndStorageBuffer16BitAccess;
pub const ShaderViewportIndexLayerNV = Capability.ShaderViewportIndexLayerEXT;
pub const ShadingRateNV = Capability.FragmentDensityEXT;
pub const ShaderNonUniformEXT = Capability.ShaderNonUniform;
pub const RuntimeDescriptorArrayEXT = Capability.RuntimeDescriptorArray;
pub const InputAttachmentArrayDynamicIndexingEXT = Capability.InputAttachmentArrayDynamicIndexing;
pub const UniformTexelBufferArrayDynamicIndexingEXT = Capability.UniformTexelBufferArrayDynamicIndexing;
pub const StorageTexelBufferArrayDynamicIndexingEXT = Capability.StorageTexelBufferArrayDynamicIndexing;
pub const UniformBufferArrayNonUniformIndexingEXT = Capability.UniformBufferArrayNonUniformIndexing;
pub const SampledImageArrayNonUniformIndexingEXT = Capability.SampledImageArrayNonUniformIndexing;
pub const StorageBufferArrayNonUniformIndexingEXT = Capability.StorageBufferArrayNonUniformIndexing;
pub const StorageImageArrayNonUniformIndexingEXT = Capability.StorageImageArrayNonUniformIndexing;
pub const InputAttachmentArrayNonUniformIndexingEXT = Capability.InputAttachmentArrayNonUniformIndexing;
pub const UniformTexelBufferArrayNonUniformIndexingEXT = Capability.UniformTexelBufferArrayNonUniformIndexing;
pub const StorageTexelBufferArrayNonUniformIndexingEXT = Capability.StorageTexelBufferArrayNonUniformIndexing;
pub const VulkanMemoryModelKHR = Capability.VulkanMemoryModel;
pub const VulkanMemoryModelDeviceScopeKHR = Capability.VulkanMemoryModelDeviceScope;
pub const PhysicalStorageBufferAddressesEXT = Capability.PhysicalStorageBufferAddresses;
};
pub const RayQueryIntersection = enum(u32) {
RayQueryCandidateIntersectionKHR = 0,
RayQueryCommittedIntersectionKHR = 1,
};
pub const RayQueryCommittedIntersectionType = enum(u32) {
RayQueryCommittedIntersectionNoneKHR = 0,
RayQueryCommittedIntersectionTriangleKHR = 1,
RayQueryCommittedIntersectionGeneratedKHR = 2,
};
pub const RayQueryCandidateIntersectionType = enum(u32) {
RayQueryCandidateIntersectionTriangleKHR = 0,
RayQueryCandidateIntersectionAABBKHR = 1,
}; | src/codegen/spirv/spec.zig |
const std = @import("std");
const print = std.debug.print;
const data = @embedFile("../data/day02.txt");
const Direction = enum(u2) {
up,
down,
forward
};
fn day01() !void {
var depth : i32 = 0;
var position : i32 = 0;
var iterator = std.mem.tokenize(data, "\r\n ");
var nextCommand : ?Direction = null;
while (iterator.next()) |token| {
if (std.mem.startsWith(u8, token, "up")) {
nextCommand = Direction.up;
} else if (std.mem.startsWith(u8, token, "down")) {
nextCommand = Direction.down;
} else if (std.mem.startsWith(u8, token, "forward")) {
nextCommand = Direction.forward;
} else {
var change = try std.fmt.parseInt(i32, token, 10);
switch (nextCommand.?) {
Direction.up => depth -= change,
Direction.down => depth += change,
Direction.forward => position += change,
}
}
}
print("🎁 Horizontal Position * Depth: {}\n", .{position * depth});
}
fn day02() !void {
var depth : i32 = 0;
var position : i32 = 0;
var aim : i32 = 0;
var iterator = std.mem.tokenize(data, "\r\n ");
var nextCommand : ?Direction = null;
while (iterator.next()) |token| {
if (std.mem.startsWith(u8, token, "up")) {
nextCommand = Direction.up;
} else if (std.mem.startsWith(u8, token, "down")) {
nextCommand = Direction.down;
} else if (std.mem.startsWith(u8, token, "forward")) {
nextCommand = Direction.forward;
} else {
var change = try std.fmt.parseInt(i32, token, 10);
switch (nextCommand.?) {
Direction.up => aim -= change,
Direction.down => aim += change,
Direction.forward => {
position += change;
depth += aim * change;
},
}
}
}
print("🎁 Horizontal Position * Depth: {}\n", .{position * depth});
}
pub fn main() !void {
var timer = try std.time.Timer.start();
try day01();
var part01 = timer.lap();
print("Day 02 - part 01 took {:15}ns\n", .{part01});
timer.reset();
try day02();
var part02 = timer.lap();
print("Day 02 - part 02 took {:15}ns\n", .{part02});
print("❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️❄️\n", .{});
} | src/day02.zig |
const kernel = @import("kernel.zig");
const log = kernel.log.scoped(.ELF);
const FileHeader = extern struct {
// e_ident
magic: u8 = magic,
elf_id: [3]u8 = elf_signature.*,
bit_count: u8 = @enumToInt(Bits.b64),
endianness: u8 = @enumToInt(Endianness.little),
header_version: u8 = 1,
os_abi: u8 = @enumToInt(ABI.SystemV),
abi_version: u8 = 0,
padding: [7]u8 = [_]u8{0} ** 7,
object_type: u16 = @enumToInt(ObjectFileType.executable), // e_type
machine: u16 = @enumToInt(Machine.AMD64),
version: u32 = 1,
entry: u64,
program_header_offset: u64 = 0x40,
section_header_offset: u64,
flags: u32 = 0,
header_size: u16 = 0x40,
program_header_size: u16 = @sizeOf(ProgramHeader),
program_header_entry_count: u16 = 1,
section_header_size: u16 = @sizeOf(SectionHeader),
section_header_entry_count: u16,
name_section_header_index: u16,
const magic = 0x7f;
const elf_signature = "ELF";
const Bits = enum(u8) {
b32 = 1,
b64 = 2,
};
const Endianness = enum(u8) {
little = 1,
big = 2,
};
const ABI = enum(u8) {
SystemV = 0,
};
const ObjectFileType = enum(u16) {
none = 0,
relocatable = 1,
executable = 2,
dynamic = 3,
core = 4,
lo_os = 0xfe00,
hi_os = 0xfeff,
lo_proc = 0xff00,
hi_proc = 0xffff,
};
const Machine = enum(u16) {
AMD64 = 0x3e,
};
};
const ProgramHeader = extern struct {
type: u32 = @enumToInt(ProgramHeaderType.load),
flags: u32 = @enumToInt(Flags.readable) | @enumToInt(Flags.executable),
offset: u64,
virtual_address: u64,
physical_address: u64,
size_in_file: u64,
size_in_memory: u64,
alignment: u64 = 0,
const ProgramHeaderType = enum(u32) {
@"null" = 0,
load = 1,
dynamic = 2,
interpreter = 3,
note = 4,
shlib = 5, // reserved
program_header = 6,
tls = 7,
lo_os = 0x60000000,
hi_os = 0x6fffffff,
lo_proc = 0x70000000,
hi_proc = 0x7fffffff,
};
const Flags = enum(u8) {
executable = 1,
writable = 2,
readable = 4,
};
};
const SectionHeader = extern struct {
name_offset: u32,
type: u32,
flags: u64,
address: u64,
offset: u64,
size: u64,
// section index
link: u32,
info: u32,
alignment: u64,
entry_size: u64,
// type
const ID = enum(u32) {
@"null" = 0,
program_data = 1,
symbol_table = 2,
string_table = 3,
relocation_entries_addends = 4,
symbol_hash_table = 5,
dynamic_linking_info = 6,
notes = 7,
program_space_no_data = 8,
relocation_entries = 9,
reserved = 10,
dynamic_linker_symbol_table = 11,
array_of_constructors = 14,
array_of_destructors = 15,
array_of_pre_constructors = 16,
section_group = 17,
extended_section_indices = 18,
number_of_defined_types = 19,
start_os_specific = 0x60000000,
};
const Flag = enum(u64) {
writable = 0x01,
alloc = 0x02,
executable = 0x04,
mergeable = 0x10,
contains_null_terminated_strings = 0x20,
info_link = 0x40,
link_order = 0x80,
os_non_conforming = 0x100,
section_group = 0x200,
tls = 0x400,
mask_os = 0x0ff00000,
mask_processor = 0xf0000000,
ordered = 0x4000000,
exclude = 0x8000000,
};
};
pub fn parse(file: []const u8) void {
const file_header = @ptrCast(*align(1) const FileHeader, file.ptr);
if (file_header.magic != FileHeader.magic) @panic("magic");
if (!kernel.string_eq(&file_header.elf_id, FileHeader.elf_signature)) @panic("signature");
log.debug("Parsed so far the kernel ELF file\n{}", .{file_header});
} | src/kernel/elf.zig |
const std = @import("std");
const mem = std.mem;
const sort = std.sort.sort;
const unicode = std.unicode;
const CccMap = @import("../DerivedCombiningClass/CccMap.zig");
const HangulMap = @import("../HangulSyllableType/HangulMap.zig");
/// Decomposed is the result of a code point full decomposition. It can be one of:
/// * .src: Sorce code point.
/// * .same : Default canonical decomposition to the code point itself.
/// * .single : Singleton canonical decomposition to a different single code point.
/// * .canon : Canonical decomposition, which always results in two code points.
/// * .compat : Compatibility decomposition, which can results in at most 18 code points.
pub const Decomposed = union(enum) {
src: u21,
same: u21,
single: u21,
canon: [2]u21,
compat: []const u21,
};
pub const Form = enum {
D, // Canonical Decomposition
KD, // Compatibility Decomposition
};
allocator: *std.mem.Allocator,
ccc_map: CccMap,
han_map: HangulMap,
map: std.AutoHashMap(u21, Decomposed),
const Self = @This();
pub fn init(allocator: *std.mem.Allocator) !Self {
var instance = Self{
.allocator = allocator,
.ccc_map = try CccMap.init(allocator),
.han_map = try HangulMap.init(allocator),
.map = std.AutoHashMap(u21, Decomposed).init(allocator),
};
try instance.map.put(0x00A0, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x00A8, .{ .compat = &[_]u21{
0x0020,
0x0308,
} });
try instance.map.put(0x00AA, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x00AF, .{ .compat = &[_]u21{
0x0020,
0x0304,
} });
try instance.map.put(0x00B2, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0x00B3, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0x00B4, .{ .compat = &[_]u21{
0x0020,
0x0301,
} });
try instance.map.put(0x00B5, .{ .compat = &[_]u21{
0x03BC,
} });
try instance.map.put(0x00B8, .{ .compat = &[_]u21{
0x0020,
0x0327,
} });
try instance.map.put(0x00B9, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0x00BA, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x00BC, .{ .compat = &[_]u21{
0x0031,
0x2044,
0x0034,
} });
try instance.map.put(0x00BD, .{ .compat = &[_]u21{
0x0031,
0x2044,
0x0032,
} });
try instance.map.put(0x00BE, .{ .compat = &[_]u21{
0x0033,
0x2044,
0x0034,
} });
try instance.map.put(0x00C0, .{ .canon = [2]u21{
0x0041,
0x0300,
} });
try instance.map.put(0x00C1, .{ .canon = [2]u21{
0x0041,
0x0301,
} });
try instance.map.put(0x00C2, .{ .canon = [2]u21{
0x0041,
0x0302,
} });
try instance.map.put(0x00C3, .{ .canon = [2]u21{
0x0041,
0x0303,
} });
try instance.map.put(0x00C4, .{ .canon = [2]u21{
0x0041,
0x0308,
} });
try instance.map.put(0x00C5, .{ .canon = [2]u21{
0x0041,
0x030A,
} });
try instance.map.put(0x00C7, .{ .canon = [2]u21{
0x0043,
0x0327,
} });
try instance.map.put(0x00C8, .{ .canon = [2]u21{
0x0045,
0x0300,
} });
try instance.map.put(0x00C9, .{ .canon = [2]u21{
0x0045,
0x0301,
} });
try instance.map.put(0x00CA, .{ .canon = [2]u21{
0x0045,
0x0302,
} });
try instance.map.put(0x00CB, .{ .canon = [2]u21{
0x0045,
0x0308,
} });
try instance.map.put(0x00CC, .{ .canon = [2]u21{
0x0049,
0x0300,
} });
try instance.map.put(0x00CD, .{ .canon = [2]u21{
0x0049,
0x0301,
} });
try instance.map.put(0x00CE, .{ .canon = [2]u21{
0x0049,
0x0302,
} });
try instance.map.put(0x00CF, .{ .canon = [2]u21{
0x0049,
0x0308,
} });
try instance.map.put(0x00D1, .{ .canon = [2]u21{
0x004E,
0x0303,
} });
try instance.map.put(0x00D2, .{ .canon = [2]u21{
0x004F,
0x0300,
} });
try instance.map.put(0x00D3, .{ .canon = [2]u21{
0x004F,
0x0301,
} });
try instance.map.put(0x00D4, .{ .canon = [2]u21{
0x004F,
0x0302,
} });
try instance.map.put(0x00D5, .{ .canon = [2]u21{
0x004F,
0x0303,
} });
try instance.map.put(0x00D6, .{ .canon = [2]u21{
0x004F,
0x0308,
} });
try instance.map.put(0x00D9, .{ .canon = [2]u21{
0x0055,
0x0300,
} });
try instance.map.put(0x00DA, .{ .canon = [2]u21{
0x0055,
0x0301,
} });
try instance.map.put(0x00DB, .{ .canon = [2]u21{
0x0055,
0x0302,
} });
try instance.map.put(0x00DC, .{ .canon = [2]u21{
0x0055,
0x0308,
} });
try instance.map.put(0x00DD, .{ .canon = [2]u21{
0x0059,
0x0301,
} });
try instance.map.put(0x00E0, .{ .canon = [2]u21{
0x0061,
0x0300,
} });
try instance.map.put(0x00E1, .{ .canon = [2]u21{
0x0061,
0x0301,
} });
try instance.map.put(0x00E2, .{ .canon = [2]u21{
0x0061,
0x0302,
} });
try instance.map.put(0x00E3, .{ .canon = [2]u21{
0x0061,
0x0303,
} });
try instance.map.put(0x00E4, .{ .canon = [2]u21{
0x0061,
0x0308,
} });
try instance.map.put(0x00E5, .{ .canon = [2]u21{
0x0061,
0x030A,
} });
try instance.map.put(0x00E7, .{ .canon = [2]u21{
0x0063,
0x0327,
} });
try instance.map.put(0x00E8, .{ .canon = [2]u21{
0x0065,
0x0300,
} });
try instance.map.put(0x00E9, .{ .canon = [2]u21{
0x0065,
0x0301,
} });
try instance.map.put(0x00EA, .{ .canon = [2]u21{
0x0065,
0x0302,
} });
try instance.map.put(0x00EB, .{ .canon = [2]u21{
0x0065,
0x0308,
} });
try instance.map.put(0x00EC, .{ .canon = [2]u21{
0x0069,
0x0300,
} });
try instance.map.put(0x00ED, .{ .canon = [2]u21{
0x0069,
0x0301,
} });
try instance.map.put(0x00EE, .{ .canon = [2]u21{
0x0069,
0x0302,
} });
try instance.map.put(0x00EF, .{ .canon = [2]u21{
0x0069,
0x0308,
} });
try instance.map.put(0x00F1, .{ .canon = [2]u21{
0x006E,
0x0303,
} });
try instance.map.put(0x00F2, .{ .canon = [2]u21{
0x006F,
0x0300,
} });
try instance.map.put(0x00F3, .{ .canon = [2]u21{
0x006F,
0x0301,
} });
try instance.map.put(0x00F4, .{ .canon = [2]u21{
0x006F,
0x0302,
} });
try instance.map.put(0x00F5, .{ .canon = [2]u21{
0x006F,
0x0303,
} });
try instance.map.put(0x00F6, .{ .canon = [2]u21{
0x006F,
0x0308,
} });
try instance.map.put(0x00F9, .{ .canon = [2]u21{
0x0075,
0x0300,
} });
try instance.map.put(0x00FA, .{ .canon = [2]u21{
0x0075,
0x0301,
} });
try instance.map.put(0x00FB, .{ .canon = [2]u21{
0x0075,
0x0302,
} });
try instance.map.put(0x00FC, .{ .canon = [2]u21{
0x0075,
0x0308,
} });
try instance.map.put(0x00FD, .{ .canon = [2]u21{
0x0079,
0x0301,
} });
try instance.map.put(0x00FF, .{ .canon = [2]u21{
0x0079,
0x0308,
} });
try instance.map.put(0x0100, .{ .canon = [2]u21{
0x0041,
0x0304,
} });
try instance.map.put(0x0101, .{ .canon = [2]u21{
0x0061,
0x0304,
} });
try instance.map.put(0x0102, .{ .canon = [2]u21{
0x0041,
0x0306,
} });
try instance.map.put(0x0103, .{ .canon = [2]u21{
0x0061,
0x0306,
} });
try instance.map.put(0x0104, .{ .canon = [2]u21{
0x0041,
0x0328,
} });
try instance.map.put(0x0105, .{ .canon = [2]u21{
0x0061,
0x0328,
} });
try instance.map.put(0x0106, .{ .canon = [2]u21{
0x0043,
0x0301,
} });
try instance.map.put(0x0107, .{ .canon = [2]u21{
0x0063,
0x0301,
} });
try instance.map.put(0x0108, .{ .canon = [2]u21{
0x0043,
0x0302,
} });
try instance.map.put(0x0109, .{ .canon = [2]u21{
0x0063,
0x0302,
} });
try instance.map.put(0x010A, .{ .canon = [2]u21{
0x0043,
0x0307,
} });
try instance.map.put(0x010B, .{ .canon = [2]u21{
0x0063,
0x0307,
} });
try instance.map.put(0x010C, .{ .canon = [2]u21{
0x0043,
0x030C,
} });
try instance.map.put(0x010D, .{ .canon = [2]u21{
0x0063,
0x030C,
} });
try instance.map.put(0x010E, .{ .canon = [2]u21{
0x0044,
0x030C,
} });
try instance.map.put(0x010F, .{ .canon = [2]u21{
0x0064,
0x030C,
} });
try instance.map.put(0x0112, .{ .canon = [2]u21{
0x0045,
0x0304,
} });
try instance.map.put(0x0113, .{ .canon = [2]u21{
0x0065,
0x0304,
} });
try instance.map.put(0x0114, .{ .canon = [2]u21{
0x0045,
0x0306,
} });
try instance.map.put(0x0115, .{ .canon = [2]u21{
0x0065,
0x0306,
} });
try instance.map.put(0x0116, .{ .canon = [2]u21{
0x0045,
0x0307,
} });
try instance.map.put(0x0117, .{ .canon = [2]u21{
0x0065,
0x0307,
} });
try instance.map.put(0x0118, .{ .canon = [2]u21{
0x0045,
0x0328,
} });
try instance.map.put(0x0119, .{ .canon = [2]u21{
0x0065,
0x0328,
} });
try instance.map.put(0x011A, .{ .canon = [2]u21{
0x0045,
0x030C,
} });
try instance.map.put(0x011B, .{ .canon = [2]u21{
0x0065,
0x030C,
} });
try instance.map.put(0x011C, .{ .canon = [2]u21{
0x0047,
0x0302,
} });
try instance.map.put(0x011D, .{ .canon = [2]u21{
0x0067,
0x0302,
} });
try instance.map.put(0x011E, .{ .canon = [2]u21{
0x0047,
0x0306,
} });
try instance.map.put(0x011F, .{ .canon = [2]u21{
0x0067,
0x0306,
} });
try instance.map.put(0x0120, .{ .canon = [2]u21{
0x0047,
0x0307,
} });
try instance.map.put(0x0121, .{ .canon = [2]u21{
0x0067,
0x0307,
} });
try instance.map.put(0x0122, .{ .canon = [2]u21{
0x0047,
0x0327,
} });
try instance.map.put(0x0123, .{ .canon = [2]u21{
0x0067,
0x0327,
} });
try instance.map.put(0x0124, .{ .canon = [2]u21{
0x0048,
0x0302,
} });
try instance.map.put(0x0125, .{ .canon = [2]u21{
0x0068,
0x0302,
} });
try instance.map.put(0x0128, .{ .canon = [2]u21{
0x0049,
0x0303,
} });
try instance.map.put(0x0129, .{ .canon = [2]u21{
0x0069,
0x0303,
} });
try instance.map.put(0x012A, .{ .canon = [2]u21{
0x0049,
0x0304,
} });
try instance.map.put(0x012B, .{ .canon = [2]u21{
0x0069,
0x0304,
} });
try instance.map.put(0x012C, .{ .canon = [2]u21{
0x0049,
0x0306,
} });
try instance.map.put(0x012D, .{ .canon = [2]u21{
0x0069,
0x0306,
} });
try instance.map.put(0x012E, .{ .canon = [2]u21{
0x0049,
0x0328,
} });
try instance.map.put(0x012F, .{ .canon = [2]u21{
0x0069,
0x0328,
} });
try instance.map.put(0x0130, .{ .canon = [2]u21{
0x0049,
0x0307,
} });
try instance.map.put(0x0132, .{ .compat = &[_]u21{
0x0049,
0x004A,
} });
try instance.map.put(0x0133, .{ .compat = &[_]u21{
0x0069,
0x006A,
} });
try instance.map.put(0x0134, .{ .canon = [2]u21{
0x004A,
0x0302,
} });
try instance.map.put(0x0135, .{ .canon = [2]u21{
0x006A,
0x0302,
} });
try instance.map.put(0x0136, .{ .canon = [2]u21{
0x004B,
0x0327,
} });
try instance.map.put(0x0137, .{ .canon = [2]u21{
0x006B,
0x0327,
} });
try instance.map.put(0x0139, .{ .canon = [2]u21{
0x004C,
0x0301,
} });
try instance.map.put(0x013A, .{ .canon = [2]u21{
0x006C,
0x0301,
} });
try instance.map.put(0x013B, .{ .canon = [2]u21{
0x004C,
0x0327,
} });
try instance.map.put(0x013C, .{ .canon = [2]u21{
0x006C,
0x0327,
} });
try instance.map.put(0x013D, .{ .canon = [2]u21{
0x004C,
0x030C,
} });
try instance.map.put(0x013E, .{ .canon = [2]u21{
0x006C,
0x030C,
} });
try instance.map.put(0x013F, .{ .compat = &[_]u21{
0x004C,
0x00B7,
} });
try instance.map.put(0x0140, .{ .compat = &[_]u21{
0x006C,
0x00B7,
} });
try instance.map.put(0x0143, .{ .canon = [2]u21{
0x004E,
0x0301,
} });
try instance.map.put(0x0144, .{ .canon = [2]u21{
0x006E,
0x0301,
} });
try instance.map.put(0x0145, .{ .canon = [2]u21{
0x004E,
0x0327,
} });
try instance.map.put(0x0146, .{ .canon = [2]u21{
0x006E,
0x0327,
} });
try instance.map.put(0x0147, .{ .canon = [2]u21{
0x004E,
0x030C,
} });
try instance.map.put(0x0148, .{ .canon = [2]u21{
0x006E,
0x030C,
} });
try instance.map.put(0x0149, .{ .compat = &[_]u21{
0x02BC,
0x006E,
} });
try instance.map.put(0x014C, .{ .canon = [2]u21{
0x004F,
0x0304,
} });
try instance.map.put(0x014D, .{ .canon = [2]u21{
0x006F,
0x0304,
} });
try instance.map.put(0x014E, .{ .canon = [2]u21{
0x004F,
0x0306,
} });
try instance.map.put(0x014F, .{ .canon = [2]u21{
0x006F,
0x0306,
} });
try instance.map.put(0x0150, .{ .canon = [2]u21{
0x004F,
0x030B,
} });
try instance.map.put(0x0151, .{ .canon = [2]u21{
0x006F,
0x030B,
} });
try instance.map.put(0x0154, .{ .canon = [2]u21{
0x0052,
0x0301,
} });
try instance.map.put(0x0155, .{ .canon = [2]u21{
0x0072,
0x0301,
} });
try instance.map.put(0x0156, .{ .canon = [2]u21{
0x0052,
0x0327,
} });
try instance.map.put(0x0157, .{ .canon = [2]u21{
0x0072,
0x0327,
} });
try instance.map.put(0x0158, .{ .canon = [2]u21{
0x0052,
0x030C,
} });
try instance.map.put(0x0159, .{ .canon = [2]u21{
0x0072,
0x030C,
} });
try instance.map.put(0x015A, .{ .canon = [2]u21{
0x0053,
0x0301,
} });
try instance.map.put(0x015B, .{ .canon = [2]u21{
0x0073,
0x0301,
} });
try instance.map.put(0x015C, .{ .canon = [2]u21{
0x0053,
0x0302,
} });
try instance.map.put(0x015D, .{ .canon = [2]u21{
0x0073,
0x0302,
} });
try instance.map.put(0x015E, .{ .canon = [2]u21{
0x0053,
0x0327,
} });
try instance.map.put(0x015F, .{ .canon = [2]u21{
0x0073,
0x0327,
} });
try instance.map.put(0x0160, .{ .canon = [2]u21{
0x0053,
0x030C,
} });
try instance.map.put(0x0161, .{ .canon = [2]u21{
0x0073,
0x030C,
} });
try instance.map.put(0x0162, .{ .canon = [2]u21{
0x0054,
0x0327,
} });
try instance.map.put(0x0163, .{ .canon = [2]u21{
0x0074,
0x0327,
} });
try instance.map.put(0x0164, .{ .canon = [2]u21{
0x0054,
0x030C,
} });
try instance.map.put(0x0165, .{ .canon = [2]u21{
0x0074,
0x030C,
} });
try instance.map.put(0x0168, .{ .canon = [2]u21{
0x0055,
0x0303,
} });
try instance.map.put(0x0169, .{ .canon = [2]u21{
0x0075,
0x0303,
} });
try instance.map.put(0x016A, .{ .canon = [2]u21{
0x0055,
0x0304,
} });
try instance.map.put(0x016B, .{ .canon = [2]u21{
0x0075,
0x0304,
} });
try instance.map.put(0x016C, .{ .canon = [2]u21{
0x0055,
0x0306,
} });
try instance.map.put(0x016D, .{ .canon = [2]u21{
0x0075,
0x0306,
} });
try instance.map.put(0x016E, .{ .canon = [2]u21{
0x0055,
0x030A,
} });
try instance.map.put(0x016F, .{ .canon = [2]u21{
0x0075,
0x030A,
} });
try instance.map.put(0x0170, .{ .canon = [2]u21{
0x0055,
0x030B,
} });
try instance.map.put(0x0171, .{ .canon = [2]u21{
0x0075,
0x030B,
} });
try instance.map.put(0x0172, .{ .canon = [2]u21{
0x0055,
0x0328,
} });
try instance.map.put(0x0173, .{ .canon = [2]u21{
0x0075,
0x0328,
} });
try instance.map.put(0x0174, .{ .canon = [2]u21{
0x0057,
0x0302,
} });
try instance.map.put(0x0175, .{ .canon = [2]u21{
0x0077,
0x0302,
} });
try instance.map.put(0x0176, .{ .canon = [2]u21{
0x0059,
0x0302,
} });
try instance.map.put(0x0177, .{ .canon = [2]u21{
0x0079,
0x0302,
} });
try instance.map.put(0x0178, .{ .canon = [2]u21{
0x0059,
0x0308,
} });
try instance.map.put(0x0179, .{ .canon = [2]u21{
0x005A,
0x0301,
} });
try instance.map.put(0x017A, .{ .canon = [2]u21{
0x007A,
0x0301,
} });
try instance.map.put(0x017B, .{ .canon = [2]u21{
0x005A,
0x0307,
} });
try instance.map.put(0x017C, .{ .canon = [2]u21{
0x007A,
0x0307,
} });
try instance.map.put(0x017D, .{ .canon = [2]u21{
0x005A,
0x030C,
} });
try instance.map.put(0x017E, .{ .canon = [2]u21{
0x007A,
0x030C,
} });
try instance.map.put(0x017F, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x01A0, .{ .canon = [2]u21{
0x004F,
0x031B,
} });
try instance.map.put(0x01A1, .{ .canon = [2]u21{
0x006F,
0x031B,
} });
try instance.map.put(0x01AF, .{ .canon = [2]u21{
0x0055,
0x031B,
} });
try instance.map.put(0x01B0, .{ .canon = [2]u21{
0x0075,
0x031B,
} });
try instance.map.put(0x01C4, .{ .compat = &[_]u21{
0x0044,
0x017D,
} });
try instance.map.put(0x01C5, .{ .compat = &[_]u21{
0x0044,
0x017E,
} });
try instance.map.put(0x01C6, .{ .compat = &[_]u21{
0x0064,
0x017E,
} });
try instance.map.put(0x01C7, .{ .compat = &[_]u21{
0x004C,
0x004A,
} });
try instance.map.put(0x01C8, .{ .compat = &[_]u21{
0x004C,
0x006A,
} });
try instance.map.put(0x01C9, .{ .compat = &[_]u21{
0x006C,
0x006A,
} });
try instance.map.put(0x01CA, .{ .compat = &[_]u21{
0x004E,
0x004A,
} });
try instance.map.put(0x01CB, .{ .compat = &[_]u21{
0x004E,
0x006A,
} });
try instance.map.put(0x01CC, .{ .compat = &[_]u21{
0x006E,
0x006A,
} });
try instance.map.put(0x01CD, .{ .canon = [2]u21{
0x0041,
0x030C,
} });
try instance.map.put(0x01CE, .{ .canon = [2]u21{
0x0061,
0x030C,
} });
try instance.map.put(0x01CF, .{ .canon = [2]u21{
0x0049,
0x030C,
} });
try instance.map.put(0x01D0, .{ .canon = [2]u21{
0x0069,
0x030C,
} });
try instance.map.put(0x01D1, .{ .canon = [2]u21{
0x004F,
0x030C,
} });
try instance.map.put(0x01D2, .{ .canon = [2]u21{
0x006F,
0x030C,
} });
try instance.map.put(0x01D3, .{ .canon = [2]u21{
0x0055,
0x030C,
} });
try instance.map.put(0x01D4, .{ .canon = [2]u21{
0x0075,
0x030C,
} });
try instance.map.put(0x01D5, .{ .canon = [2]u21{
0x00DC,
0x0304,
} });
try instance.map.put(0x01D6, .{ .canon = [2]u21{
0x00FC,
0x0304,
} });
try instance.map.put(0x01D7, .{ .canon = [2]u21{
0x00DC,
0x0301,
} });
try instance.map.put(0x01D8, .{ .canon = [2]u21{
0x00FC,
0x0301,
} });
try instance.map.put(0x01D9, .{ .canon = [2]u21{
0x00DC,
0x030C,
} });
try instance.map.put(0x01DA, .{ .canon = [2]u21{
0x00FC,
0x030C,
} });
try instance.map.put(0x01DB, .{ .canon = [2]u21{
0x00DC,
0x0300,
} });
try instance.map.put(0x01DC, .{ .canon = [2]u21{
0x00FC,
0x0300,
} });
try instance.map.put(0x01DE, .{ .canon = [2]u21{
0x00C4,
0x0304,
} });
try instance.map.put(0x01DF, .{ .canon = [2]u21{
0x00E4,
0x0304,
} });
try instance.map.put(0x01E0, .{ .canon = [2]u21{
0x0226,
0x0304,
} });
try instance.map.put(0x01E1, .{ .canon = [2]u21{
0x0227,
0x0304,
} });
try instance.map.put(0x01E2, .{ .canon = [2]u21{
0x00C6,
0x0304,
} });
try instance.map.put(0x01E3, .{ .canon = [2]u21{
0x00E6,
0x0304,
} });
try instance.map.put(0x01E6, .{ .canon = [2]u21{
0x0047,
0x030C,
} });
try instance.map.put(0x01E7, .{ .canon = [2]u21{
0x0067,
0x030C,
} });
try instance.map.put(0x01E8, .{ .canon = [2]u21{
0x004B,
0x030C,
} });
try instance.map.put(0x01E9, .{ .canon = [2]u21{
0x006B,
0x030C,
} });
try instance.map.put(0x01EA, .{ .canon = [2]u21{
0x004F,
0x0328,
} });
try instance.map.put(0x01EB, .{ .canon = [2]u21{
0x006F,
0x0328,
} });
try instance.map.put(0x01EC, .{ .canon = [2]u21{
0x01EA,
0x0304,
} });
try instance.map.put(0x01ED, .{ .canon = [2]u21{
0x01EB,
0x0304,
} });
try instance.map.put(0x01EE, .{ .canon = [2]u21{
0x01B7,
0x030C,
} });
try instance.map.put(0x01EF, .{ .canon = [2]u21{
0x0292,
0x030C,
} });
try instance.map.put(0x01F0, .{ .canon = [2]u21{
0x006A,
0x030C,
} });
try instance.map.put(0x01F1, .{ .compat = &[_]u21{
0x0044,
0x005A,
} });
try instance.map.put(0x01F2, .{ .compat = &[_]u21{
0x0044,
0x007A,
} });
try instance.map.put(0x01F3, .{ .compat = &[_]u21{
0x0064,
0x007A,
} });
try instance.map.put(0x01F4, .{ .canon = [2]u21{
0x0047,
0x0301,
} });
try instance.map.put(0x01F5, .{ .canon = [2]u21{
0x0067,
0x0301,
} });
try instance.map.put(0x01F8, .{ .canon = [2]u21{
0x004E,
0x0300,
} });
try instance.map.put(0x01F9, .{ .canon = [2]u21{
0x006E,
0x0300,
} });
try instance.map.put(0x01FA, .{ .canon = [2]u21{
0x00C5,
0x0301,
} });
try instance.map.put(0x01FB, .{ .canon = [2]u21{
0x00E5,
0x0301,
} });
try instance.map.put(0x01FC, .{ .canon = [2]u21{
0x00C6,
0x0301,
} });
try instance.map.put(0x01FD, .{ .canon = [2]u21{
0x00E6,
0x0301,
} });
try instance.map.put(0x01FE, .{ .canon = [2]u21{
0x00D8,
0x0301,
} });
try instance.map.put(0x01FF, .{ .canon = [2]u21{
0x00F8,
0x0301,
} });
try instance.map.put(0x0200, .{ .canon = [2]u21{
0x0041,
0x030F,
} });
try instance.map.put(0x0201, .{ .canon = [2]u21{
0x0061,
0x030F,
} });
try instance.map.put(0x0202, .{ .canon = [2]u21{
0x0041,
0x0311,
} });
try instance.map.put(0x0203, .{ .canon = [2]u21{
0x0061,
0x0311,
} });
try instance.map.put(0x0204, .{ .canon = [2]u21{
0x0045,
0x030F,
} });
try instance.map.put(0x0205, .{ .canon = [2]u21{
0x0065,
0x030F,
} });
try instance.map.put(0x0206, .{ .canon = [2]u21{
0x0045,
0x0311,
} });
try instance.map.put(0x0207, .{ .canon = [2]u21{
0x0065,
0x0311,
} });
try instance.map.put(0x0208, .{ .canon = [2]u21{
0x0049,
0x030F,
} });
try instance.map.put(0x0209, .{ .canon = [2]u21{
0x0069,
0x030F,
} });
try instance.map.put(0x020A, .{ .canon = [2]u21{
0x0049,
0x0311,
} });
try instance.map.put(0x020B, .{ .canon = [2]u21{
0x0069,
0x0311,
} });
try instance.map.put(0x020C, .{ .canon = [2]u21{
0x004F,
0x030F,
} });
try instance.map.put(0x020D, .{ .canon = [2]u21{
0x006F,
0x030F,
} });
try instance.map.put(0x020E, .{ .canon = [2]u21{
0x004F,
0x0311,
} });
try instance.map.put(0x020F, .{ .canon = [2]u21{
0x006F,
0x0311,
} });
try instance.map.put(0x0210, .{ .canon = [2]u21{
0x0052,
0x030F,
} });
try instance.map.put(0x0211, .{ .canon = [2]u21{
0x0072,
0x030F,
} });
try instance.map.put(0x0212, .{ .canon = [2]u21{
0x0052,
0x0311,
} });
try instance.map.put(0x0213, .{ .canon = [2]u21{
0x0072,
0x0311,
} });
try instance.map.put(0x0214, .{ .canon = [2]u21{
0x0055,
0x030F,
} });
try instance.map.put(0x0215, .{ .canon = [2]u21{
0x0075,
0x030F,
} });
try instance.map.put(0x0216, .{ .canon = [2]u21{
0x0055,
0x0311,
} });
try instance.map.put(0x0217, .{ .canon = [2]u21{
0x0075,
0x0311,
} });
try instance.map.put(0x0218, .{ .canon = [2]u21{
0x0053,
0x0326,
} });
try instance.map.put(0x0219, .{ .canon = [2]u21{
0x0073,
0x0326,
} });
try instance.map.put(0x021A, .{ .canon = [2]u21{
0x0054,
0x0326,
} });
try instance.map.put(0x021B, .{ .canon = [2]u21{
0x0074,
0x0326,
} });
try instance.map.put(0x021E, .{ .canon = [2]u21{
0x0048,
0x030C,
} });
try instance.map.put(0x021F, .{ .canon = [2]u21{
0x0068,
0x030C,
} });
try instance.map.put(0x0226, .{ .canon = [2]u21{
0x0041,
0x0307,
} });
try instance.map.put(0x0227, .{ .canon = [2]u21{
0x0061,
0x0307,
} });
try instance.map.put(0x0228, .{ .canon = [2]u21{
0x0045,
0x0327,
} });
try instance.map.put(0x0229, .{ .canon = [2]u21{
0x0065,
0x0327,
} });
try instance.map.put(0x022A, .{ .canon = [2]u21{
0x00D6,
0x0304,
} });
try instance.map.put(0x022B, .{ .canon = [2]u21{
0x00F6,
0x0304,
} });
try instance.map.put(0x022C, .{ .canon = [2]u21{
0x00D5,
0x0304,
} });
try instance.map.put(0x022D, .{ .canon = [2]u21{
0x00F5,
0x0304,
} });
try instance.map.put(0x022E, .{ .canon = [2]u21{
0x004F,
0x0307,
} });
try instance.map.put(0x022F, .{ .canon = [2]u21{
0x006F,
0x0307,
} });
try instance.map.put(0x0230, .{ .canon = [2]u21{
0x022E,
0x0304,
} });
try instance.map.put(0x0231, .{ .canon = [2]u21{
0x022F,
0x0304,
} });
try instance.map.put(0x0232, .{ .canon = [2]u21{
0x0059,
0x0304,
} });
try instance.map.put(0x0233, .{ .canon = [2]u21{
0x0079,
0x0304,
} });
try instance.map.put(0x02B0, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x02B1, .{ .compat = &[_]u21{
0x0266,
} });
try instance.map.put(0x02B2, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x02B3, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x02B4, .{ .compat = &[_]u21{
0x0279,
} });
try instance.map.put(0x02B5, .{ .compat = &[_]u21{
0x027B,
} });
try instance.map.put(0x02B6, .{ .compat = &[_]u21{
0x0281,
} });
try instance.map.put(0x02B7, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x02B8, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x02D8, .{ .compat = &[_]u21{
0x0020,
0x0306,
} });
try instance.map.put(0x02D9, .{ .compat = &[_]u21{
0x0020,
0x0307,
} });
try instance.map.put(0x02DA, .{ .compat = &[_]u21{
0x0020,
0x030A,
} });
try instance.map.put(0x02DB, .{ .compat = &[_]u21{
0x0020,
0x0328,
} });
try instance.map.put(0x02DC, .{ .compat = &[_]u21{
0x0020,
0x0303,
} });
try instance.map.put(0x02DD, .{ .compat = &[_]u21{
0x0020,
0x030B,
} });
try instance.map.put(0x02E0, .{ .compat = &[_]u21{
0x0263,
} });
try instance.map.put(0x02E1, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x02E2, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x02E3, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x02E4, .{ .compat = &[_]u21{
0x0295,
} });
try instance.map.put(0x0340, .{ .single = 0x0300 });
try instance.map.put(0x0341, .{ .single = 0x0301 });
try instance.map.put(0x0343, .{ .single = 0x0313 });
try instance.map.put(0x0344, .{ .canon = [2]u21{
0x0308,
0x0301,
} });
try instance.map.put(0x0374, .{ .single = 0x02B9 });
try instance.map.put(0x037A, .{ .compat = &[_]u21{
0x0020,
0x0345,
} });
try instance.map.put(0x037E, .{ .single = 0x003B });
try instance.map.put(0x0384, .{ .compat = &[_]u21{
0x0020,
0x0301,
} });
try instance.map.put(0x0385, .{ .canon = [2]u21{
0x00A8,
0x0301,
} });
try instance.map.put(0x0386, .{ .canon = [2]u21{
0x0391,
0x0301,
} });
try instance.map.put(0x0387, .{ .single = 0x00B7 });
try instance.map.put(0x0388, .{ .canon = [2]u21{
0x0395,
0x0301,
} });
try instance.map.put(0x0389, .{ .canon = [2]u21{
0x0397,
0x0301,
} });
try instance.map.put(0x038A, .{ .canon = [2]u21{
0x0399,
0x0301,
} });
try instance.map.put(0x038C, .{ .canon = [2]u21{
0x039F,
0x0301,
} });
try instance.map.put(0x038E, .{ .canon = [2]u21{
0x03A5,
0x0301,
} });
try instance.map.put(0x038F, .{ .canon = [2]u21{
0x03A9,
0x0301,
} });
try instance.map.put(0x0390, .{ .canon = [2]u21{
0x03CA,
0x0301,
} });
try instance.map.put(0x03AA, .{ .canon = [2]u21{
0x0399,
0x0308,
} });
try instance.map.put(0x03AB, .{ .canon = [2]u21{
0x03A5,
0x0308,
} });
try instance.map.put(0x03AC, .{ .canon = [2]u21{
0x03B1,
0x0301,
} });
try instance.map.put(0x03AD, .{ .canon = [2]u21{
0x03B5,
0x0301,
} });
try instance.map.put(0x03AE, .{ .canon = [2]u21{
0x03B7,
0x0301,
} });
try instance.map.put(0x03AF, .{ .canon = [2]u21{
0x03B9,
0x0301,
} });
try instance.map.put(0x03B0, .{ .canon = [2]u21{
0x03CB,
0x0301,
} });
try instance.map.put(0x03CA, .{ .canon = [2]u21{
0x03B9,
0x0308,
} });
try instance.map.put(0x03CB, .{ .canon = [2]u21{
0x03C5,
0x0308,
} });
try instance.map.put(0x03CC, .{ .canon = [2]u21{
0x03BF,
0x0301,
} });
try instance.map.put(0x03CD, .{ .canon = [2]u21{
0x03C5,
0x0301,
} });
try instance.map.put(0x03CE, .{ .canon = [2]u21{
0x03C9,
0x0301,
} });
try instance.map.put(0x03D0, .{ .compat = &[_]u21{
0x03B2,
} });
try instance.map.put(0x03D1, .{ .compat = &[_]u21{
0x03B8,
} });
try instance.map.put(0x03D2, .{ .compat = &[_]u21{
0x03A5,
} });
try instance.map.put(0x03D3, .{ .canon = [2]u21{
0x03D2,
0x0301,
} });
try instance.map.put(0x03D4, .{ .canon = [2]u21{
0x03D2,
0x0308,
} });
try instance.map.put(0x03D5, .{ .compat = &[_]u21{
0x03C6,
} });
try instance.map.put(0x03D6, .{ .compat = &[_]u21{
0x03C0,
} });
try instance.map.put(0x03F0, .{ .compat = &[_]u21{
0x03BA,
} });
try instance.map.put(0x03F1, .{ .compat = &[_]u21{
0x03C1,
} });
try instance.map.put(0x03F2, .{ .compat = &[_]u21{
0x03C2,
} });
try instance.map.put(0x03F4, .{ .compat = &[_]u21{
0x0398,
} });
try instance.map.put(0x03F5, .{ .compat = &[_]u21{
0x03B5,
} });
try instance.map.put(0x03F9, .{ .compat = &[_]u21{
0x03A3,
} });
try instance.map.put(0x0400, .{ .canon = [2]u21{
0x0415,
0x0300,
} });
try instance.map.put(0x0401, .{ .canon = [2]u21{
0x0415,
0x0308,
} });
try instance.map.put(0x0403, .{ .canon = [2]u21{
0x0413,
0x0301,
} });
try instance.map.put(0x0407, .{ .canon = [2]u21{
0x0406,
0x0308,
} });
try instance.map.put(0x040C, .{ .canon = [2]u21{
0x041A,
0x0301,
} });
try instance.map.put(0x040D, .{ .canon = [2]u21{
0x0418,
0x0300,
} });
try instance.map.put(0x040E, .{ .canon = [2]u21{
0x0423,
0x0306,
} });
try instance.map.put(0x0419, .{ .canon = [2]u21{
0x0418,
0x0306,
} });
try instance.map.put(0x0439, .{ .canon = [2]u21{
0x0438,
0x0306,
} });
try instance.map.put(0x0450, .{ .canon = [2]u21{
0x0435,
0x0300,
} });
try instance.map.put(0x0451, .{ .canon = [2]u21{
0x0435,
0x0308,
} });
try instance.map.put(0x0453, .{ .canon = [2]u21{
0x0433,
0x0301,
} });
try instance.map.put(0x0457, .{ .canon = [2]u21{
0x0456,
0x0308,
} });
try instance.map.put(0x045C, .{ .canon = [2]u21{
0x043A,
0x0301,
} });
try instance.map.put(0x045D, .{ .canon = [2]u21{
0x0438,
0x0300,
} });
try instance.map.put(0x045E, .{ .canon = [2]u21{
0x0443,
0x0306,
} });
try instance.map.put(0x0476, .{ .canon = [2]u21{
0x0474,
0x030F,
} });
try instance.map.put(0x0477, .{ .canon = [2]u21{
0x0475,
0x030F,
} });
try instance.map.put(0x04C1, .{ .canon = [2]u21{
0x0416,
0x0306,
} });
try instance.map.put(0x04C2, .{ .canon = [2]u21{
0x0436,
0x0306,
} });
try instance.map.put(0x04D0, .{ .canon = [2]u21{
0x0410,
0x0306,
} });
try instance.map.put(0x04D1, .{ .canon = [2]u21{
0x0430,
0x0306,
} });
try instance.map.put(0x04D2, .{ .canon = [2]u21{
0x0410,
0x0308,
} });
try instance.map.put(0x04D3, .{ .canon = [2]u21{
0x0430,
0x0308,
} });
try instance.map.put(0x04D6, .{ .canon = [2]u21{
0x0415,
0x0306,
} });
try instance.map.put(0x04D7, .{ .canon = [2]u21{
0x0435,
0x0306,
} });
try instance.map.put(0x04DA, .{ .canon = [2]u21{
0x04D8,
0x0308,
} });
try instance.map.put(0x04DB, .{ .canon = [2]u21{
0x04D9,
0x0308,
} });
try instance.map.put(0x04DC, .{ .canon = [2]u21{
0x0416,
0x0308,
} });
try instance.map.put(0x04DD, .{ .canon = [2]u21{
0x0436,
0x0308,
} });
try instance.map.put(0x04DE, .{ .canon = [2]u21{
0x0417,
0x0308,
} });
try instance.map.put(0x04DF, .{ .canon = [2]u21{
0x0437,
0x0308,
} });
try instance.map.put(0x04E2, .{ .canon = [2]u21{
0x0418,
0x0304,
} });
try instance.map.put(0x04E3, .{ .canon = [2]u21{
0x0438,
0x0304,
} });
try instance.map.put(0x04E4, .{ .canon = [2]u21{
0x0418,
0x0308,
} });
try instance.map.put(0x04E5, .{ .canon = [2]u21{
0x0438,
0x0308,
} });
try instance.map.put(0x04E6, .{ .canon = [2]u21{
0x041E,
0x0308,
} });
try instance.map.put(0x04E7, .{ .canon = [2]u21{
0x043E,
0x0308,
} });
try instance.map.put(0x04EA, .{ .canon = [2]u21{
0x04E8,
0x0308,
} });
try instance.map.put(0x04EB, .{ .canon = [2]u21{
0x04E9,
0x0308,
} });
try instance.map.put(0x04EC, .{ .canon = [2]u21{
0x042D,
0x0308,
} });
try instance.map.put(0x04ED, .{ .canon = [2]u21{
0x044D,
0x0308,
} });
try instance.map.put(0x04EE, .{ .canon = [2]u21{
0x0423,
0x0304,
} });
try instance.map.put(0x04EF, .{ .canon = [2]u21{
0x0443,
0x0304,
} });
try instance.map.put(0x04F0, .{ .canon = [2]u21{
0x0423,
0x0308,
} });
try instance.map.put(0x04F1, .{ .canon = [2]u21{
0x0443,
0x0308,
} });
try instance.map.put(0x04F2, .{ .canon = [2]u21{
0x0423,
0x030B,
} });
try instance.map.put(0x04F3, .{ .canon = [2]u21{
0x0443,
0x030B,
} });
try instance.map.put(0x04F4, .{ .canon = [2]u21{
0x0427,
0x0308,
} });
try instance.map.put(0x04F5, .{ .canon = [2]u21{
0x0447,
0x0308,
} });
try instance.map.put(0x04F8, .{ .canon = [2]u21{
0x042B,
0x0308,
} });
try instance.map.put(0x04F9, .{ .canon = [2]u21{
0x044B,
0x0308,
} });
try instance.map.put(0x0587, .{ .compat = &[_]u21{
0x0565,
0x0582,
} });
try instance.map.put(0x0622, .{ .canon = [2]u21{
0x0627,
0x0653,
} });
try instance.map.put(0x0623, .{ .canon = [2]u21{
0x0627,
0x0654,
} });
try instance.map.put(0x0624, .{ .canon = [2]u21{
0x0648,
0x0654,
} });
try instance.map.put(0x0625, .{ .canon = [2]u21{
0x0627,
0x0655,
} });
try instance.map.put(0x0626, .{ .canon = [2]u21{
0x064A,
0x0654,
} });
try instance.map.put(0x0675, .{ .compat = &[_]u21{
0x0627,
0x0674,
} });
try instance.map.put(0x0676, .{ .compat = &[_]u21{
0x0648,
0x0674,
} });
try instance.map.put(0x0677, .{ .compat = &[_]u21{
0x06C7,
0x0674,
} });
try instance.map.put(0x0678, .{ .compat = &[_]u21{
0x064A,
0x0674,
} });
try instance.map.put(0x06C0, .{ .canon = [2]u21{
0x06D5,
0x0654,
} });
try instance.map.put(0x06C2, .{ .canon = [2]u21{
0x06C1,
0x0654,
} });
try instance.map.put(0x06D3, .{ .canon = [2]u21{
0x06D2,
0x0654,
} });
try instance.map.put(0x0929, .{ .canon = [2]u21{
0x0928,
0x093C,
} });
try instance.map.put(0x0931, .{ .canon = [2]u21{
0x0930,
0x093C,
} });
try instance.map.put(0x0934, .{ .canon = [2]u21{
0x0933,
0x093C,
} });
try instance.map.put(0x0958, .{ .canon = [2]u21{
0x0915,
0x093C,
} });
try instance.map.put(0x0959, .{ .canon = [2]u21{
0x0916,
0x093C,
} });
try instance.map.put(0x095A, .{ .canon = [2]u21{
0x0917,
0x093C,
} });
try instance.map.put(0x095B, .{ .canon = [2]u21{
0x091C,
0x093C,
} });
try instance.map.put(0x095C, .{ .canon = [2]u21{
0x0921,
0x093C,
} });
try instance.map.put(0x095D, .{ .canon = [2]u21{
0x0922,
0x093C,
} });
try instance.map.put(0x095E, .{ .canon = [2]u21{
0x092B,
0x093C,
} });
try instance.map.put(0x095F, .{ .canon = [2]u21{
0x092F,
0x093C,
} });
try instance.map.put(0x09CB, .{ .canon = [2]u21{
0x09C7,
0x09BE,
} });
try instance.map.put(0x09CC, .{ .canon = [2]u21{
0x09C7,
0x09D7,
} });
try instance.map.put(0x09DC, .{ .canon = [2]u21{
0x09A1,
0x09BC,
} });
try instance.map.put(0x09DD, .{ .canon = [2]u21{
0x09A2,
0x09BC,
} });
try instance.map.put(0x09DF, .{ .canon = [2]u21{
0x09AF,
0x09BC,
} });
try instance.map.put(0x0A33, .{ .canon = [2]u21{
0x0A32,
0x0A3C,
} });
try instance.map.put(0x0A36, .{ .canon = [2]u21{
0x0A38,
0x0A3C,
} });
try instance.map.put(0x0A59, .{ .canon = [2]u21{
0x0A16,
0x0A3C,
} });
try instance.map.put(0x0A5A, .{ .canon = [2]u21{
0x0A17,
0x0A3C,
} });
try instance.map.put(0x0A5B, .{ .canon = [2]u21{
0x0A1C,
0x0A3C,
} });
try instance.map.put(0x0A5E, .{ .canon = [2]u21{
0x0A2B,
0x0A3C,
} });
try instance.map.put(0x0B48, .{ .canon = [2]u21{
0x0B47,
0x0B56,
} });
try instance.map.put(0x0B4B, .{ .canon = [2]u21{
0x0B47,
0x0B3E,
} });
try instance.map.put(0x0B4C, .{ .canon = [2]u21{
0x0B47,
0x0B57,
} });
try instance.map.put(0x0B5C, .{ .canon = [2]u21{
0x0B21,
0x0B3C,
} });
try instance.map.put(0x0B5D, .{ .canon = [2]u21{
0x0B22,
0x0B3C,
} });
try instance.map.put(0x0B94, .{ .canon = [2]u21{
0x0B92,
0x0BD7,
} });
try instance.map.put(0x0BCA, .{ .canon = [2]u21{
0x0BC6,
0x0BBE,
} });
try instance.map.put(0x0BCB, .{ .canon = [2]u21{
0x0BC7,
0x0BBE,
} });
try instance.map.put(0x0BCC, .{ .canon = [2]u21{
0x0BC6,
0x0BD7,
} });
try instance.map.put(0x0C48, .{ .canon = [2]u21{
0x0C46,
0x0C56,
} });
try instance.map.put(0x0CC0, .{ .canon = [2]u21{
0x0CBF,
0x0CD5,
} });
try instance.map.put(0x0CC7, .{ .canon = [2]u21{
0x0CC6,
0x0CD5,
} });
try instance.map.put(0x0CC8, .{ .canon = [2]u21{
0x0CC6,
0x0CD6,
} });
try instance.map.put(0x0CCA, .{ .canon = [2]u21{
0x0CC6,
0x0CC2,
} });
try instance.map.put(0x0CCB, .{ .canon = [2]u21{
0x0CCA,
0x0CD5,
} });
try instance.map.put(0x0D4A, .{ .canon = [2]u21{
0x0D46,
0x0D3E,
} });
try instance.map.put(0x0D4B, .{ .canon = [2]u21{
0x0D47,
0x0D3E,
} });
try instance.map.put(0x0D4C, .{ .canon = [2]u21{
0x0D46,
0x0D57,
} });
try instance.map.put(0x0DDA, .{ .canon = [2]u21{
0x0DD9,
0x0DCA,
} });
try instance.map.put(0x0DDC, .{ .canon = [2]u21{
0x0DD9,
0x0DCF,
} });
try instance.map.put(0x0DDD, .{ .canon = [2]u21{
0x0DDC,
0x0DCA,
} });
try instance.map.put(0x0DDE, .{ .canon = [2]u21{
0x0DD9,
0x0DDF,
} });
try instance.map.put(0x0E33, .{ .compat = &[_]u21{
0x0E4D,
0x0E32,
} });
try instance.map.put(0x0EB3, .{ .compat = &[_]u21{
0x0ECD,
0x0EB2,
} });
try instance.map.put(0x0EDC, .{ .compat = &[_]u21{
0x0EAB,
0x0E99,
} });
try instance.map.put(0x0EDD, .{ .compat = &[_]u21{
0x0EAB,
0x0EA1,
} });
try instance.map.put(0x0F0C, .{ .compat = &[_]u21{
0x0F0B,
} });
try instance.map.put(0x0F43, .{ .canon = [2]u21{
0x0F42,
0x0FB7,
} });
try instance.map.put(0x0F4D, .{ .canon = [2]u21{
0x0F4C,
0x0FB7,
} });
try instance.map.put(0x0F52, .{ .canon = [2]u21{
0x0F51,
0x0FB7,
} });
try instance.map.put(0x0F57, .{ .canon = [2]u21{
0x0F56,
0x0FB7,
} });
try instance.map.put(0x0F5C, .{ .canon = [2]u21{
0x0F5B,
0x0FB7,
} });
try instance.map.put(0x0F69, .{ .canon = [2]u21{
0x0F40,
0x0FB5,
} });
try instance.map.put(0x0F73, .{ .canon = [2]u21{
0x0F71,
0x0F72,
} });
try instance.map.put(0x0F75, .{ .canon = [2]u21{
0x0F71,
0x0F74,
} });
try instance.map.put(0x0F76, .{ .canon = [2]u21{
0x0FB2,
0x0F80,
} });
try instance.map.put(0x0F77, .{ .compat = &[_]u21{
0x0FB2,
0x0F81,
} });
try instance.map.put(0x0F78, .{ .canon = [2]u21{
0x0FB3,
0x0F80,
} });
try instance.map.put(0x0F79, .{ .compat = &[_]u21{
0x0FB3,
0x0F81,
} });
try instance.map.put(0x0F81, .{ .canon = [2]u21{
0x0F71,
0x0F80,
} });
try instance.map.put(0x0F93, .{ .canon = [2]u21{
0x0F92,
0x0FB7,
} });
try instance.map.put(0x0F9D, .{ .canon = [2]u21{
0x0F9C,
0x0FB7,
} });
try instance.map.put(0x0FA2, .{ .canon = [2]u21{
0x0FA1,
0x0FB7,
} });
try instance.map.put(0x0FA7, .{ .canon = [2]u21{
0x0FA6,
0x0FB7,
} });
try instance.map.put(0x0FAC, .{ .canon = [2]u21{
0x0FAB,
0x0FB7,
} });
try instance.map.put(0x0FB9, .{ .canon = [2]u21{
0x0F90,
0x0FB5,
} });
try instance.map.put(0x1026, .{ .canon = [2]u21{
0x1025,
0x102E,
} });
try instance.map.put(0x10FC, .{ .compat = &[_]u21{
0x10DC,
} });
try instance.map.put(0x1B06, .{ .canon = [2]u21{
0x1B05,
0x1B35,
} });
try instance.map.put(0x1B08, .{ .canon = [2]u21{
0x1B07,
0x1B35,
} });
try instance.map.put(0x1B0A, .{ .canon = [2]u21{
0x1B09,
0x1B35,
} });
try instance.map.put(0x1B0C, .{ .canon = [2]u21{
0x1B0B,
0x1B35,
} });
try instance.map.put(0x1B0E, .{ .canon = [2]u21{
0x1B0D,
0x1B35,
} });
try instance.map.put(0x1B12, .{ .canon = [2]u21{
0x1B11,
0x1B35,
} });
try instance.map.put(0x1B3B, .{ .canon = [2]u21{
0x1B3A,
0x1B35,
} });
try instance.map.put(0x1B3D, .{ .canon = [2]u21{
0x1B3C,
0x1B35,
} });
try instance.map.put(0x1B40, .{ .canon = [2]u21{
0x1B3E,
0x1B35,
} });
try instance.map.put(0x1B41, .{ .canon = [2]u21{
0x1B3F,
0x1B35,
} });
try instance.map.put(0x1B43, .{ .canon = [2]u21{
0x1B42,
0x1B35,
} });
try instance.map.put(0x1D2C, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D2D, .{ .compat = &[_]u21{
0x00C6,
} });
try instance.map.put(0x1D2E, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D30, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D31, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D32, .{ .compat = &[_]u21{
0x018E,
} });
try instance.map.put(0x1D33, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D34, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D35, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D36, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D37, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D38, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D39, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D3A, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D3C, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D3D, .{ .compat = &[_]u21{
0x0222,
} });
try instance.map.put(0x1D3E, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D3F, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D40, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D41, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D42, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D43, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D44, .{ .compat = &[_]u21{
0x0250,
} });
try instance.map.put(0x1D45, .{ .compat = &[_]u21{
0x0251,
} });
try instance.map.put(0x1D46, .{ .compat = &[_]u21{
0x1D02,
} });
try instance.map.put(0x1D47, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D48, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D49, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D4A, .{ .compat = &[_]u21{
0x0259,
} });
try instance.map.put(0x1D4B, .{ .compat = &[_]u21{
0x025B,
} });
try instance.map.put(0x1D4C, .{ .compat = &[_]u21{
0x025C,
} });
try instance.map.put(0x1D4D, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D4F, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D50, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D51, .{ .compat = &[_]u21{
0x014B,
} });
try instance.map.put(0x1D52, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D53, .{ .compat = &[_]u21{
0x0254,
} });
try instance.map.put(0x1D54, .{ .compat = &[_]u21{
0x1D16,
} });
try instance.map.put(0x1D55, .{ .compat = &[_]u21{
0x1D17,
} });
try instance.map.put(0x1D56, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D57, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D58, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D59, .{ .compat = &[_]u21{
0x1D1D,
} });
try instance.map.put(0x1D5A, .{ .compat = &[_]u21{
0x026F,
} });
try instance.map.put(0x1D5B, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D5C, .{ .compat = &[_]u21{
0x1D25,
} });
try instance.map.put(0x1D5D, .{ .compat = &[_]u21{
0x03B2,
} });
try instance.map.put(0x1D5E, .{ .compat = &[_]u21{
0x03B3,
} });
try instance.map.put(0x1D5F, .{ .compat = &[_]u21{
0x03B4,
} });
try instance.map.put(0x1D60, .{ .compat = &[_]u21{
0x03C6,
} });
try instance.map.put(0x1D61, .{ .compat = &[_]u21{
0x03C7,
} });
try instance.map.put(0x1D62, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D63, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D64, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D65, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D66, .{ .compat = &[_]u21{
0x03B2,
} });
try instance.map.put(0x1D67, .{ .compat = &[_]u21{
0x03B3,
} });
try instance.map.put(0x1D68, .{ .compat = &[_]u21{
0x03C1,
} });
try instance.map.put(0x1D69, .{ .compat = &[_]u21{
0x03C6,
} });
try instance.map.put(0x1D6A, .{ .compat = &[_]u21{
0x03C7,
} });
try instance.map.put(0x1D78, .{ .compat = &[_]u21{
0x043D,
} });
try instance.map.put(0x1D9B, .{ .compat = &[_]u21{
0x0252,
} });
try instance.map.put(0x1D9C, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D9D, .{ .compat = &[_]u21{
0x0255,
} });
try instance.map.put(0x1D9E, .{ .compat = &[_]u21{
0x00F0,
} });
try instance.map.put(0x1D9F, .{ .compat = &[_]u21{
0x025C,
} });
try instance.map.put(0x1DA0, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1DA1, .{ .compat = &[_]u21{
0x025F,
} });
try instance.map.put(0x1DA2, .{ .compat = &[_]u21{
0x0261,
} });
try instance.map.put(0x1DA3, .{ .compat = &[_]u21{
0x0265,
} });
try instance.map.put(0x1DA4, .{ .compat = &[_]u21{
0x0268,
} });
try instance.map.put(0x1DA5, .{ .compat = &[_]u21{
0x0269,
} });
try instance.map.put(0x1DA6, .{ .compat = &[_]u21{
0x026A,
} });
try instance.map.put(0x1DA7, .{ .compat = &[_]u21{
0x1D7B,
} });
try instance.map.put(0x1DA8, .{ .compat = &[_]u21{
0x029D,
} });
try instance.map.put(0x1DA9, .{ .compat = &[_]u21{
0x026D,
} });
try instance.map.put(0x1DAA, .{ .compat = &[_]u21{
0x1D85,
} });
try instance.map.put(0x1DAB, .{ .compat = &[_]u21{
0x029F,
} });
try instance.map.put(0x1DAC, .{ .compat = &[_]u21{
0x0271,
} });
try instance.map.put(0x1DAD, .{ .compat = &[_]u21{
0x0270,
} });
try instance.map.put(0x1DAE, .{ .compat = &[_]u21{
0x0272,
} });
try instance.map.put(0x1DAF, .{ .compat = &[_]u21{
0x0273,
} });
try instance.map.put(0x1DB0, .{ .compat = &[_]u21{
0x0274,
} });
try instance.map.put(0x1DB1, .{ .compat = &[_]u21{
0x0275,
} });
try instance.map.put(0x1DB2, .{ .compat = &[_]u21{
0x0278,
} });
try instance.map.put(0x1DB3, .{ .compat = &[_]u21{
0x0282,
} });
try instance.map.put(0x1DB4, .{ .compat = &[_]u21{
0x0283,
} });
try instance.map.put(0x1DB5, .{ .compat = &[_]u21{
0x01AB,
} });
try instance.map.put(0x1DB6, .{ .compat = &[_]u21{
0x0289,
} });
try instance.map.put(0x1DB7, .{ .compat = &[_]u21{
0x028A,
} });
try instance.map.put(0x1DB8, .{ .compat = &[_]u21{
0x1D1C,
} });
try instance.map.put(0x1DB9, .{ .compat = &[_]u21{
0x028B,
} });
try instance.map.put(0x1DBA, .{ .compat = &[_]u21{
0x028C,
} });
try instance.map.put(0x1DBB, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1DBC, .{ .compat = &[_]u21{
0x0290,
} });
try instance.map.put(0x1DBD, .{ .compat = &[_]u21{
0x0291,
} });
try instance.map.put(0x1DBE, .{ .compat = &[_]u21{
0x0292,
} });
try instance.map.put(0x1DBF, .{ .compat = &[_]u21{
0x03B8,
} });
try instance.map.put(0x1E00, .{ .canon = [2]u21{
0x0041,
0x0325,
} });
try instance.map.put(0x1E01, .{ .canon = [2]u21{
0x0061,
0x0325,
} });
try instance.map.put(0x1E02, .{ .canon = [2]u21{
0x0042,
0x0307,
} });
try instance.map.put(0x1E03, .{ .canon = [2]u21{
0x0062,
0x0307,
} });
try instance.map.put(0x1E04, .{ .canon = [2]u21{
0x0042,
0x0323,
} });
try instance.map.put(0x1E05, .{ .canon = [2]u21{
0x0062,
0x0323,
} });
try instance.map.put(0x1E06, .{ .canon = [2]u21{
0x0042,
0x0331,
} });
try instance.map.put(0x1E07, .{ .canon = [2]u21{
0x0062,
0x0331,
} });
try instance.map.put(0x1E08, .{ .canon = [2]u21{
0x00C7,
0x0301,
} });
try instance.map.put(0x1E09, .{ .canon = [2]u21{
0x00E7,
0x0301,
} });
try instance.map.put(0x1E0A, .{ .canon = [2]u21{
0x0044,
0x0307,
} });
try instance.map.put(0x1E0B, .{ .canon = [2]u21{
0x0064,
0x0307,
} });
try instance.map.put(0x1E0C, .{ .canon = [2]u21{
0x0044,
0x0323,
} });
try instance.map.put(0x1E0D, .{ .canon = [2]u21{
0x0064,
0x0323,
} });
try instance.map.put(0x1E0E, .{ .canon = [2]u21{
0x0044,
0x0331,
} });
try instance.map.put(0x1E0F, .{ .canon = [2]u21{
0x0064,
0x0331,
} });
try instance.map.put(0x1E10, .{ .canon = [2]u21{
0x0044,
0x0327,
} });
try instance.map.put(0x1E11, .{ .canon = [2]u21{
0x0064,
0x0327,
} });
try instance.map.put(0x1E12, .{ .canon = [2]u21{
0x0044,
0x032D,
} });
try instance.map.put(0x1E13, .{ .canon = [2]u21{
0x0064,
0x032D,
} });
try instance.map.put(0x1E14, .{ .canon = [2]u21{
0x0112,
0x0300,
} });
try instance.map.put(0x1E15, .{ .canon = [2]u21{
0x0113,
0x0300,
} });
try instance.map.put(0x1E16, .{ .canon = [2]u21{
0x0112,
0x0301,
} });
try instance.map.put(0x1E17, .{ .canon = [2]u21{
0x0113,
0x0301,
} });
try instance.map.put(0x1E18, .{ .canon = [2]u21{
0x0045,
0x032D,
} });
try instance.map.put(0x1E19, .{ .canon = [2]u21{
0x0065,
0x032D,
} });
try instance.map.put(0x1E1A, .{ .canon = [2]u21{
0x0045,
0x0330,
} });
try instance.map.put(0x1E1B, .{ .canon = [2]u21{
0x0065,
0x0330,
} });
try instance.map.put(0x1E1C, .{ .canon = [2]u21{
0x0228,
0x0306,
} });
try instance.map.put(0x1E1D, .{ .canon = [2]u21{
0x0229,
0x0306,
} });
try instance.map.put(0x1E1E, .{ .canon = [2]u21{
0x0046,
0x0307,
} });
try instance.map.put(0x1E1F, .{ .canon = [2]u21{
0x0066,
0x0307,
} });
try instance.map.put(0x1E20, .{ .canon = [2]u21{
0x0047,
0x0304,
} });
try instance.map.put(0x1E21, .{ .canon = [2]u21{
0x0067,
0x0304,
} });
try instance.map.put(0x1E22, .{ .canon = [2]u21{
0x0048,
0x0307,
} });
try instance.map.put(0x1E23, .{ .canon = [2]u21{
0x0068,
0x0307,
} });
try instance.map.put(0x1E24, .{ .canon = [2]u21{
0x0048,
0x0323,
} });
try instance.map.put(0x1E25, .{ .canon = [2]u21{
0x0068,
0x0323,
} });
try instance.map.put(0x1E26, .{ .canon = [2]u21{
0x0048,
0x0308,
} });
try instance.map.put(0x1E27, .{ .canon = [2]u21{
0x0068,
0x0308,
} });
try instance.map.put(0x1E28, .{ .canon = [2]u21{
0x0048,
0x0327,
} });
try instance.map.put(0x1E29, .{ .canon = [2]u21{
0x0068,
0x0327,
} });
try instance.map.put(0x1E2A, .{ .canon = [2]u21{
0x0048,
0x032E,
} });
try instance.map.put(0x1E2B, .{ .canon = [2]u21{
0x0068,
0x032E,
} });
try instance.map.put(0x1E2C, .{ .canon = [2]u21{
0x0049,
0x0330,
} });
try instance.map.put(0x1E2D, .{ .canon = [2]u21{
0x0069,
0x0330,
} });
try instance.map.put(0x1E2E, .{ .canon = [2]u21{
0x00CF,
0x0301,
} });
try instance.map.put(0x1E2F, .{ .canon = [2]u21{
0x00EF,
0x0301,
} });
try instance.map.put(0x1E30, .{ .canon = [2]u21{
0x004B,
0x0301,
} });
try instance.map.put(0x1E31, .{ .canon = [2]u21{
0x006B,
0x0301,
} });
try instance.map.put(0x1E32, .{ .canon = [2]u21{
0x004B,
0x0323,
} });
try instance.map.put(0x1E33, .{ .canon = [2]u21{
0x006B,
0x0323,
} });
try instance.map.put(0x1E34, .{ .canon = [2]u21{
0x004B,
0x0331,
} });
try instance.map.put(0x1E35, .{ .canon = [2]u21{
0x006B,
0x0331,
} });
try instance.map.put(0x1E36, .{ .canon = [2]u21{
0x004C,
0x0323,
} });
try instance.map.put(0x1E37, .{ .canon = [2]u21{
0x006C,
0x0323,
} });
try instance.map.put(0x1E38, .{ .canon = [2]u21{
0x1E36,
0x0304,
} });
try instance.map.put(0x1E39, .{ .canon = [2]u21{
0x1E37,
0x0304,
} });
try instance.map.put(0x1E3A, .{ .canon = [2]u21{
0x004C,
0x0331,
} });
try instance.map.put(0x1E3B, .{ .canon = [2]u21{
0x006C,
0x0331,
} });
try instance.map.put(0x1E3C, .{ .canon = [2]u21{
0x004C,
0x032D,
} });
try instance.map.put(0x1E3D, .{ .canon = [2]u21{
0x006C,
0x032D,
} });
try instance.map.put(0x1E3E, .{ .canon = [2]u21{
0x004D,
0x0301,
} });
try instance.map.put(0x1E3F, .{ .canon = [2]u21{
0x006D,
0x0301,
} });
try instance.map.put(0x1E40, .{ .canon = [2]u21{
0x004D,
0x0307,
} });
try instance.map.put(0x1E41, .{ .canon = [2]u21{
0x006D,
0x0307,
} });
try instance.map.put(0x1E42, .{ .canon = [2]u21{
0x004D,
0x0323,
} });
try instance.map.put(0x1E43, .{ .canon = [2]u21{
0x006D,
0x0323,
} });
try instance.map.put(0x1E44, .{ .canon = [2]u21{
0x004E,
0x0307,
} });
try instance.map.put(0x1E45, .{ .canon = [2]u21{
0x006E,
0x0307,
} });
try instance.map.put(0x1E46, .{ .canon = [2]u21{
0x004E,
0x0323,
} });
try instance.map.put(0x1E47, .{ .canon = [2]u21{
0x006E,
0x0323,
} });
try instance.map.put(0x1E48, .{ .canon = [2]u21{
0x004E,
0x0331,
} });
try instance.map.put(0x1E49, .{ .canon = [2]u21{
0x006E,
0x0331,
} });
try instance.map.put(0x1E4A, .{ .canon = [2]u21{
0x004E,
0x032D,
} });
try instance.map.put(0x1E4B, .{ .canon = [2]u21{
0x006E,
0x032D,
} });
try instance.map.put(0x1E4C, .{ .canon = [2]u21{
0x00D5,
0x0301,
} });
try instance.map.put(0x1E4D, .{ .canon = [2]u21{
0x00F5,
0x0301,
} });
try instance.map.put(0x1E4E, .{ .canon = [2]u21{
0x00D5,
0x0308,
} });
try instance.map.put(0x1E4F, .{ .canon = [2]u21{
0x00F5,
0x0308,
} });
try instance.map.put(0x1E50, .{ .canon = [2]u21{
0x014C,
0x0300,
} });
try instance.map.put(0x1E51, .{ .canon = [2]u21{
0x014D,
0x0300,
} });
try instance.map.put(0x1E52, .{ .canon = [2]u21{
0x014C,
0x0301,
} });
try instance.map.put(0x1E53, .{ .canon = [2]u21{
0x014D,
0x0301,
} });
try instance.map.put(0x1E54, .{ .canon = [2]u21{
0x0050,
0x0301,
} });
try instance.map.put(0x1E55, .{ .canon = [2]u21{
0x0070,
0x0301,
} });
try instance.map.put(0x1E56, .{ .canon = [2]u21{
0x0050,
0x0307,
} });
try instance.map.put(0x1E57, .{ .canon = [2]u21{
0x0070,
0x0307,
} });
try instance.map.put(0x1E58, .{ .canon = [2]u21{
0x0052,
0x0307,
} });
try instance.map.put(0x1E59, .{ .canon = [2]u21{
0x0072,
0x0307,
} });
try instance.map.put(0x1E5A, .{ .canon = [2]u21{
0x0052,
0x0323,
} });
try instance.map.put(0x1E5B, .{ .canon = [2]u21{
0x0072,
0x0323,
} });
try instance.map.put(0x1E5C, .{ .canon = [2]u21{
0x1E5A,
0x0304,
} });
try instance.map.put(0x1E5D, .{ .canon = [2]u21{
0x1E5B,
0x0304,
} });
try instance.map.put(0x1E5E, .{ .canon = [2]u21{
0x0052,
0x0331,
} });
try instance.map.put(0x1E5F, .{ .canon = [2]u21{
0x0072,
0x0331,
} });
try instance.map.put(0x1E60, .{ .canon = [2]u21{
0x0053,
0x0307,
} });
try instance.map.put(0x1E61, .{ .canon = [2]u21{
0x0073,
0x0307,
} });
try instance.map.put(0x1E62, .{ .canon = [2]u21{
0x0053,
0x0323,
} });
try instance.map.put(0x1E63, .{ .canon = [2]u21{
0x0073,
0x0323,
} });
try instance.map.put(0x1E64, .{ .canon = [2]u21{
0x015A,
0x0307,
} });
try instance.map.put(0x1E65, .{ .canon = [2]u21{
0x015B,
0x0307,
} });
try instance.map.put(0x1E66, .{ .canon = [2]u21{
0x0160,
0x0307,
} });
try instance.map.put(0x1E67, .{ .canon = [2]u21{
0x0161,
0x0307,
} });
try instance.map.put(0x1E68, .{ .canon = [2]u21{
0x1E62,
0x0307,
} });
try instance.map.put(0x1E69, .{ .canon = [2]u21{
0x1E63,
0x0307,
} });
try instance.map.put(0x1E6A, .{ .canon = [2]u21{
0x0054,
0x0307,
} });
try instance.map.put(0x1E6B, .{ .canon = [2]u21{
0x0074,
0x0307,
} });
try instance.map.put(0x1E6C, .{ .canon = [2]u21{
0x0054,
0x0323,
} });
try instance.map.put(0x1E6D, .{ .canon = [2]u21{
0x0074,
0x0323,
} });
try instance.map.put(0x1E6E, .{ .canon = [2]u21{
0x0054,
0x0331,
} });
try instance.map.put(0x1E6F, .{ .canon = [2]u21{
0x0074,
0x0331,
} });
try instance.map.put(0x1E70, .{ .canon = [2]u21{
0x0054,
0x032D,
} });
try instance.map.put(0x1E71, .{ .canon = [2]u21{
0x0074,
0x032D,
} });
try instance.map.put(0x1E72, .{ .canon = [2]u21{
0x0055,
0x0324,
} });
try instance.map.put(0x1E73, .{ .canon = [2]u21{
0x0075,
0x0324,
} });
try instance.map.put(0x1E74, .{ .canon = [2]u21{
0x0055,
0x0330,
} });
try instance.map.put(0x1E75, .{ .canon = [2]u21{
0x0075,
0x0330,
} });
try instance.map.put(0x1E76, .{ .canon = [2]u21{
0x0055,
0x032D,
} });
try instance.map.put(0x1E77, .{ .canon = [2]u21{
0x0075,
0x032D,
} });
try instance.map.put(0x1E78, .{ .canon = [2]u21{
0x0168,
0x0301,
} });
try instance.map.put(0x1E79, .{ .canon = [2]u21{
0x0169,
0x0301,
} });
try instance.map.put(0x1E7A, .{ .canon = [2]u21{
0x016A,
0x0308,
} });
try instance.map.put(0x1E7B, .{ .canon = [2]u21{
0x016B,
0x0308,
} });
try instance.map.put(0x1E7C, .{ .canon = [2]u21{
0x0056,
0x0303,
} });
try instance.map.put(0x1E7D, .{ .canon = [2]u21{
0x0076,
0x0303,
} });
try instance.map.put(0x1E7E, .{ .canon = [2]u21{
0x0056,
0x0323,
} });
try instance.map.put(0x1E7F, .{ .canon = [2]u21{
0x0076,
0x0323,
} });
try instance.map.put(0x1E80, .{ .canon = [2]u21{
0x0057,
0x0300,
} });
try instance.map.put(0x1E81, .{ .canon = [2]u21{
0x0077,
0x0300,
} });
try instance.map.put(0x1E82, .{ .canon = [2]u21{
0x0057,
0x0301,
} });
try instance.map.put(0x1E83, .{ .canon = [2]u21{
0x0077,
0x0301,
} });
try instance.map.put(0x1E84, .{ .canon = [2]u21{
0x0057,
0x0308,
} });
try instance.map.put(0x1E85, .{ .canon = [2]u21{
0x0077,
0x0308,
} });
try instance.map.put(0x1E86, .{ .canon = [2]u21{
0x0057,
0x0307,
} });
try instance.map.put(0x1E87, .{ .canon = [2]u21{
0x0077,
0x0307,
} });
try instance.map.put(0x1E88, .{ .canon = [2]u21{
0x0057,
0x0323,
} });
try instance.map.put(0x1E89, .{ .canon = [2]u21{
0x0077,
0x0323,
} });
try instance.map.put(0x1E8A, .{ .canon = [2]u21{
0x0058,
0x0307,
} });
try instance.map.put(0x1E8B, .{ .canon = [2]u21{
0x0078,
0x0307,
} });
try instance.map.put(0x1E8C, .{ .canon = [2]u21{
0x0058,
0x0308,
} });
try instance.map.put(0x1E8D, .{ .canon = [2]u21{
0x0078,
0x0308,
} });
try instance.map.put(0x1E8E, .{ .canon = [2]u21{
0x0059,
0x0307,
} });
try instance.map.put(0x1E8F, .{ .canon = [2]u21{
0x0079,
0x0307,
} });
try instance.map.put(0x1E90, .{ .canon = [2]u21{
0x005A,
0x0302,
} });
try instance.map.put(0x1E91, .{ .canon = [2]u21{
0x007A,
0x0302,
} });
try instance.map.put(0x1E92, .{ .canon = [2]u21{
0x005A,
0x0323,
} });
try instance.map.put(0x1E93, .{ .canon = [2]u21{
0x007A,
0x0323,
} });
try instance.map.put(0x1E94, .{ .canon = [2]u21{
0x005A,
0x0331,
} });
try instance.map.put(0x1E95, .{ .canon = [2]u21{
0x007A,
0x0331,
} });
try instance.map.put(0x1E96, .{ .canon = [2]u21{
0x0068,
0x0331,
} });
try instance.map.put(0x1E97, .{ .canon = [2]u21{
0x0074,
0x0308,
} });
try instance.map.put(0x1E98, .{ .canon = [2]u21{
0x0077,
0x030A,
} });
try instance.map.put(0x1E99, .{ .canon = [2]u21{
0x0079,
0x030A,
} });
try instance.map.put(0x1E9A, .{ .compat = &[_]u21{
0x0061,
0x02BE,
} });
try instance.map.put(0x1E9B, .{ .canon = [2]u21{
0x017F,
0x0307,
} });
try instance.map.put(0x1EA0, .{ .canon = [2]u21{
0x0041,
0x0323,
} });
try instance.map.put(0x1EA1, .{ .canon = [2]u21{
0x0061,
0x0323,
} });
try instance.map.put(0x1EA2, .{ .canon = [2]u21{
0x0041,
0x0309,
} });
try instance.map.put(0x1EA3, .{ .canon = [2]u21{
0x0061,
0x0309,
} });
try instance.map.put(0x1EA4, .{ .canon = [2]u21{
0x00C2,
0x0301,
} });
try instance.map.put(0x1EA5, .{ .canon = [2]u21{
0x00E2,
0x0301,
} });
try instance.map.put(0x1EA6, .{ .canon = [2]u21{
0x00C2,
0x0300,
} });
try instance.map.put(0x1EA7, .{ .canon = [2]u21{
0x00E2,
0x0300,
} });
try instance.map.put(0x1EA8, .{ .canon = [2]u21{
0x00C2,
0x0309,
} });
try instance.map.put(0x1EA9, .{ .canon = [2]u21{
0x00E2,
0x0309,
} });
try instance.map.put(0x1EAA, .{ .canon = [2]u21{
0x00C2,
0x0303,
} });
try instance.map.put(0x1EAB, .{ .canon = [2]u21{
0x00E2,
0x0303,
} });
try instance.map.put(0x1EAC, .{ .canon = [2]u21{
0x1EA0,
0x0302,
} });
try instance.map.put(0x1EAD, .{ .canon = [2]u21{
0x1EA1,
0x0302,
} });
try instance.map.put(0x1EAE, .{ .canon = [2]u21{
0x0102,
0x0301,
} });
try instance.map.put(0x1EAF, .{ .canon = [2]u21{
0x0103,
0x0301,
} });
try instance.map.put(0x1EB0, .{ .canon = [2]u21{
0x0102,
0x0300,
} });
try instance.map.put(0x1EB1, .{ .canon = [2]u21{
0x0103,
0x0300,
} });
try instance.map.put(0x1EB2, .{ .canon = [2]u21{
0x0102,
0x0309,
} });
try instance.map.put(0x1EB3, .{ .canon = [2]u21{
0x0103,
0x0309,
} });
try instance.map.put(0x1EB4, .{ .canon = [2]u21{
0x0102,
0x0303,
} });
try instance.map.put(0x1EB5, .{ .canon = [2]u21{
0x0103,
0x0303,
} });
try instance.map.put(0x1EB6, .{ .canon = [2]u21{
0x1EA0,
0x0306,
} });
try instance.map.put(0x1EB7, .{ .canon = [2]u21{
0x1EA1,
0x0306,
} });
try instance.map.put(0x1EB8, .{ .canon = [2]u21{
0x0045,
0x0323,
} });
try instance.map.put(0x1EB9, .{ .canon = [2]u21{
0x0065,
0x0323,
} });
try instance.map.put(0x1EBA, .{ .canon = [2]u21{
0x0045,
0x0309,
} });
try instance.map.put(0x1EBB, .{ .canon = [2]u21{
0x0065,
0x0309,
} });
try instance.map.put(0x1EBC, .{ .canon = [2]u21{
0x0045,
0x0303,
} });
try instance.map.put(0x1EBD, .{ .canon = [2]u21{
0x0065,
0x0303,
} });
try instance.map.put(0x1EBE, .{ .canon = [2]u21{
0x00CA,
0x0301,
} });
try instance.map.put(0x1EBF, .{ .canon = [2]u21{
0x00EA,
0x0301,
} });
try instance.map.put(0x1EC0, .{ .canon = [2]u21{
0x00CA,
0x0300,
} });
try instance.map.put(0x1EC1, .{ .canon = [2]u21{
0x00EA,
0x0300,
} });
try instance.map.put(0x1EC2, .{ .canon = [2]u21{
0x00CA,
0x0309,
} });
try instance.map.put(0x1EC3, .{ .canon = [2]u21{
0x00EA,
0x0309,
} });
try instance.map.put(0x1EC4, .{ .canon = [2]u21{
0x00CA,
0x0303,
} });
try instance.map.put(0x1EC5, .{ .canon = [2]u21{
0x00EA,
0x0303,
} });
try instance.map.put(0x1EC6, .{ .canon = [2]u21{
0x1EB8,
0x0302,
} });
try instance.map.put(0x1EC7, .{ .canon = [2]u21{
0x1EB9,
0x0302,
} });
try instance.map.put(0x1EC8, .{ .canon = [2]u21{
0x0049,
0x0309,
} });
try instance.map.put(0x1EC9, .{ .canon = [2]u21{
0x0069,
0x0309,
} });
try instance.map.put(0x1ECA, .{ .canon = [2]u21{
0x0049,
0x0323,
} });
try instance.map.put(0x1ECB, .{ .canon = [2]u21{
0x0069,
0x0323,
} });
try instance.map.put(0x1ECC, .{ .canon = [2]u21{
0x004F,
0x0323,
} });
try instance.map.put(0x1ECD, .{ .canon = [2]u21{
0x006F,
0x0323,
} });
try instance.map.put(0x1ECE, .{ .canon = [2]u21{
0x004F,
0x0309,
} });
try instance.map.put(0x1ECF, .{ .canon = [2]u21{
0x006F,
0x0309,
} });
try instance.map.put(0x1ED0, .{ .canon = [2]u21{
0x00D4,
0x0301,
} });
try instance.map.put(0x1ED1, .{ .canon = [2]u21{
0x00F4,
0x0301,
} });
try instance.map.put(0x1ED2, .{ .canon = [2]u21{
0x00D4,
0x0300,
} });
try instance.map.put(0x1ED3, .{ .canon = [2]u21{
0x00F4,
0x0300,
} });
try instance.map.put(0x1ED4, .{ .canon = [2]u21{
0x00D4,
0x0309,
} });
try instance.map.put(0x1ED5, .{ .canon = [2]u21{
0x00F4,
0x0309,
} });
try instance.map.put(0x1ED6, .{ .canon = [2]u21{
0x00D4,
0x0303,
} });
try instance.map.put(0x1ED7, .{ .canon = [2]u21{
0x00F4,
0x0303,
} });
try instance.map.put(0x1ED8, .{ .canon = [2]u21{
0x1ECC,
0x0302,
} });
try instance.map.put(0x1ED9, .{ .canon = [2]u21{
0x1ECD,
0x0302,
} });
try instance.map.put(0x1EDA, .{ .canon = [2]u21{
0x01A0,
0x0301,
} });
try instance.map.put(0x1EDB, .{ .canon = [2]u21{
0x01A1,
0x0301,
} });
try instance.map.put(0x1EDC, .{ .canon = [2]u21{
0x01A0,
0x0300,
} });
try instance.map.put(0x1EDD, .{ .canon = [2]u21{
0x01A1,
0x0300,
} });
try instance.map.put(0x1EDE, .{ .canon = [2]u21{
0x01A0,
0x0309,
} });
try instance.map.put(0x1EDF, .{ .canon = [2]u21{
0x01A1,
0x0309,
} });
try instance.map.put(0x1EE0, .{ .canon = [2]u21{
0x01A0,
0x0303,
} });
try instance.map.put(0x1EE1, .{ .canon = [2]u21{
0x01A1,
0x0303,
} });
try instance.map.put(0x1EE2, .{ .canon = [2]u21{
0x01A0,
0x0323,
} });
try instance.map.put(0x1EE3, .{ .canon = [2]u21{
0x01A1,
0x0323,
} });
try instance.map.put(0x1EE4, .{ .canon = [2]u21{
0x0055,
0x0323,
} });
try instance.map.put(0x1EE5, .{ .canon = [2]u21{
0x0075,
0x0323,
} });
try instance.map.put(0x1EE6, .{ .canon = [2]u21{
0x0055,
0x0309,
} });
try instance.map.put(0x1EE7, .{ .canon = [2]u21{
0x0075,
0x0309,
} });
try instance.map.put(0x1EE8, .{ .canon = [2]u21{
0x01AF,
0x0301,
} });
try instance.map.put(0x1EE9, .{ .canon = [2]u21{
0x01B0,
0x0301,
} });
try instance.map.put(0x1EEA, .{ .canon = [2]u21{
0x01AF,
0x0300,
} });
try instance.map.put(0x1EEB, .{ .canon = [2]u21{
0x01B0,
0x0300,
} });
try instance.map.put(0x1EEC, .{ .canon = [2]u21{
0x01AF,
0x0309,
} });
try instance.map.put(0x1EED, .{ .canon = [2]u21{
0x01B0,
0x0309,
} });
try instance.map.put(0x1EEE, .{ .canon = [2]u21{
0x01AF,
0x0303,
} });
try instance.map.put(0x1EEF, .{ .canon = [2]u21{
0x01B0,
0x0303,
} });
try instance.map.put(0x1EF0, .{ .canon = [2]u21{
0x01AF,
0x0323,
} });
try instance.map.put(0x1EF1, .{ .canon = [2]u21{
0x01B0,
0x0323,
} });
try instance.map.put(0x1EF2, .{ .canon = [2]u21{
0x0059,
0x0300,
} });
try instance.map.put(0x1EF3, .{ .canon = [2]u21{
0x0079,
0x0300,
} });
try instance.map.put(0x1EF4, .{ .canon = [2]u21{
0x0059,
0x0323,
} });
try instance.map.put(0x1EF5, .{ .canon = [2]u21{
0x0079,
0x0323,
} });
try instance.map.put(0x1EF6, .{ .canon = [2]u21{
0x0059,
0x0309,
} });
try instance.map.put(0x1EF7, .{ .canon = [2]u21{
0x0079,
0x0309,
} });
try instance.map.put(0x1EF8, .{ .canon = [2]u21{
0x0059,
0x0303,
} });
try instance.map.put(0x1EF9, .{ .canon = [2]u21{
0x0079,
0x0303,
} });
try instance.map.put(0x1F00, .{ .canon = [2]u21{
0x03B1,
0x0313,
} });
try instance.map.put(0x1F01, .{ .canon = [2]u21{
0x03B1,
0x0314,
} });
try instance.map.put(0x1F02, .{ .canon = [2]u21{
0x1F00,
0x0300,
} });
try instance.map.put(0x1F03, .{ .canon = [2]u21{
0x1F01,
0x0300,
} });
try instance.map.put(0x1F04, .{ .canon = [2]u21{
0x1F00,
0x0301,
} });
try instance.map.put(0x1F05, .{ .canon = [2]u21{
0x1F01,
0x0301,
} });
try instance.map.put(0x1F06, .{ .canon = [2]u21{
0x1F00,
0x0342,
} });
try instance.map.put(0x1F07, .{ .canon = [2]u21{
0x1F01,
0x0342,
} });
try instance.map.put(0x1F08, .{ .canon = [2]u21{
0x0391,
0x0313,
} });
try instance.map.put(0x1F09, .{ .canon = [2]u21{
0x0391,
0x0314,
} });
try instance.map.put(0x1F0A, .{ .canon = [2]u21{
0x1F08,
0x0300,
} });
try instance.map.put(0x1F0B, .{ .canon = [2]u21{
0x1F09,
0x0300,
} });
try instance.map.put(0x1F0C, .{ .canon = [2]u21{
0x1F08,
0x0301,
} });
try instance.map.put(0x1F0D, .{ .canon = [2]u21{
0x1F09,
0x0301,
} });
try instance.map.put(0x1F0E, .{ .canon = [2]u21{
0x1F08,
0x0342,
} });
try instance.map.put(0x1F0F, .{ .canon = [2]u21{
0x1F09,
0x0342,
} });
try instance.map.put(0x1F10, .{ .canon = [2]u21{
0x03B5,
0x0313,
} });
try instance.map.put(0x1F11, .{ .canon = [2]u21{
0x03B5,
0x0314,
} });
try instance.map.put(0x1F12, .{ .canon = [2]u21{
0x1F10,
0x0300,
} });
try instance.map.put(0x1F13, .{ .canon = [2]u21{
0x1F11,
0x0300,
} });
try instance.map.put(0x1F14, .{ .canon = [2]u21{
0x1F10,
0x0301,
} });
try instance.map.put(0x1F15, .{ .canon = [2]u21{
0x1F11,
0x0301,
} });
try instance.map.put(0x1F18, .{ .canon = [2]u21{
0x0395,
0x0313,
} });
try instance.map.put(0x1F19, .{ .canon = [2]u21{
0x0395,
0x0314,
} });
try instance.map.put(0x1F1A, .{ .canon = [2]u21{
0x1F18,
0x0300,
} });
try instance.map.put(0x1F1B, .{ .canon = [2]u21{
0x1F19,
0x0300,
} });
try instance.map.put(0x1F1C, .{ .canon = [2]u21{
0x1F18,
0x0301,
} });
try instance.map.put(0x1F1D, .{ .canon = [2]u21{
0x1F19,
0x0301,
} });
try instance.map.put(0x1F20, .{ .canon = [2]u21{
0x03B7,
0x0313,
} });
try instance.map.put(0x1F21, .{ .canon = [2]u21{
0x03B7,
0x0314,
} });
try instance.map.put(0x1F22, .{ .canon = [2]u21{
0x1F20,
0x0300,
} });
try instance.map.put(0x1F23, .{ .canon = [2]u21{
0x1F21,
0x0300,
} });
try instance.map.put(0x1F24, .{ .canon = [2]u21{
0x1F20,
0x0301,
} });
try instance.map.put(0x1F25, .{ .canon = [2]u21{
0x1F21,
0x0301,
} });
try instance.map.put(0x1F26, .{ .canon = [2]u21{
0x1F20,
0x0342,
} });
try instance.map.put(0x1F27, .{ .canon = [2]u21{
0x1F21,
0x0342,
} });
try instance.map.put(0x1F28, .{ .canon = [2]u21{
0x0397,
0x0313,
} });
try instance.map.put(0x1F29, .{ .canon = [2]u21{
0x0397,
0x0314,
} });
try instance.map.put(0x1F2A, .{ .canon = [2]u21{
0x1F28,
0x0300,
} });
try instance.map.put(0x1F2B, .{ .canon = [2]u21{
0x1F29,
0x0300,
} });
try instance.map.put(0x1F2C, .{ .canon = [2]u21{
0x1F28,
0x0301,
} });
try instance.map.put(0x1F2D, .{ .canon = [2]u21{
0x1F29,
0x0301,
} });
try instance.map.put(0x1F2E, .{ .canon = [2]u21{
0x1F28,
0x0342,
} });
try instance.map.put(0x1F2F, .{ .canon = [2]u21{
0x1F29,
0x0342,
} });
try instance.map.put(0x1F30, .{ .canon = [2]u21{
0x03B9,
0x0313,
} });
try instance.map.put(0x1F31, .{ .canon = [2]u21{
0x03B9,
0x0314,
} });
try instance.map.put(0x1F32, .{ .canon = [2]u21{
0x1F30,
0x0300,
} });
try instance.map.put(0x1F33, .{ .canon = [2]u21{
0x1F31,
0x0300,
} });
try instance.map.put(0x1F34, .{ .canon = [2]u21{
0x1F30,
0x0301,
} });
try instance.map.put(0x1F35, .{ .canon = [2]u21{
0x1F31,
0x0301,
} });
try instance.map.put(0x1F36, .{ .canon = [2]u21{
0x1F30,
0x0342,
} });
try instance.map.put(0x1F37, .{ .canon = [2]u21{
0x1F31,
0x0342,
} });
try instance.map.put(0x1F38, .{ .canon = [2]u21{
0x0399,
0x0313,
} });
try instance.map.put(0x1F39, .{ .canon = [2]u21{
0x0399,
0x0314,
} });
try instance.map.put(0x1F3A, .{ .canon = [2]u21{
0x1F38,
0x0300,
} });
try instance.map.put(0x1F3B, .{ .canon = [2]u21{
0x1F39,
0x0300,
} });
try instance.map.put(0x1F3C, .{ .canon = [2]u21{
0x1F38,
0x0301,
} });
try instance.map.put(0x1F3D, .{ .canon = [2]u21{
0x1F39,
0x0301,
} });
try instance.map.put(0x1F3E, .{ .canon = [2]u21{
0x1F38,
0x0342,
} });
try instance.map.put(0x1F3F, .{ .canon = [2]u21{
0x1F39,
0x0342,
} });
try instance.map.put(0x1F40, .{ .canon = [2]u21{
0x03BF,
0x0313,
} });
try instance.map.put(0x1F41, .{ .canon = [2]u21{
0x03BF,
0x0314,
} });
try instance.map.put(0x1F42, .{ .canon = [2]u21{
0x1F40,
0x0300,
} });
try instance.map.put(0x1F43, .{ .canon = [2]u21{
0x1F41,
0x0300,
} });
try instance.map.put(0x1F44, .{ .canon = [2]u21{
0x1F40,
0x0301,
} });
try instance.map.put(0x1F45, .{ .canon = [2]u21{
0x1F41,
0x0301,
} });
try instance.map.put(0x1F48, .{ .canon = [2]u21{
0x039F,
0x0313,
} });
try instance.map.put(0x1F49, .{ .canon = [2]u21{
0x039F,
0x0314,
} });
try instance.map.put(0x1F4A, .{ .canon = [2]u21{
0x1F48,
0x0300,
} });
try instance.map.put(0x1F4B, .{ .canon = [2]u21{
0x1F49,
0x0300,
} });
try instance.map.put(0x1F4C, .{ .canon = [2]u21{
0x1F48,
0x0301,
} });
try instance.map.put(0x1F4D, .{ .canon = [2]u21{
0x1F49,
0x0301,
} });
try instance.map.put(0x1F50, .{ .canon = [2]u21{
0x03C5,
0x0313,
} });
try instance.map.put(0x1F51, .{ .canon = [2]u21{
0x03C5,
0x0314,
} });
try instance.map.put(0x1F52, .{ .canon = [2]u21{
0x1F50,
0x0300,
} });
try instance.map.put(0x1F53, .{ .canon = [2]u21{
0x1F51,
0x0300,
} });
try instance.map.put(0x1F54, .{ .canon = [2]u21{
0x1F50,
0x0301,
} });
try instance.map.put(0x1F55, .{ .canon = [2]u21{
0x1F51,
0x0301,
} });
try instance.map.put(0x1F56, .{ .canon = [2]u21{
0x1F50,
0x0342,
} });
try instance.map.put(0x1F57, .{ .canon = [2]u21{
0x1F51,
0x0342,
} });
try instance.map.put(0x1F59, .{ .canon = [2]u21{
0x03A5,
0x0314,
} });
try instance.map.put(0x1F5B, .{ .canon = [2]u21{
0x1F59,
0x0300,
} });
try instance.map.put(0x1F5D, .{ .canon = [2]u21{
0x1F59,
0x0301,
} });
try instance.map.put(0x1F5F, .{ .canon = [2]u21{
0x1F59,
0x0342,
} });
try instance.map.put(0x1F60, .{ .canon = [2]u21{
0x03C9,
0x0313,
} });
try instance.map.put(0x1F61, .{ .canon = [2]u21{
0x03C9,
0x0314,
} });
try instance.map.put(0x1F62, .{ .canon = [2]u21{
0x1F60,
0x0300,
} });
try instance.map.put(0x1F63, .{ .canon = [2]u21{
0x1F61,
0x0300,
} });
try instance.map.put(0x1F64, .{ .canon = [2]u21{
0x1F60,
0x0301,
} });
try instance.map.put(0x1F65, .{ .canon = [2]u21{
0x1F61,
0x0301,
} });
try instance.map.put(0x1F66, .{ .canon = [2]u21{
0x1F60,
0x0342,
} });
try instance.map.put(0x1F67, .{ .canon = [2]u21{
0x1F61,
0x0342,
} });
try instance.map.put(0x1F68, .{ .canon = [2]u21{
0x03A9,
0x0313,
} });
try instance.map.put(0x1F69, .{ .canon = [2]u21{
0x03A9,
0x0314,
} });
try instance.map.put(0x1F6A, .{ .canon = [2]u21{
0x1F68,
0x0300,
} });
try instance.map.put(0x1F6B, .{ .canon = [2]u21{
0x1F69,
0x0300,
} });
try instance.map.put(0x1F6C, .{ .canon = [2]u21{
0x1F68,
0x0301,
} });
try instance.map.put(0x1F6D, .{ .canon = [2]u21{
0x1F69,
0x0301,
} });
try instance.map.put(0x1F6E, .{ .canon = [2]u21{
0x1F68,
0x0342,
} });
try instance.map.put(0x1F6F, .{ .canon = [2]u21{
0x1F69,
0x0342,
} });
try instance.map.put(0x1F70, .{ .canon = [2]u21{
0x03B1,
0x0300,
} });
try instance.map.put(0x1F71, .{ .single = 0x03AC });
try instance.map.put(0x1F72, .{ .canon = [2]u21{
0x03B5,
0x0300,
} });
try instance.map.put(0x1F73, .{ .single = 0x03AD });
try instance.map.put(0x1F74, .{ .canon = [2]u21{
0x03B7,
0x0300,
} });
try instance.map.put(0x1F75, .{ .single = 0x03AE });
try instance.map.put(0x1F76, .{ .canon = [2]u21{
0x03B9,
0x0300,
} });
try instance.map.put(0x1F77, .{ .single = 0x03AF });
try instance.map.put(0x1F78, .{ .canon = [2]u21{
0x03BF,
0x0300,
} });
try instance.map.put(0x1F79, .{ .single = 0x03CC });
try instance.map.put(0x1F7A, .{ .canon = [2]u21{
0x03C5,
0x0300,
} });
try instance.map.put(0x1F7B, .{ .single = 0x03CD });
try instance.map.put(0x1F7C, .{ .canon = [2]u21{
0x03C9,
0x0300,
} });
try instance.map.put(0x1F7D, .{ .single = 0x03CE });
try instance.map.put(0x1F80, .{ .canon = [2]u21{
0x1F00,
0x0345,
} });
try instance.map.put(0x1F81, .{ .canon = [2]u21{
0x1F01,
0x0345,
} });
try instance.map.put(0x1F82, .{ .canon = [2]u21{
0x1F02,
0x0345,
} });
try instance.map.put(0x1F83, .{ .canon = [2]u21{
0x1F03,
0x0345,
} });
try instance.map.put(0x1F84, .{ .canon = [2]u21{
0x1F04,
0x0345,
} });
try instance.map.put(0x1F85, .{ .canon = [2]u21{
0x1F05,
0x0345,
} });
try instance.map.put(0x1F86, .{ .canon = [2]u21{
0x1F06,
0x0345,
} });
try instance.map.put(0x1F87, .{ .canon = [2]u21{
0x1F07,
0x0345,
} });
try instance.map.put(0x1F88, .{ .canon = [2]u21{
0x1F08,
0x0345,
} });
try instance.map.put(0x1F89, .{ .canon = [2]u21{
0x1F09,
0x0345,
} });
try instance.map.put(0x1F8A, .{ .canon = [2]u21{
0x1F0A,
0x0345,
} });
try instance.map.put(0x1F8B, .{ .canon = [2]u21{
0x1F0B,
0x0345,
} });
try instance.map.put(0x1F8C, .{ .canon = [2]u21{
0x1F0C,
0x0345,
} });
try instance.map.put(0x1F8D, .{ .canon = [2]u21{
0x1F0D,
0x0345,
} });
try instance.map.put(0x1F8E, .{ .canon = [2]u21{
0x1F0E,
0x0345,
} });
try instance.map.put(0x1F8F, .{ .canon = [2]u21{
0x1F0F,
0x0345,
} });
try instance.map.put(0x1F90, .{ .canon = [2]u21{
0x1F20,
0x0345,
} });
try instance.map.put(0x1F91, .{ .canon = [2]u21{
0x1F21,
0x0345,
} });
try instance.map.put(0x1F92, .{ .canon = [2]u21{
0x1F22,
0x0345,
} });
try instance.map.put(0x1F93, .{ .canon = [2]u21{
0x1F23,
0x0345,
} });
try instance.map.put(0x1F94, .{ .canon = [2]u21{
0x1F24,
0x0345,
} });
try instance.map.put(0x1F95, .{ .canon = [2]u21{
0x1F25,
0x0345,
} });
try instance.map.put(0x1F96, .{ .canon = [2]u21{
0x1F26,
0x0345,
} });
try instance.map.put(0x1F97, .{ .canon = [2]u21{
0x1F27,
0x0345,
} });
try instance.map.put(0x1F98, .{ .canon = [2]u21{
0x1F28,
0x0345,
} });
try instance.map.put(0x1F99, .{ .canon = [2]u21{
0x1F29,
0x0345,
} });
try instance.map.put(0x1F9A, .{ .canon = [2]u21{
0x1F2A,
0x0345,
} });
try instance.map.put(0x1F9B, .{ .canon = [2]u21{
0x1F2B,
0x0345,
} });
try instance.map.put(0x1F9C, .{ .canon = [2]u21{
0x1F2C,
0x0345,
} });
try instance.map.put(0x1F9D, .{ .canon = [2]u21{
0x1F2D,
0x0345,
} });
try instance.map.put(0x1F9E, .{ .canon = [2]u21{
0x1F2E,
0x0345,
} });
try instance.map.put(0x1F9F, .{ .canon = [2]u21{
0x1F2F,
0x0345,
} });
try instance.map.put(0x1FA0, .{ .canon = [2]u21{
0x1F60,
0x0345,
} });
try instance.map.put(0x1FA1, .{ .canon = [2]u21{
0x1F61,
0x0345,
} });
try instance.map.put(0x1FA2, .{ .canon = [2]u21{
0x1F62,
0x0345,
} });
try instance.map.put(0x1FA3, .{ .canon = [2]u21{
0x1F63,
0x0345,
} });
try instance.map.put(0x1FA4, .{ .canon = [2]u21{
0x1F64,
0x0345,
} });
try instance.map.put(0x1FA5, .{ .canon = [2]u21{
0x1F65,
0x0345,
} });
try instance.map.put(0x1FA6, .{ .canon = [2]u21{
0x1F66,
0x0345,
} });
try instance.map.put(0x1FA7, .{ .canon = [2]u21{
0x1F67,
0x0345,
} });
try instance.map.put(0x1FA8, .{ .canon = [2]u21{
0x1F68,
0x0345,
} });
try instance.map.put(0x1FA9, .{ .canon = [2]u21{
0x1F69,
0x0345,
} });
try instance.map.put(0x1FAA, .{ .canon = [2]u21{
0x1F6A,
0x0345,
} });
try instance.map.put(0x1FAB, .{ .canon = [2]u21{
0x1F6B,
0x0345,
} });
try instance.map.put(0x1FAC, .{ .canon = [2]u21{
0x1F6C,
0x0345,
} });
try instance.map.put(0x1FAD, .{ .canon = [2]u21{
0x1F6D,
0x0345,
} });
try instance.map.put(0x1FAE, .{ .canon = [2]u21{
0x1F6E,
0x0345,
} });
try instance.map.put(0x1FAF, .{ .canon = [2]u21{
0x1F6F,
0x0345,
} });
try instance.map.put(0x1FB0, .{ .canon = [2]u21{
0x03B1,
0x0306,
} });
try instance.map.put(0x1FB1, .{ .canon = [2]u21{
0x03B1,
0x0304,
} });
try instance.map.put(0x1FB2, .{ .canon = [2]u21{
0x1F70,
0x0345,
} });
try instance.map.put(0x1FB3, .{ .canon = [2]u21{
0x03B1,
0x0345,
} });
try instance.map.put(0x1FB4, .{ .canon = [2]u21{
0x03AC,
0x0345,
} });
try instance.map.put(0x1FB6, .{ .canon = [2]u21{
0x03B1,
0x0342,
} });
try instance.map.put(0x1FB7, .{ .canon = [2]u21{
0x1FB6,
0x0345,
} });
try instance.map.put(0x1FB8, .{ .canon = [2]u21{
0x0391,
0x0306,
} });
try instance.map.put(0x1FB9, .{ .canon = [2]u21{
0x0391,
0x0304,
} });
try instance.map.put(0x1FBA, .{ .canon = [2]u21{
0x0391,
0x0300,
} });
try instance.map.put(0x1FBB, .{ .single = 0x0386 });
try instance.map.put(0x1FBC, .{ .canon = [2]u21{
0x0391,
0x0345,
} });
try instance.map.put(0x1FBD, .{ .compat = &[_]u21{
0x0020,
0x0313,
} });
try instance.map.put(0x1FBE, .{ .single = 0x03B9 });
try instance.map.put(0x1FBF, .{ .compat = &[_]u21{
0x0020,
0x0313,
} });
try instance.map.put(0x1FC0, .{ .compat = &[_]u21{
0x0020,
0x0342,
} });
try instance.map.put(0x1FC1, .{ .canon = [2]u21{
0x00A8,
0x0342,
} });
try instance.map.put(0x1FC2, .{ .canon = [2]u21{
0x1F74,
0x0345,
} });
try instance.map.put(0x1FC3, .{ .canon = [2]u21{
0x03B7,
0x0345,
} });
try instance.map.put(0x1FC4, .{ .canon = [2]u21{
0x03AE,
0x0345,
} });
try instance.map.put(0x1FC6, .{ .canon = [2]u21{
0x03B7,
0x0342,
} });
try instance.map.put(0x1FC7, .{ .canon = [2]u21{
0x1FC6,
0x0345,
} });
try instance.map.put(0x1FC8, .{ .canon = [2]u21{
0x0395,
0x0300,
} });
try instance.map.put(0x1FC9, .{ .single = 0x0388 });
try instance.map.put(0x1FCA, .{ .canon = [2]u21{
0x0397,
0x0300,
} });
try instance.map.put(0x1FCB, .{ .single = 0x0389 });
try instance.map.put(0x1FCC, .{ .canon = [2]u21{
0x0397,
0x0345,
} });
try instance.map.put(0x1FCD, .{ .canon = [2]u21{
0x1FBF,
0x0300,
} });
try instance.map.put(0x1FCE, .{ .canon = [2]u21{
0x1FBF,
0x0301,
} });
try instance.map.put(0x1FCF, .{ .canon = [2]u21{
0x1FBF,
0x0342,
} });
try instance.map.put(0x1FD0, .{ .canon = [2]u21{
0x03B9,
0x0306,
} });
try instance.map.put(0x1FD1, .{ .canon = [2]u21{
0x03B9,
0x0304,
} });
try instance.map.put(0x1FD2, .{ .canon = [2]u21{
0x03CA,
0x0300,
} });
try instance.map.put(0x1FD3, .{ .single = 0x0390 });
try instance.map.put(0x1FD6, .{ .canon = [2]u21{
0x03B9,
0x0342,
} });
try instance.map.put(0x1FD7, .{ .canon = [2]u21{
0x03CA,
0x0342,
} });
try instance.map.put(0x1FD8, .{ .canon = [2]u21{
0x0399,
0x0306,
} });
try instance.map.put(0x1FD9, .{ .canon = [2]u21{
0x0399,
0x0304,
} });
try instance.map.put(0x1FDA, .{ .canon = [2]u21{
0x0399,
0x0300,
} });
try instance.map.put(0x1FDB, .{ .single = 0x038A });
try instance.map.put(0x1FDD, .{ .canon = [2]u21{
0x1FFE,
0x0300,
} });
try instance.map.put(0x1FDE, .{ .canon = [2]u21{
0x1FFE,
0x0301,
} });
try instance.map.put(0x1FDF, .{ .canon = [2]u21{
0x1FFE,
0x0342,
} });
try instance.map.put(0x1FE0, .{ .canon = [2]u21{
0x03C5,
0x0306,
} });
try instance.map.put(0x1FE1, .{ .canon = [2]u21{
0x03C5,
0x0304,
} });
try instance.map.put(0x1FE2, .{ .canon = [2]u21{
0x03CB,
0x0300,
} });
try instance.map.put(0x1FE3, .{ .single = 0x03B0 });
try instance.map.put(0x1FE4, .{ .canon = [2]u21{
0x03C1,
0x0313,
} });
try instance.map.put(0x1FE5, .{ .canon = [2]u21{
0x03C1,
0x0314,
} });
try instance.map.put(0x1FE6, .{ .canon = [2]u21{
0x03C5,
0x0342,
} });
try instance.map.put(0x1FE7, .{ .canon = [2]u21{
0x03CB,
0x0342,
} });
try instance.map.put(0x1FE8, .{ .canon = [2]u21{
0x03A5,
0x0306,
} });
try instance.map.put(0x1FE9, .{ .canon = [2]u21{
0x03A5,
0x0304,
} });
try instance.map.put(0x1FEA, .{ .canon = [2]u21{
0x03A5,
0x0300,
} });
try instance.map.put(0x1FEB, .{ .single = 0x038E });
try instance.map.put(0x1FEC, .{ .canon = [2]u21{
0x03A1,
0x0314,
} });
try instance.map.put(0x1FED, .{ .canon = [2]u21{
0x00A8,
0x0300,
} });
try instance.map.put(0x1FEE, .{ .single = 0x0385 });
try instance.map.put(0x1FEF, .{ .single = 0x0060 });
try instance.map.put(0x1FF2, .{ .canon = [2]u21{
0x1F7C,
0x0345,
} });
try instance.map.put(0x1FF3, .{ .canon = [2]u21{
0x03C9,
0x0345,
} });
try instance.map.put(0x1FF4, .{ .canon = [2]u21{
0x03CE,
0x0345,
} });
try instance.map.put(0x1FF6, .{ .canon = [2]u21{
0x03C9,
0x0342,
} });
try instance.map.put(0x1FF7, .{ .canon = [2]u21{
0x1FF6,
0x0345,
} });
try instance.map.put(0x1FF8, .{ .canon = [2]u21{
0x039F,
0x0300,
} });
try instance.map.put(0x1FF9, .{ .single = 0x038C });
try instance.map.put(0x1FFA, .{ .canon = [2]u21{
0x03A9,
0x0300,
} });
try instance.map.put(0x1FFB, .{ .single = 0x038F });
try instance.map.put(0x1FFC, .{ .canon = [2]u21{
0x03A9,
0x0345,
} });
try instance.map.put(0x1FFD, .{ .single = 0x00B4 });
try instance.map.put(0x1FFE, .{ .compat = &[_]u21{
0x0020,
0x0314,
} });
try instance.map.put(0x2000, .{ .single = 0x2002 });
try instance.map.put(0x2001, .{ .single = 0x2003 });
try instance.map.put(0x2002, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2003, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2004, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2005, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2006, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2007, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2008, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2009, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x200A, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2011, .{ .compat = &[_]u21{
0x2010,
} });
try instance.map.put(0x2017, .{ .compat = &[_]u21{
0x0020,
0x0333,
} });
try instance.map.put(0x2024, .{ .compat = &[_]u21{
0x002E,
} });
try instance.map.put(0x2025, .{ .compat = &[_]u21{
0x002E,
0x002E,
} });
try instance.map.put(0x2026, .{ .compat = &[_]u21{
0x002E,
0x002E,
0x002E,
} });
try instance.map.put(0x202F, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2033, .{ .compat = &[_]u21{
0x2032,
0x2032,
} });
try instance.map.put(0x2034, .{ .compat = &[_]u21{
0x2032,
0x2032,
0x2032,
} });
try instance.map.put(0x2036, .{ .compat = &[_]u21{
0x2035,
0x2035,
} });
try instance.map.put(0x2037, .{ .compat = &[_]u21{
0x2035,
0x2035,
0x2035,
} });
try instance.map.put(0x203C, .{ .compat = &[_]u21{
0x0021,
0x0021,
} });
try instance.map.put(0x203E, .{ .compat = &[_]u21{
0x0020,
0x0305,
} });
try instance.map.put(0x2047, .{ .compat = &[_]u21{
0x003F,
0x003F,
} });
try instance.map.put(0x2048, .{ .compat = &[_]u21{
0x003F,
0x0021,
} });
try instance.map.put(0x2049, .{ .compat = &[_]u21{
0x0021,
0x003F,
} });
try instance.map.put(0x2057, .{ .compat = &[_]u21{
0x2032,
0x2032,
0x2032,
0x2032,
} });
try instance.map.put(0x205F, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x2070, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0x2071, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x2074, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0x2075, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0x2076, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0x2077, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0x2078, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0x2079, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0x207A, .{ .compat = &[_]u21{
0x002B,
} });
try instance.map.put(0x207B, .{ .compat = &[_]u21{
0x2212,
} });
try instance.map.put(0x207C, .{ .compat = &[_]u21{
0x003D,
} });
try instance.map.put(0x207D, .{ .compat = &[_]u21{
0x0028,
} });
try instance.map.put(0x207E, .{ .compat = &[_]u21{
0x0029,
} });
try instance.map.put(0x207F, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x2080, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0x2081, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0x2082, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0x2083, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0x2084, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0x2085, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0x2086, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0x2087, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0x2088, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0x2089, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0x208A, .{ .compat = &[_]u21{
0x002B,
} });
try instance.map.put(0x208B, .{ .compat = &[_]u21{
0x2212,
} });
try instance.map.put(0x208C, .{ .compat = &[_]u21{
0x003D,
} });
try instance.map.put(0x208D, .{ .compat = &[_]u21{
0x0028,
} });
try instance.map.put(0x208E, .{ .compat = &[_]u21{
0x0029,
} });
try instance.map.put(0x2090, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x2091, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x2092, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x2093, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x2094, .{ .compat = &[_]u21{
0x0259,
} });
try instance.map.put(0x2095, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x2096, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x2097, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x2098, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x2099, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x209A, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x209B, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x209C, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x20A8, .{ .compat = &[_]u21{
0x0052,
0x0073,
} });
try instance.map.put(0x2100, .{ .compat = &[_]u21{
0x0061,
0x002F,
0x0063,
} });
try instance.map.put(0x2101, .{ .compat = &[_]u21{
0x0061,
0x002F,
0x0073,
} });
try instance.map.put(0x2102, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x2103, .{ .compat = &[_]u21{
0x00B0,
0x0043,
} });
try instance.map.put(0x2105, .{ .compat = &[_]u21{
0x0063,
0x002F,
0x006F,
} });
try instance.map.put(0x2106, .{ .compat = &[_]u21{
0x0063,
0x002F,
0x0075,
} });
try instance.map.put(0x2107, .{ .compat = &[_]u21{
0x0190,
} });
try instance.map.put(0x2109, .{ .compat = &[_]u21{
0x00B0,
0x0046,
} });
try instance.map.put(0x210A, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x210B, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x210C, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x210D, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x210E, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x210F, .{ .compat = &[_]u21{
0x0127,
} });
try instance.map.put(0x2110, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x2111, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x2112, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x2113, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x2115, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x2116, .{ .compat = &[_]u21{
0x004E,
0x006F,
} });
try instance.map.put(0x2119, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x211A, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x211B, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x211C, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x211D, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x2120, .{ .compat = &[_]u21{
0x0053,
0x004D,
} });
try instance.map.put(0x2121, .{ .compat = &[_]u21{
0x0054,
0x0045,
0x004C,
} });
try instance.map.put(0x2122, .{ .compat = &[_]u21{
0x0054,
0x004D,
} });
try instance.map.put(0x2124, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x2126, .{ .single = 0x03A9 });
try instance.map.put(0x2128, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x212A, .{ .single = 0x004B });
try instance.map.put(0x212B, .{ .single = 0x00C5 });
try instance.map.put(0x212C, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x212D, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x212F, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x2130, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x2131, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x2133, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x2134, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x2135, .{ .compat = &[_]u21{
0x05D0,
} });
try instance.map.put(0x2136, .{ .compat = &[_]u21{
0x05D1,
} });
try instance.map.put(0x2137, .{ .compat = &[_]u21{
0x05D2,
} });
try instance.map.put(0x2138, .{ .compat = &[_]u21{
0x05D3,
} });
try instance.map.put(0x2139, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x213B, .{ .compat = &[_]u21{
0x0046,
0x0041,
0x0058,
} });
try instance.map.put(0x213C, .{ .compat = &[_]u21{
0x03C0,
} });
try instance.map.put(0x213D, .{ .compat = &[_]u21{
0x03B3,
} });
try instance.map.put(0x213E, .{ .compat = &[_]u21{
0x0393,
} });
try instance.map.put(0x213F, .{ .compat = &[_]u21{
0x03A0,
} });
try instance.map.put(0x2140, .{ .compat = &[_]u21{
0x2211,
} });
try instance.map.put(0x2145, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x2146, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x2147, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x2148, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x2149, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x2150, .{ .compat = &[_]u21{
0x0031,
0x2044,
0x0037,
} });
try instance.map.put(0x2151, .{ .compat = &[_]u21{
0x0031,
0x2044,
0x0039,
} });
try instance.map.put(0x2152, .{ .compat = &[_]u21{
0x0031,
0x2044,
0x0031,
0x0030,
} });
try instance.map.put(0x2153, .{ .compat = &[_]u21{
0x0031,
0x2044,
0x0033,
} });
try instance.map.put(0x2154, .{ .compat = &[_]u21{
0x0032,
0x2044,
0x0033,
} });
try instance.map.put(0x2155, .{ .compat = &[_]u21{
0x0031,
0x2044,
0x0035,
} });
try instance.map.put(0x2156, .{ .compat = &[_]u21{
0x0032,
0x2044,
0x0035,
} });
try instance.map.put(0x2157, .{ .compat = &[_]u21{
0x0033,
0x2044,
0x0035,
} });
try instance.map.put(0x2158, .{ .compat = &[_]u21{
0x0034,
0x2044,
0x0035,
} });
try instance.map.put(0x2159, .{ .compat = &[_]u21{
0x0031,
0x2044,
0x0036,
} });
try instance.map.put(0x215A, .{ .compat = &[_]u21{
0x0035,
0x2044,
0x0036,
} });
try instance.map.put(0x215B, .{ .compat = &[_]u21{
0x0031,
0x2044,
0x0038,
} });
try instance.map.put(0x215C, .{ .compat = &[_]u21{
0x0033,
0x2044,
0x0038,
} });
try instance.map.put(0x215D, .{ .compat = &[_]u21{
0x0035,
0x2044,
0x0038,
} });
try instance.map.put(0x215E, .{ .compat = &[_]u21{
0x0037,
0x2044,
0x0038,
} });
try instance.map.put(0x215F, .{ .compat = &[_]u21{
0x0031,
0x2044,
} });
try instance.map.put(0x2160, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x2161, .{ .compat = &[_]u21{
0x0049,
0x0049,
} });
try instance.map.put(0x2162, .{ .compat = &[_]u21{
0x0049,
0x0049,
0x0049,
} });
try instance.map.put(0x2163, .{ .compat = &[_]u21{
0x0049,
0x0056,
} });
try instance.map.put(0x2164, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x2165, .{ .compat = &[_]u21{
0x0056,
0x0049,
} });
try instance.map.put(0x2166, .{ .compat = &[_]u21{
0x0056,
0x0049,
0x0049,
} });
try instance.map.put(0x2167, .{ .compat = &[_]u21{
0x0056,
0x0049,
0x0049,
0x0049,
} });
try instance.map.put(0x2168, .{ .compat = &[_]u21{
0x0049,
0x0058,
} });
try instance.map.put(0x2169, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x216A, .{ .compat = &[_]u21{
0x0058,
0x0049,
} });
try instance.map.put(0x216B, .{ .compat = &[_]u21{
0x0058,
0x0049,
0x0049,
} });
try instance.map.put(0x216C, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x216D, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x216E, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x216F, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x2170, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x2171, .{ .compat = &[_]u21{
0x0069,
0x0069,
} });
try instance.map.put(0x2172, .{ .compat = &[_]u21{
0x0069,
0x0069,
0x0069,
} });
try instance.map.put(0x2173, .{ .compat = &[_]u21{
0x0069,
0x0076,
} });
try instance.map.put(0x2174, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x2175, .{ .compat = &[_]u21{
0x0076,
0x0069,
} });
try instance.map.put(0x2176, .{ .compat = &[_]u21{
0x0076,
0x0069,
0x0069,
} });
try instance.map.put(0x2177, .{ .compat = &[_]u21{
0x0076,
0x0069,
0x0069,
0x0069,
} });
try instance.map.put(0x2178, .{ .compat = &[_]u21{
0x0069,
0x0078,
} });
try instance.map.put(0x2179, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x217A, .{ .compat = &[_]u21{
0x0078,
0x0069,
} });
try instance.map.put(0x217B, .{ .compat = &[_]u21{
0x0078,
0x0069,
0x0069,
} });
try instance.map.put(0x217C, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x217D, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x217E, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x217F, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x2189, .{ .compat = &[_]u21{
0x0030,
0x2044,
0x0033,
} });
try instance.map.put(0x219A, .{ .canon = [2]u21{
0x2190,
0x0338,
} });
try instance.map.put(0x219B, .{ .canon = [2]u21{
0x2192,
0x0338,
} });
try instance.map.put(0x21AE, .{ .canon = [2]u21{
0x2194,
0x0338,
} });
try instance.map.put(0x21CD, .{ .canon = [2]u21{
0x21D0,
0x0338,
} });
try instance.map.put(0x21CE, .{ .canon = [2]u21{
0x21D4,
0x0338,
} });
try instance.map.put(0x21CF, .{ .canon = [2]u21{
0x21D2,
0x0338,
} });
try instance.map.put(0x2204, .{ .canon = [2]u21{
0x2203,
0x0338,
} });
try instance.map.put(0x2209, .{ .canon = [2]u21{
0x2208,
0x0338,
} });
try instance.map.put(0x220C, .{ .canon = [2]u21{
0x220B,
0x0338,
} });
try instance.map.put(0x2224, .{ .canon = [2]u21{
0x2223,
0x0338,
} });
try instance.map.put(0x2226, .{ .canon = [2]u21{
0x2225,
0x0338,
} });
try instance.map.put(0x222C, .{ .compat = &[_]u21{
0x222B,
0x222B,
} });
try instance.map.put(0x222D, .{ .compat = &[_]u21{
0x222B,
0x222B,
0x222B,
} });
try instance.map.put(0x222F, .{ .compat = &[_]u21{
0x222E,
0x222E,
} });
try instance.map.put(0x2230, .{ .compat = &[_]u21{
0x222E,
0x222E,
0x222E,
} });
try instance.map.put(0x2241, .{ .canon = [2]u21{
0x223C,
0x0338,
} });
try instance.map.put(0x2244, .{ .canon = [2]u21{
0x2243,
0x0338,
} });
try instance.map.put(0x2247, .{ .canon = [2]u21{
0x2245,
0x0338,
} });
try instance.map.put(0x2249, .{ .canon = [2]u21{
0x2248,
0x0338,
} });
try instance.map.put(0x2260, .{ .canon = [2]u21{
0x003D,
0x0338,
} });
try instance.map.put(0x2262, .{ .canon = [2]u21{
0x2261,
0x0338,
} });
try instance.map.put(0x226D, .{ .canon = [2]u21{
0x224D,
0x0338,
} });
try instance.map.put(0x226E, .{ .canon = [2]u21{
0x003C,
0x0338,
} });
try instance.map.put(0x226F, .{ .canon = [2]u21{
0x003E,
0x0338,
} });
try instance.map.put(0x2270, .{ .canon = [2]u21{
0x2264,
0x0338,
} });
try instance.map.put(0x2271, .{ .canon = [2]u21{
0x2265,
0x0338,
} });
try instance.map.put(0x2274, .{ .canon = [2]u21{
0x2272,
0x0338,
} });
try instance.map.put(0x2275, .{ .canon = [2]u21{
0x2273,
0x0338,
} });
try instance.map.put(0x2278, .{ .canon = [2]u21{
0x2276,
0x0338,
} });
try instance.map.put(0x2279, .{ .canon = [2]u21{
0x2277,
0x0338,
} });
try instance.map.put(0x2280, .{ .canon = [2]u21{
0x227A,
0x0338,
} });
try instance.map.put(0x2281, .{ .canon = [2]u21{
0x227B,
0x0338,
} });
try instance.map.put(0x2284, .{ .canon = [2]u21{
0x2282,
0x0338,
} });
try instance.map.put(0x2285, .{ .canon = [2]u21{
0x2283,
0x0338,
} });
try instance.map.put(0x2288, .{ .canon = [2]u21{
0x2286,
0x0338,
} });
try instance.map.put(0x2289, .{ .canon = [2]u21{
0x2287,
0x0338,
} });
try instance.map.put(0x22AC, .{ .canon = [2]u21{
0x22A2,
0x0338,
} });
try instance.map.put(0x22AD, .{ .canon = [2]u21{
0x22A8,
0x0338,
} });
try instance.map.put(0x22AE, .{ .canon = [2]u21{
0x22A9,
0x0338,
} });
try instance.map.put(0x22AF, .{ .canon = [2]u21{
0x22AB,
0x0338,
} });
try instance.map.put(0x22E0, .{ .canon = [2]u21{
0x227C,
0x0338,
} });
try instance.map.put(0x22E1, .{ .canon = [2]u21{
0x227D,
0x0338,
} });
try instance.map.put(0x22E2, .{ .canon = [2]u21{
0x2291,
0x0338,
} });
try instance.map.put(0x22E3, .{ .canon = [2]u21{
0x2292,
0x0338,
} });
try instance.map.put(0x22EA, .{ .canon = [2]u21{
0x22B2,
0x0338,
} });
try instance.map.put(0x22EB, .{ .canon = [2]u21{
0x22B3,
0x0338,
} });
try instance.map.put(0x22EC, .{ .canon = [2]u21{
0x22B4,
0x0338,
} });
try instance.map.put(0x22ED, .{ .canon = [2]u21{
0x22B5,
0x0338,
} });
try instance.map.put(0x2329, .{ .single = 0x3008 });
try instance.map.put(0x232A, .{ .single = 0x3009 });
try instance.map.put(0x2460, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0x2461, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0x2462, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0x2463, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0x2464, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0x2465, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0x2466, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0x2467, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0x2468, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0x2469, .{ .compat = &[_]u21{
0x0031,
0x0030,
} });
try instance.map.put(0x246A, .{ .compat = &[_]u21{
0x0031,
0x0031,
} });
try instance.map.put(0x246B, .{ .compat = &[_]u21{
0x0031,
0x0032,
} });
try instance.map.put(0x246C, .{ .compat = &[_]u21{
0x0031,
0x0033,
} });
try instance.map.put(0x246D, .{ .compat = &[_]u21{
0x0031,
0x0034,
} });
try instance.map.put(0x246E, .{ .compat = &[_]u21{
0x0031,
0x0035,
} });
try instance.map.put(0x246F, .{ .compat = &[_]u21{
0x0031,
0x0036,
} });
try instance.map.put(0x2470, .{ .compat = &[_]u21{
0x0031,
0x0037,
} });
try instance.map.put(0x2471, .{ .compat = &[_]u21{
0x0031,
0x0038,
} });
try instance.map.put(0x2472, .{ .compat = &[_]u21{
0x0031,
0x0039,
} });
try instance.map.put(0x2473, .{ .compat = &[_]u21{
0x0032,
0x0030,
} });
try instance.map.put(0x2474, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0029,
} });
try instance.map.put(0x2475, .{ .compat = &[_]u21{
0x0028,
0x0032,
0x0029,
} });
try instance.map.put(0x2476, .{ .compat = &[_]u21{
0x0028,
0x0033,
0x0029,
} });
try instance.map.put(0x2477, .{ .compat = &[_]u21{
0x0028,
0x0034,
0x0029,
} });
try instance.map.put(0x2478, .{ .compat = &[_]u21{
0x0028,
0x0035,
0x0029,
} });
try instance.map.put(0x2479, .{ .compat = &[_]u21{
0x0028,
0x0036,
0x0029,
} });
try instance.map.put(0x247A, .{ .compat = &[_]u21{
0x0028,
0x0037,
0x0029,
} });
try instance.map.put(0x247B, .{ .compat = &[_]u21{
0x0028,
0x0038,
0x0029,
} });
try instance.map.put(0x247C, .{ .compat = &[_]u21{
0x0028,
0x0039,
0x0029,
} });
try instance.map.put(0x247D, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0030,
0x0029,
} });
try instance.map.put(0x247E, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0031,
0x0029,
} });
try instance.map.put(0x247F, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0032,
0x0029,
} });
try instance.map.put(0x2480, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0033,
0x0029,
} });
try instance.map.put(0x2481, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0034,
0x0029,
} });
try instance.map.put(0x2482, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0035,
0x0029,
} });
try instance.map.put(0x2483, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0036,
0x0029,
} });
try instance.map.put(0x2484, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0037,
0x0029,
} });
try instance.map.put(0x2485, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0038,
0x0029,
} });
try instance.map.put(0x2486, .{ .compat = &[_]u21{
0x0028,
0x0031,
0x0039,
0x0029,
} });
try instance.map.put(0x2487, .{ .compat = &[_]u21{
0x0028,
0x0032,
0x0030,
0x0029,
} });
try instance.map.put(0x2488, .{ .compat = &[_]u21{
0x0031,
0x002E,
} });
try instance.map.put(0x2489, .{ .compat = &[_]u21{
0x0032,
0x002E,
} });
try instance.map.put(0x248A, .{ .compat = &[_]u21{
0x0033,
0x002E,
} });
try instance.map.put(0x248B, .{ .compat = &[_]u21{
0x0034,
0x002E,
} });
try instance.map.put(0x248C, .{ .compat = &[_]u21{
0x0035,
0x002E,
} });
try instance.map.put(0x248D, .{ .compat = &[_]u21{
0x0036,
0x002E,
} });
try instance.map.put(0x248E, .{ .compat = &[_]u21{
0x0037,
0x002E,
} });
try instance.map.put(0x248F, .{ .compat = &[_]u21{
0x0038,
0x002E,
} });
try instance.map.put(0x2490, .{ .compat = &[_]u21{
0x0039,
0x002E,
} });
try instance.map.put(0x2491, .{ .compat = &[_]u21{
0x0031,
0x0030,
0x002E,
} });
try instance.map.put(0x2492, .{ .compat = &[_]u21{
0x0031,
0x0031,
0x002E,
} });
try instance.map.put(0x2493, .{ .compat = &[_]u21{
0x0031,
0x0032,
0x002E,
} });
try instance.map.put(0x2494, .{ .compat = &[_]u21{
0x0031,
0x0033,
0x002E,
} });
try instance.map.put(0x2495, .{ .compat = &[_]u21{
0x0031,
0x0034,
0x002E,
} });
try instance.map.put(0x2496, .{ .compat = &[_]u21{
0x0031,
0x0035,
0x002E,
} });
try instance.map.put(0x2497, .{ .compat = &[_]u21{
0x0031,
0x0036,
0x002E,
} });
try instance.map.put(0x2498, .{ .compat = &[_]u21{
0x0031,
0x0037,
0x002E,
} });
try instance.map.put(0x2499, .{ .compat = &[_]u21{
0x0031,
0x0038,
0x002E,
} });
try instance.map.put(0x249A, .{ .compat = &[_]u21{
0x0031,
0x0039,
0x002E,
} });
try instance.map.put(0x249B, .{ .compat = &[_]u21{
0x0032,
0x0030,
0x002E,
} });
try instance.map.put(0x249C, .{ .compat = &[_]u21{
0x0028,
0x0061,
0x0029,
} });
try instance.map.put(0x249D, .{ .compat = &[_]u21{
0x0028,
0x0062,
0x0029,
} });
try instance.map.put(0x249E, .{ .compat = &[_]u21{
0x0028,
0x0063,
0x0029,
} });
try instance.map.put(0x249F, .{ .compat = &[_]u21{
0x0028,
0x0064,
0x0029,
} });
try instance.map.put(0x24A0, .{ .compat = &[_]u21{
0x0028,
0x0065,
0x0029,
} });
try instance.map.put(0x24A1, .{ .compat = &[_]u21{
0x0028,
0x0066,
0x0029,
} });
try instance.map.put(0x24A2, .{ .compat = &[_]u21{
0x0028,
0x0067,
0x0029,
} });
try instance.map.put(0x24A3, .{ .compat = &[_]u21{
0x0028,
0x0068,
0x0029,
} });
try instance.map.put(0x24A4, .{ .compat = &[_]u21{
0x0028,
0x0069,
0x0029,
} });
try instance.map.put(0x24A5, .{ .compat = &[_]u21{
0x0028,
0x006A,
0x0029,
} });
try instance.map.put(0x24A6, .{ .compat = &[_]u21{
0x0028,
0x006B,
0x0029,
} });
try instance.map.put(0x24A7, .{ .compat = &[_]u21{
0x0028,
0x006C,
0x0029,
} });
try instance.map.put(0x24A8, .{ .compat = &[_]u21{
0x0028,
0x006D,
0x0029,
} });
try instance.map.put(0x24A9, .{ .compat = &[_]u21{
0x0028,
0x006E,
0x0029,
} });
try instance.map.put(0x24AA, .{ .compat = &[_]u21{
0x0028,
0x006F,
0x0029,
} });
try instance.map.put(0x24AB, .{ .compat = &[_]u21{
0x0028,
0x0070,
0x0029,
} });
try instance.map.put(0x24AC, .{ .compat = &[_]u21{
0x0028,
0x0071,
0x0029,
} });
try instance.map.put(0x24AD, .{ .compat = &[_]u21{
0x0028,
0x0072,
0x0029,
} });
try instance.map.put(0x24AE, .{ .compat = &[_]u21{
0x0028,
0x0073,
0x0029,
} });
try instance.map.put(0x24AF, .{ .compat = &[_]u21{
0x0028,
0x0074,
0x0029,
} });
try instance.map.put(0x24B0, .{ .compat = &[_]u21{
0x0028,
0x0075,
0x0029,
} });
try instance.map.put(0x24B1, .{ .compat = &[_]u21{
0x0028,
0x0076,
0x0029,
} });
try instance.map.put(0x24B2, .{ .compat = &[_]u21{
0x0028,
0x0077,
0x0029,
} });
try instance.map.put(0x24B3, .{ .compat = &[_]u21{
0x0028,
0x0078,
0x0029,
} });
try instance.map.put(0x24B4, .{ .compat = &[_]u21{
0x0028,
0x0079,
0x0029,
} });
try instance.map.put(0x24B5, .{ .compat = &[_]u21{
0x0028,
0x007A,
0x0029,
} });
try instance.map.put(0x24B6, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x24B7, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x24B8, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x24B9, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x24BA, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x24BB, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x24BC, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x24BD, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x24BE, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x24BF, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x24C0, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x24C1, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x24C2, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x24C3, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x24C4, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x24C5, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x24C6, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x24C7, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x24C8, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x24C9, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x24CA, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x24CB, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x24CC, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x24CD, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x24CE, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x24CF, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x24D0, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x24D1, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x24D2, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x24D3, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x24D4, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x24D5, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x24D6, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x24D7, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x24D8, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x24D9, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x24DA, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x24DB, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x24DC, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x24DD, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x24DE, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x24DF, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x24E0, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x24E1, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x24E2, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x24E3, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x24E4, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x24E5, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x24E6, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x24E7, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x24E8, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x24E9, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x24EA, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0x2A0C, .{ .compat = &[_]u21{
0x222B,
0x222B,
0x222B,
0x222B,
} });
try instance.map.put(0x2A74, .{ .compat = &[_]u21{
0x003A,
0x003A,
0x003D,
} });
try instance.map.put(0x2A75, .{ .compat = &[_]u21{
0x003D,
0x003D,
} });
try instance.map.put(0x2A76, .{ .compat = &[_]u21{
0x003D,
0x003D,
0x003D,
} });
try instance.map.put(0x2ADC, .{ .canon = [2]u21{
0x2ADD,
0x0338,
} });
try instance.map.put(0x2C7C, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x2C7D, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x2D6F, .{ .compat = &[_]u21{
0x2D61,
} });
try instance.map.put(0x2E9F, .{ .compat = &[_]u21{
0x6BCD,
} });
try instance.map.put(0x2EF3, .{ .compat = &[_]u21{
0x9F9F,
} });
try instance.map.put(0x2F00, .{ .compat = &[_]u21{
0x4E00,
} });
try instance.map.put(0x2F01, .{ .compat = &[_]u21{
0x4E28,
} });
try instance.map.put(0x2F02, .{ .compat = &[_]u21{
0x4E36,
} });
try instance.map.put(0x2F03, .{ .compat = &[_]u21{
0x4E3F,
} });
try instance.map.put(0x2F04, .{ .compat = &[_]u21{
0x4E59,
} });
try instance.map.put(0x2F05, .{ .compat = &[_]u21{
0x4E85,
} });
try instance.map.put(0x2F06, .{ .compat = &[_]u21{
0x4E8C,
} });
try instance.map.put(0x2F07, .{ .compat = &[_]u21{
0x4EA0,
} });
try instance.map.put(0x2F08, .{ .compat = &[_]u21{
0x4EBA,
} });
try instance.map.put(0x2F09, .{ .compat = &[_]u21{
0x513F,
} });
try instance.map.put(0x2F0A, .{ .compat = &[_]u21{
0x5165,
} });
try instance.map.put(0x2F0B, .{ .compat = &[_]u21{
0x516B,
} });
try instance.map.put(0x2F0C, .{ .compat = &[_]u21{
0x5182,
} });
try instance.map.put(0x2F0D, .{ .compat = &[_]u21{
0x5196,
} });
try instance.map.put(0x2F0E, .{ .compat = &[_]u21{
0x51AB,
} });
try instance.map.put(0x2F0F, .{ .compat = &[_]u21{
0x51E0,
} });
try instance.map.put(0x2F10, .{ .compat = &[_]u21{
0x51F5,
} });
try instance.map.put(0x2F11, .{ .compat = &[_]u21{
0x5200,
} });
try instance.map.put(0x2F12, .{ .compat = &[_]u21{
0x529B,
} });
try instance.map.put(0x2F13, .{ .compat = &[_]u21{
0x52F9,
} });
try instance.map.put(0x2F14, .{ .compat = &[_]u21{
0x5315,
} });
try instance.map.put(0x2F15, .{ .compat = &[_]u21{
0x531A,
} });
try instance.map.put(0x2F16, .{ .compat = &[_]u21{
0x5338,
} });
try instance.map.put(0x2F17, .{ .compat = &[_]u21{
0x5341,
} });
try instance.map.put(0x2F18, .{ .compat = &[_]u21{
0x535C,
} });
try instance.map.put(0x2F19, .{ .compat = &[_]u21{
0x5369,
} });
try instance.map.put(0x2F1A, .{ .compat = &[_]u21{
0x5382,
} });
try instance.map.put(0x2F1B, .{ .compat = &[_]u21{
0x53B6,
} });
try instance.map.put(0x2F1C, .{ .compat = &[_]u21{
0x53C8,
} });
try instance.map.put(0x2F1D, .{ .compat = &[_]u21{
0x53E3,
} });
try instance.map.put(0x2F1E, .{ .compat = &[_]u21{
0x56D7,
} });
try instance.map.put(0x2F1F, .{ .compat = &[_]u21{
0x571F,
} });
try instance.map.put(0x2F20, .{ .compat = &[_]u21{
0x58EB,
} });
try instance.map.put(0x2F21, .{ .compat = &[_]u21{
0x5902,
} });
try instance.map.put(0x2F22, .{ .compat = &[_]u21{
0x590A,
} });
try instance.map.put(0x2F23, .{ .compat = &[_]u21{
0x5915,
} });
try instance.map.put(0x2F24, .{ .compat = &[_]u21{
0x5927,
} });
try instance.map.put(0x2F25, .{ .compat = &[_]u21{
0x5973,
} });
try instance.map.put(0x2F26, .{ .compat = &[_]u21{
0x5B50,
} });
try instance.map.put(0x2F27, .{ .compat = &[_]u21{
0x5B80,
} });
try instance.map.put(0x2F28, .{ .compat = &[_]u21{
0x5BF8,
} });
try instance.map.put(0x2F29, .{ .compat = &[_]u21{
0x5C0F,
} });
try instance.map.put(0x2F2A, .{ .compat = &[_]u21{
0x5C22,
} });
try instance.map.put(0x2F2B, .{ .compat = &[_]u21{
0x5C38,
} });
try instance.map.put(0x2F2C, .{ .compat = &[_]u21{
0x5C6E,
} });
try instance.map.put(0x2F2D, .{ .compat = &[_]u21{
0x5C71,
} });
try instance.map.put(0x2F2E, .{ .compat = &[_]u21{
0x5DDB,
} });
try instance.map.put(0x2F2F, .{ .compat = &[_]u21{
0x5DE5,
} });
try instance.map.put(0x2F30, .{ .compat = &[_]u21{
0x5DF1,
} });
try instance.map.put(0x2F31, .{ .compat = &[_]u21{
0x5DFE,
} });
try instance.map.put(0x2F32, .{ .compat = &[_]u21{
0x5E72,
} });
try instance.map.put(0x2F33, .{ .compat = &[_]u21{
0x5E7A,
} });
try instance.map.put(0x2F34, .{ .compat = &[_]u21{
0x5E7F,
} });
try instance.map.put(0x2F35, .{ .compat = &[_]u21{
0x5EF4,
} });
try instance.map.put(0x2F36, .{ .compat = &[_]u21{
0x5EFE,
} });
try instance.map.put(0x2F37, .{ .compat = &[_]u21{
0x5F0B,
} });
try instance.map.put(0x2F38, .{ .compat = &[_]u21{
0x5F13,
} });
try instance.map.put(0x2F39, .{ .compat = &[_]u21{
0x5F50,
} });
try instance.map.put(0x2F3A, .{ .compat = &[_]u21{
0x5F61,
} });
try instance.map.put(0x2F3B, .{ .compat = &[_]u21{
0x5F73,
} });
try instance.map.put(0x2F3C, .{ .compat = &[_]u21{
0x5FC3,
} });
try instance.map.put(0x2F3D, .{ .compat = &[_]u21{
0x6208,
} });
try instance.map.put(0x2F3E, .{ .compat = &[_]u21{
0x6236,
} });
try instance.map.put(0x2F3F, .{ .compat = &[_]u21{
0x624B,
} });
try instance.map.put(0x2F40, .{ .compat = &[_]u21{
0x652F,
} });
try instance.map.put(0x2F41, .{ .compat = &[_]u21{
0x6534,
} });
try instance.map.put(0x2F42, .{ .compat = &[_]u21{
0x6587,
} });
try instance.map.put(0x2F43, .{ .compat = &[_]u21{
0x6597,
} });
try instance.map.put(0x2F44, .{ .compat = &[_]u21{
0x65A4,
} });
try instance.map.put(0x2F45, .{ .compat = &[_]u21{
0x65B9,
} });
try instance.map.put(0x2F46, .{ .compat = &[_]u21{
0x65E0,
} });
try instance.map.put(0x2F47, .{ .compat = &[_]u21{
0x65E5,
} });
try instance.map.put(0x2F48, .{ .compat = &[_]u21{
0x66F0,
} });
try instance.map.put(0x2F49, .{ .compat = &[_]u21{
0x6708,
} });
try instance.map.put(0x2F4A, .{ .compat = &[_]u21{
0x6728,
} });
try instance.map.put(0x2F4B, .{ .compat = &[_]u21{
0x6B20,
} });
try instance.map.put(0x2F4C, .{ .compat = &[_]u21{
0x6B62,
} });
try instance.map.put(0x2F4D, .{ .compat = &[_]u21{
0x6B79,
} });
try instance.map.put(0x2F4E, .{ .compat = &[_]u21{
0x6BB3,
} });
try instance.map.put(0x2F4F, .{ .compat = &[_]u21{
0x6BCB,
} });
try instance.map.put(0x2F50, .{ .compat = &[_]u21{
0x6BD4,
} });
try instance.map.put(0x2F51, .{ .compat = &[_]u21{
0x6BDB,
} });
try instance.map.put(0x2F52, .{ .compat = &[_]u21{
0x6C0F,
} });
try instance.map.put(0x2F53, .{ .compat = &[_]u21{
0x6C14,
} });
try instance.map.put(0x2F54, .{ .compat = &[_]u21{
0x6C34,
} });
try instance.map.put(0x2F55, .{ .compat = &[_]u21{
0x706B,
} });
try instance.map.put(0x2F56, .{ .compat = &[_]u21{
0x722A,
} });
try instance.map.put(0x2F57, .{ .compat = &[_]u21{
0x7236,
} });
try instance.map.put(0x2F58, .{ .compat = &[_]u21{
0x723B,
} });
try instance.map.put(0x2F59, .{ .compat = &[_]u21{
0x723F,
} });
try instance.map.put(0x2F5A, .{ .compat = &[_]u21{
0x7247,
} });
try instance.map.put(0x2F5B, .{ .compat = &[_]u21{
0x7259,
} });
try instance.map.put(0x2F5C, .{ .compat = &[_]u21{
0x725B,
} });
try instance.map.put(0x2F5D, .{ .compat = &[_]u21{
0x72AC,
} });
try instance.map.put(0x2F5E, .{ .compat = &[_]u21{
0x7384,
} });
try instance.map.put(0x2F5F, .{ .compat = &[_]u21{
0x7389,
} });
try instance.map.put(0x2F60, .{ .compat = &[_]u21{
0x74DC,
} });
try instance.map.put(0x2F61, .{ .compat = &[_]u21{
0x74E6,
} });
try instance.map.put(0x2F62, .{ .compat = &[_]u21{
0x7518,
} });
try instance.map.put(0x2F63, .{ .compat = &[_]u21{
0x751F,
} });
try instance.map.put(0x2F64, .{ .compat = &[_]u21{
0x7528,
} });
try instance.map.put(0x2F65, .{ .compat = &[_]u21{
0x7530,
} });
try instance.map.put(0x2F66, .{ .compat = &[_]u21{
0x758B,
} });
try instance.map.put(0x2F67, .{ .compat = &[_]u21{
0x7592,
} });
try instance.map.put(0x2F68, .{ .compat = &[_]u21{
0x7676,
} });
try instance.map.put(0x2F69, .{ .compat = &[_]u21{
0x767D,
} });
try instance.map.put(0x2F6A, .{ .compat = &[_]u21{
0x76AE,
} });
try instance.map.put(0x2F6B, .{ .compat = &[_]u21{
0x76BF,
} });
try instance.map.put(0x2F6C, .{ .compat = &[_]u21{
0x76EE,
} });
try instance.map.put(0x2F6D, .{ .compat = &[_]u21{
0x77DB,
} });
try instance.map.put(0x2F6E, .{ .compat = &[_]u21{
0x77E2,
} });
try instance.map.put(0x2F6F, .{ .compat = &[_]u21{
0x77F3,
} });
try instance.map.put(0x2F70, .{ .compat = &[_]u21{
0x793A,
} });
try instance.map.put(0x2F71, .{ .compat = &[_]u21{
0x79B8,
} });
try instance.map.put(0x2F72, .{ .compat = &[_]u21{
0x79BE,
} });
try instance.map.put(0x2F73, .{ .compat = &[_]u21{
0x7A74,
} });
try instance.map.put(0x2F74, .{ .compat = &[_]u21{
0x7ACB,
} });
try instance.map.put(0x2F75, .{ .compat = &[_]u21{
0x7AF9,
} });
try instance.map.put(0x2F76, .{ .compat = &[_]u21{
0x7C73,
} });
try instance.map.put(0x2F77, .{ .compat = &[_]u21{
0x7CF8,
} });
try instance.map.put(0x2F78, .{ .compat = &[_]u21{
0x7F36,
} });
try instance.map.put(0x2F79, .{ .compat = &[_]u21{
0x7F51,
} });
try instance.map.put(0x2F7A, .{ .compat = &[_]u21{
0x7F8A,
} });
try instance.map.put(0x2F7B, .{ .compat = &[_]u21{
0x7FBD,
} });
try instance.map.put(0x2F7C, .{ .compat = &[_]u21{
0x8001,
} });
try instance.map.put(0x2F7D, .{ .compat = &[_]u21{
0x800C,
} });
try instance.map.put(0x2F7E, .{ .compat = &[_]u21{
0x8012,
} });
try instance.map.put(0x2F7F, .{ .compat = &[_]u21{
0x8033,
} });
try instance.map.put(0x2F80, .{ .compat = &[_]u21{
0x807F,
} });
try instance.map.put(0x2F81, .{ .compat = &[_]u21{
0x8089,
} });
try instance.map.put(0x2F82, .{ .compat = &[_]u21{
0x81E3,
} });
try instance.map.put(0x2F83, .{ .compat = &[_]u21{
0x81EA,
} });
try instance.map.put(0x2F84, .{ .compat = &[_]u21{
0x81F3,
} });
try instance.map.put(0x2F85, .{ .compat = &[_]u21{
0x81FC,
} });
try instance.map.put(0x2F86, .{ .compat = &[_]u21{
0x820C,
} });
try instance.map.put(0x2F87, .{ .compat = &[_]u21{
0x821B,
} });
try instance.map.put(0x2F88, .{ .compat = &[_]u21{
0x821F,
} });
try instance.map.put(0x2F89, .{ .compat = &[_]u21{
0x826E,
} });
try instance.map.put(0x2F8A, .{ .compat = &[_]u21{
0x8272,
} });
try instance.map.put(0x2F8B, .{ .compat = &[_]u21{
0x8278,
} });
try instance.map.put(0x2F8C, .{ .compat = &[_]u21{
0x864D,
} });
try instance.map.put(0x2F8D, .{ .compat = &[_]u21{
0x866B,
} });
try instance.map.put(0x2F8E, .{ .compat = &[_]u21{
0x8840,
} });
try instance.map.put(0x2F8F, .{ .compat = &[_]u21{
0x884C,
} });
try instance.map.put(0x2F90, .{ .compat = &[_]u21{
0x8863,
} });
try instance.map.put(0x2F91, .{ .compat = &[_]u21{
0x897E,
} });
try instance.map.put(0x2F92, .{ .compat = &[_]u21{
0x898B,
} });
try instance.map.put(0x2F93, .{ .compat = &[_]u21{
0x89D2,
} });
try instance.map.put(0x2F94, .{ .compat = &[_]u21{
0x8A00,
} });
try instance.map.put(0x2F95, .{ .compat = &[_]u21{
0x8C37,
} });
try instance.map.put(0x2F96, .{ .compat = &[_]u21{
0x8C46,
} });
try instance.map.put(0x2F97, .{ .compat = &[_]u21{
0x8C55,
} });
try instance.map.put(0x2F98, .{ .compat = &[_]u21{
0x8C78,
} });
try instance.map.put(0x2F99, .{ .compat = &[_]u21{
0x8C9D,
} });
try instance.map.put(0x2F9A, .{ .compat = &[_]u21{
0x8D64,
} });
try instance.map.put(0x2F9B, .{ .compat = &[_]u21{
0x8D70,
} });
try instance.map.put(0x2F9C, .{ .compat = &[_]u21{
0x8DB3,
} });
try instance.map.put(0x2F9D, .{ .compat = &[_]u21{
0x8EAB,
} });
try instance.map.put(0x2F9E, .{ .compat = &[_]u21{
0x8ECA,
} });
try instance.map.put(0x2F9F, .{ .compat = &[_]u21{
0x8F9B,
} });
try instance.map.put(0x2FA0, .{ .compat = &[_]u21{
0x8FB0,
} });
try instance.map.put(0x2FA1, .{ .compat = &[_]u21{
0x8FB5,
} });
try instance.map.put(0x2FA2, .{ .compat = &[_]u21{
0x9091,
} });
try instance.map.put(0x2FA3, .{ .compat = &[_]u21{
0x9149,
} });
try instance.map.put(0x2FA4, .{ .compat = &[_]u21{
0x91C6,
} });
try instance.map.put(0x2FA5, .{ .compat = &[_]u21{
0x91CC,
} });
try instance.map.put(0x2FA6, .{ .compat = &[_]u21{
0x91D1,
} });
try instance.map.put(0x2FA7, .{ .compat = &[_]u21{
0x9577,
} });
try instance.map.put(0x2FA8, .{ .compat = &[_]u21{
0x9580,
} });
try instance.map.put(0x2FA9, .{ .compat = &[_]u21{
0x961C,
} });
try instance.map.put(0x2FAA, .{ .compat = &[_]u21{
0x96B6,
} });
try instance.map.put(0x2FAB, .{ .compat = &[_]u21{
0x96B9,
} });
try instance.map.put(0x2FAC, .{ .compat = &[_]u21{
0x96E8,
} });
try instance.map.put(0x2FAD, .{ .compat = &[_]u21{
0x9751,
} });
try instance.map.put(0x2FAE, .{ .compat = &[_]u21{
0x975E,
} });
try instance.map.put(0x2FAF, .{ .compat = &[_]u21{
0x9762,
} });
try instance.map.put(0x2FB0, .{ .compat = &[_]u21{
0x9769,
} });
try instance.map.put(0x2FB1, .{ .compat = &[_]u21{
0x97CB,
} });
try instance.map.put(0x2FB2, .{ .compat = &[_]u21{
0x97ED,
} });
try instance.map.put(0x2FB3, .{ .compat = &[_]u21{
0x97F3,
} });
try instance.map.put(0x2FB4, .{ .compat = &[_]u21{
0x9801,
} });
try instance.map.put(0x2FB5, .{ .compat = &[_]u21{
0x98A8,
} });
try instance.map.put(0x2FB6, .{ .compat = &[_]u21{
0x98DB,
} });
try instance.map.put(0x2FB7, .{ .compat = &[_]u21{
0x98DF,
} });
try instance.map.put(0x2FB8, .{ .compat = &[_]u21{
0x9996,
} });
try instance.map.put(0x2FB9, .{ .compat = &[_]u21{
0x9999,
} });
try instance.map.put(0x2FBA, .{ .compat = &[_]u21{
0x99AC,
} });
try instance.map.put(0x2FBB, .{ .compat = &[_]u21{
0x9AA8,
} });
try instance.map.put(0x2FBC, .{ .compat = &[_]u21{
0x9AD8,
} });
try instance.map.put(0x2FBD, .{ .compat = &[_]u21{
0x9ADF,
} });
try instance.map.put(0x2FBE, .{ .compat = &[_]u21{
0x9B25,
} });
try instance.map.put(0x2FBF, .{ .compat = &[_]u21{
0x9B2F,
} });
try instance.map.put(0x2FC0, .{ .compat = &[_]u21{
0x9B32,
} });
try instance.map.put(0x2FC1, .{ .compat = &[_]u21{
0x9B3C,
} });
try instance.map.put(0x2FC2, .{ .compat = &[_]u21{
0x9B5A,
} });
try instance.map.put(0x2FC3, .{ .compat = &[_]u21{
0x9CE5,
} });
try instance.map.put(0x2FC4, .{ .compat = &[_]u21{
0x9E75,
} });
try instance.map.put(0x2FC5, .{ .compat = &[_]u21{
0x9E7F,
} });
try instance.map.put(0x2FC6, .{ .compat = &[_]u21{
0x9EA5,
} });
try instance.map.put(0x2FC7, .{ .compat = &[_]u21{
0x9EBB,
} });
try instance.map.put(0x2FC8, .{ .compat = &[_]u21{
0x9EC3,
} });
try instance.map.put(0x2FC9, .{ .compat = &[_]u21{
0x9ECD,
} });
try instance.map.put(0x2FCA, .{ .compat = &[_]u21{
0x9ED1,
} });
try instance.map.put(0x2FCB, .{ .compat = &[_]u21{
0x9EF9,
} });
try instance.map.put(0x2FCC, .{ .compat = &[_]u21{
0x9EFD,
} });
try instance.map.put(0x2FCD, .{ .compat = &[_]u21{
0x9F0E,
} });
try instance.map.put(0x2FCE, .{ .compat = &[_]u21{
0x9F13,
} });
try instance.map.put(0x2FCF, .{ .compat = &[_]u21{
0x9F20,
} });
try instance.map.put(0x2FD0, .{ .compat = &[_]u21{
0x9F3B,
} });
try instance.map.put(0x2FD1, .{ .compat = &[_]u21{
0x9F4A,
} });
try instance.map.put(0x2FD2, .{ .compat = &[_]u21{
0x9F52,
} });
try instance.map.put(0x2FD3, .{ .compat = &[_]u21{
0x9F8D,
} });
try instance.map.put(0x2FD4, .{ .compat = &[_]u21{
0x9F9C,
} });
try instance.map.put(0x2FD5, .{ .compat = &[_]u21{
0x9FA0,
} });
try instance.map.put(0x3000, .{ .compat = &[_]u21{
0x0020,
} });
try instance.map.put(0x3036, .{ .compat = &[_]u21{
0x3012,
} });
try instance.map.put(0x3038, .{ .compat = &[_]u21{
0x5341,
} });
try instance.map.put(0x3039, .{ .compat = &[_]u21{
0x5344,
} });
try instance.map.put(0x303A, .{ .compat = &[_]u21{
0x5345,
} });
try instance.map.put(0x304C, .{ .canon = [2]u21{
0x304B,
0x3099,
} });
try instance.map.put(0x304E, .{ .canon = [2]u21{
0x304D,
0x3099,
} });
try instance.map.put(0x3050, .{ .canon = [2]u21{
0x304F,
0x3099,
} });
try instance.map.put(0x3052, .{ .canon = [2]u21{
0x3051,
0x3099,
} });
try instance.map.put(0x3054, .{ .canon = [2]u21{
0x3053,
0x3099,
} });
try instance.map.put(0x3056, .{ .canon = [2]u21{
0x3055,
0x3099,
} });
try instance.map.put(0x3058, .{ .canon = [2]u21{
0x3057,
0x3099,
} });
try instance.map.put(0x305A, .{ .canon = [2]u21{
0x3059,
0x3099,
} });
try instance.map.put(0x305C, .{ .canon = [2]u21{
0x305B,
0x3099,
} });
try instance.map.put(0x305E, .{ .canon = [2]u21{
0x305D,
0x3099,
} });
try instance.map.put(0x3060, .{ .canon = [2]u21{
0x305F,
0x3099,
} });
try instance.map.put(0x3062, .{ .canon = [2]u21{
0x3061,
0x3099,
} });
try instance.map.put(0x3065, .{ .canon = [2]u21{
0x3064,
0x3099,
} });
try instance.map.put(0x3067, .{ .canon = [2]u21{
0x3066,
0x3099,
} });
try instance.map.put(0x3069, .{ .canon = [2]u21{
0x3068,
0x3099,
} });
try instance.map.put(0x3070, .{ .canon = [2]u21{
0x306F,
0x3099,
} });
try instance.map.put(0x3071, .{ .canon = [2]u21{
0x306F,
0x309A,
} });
try instance.map.put(0x3073, .{ .canon = [2]u21{
0x3072,
0x3099,
} });
try instance.map.put(0x3074, .{ .canon = [2]u21{
0x3072,
0x309A,
} });
try instance.map.put(0x3076, .{ .canon = [2]u21{
0x3075,
0x3099,
} });
try instance.map.put(0x3077, .{ .canon = [2]u21{
0x3075,
0x309A,
} });
try instance.map.put(0x3079, .{ .canon = [2]u21{
0x3078,
0x3099,
} });
try instance.map.put(0x307A, .{ .canon = [2]u21{
0x3078,
0x309A,
} });
try instance.map.put(0x307C, .{ .canon = [2]u21{
0x307B,
0x3099,
} });
try instance.map.put(0x307D, .{ .canon = [2]u21{
0x307B,
0x309A,
} });
try instance.map.put(0x3094, .{ .canon = [2]u21{
0x3046,
0x3099,
} });
try instance.map.put(0x309B, .{ .compat = &[_]u21{
0x0020,
0x3099,
} });
try instance.map.put(0x309C, .{ .compat = &[_]u21{
0x0020,
0x309A,
} });
try instance.map.put(0x309E, .{ .canon = [2]u21{
0x309D,
0x3099,
} });
try instance.map.put(0x309F, .{ .compat = &[_]u21{
0x3088,
0x308A,
} });
try instance.map.put(0x30AC, .{ .canon = [2]u21{
0x30AB,
0x3099,
} });
try instance.map.put(0x30AE, .{ .canon = [2]u21{
0x30AD,
0x3099,
} });
try instance.map.put(0x30B0, .{ .canon = [2]u21{
0x30AF,
0x3099,
} });
try instance.map.put(0x30B2, .{ .canon = [2]u21{
0x30B1,
0x3099,
} });
try instance.map.put(0x30B4, .{ .canon = [2]u21{
0x30B3,
0x3099,
} });
try instance.map.put(0x30B6, .{ .canon = [2]u21{
0x30B5,
0x3099,
} });
try instance.map.put(0x30B8, .{ .canon = [2]u21{
0x30B7,
0x3099,
} });
try instance.map.put(0x30BA, .{ .canon = [2]u21{
0x30B9,
0x3099,
} });
try instance.map.put(0x30BC, .{ .canon = [2]u21{
0x30BB,
0x3099,
} });
try instance.map.put(0x30BE, .{ .canon = [2]u21{
0x30BD,
0x3099,
} });
try instance.map.put(0x30C0, .{ .canon = [2]u21{
0x30BF,
0x3099,
} });
try instance.map.put(0x30C2, .{ .canon = [2]u21{
0x30C1,
0x3099,
} });
try instance.map.put(0x30C5, .{ .canon = [2]u21{
0x30C4,
0x3099,
} });
try instance.map.put(0x30C7, .{ .canon = [2]u21{
0x30C6,
0x3099,
} });
try instance.map.put(0x30C9, .{ .canon = [2]u21{
0x30C8,
0x3099,
} });
try instance.map.put(0x30D0, .{ .canon = [2]u21{
0x30CF,
0x3099,
} });
try instance.map.put(0x30D1, .{ .canon = [2]u21{
0x30CF,
0x309A,
} });
try instance.map.put(0x30D3, .{ .canon = [2]u21{
0x30D2,
0x3099,
} });
try instance.map.put(0x30D4, .{ .canon = [2]u21{
0x30D2,
0x309A,
} });
try instance.map.put(0x30D6, .{ .canon = [2]u21{
0x30D5,
0x3099,
} });
try instance.map.put(0x30D7, .{ .canon = [2]u21{
0x30D5,
0x309A,
} });
try instance.map.put(0x30D9, .{ .canon = [2]u21{
0x30D8,
0x3099,
} });
try instance.map.put(0x30DA, .{ .canon = [2]u21{
0x30D8,
0x309A,
} });
try instance.map.put(0x30DC, .{ .canon = [2]u21{
0x30DB,
0x3099,
} });
try instance.map.put(0x30DD, .{ .canon = [2]u21{
0x30DB,
0x309A,
} });
try instance.map.put(0x30F4, .{ .canon = [2]u21{
0x30A6,
0x3099,
} });
try instance.map.put(0x30F7, .{ .canon = [2]u21{
0x30EF,
0x3099,
} });
try instance.map.put(0x30F8, .{ .canon = [2]u21{
0x30F0,
0x3099,
} });
try instance.map.put(0x30F9, .{ .canon = [2]u21{
0x30F1,
0x3099,
} });
try instance.map.put(0x30FA, .{ .canon = [2]u21{
0x30F2,
0x3099,
} });
try instance.map.put(0x30FE, .{ .canon = [2]u21{
0x30FD,
0x3099,
} });
try instance.map.put(0x30FF, .{ .compat = &[_]u21{
0x30B3,
0x30C8,
} });
try instance.map.put(0x3131, .{ .compat = &[_]u21{
0x1100,
} });
try instance.map.put(0x3132, .{ .compat = &[_]u21{
0x1101,
} });
try instance.map.put(0x3133, .{ .compat = &[_]u21{
0x11AA,
} });
try instance.map.put(0x3134, .{ .compat = &[_]u21{
0x1102,
} });
try instance.map.put(0x3135, .{ .compat = &[_]u21{
0x11AC,
} });
try instance.map.put(0x3136, .{ .compat = &[_]u21{
0x11AD,
} });
try instance.map.put(0x3137, .{ .compat = &[_]u21{
0x1103,
} });
try instance.map.put(0x3138, .{ .compat = &[_]u21{
0x1104,
} });
try instance.map.put(0x3139, .{ .compat = &[_]u21{
0x1105,
} });
try instance.map.put(0x313A, .{ .compat = &[_]u21{
0x11B0,
} });
try instance.map.put(0x313B, .{ .compat = &[_]u21{
0x11B1,
} });
try instance.map.put(0x313C, .{ .compat = &[_]u21{
0x11B2,
} });
try instance.map.put(0x313D, .{ .compat = &[_]u21{
0x11B3,
} });
try instance.map.put(0x313E, .{ .compat = &[_]u21{
0x11B4,
} });
try instance.map.put(0x313F, .{ .compat = &[_]u21{
0x11B5,
} });
try instance.map.put(0x3140, .{ .compat = &[_]u21{
0x111A,
} });
try instance.map.put(0x3141, .{ .compat = &[_]u21{
0x1106,
} });
try instance.map.put(0x3142, .{ .compat = &[_]u21{
0x1107,
} });
try instance.map.put(0x3143, .{ .compat = &[_]u21{
0x1108,
} });
try instance.map.put(0x3144, .{ .compat = &[_]u21{
0x1121,
} });
try instance.map.put(0x3145, .{ .compat = &[_]u21{
0x1109,
} });
try instance.map.put(0x3146, .{ .compat = &[_]u21{
0x110A,
} });
try instance.map.put(0x3147, .{ .compat = &[_]u21{
0x110B,
} });
try instance.map.put(0x3148, .{ .compat = &[_]u21{
0x110C,
} });
try instance.map.put(0x3149, .{ .compat = &[_]u21{
0x110D,
} });
try instance.map.put(0x314A, .{ .compat = &[_]u21{
0x110E,
} });
try instance.map.put(0x314B, .{ .compat = &[_]u21{
0x110F,
} });
try instance.map.put(0x314C, .{ .compat = &[_]u21{
0x1110,
} });
try instance.map.put(0x314D, .{ .compat = &[_]u21{
0x1111,
} });
try instance.map.put(0x314E, .{ .compat = &[_]u21{
0x1112,
} });
try instance.map.put(0x314F, .{ .compat = &[_]u21{
0x1161,
} });
try instance.map.put(0x3150, .{ .compat = &[_]u21{
0x1162,
} });
try instance.map.put(0x3151, .{ .compat = &[_]u21{
0x1163,
} });
try instance.map.put(0x3152, .{ .compat = &[_]u21{
0x1164,
} });
try instance.map.put(0x3153, .{ .compat = &[_]u21{
0x1165,
} });
try instance.map.put(0x3154, .{ .compat = &[_]u21{
0x1166,
} });
try instance.map.put(0x3155, .{ .compat = &[_]u21{
0x1167,
} });
try instance.map.put(0x3156, .{ .compat = &[_]u21{
0x1168,
} });
try instance.map.put(0x3157, .{ .compat = &[_]u21{
0x1169,
} });
try instance.map.put(0x3158, .{ .compat = &[_]u21{
0x116A,
} });
try instance.map.put(0x3159, .{ .compat = &[_]u21{
0x116B,
} });
try instance.map.put(0x315A, .{ .compat = &[_]u21{
0x116C,
} });
try instance.map.put(0x315B, .{ .compat = &[_]u21{
0x116D,
} });
try instance.map.put(0x315C, .{ .compat = &[_]u21{
0x116E,
} });
try instance.map.put(0x315D, .{ .compat = &[_]u21{
0x116F,
} });
try instance.map.put(0x315E, .{ .compat = &[_]u21{
0x1170,
} });
try instance.map.put(0x315F, .{ .compat = &[_]u21{
0x1171,
} });
try instance.map.put(0x3160, .{ .compat = &[_]u21{
0x1172,
} });
try instance.map.put(0x3161, .{ .compat = &[_]u21{
0x1173,
} });
try instance.map.put(0x3162, .{ .compat = &[_]u21{
0x1174,
} });
try instance.map.put(0x3163, .{ .compat = &[_]u21{
0x1175,
} });
try instance.map.put(0x3164, .{ .compat = &[_]u21{
0x1160,
} });
try instance.map.put(0x3165, .{ .compat = &[_]u21{
0x1114,
} });
try instance.map.put(0x3166, .{ .compat = &[_]u21{
0x1115,
} });
try instance.map.put(0x3167, .{ .compat = &[_]u21{
0x11C7,
} });
try instance.map.put(0x3168, .{ .compat = &[_]u21{
0x11C8,
} });
try instance.map.put(0x3169, .{ .compat = &[_]u21{
0x11CC,
} });
try instance.map.put(0x316A, .{ .compat = &[_]u21{
0x11CE,
} });
try instance.map.put(0x316B, .{ .compat = &[_]u21{
0x11D3,
} });
try instance.map.put(0x316C, .{ .compat = &[_]u21{
0x11D7,
} });
try instance.map.put(0x316D, .{ .compat = &[_]u21{
0x11D9,
} });
try instance.map.put(0x316E, .{ .compat = &[_]u21{
0x111C,
} });
try instance.map.put(0x316F, .{ .compat = &[_]u21{
0x11DD,
} });
try instance.map.put(0x3170, .{ .compat = &[_]u21{
0x11DF,
} });
try instance.map.put(0x3171, .{ .compat = &[_]u21{
0x111D,
} });
try instance.map.put(0x3172, .{ .compat = &[_]u21{
0x111E,
} });
try instance.map.put(0x3173, .{ .compat = &[_]u21{
0x1120,
} });
try instance.map.put(0x3174, .{ .compat = &[_]u21{
0x1122,
} });
try instance.map.put(0x3175, .{ .compat = &[_]u21{
0x1123,
} });
try instance.map.put(0x3176, .{ .compat = &[_]u21{
0x1127,
} });
try instance.map.put(0x3177, .{ .compat = &[_]u21{
0x1129,
} });
try instance.map.put(0x3178, .{ .compat = &[_]u21{
0x112B,
} });
try instance.map.put(0x3179, .{ .compat = &[_]u21{
0x112C,
} });
try instance.map.put(0x317A, .{ .compat = &[_]u21{
0x112D,
} });
try instance.map.put(0x317B, .{ .compat = &[_]u21{
0x112E,
} });
try instance.map.put(0x317C, .{ .compat = &[_]u21{
0x112F,
} });
try instance.map.put(0x317D, .{ .compat = &[_]u21{
0x1132,
} });
try instance.map.put(0x317E, .{ .compat = &[_]u21{
0x1136,
} });
try instance.map.put(0x317F, .{ .compat = &[_]u21{
0x1140,
} });
try instance.map.put(0x3180, .{ .compat = &[_]u21{
0x1147,
} });
try instance.map.put(0x3181, .{ .compat = &[_]u21{
0x114C,
} });
try instance.map.put(0x3182, .{ .compat = &[_]u21{
0x11F1,
} });
try instance.map.put(0x3183, .{ .compat = &[_]u21{
0x11F2,
} });
try instance.map.put(0x3184, .{ .compat = &[_]u21{
0x1157,
} });
try instance.map.put(0x3185, .{ .compat = &[_]u21{
0x1158,
} });
try instance.map.put(0x3186, .{ .compat = &[_]u21{
0x1159,
} });
try instance.map.put(0x3187, .{ .compat = &[_]u21{
0x1184,
} });
try instance.map.put(0x3188, .{ .compat = &[_]u21{
0x1185,
} });
try instance.map.put(0x3189, .{ .compat = &[_]u21{
0x1188,
} });
try instance.map.put(0x318A, .{ .compat = &[_]u21{
0x1191,
} });
try instance.map.put(0x318B, .{ .compat = &[_]u21{
0x1192,
} });
try instance.map.put(0x318C, .{ .compat = &[_]u21{
0x1194,
} });
try instance.map.put(0x318D, .{ .compat = &[_]u21{
0x119E,
} });
try instance.map.put(0x318E, .{ .compat = &[_]u21{
0x11A1,
} });
try instance.map.put(0x3192, .{ .compat = &[_]u21{
0x4E00,
} });
try instance.map.put(0x3193, .{ .compat = &[_]u21{
0x4E8C,
} });
try instance.map.put(0x3194, .{ .compat = &[_]u21{
0x4E09,
} });
try instance.map.put(0x3195, .{ .compat = &[_]u21{
0x56DB,
} });
try instance.map.put(0x3196, .{ .compat = &[_]u21{
0x4E0A,
} });
try instance.map.put(0x3197, .{ .compat = &[_]u21{
0x4E2D,
} });
try instance.map.put(0x3198, .{ .compat = &[_]u21{
0x4E0B,
} });
try instance.map.put(0x3199, .{ .compat = &[_]u21{
0x7532,
} });
try instance.map.put(0x319A, .{ .compat = &[_]u21{
0x4E59,
} });
try instance.map.put(0x319B, .{ .compat = &[_]u21{
0x4E19,
} });
try instance.map.put(0x319C, .{ .compat = &[_]u21{
0x4E01,
} });
try instance.map.put(0x319D, .{ .compat = &[_]u21{
0x5929,
} });
try instance.map.put(0x319E, .{ .compat = &[_]u21{
0x5730,
} });
try instance.map.put(0x319F, .{ .compat = &[_]u21{
0x4EBA,
} });
try instance.map.put(0x3200, .{ .compat = &[_]u21{
0x0028,
0x1100,
0x0029,
} });
try instance.map.put(0x3201, .{ .compat = &[_]u21{
0x0028,
0x1102,
0x0029,
} });
try instance.map.put(0x3202, .{ .compat = &[_]u21{
0x0028,
0x1103,
0x0029,
} });
try instance.map.put(0x3203, .{ .compat = &[_]u21{
0x0028,
0x1105,
0x0029,
} });
try instance.map.put(0x3204, .{ .compat = &[_]u21{
0x0028,
0x1106,
0x0029,
} });
try instance.map.put(0x3205, .{ .compat = &[_]u21{
0x0028,
0x1107,
0x0029,
} });
try instance.map.put(0x3206, .{ .compat = &[_]u21{
0x0028,
0x1109,
0x0029,
} });
try instance.map.put(0x3207, .{ .compat = &[_]u21{
0x0028,
0x110B,
0x0029,
} });
try instance.map.put(0x3208, .{ .compat = &[_]u21{
0x0028,
0x110C,
0x0029,
} });
try instance.map.put(0x3209, .{ .compat = &[_]u21{
0x0028,
0x110E,
0x0029,
} });
try instance.map.put(0x320A, .{ .compat = &[_]u21{
0x0028,
0x110F,
0x0029,
} });
try instance.map.put(0x320B, .{ .compat = &[_]u21{
0x0028,
0x1110,
0x0029,
} });
try instance.map.put(0x320C, .{ .compat = &[_]u21{
0x0028,
0x1111,
0x0029,
} });
try instance.map.put(0x320D, .{ .compat = &[_]u21{
0x0028,
0x1112,
0x0029,
} });
try instance.map.put(0x320E, .{ .compat = &[_]u21{
0x0028,
0x1100,
0x1161,
0x0029,
} });
try instance.map.put(0x320F, .{ .compat = &[_]u21{
0x0028,
0x1102,
0x1161,
0x0029,
} });
try instance.map.put(0x3210, .{ .compat = &[_]u21{
0x0028,
0x1103,
0x1161,
0x0029,
} });
try instance.map.put(0x3211, .{ .compat = &[_]u21{
0x0028,
0x1105,
0x1161,
0x0029,
} });
try instance.map.put(0x3212, .{ .compat = &[_]u21{
0x0028,
0x1106,
0x1161,
0x0029,
} });
try instance.map.put(0x3213, .{ .compat = &[_]u21{
0x0028,
0x1107,
0x1161,
0x0029,
} });
try instance.map.put(0x3214, .{ .compat = &[_]u21{
0x0028,
0x1109,
0x1161,
0x0029,
} });
try instance.map.put(0x3215, .{ .compat = &[_]u21{
0x0028,
0x110B,
0x1161,
0x0029,
} });
try instance.map.put(0x3216, .{ .compat = &[_]u21{
0x0028,
0x110C,
0x1161,
0x0029,
} });
try instance.map.put(0x3217, .{ .compat = &[_]u21{
0x0028,
0x110E,
0x1161,
0x0029,
} });
try instance.map.put(0x3218, .{ .compat = &[_]u21{
0x0028,
0x110F,
0x1161,
0x0029,
} });
try instance.map.put(0x3219, .{ .compat = &[_]u21{
0x0028,
0x1110,
0x1161,
0x0029,
} });
try instance.map.put(0x321A, .{ .compat = &[_]u21{
0x0028,
0x1111,
0x1161,
0x0029,
} });
try instance.map.put(0x321B, .{ .compat = &[_]u21{
0x0028,
0x1112,
0x1161,
0x0029,
} });
try instance.map.put(0x321C, .{ .compat = &[_]u21{
0x0028,
0x110C,
0x116E,
0x0029,
} });
try instance.map.put(0x321D, .{ .compat = &[_]u21{
0x0028,
0x110B,
0x1169,
0x110C,
0x1165,
0x11AB,
0x0029,
} });
try instance.map.put(0x321E, .{ .compat = &[_]u21{
0x0028,
0x110B,
0x1169,
0x1112,
0x116E,
0x0029,
} });
try instance.map.put(0x3220, .{ .compat = &[_]u21{
0x0028,
0x4E00,
0x0029,
} });
try instance.map.put(0x3221, .{ .compat = &[_]u21{
0x0028,
0x4E8C,
0x0029,
} });
try instance.map.put(0x3222, .{ .compat = &[_]u21{
0x0028,
0x4E09,
0x0029,
} });
try instance.map.put(0x3223, .{ .compat = &[_]u21{
0x0028,
0x56DB,
0x0029,
} });
try instance.map.put(0x3224, .{ .compat = &[_]u21{
0x0028,
0x4E94,
0x0029,
} });
try instance.map.put(0x3225, .{ .compat = &[_]u21{
0x0028,
0x516D,
0x0029,
} });
try instance.map.put(0x3226, .{ .compat = &[_]u21{
0x0028,
0x4E03,
0x0029,
} });
try instance.map.put(0x3227, .{ .compat = &[_]u21{
0x0028,
0x516B,
0x0029,
} });
try instance.map.put(0x3228, .{ .compat = &[_]u21{
0x0028,
0x4E5D,
0x0029,
} });
try instance.map.put(0x3229, .{ .compat = &[_]u21{
0x0028,
0x5341,
0x0029,
} });
try instance.map.put(0x322A, .{ .compat = &[_]u21{
0x0028,
0x6708,
0x0029,
} });
try instance.map.put(0x322B, .{ .compat = &[_]u21{
0x0028,
0x706B,
0x0029,
} });
try instance.map.put(0x322C, .{ .compat = &[_]u21{
0x0028,
0x6C34,
0x0029,
} });
try instance.map.put(0x322D, .{ .compat = &[_]u21{
0x0028,
0x6728,
0x0029,
} });
try instance.map.put(0x322E, .{ .compat = &[_]u21{
0x0028,
0x91D1,
0x0029,
} });
try instance.map.put(0x322F, .{ .compat = &[_]u21{
0x0028,
0x571F,
0x0029,
} });
try instance.map.put(0x3230, .{ .compat = &[_]u21{
0x0028,
0x65E5,
0x0029,
} });
try instance.map.put(0x3231, .{ .compat = &[_]u21{
0x0028,
0x682A,
0x0029,
} });
try instance.map.put(0x3232, .{ .compat = &[_]u21{
0x0028,
0x6709,
0x0029,
} });
try instance.map.put(0x3233, .{ .compat = &[_]u21{
0x0028,
0x793E,
0x0029,
} });
try instance.map.put(0x3234, .{ .compat = &[_]u21{
0x0028,
0x540D,
0x0029,
} });
try instance.map.put(0x3235, .{ .compat = &[_]u21{
0x0028,
0x7279,
0x0029,
} });
try instance.map.put(0x3236, .{ .compat = &[_]u21{
0x0028,
0x8CA1,
0x0029,
} });
try instance.map.put(0x3237, .{ .compat = &[_]u21{
0x0028,
0x795D,
0x0029,
} });
try instance.map.put(0x3238, .{ .compat = &[_]u21{
0x0028,
0x52B4,
0x0029,
} });
try instance.map.put(0x3239, .{ .compat = &[_]u21{
0x0028,
0x4EE3,
0x0029,
} });
try instance.map.put(0x323A, .{ .compat = &[_]u21{
0x0028,
0x547C,
0x0029,
} });
try instance.map.put(0x323B, .{ .compat = &[_]u21{
0x0028,
0x5B66,
0x0029,
} });
try instance.map.put(0x323C, .{ .compat = &[_]u21{
0x0028,
0x76E3,
0x0029,
} });
try instance.map.put(0x323D, .{ .compat = &[_]u21{
0x0028,
0x4F01,
0x0029,
} });
try instance.map.put(0x323E, .{ .compat = &[_]u21{
0x0028,
0x8CC7,
0x0029,
} });
try instance.map.put(0x323F, .{ .compat = &[_]u21{
0x0028,
0x5354,
0x0029,
} });
try instance.map.put(0x3240, .{ .compat = &[_]u21{
0x0028,
0x796D,
0x0029,
} });
try instance.map.put(0x3241, .{ .compat = &[_]u21{
0x0028,
0x4F11,
0x0029,
} });
try instance.map.put(0x3242, .{ .compat = &[_]u21{
0x0028,
0x81EA,
0x0029,
} });
try instance.map.put(0x3243, .{ .compat = &[_]u21{
0x0028,
0x81F3,
0x0029,
} });
try instance.map.put(0x3244, .{ .compat = &[_]u21{
0x554F,
} });
try instance.map.put(0x3245, .{ .compat = &[_]u21{
0x5E7C,
} });
try instance.map.put(0x3246, .{ .compat = &[_]u21{
0x6587,
} });
try instance.map.put(0x3247, .{ .compat = &[_]u21{
0x7B8F,
} });
try instance.map.put(0x3250, .{ .compat = &[_]u21{
0x0050,
0x0054,
0x0045,
} });
try instance.map.put(0x3251, .{ .compat = &[_]u21{
0x0032,
0x0031,
} });
try instance.map.put(0x3252, .{ .compat = &[_]u21{
0x0032,
0x0032,
} });
try instance.map.put(0x3253, .{ .compat = &[_]u21{
0x0032,
0x0033,
} });
try instance.map.put(0x3254, .{ .compat = &[_]u21{
0x0032,
0x0034,
} });
try instance.map.put(0x3255, .{ .compat = &[_]u21{
0x0032,
0x0035,
} });
try instance.map.put(0x3256, .{ .compat = &[_]u21{
0x0032,
0x0036,
} });
try instance.map.put(0x3257, .{ .compat = &[_]u21{
0x0032,
0x0037,
} });
try instance.map.put(0x3258, .{ .compat = &[_]u21{
0x0032,
0x0038,
} });
try instance.map.put(0x3259, .{ .compat = &[_]u21{
0x0032,
0x0039,
} });
try instance.map.put(0x325A, .{ .compat = &[_]u21{
0x0033,
0x0030,
} });
try instance.map.put(0x325B, .{ .compat = &[_]u21{
0x0033,
0x0031,
} });
try instance.map.put(0x325C, .{ .compat = &[_]u21{
0x0033,
0x0032,
} });
try instance.map.put(0x325D, .{ .compat = &[_]u21{
0x0033,
0x0033,
} });
try instance.map.put(0x325E, .{ .compat = &[_]u21{
0x0033,
0x0034,
} });
try instance.map.put(0x325F, .{ .compat = &[_]u21{
0x0033,
0x0035,
} });
try instance.map.put(0x3260, .{ .compat = &[_]u21{
0x1100,
} });
try instance.map.put(0x3261, .{ .compat = &[_]u21{
0x1102,
} });
try instance.map.put(0x3262, .{ .compat = &[_]u21{
0x1103,
} });
try instance.map.put(0x3263, .{ .compat = &[_]u21{
0x1105,
} });
try instance.map.put(0x3264, .{ .compat = &[_]u21{
0x1106,
} });
try instance.map.put(0x3265, .{ .compat = &[_]u21{
0x1107,
} });
try instance.map.put(0x3266, .{ .compat = &[_]u21{
0x1109,
} });
try instance.map.put(0x3267, .{ .compat = &[_]u21{
0x110B,
} });
try instance.map.put(0x3268, .{ .compat = &[_]u21{
0x110C,
} });
try instance.map.put(0x3269, .{ .compat = &[_]u21{
0x110E,
} });
try instance.map.put(0x326A, .{ .compat = &[_]u21{
0x110F,
} });
try instance.map.put(0x326B, .{ .compat = &[_]u21{
0x1110,
} });
try instance.map.put(0x326C, .{ .compat = &[_]u21{
0x1111,
} });
try instance.map.put(0x326D, .{ .compat = &[_]u21{
0x1112,
} });
try instance.map.put(0x326E, .{ .compat = &[_]u21{
0x1100,
0x1161,
} });
try instance.map.put(0x326F, .{ .compat = &[_]u21{
0x1102,
0x1161,
} });
try instance.map.put(0x3270, .{ .compat = &[_]u21{
0x1103,
0x1161,
} });
try instance.map.put(0x3271, .{ .compat = &[_]u21{
0x1105,
0x1161,
} });
try instance.map.put(0x3272, .{ .compat = &[_]u21{
0x1106,
0x1161,
} });
try instance.map.put(0x3273, .{ .compat = &[_]u21{
0x1107,
0x1161,
} });
try instance.map.put(0x3274, .{ .compat = &[_]u21{
0x1109,
0x1161,
} });
try instance.map.put(0x3275, .{ .compat = &[_]u21{
0x110B,
0x1161,
} });
try instance.map.put(0x3276, .{ .compat = &[_]u21{
0x110C,
0x1161,
} });
try instance.map.put(0x3277, .{ .compat = &[_]u21{
0x110E,
0x1161,
} });
try instance.map.put(0x3278, .{ .compat = &[_]u21{
0x110F,
0x1161,
} });
try instance.map.put(0x3279, .{ .compat = &[_]u21{
0x1110,
0x1161,
} });
try instance.map.put(0x327A, .{ .compat = &[_]u21{
0x1111,
0x1161,
} });
try instance.map.put(0x327B, .{ .compat = &[_]u21{
0x1112,
0x1161,
} });
try instance.map.put(0x327C, .{ .compat = &[_]u21{
0x110E,
0x1161,
0x11B7,
0x1100,
0x1169,
} });
try instance.map.put(0x327D, .{ .compat = &[_]u21{
0x110C,
0x116E,
0x110B,
0x1174,
} });
try instance.map.put(0x327E, .{ .compat = &[_]u21{
0x110B,
0x116E,
} });
try instance.map.put(0x3280, .{ .compat = &[_]u21{
0x4E00,
} });
try instance.map.put(0x3281, .{ .compat = &[_]u21{
0x4E8C,
} });
try instance.map.put(0x3282, .{ .compat = &[_]u21{
0x4E09,
} });
try instance.map.put(0x3283, .{ .compat = &[_]u21{
0x56DB,
} });
try instance.map.put(0x3284, .{ .compat = &[_]u21{
0x4E94,
} });
try instance.map.put(0x3285, .{ .compat = &[_]u21{
0x516D,
} });
try instance.map.put(0x3286, .{ .compat = &[_]u21{
0x4E03,
} });
try instance.map.put(0x3287, .{ .compat = &[_]u21{
0x516B,
} });
try instance.map.put(0x3288, .{ .compat = &[_]u21{
0x4E5D,
} });
try instance.map.put(0x3289, .{ .compat = &[_]u21{
0x5341,
} });
try instance.map.put(0x328A, .{ .compat = &[_]u21{
0x6708,
} });
try instance.map.put(0x328B, .{ .compat = &[_]u21{
0x706B,
} });
try instance.map.put(0x328C, .{ .compat = &[_]u21{
0x6C34,
} });
try instance.map.put(0x328D, .{ .compat = &[_]u21{
0x6728,
} });
try instance.map.put(0x328E, .{ .compat = &[_]u21{
0x91D1,
} });
try instance.map.put(0x328F, .{ .compat = &[_]u21{
0x571F,
} });
try instance.map.put(0x3290, .{ .compat = &[_]u21{
0x65E5,
} });
try instance.map.put(0x3291, .{ .compat = &[_]u21{
0x682A,
} });
try instance.map.put(0x3292, .{ .compat = &[_]u21{
0x6709,
} });
try instance.map.put(0x3293, .{ .compat = &[_]u21{
0x793E,
} });
try instance.map.put(0x3294, .{ .compat = &[_]u21{
0x540D,
} });
try instance.map.put(0x3295, .{ .compat = &[_]u21{
0x7279,
} });
try instance.map.put(0x3296, .{ .compat = &[_]u21{
0x8CA1,
} });
try instance.map.put(0x3297, .{ .compat = &[_]u21{
0x795D,
} });
try instance.map.put(0x3298, .{ .compat = &[_]u21{
0x52B4,
} });
try instance.map.put(0x3299, .{ .compat = &[_]u21{
0x79D8,
} });
try instance.map.put(0x329A, .{ .compat = &[_]u21{
0x7537,
} });
try instance.map.put(0x329B, .{ .compat = &[_]u21{
0x5973,
} });
try instance.map.put(0x329C, .{ .compat = &[_]u21{
0x9069,
} });
try instance.map.put(0x329D, .{ .compat = &[_]u21{
0x512A,
} });
try instance.map.put(0x329E, .{ .compat = &[_]u21{
0x5370,
} });
try instance.map.put(0x329F, .{ .compat = &[_]u21{
0x6CE8,
} });
try instance.map.put(0x32A0, .{ .compat = &[_]u21{
0x9805,
} });
try instance.map.put(0x32A1, .{ .compat = &[_]u21{
0x4F11,
} });
try instance.map.put(0x32A2, .{ .compat = &[_]u21{
0x5199,
} });
try instance.map.put(0x32A3, .{ .compat = &[_]u21{
0x6B63,
} });
try instance.map.put(0x32A4, .{ .compat = &[_]u21{
0x4E0A,
} });
try instance.map.put(0x32A5, .{ .compat = &[_]u21{
0x4E2D,
} });
try instance.map.put(0x32A6, .{ .compat = &[_]u21{
0x4E0B,
} });
try instance.map.put(0x32A7, .{ .compat = &[_]u21{
0x5DE6,
} });
try instance.map.put(0x32A8, .{ .compat = &[_]u21{
0x53F3,
} });
try instance.map.put(0x32A9, .{ .compat = &[_]u21{
0x533B,
} });
try instance.map.put(0x32AA, .{ .compat = &[_]u21{
0x5B97,
} });
try instance.map.put(0x32AB, .{ .compat = &[_]u21{
0x5B66,
} });
try instance.map.put(0x32AC, .{ .compat = &[_]u21{
0x76E3,
} });
try instance.map.put(0x32AD, .{ .compat = &[_]u21{
0x4F01,
} });
try instance.map.put(0x32AE, .{ .compat = &[_]u21{
0x8CC7,
} });
try instance.map.put(0x32AF, .{ .compat = &[_]u21{
0x5354,
} });
try instance.map.put(0x32B0, .{ .compat = &[_]u21{
0x591C,
} });
try instance.map.put(0x32B1, .{ .compat = &[_]u21{
0x0033,
0x0036,
} });
try instance.map.put(0x32B2, .{ .compat = &[_]u21{
0x0033,
0x0037,
} });
try instance.map.put(0x32B3, .{ .compat = &[_]u21{
0x0033,
0x0038,
} });
try instance.map.put(0x32B4, .{ .compat = &[_]u21{
0x0033,
0x0039,
} });
try instance.map.put(0x32B5, .{ .compat = &[_]u21{
0x0034,
0x0030,
} });
try instance.map.put(0x32B6, .{ .compat = &[_]u21{
0x0034,
0x0031,
} });
try instance.map.put(0x32B7, .{ .compat = &[_]u21{
0x0034,
0x0032,
} });
try instance.map.put(0x32B8, .{ .compat = &[_]u21{
0x0034,
0x0033,
} });
try instance.map.put(0x32B9, .{ .compat = &[_]u21{
0x0034,
0x0034,
} });
try instance.map.put(0x32BA, .{ .compat = &[_]u21{
0x0034,
0x0035,
} });
try instance.map.put(0x32BB, .{ .compat = &[_]u21{
0x0034,
0x0036,
} });
try instance.map.put(0x32BC, .{ .compat = &[_]u21{
0x0034,
0x0037,
} });
try instance.map.put(0x32BD, .{ .compat = &[_]u21{
0x0034,
0x0038,
} });
try instance.map.put(0x32BE, .{ .compat = &[_]u21{
0x0034,
0x0039,
} });
try instance.map.put(0x32BF, .{ .compat = &[_]u21{
0x0035,
0x0030,
} });
try instance.map.put(0x32C0, .{ .compat = &[_]u21{
0x0031,
0x6708,
} });
try instance.map.put(0x32C1, .{ .compat = &[_]u21{
0x0032,
0x6708,
} });
try instance.map.put(0x32C2, .{ .compat = &[_]u21{
0x0033,
0x6708,
} });
try instance.map.put(0x32C3, .{ .compat = &[_]u21{
0x0034,
0x6708,
} });
try instance.map.put(0x32C4, .{ .compat = &[_]u21{
0x0035,
0x6708,
} });
try instance.map.put(0x32C5, .{ .compat = &[_]u21{
0x0036,
0x6708,
} });
try instance.map.put(0x32C6, .{ .compat = &[_]u21{
0x0037,
0x6708,
} });
try instance.map.put(0x32C7, .{ .compat = &[_]u21{
0x0038,
0x6708,
} });
try instance.map.put(0x32C8, .{ .compat = &[_]u21{
0x0039,
0x6708,
} });
try instance.map.put(0x32C9, .{ .compat = &[_]u21{
0x0031,
0x0030,
0x6708,
} });
try instance.map.put(0x32CA, .{ .compat = &[_]u21{
0x0031,
0x0031,
0x6708,
} });
try instance.map.put(0x32CB, .{ .compat = &[_]u21{
0x0031,
0x0032,
0x6708,
} });
try instance.map.put(0x32CC, .{ .compat = &[_]u21{
0x0048,
0x0067,
} });
try instance.map.put(0x32CD, .{ .compat = &[_]u21{
0x0065,
0x0072,
0x0067,
} });
try instance.map.put(0x32CE, .{ .compat = &[_]u21{
0x0065,
0x0056,
} });
try instance.map.put(0x32CF, .{ .compat = &[_]u21{
0x004C,
0x0054,
0x0044,
} });
try instance.map.put(0x32D0, .{ .compat = &[_]u21{
0x30A2,
} });
try instance.map.put(0x32D1, .{ .compat = &[_]u21{
0x30A4,
} });
try instance.map.put(0x32D2, .{ .compat = &[_]u21{
0x30A6,
} });
try instance.map.put(0x32D3, .{ .compat = &[_]u21{
0x30A8,
} });
try instance.map.put(0x32D4, .{ .compat = &[_]u21{
0x30AA,
} });
try instance.map.put(0x32D5, .{ .compat = &[_]u21{
0x30AB,
} });
try instance.map.put(0x32D6, .{ .compat = &[_]u21{
0x30AD,
} });
try instance.map.put(0x32D7, .{ .compat = &[_]u21{
0x30AF,
} });
try instance.map.put(0x32D8, .{ .compat = &[_]u21{
0x30B1,
} });
try instance.map.put(0x32D9, .{ .compat = &[_]u21{
0x30B3,
} });
try instance.map.put(0x32DA, .{ .compat = &[_]u21{
0x30B5,
} });
try instance.map.put(0x32DB, .{ .compat = &[_]u21{
0x30B7,
} });
try instance.map.put(0x32DC, .{ .compat = &[_]u21{
0x30B9,
} });
try instance.map.put(0x32DD, .{ .compat = &[_]u21{
0x30BB,
} });
try instance.map.put(0x32DE, .{ .compat = &[_]u21{
0x30BD,
} });
try instance.map.put(0x32DF, .{ .compat = &[_]u21{
0x30BF,
} });
try instance.map.put(0x32E0, .{ .compat = &[_]u21{
0x30C1,
} });
try instance.map.put(0x32E1, .{ .compat = &[_]u21{
0x30C4,
} });
try instance.map.put(0x32E2, .{ .compat = &[_]u21{
0x30C6,
} });
try instance.map.put(0x32E3, .{ .compat = &[_]u21{
0x30C8,
} });
try instance.map.put(0x32E4, .{ .compat = &[_]u21{
0x30CA,
} });
try instance.map.put(0x32E5, .{ .compat = &[_]u21{
0x30CB,
} });
try instance.map.put(0x32E6, .{ .compat = &[_]u21{
0x30CC,
} });
try instance.map.put(0x32E7, .{ .compat = &[_]u21{
0x30CD,
} });
try instance.map.put(0x32E8, .{ .compat = &[_]u21{
0x30CE,
} });
try instance.map.put(0x32E9, .{ .compat = &[_]u21{
0x30CF,
} });
try instance.map.put(0x32EA, .{ .compat = &[_]u21{
0x30D2,
} });
try instance.map.put(0x32EB, .{ .compat = &[_]u21{
0x30D5,
} });
try instance.map.put(0x32EC, .{ .compat = &[_]u21{
0x30D8,
} });
try instance.map.put(0x32ED, .{ .compat = &[_]u21{
0x30DB,
} });
try instance.map.put(0x32EE, .{ .compat = &[_]u21{
0x30DE,
} });
try instance.map.put(0x32EF, .{ .compat = &[_]u21{
0x30DF,
} });
try instance.map.put(0x32F0, .{ .compat = &[_]u21{
0x30E0,
} });
try instance.map.put(0x32F1, .{ .compat = &[_]u21{
0x30E1,
} });
try instance.map.put(0x32F2, .{ .compat = &[_]u21{
0x30E2,
} });
try instance.map.put(0x32F3, .{ .compat = &[_]u21{
0x30E4,
} });
try instance.map.put(0x32F4, .{ .compat = &[_]u21{
0x30E6,
} });
try instance.map.put(0x32F5, .{ .compat = &[_]u21{
0x30E8,
} });
try instance.map.put(0x32F6, .{ .compat = &[_]u21{
0x30E9,
} });
try instance.map.put(0x32F7, .{ .compat = &[_]u21{
0x30EA,
} });
try instance.map.put(0x32F8, .{ .compat = &[_]u21{
0x30EB,
} });
try instance.map.put(0x32F9, .{ .compat = &[_]u21{
0x30EC,
} });
try instance.map.put(0x32FA, .{ .compat = &[_]u21{
0x30ED,
} });
try instance.map.put(0x32FB, .{ .compat = &[_]u21{
0x30EF,
} });
try instance.map.put(0x32FC, .{ .compat = &[_]u21{
0x30F0,
} });
try instance.map.put(0x32FD, .{ .compat = &[_]u21{
0x30F1,
} });
try instance.map.put(0x32FE, .{ .compat = &[_]u21{
0x30F2,
} });
try instance.map.put(0x32FF, .{ .compat = &[_]u21{
0x4EE4,
0x548C,
} });
try instance.map.put(0x3300, .{ .compat = &[_]u21{
0x30A2,
0x30D1,
0x30FC,
0x30C8,
} });
try instance.map.put(0x3301, .{ .compat = &[_]u21{
0x30A2,
0x30EB,
0x30D5,
0x30A1,
} });
try instance.map.put(0x3302, .{ .compat = &[_]u21{
0x30A2,
0x30F3,
0x30DA,
0x30A2,
} });
try instance.map.put(0x3303, .{ .compat = &[_]u21{
0x30A2,
0x30FC,
0x30EB,
} });
try instance.map.put(0x3304, .{ .compat = &[_]u21{
0x30A4,
0x30CB,
0x30F3,
0x30B0,
} });
try instance.map.put(0x3305, .{ .compat = &[_]u21{
0x30A4,
0x30F3,
0x30C1,
} });
try instance.map.put(0x3306, .{ .compat = &[_]u21{
0x30A6,
0x30A9,
0x30F3,
} });
try instance.map.put(0x3307, .{ .compat = &[_]u21{
0x30A8,
0x30B9,
0x30AF,
0x30FC,
0x30C9,
} });
try instance.map.put(0x3308, .{ .compat = &[_]u21{
0x30A8,
0x30FC,
0x30AB,
0x30FC,
} });
try instance.map.put(0x3309, .{ .compat = &[_]u21{
0x30AA,
0x30F3,
0x30B9,
} });
try instance.map.put(0x330A, .{ .compat = &[_]u21{
0x30AA,
0x30FC,
0x30E0,
} });
try instance.map.put(0x330B, .{ .compat = &[_]u21{
0x30AB,
0x30A4,
0x30EA,
} });
try instance.map.put(0x330C, .{ .compat = &[_]u21{
0x30AB,
0x30E9,
0x30C3,
0x30C8,
} });
try instance.map.put(0x330D, .{ .compat = &[_]u21{
0x30AB,
0x30ED,
0x30EA,
0x30FC,
} });
try instance.map.put(0x330E, .{ .compat = &[_]u21{
0x30AC,
0x30ED,
0x30F3,
} });
try instance.map.put(0x330F, .{ .compat = &[_]u21{
0x30AC,
0x30F3,
0x30DE,
} });
try instance.map.put(0x3310, .{ .compat = &[_]u21{
0x30AE,
0x30AC,
} });
try instance.map.put(0x3311, .{ .compat = &[_]u21{
0x30AE,
0x30CB,
0x30FC,
} });
try instance.map.put(0x3312, .{ .compat = &[_]u21{
0x30AD,
0x30E5,
0x30EA,
0x30FC,
} });
try instance.map.put(0x3313, .{ .compat = &[_]u21{
0x30AE,
0x30EB,
0x30C0,
0x30FC,
} });
try instance.map.put(0x3314, .{ .compat = &[_]u21{
0x30AD,
0x30ED,
} });
try instance.map.put(0x3315, .{ .compat = &[_]u21{
0x30AD,
0x30ED,
0x30B0,
0x30E9,
0x30E0,
} });
try instance.map.put(0x3316, .{ .compat = &[_]u21{
0x30AD,
0x30ED,
0x30E1,
0x30FC,
0x30C8,
0x30EB,
} });
try instance.map.put(0x3317, .{ .compat = &[_]u21{
0x30AD,
0x30ED,
0x30EF,
0x30C3,
0x30C8,
} });
try instance.map.put(0x3318, .{ .compat = &[_]u21{
0x30B0,
0x30E9,
0x30E0,
} });
try instance.map.put(0x3319, .{ .compat = &[_]u21{
0x30B0,
0x30E9,
0x30E0,
0x30C8,
0x30F3,
} });
try instance.map.put(0x331A, .{ .compat = &[_]u21{
0x30AF,
0x30EB,
0x30BC,
0x30A4,
0x30ED,
} });
try instance.map.put(0x331B, .{ .compat = &[_]u21{
0x30AF,
0x30ED,
0x30FC,
0x30CD,
} });
try instance.map.put(0x331C, .{ .compat = &[_]u21{
0x30B1,
0x30FC,
0x30B9,
} });
try instance.map.put(0x331D, .{ .compat = &[_]u21{
0x30B3,
0x30EB,
0x30CA,
} });
try instance.map.put(0x331E, .{ .compat = &[_]u21{
0x30B3,
0x30FC,
0x30DD,
} });
try instance.map.put(0x331F, .{ .compat = &[_]u21{
0x30B5,
0x30A4,
0x30AF,
0x30EB,
} });
try instance.map.put(0x3320, .{ .compat = &[_]u21{
0x30B5,
0x30F3,
0x30C1,
0x30FC,
0x30E0,
} });
try instance.map.put(0x3321, .{ .compat = &[_]u21{
0x30B7,
0x30EA,
0x30F3,
0x30B0,
} });
try instance.map.put(0x3322, .{ .compat = &[_]u21{
0x30BB,
0x30F3,
0x30C1,
} });
try instance.map.put(0x3323, .{ .compat = &[_]u21{
0x30BB,
0x30F3,
0x30C8,
} });
try instance.map.put(0x3324, .{ .compat = &[_]u21{
0x30C0,
0x30FC,
0x30B9,
} });
try instance.map.put(0x3325, .{ .compat = &[_]u21{
0x30C7,
0x30B7,
} });
try instance.map.put(0x3326, .{ .compat = &[_]u21{
0x30C9,
0x30EB,
} });
try instance.map.put(0x3327, .{ .compat = &[_]u21{
0x30C8,
0x30F3,
} });
try instance.map.put(0x3328, .{ .compat = &[_]u21{
0x30CA,
0x30CE,
} });
try instance.map.put(0x3329, .{ .compat = &[_]u21{
0x30CE,
0x30C3,
0x30C8,
} });
try instance.map.put(0x332A, .{ .compat = &[_]u21{
0x30CF,
0x30A4,
0x30C4,
} });
try instance.map.put(0x332B, .{ .compat = &[_]u21{
0x30D1,
0x30FC,
0x30BB,
0x30F3,
0x30C8,
} });
try instance.map.put(0x332C, .{ .compat = &[_]u21{
0x30D1,
0x30FC,
0x30C4,
} });
try instance.map.put(0x332D, .{ .compat = &[_]u21{
0x30D0,
0x30FC,
0x30EC,
0x30EB,
} });
try instance.map.put(0x332E, .{ .compat = &[_]u21{
0x30D4,
0x30A2,
0x30B9,
0x30C8,
0x30EB,
} });
try instance.map.put(0x332F, .{ .compat = &[_]u21{
0x30D4,
0x30AF,
0x30EB,
} });
try instance.map.put(0x3330, .{ .compat = &[_]u21{
0x30D4,
0x30B3,
} });
try instance.map.put(0x3331, .{ .compat = &[_]u21{
0x30D3,
0x30EB,
} });
try instance.map.put(0x3332, .{ .compat = &[_]u21{
0x30D5,
0x30A1,
0x30E9,
0x30C3,
0x30C9,
} });
try instance.map.put(0x3333, .{ .compat = &[_]u21{
0x30D5,
0x30A3,
0x30FC,
0x30C8,
} });
try instance.map.put(0x3334, .{ .compat = &[_]u21{
0x30D6,
0x30C3,
0x30B7,
0x30A7,
0x30EB,
} });
try instance.map.put(0x3335, .{ .compat = &[_]u21{
0x30D5,
0x30E9,
0x30F3,
} });
try instance.map.put(0x3336, .{ .compat = &[_]u21{
0x30D8,
0x30AF,
0x30BF,
0x30FC,
0x30EB,
} });
try instance.map.put(0x3337, .{ .compat = &[_]u21{
0x30DA,
0x30BD,
} });
try instance.map.put(0x3338, .{ .compat = &[_]u21{
0x30DA,
0x30CB,
0x30D2,
} });
try instance.map.put(0x3339, .{ .compat = &[_]u21{
0x30D8,
0x30EB,
0x30C4,
} });
try instance.map.put(0x333A, .{ .compat = &[_]u21{
0x30DA,
0x30F3,
0x30B9,
} });
try instance.map.put(0x333B, .{ .compat = &[_]u21{
0x30DA,
0x30FC,
0x30B8,
} });
try instance.map.put(0x333C, .{ .compat = &[_]u21{
0x30D9,
0x30FC,
0x30BF,
} });
try instance.map.put(0x333D, .{ .compat = &[_]u21{
0x30DD,
0x30A4,
0x30F3,
0x30C8,
} });
try instance.map.put(0x333E, .{ .compat = &[_]u21{
0x30DC,
0x30EB,
0x30C8,
} });
try instance.map.put(0x333F, .{ .compat = &[_]u21{
0x30DB,
0x30F3,
} });
try instance.map.put(0x3340, .{ .compat = &[_]u21{
0x30DD,
0x30F3,
0x30C9,
} });
try instance.map.put(0x3341, .{ .compat = &[_]u21{
0x30DB,
0x30FC,
0x30EB,
} });
try instance.map.put(0x3342, .{ .compat = &[_]u21{
0x30DB,
0x30FC,
0x30F3,
} });
try instance.map.put(0x3343, .{ .compat = &[_]u21{
0x30DE,
0x30A4,
0x30AF,
0x30ED,
} });
try instance.map.put(0x3344, .{ .compat = &[_]u21{
0x30DE,
0x30A4,
0x30EB,
} });
try instance.map.put(0x3345, .{ .compat = &[_]u21{
0x30DE,
0x30C3,
0x30CF,
} });
try instance.map.put(0x3346, .{ .compat = &[_]u21{
0x30DE,
0x30EB,
0x30AF,
} });
try instance.map.put(0x3347, .{ .compat = &[_]u21{
0x30DE,
0x30F3,
0x30B7,
0x30E7,
0x30F3,
} });
try instance.map.put(0x3348, .{ .compat = &[_]u21{
0x30DF,
0x30AF,
0x30ED,
0x30F3,
} });
try instance.map.put(0x3349, .{ .compat = &[_]u21{
0x30DF,
0x30EA,
} });
try instance.map.put(0x334A, .{ .compat = &[_]u21{
0x30DF,
0x30EA,
0x30D0,
0x30FC,
0x30EB,
} });
try instance.map.put(0x334B, .{ .compat = &[_]u21{
0x30E1,
0x30AC,
} });
try instance.map.put(0x334C, .{ .compat = &[_]u21{
0x30E1,
0x30AC,
0x30C8,
0x30F3,
} });
try instance.map.put(0x334D, .{ .compat = &[_]u21{
0x30E1,
0x30FC,
0x30C8,
0x30EB,
} });
try instance.map.put(0x334E, .{ .compat = &[_]u21{
0x30E4,
0x30FC,
0x30C9,
} });
try instance.map.put(0x334F, .{ .compat = &[_]u21{
0x30E4,
0x30FC,
0x30EB,
} });
try instance.map.put(0x3350, .{ .compat = &[_]u21{
0x30E6,
0x30A2,
0x30F3,
} });
try instance.map.put(0x3351, .{ .compat = &[_]u21{
0x30EA,
0x30C3,
0x30C8,
0x30EB,
} });
try instance.map.put(0x3352, .{ .compat = &[_]u21{
0x30EA,
0x30E9,
} });
try instance.map.put(0x3353, .{ .compat = &[_]u21{
0x30EB,
0x30D4,
0x30FC,
} });
try instance.map.put(0x3354, .{ .compat = &[_]u21{
0x30EB,
0x30FC,
0x30D6,
0x30EB,
} });
try instance.map.put(0x3355, .{ .compat = &[_]u21{
0x30EC,
0x30E0,
} });
try instance.map.put(0x3356, .{ .compat = &[_]u21{
0x30EC,
0x30F3,
0x30C8,
0x30B2,
0x30F3,
} });
try instance.map.put(0x3357, .{ .compat = &[_]u21{
0x30EF,
0x30C3,
0x30C8,
} });
try instance.map.put(0x3358, .{ .compat = &[_]u21{
0x0030,
0x70B9,
} });
try instance.map.put(0x3359, .{ .compat = &[_]u21{
0x0031,
0x70B9,
} });
try instance.map.put(0x335A, .{ .compat = &[_]u21{
0x0032,
0x70B9,
} });
try instance.map.put(0x335B, .{ .compat = &[_]u21{
0x0033,
0x70B9,
} });
try instance.map.put(0x335C, .{ .compat = &[_]u21{
0x0034,
0x70B9,
} });
try instance.map.put(0x335D, .{ .compat = &[_]u21{
0x0035,
0x70B9,
} });
try instance.map.put(0x335E, .{ .compat = &[_]u21{
0x0036,
0x70B9,
} });
try instance.map.put(0x335F, .{ .compat = &[_]u21{
0x0037,
0x70B9,
} });
try instance.map.put(0x3360, .{ .compat = &[_]u21{
0x0038,
0x70B9,
} });
try instance.map.put(0x3361, .{ .compat = &[_]u21{
0x0039,
0x70B9,
} });
try instance.map.put(0x3362, .{ .compat = &[_]u21{
0x0031,
0x0030,
0x70B9,
} });
try instance.map.put(0x3363, .{ .compat = &[_]u21{
0x0031,
0x0031,
0x70B9,
} });
try instance.map.put(0x3364, .{ .compat = &[_]u21{
0x0031,
0x0032,
0x70B9,
} });
try instance.map.put(0x3365, .{ .compat = &[_]u21{
0x0031,
0x0033,
0x70B9,
} });
try instance.map.put(0x3366, .{ .compat = &[_]u21{
0x0031,
0x0034,
0x70B9,
} });
try instance.map.put(0x3367, .{ .compat = &[_]u21{
0x0031,
0x0035,
0x70B9,
} });
try instance.map.put(0x3368, .{ .compat = &[_]u21{
0x0031,
0x0036,
0x70B9,
} });
try instance.map.put(0x3369, .{ .compat = &[_]u21{
0x0031,
0x0037,
0x70B9,
} });
try instance.map.put(0x336A, .{ .compat = &[_]u21{
0x0031,
0x0038,
0x70B9,
} });
try instance.map.put(0x336B, .{ .compat = &[_]u21{
0x0031,
0x0039,
0x70B9,
} });
try instance.map.put(0x336C, .{ .compat = &[_]u21{
0x0032,
0x0030,
0x70B9,
} });
try instance.map.put(0x336D, .{ .compat = &[_]u21{
0x0032,
0x0031,
0x70B9,
} });
try instance.map.put(0x336E, .{ .compat = &[_]u21{
0x0032,
0x0032,
0x70B9,
} });
try instance.map.put(0x336F, .{ .compat = &[_]u21{
0x0032,
0x0033,
0x70B9,
} });
try instance.map.put(0x3370, .{ .compat = &[_]u21{
0x0032,
0x0034,
0x70B9,
} });
try instance.map.put(0x3371, .{ .compat = &[_]u21{
0x0068,
0x0050,
0x0061,
} });
try instance.map.put(0x3372, .{ .compat = &[_]u21{
0x0064,
0x0061,
} });
try instance.map.put(0x3373, .{ .compat = &[_]u21{
0x0041,
0x0055,
} });
try instance.map.put(0x3374, .{ .compat = &[_]u21{
0x0062,
0x0061,
0x0072,
} });
try instance.map.put(0x3375, .{ .compat = &[_]u21{
0x006F,
0x0056,
} });
try instance.map.put(0x3376, .{ .compat = &[_]u21{
0x0070,
0x0063,
} });
try instance.map.put(0x3377, .{ .compat = &[_]u21{
0x0064,
0x006D,
} });
try instance.map.put(0x3378, .{ .compat = &[_]u21{
0x0064,
0x006D,
0x00B2,
} });
try instance.map.put(0x3379, .{ .compat = &[_]u21{
0x0064,
0x006D,
0x00B3,
} });
try instance.map.put(0x337A, .{ .compat = &[_]u21{
0x0049,
0x0055,
} });
try instance.map.put(0x337B, .{ .compat = &[_]u21{
0x5E73,
0x6210,
} });
try instance.map.put(0x337C, .{ .compat = &[_]u21{
0x662D,
0x548C,
} });
try instance.map.put(0x337D, .{ .compat = &[_]u21{
0x5927,
0x6B63,
} });
try instance.map.put(0x337E, .{ .compat = &[_]u21{
0x660E,
0x6CBB,
} });
try instance.map.put(0x337F, .{ .compat = &[_]u21{
0x682A,
0x5F0F,
0x4F1A,
0x793E,
} });
try instance.map.put(0x3380, .{ .compat = &[_]u21{
0x0070,
0x0041,
} });
try instance.map.put(0x3381, .{ .compat = &[_]u21{
0x006E,
0x0041,
} });
try instance.map.put(0x3382, .{ .compat = &[_]u21{
0x03BC,
0x0041,
} });
try instance.map.put(0x3383, .{ .compat = &[_]u21{
0x006D,
0x0041,
} });
try instance.map.put(0x3384, .{ .compat = &[_]u21{
0x006B,
0x0041,
} });
try instance.map.put(0x3385, .{ .compat = &[_]u21{
0x004B,
0x0042,
} });
try instance.map.put(0x3386, .{ .compat = &[_]u21{
0x004D,
0x0042,
} });
try instance.map.put(0x3387, .{ .compat = &[_]u21{
0x0047,
0x0042,
} });
try instance.map.put(0x3388, .{ .compat = &[_]u21{
0x0063,
0x0061,
0x006C,
} });
try instance.map.put(0x3389, .{ .compat = &[_]u21{
0x006B,
0x0063,
0x0061,
0x006C,
} });
try instance.map.put(0x338A, .{ .compat = &[_]u21{
0x0070,
0x0046,
} });
try instance.map.put(0x338B, .{ .compat = &[_]u21{
0x006E,
0x0046,
} });
try instance.map.put(0x338C, .{ .compat = &[_]u21{
0x03BC,
0x0046,
} });
try instance.map.put(0x338D, .{ .compat = &[_]u21{
0x03BC,
0x0067,
} });
try instance.map.put(0x338E, .{ .compat = &[_]u21{
0x006D,
0x0067,
} });
try instance.map.put(0x338F, .{ .compat = &[_]u21{
0x006B,
0x0067,
} });
try instance.map.put(0x3390, .{ .compat = &[_]u21{
0x0048,
0x007A,
} });
try instance.map.put(0x3391, .{ .compat = &[_]u21{
0x006B,
0x0048,
0x007A,
} });
try instance.map.put(0x3392, .{ .compat = &[_]u21{
0x004D,
0x0048,
0x007A,
} });
try instance.map.put(0x3393, .{ .compat = &[_]u21{
0x0047,
0x0048,
0x007A,
} });
try instance.map.put(0x3394, .{ .compat = &[_]u21{
0x0054,
0x0048,
0x007A,
} });
try instance.map.put(0x3395, .{ .compat = &[_]u21{
0x03BC,
0x2113,
} });
try instance.map.put(0x3396, .{ .compat = &[_]u21{
0x006D,
0x2113,
} });
try instance.map.put(0x3397, .{ .compat = &[_]u21{
0x0064,
0x2113,
} });
try instance.map.put(0x3398, .{ .compat = &[_]u21{
0x006B,
0x2113,
} });
try instance.map.put(0x3399, .{ .compat = &[_]u21{
0x0066,
0x006D,
} });
try instance.map.put(0x339A, .{ .compat = &[_]u21{
0x006E,
0x006D,
} });
try instance.map.put(0x339B, .{ .compat = &[_]u21{
0x03BC,
0x006D,
} });
try instance.map.put(0x339C, .{ .compat = &[_]u21{
0x006D,
0x006D,
} });
try instance.map.put(0x339D, .{ .compat = &[_]u21{
0x0063,
0x006D,
} });
try instance.map.put(0x339E, .{ .compat = &[_]u21{
0x006B,
0x006D,
} });
try instance.map.put(0x339F, .{ .compat = &[_]u21{
0x006D,
0x006D,
0x00B2,
} });
try instance.map.put(0x33A0, .{ .compat = &[_]u21{
0x0063,
0x006D,
0x00B2,
} });
try instance.map.put(0x33A1, .{ .compat = &[_]u21{
0x006D,
0x00B2,
} });
try instance.map.put(0x33A2, .{ .compat = &[_]u21{
0x006B,
0x006D,
0x00B2,
} });
try instance.map.put(0x33A3, .{ .compat = &[_]u21{
0x006D,
0x006D,
0x00B3,
} });
try instance.map.put(0x33A4, .{ .compat = &[_]u21{
0x0063,
0x006D,
0x00B3,
} });
try instance.map.put(0x33A5, .{ .compat = &[_]u21{
0x006D,
0x00B3,
} });
try instance.map.put(0x33A6, .{ .compat = &[_]u21{
0x006B,
0x006D,
0x00B3,
} });
try instance.map.put(0x33A7, .{ .compat = &[_]u21{
0x006D,
0x2215,
0x0073,
} });
try instance.map.put(0x33A8, .{ .compat = &[_]u21{
0x006D,
0x2215,
0x0073,
0x00B2,
} });
try instance.map.put(0x33A9, .{ .compat = &[_]u21{
0x0050,
0x0061,
} });
try instance.map.put(0x33AA, .{ .compat = &[_]u21{
0x006B,
0x0050,
0x0061,
} });
try instance.map.put(0x33AB, .{ .compat = &[_]u21{
0x004D,
0x0050,
0x0061,
} });
try instance.map.put(0x33AC, .{ .compat = &[_]u21{
0x0047,
0x0050,
0x0061,
} });
try instance.map.put(0x33AD, .{ .compat = &[_]u21{
0x0072,
0x0061,
0x0064,
} });
try instance.map.put(0x33AE, .{ .compat = &[_]u21{
0x0072,
0x0061,
0x0064,
0x2215,
0x0073,
} });
try instance.map.put(0x33AF, .{ .compat = &[_]u21{
0x0072,
0x0061,
0x0064,
0x2215,
0x0073,
0x00B2,
} });
try instance.map.put(0x33B0, .{ .compat = &[_]u21{
0x0070,
0x0073,
} });
try instance.map.put(0x33B1, .{ .compat = &[_]u21{
0x006E,
0x0073,
} });
try instance.map.put(0x33B2, .{ .compat = &[_]u21{
0x03BC,
0x0073,
} });
try instance.map.put(0x33B3, .{ .compat = &[_]u21{
0x006D,
0x0073,
} });
try instance.map.put(0x33B4, .{ .compat = &[_]u21{
0x0070,
0x0056,
} });
try instance.map.put(0x33B5, .{ .compat = &[_]u21{
0x006E,
0x0056,
} });
try instance.map.put(0x33B6, .{ .compat = &[_]u21{
0x03BC,
0x0056,
} });
try instance.map.put(0x33B7, .{ .compat = &[_]u21{
0x006D,
0x0056,
} });
try instance.map.put(0x33B8, .{ .compat = &[_]u21{
0x006B,
0x0056,
} });
try instance.map.put(0x33B9, .{ .compat = &[_]u21{
0x004D,
0x0056,
} });
try instance.map.put(0x33BA, .{ .compat = &[_]u21{
0x0070,
0x0057,
} });
try instance.map.put(0x33BB, .{ .compat = &[_]u21{
0x006E,
0x0057,
} });
try instance.map.put(0x33BC, .{ .compat = &[_]u21{
0x03BC,
0x0057,
} });
try instance.map.put(0x33BD, .{ .compat = &[_]u21{
0x006D,
0x0057,
} });
try instance.map.put(0x33BE, .{ .compat = &[_]u21{
0x006B,
0x0057,
} });
try instance.map.put(0x33BF, .{ .compat = &[_]u21{
0x004D,
0x0057,
} });
try instance.map.put(0x33C0, .{ .compat = &[_]u21{
0x006B,
0x03A9,
} });
try instance.map.put(0x33C1, .{ .compat = &[_]u21{
0x004D,
0x03A9,
} });
try instance.map.put(0x33C2, .{ .compat = &[_]u21{
0x0061,
0x002E,
0x006D,
0x002E,
} });
try instance.map.put(0x33C3, .{ .compat = &[_]u21{
0x0042,
0x0071,
} });
try instance.map.put(0x33C4, .{ .compat = &[_]u21{
0x0063,
0x0063,
} });
try instance.map.put(0x33C5, .{ .compat = &[_]u21{
0x0063,
0x0064,
} });
try instance.map.put(0x33C6, .{ .compat = &[_]u21{
0x0043,
0x2215,
0x006B,
0x0067,
} });
try instance.map.put(0x33C7, .{ .compat = &[_]u21{
0x0043,
0x006F,
0x002E,
} });
try instance.map.put(0x33C8, .{ .compat = &[_]u21{
0x0064,
0x0042,
} });
try instance.map.put(0x33C9, .{ .compat = &[_]u21{
0x0047,
0x0079,
} });
try instance.map.put(0x33CA, .{ .compat = &[_]u21{
0x0068,
0x0061,
} });
try instance.map.put(0x33CB, .{ .compat = &[_]u21{
0x0048,
0x0050,
} });
try instance.map.put(0x33CC, .{ .compat = &[_]u21{
0x0069,
0x006E,
} });
try instance.map.put(0x33CD, .{ .compat = &[_]u21{
0x004B,
0x004B,
} });
try instance.map.put(0x33CE, .{ .compat = &[_]u21{
0x004B,
0x004D,
} });
try instance.map.put(0x33CF, .{ .compat = &[_]u21{
0x006B,
0x0074,
} });
try instance.map.put(0x33D0, .{ .compat = &[_]u21{
0x006C,
0x006D,
} });
try instance.map.put(0x33D1, .{ .compat = &[_]u21{
0x006C,
0x006E,
} });
try instance.map.put(0x33D2, .{ .compat = &[_]u21{
0x006C,
0x006F,
0x0067,
} });
try instance.map.put(0x33D3, .{ .compat = &[_]u21{
0x006C,
0x0078,
} });
try instance.map.put(0x33D4, .{ .compat = &[_]u21{
0x006D,
0x0062,
} });
try instance.map.put(0x33D5, .{ .compat = &[_]u21{
0x006D,
0x0069,
0x006C,
} });
try instance.map.put(0x33D6, .{ .compat = &[_]u21{
0x006D,
0x006F,
0x006C,
} });
try instance.map.put(0x33D7, .{ .compat = &[_]u21{
0x0050,
0x0048,
} });
try instance.map.put(0x33D8, .{ .compat = &[_]u21{
0x0070,
0x002E,
0x006D,
0x002E,
} });
try instance.map.put(0x33D9, .{ .compat = &[_]u21{
0x0050,
0x0050,
0x004D,
} });
try instance.map.put(0x33DA, .{ .compat = &[_]u21{
0x0050,
0x0052,
} });
try instance.map.put(0x33DB, .{ .compat = &[_]u21{
0x0073,
0x0072,
} });
try instance.map.put(0x33DC, .{ .compat = &[_]u21{
0x0053,
0x0076,
} });
try instance.map.put(0x33DD, .{ .compat = &[_]u21{
0x0057,
0x0062,
} });
try instance.map.put(0x33DE, .{ .compat = &[_]u21{
0x0056,
0x2215,
0x006D,
} });
try instance.map.put(0x33DF, .{ .compat = &[_]u21{
0x0041,
0x2215,
0x006D,
} });
try instance.map.put(0x33E0, .{ .compat = &[_]u21{
0x0031,
0x65E5,
} });
try instance.map.put(0x33E1, .{ .compat = &[_]u21{
0x0032,
0x65E5,
} });
try instance.map.put(0x33E2, .{ .compat = &[_]u21{
0x0033,
0x65E5,
} });
try instance.map.put(0x33E3, .{ .compat = &[_]u21{
0x0034,
0x65E5,
} });
try instance.map.put(0x33E4, .{ .compat = &[_]u21{
0x0035,
0x65E5,
} });
try instance.map.put(0x33E5, .{ .compat = &[_]u21{
0x0036,
0x65E5,
} });
try instance.map.put(0x33E6, .{ .compat = &[_]u21{
0x0037,
0x65E5,
} });
try instance.map.put(0x33E7, .{ .compat = &[_]u21{
0x0038,
0x65E5,
} });
try instance.map.put(0x33E8, .{ .compat = &[_]u21{
0x0039,
0x65E5,
} });
try instance.map.put(0x33E9, .{ .compat = &[_]u21{
0x0031,
0x0030,
0x65E5,
} });
try instance.map.put(0x33EA, .{ .compat = &[_]u21{
0x0031,
0x0031,
0x65E5,
} });
try instance.map.put(0x33EB, .{ .compat = &[_]u21{
0x0031,
0x0032,
0x65E5,
} });
try instance.map.put(0x33EC, .{ .compat = &[_]u21{
0x0031,
0x0033,
0x65E5,
} });
try instance.map.put(0x33ED, .{ .compat = &[_]u21{
0x0031,
0x0034,
0x65E5,
} });
try instance.map.put(0x33EE, .{ .compat = &[_]u21{
0x0031,
0x0035,
0x65E5,
} });
try instance.map.put(0x33EF, .{ .compat = &[_]u21{
0x0031,
0x0036,
0x65E5,
} });
try instance.map.put(0x33F0, .{ .compat = &[_]u21{
0x0031,
0x0037,
0x65E5,
} });
try instance.map.put(0x33F1, .{ .compat = &[_]u21{
0x0031,
0x0038,
0x65E5,
} });
try instance.map.put(0x33F2, .{ .compat = &[_]u21{
0x0031,
0x0039,
0x65E5,
} });
try instance.map.put(0x33F3, .{ .compat = &[_]u21{
0x0032,
0x0030,
0x65E5,
} });
try instance.map.put(0x33F4, .{ .compat = &[_]u21{
0x0032,
0x0031,
0x65E5,
} });
try instance.map.put(0x33F5, .{ .compat = &[_]u21{
0x0032,
0x0032,
0x65E5,
} });
try instance.map.put(0x33F6, .{ .compat = &[_]u21{
0x0032,
0x0033,
0x65E5,
} });
try instance.map.put(0x33F7, .{ .compat = &[_]u21{
0x0032,
0x0034,
0x65E5,
} });
try instance.map.put(0x33F8, .{ .compat = &[_]u21{
0x0032,
0x0035,
0x65E5,
} });
try instance.map.put(0x33F9, .{ .compat = &[_]u21{
0x0032,
0x0036,
0x65E5,
} });
try instance.map.put(0x33FA, .{ .compat = &[_]u21{
0x0032,
0x0037,
0x65E5,
} });
try instance.map.put(0x33FB, .{ .compat = &[_]u21{
0x0032,
0x0038,
0x65E5,
} });
try instance.map.put(0x33FC, .{ .compat = &[_]u21{
0x0032,
0x0039,
0x65E5,
} });
try instance.map.put(0x33FD, .{ .compat = &[_]u21{
0x0033,
0x0030,
0x65E5,
} });
try instance.map.put(0x33FE, .{ .compat = &[_]u21{
0x0033,
0x0031,
0x65E5,
} });
try instance.map.put(0x33FF, .{ .compat = &[_]u21{
0x0067,
0x0061,
0x006C,
} });
try instance.map.put(0xA69C, .{ .compat = &[_]u21{
0x044A,
} });
try instance.map.put(0xA69D, .{ .compat = &[_]u21{
0x044C,
} });
try instance.map.put(0xA770, .{ .compat = &[_]u21{
0xA76F,
} });
try instance.map.put(0xA7F8, .{ .compat = &[_]u21{
0x0126,
} });
try instance.map.put(0xA7F9, .{ .compat = &[_]u21{
0x0153,
} });
try instance.map.put(0xAB5C, .{ .compat = &[_]u21{
0xA727,
} });
try instance.map.put(0xAB5D, .{ .compat = &[_]u21{
0xAB37,
} });
try instance.map.put(0xAB5E, .{ .compat = &[_]u21{
0x026B,
} });
try instance.map.put(0xAB5F, .{ .compat = &[_]u21{
0xAB52,
} });
try instance.map.put(0xAB69, .{ .compat = &[_]u21{
0x028D,
} });
try instance.map.put(0xF900, .{ .single = 0x8C48 });
try instance.map.put(0xF901, .{ .single = 0x66F4 });
try instance.map.put(0xF902, .{ .single = 0x8ECA });
try instance.map.put(0xF903, .{ .single = 0x8CC8 });
try instance.map.put(0xF904, .{ .single = 0x6ED1 });
try instance.map.put(0xF905, .{ .single = 0x4E32 });
try instance.map.put(0xF906, .{ .single = 0x53E5 });
try instance.map.put(0xF907, .{ .single = 0x9F9C });
try instance.map.put(0xF908, .{ .single = 0x9F9C });
try instance.map.put(0xF909, .{ .single = 0x5951 });
try instance.map.put(0xF90A, .{ .single = 0x91D1 });
try instance.map.put(0xF90B, .{ .single = 0x5587 });
try instance.map.put(0xF90C, .{ .single = 0x5948 });
try instance.map.put(0xF90D, .{ .single = 0x61F6 });
try instance.map.put(0xF90E, .{ .single = 0x7669 });
try instance.map.put(0xF90F, .{ .single = 0x7F85 });
try instance.map.put(0xF910, .{ .single = 0x863F });
try instance.map.put(0xF911, .{ .single = 0x87BA });
try instance.map.put(0xF912, .{ .single = 0x88F8 });
try instance.map.put(0xF913, .{ .single = 0x908F });
try instance.map.put(0xF914, .{ .single = 0x6A02 });
try instance.map.put(0xF915, .{ .single = 0x6D1B });
try instance.map.put(0xF916, .{ .single = 0x70D9 });
try instance.map.put(0xF917, .{ .single = 0x73DE });
try instance.map.put(0xF918, .{ .single = 0x843D });
try instance.map.put(0xF919, .{ .single = 0x916A });
try instance.map.put(0xF91A, .{ .single = 0x99F1 });
try instance.map.put(0xF91B, .{ .single = 0x4E82 });
try instance.map.put(0xF91C, .{ .single = 0x5375 });
try instance.map.put(0xF91D, .{ .single = 0x6B04 });
try instance.map.put(0xF91E, .{ .single = 0x721B });
try instance.map.put(0xF91F, .{ .single = 0x862D });
try instance.map.put(0xF920, .{ .single = 0x9E1E });
try instance.map.put(0xF921, .{ .single = 0x5D50 });
try instance.map.put(0xF922, .{ .single = 0x6FEB });
try instance.map.put(0xF923, .{ .single = 0x85CD });
try instance.map.put(0xF924, .{ .single = 0x8964 });
try instance.map.put(0xF925, .{ .single = 0x62C9 });
try instance.map.put(0xF926, .{ .single = 0x81D8 });
try instance.map.put(0xF927, .{ .single = 0x881F });
try instance.map.put(0xF928, .{ .single = 0x5ECA });
try instance.map.put(0xF929, .{ .single = 0x6717 });
try instance.map.put(0xF92A, .{ .single = 0x6D6A });
try instance.map.put(0xF92B, .{ .single = 0x72FC });
try instance.map.put(0xF92C, .{ .single = 0x90CE });
try instance.map.put(0xF92D, .{ .single = 0x4F86 });
try instance.map.put(0xF92E, .{ .single = 0x51B7 });
try instance.map.put(0xF92F, .{ .single = 0x52DE });
try instance.map.put(0xF930, .{ .single = 0x64C4 });
try instance.map.put(0xF931, .{ .single = 0x6AD3 });
try instance.map.put(0xF932, .{ .single = 0x7210 });
try instance.map.put(0xF933, .{ .single = 0x76E7 });
try instance.map.put(0xF934, .{ .single = 0x8001 });
try instance.map.put(0xF935, .{ .single = 0x8606 });
try instance.map.put(0xF936, .{ .single = 0x865C });
try instance.map.put(0xF937, .{ .single = 0x8DEF });
try instance.map.put(0xF938, .{ .single = 0x9732 });
try instance.map.put(0xF939, .{ .single = 0x9B6F });
try instance.map.put(0xF93A, .{ .single = 0x9DFA });
try instance.map.put(0xF93B, .{ .single = 0x788C });
try instance.map.put(0xF93C, .{ .single = 0x797F });
try instance.map.put(0xF93D, .{ .single = 0x7DA0 });
try instance.map.put(0xF93E, .{ .single = 0x83C9 });
try instance.map.put(0xF93F, .{ .single = 0x9304 });
try instance.map.put(0xF940, .{ .single = 0x9E7F });
try instance.map.put(0xF941, .{ .single = 0x8AD6 });
try instance.map.put(0xF942, .{ .single = 0x58DF });
try instance.map.put(0xF943, .{ .single = 0x5F04 });
try instance.map.put(0xF944, .{ .single = 0x7C60 });
try instance.map.put(0xF945, .{ .single = 0x807E });
try instance.map.put(0xF946, .{ .single = 0x7262 });
try instance.map.put(0xF947, .{ .single = 0x78CA });
try instance.map.put(0xF948, .{ .single = 0x8CC2 });
try instance.map.put(0xF949, .{ .single = 0x96F7 });
try instance.map.put(0xF94A, .{ .single = 0x58D8 });
try instance.map.put(0xF94B, .{ .single = 0x5C62 });
try instance.map.put(0xF94C, .{ .single = 0x6A13 });
try instance.map.put(0xF94D, .{ .single = 0x6DDA });
try instance.map.put(0xF94E, .{ .single = 0x6F0F });
try instance.map.put(0xF94F, .{ .single = 0x7D2F });
try instance.map.put(0xF950, .{ .single = 0x7E37 });
try instance.map.put(0xF951, .{ .single = 0x964B });
try instance.map.put(0xF952, .{ .single = 0x52D2 });
try instance.map.put(0xF953, .{ .single = 0x808B });
try instance.map.put(0xF954, .{ .single = 0x51DC });
try instance.map.put(0xF955, .{ .single = 0x51CC });
try instance.map.put(0xF956, .{ .single = 0x7A1C });
try instance.map.put(0xF957, .{ .single = 0x7DBE });
try instance.map.put(0xF958, .{ .single = 0x83F1 });
try instance.map.put(0xF959, .{ .single = 0x9675 });
try instance.map.put(0xF95A, .{ .single = 0x8B80 });
try instance.map.put(0xF95B, .{ .single = 0x62CF });
try instance.map.put(0xF95C, .{ .single = 0x6A02 });
try instance.map.put(0xF95D, .{ .single = 0x8AFE });
try instance.map.put(0xF95E, .{ .single = 0x4E39 });
try instance.map.put(0xF95F, .{ .single = 0x5BE7 });
try instance.map.put(0xF960, .{ .single = 0x6012 });
try instance.map.put(0xF961, .{ .single = 0x7387 });
try instance.map.put(0xF962, .{ .single = 0x7570 });
try instance.map.put(0xF963, .{ .single = 0x5317 });
try instance.map.put(0xF964, .{ .single = 0x78FB });
try instance.map.put(0xF965, .{ .single = 0x4FBF });
try instance.map.put(0xF966, .{ .single = 0x5FA9 });
try instance.map.put(0xF967, .{ .single = 0x4E0D });
try instance.map.put(0xF968, .{ .single = 0x6CCC });
try instance.map.put(0xF969, .{ .single = 0x6578 });
try instance.map.put(0xF96A, .{ .single = 0x7D22 });
try instance.map.put(0xF96B, .{ .single = 0x53C3 });
try instance.map.put(0xF96C, .{ .single = 0x585E });
try instance.map.put(0xF96D, .{ .single = 0x7701 });
try instance.map.put(0xF96E, .{ .single = 0x8449 });
try instance.map.put(0xF96F, .{ .single = 0x8AAA });
try instance.map.put(0xF970, .{ .single = 0x6BBA });
try instance.map.put(0xF971, .{ .single = 0x8FB0 });
try instance.map.put(0xF972, .{ .single = 0x6C88 });
try instance.map.put(0xF973, .{ .single = 0x62FE });
try instance.map.put(0xF974, .{ .single = 0x82E5 });
try instance.map.put(0xF975, .{ .single = 0x63A0 });
try instance.map.put(0xF976, .{ .single = 0x7565 });
try instance.map.put(0xF977, .{ .single = 0x4EAE });
try instance.map.put(0xF978, .{ .single = 0x5169 });
try instance.map.put(0xF979, .{ .single = 0x51C9 });
try instance.map.put(0xF97A, .{ .single = 0x6881 });
try instance.map.put(0xF97B, .{ .single = 0x7CE7 });
try instance.map.put(0xF97C, .{ .single = 0x826F });
try instance.map.put(0xF97D, .{ .single = 0x8AD2 });
try instance.map.put(0xF97E, .{ .single = 0x91CF });
try instance.map.put(0xF97F, .{ .single = 0x52F5 });
try instance.map.put(0xF980, .{ .single = 0x5442 });
try instance.map.put(0xF981, .{ .single = 0x5973 });
try instance.map.put(0xF982, .{ .single = 0x5EEC });
try instance.map.put(0xF983, .{ .single = 0x65C5 });
try instance.map.put(0xF984, .{ .single = 0x6FFE });
try instance.map.put(0xF985, .{ .single = 0x792A });
try instance.map.put(0xF986, .{ .single = 0x95AD });
try instance.map.put(0xF987, .{ .single = 0x9A6A });
try instance.map.put(0xF988, .{ .single = 0x9E97 });
try instance.map.put(0xF989, .{ .single = 0x9ECE });
try instance.map.put(0xF98A, .{ .single = 0x529B });
try instance.map.put(0xF98B, .{ .single = 0x66C6 });
try instance.map.put(0xF98C, .{ .single = 0x6B77 });
try instance.map.put(0xF98D, .{ .single = 0x8F62 });
try instance.map.put(0xF98E, .{ .single = 0x5E74 });
try instance.map.put(0xF98F, .{ .single = 0x6190 });
try instance.map.put(0xF990, .{ .single = 0x6200 });
try instance.map.put(0xF991, .{ .single = 0x649A });
try instance.map.put(0xF992, .{ .single = 0x6F23 });
try instance.map.put(0xF993, .{ .single = 0x7149 });
try instance.map.put(0xF994, .{ .single = 0x7489 });
try instance.map.put(0xF995, .{ .single = 0x79CA });
try instance.map.put(0xF996, .{ .single = 0x7DF4 });
try instance.map.put(0xF997, .{ .single = 0x806F });
try instance.map.put(0xF998, .{ .single = 0x8F26 });
try instance.map.put(0xF999, .{ .single = 0x84EE });
try instance.map.put(0xF99A, .{ .single = 0x9023 });
try instance.map.put(0xF99B, .{ .single = 0x934A });
try instance.map.put(0xF99C, .{ .single = 0x5217 });
try instance.map.put(0xF99D, .{ .single = 0x52A3 });
try instance.map.put(0xF99E, .{ .single = 0x54BD });
try instance.map.put(0xF99F, .{ .single = 0x70C8 });
try instance.map.put(0xF9A0, .{ .single = 0x88C2 });
try instance.map.put(0xF9A1, .{ .single = 0x8AAA });
try instance.map.put(0xF9A2, .{ .single = 0x5EC9 });
try instance.map.put(0xF9A3, .{ .single = 0x5FF5 });
try instance.map.put(0xF9A4, .{ .single = 0x637B });
try instance.map.put(0xF9A5, .{ .single = 0x6BAE });
try instance.map.put(0xF9A6, .{ .single = 0x7C3E });
try instance.map.put(0xF9A7, .{ .single = 0x7375 });
try instance.map.put(0xF9A8, .{ .single = 0x4EE4 });
try instance.map.put(0xF9A9, .{ .single = 0x56F9 });
try instance.map.put(0xF9AA, .{ .single = 0x5BE7 });
try instance.map.put(0xF9AB, .{ .single = 0x5DBA });
try instance.map.put(0xF9AC, .{ .single = 0x601C });
try instance.map.put(0xF9AD, .{ .single = 0x73B2 });
try instance.map.put(0xF9AE, .{ .single = 0x7469 });
try instance.map.put(0xF9AF, .{ .single = 0x7F9A });
try instance.map.put(0xF9B0, .{ .single = 0x8046 });
try instance.map.put(0xF9B1, .{ .single = 0x9234 });
try instance.map.put(0xF9B2, .{ .single = 0x96F6 });
try instance.map.put(0xF9B3, .{ .single = 0x9748 });
try instance.map.put(0xF9B4, .{ .single = 0x9818 });
try instance.map.put(0xF9B5, .{ .single = 0x4F8B });
try instance.map.put(0xF9B6, .{ .single = 0x79AE });
try instance.map.put(0xF9B7, .{ .single = 0x91B4 });
try instance.map.put(0xF9B8, .{ .single = 0x96B8 });
try instance.map.put(0xF9B9, .{ .single = 0x60E1 });
try instance.map.put(0xF9BA, .{ .single = 0x4E86 });
try instance.map.put(0xF9BB, .{ .single = 0x50DA });
try instance.map.put(0xF9BC, .{ .single = 0x5BEE });
try instance.map.put(0xF9BD, .{ .single = 0x5C3F });
try instance.map.put(0xF9BE, .{ .single = 0x6599 });
try instance.map.put(0xF9BF, .{ .single = 0x6A02 });
try instance.map.put(0xF9C0, .{ .single = 0x71CE });
try instance.map.put(0xF9C1, .{ .single = 0x7642 });
try instance.map.put(0xF9C2, .{ .single = 0x84FC });
try instance.map.put(0xF9C3, .{ .single = 0x907C });
try instance.map.put(0xF9C4, .{ .single = 0x9F8D });
try instance.map.put(0xF9C5, .{ .single = 0x6688 });
try instance.map.put(0xF9C6, .{ .single = 0x962E });
try instance.map.put(0xF9C7, .{ .single = 0x5289 });
try instance.map.put(0xF9C8, .{ .single = 0x677B });
try instance.map.put(0xF9C9, .{ .single = 0x67F3 });
try instance.map.put(0xF9CA, .{ .single = 0x6D41 });
try instance.map.put(0xF9CB, .{ .single = 0x6E9C });
try instance.map.put(0xF9CC, .{ .single = 0x7409 });
try instance.map.put(0xF9CD, .{ .single = 0x7559 });
try instance.map.put(0xF9CE, .{ .single = 0x786B });
try instance.map.put(0xF9CF, .{ .single = 0x7D10 });
try instance.map.put(0xF9D0, .{ .single = 0x985E });
try instance.map.put(0xF9D1, .{ .single = 0x516D });
try instance.map.put(0xF9D2, .{ .single = 0x622E });
try instance.map.put(0xF9D3, .{ .single = 0x9678 });
try instance.map.put(0xF9D4, .{ .single = 0x502B });
try instance.map.put(0xF9D5, .{ .single = 0x5D19 });
try instance.map.put(0xF9D6, .{ .single = 0x6DEA });
try instance.map.put(0xF9D7, .{ .single = 0x8F2A });
try instance.map.put(0xF9D8, .{ .single = 0x5F8B });
try instance.map.put(0xF9D9, .{ .single = 0x6144 });
try instance.map.put(0xF9DA, .{ .single = 0x6817 });
try instance.map.put(0xF9DB, .{ .single = 0x7387 });
try instance.map.put(0xF9DC, .{ .single = 0x9686 });
try instance.map.put(0xF9DD, .{ .single = 0x5229 });
try instance.map.put(0xF9DE, .{ .single = 0x540F });
try instance.map.put(0xF9DF, .{ .single = 0x5C65 });
try instance.map.put(0xF9E0, .{ .single = 0x6613 });
try instance.map.put(0xF9E1, .{ .single = 0x674E });
try instance.map.put(0xF9E2, .{ .single = 0x68A8 });
try instance.map.put(0xF9E3, .{ .single = 0x6CE5 });
try instance.map.put(0xF9E4, .{ .single = 0x7406 });
try instance.map.put(0xF9E5, .{ .single = 0x75E2 });
try instance.map.put(0xF9E6, .{ .single = 0x7F79 });
try instance.map.put(0xF9E7, .{ .single = 0x88CF });
try instance.map.put(0xF9E8, .{ .single = 0x88E1 });
try instance.map.put(0xF9E9, .{ .single = 0x91CC });
try instance.map.put(0xF9EA, .{ .single = 0x96E2 });
try instance.map.put(0xF9EB, .{ .single = 0x533F });
try instance.map.put(0xF9EC, .{ .single = 0x6EBA });
try instance.map.put(0xF9ED, .{ .single = 0x541D });
try instance.map.put(0xF9EE, .{ .single = 0x71D0 });
try instance.map.put(0xF9EF, .{ .single = 0x7498 });
try instance.map.put(0xF9F0, .{ .single = 0x85FA });
try instance.map.put(0xF9F1, .{ .single = 0x96A3 });
try instance.map.put(0xF9F2, .{ .single = 0x9C57 });
try instance.map.put(0xF9F3, .{ .single = 0x9E9F });
try instance.map.put(0xF9F4, .{ .single = 0x6797 });
try instance.map.put(0xF9F5, .{ .single = 0x6DCB });
try instance.map.put(0xF9F6, .{ .single = 0x81E8 });
try instance.map.put(0xF9F7, .{ .single = 0x7ACB });
try instance.map.put(0xF9F8, .{ .single = 0x7B20 });
try instance.map.put(0xF9F9, .{ .single = 0x7C92 });
try instance.map.put(0xF9FA, .{ .single = 0x72C0 });
try instance.map.put(0xF9FB, .{ .single = 0x7099 });
try instance.map.put(0xF9FC, .{ .single = 0x8B58 });
try instance.map.put(0xF9FD, .{ .single = 0x4EC0 });
try instance.map.put(0xF9FE, .{ .single = 0x8336 });
try instance.map.put(0xF9FF, .{ .single = 0x523A });
try instance.map.put(0xFA00, .{ .single = 0x5207 });
try instance.map.put(0xFA01, .{ .single = 0x5EA6 });
try instance.map.put(0xFA02, .{ .single = 0x62D3 });
try instance.map.put(0xFA03, .{ .single = 0x7CD6 });
try instance.map.put(0xFA04, .{ .single = 0x5B85 });
try instance.map.put(0xFA05, .{ .single = 0x6D1E });
try instance.map.put(0xFA06, .{ .single = 0x66B4 });
try instance.map.put(0xFA07, .{ .single = 0x8F3B });
try instance.map.put(0xFA08, .{ .single = 0x884C });
try instance.map.put(0xFA09, .{ .single = 0x964D });
try instance.map.put(0xFA0A, .{ .single = 0x898B });
try instance.map.put(0xFA0B, .{ .single = 0x5ED3 });
try instance.map.put(0xFA0C, .{ .single = 0x5140 });
try instance.map.put(0xFA0D, .{ .single = 0x55C0 });
try instance.map.put(0xFA10, .{ .single = 0x585A });
try instance.map.put(0xFA12, .{ .single = 0x6674 });
try instance.map.put(0xFA15, .{ .single = 0x51DE });
try instance.map.put(0xFA16, .{ .single = 0x732A });
try instance.map.put(0xFA17, .{ .single = 0x76CA });
try instance.map.put(0xFA18, .{ .single = 0x793C });
try instance.map.put(0xFA19, .{ .single = 0x795E });
try instance.map.put(0xFA1A, .{ .single = 0x7965 });
try instance.map.put(0xFA1B, .{ .single = 0x798F });
try instance.map.put(0xFA1C, .{ .single = 0x9756 });
try instance.map.put(0xFA1D, .{ .single = 0x7CBE });
try instance.map.put(0xFA1E, .{ .single = 0x7FBD });
try instance.map.put(0xFA20, .{ .single = 0x8612 });
try instance.map.put(0xFA22, .{ .single = 0x8AF8 });
try instance.map.put(0xFA25, .{ .single = 0x9038 });
try instance.map.put(0xFA26, .{ .single = 0x90FD });
try instance.map.put(0xFA2A, .{ .single = 0x98EF });
try instance.map.put(0xFA2B, .{ .single = 0x98FC });
try instance.map.put(0xFA2C, .{ .single = 0x9928 });
try instance.map.put(0xFA2D, .{ .single = 0x9DB4 });
try instance.map.put(0xFA2E, .{ .single = 0x90DE });
try instance.map.put(0xFA2F, .{ .single = 0x96B7 });
try instance.map.put(0xFA30, .{ .single = 0x4FAE });
try instance.map.put(0xFA31, .{ .single = 0x50E7 });
try instance.map.put(0xFA32, .{ .single = 0x514D });
try instance.map.put(0xFA33, .{ .single = 0x52C9 });
try instance.map.put(0xFA34, .{ .single = 0x52E4 });
try instance.map.put(0xFA35, .{ .single = 0x5351 });
try instance.map.put(0xFA36, .{ .single = 0x559D });
try instance.map.put(0xFA37, .{ .single = 0x5606 });
try instance.map.put(0xFA38, .{ .single = 0x5668 });
try instance.map.put(0xFA39, .{ .single = 0x5840 });
try instance.map.put(0xFA3A, .{ .single = 0x58A8 });
try instance.map.put(0xFA3B, .{ .single = 0x5C64 });
try instance.map.put(0xFA3C, .{ .single = 0x5C6E });
try instance.map.put(0xFA3D, .{ .single = 0x6094 });
try instance.map.put(0xFA3E, .{ .single = 0x6168 });
try instance.map.put(0xFA3F, .{ .single = 0x618E });
try instance.map.put(0xFA40, .{ .single = 0x61F2 });
try instance.map.put(0xFA41, .{ .single = 0x654F });
try instance.map.put(0xFA42, .{ .single = 0x65E2 });
try instance.map.put(0xFA43, .{ .single = 0x6691 });
try instance.map.put(0xFA44, .{ .single = 0x6885 });
try instance.map.put(0xFA45, .{ .single = 0x6D77 });
try instance.map.put(0xFA46, .{ .single = 0x6E1A });
try instance.map.put(0xFA47, .{ .single = 0x6F22 });
try instance.map.put(0xFA48, .{ .single = 0x716E });
try instance.map.put(0xFA49, .{ .single = 0x722B });
try instance.map.put(0xFA4A, .{ .single = 0x7422 });
try instance.map.put(0xFA4B, .{ .single = 0x7891 });
try instance.map.put(0xFA4C, .{ .single = 0x793E });
try instance.map.put(0xFA4D, .{ .single = 0x7949 });
try instance.map.put(0xFA4E, .{ .single = 0x7948 });
try instance.map.put(0xFA4F, .{ .single = 0x7950 });
try instance.map.put(0xFA50, .{ .single = 0x7956 });
try instance.map.put(0xFA51, .{ .single = 0x795D });
try instance.map.put(0xFA52, .{ .single = 0x798D });
try instance.map.put(0xFA53, .{ .single = 0x798E });
try instance.map.put(0xFA54, .{ .single = 0x7A40 });
try instance.map.put(0xFA55, .{ .single = 0x7A81 });
try instance.map.put(0xFA56, .{ .single = 0x7BC0 });
try instance.map.put(0xFA57, .{ .single = 0x7DF4 });
try instance.map.put(0xFA58, .{ .single = 0x7E09 });
try instance.map.put(0xFA59, .{ .single = 0x7E41 });
try instance.map.put(0xFA5A, .{ .single = 0x7F72 });
try instance.map.put(0xFA5B, .{ .single = 0x8005 });
try instance.map.put(0xFA5C, .{ .single = 0x81ED });
try instance.map.put(0xFA5D, .{ .single = 0x8279 });
try instance.map.put(0xFA5E, .{ .single = 0x8279 });
try instance.map.put(0xFA5F, .{ .single = 0x8457 });
try instance.map.put(0xFA60, .{ .single = 0x8910 });
try instance.map.put(0xFA61, .{ .single = 0x8996 });
try instance.map.put(0xFA62, .{ .single = 0x8B01 });
try instance.map.put(0xFA63, .{ .single = 0x8B39 });
try instance.map.put(0xFA64, .{ .single = 0x8CD3 });
try instance.map.put(0xFA65, .{ .single = 0x8D08 });
try instance.map.put(0xFA66, .{ .single = 0x8FB6 });
try instance.map.put(0xFA67, .{ .single = 0x9038 });
try instance.map.put(0xFA68, .{ .single = 0x96E3 });
try instance.map.put(0xFA69, .{ .single = 0x97FF });
try instance.map.put(0xFA6A, .{ .single = 0x983B });
try instance.map.put(0xFA6B, .{ .single = 0x6075 });
try instance.map.put(0xFA6C, .{ .single = 0x242EE });
try instance.map.put(0xFA6D, .{ .single = 0x8218 });
try instance.map.put(0xFA70, .{ .single = 0x4E26 });
try instance.map.put(0xFA71, .{ .single = 0x51B5 });
try instance.map.put(0xFA72, .{ .single = 0x5168 });
try instance.map.put(0xFA73, .{ .single = 0x4F80 });
try instance.map.put(0xFA74, .{ .single = 0x5145 });
try instance.map.put(0xFA75, .{ .single = 0x5180 });
try instance.map.put(0xFA76, .{ .single = 0x52C7 });
try instance.map.put(0xFA77, .{ .single = 0x52FA });
try instance.map.put(0xFA78, .{ .single = 0x559D });
try instance.map.put(0xFA79, .{ .single = 0x5555 });
try instance.map.put(0xFA7A, .{ .single = 0x5599 });
try instance.map.put(0xFA7B, .{ .single = 0x55E2 });
try instance.map.put(0xFA7C, .{ .single = 0x585A });
try instance.map.put(0xFA7D, .{ .single = 0x58B3 });
try instance.map.put(0xFA7E, .{ .single = 0x5944 });
try instance.map.put(0xFA7F, .{ .single = 0x5954 });
try instance.map.put(0xFA80, .{ .single = 0x5A62 });
try instance.map.put(0xFA81, .{ .single = 0x5B28 });
try instance.map.put(0xFA82, .{ .single = 0x5ED2 });
try instance.map.put(0xFA83, .{ .single = 0x5ED9 });
try instance.map.put(0xFA84, .{ .single = 0x5F69 });
try instance.map.put(0xFA85, .{ .single = 0x5FAD });
try instance.map.put(0xFA86, .{ .single = 0x60D8 });
try instance.map.put(0xFA87, .{ .single = 0x614E });
try instance.map.put(0xFA88, .{ .single = 0x6108 });
try instance.map.put(0xFA89, .{ .single = 0x618E });
try instance.map.put(0xFA8A, .{ .single = 0x6160 });
try instance.map.put(0xFA8B, .{ .single = 0x61F2 });
try instance.map.put(0xFA8C, .{ .single = 0x6234 });
try instance.map.put(0xFA8D, .{ .single = 0x63C4 });
try instance.map.put(0xFA8E, .{ .single = 0x641C });
try instance.map.put(0xFA8F, .{ .single = 0x6452 });
try instance.map.put(0xFA90, .{ .single = 0x6556 });
try instance.map.put(0xFA91, .{ .single = 0x6674 });
try instance.map.put(0xFA92, .{ .single = 0x6717 });
try instance.map.put(0xFA93, .{ .single = 0x671B });
try instance.map.put(0xFA94, .{ .single = 0x6756 });
try instance.map.put(0xFA95, .{ .single = 0x6B79 });
try instance.map.put(0xFA96, .{ .single = 0x6BBA });
try instance.map.put(0xFA97, .{ .single = 0x6D41 });
try instance.map.put(0xFA98, .{ .single = 0x6EDB });
try instance.map.put(0xFA99, .{ .single = 0x6ECB });
try instance.map.put(0xFA9A, .{ .single = 0x6F22 });
try instance.map.put(0xFA9B, .{ .single = 0x701E });
try instance.map.put(0xFA9C, .{ .single = 0x716E });
try instance.map.put(0xFA9D, .{ .single = 0x77A7 });
try instance.map.put(0xFA9E, .{ .single = 0x7235 });
try instance.map.put(0xFA9F, .{ .single = 0x72AF });
try instance.map.put(0xFAA0, .{ .single = 0x732A });
try instance.map.put(0xFAA1, .{ .single = 0x7471 });
try instance.map.put(0xFAA2, .{ .single = 0x7506 });
try instance.map.put(0xFAA3, .{ .single = 0x753B });
try instance.map.put(0xFAA4, .{ .single = 0x761D });
try instance.map.put(0xFAA5, .{ .single = 0x761F });
try instance.map.put(0xFAA6, .{ .single = 0x76CA });
try instance.map.put(0xFAA7, .{ .single = 0x76DB });
try instance.map.put(0xFAA8, .{ .single = 0x76F4 });
try instance.map.put(0xFAA9, .{ .single = 0x774A });
try instance.map.put(0xFAAA, .{ .single = 0x7740 });
try instance.map.put(0xFAAB, .{ .single = 0x78CC });
try instance.map.put(0xFAAC, .{ .single = 0x7AB1 });
try instance.map.put(0xFAAD, .{ .single = 0x7BC0 });
try instance.map.put(0xFAAE, .{ .single = 0x7C7B });
try instance.map.put(0xFAAF, .{ .single = 0x7D5B });
try instance.map.put(0xFAB0, .{ .single = 0x7DF4 });
try instance.map.put(0xFAB1, .{ .single = 0x7F3E });
try instance.map.put(0xFAB2, .{ .single = 0x8005 });
try instance.map.put(0xFAB3, .{ .single = 0x8352 });
try instance.map.put(0xFAB4, .{ .single = 0x83EF });
try instance.map.put(0xFAB5, .{ .single = 0x8779 });
try instance.map.put(0xFAB6, .{ .single = 0x8941 });
try instance.map.put(0xFAB7, .{ .single = 0x8986 });
try instance.map.put(0xFAB8, .{ .single = 0x8996 });
try instance.map.put(0xFAB9, .{ .single = 0x8ABF });
try instance.map.put(0xFABA, .{ .single = 0x8AF8 });
try instance.map.put(0xFABB, .{ .single = 0x8ACB });
try instance.map.put(0xFABC, .{ .single = 0x8B01 });
try instance.map.put(0xFABD, .{ .single = 0x8AFE });
try instance.map.put(0xFABE, .{ .single = 0x8AED });
try instance.map.put(0xFABF, .{ .single = 0x8B39 });
try instance.map.put(0xFAC0, .{ .single = 0x8B8A });
try instance.map.put(0xFAC1, .{ .single = 0x8D08 });
try instance.map.put(0xFAC2, .{ .single = 0x8F38 });
try instance.map.put(0xFAC3, .{ .single = 0x9072 });
try instance.map.put(0xFAC4, .{ .single = 0x9199 });
try instance.map.put(0xFAC5, .{ .single = 0x9276 });
try instance.map.put(0xFAC6, .{ .single = 0x967C });
try instance.map.put(0xFAC7, .{ .single = 0x96E3 });
try instance.map.put(0xFAC8, .{ .single = 0x9756 });
try instance.map.put(0xFAC9, .{ .single = 0x97DB });
try instance.map.put(0xFACA, .{ .single = 0x97FF });
try instance.map.put(0xFACB, .{ .single = 0x980B });
try instance.map.put(0xFACC, .{ .single = 0x983B });
try instance.map.put(0xFACD, .{ .single = 0x9B12 });
try instance.map.put(0xFACE, .{ .single = 0x9F9C });
try instance.map.put(0xFACF, .{ .single = 0x2284A });
try instance.map.put(0xFAD0, .{ .single = 0x22844 });
try instance.map.put(0xFAD1, .{ .single = 0x233D5 });
try instance.map.put(0xFAD2, .{ .single = 0x3B9D });
try instance.map.put(0xFAD3, .{ .single = 0x4018 });
try instance.map.put(0xFAD4, .{ .single = 0x4039 });
try instance.map.put(0xFAD5, .{ .single = 0x25249 });
try instance.map.put(0xFAD6, .{ .single = 0x25CD0 });
try instance.map.put(0xFAD7, .{ .single = 0x27ED3 });
try instance.map.put(0xFAD8, .{ .single = 0x9F43 });
try instance.map.put(0xFAD9, .{ .single = 0x9F8E });
try instance.map.put(0xFB00, .{ .compat = &[_]u21{
0x0066,
0x0066,
} });
try instance.map.put(0xFB01, .{ .compat = &[_]u21{
0x0066,
0x0069,
} });
try instance.map.put(0xFB02, .{ .compat = &[_]u21{
0x0066,
0x006C,
} });
try instance.map.put(0xFB03, .{ .compat = &[_]u21{
0x0066,
0x0066,
0x0069,
} });
try instance.map.put(0xFB04, .{ .compat = &[_]u21{
0x0066,
0x0066,
0x006C,
} });
try instance.map.put(0xFB05, .{ .compat = &[_]u21{
0x017F,
0x0074,
} });
try instance.map.put(0xFB06, .{ .compat = &[_]u21{
0x0073,
0x0074,
} });
try instance.map.put(0xFB13, .{ .compat = &[_]u21{
0x0574,
0x0576,
} });
try instance.map.put(0xFB14, .{ .compat = &[_]u21{
0x0574,
0x0565,
} });
try instance.map.put(0xFB15, .{ .compat = &[_]u21{
0x0574,
0x056B,
} });
try instance.map.put(0xFB16, .{ .compat = &[_]u21{
0x057E,
0x0576,
} });
try instance.map.put(0xFB17, .{ .compat = &[_]u21{
0x0574,
0x056D,
} });
try instance.map.put(0xFB1D, .{ .canon = [2]u21{
0x05D9,
0x05B4,
} });
try instance.map.put(0xFB1F, .{ .canon = [2]u21{
0x05F2,
0x05B7,
} });
try instance.map.put(0xFB20, .{ .compat = &[_]u21{
0x05E2,
} });
try instance.map.put(0xFB21, .{ .compat = &[_]u21{
0x05D0,
} });
try instance.map.put(0xFB22, .{ .compat = &[_]u21{
0x05D3,
} });
try instance.map.put(0xFB23, .{ .compat = &[_]u21{
0x05D4,
} });
try instance.map.put(0xFB24, .{ .compat = &[_]u21{
0x05DB,
} });
try instance.map.put(0xFB25, .{ .compat = &[_]u21{
0x05DC,
} });
try instance.map.put(0xFB26, .{ .compat = &[_]u21{
0x05DD,
} });
try instance.map.put(0xFB27, .{ .compat = &[_]u21{
0x05E8,
} });
try instance.map.put(0xFB28, .{ .compat = &[_]u21{
0x05EA,
} });
try instance.map.put(0xFB29, .{ .compat = &[_]u21{
0x002B,
} });
try instance.map.put(0xFB2A, .{ .canon = [2]u21{
0x05E9,
0x05C1,
} });
try instance.map.put(0xFB2B, .{ .canon = [2]u21{
0x05E9,
0x05C2,
} });
try instance.map.put(0xFB2C, .{ .canon = [2]u21{
0xFB49,
0x05C1,
} });
try instance.map.put(0xFB2D, .{ .canon = [2]u21{
0xFB49,
0x05C2,
} });
try instance.map.put(0xFB2E, .{ .canon = [2]u21{
0x05D0,
0x05B7,
} });
try instance.map.put(0xFB2F, .{ .canon = [2]u21{
0x05D0,
0x05B8,
} });
try instance.map.put(0xFB30, .{ .canon = [2]u21{
0x05D0,
0x05BC,
} });
try instance.map.put(0xFB31, .{ .canon = [2]u21{
0x05D1,
0x05BC,
} });
try instance.map.put(0xFB32, .{ .canon = [2]u21{
0x05D2,
0x05BC,
} });
try instance.map.put(0xFB33, .{ .canon = [2]u21{
0x05D3,
0x05BC,
} });
try instance.map.put(0xFB34, .{ .canon = [2]u21{
0x05D4,
0x05BC,
} });
try instance.map.put(0xFB35, .{ .canon = [2]u21{
0x05D5,
0x05BC,
} });
try instance.map.put(0xFB36, .{ .canon = [2]u21{
0x05D6,
0x05BC,
} });
try instance.map.put(0xFB38, .{ .canon = [2]u21{
0x05D8,
0x05BC,
} });
try instance.map.put(0xFB39, .{ .canon = [2]u21{
0x05D9,
0x05BC,
} });
try instance.map.put(0xFB3A, .{ .canon = [2]u21{
0x05DA,
0x05BC,
} });
try instance.map.put(0xFB3B, .{ .canon = [2]u21{
0x05DB,
0x05BC,
} });
try instance.map.put(0xFB3C, .{ .canon = [2]u21{
0x05DC,
0x05BC,
} });
try instance.map.put(0xFB3E, .{ .canon = [2]u21{
0x05DE,
0x05BC,
} });
try instance.map.put(0xFB40, .{ .canon = [2]u21{
0x05E0,
0x05BC,
} });
try instance.map.put(0xFB41, .{ .canon = [2]u21{
0x05E1,
0x05BC,
} });
try instance.map.put(0xFB43, .{ .canon = [2]u21{
0x05E3,
0x05BC,
} });
try instance.map.put(0xFB44, .{ .canon = [2]u21{
0x05E4,
0x05BC,
} });
try instance.map.put(0xFB46, .{ .canon = [2]u21{
0x05E6,
0x05BC,
} });
try instance.map.put(0xFB47, .{ .canon = [2]u21{
0x05E7,
0x05BC,
} });
try instance.map.put(0xFB48, .{ .canon = [2]u21{
0x05E8,
0x05BC,
} });
try instance.map.put(0xFB49, .{ .canon = [2]u21{
0x05E9,
0x05BC,
} });
try instance.map.put(0xFB4A, .{ .canon = [2]u21{
0x05EA,
0x05BC,
} });
try instance.map.put(0xFB4B, .{ .canon = [2]u21{
0x05D5,
0x05B9,
} });
try instance.map.put(0xFB4C, .{ .canon = [2]u21{
0x05D1,
0x05BF,
} });
try instance.map.put(0xFB4D, .{ .canon = [2]u21{
0x05DB,
0x05BF,
} });
try instance.map.put(0xFB4E, .{ .canon = [2]u21{
0x05E4,
0x05BF,
} });
try instance.map.put(0xFB4F, .{ .compat = &[_]u21{
0x05D0,
0x05DC,
} });
try instance.map.put(0xFB50, .{ .compat = &[_]u21{
0x0671,
} });
try instance.map.put(0xFB51, .{ .compat = &[_]u21{
0x0671,
} });
try instance.map.put(0xFB52, .{ .compat = &[_]u21{
0x067B,
} });
try instance.map.put(0xFB53, .{ .compat = &[_]u21{
0x067B,
} });
try instance.map.put(0xFB54, .{ .compat = &[_]u21{
0x067B,
} });
try instance.map.put(0xFB55, .{ .compat = &[_]u21{
0x067B,
} });
try instance.map.put(0xFB56, .{ .compat = &[_]u21{
0x067E,
} });
try instance.map.put(0xFB57, .{ .compat = &[_]u21{
0x067E,
} });
try instance.map.put(0xFB58, .{ .compat = &[_]u21{
0x067E,
} });
try instance.map.put(0xFB59, .{ .compat = &[_]u21{
0x067E,
} });
try instance.map.put(0xFB5A, .{ .compat = &[_]u21{
0x0680,
} });
try instance.map.put(0xFB5B, .{ .compat = &[_]u21{
0x0680,
} });
try instance.map.put(0xFB5C, .{ .compat = &[_]u21{
0x0680,
} });
try instance.map.put(0xFB5D, .{ .compat = &[_]u21{
0x0680,
} });
try instance.map.put(0xFB5E, .{ .compat = &[_]u21{
0x067A,
} });
try instance.map.put(0xFB5F, .{ .compat = &[_]u21{
0x067A,
} });
try instance.map.put(0xFB60, .{ .compat = &[_]u21{
0x067A,
} });
try instance.map.put(0xFB61, .{ .compat = &[_]u21{
0x067A,
} });
try instance.map.put(0xFB62, .{ .compat = &[_]u21{
0x067F,
} });
try instance.map.put(0xFB63, .{ .compat = &[_]u21{
0x067F,
} });
try instance.map.put(0xFB64, .{ .compat = &[_]u21{
0x067F,
} });
try instance.map.put(0xFB65, .{ .compat = &[_]u21{
0x067F,
} });
try instance.map.put(0xFB66, .{ .compat = &[_]u21{
0x0679,
} });
try instance.map.put(0xFB67, .{ .compat = &[_]u21{
0x0679,
} });
try instance.map.put(0xFB68, .{ .compat = &[_]u21{
0x0679,
} });
try instance.map.put(0xFB69, .{ .compat = &[_]u21{
0x0679,
} });
try instance.map.put(0xFB6A, .{ .compat = &[_]u21{
0x06A4,
} });
try instance.map.put(0xFB6B, .{ .compat = &[_]u21{
0x06A4,
} });
try instance.map.put(0xFB6C, .{ .compat = &[_]u21{
0x06A4,
} });
try instance.map.put(0xFB6D, .{ .compat = &[_]u21{
0x06A4,
} });
try instance.map.put(0xFB6E, .{ .compat = &[_]u21{
0x06A6,
} });
try instance.map.put(0xFB6F, .{ .compat = &[_]u21{
0x06A6,
} });
try instance.map.put(0xFB70, .{ .compat = &[_]u21{
0x06A6,
} });
try instance.map.put(0xFB71, .{ .compat = &[_]u21{
0x06A6,
} });
try instance.map.put(0xFB72, .{ .compat = &[_]u21{
0x0684,
} });
try instance.map.put(0xFB73, .{ .compat = &[_]u21{
0x0684,
} });
try instance.map.put(0xFB74, .{ .compat = &[_]u21{
0x0684,
} });
try instance.map.put(0xFB75, .{ .compat = &[_]u21{
0x0684,
} });
try instance.map.put(0xFB76, .{ .compat = &[_]u21{
0x0683,
} });
try instance.map.put(0xFB77, .{ .compat = &[_]u21{
0x0683,
} });
try instance.map.put(0xFB78, .{ .compat = &[_]u21{
0x0683,
} });
try instance.map.put(0xFB79, .{ .compat = &[_]u21{
0x0683,
} });
try instance.map.put(0xFB7A, .{ .compat = &[_]u21{
0x0686,
} });
try instance.map.put(0xFB7B, .{ .compat = &[_]u21{
0x0686,
} });
try instance.map.put(0xFB7C, .{ .compat = &[_]u21{
0x0686,
} });
try instance.map.put(0xFB7D, .{ .compat = &[_]u21{
0x0686,
} });
try instance.map.put(0xFB7E, .{ .compat = &[_]u21{
0x0687,
} });
try instance.map.put(0xFB7F, .{ .compat = &[_]u21{
0x0687,
} });
try instance.map.put(0xFB80, .{ .compat = &[_]u21{
0x0687,
} });
try instance.map.put(0xFB81, .{ .compat = &[_]u21{
0x0687,
} });
try instance.map.put(0xFB82, .{ .compat = &[_]u21{
0x068D,
} });
try instance.map.put(0xFB83, .{ .compat = &[_]u21{
0x068D,
} });
try instance.map.put(0xFB84, .{ .compat = &[_]u21{
0x068C,
} });
try instance.map.put(0xFB85, .{ .compat = &[_]u21{
0x068C,
} });
try instance.map.put(0xFB86, .{ .compat = &[_]u21{
0x068E,
} });
try instance.map.put(0xFB87, .{ .compat = &[_]u21{
0x068E,
} });
try instance.map.put(0xFB88, .{ .compat = &[_]u21{
0x0688,
} });
try instance.map.put(0xFB89, .{ .compat = &[_]u21{
0x0688,
} });
try instance.map.put(0xFB8A, .{ .compat = &[_]u21{
0x0698,
} });
try instance.map.put(0xFB8B, .{ .compat = &[_]u21{
0x0698,
} });
try instance.map.put(0xFB8C, .{ .compat = &[_]u21{
0x0691,
} });
try instance.map.put(0xFB8D, .{ .compat = &[_]u21{
0x0691,
} });
try instance.map.put(0xFB8E, .{ .compat = &[_]u21{
0x06A9,
} });
try instance.map.put(0xFB8F, .{ .compat = &[_]u21{
0x06A9,
} });
try instance.map.put(0xFB90, .{ .compat = &[_]u21{
0x06A9,
} });
try instance.map.put(0xFB91, .{ .compat = &[_]u21{
0x06A9,
} });
try instance.map.put(0xFB92, .{ .compat = &[_]u21{
0x06AF,
} });
try instance.map.put(0xFB93, .{ .compat = &[_]u21{
0x06AF,
} });
try instance.map.put(0xFB94, .{ .compat = &[_]u21{
0x06AF,
} });
try instance.map.put(0xFB95, .{ .compat = &[_]u21{
0x06AF,
} });
try instance.map.put(0xFB96, .{ .compat = &[_]u21{
0x06B3,
} });
try instance.map.put(0xFB97, .{ .compat = &[_]u21{
0x06B3,
} });
try instance.map.put(0xFB98, .{ .compat = &[_]u21{
0x06B3,
} });
try instance.map.put(0xFB99, .{ .compat = &[_]u21{
0x06B3,
} });
try instance.map.put(0xFB9A, .{ .compat = &[_]u21{
0x06B1,
} });
try instance.map.put(0xFB9B, .{ .compat = &[_]u21{
0x06B1,
} });
try instance.map.put(0xFB9C, .{ .compat = &[_]u21{
0x06B1,
} });
try instance.map.put(0xFB9D, .{ .compat = &[_]u21{
0x06B1,
} });
try instance.map.put(0xFB9E, .{ .compat = &[_]u21{
0x06BA,
} });
try instance.map.put(0xFB9F, .{ .compat = &[_]u21{
0x06BA,
} });
try instance.map.put(0xFBA0, .{ .compat = &[_]u21{
0x06BB,
} });
try instance.map.put(0xFBA1, .{ .compat = &[_]u21{
0x06BB,
} });
try instance.map.put(0xFBA2, .{ .compat = &[_]u21{
0x06BB,
} });
try instance.map.put(0xFBA3, .{ .compat = &[_]u21{
0x06BB,
} });
try instance.map.put(0xFBA4, .{ .compat = &[_]u21{
0x06C0,
} });
try instance.map.put(0xFBA5, .{ .compat = &[_]u21{
0x06C0,
} });
try instance.map.put(0xFBA6, .{ .compat = &[_]u21{
0x06C1,
} });
try instance.map.put(0xFBA7, .{ .compat = &[_]u21{
0x06C1,
} });
try instance.map.put(0xFBA8, .{ .compat = &[_]u21{
0x06C1,
} });
try instance.map.put(0xFBA9, .{ .compat = &[_]u21{
0x06C1,
} });
try instance.map.put(0xFBAA, .{ .compat = &[_]u21{
0x06BE,
} });
try instance.map.put(0xFBAB, .{ .compat = &[_]u21{
0x06BE,
} });
try instance.map.put(0xFBAC, .{ .compat = &[_]u21{
0x06BE,
} });
try instance.map.put(0xFBAD, .{ .compat = &[_]u21{
0x06BE,
} });
try instance.map.put(0xFBAE, .{ .compat = &[_]u21{
0x06D2,
} });
try instance.map.put(0xFBAF, .{ .compat = &[_]u21{
0x06D2,
} });
try instance.map.put(0xFBB0, .{ .compat = &[_]u21{
0x06D3,
} });
try instance.map.put(0xFBB1, .{ .compat = &[_]u21{
0x06D3,
} });
try instance.map.put(0xFBD3, .{ .compat = &[_]u21{
0x06AD,
} });
try instance.map.put(0xFBD4, .{ .compat = &[_]u21{
0x06AD,
} });
try instance.map.put(0xFBD5, .{ .compat = &[_]u21{
0x06AD,
} });
try instance.map.put(0xFBD6, .{ .compat = &[_]u21{
0x06AD,
} });
try instance.map.put(0xFBD7, .{ .compat = &[_]u21{
0x06C7,
} });
try instance.map.put(0xFBD8, .{ .compat = &[_]u21{
0x06C7,
} });
try instance.map.put(0xFBD9, .{ .compat = &[_]u21{
0x06C6,
} });
try instance.map.put(0xFBDA, .{ .compat = &[_]u21{
0x06C6,
} });
try instance.map.put(0xFBDB, .{ .compat = &[_]u21{
0x06C8,
} });
try instance.map.put(0xFBDC, .{ .compat = &[_]u21{
0x06C8,
} });
try instance.map.put(0xFBDD, .{ .compat = &[_]u21{
0x0677,
} });
try instance.map.put(0xFBDE, .{ .compat = &[_]u21{
0x06CB,
} });
try instance.map.put(0xFBDF, .{ .compat = &[_]u21{
0x06CB,
} });
try instance.map.put(0xFBE0, .{ .compat = &[_]u21{
0x06C5,
} });
try instance.map.put(0xFBE1, .{ .compat = &[_]u21{
0x06C5,
} });
try instance.map.put(0xFBE2, .{ .compat = &[_]u21{
0x06C9,
} });
try instance.map.put(0xFBE3, .{ .compat = &[_]u21{
0x06C9,
} });
try instance.map.put(0xFBE4, .{ .compat = &[_]u21{
0x06D0,
} });
try instance.map.put(0xFBE5, .{ .compat = &[_]u21{
0x06D0,
} });
try instance.map.put(0xFBE6, .{ .compat = &[_]u21{
0x06D0,
} });
try instance.map.put(0xFBE7, .{ .compat = &[_]u21{
0x06D0,
} });
try instance.map.put(0xFBE8, .{ .compat = &[_]u21{
0x0649,
} });
try instance.map.put(0xFBE9, .{ .compat = &[_]u21{
0x0649,
} });
try instance.map.put(0xFBEA, .{ .compat = &[_]u21{
0x0626,
0x0627,
} });
try instance.map.put(0xFBEB, .{ .compat = &[_]u21{
0x0626,
0x0627,
} });
try instance.map.put(0xFBEC, .{ .compat = &[_]u21{
0x0626,
0x06D5,
} });
try instance.map.put(0xFBED, .{ .compat = &[_]u21{
0x0626,
0x06D5,
} });
try instance.map.put(0xFBEE, .{ .compat = &[_]u21{
0x0626,
0x0648,
} });
try instance.map.put(0xFBEF, .{ .compat = &[_]u21{
0x0626,
0x0648,
} });
try instance.map.put(0xFBF0, .{ .compat = &[_]u21{
0x0626,
0x06C7,
} });
try instance.map.put(0xFBF1, .{ .compat = &[_]u21{
0x0626,
0x06C7,
} });
try instance.map.put(0xFBF2, .{ .compat = &[_]u21{
0x0626,
0x06C6,
} });
try instance.map.put(0xFBF3, .{ .compat = &[_]u21{
0x0626,
0x06C6,
} });
try instance.map.put(0xFBF4, .{ .compat = &[_]u21{
0x0626,
0x06C8,
} });
try instance.map.put(0xFBF5, .{ .compat = &[_]u21{
0x0626,
0x06C8,
} });
try instance.map.put(0xFBF6, .{ .compat = &[_]u21{
0x0626,
0x06D0,
} });
try instance.map.put(0xFBF7, .{ .compat = &[_]u21{
0x0626,
0x06D0,
} });
try instance.map.put(0xFBF8, .{ .compat = &[_]u21{
0x0626,
0x06D0,
} });
try instance.map.put(0xFBF9, .{ .compat = &[_]u21{
0x0626,
0x0649,
} });
try instance.map.put(0xFBFA, .{ .compat = &[_]u21{
0x0626,
0x0649,
} });
try instance.map.put(0xFBFB, .{ .compat = &[_]u21{
0x0626,
0x0649,
} });
try instance.map.put(0xFBFC, .{ .compat = &[_]u21{
0x06CC,
} });
try instance.map.put(0xFBFD, .{ .compat = &[_]u21{
0x06CC,
} });
try instance.map.put(0xFBFE, .{ .compat = &[_]u21{
0x06CC,
} });
try instance.map.put(0xFBFF, .{ .compat = &[_]u21{
0x06CC,
} });
try instance.map.put(0xFC00, .{ .compat = &[_]u21{
0x0626,
0x062C,
} });
try instance.map.put(0xFC01, .{ .compat = &[_]u21{
0x0626,
0x062D,
} });
try instance.map.put(0xFC02, .{ .compat = &[_]u21{
0x0626,
0x0645,
} });
try instance.map.put(0xFC03, .{ .compat = &[_]u21{
0x0626,
0x0649,
} });
try instance.map.put(0xFC04, .{ .compat = &[_]u21{
0x0626,
0x064A,
} });
try instance.map.put(0xFC05, .{ .compat = &[_]u21{
0x0628,
0x062C,
} });
try instance.map.put(0xFC06, .{ .compat = &[_]u21{
0x0628,
0x062D,
} });
try instance.map.put(0xFC07, .{ .compat = &[_]u21{
0x0628,
0x062E,
} });
try instance.map.put(0xFC08, .{ .compat = &[_]u21{
0x0628,
0x0645,
} });
try instance.map.put(0xFC09, .{ .compat = &[_]u21{
0x0628,
0x0649,
} });
try instance.map.put(0xFC0A, .{ .compat = &[_]u21{
0x0628,
0x064A,
} });
try instance.map.put(0xFC0B, .{ .compat = &[_]u21{
0x062A,
0x062C,
} });
try instance.map.put(0xFC0C, .{ .compat = &[_]u21{
0x062A,
0x062D,
} });
try instance.map.put(0xFC0D, .{ .compat = &[_]u21{
0x062A,
0x062E,
} });
try instance.map.put(0xFC0E, .{ .compat = &[_]u21{
0x062A,
0x0645,
} });
try instance.map.put(0xFC0F, .{ .compat = &[_]u21{
0x062A,
0x0649,
} });
try instance.map.put(0xFC10, .{ .compat = &[_]u21{
0x062A,
0x064A,
} });
try instance.map.put(0xFC11, .{ .compat = &[_]u21{
0x062B,
0x062C,
} });
try instance.map.put(0xFC12, .{ .compat = &[_]u21{
0x062B,
0x0645,
} });
try instance.map.put(0xFC13, .{ .compat = &[_]u21{
0x062B,
0x0649,
} });
try instance.map.put(0xFC14, .{ .compat = &[_]u21{
0x062B,
0x064A,
} });
try instance.map.put(0xFC15, .{ .compat = &[_]u21{
0x062C,
0x062D,
} });
try instance.map.put(0xFC16, .{ .compat = &[_]u21{
0x062C,
0x0645,
} });
try instance.map.put(0xFC17, .{ .compat = &[_]u21{
0x062D,
0x062C,
} });
try instance.map.put(0xFC18, .{ .compat = &[_]u21{
0x062D,
0x0645,
} });
try instance.map.put(0xFC19, .{ .compat = &[_]u21{
0x062E,
0x062C,
} });
try instance.map.put(0xFC1A, .{ .compat = &[_]u21{
0x062E,
0x062D,
} });
try instance.map.put(0xFC1B, .{ .compat = &[_]u21{
0x062E,
0x0645,
} });
try instance.map.put(0xFC1C, .{ .compat = &[_]u21{
0x0633,
0x062C,
} });
try instance.map.put(0xFC1D, .{ .compat = &[_]u21{
0x0633,
0x062D,
} });
try instance.map.put(0xFC1E, .{ .compat = &[_]u21{
0x0633,
0x062E,
} });
try instance.map.put(0xFC1F, .{ .compat = &[_]u21{
0x0633,
0x0645,
} });
try instance.map.put(0xFC20, .{ .compat = &[_]u21{
0x0635,
0x062D,
} });
try instance.map.put(0xFC21, .{ .compat = &[_]u21{
0x0635,
0x0645,
} });
try instance.map.put(0xFC22, .{ .compat = &[_]u21{
0x0636,
0x062C,
} });
try instance.map.put(0xFC23, .{ .compat = &[_]u21{
0x0636,
0x062D,
} });
try instance.map.put(0xFC24, .{ .compat = &[_]u21{
0x0636,
0x062E,
} });
try instance.map.put(0xFC25, .{ .compat = &[_]u21{
0x0636,
0x0645,
} });
try instance.map.put(0xFC26, .{ .compat = &[_]u21{
0x0637,
0x062D,
} });
try instance.map.put(0xFC27, .{ .compat = &[_]u21{
0x0637,
0x0645,
} });
try instance.map.put(0xFC28, .{ .compat = &[_]u21{
0x0638,
0x0645,
} });
try instance.map.put(0xFC29, .{ .compat = &[_]u21{
0x0639,
0x062C,
} });
try instance.map.put(0xFC2A, .{ .compat = &[_]u21{
0x0639,
0x0645,
} });
try instance.map.put(0xFC2B, .{ .compat = &[_]u21{
0x063A,
0x062C,
} });
try instance.map.put(0xFC2C, .{ .compat = &[_]u21{
0x063A,
0x0645,
} });
try instance.map.put(0xFC2D, .{ .compat = &[_]u21{
0x0641,
0x062C,
} });
try instance.map.put(0xFC2E, .{ .compat = &[_]u21{
0x0641,
0x062D,
} });
try instance.map.put(0xFC2F, .{ .compat = &[_]u21{
0x0641,
0x062E,
} });
try instance.map.put(0xFC30, .{ .compat = &[_]u21{
0x0641,
0x0645,
} });
try instance.map.put(0xFC31, .{ .compat = &[_]u21{
0x0641,
0x0649,
} });
try instance.map.put(0xFC32, .{ .compat = &[_]u21{
0x0641,
0x064A,
} });
try instance.map.put(0xFC33, .{ .compat = &[_]u21{
0x0642,
0x062D,
} });
try instance.map.put(0xFC34, .{ .compat = &[_]u21{
0x0642,
0x0645,
} });
try instance.map.put(0xFC35, .{ .compat = &[_]u21{
0x0642,
0x0649,
} });
try instance.map.put(0xFC36, .{ .compat = &[_]u21{
0x0642,
0x064A,
} });
try instance.map.put(0xFC37, .{ .compat = &[_]u21{
0x0643,
0x0627,
} });
try instance.map.put(0xFC38, .{ .compat = &[_]u21{
0x0643,
0x062C,
} });
try instance.map.put(0xFC39, .{ .compat = &[_]u21{
0x0643,
0x062D,
} });
try instance.map.put(0xFC3A, .{ .compat = &[_]u21{
0x0643,
0x062E,
} });
try instance.map.put(0xFC3B, .{ .compat = &[_]u21{
0x0643,
0x0644,
} });
try instance.map.put(0xFC3C, .{ .compat = &[_]u21{
0x0643,
0x0645,
} });
try instance.map.put(0xFC3D, .{ .compat = &[_]u21{
0x0643,
0x0649,
} });
try instance.map.put(0xFC3E, .{ .compat = &[_]u21{
0x0643,
0x064A,
} });
try instance.map.put(0xFC3F, .{ .compat = &[_]u21{
0x0644,
0x062C,
} });
try instance.map.put(0xFC40, .{ .compat = &[_]u21{
0x0644,
0x062D,
} });
try instance.map.put(0xFC41, .{ .compat = &[_]u21{
0x0644,
0x062E,
} });
try instance.map.put(0xFC42, .{ .compat = &[_]u21{
0x0644,
0x0645,
} });
try instance.map.put(0xFC43, .{ .compat = &[_]u21{
0x0644,
0x0649,
} });
try instance.map.put(0xFC44, .{ .compat = &[_]u21{
0x0644,
0x064A,
} });
try instance.map.put(0xFC45, .{ .compat = &[_]u21{
0x0645,
0x062C,
} });
try instance.map.put(0xFC46, .{ .compat = &[_]u21{
0x0645,
0x062D,
} });
try instance.map.put(0xFC47, .{ .compat = &[_]u21{
0x0645,
0x062E,
} });
try instance.map.put(0xFC48, .{ .compat = &[_]u21{
0x0645,
0x0645,
} });
try instance.map.put(0xFC49, .{ .compat = &[_]u21{
0x0645,
0x0649,
} });
try instance.map.put(0xFC4A, .{ .compat = &[_]u21{
0x0645,
0x064A,
} });
try instance.map.put(0xFC4B, .{ .compat = &[_]u21{
0x0646,
0x062C,
} });
try instance.map.put(0xFC4C, .{ .compat = &[_]u21{
0x0646,
0x062D,
} });
try instance.map.put(0xFC4D, .{ .compat = &[_]u21{
0x0646,
0x062E,
} });
try instance.map.put(0xFC4E, .{ .compat = &[_]u21{
0x0646,
0x0645,
} });
try instance.map.put(0xFC4F, .{ .compat = &[_]u21{
0x0646,
0x0649,
} });
try instance.map.put(0xFC50, .{ .compat = &[_]u21{
0x0646,
0x064A,
} });
try instance.map.put(0xFC51, .{ .compat = &[_]u21{
0x0647,
0x062C,
} });
try instance.map.put(0xFC52, .{ .compat = &[_]u21{
0x0647,
0x0645,
} });
try instance.map.put(0xFC53, .{ .compat = &[_]u21{
0x0647,
0x0649,
} });
try instance.map.put(0xFC54, .{ .compat = &[_]u21{
0x0647,
0x064A,
} });
try instance.map.put(0xFC55, .{ .compat = &[_]u21{
0x064A,
0x062C,
} });
try instance.map.put(0xFC56, .{ .compat = &[_]u21{
0x064A,
0x062D,
} });
try instance.map.put(0xFC57, .{ .compat = &[_]u21{
0x064A,
0x062E,
} });
try instance.map.put(0xFC58, .{ .compat = &[_]u21{
0x064A,
0x0645,
} });
try instance.map.put(0xFC59, .{ .compat = &[_]u21{
0x064A,
0x0649,
} });
try instance.map.put(0xFC5A, .{ .compat = &[_]u21{
0x064A,
0x064A,
} });
try instance.map.put(0xFC5B, .{ .compat = &[_]u21{
0x0630,
0x0670,
} });
try instance.map.put(0xFC5C, .{ .compat = &[_]u21{
0x0631,
0x0670,
} });
try instance.map.put(0xFC5D, .{ .compat = &[_]u21{
0x0649,
0x0670,
} });
try instance.map.put(0xFC5E, .{ .compat = &[_]u21{
0x0020,
0x064C,
0x0651,
} });
try instance.map.put(0xFC5F, .{ .compat = &[_]u21{
0x0020,
0x064D,
0x0651,
} });
try instance.map.put(0xFC60, .{ .compat = &[_]u21{
0x0020,
0x064E,
0x0651,
} });
try instance.map.put(0xFC61, .{ .compat = &[_]u21{
0x0020,
0x064F,
0x0651,
} });
try instance.map.put(0xFC62, .{ .compat = &[_]u21{
0x0020,
0x0650,
0x0651,
} });
try instance.map.put(0xFC63, .{ .compat = &[_]u21{
0x0020,
0x0651,
0x0670,
} });
try instance.map.put(0xFC64, .{ .compat = &[_]u21{
0x0626,
0x0631,
} });
try instance.map.put(0xFC65, .{ .compat = &[_]u21{
0x0626,
0x0632,
} });
try instance.map.put(0xFC66, .{ .compat = &[_]u21{
0x0626,
0x0645,
} });
try instance.map.put(0xFC67, .{ .compat = &[_]u21{
0x0626,
0x0646,
} });
try instance.map.put(0xFC68, .{ .compat = &[_]u21{
0x0626,
0x0649,
} });
try instance.map.put(0xFC69, .{ .compat = &[_]u21{
0x0626,
0x064A,
} });
try instance.map.put(0xFC6A, .{ .compat = &[_]u21{
0x0628,
0x0631,
} });
try instance.map.put(0xFC6B, .{ .compat = &[_]u21{
0x0628,
0x0632,
} });
try instance.map.put(0xFC6C, .{ .compat = &[_]u21{
0x0628,
0x0645,
} });
try instance.map.put(0xFC6D, .{ .compat = &[_]u21{
0x0628,
0x0646,
} });
try instance.map.put(0xFC6E, .{ .compat = &[_]u21{
0x0628,
0x0649,
} });
try instance.map.put(0xFC6F, .{ .compat = &[_]u21{
0x0628,
0x064A,
} });
try instance.map.put(0xFC70, .{ .compat = &[_]u21{
0x062A,
0x0631,
} });
try instance.map.put(0xFC71, .{ .compat = &[_]u21{
0x062A,
0x0632,
} });
try instance.map.put(0xFC72, .{ .compat = &[_]u21{
0x062A,
0x0645,
} });
try instance.map.put(0xFC73, .{ .compat = &[_]u21{
0x062A,
0x0646,
} });
try instance.map.put(0xFC74, .{ .compat = &[_]u21{
0x062A,
0x0649,
} });
try instance.map.put(0xFC75, .{ .compat = &[_]u21{
0x062A,
0x064A,
} });
try instance.map.put(0xFC76, .{ .compat = &[_]u21{
0x062B,
0x0631,
} });
try instance.map.put(0xFC77, .{ .compat = &[_]u21{
0x062B,
0x0632,
} });
try instance.map.put(0xFC78, .{ .compat = &[_]u21{
0x062B,
0x0645,
} });
try instance.map.put(0xFC79, .{ .compat = &[_]u21{
0x062B,
0x0646,
} });
try instance.map.put(0xFC7A, .{ .compat = &[_]u21{
0x062B,
0x0649,
} });
try instance.map.put(0xFC7B, .{ .compat = &[_]u21{
0x062B,
0x064A,
} });
try instance.map.put(0xFC7C, .{ .compat = &[_]u21{
0x0641,
0x0649,
} });
try instance.map.put(0xFC7D, .{ .compat = &[_]u21{
0x0641,
0x064A,
} });
try instance.map.put(0xFC7E, .{ .compat = &[_]u21{
0x0642,
0x0649,
} });
try instance.map.put(0xFC7F, .{ .compat = &[_]u21{
0x0642,
0x064A,
} });
try instance.map.put(0xFC80, .{ .compat = &[_]u21{
0x0643,
0x0627,
} });
try instance.map.put(0xFC81, .{ .compat = &[_]u21{
0x0643,
0x0644,
} });
try instance.map.put(0xFC82, .{ .compat = &[_]u21{
0x0643,
0x0645,
} });
try instance.map.put(0xFC83, .{ .compat = &[_]u21{
0x0643,
0x0649,
} });
try instance.map.put(0xFC84, .{ .compat = &[_]u21{
0x0643,
0x064A,
} });
try instance.map.put(0xFC85, .{ .compat = &[_]u21{
0x0644,
0x0645,
} });
try instance.map.put(0xFC86, .{ .compat = &[_]u21{
0x0644,
0x0649,
} });
try instance.map.put(0xFC87, .{ .compat = &[_]u21{
0x0644,
0x064A,
} });
try instance.map.put(0xFC88, .{ .compat = &[_]u21{
0x0645,
0x0627,
} });
try instance.map.put(0xFC89, .{ .compat = &[_]u21{
0x0645,
0x0645,
} });
try instance.map.put(0xFC8A, .{ .compat = &[_]u21{
0x0646,
0x0631,
} });
try instance.map.put(0xFC8B, .{ .compat = &[_]u21{
0x0646,
0x0632,
} });
try instance.map.put(0xFC8C, .{ .compat = &[_]u21{
0x0646,
0x0645,
} });
try instance.map.put(0xFC8D, .{ .compat = &[_]u21{
0x0646,
0x0646,
} });
try instance.map.put(0xFC8E, .{ .compat = &[_]u21{
0x0646,
0x0649,
} });
try instance.map.put(0xFC8F, .{ .compat = &[_]u21{
0x0646,
0x064A,
} });
try instance.map.put(0xFC90, .{ .compat = &[_]u21{
0x0649,
0x0670,
} });
try instance.map.put(0xFC91, .{ .compat = &[_]u21{
0x064A,
0x0631,
} });
try instance.map.put(0xFC92, .{ .compat = &[_]u21{
0x064A,
0x0632,
} });
try instance.map.put(0xFC93, .{ .compat = &[_]u21{
0x064A,
0x0645,
} });
try instance.map.put(0xFC94, .{ .compat = &[_]u21{
0x064A,
0x0646,
} });
try instance.map.put(0xFC95, .{ .compat = &[_]u21{
0x064A,
0x0649,
} });
try instance.map.put(0xFC96, .{ .compat = &[_]u21{
0x064A,
0x064A,
} });
try instance.map.put(0xFC97, .{ .compat = &[_]u21{
0x0626,
0x062C,
} });
try instance.map.put(0xFC98, .{ .compat = &[_]u21{
0x0626,
0x062D,
} });
try instance.map.put(0xFC99, .{ .compat = &[_]u21{
0x0626,
0x062E,
} });
try instance.map.put(0xFC9A, .{ .compat = &[_]u21{
0x0626,
0x0645,
} });
try instance.map.put(0xFC9B, .{ .compat = &[_]u21{
0x0626,
0x0647,
} });
try instance.map.put(0xFC9C, .{ .compat = &[_]u21{
0x0628,
0x062C,
} });
try instance.map.put(0xFC9D, .{ .compat = &[_]u21{
0x0628,
0x062D,
} });
try instance.map.put(0xFC9E, .{ .compat = &[_]u21{
0x0628,
0x062E,
} });
try instance.map.put(0xFC9F, .{ .compat = &[_]u21{
0x0628,
0x0645,
} });
try instance.map.put(0xFCA0, .{ .compat = &[_]u21{
0x0628,
0x0647,
} });
try instance.map.put(0xFCA1, .{ .compat = &[_]u21{
0x062A,
0x062C,
} });
try instance.map.put(0xFCA2, .{ .compat = &[_]u21{
0x062A,
0x062D,
} });
try instance.map.put(0xFCA3, .{ .compat = &[_]u21{
0x062A,
0x062E,
} });
try instance.map.put(0xFCA4, .{ .compat = &[_]u21{
0x062A,
0x0645,
} });
try instance.map.put(0xFCA5, .{ .compat = &[_]u21{
0x062A,
0x0647,
} });
try instance.map.put(0xFCA6, .{ .compat = &[_]u21{
0x062B,
0x0645,
} });
try instance.map.put(0xFCA7, .{ .compat = &[_]u21{
0x062C,
0x062D,
} });
try instance.map.put(0xFCA8, .{ .compat = &[_]u21{
0x062C,
0x0645,
} });
try instance.map.put(0xFCA9, .{ .compat = &[_]u21{
0x062D,
0x062C,
} });
try instance.map.put(0xFCAA, .{ .compat = &[_]u21{
0x062D,
0x0645,
} });
try instance.map.put(0xFCAB, .{ .compat = &[_]u21{
0x062E,
0x062C,
} });
try instance.map.put(0xFCAC, .{ .compat = &[_]u21{
0x062E,
0x0645,
} });
try instance.map.put(0xFCAD, .{ .compat = &[_]u21{
0x0633,
0x062C,
} });
try instance.map.put(0xFCAE, .{ .compat = &[_]u21{
0x0633,
0x062D,
} });
try instance.map.put(0xFCAF, .{ .compat = &[_]u21{
0x0633,
0x062E,
} });
try instance.map.put(0xFCB0, .{ .compat = &[_]u21{
0x0633,
0x0645,
} });
try instance.map.put(0xFCB1, .{ .compat = &[_]u21{
0x0635,
0x062D,
} });
try instance.map.put(0xFCB2, .{ .compat = &[_]u21{
0x0635,
0x062E,
} });
try instance.map.put(0xFCB3, .{ .compat = &[_]u21{
0x0635,
0x0645,
} });
try instance.map.put(0xFCB4, .{ .compat = &[_]u21{
0x0636,
0x062C,
} });
try instance.map.put(0xFCB5, .{ .compat = &[_]u21{
0x0636,
0x062D,
} });
try instance.map.put(0xFCB6, .{ .compat = &[_]u21{
0x0636,
0x062E,
} });
try instance.map.put(0xFCB7, .{ .compat = &[_]u21{
0x0636,
0x0645,
} });
try instance.map.put(0xFCB8, .{ .compat = &[_]u21{
0x0637,
0x062D,
} });
try instance.map.put(0xFCB9, .{ .compat = &[_]u21{
0x0638,
0x0645,
} });
try instance.map.put(0xFCBA, .{ .compat = &[_]u21{
0x0639,
0x062C,
} });
try instance.map.put(0xFCBB, .{ .compat = &[_]u21{
0x0639,
0x0645,
} });
try instance.map.put(0xFCBC, .{ .compat = &[_]u21{
0x063A,
0x062C,
} });
try instance.map.put(0xFCBD, .{ .compat = &[_]u21{
0x063A,
0x0645,
} });
try instance.map.put(0xFCBE, .{ .compat = &[_]u21{
0x0641,
0x062C,
} });
try instance.map.put(0xFCBF, .{ .compat = &[_]u21{
0x0641,
0x062D,
} });
try instance.map.put(0xFCC0, .{ .compat = &[_]u21{
0x0641,
0x062E,
} });
try instance.map.put(0xFCC1, .{ .compat = &[_]u21{
0x0641,
0x0645,
} });
try instance.map.put(0xFCC2, .{ .compat = &[_]u21{
0x0642,
0x062D,
} });
try instance.map.put(0xFCC3, .{ .compat = &[_]u21{
0x0642,
0x0645,
} });
try instance.map.put(0xFCC4, .{ .compat = &[_]u21{
0x0643,
0x062C,
} });
try instance.map.put(0xFCC5, .{ .compat = &[_]u21{
0x0643,
0x062D,
} });
try instance.map.put(0xFCC6, .{ .compat = &[_]u21{
0x0643,
0x062E,
} });
try instance.map.put(0xFCC7, .{ .compat = &[_]u21{
0x0643,
0x0644,
} });
try instance.map.put(0xFCC8, .{ .compat = &[_]u21{
0x0643,
0x0645,
} });
try instance.map.put(0xFCC9, .{ .compat = &[_]u21{
0x0644,
0x062C,
} });
try instance.map.put(0xFCCA, .{ .compat = &[_]u21{
0x0644,
0x062D,
} });
try instance.map.put(0xFCCB, .{ .compat = &[_]u21{
0x0644,
0x062E,
} });
try instance.map.put(0xFCCC, .{ .compat = &[_]u21{
0x0644,
0x0645,
} });
try instance.map.put(0xFCCD, .{ .compat = &[_]u21{
0x0644,
0x0647,
} });
try instance.map.put(0xFCCE, .{ .compat = &[_]u21{
0x0645,
0x062C,
} });
try instance.map.put(0xFCCF, .{ .compat = &[_]u21{
0x0645,
0x062D,
} });
try instance.map.put(0xFCD0, .{ .compat = &[_]u21{
0x0645,
0x062E,
} });
try instance.map.put(0xFCD1, .{ .compat = &[_]u21{
0x0645,
0x0645,
} });
try instance.map.put(0xFCD2, .{ .compat = &[_]u21{
0x0646,
0x062C,
} });
try instance.map.put(0xFCD3, .{ .compat = &[_]u21{
0x0646,
0x062D,
} });
try instance.map.put(0xFCD4, .{ .compat = &[_]u21{
0x0646,
0x062E,
} });
try instance.map.put(0xFCD5, .{ .compat = &[_]u21{
0x0646,
0x0645,
} });
try instance.map.put(0xFCD6, .{ .compat = &[_]u21{
0x0646,
0x0647,
} });
try instance.map.put(0xFCD7, .{ .compat = &[_]u21{
0x0647,
0x062C,
} });
try instance.map.put(0xFCD8, .{ .compat = &[_]u21{
0x0647,
0x0645,
} });
try instance.map.put(0xFCD9, .{ .compat = &[_]u21{
0x0647,
0x0670,
} });
try instance.map.put(0xFCDA, .{ .compat = &[_]u21{
0x064A,
0x062C,
} });
try instance.map.put(0xFCDB, .{ .compat = &[_]u21{
0x064A,
0x062D,
} });
try instance.map.put(0xFCDC, .{ .compat = &[_]u21{
0x064A,
0x062E,
} });
try instance.map.put(0xFCDD, .{ .compat = &[_]u21{
0x064A,
0x0645,
} });
try instance.map.put(0xFCDE, .{ .compat = &[_]u21{
0x064A,
0x0647,
} });
try instance.map.put(0xFCDF, .{ .compat = &[_]u21{
0x0626,
0x0645,
} });
try instance.map.put(0xFCE0, .{ .compat = &[_]u21{
0x0626,
0x0647,
} });
try instance.map.put(0xFCE1, .{ .compat = &[_]u21{
0x0628,
0x0645,
} });
try instance.map.put(0xFCE2, .{ .compat = &[_]u21{
0x0628,
0x0647,
} });
try instance.map.put(0xFCE3, .{ .compat = &[_]u21{
0x062A,
0x0645,
} });
try instance.map.put(0xFCE4, .{ .compat = &[_]u21{
0x062A,
0x0647,
} });
try instance.map.put(0xFCE5, .{ .compat = &[_]u21{
0x062B,
0x0645,
} });
try instance.map.put(0xFCE6, .{ .compat = &[_]u21{
0x062B,
0x0647,
} });
try instance.map.put(0xFCE7, .{ .compat = &[_]u21{
0x0633,
0x0645,
} });
try instance.map.put(0xFCE8, .{ .compat = &[_]u21{
0x0633,
0x0647,
} });
try instance.map.put(0xFCE9, .{ .compat = &[_]u21{
0x0634,
0x0645,
} });
try instance.map.put(0xFCEA, .{ .compat = &[_]u21{
0x0634,
0x0647,
} });
try instance.map.put(0xFCEB, .{ .compat = &[_]u21{
0x0643,
0x0644,
} });
try instance.map.put(0xFCEC, .{ .compat = &[_]u21{
0x0643,
0x0645,
} });
try instance.map.put(0xFCED, .{ .compat = &[_]u21{
0x0644,
0x0645,
} });
try instance.map.put(0xFCEE, .{ .compat = &[_]u21{
0x0646,
0x0645,
} });
try instance.map.put(0xFCEF, .{ .compat = &[_]u21{
0x0646,
0x0647,
} });
try instance.map.put(0xFCF0, .{ .compat = &[_]u21{
0x064A,
0x0645,
} });
try instance.map.put(0xFCF1, .{ .compat = &[_]u21{
0x064A,
0x0647,
} });
try instance.map.put(0xFCF2, .{ .compat = &[_]u21{
0x0640,
0x064E,
0x0651,
} });
try instance.map.put(0xFCF3, .{ .compat = &[_]u21{
0x0640,
0x064F,
0x0651,
} });
try instance.map.put(0xFCF4, .{ .compat = &[_]u21{
0x0640,
0x0650,
0x0651,
} });
try instance.map.put(0xFCF5, .{ .compat = &[_]u21{
0x0637,
0x0649,
} });
try instance.map.put(0xFCF6, .{ .compat = &[_]u21{
0x0637,
0x064A,
} });
try instance.map.put(0xFCF7, .{ .compat = &[_]u21{
0x0639,
0x0649,
} });
try instance.map.put(0xFCF8, .{ .compat = &[_]u21{
0x0639,
0x064A,
} });
try instance.map.put(0xFCF9, .{ .compat = &[_]u21{
0x063A,
0x0649,
} });
try instance.map.put(0xFCFA, .{ .compat = &[_]u21{
0x063A,
0x064A,
} });
try instance.map.put(0xFCFB, .{ .compat = &[_]u21{
0x0633,
0x0649,
} });
try instance.map.put(0xFCFC, .{ .compat = &[_]u21{
0x0633,
0x064A,
} });
try instance.map.put(0xFCFD, .{ .compat = &[_]u21{
0x0634,
0x0649,
} });
try instance.map.put(0xFCFE, .{ .compat = &[_]u21{
0x0634,
0x064A,
} });
try instance.map.put(0xFCFF, .{ .compat = &[_]u21{
0x062D,
0x0649,
} });
try instance.map.put(0xFD00, .{ .compat = &[_]u21{
0x062D,
0x064A,
} });
try instance.map.put(0xFD01, .{ .compat = &[_]u21{
0x062C,
0x0649,
} });
try instance.map.put(0xFD02, .{ .compat = &[_]u21{
0x062C,
0x064A,
} });
try instance.map.put(0xFD03, .{ .compat = &[_]u21{
0x062E,
0x0649,
} });
try instance.map.put(0xFD04, .{ .compat = &[_]u21{
0x062E,
0x064A,
} });
try instance.map.put(0xFD05, .{ .compat = &[_]u21{
0x0635,
0x0649,
} });
try instance.map.put(0xFD06, .{ .compat = &[_]u21{
0x0635,
0x064A,
} });
try instance.map.put(0xFD07, .{ .compat = &[_]u21{
0x0636,
0x0649,
} });
try instance.map.put(0xFD08, .{ .compat = &[_]u21{
0x0636,
0x064A,
} });
try instance.map.put(0xFD09, .{ .compat = &[_]u21{
0x0634,
0x062C,
} });
try instance.map.put(0xFD0A, .{ .compat = &[_]u21{
0x0634,
0x062D,
} });
try instance.map.put(0xFD0B, .{ .compat = &[_]u21{
0x0634,
0x062E,
} });
try instance.map.put(0xFD0C, .{ .compat = &[_]u21{
0x0634,
0x0645,
} });
try instance.map.put(0xFD0D, .{ .compat = &[_]u21{
0x0634,
0x0631,
} });
try instance.map.put(0xFD0E, .{ .compat = &[_]u21{
0x0633,
0x0631,
} });
try instance.map.put(0xFD0F, .{ .compat = &[_]u21{
0x0635,
0x0631,
} });
try instance.map.put(0xFD10, .{ .compat = &[_]u21{
0x0636,
0x0631,
} });
try instance.map.put(0xFD11, .{ .compat = &[_]u21{
0x0637,
0x0649,
} });
try instance.map.put(0xFD12, .{ .compat = &[_]u21{
0x0637,
0x064A,
} });
try instance.map.put(0xFD13, .{ .compat = &[_]u21{
0x0639,
0x0649,
} });
try instance.map.put(0xFD14, .{ .compat = &[_]u21{
0x0639,
0x064A,
} });
try instance.map.put(0xFD15, .{ .compat = &[_]u21{
0x063A,
0x0649,
} });
try instance.map.put(0xFD16, .{ .compat = &[_]u21{
0x063A,
0x064A,
} });
try instance.map.put(0xFD17, .{ .compat = &[_]u21{
0x0633,
0x0649,
} });
try instance.map.put(0xFD18, .{ .compat = &[_]u21{
0x0633,
0x064A,
} });
try instance.map.put(0xFD19, .{ .compat = &[_]u21{
0x0634,
0x0649,
} });
try instance.map.put(0xFD1A, .{ .compat = &[_]u21{
0x0634,
0x064A,
} });
try instance.map.put(0xFD1B, .{ .compat = &[_]u21{
0x062D,
0x0649,
} });
try instance.map.put(0xFD1C, .{ .compat = &[_]u21{
0x062D,
0x064A,
} });
try instance.map.put(0xFD1D, .{ .compat = &[_]u21{
0x062C,
0x0649,
} });
try instance.map.put(0xFD1E, .{ .compat = &[_]u21{
0x062C,
0x064A,
} });
try instance.map.put(0xFD1F, .{ .compat = &[_]u21{
0x062E,
0x0649,
} });
try instance.map.put(0xFD20, .{ .compat = &[_]u21{
0x062E,
0x064A,
} });
try instance.map.put(0xFD21, .{ .compat = &[_]u21{
0x0635,
0x0649,
} });
try instance.map.put(0xFD22, .{ .compat = &[_]u21{
0x0635,
0x064A,
} });
try instance.map.put(0xFD23, .{ .compat = &[_]u21{
0x0636,
0x0649,
} });
try instance.map.put(0xFD24, .{ .compat = &[_]u21{
0x0636,
0x064A,
} });
try instance.map.put(0xFD25, .{ .compat = &[_]u21{
0x0634,
0x062C,
} });
try instance.map.put(0xFD26, .{ .compat = &[_]u21{
0x0634,
0x062D,
} });
try instance.map.put(0xFD27, .{ .compat = &[_]u21{
0x0634,
0x062E,
} });
try instance.map.put(0xFD28, .{ .compat = &[_]u21{
0x0634,
0x0645,
} });
try instance.map.put(0xFD29, .{ .compat = &[_]u21{
0x0634,
0x0631,
} });
try instance.map.put(0xFD2A, .{ .compat = &[_]u21{
0x0633,
0x0631,
} });
try instance.map.put(0xFD2B, .{ .compat = &[_]u21{
0x0635,
0x0631,
} });
try instance.map.put(0xFD2C, .{ .compat = &[_]u21{
0x0636,
0x0631,
} });
try instance.map.put(0xFD2D, .{ .compat = &[_]u21{
0x0634,
0x062C,
} });
try instance.map.put(0xFD2E, .{ .compat = &[_]u21{
0x0634,
0x062D,
} });
try instance.map.put(0xFD2F, .{ .compat = &[_]u21{
0x0634,
0x062E,
} });
try instance.map.put(0xFD30, .{ .compat = &[_]u21{
0x0634,
0x0645,
} });
try instance.map.put(0xFD31, .{ .compat = &[_]u21{
0x0633,
0x0647,
} });
try instance.map.put(0xFD32, .{ .compat = &[_]u21{
0x0634,
0x0647,
} });
try instance.map.put(0xFD33, .{ .compat = &[_]u21{
0x0637,
0x0645,
} });
try instance.map.put(0xFD34, .{ .compat = &[_]u21{
0x0633,
0x062C,
} });
try instance.map.put(0xFD35, .{ .compat = &[_]u21{
0x0633,
0x062D,
} });
try instance.map.put(0xFD36, .{ .compat = &[_]u21{
0x0633,
0x062E,
} });
try instance.map.put(0xFD37, .{ .compat = &[_]u21{
0x0634,
0x062C,
} });
try instance.map.put(0xFD38, .{ .compat = &[_]u21{
0x0634,
0x062D,
} });
try instance.map.put(0xFD39, .{ .compat = &[_]u21{
0x0634,
0x062E,
} });
try instance.map.put(0xFD3A, .{ .compat = &[_]u21{
0x0637,
0x0645,
} });
try instance.map.put(0xFD3B, .{ .compat = &[_]u21{
0x0638,
0x0645,
} });
try instance.map.put(0xFD3C, .{ .compat = &[_]u21{
0x0627,
0x064B,
} });
try instance.map.put(0xFD3D, .{ .compat = &[_]u21{
0x0627,
0x064B,
} });
try instance.map.put(0xFD50, .{ .compat = &[_]u21{
0x062A,
0x062C,
0x0645,
} });
try instance.map.put(0xFD51, .{ .compat = &[_]u21{
0x062A,
0x062D,
0x062C,
} });
try instance.map.put(0xFD52, .{ .compat = &[_]u21{
0x062A,
0x062D,
0x062C,
} });
try instance.map.put(0xFD53, .{ .compat = &[_]u21{
0x062A,
0x062D,
0x0645,
} });
try instance.map.put(0xFD54, .{ .compat = &[_]u21{
0x062A,
0x062E,
0x0645,
} });
try instance.map.put(0xFD55, .{ .compat = &[_]u21{
0x062A,
0x0645,
0x062C,
} });
try instance.map.put(0xFD56, .{ .compat = &[_]u21{
0x062A,
0x0645,
0x062D,
} });
try instance.map.put(0xFD57, .{ .compat = &[_]u21{
0x062A,
0x0645,
0x062E,
} });
try instance.map.put(0xFD58, .{ .compat = &[_]u21{
0x062C,
0x0645,
0x062D,
} });
try instance.map.put(0xFD59, .{ .compat = &[_]u21{
0x062C,
0x0645,
0x062D,
} });
try instance.map.put(0xFD5A, .{ .compat = &[_]u21{
0x062D,
0x0645,
0x064A,
} });
try instance.map.put(0xFD5B, .{ .compat = &[_]u21{
0x062D,
0x0645,
0x0649,
} });
try instance.map.put(0xFD5C, .{ .compat = &[_]u21{
0x0633,
0x062D,
0x062C,
} });
try instance.map.put(0xFD5D, .{ .compat = &[_]u21{
0x0633,
0x062C,
0x062D,
} });
try instance.map.put(0xFD5E, .{ .compat = &[_]u21{
0x0633,
0x062C,
0x0649,
} });
try instance.map.put(0xFD5F, .{ .compat = &[_]u21{
0x0633,
0x0645,
0x062D,
} });
try instance.map.put(0xFD60, .{ .compat = &[_]u21{
0x0633,
0x0645,
0x062D,
} });
try instance.map.put(0xFD61, .{ .compat = &[_]u21{
0x0633,
0x0645,
0x062C,
} });
try instance.map.put(0xFD62, .{ .compat = &[_]u21{
0x0633,
0x0645,
0x0645,
} });
try instance.map.put(0xFD63, .{ .compat = &[_]u21{
0x0633,
0x0645,
0x0645,
} });
try instance.map.put(0xFD64, .{ .compat = &[_]u21{
0x0635,
0x062D,
0x062D,
} });
try instance.map.put(0xFD65, .{ .compat = &[_]u21{
0x0635,
0x062D,
0x062D,
} });
try instance.map.put(0xFD66, .{ .compat = &[_]u21{
0x0635,
0x0645,
0x0645,
} });
try instance.map.put(0xFD67, .{ .compat = &[_]u21{
0x0634,
0x062D,
0x0645,
} });
try instance.map.put(0xFD68, .{ .compat = &[_]u21{
0x0634,
0x062D,
0x0645,
} });
try instance.map.put(0xFD69, .{ .compat = &[_]u21{
0x0634,
0x062C,
0x064A,
} });
try instance.map.put(0xFD6A, .{ .compat = &[_]u21{
0x0634,
0x0645,
0x062E,
} });
try instance.map.put(0xFD6B, .{ .compat = &[_]u21{
0x0634,
0x0645,
0x062E,
} });
try instance.map.put(0xFD6C, .{ .compat = &[_]u21{
0x0634,
0x0645,
0x0645,
} });
try instance.map.put(0xFD6D, .{ .compat = &[_]u21{
0x0634,
0x0645,
0x0645,
} });
try instance.map.put(0xFD6E, .{ .compat = &[_]u21{
0x0636,
0x062D,
0x0649,
} });
try instance.map.put(0xFD6F, .{ .compat = &[_]u21{
0x0636,
0x062E,
0x0645,
} });
try instance.map.put(0xFD70, .{ .compat = &[_]u21{
0x0636,
0x062E,
0x0645,
} });
try instance.map.put(0xFD71, .{ .compat = &[_]u21{
0x0637,
0x0645,
0x062D,
} });
try instance.map.put(0xFD72, .{ .compat = &[_]u21{
0x0637,
0x0645,
0x062D,
} });
try instance.map.put(0xFD73, .{ .compat = &[_]u21{
0x0637,
0x0645,
0x0645,
} });
try instance.map.put(0xFD74, .{ .compat = &[_]u21{
0x0637,
0x0645,
0x064A,
} });
try instance.map.put(0xFD75, .{ .compat = &[_]u21{
0x0639,
0x062C,
0x0645,
} });
try instance.map.put(0xFD76, .{ .compat = &[_]u21{
0x0639,
0x0645,
0x0645,
} });
try instance.map.put(0xFD77, .{ .compat = &[_]u21{
0x0639,
0x0645,
0x0645,
} });
try instance.map.put(0xFD78, .{ .compat = &[_]u21{
0x0639,
0x0645,
0x0649,
} });
try instance.map.put(0xFD79, .{ .compat = &[_]u21{
0x063A,
0x0645,
0x0645,
} });
try instance.map.put(0xFD7A, .{ .compat = &[_]u21{
0x063A,
0x0645,
0x064A,
} });
try instance.map.put(0xFD7B, .{ .compat = &[_]u21{
0x063A,
0x0645,
0x0649,
} });
try instance.map.put(0xFD7C, .{ .compat = &[_]u21{
0x0641,
0x062E,
0x0645,
} });
try instance.map.put(0xFD7D, .{ .compat = &[_]u21{
0x0641,
0x062E,
0x0645,
} });
try instance.map.put(0xFD7E, .{ .compat = &[_]u21{
0x0642,
0x0645,
0x062D,
} });
try instance.map.put(0xFD7F, .{ .compat = &[_]u21{
0x0642,
0x0645,
0x0645,
} });
try instance.map.put(0xFD80, .{ .compat = &[_]u21{
0x0644,
0x062D,
0x0645,
} });
try instance.map.put(0xFD81, .{ .compat = &[_]u21{
0x0644,
0x062D,
0x064A,
} });
try instance.map.put(0xFD82, .{ .compat = &[_]u21{
0x0644,
0x062D,
0x0649,
} });
try instance.map.put(0xFD83, .{ .compat = &[_]u21{
0x0644,
0x062C,
0x062C,
} });
try instance.map.put(0xFD84, .{ .compat = &[_]u21{
0x0644,
0x062C,
0x062C,
} });
try instance.map.put(0xFD85, .{ .compat = &[_]u21{
0x0644,
0x062E,
0x0645,
} });
try instance.map.put(0xFD86, .{ .compat = &[_]u21{
0x0644,
0x062E,
0x0645,
} });
try instance.map.put(0xFD87, .{ .compat = &[_]u21{
0x0644,
0x0645,
0x062D,
} });
try instance.map.put(0xFD88, .{ .compat = &[_]u21{
0x0644,
0x0645,
0x062D,
} });
try instance.map.put(0xFD89, .{ .compat = &[_]u21{
0x0645,
0x062D,
0x062C,
} });
try instance.map.put(0xFD8A, .{ .compat = &[_]u21{
0x0645,
0x062D,
0x0645,
} });
try instance.map.put(0xFD8B, .{ .compat = &[_]u21{
0x0645,
0x062D,
0x064A,
} });
try instance.map.put(0xFD8C, .{ .compat = &[_]u21{
0x0645,
0x062C,
0x062D,
} });
try instance.map.put(0xFD8D, .{ .compat = &[_]u21{
0x0645,
0x062C,
0x0645,
} });
try instance.map.put(0xFD8E, .{ .compat = &[_]u21{
0x0645,
0x062E,
0x062C,
} });
try instance.map.put(0xFD8F, .{ .compat = &[_]u21{
0x0645,
0x062E,
0x0645,
} });
try instance.map.put(0xFD92, .{ .compat = &[_]u21{
0x0645,
0x062C,
0x062E,
} });
try instance.map.put(0xFD93, .{ .compat = &[_]u21{
0x0647,
0x0645,
0x062C,
} });
try instance.map.put(0xFD94, .{ .compat = &[_]u21{
0x0647,
0x0645,
0x0645,
} });
try instance.map.put(0xFD95, .{ .compat = &[_]u21{
0x0646,
0x062D,
0x0645,
} });
try instance.map.put(0xFD96, .{ .compat = &[_]u21{
0x0646,
0x062D,
0x0649,
} });
try instance.map.put(0xFD97, .{ .compat = &[_]u21{
0x0646,
0x062C,
0x0645,
} });
try instance.map.put(0xFD98, .{ .compat = &[_]u21{
0x0646,
0x062C,
0x0645,
} });
try instance.map.put(0xFD99, .{ .compat = &[_]u21{
0x0646,
0x062C,
0x0649,
} });
try instance.map.put(0xFD9A, .{ .compat = &[_]u21{
0x0646,
0x0645,
0x064A,
} });
try instance.map.put(0xFD9B, .{ .compat = &[_]u21{
0x0646,
0x0645,
0x0649,
} });
try instance.map.put(0xFD9C, .{ .compat = &[_]u21{
0x064A,
0x0645,
0x0645,
} });
try instance.map.put(0xFD9D, .{ .compat = &[_]u21{
0x064A,
0x0645,
0x0645,
} });
try instance.map.put(0xFD9E, .{ .compat = &[_]u21{
0x0628,
0x062E,
0x064A,
} });
try instance.map.put(0xFD9F, .{ .compat = &[_]u21{
0x062A,
0x062C,
0x064A,
} });
try instance.map.put(0xFDA0, .{ .compat = &[_]u21{
0x062A,
0x062C,
0x0649,
} });
try instance.map.put(0xFDA1, .{ .compat = &[_]u21{
0x062A,
0x062E,
0x064A,
} });
try instance.map.put(0xFDA2, .{ .compat = &[_]u21{
0x062A,
0x062E,
0x0649,
} });
try instance.map.put(0xFDA3, .{ .compat = &[_]u21{
0x062A,
0x0645,
0x064A,
} });
try instance.map.put(0xFDA4, .{ .compat = &[_]u21{
0x062A,
0x0645,
0x0649,
} });
try instance.map.put(0xFDA5, .{ .compat = &[_]u21{
0x062C,
0x0645,
0x064A,
} });
try instance.map.put(0xFDA6, .{ .compat = &[_]u21{
0x062C,
0x062D,
0x0649,
} });
try instance.map.put(0xFDA7, .{ .compat = &[_]u21{
0x062C,
0x0645,
0x0649,
} });
try instance.map.put(0xFDA8, .{ .compat = &[_]u21{
0x0633,
0x062E,
0x0649,
} });
try instance.map.put(0xFDA9, .{ .compat = &[_]u21{
0x0635,
0x062D,
0x064A,
} });
try instance.map.put(0xFDAA, .{ .compat = &[_]u21{
0x0634,
0x062D,
0x064A,
} });
try instance.map.put(0xFDAB, .{ .compat = &[_]u21{
0x0636,
0x062D,
0x064A,
} });
try instance.map.put(0xFDAC, .{ .compat = &[_]u21{
0x0644,
0x062C,
0x064A,
} });
try instance.map.put(0xFDAD, .{ .compat = &[_]u21{
0x0644,
0x0645,
0x064A,
} });
try instance.map.put(0xFDAE, .{ .compat = &[_]u21{
0x064A,
0x062D,
0x064A,
} });
try instance.map.put(0xFDAF, .{ .compat = &[_]u21{
0x064A,
0x062C,
0x064A,
} });
try instance.map.put(0xFDB0, .{ .compat = &[_]u21{
0x064A,
0x0645,
0x064A,
} });
try instance.map.put(0xFDB1, .{ .compat = &[_]u21{
0x0645,
0x0645,
0x064A,
} });
try instance.map.put(0xFDB2, .{ .compat = &[_]u21{
0x0642,
0x0645,
0x064A,
} });
try instance.map.put(0xFDB3, .{ .compat = &[_]u21{
0x0646,
0x062D,
0x064A,
} });
try instance.map.put(0xFDB4, .{ .compat = &[_]u21{
0x0642,
0x0645,
0x062D,
} });
try instance.map.put(0xFDB5, .{ .compat = &[_]u21{
0x0644,
0x062D,
0x0645,
} });
try instance.map.put(0xFDB6, .{ .compat = &[_]u21{
0x0639,
0x0645,
0x064A,
} });
try instance.map.put(0xFDB7, .{ .compat = &[_]u21{
0x0643,
0x0645,
0x064A,
} });
try instance.map.put(0xFDB8, .{ .compat = &[_]u21{
0x0646,
0x062C,
0x062D,
} });
try instance.map.put(0xFDB9, .{ .compat = &[_]u21{
0x0645,
0x062E,
0x064A,
} });
try instance.map.put(0xFDBA, .{ .compat = &[_]u21{
0x0644,
0x062C,
0x0645,
} });
try instance.map.put(0xFDBB, .{ .compat = &[_]u21{
0x0643,
0x0645,
0x0645,
} });
try instance.map.put(0xFDBC, .{ .compat = &[_]u21{
0x0644,
0x062C,
0x0645,
} });
try instance.map.put(0xFDBD, .{ .compat = &[_]u21{
0x0646,
0x062C,
0x062D,
} });
try instance.map.put(0xFDBE, .{ .compat = &[_]u21{
0x062C,
0x062D,
0x064A,
} });
try instance.map.put(0xFDBF, .{ .compat = &[_]u21{
0x062D,
0x062C,
0x064A,
} });
try instance.map.put(0xFDC0, .{ .compat = &[_]u21{
0x0645,
0x062C,
0x064A,
} });
try instance.map.put(0xFDC1, .{ .compat = &[_]u21{
0x0641,
0x0645,
0x064A,
} });
try instance.map.put(0xFDC2, .{ .compat = &[_]u21{
0x0628,
0x062D,
0x064A,
} });
try instance.map.put(0xFDC3, .{ .compat = &[_]u21{
0x0643,
0x0645,
0x0645,
} });
try instance.map.put(0xFDC4, .{ .compat = &[_]u21{
0x0639,
0x062C,
0x0645,
} });
try instance.map.put(0xFDC5, .{ .compat = &[_]u21{
0x0635,
0x0645,
0x0645,
} });
try instance.map.put(0xFDC6, .{ .compat = &[_]u21{
0x0633,
0x062E,
0x064A,
} });
try instance.map.put(0xFDC7, .{ .compat = &[_]u21{
0x0646,
0x062C,
0x064A,
} });
try instance.map.put(0xFDF0, .{ .compat = &[_]u21{
0x0635,
0x0644,
0x06D2,
} });
try instance.map.put(0xFDF1, .{ .compat = &[_]u21{
0x0642,
0x0644,
0x06D2,
} });
try instance.map.put(0xFDF2, .{ .compat = &[_]u21{
0x0627,
0x0644,
0x0644,
0x0647,
} });
try instance.map.put(0xFDF3, .{ .compat = &[_]u21{
0x0627,
0x0643,
0x0628,
0x0631,
} });
try instance.map.put(0xFDF4, .{ .compat = &[_]u21{
0x0645,
0x062D,
0x0645,
0x062F,
} });
try instance.map.put(0xFDF5, .{ .compat = &[_]u21{
0x0635,
0x0644,
0x0639,
0x0645,
} });
try instance.map.put(0xFDF6, .{ .compat = &[_]u21{
0x0631,
0x0633,
0x0648,
0x0644,
} });
try instance.map.put(0xFDF7, .{ .compat = &[_]u21{
0x0639,
0x0644,
0x064A,
0x0647,
} });
try instance.map.put(0xFDF8, .{ .compat = &[_]u21{
0x0648,
0x0633,
0x0644,
0x0645,
} });
try instance.map.put(0xFDF9, .{ .compat = &[_]u21{
0x0635,
0x0644,
0x0649,
} });
try instance.map.put(0xFDFA, .{ .compat = &[_]u21{
0x0635,
0x0644,
0x0649,
0x0020,
0x0627,
0x0644,
0x0644,
0x0647,
0x0020,
0x0639,
0x0644,
0x064A,
0x0647,
0x0020,
0x0648,
0x0633,
0x0644,
0x0645,
} });
try instance.map.put(0xFDFB, .{ .compat = &[_]u21{
0x062C,
0x0644,
0x0020,
0x062C,
0x0644,
0x0627,
0x0644,
0x0647,
} });
try instance.map.put(0xFDFC, .{ .compat = &[_]u21{
0x0631,
0x06CC,
0x0627,
0x0644,
} });
try instance.map.put(0xFE10, .{ .compat = &[_]u21{
0x002C,
} });
try instance.map.put(0xFE11, .{ .compat = &[_]u21{
0x3001,
} });
try instance.map.put(0xFE12, .{ .compat = &[_]u21{
0x3002,
} });
try instance.map.put(0xFE13, .{ .compat = &[_]u21{
0x003A,
} });
try instance.map.put(0xFE14, .{ .compat = &[_]u21{
0x003B,
} });
try instance.map.put(0xFE15, .{ .compat = &[_]u21{
0x0021,
} });
try instance.map.put(0xFE16, .{ .compat = &[_]u21{
0x003F,
} });
try instance.map.put(0xFE17, .{ .compat = &[_]u21{
0x3016,
} });
try instance.map.put(0xFE18, .{ .compat = &[_]u21{
0x3017,
} });
try instance.map.put(0xFE19, .{ .compat = &[_]u21{
0x2026,
} });
try instance.map.put(0xFE30, .{ .compat = &[_]u21{
0x2025,
} });
try instance.map.put(0xFE31, .{ .compat = &[_]u21{
0x2014,
} });
try instance.map.put(0xFE32, .{ .compat = &[_]u21{
0x2013,
} });
try instance.map.put(0xFE33, .{ .compat = &[_]u21{
0x005F,
} });
try instance.map.put(0xFE34, .{ .compat = &[_]u21{
0x005F,
} });
try instance.map.put(0xFE35, .{ .compat = &[_]u21{
0x0028,
} });
try instance.map.put(0xFE36, .{ .compat = &[_]u21{
0x0029,
} });
try instance.map.put(0xFE37, .{ .compat = &[_]u21{
0x007B,
} });
try instance.map.put(0xFE38, .{ .compat = &[_]u21{
0x007D,
} });
try instance.map.put(0xFE39, .{ .compat = &[_]u21{
0x3014,
} });
try instance.map.put(0xFE3A, .{ .compat = &[_]u21{
0x3015,
} });
try instance.map.put(0xFE3B, .{ .compat = &[_]u21{
0x3010,
} });
try instance.map.put(0xFE3C, .{ .compat = &[_]u21{
0x3011,
} });
try instance.map.put(0xFE3D, .{ .compat = &[_]u21{
0x300A,
} });
try instance.map.put(0xFE3E, .{ .compat = &[_]u21{
0x300B,
} });
try instance.map.put(0xFE3F, .{ .compat = &[_]u21{
0x3008,
} });
try instance.map.put(0xFE40, .{ .compat = &[_]u21{
0x3009,
} });
try instance.map.put(0xFE41, .{ .compat = &[_]u21{
0x300C,
} });
try instance.map.put(0xFE42, .{ .compat = &[_]u21{
0x300D,
} });
try instance.map.put(0xFE43, .{ .compat = &[_]u21{
0x300E,
} });
try instance.map.put(0xFE44, .{ .compat = &[_]u21{
0x300F,
} });
try instance.map.put(0xFE47, .{ .compat = &[_]u21{
0x005B,
} });
try instance.map.put(0xFE48, .{ .compat = &[_]u21{
0x005D,
} });
try instance.map.put(0xFE49, .{ .compat = &[_]u21{
0x203E,
} });
try instance.map.put(0xFE4A, .{ .compat = &[_]u21{
0x203E,
} });
try instance.map.put(0xFE4B, .{ .compat = &[_]u21{
0x203E,
} });
try instance.map.put(0xFE4C, .{ .compat = &[_]u21{
0x203E,
} });
try instance.map.put(0xFE4D, .{ .compat = &[_]u21{
0x005F,
} });
try instance.map.put(0xFE4E, .{ .compat = &[_]u21{
0x005F,
} });
try instance.map.put(0xFE4F, .{ .compat = &[_]u21{
0x005F,
} });
try instance.map.put(0xFE50, .{ .compat = &[_]u21{
0x002C,
} });
try instance.map.put(0xFE51, .{ .compat = &[_]u21{
0x3001,
} });
try instance.map.put(0xFE52, .{ .compat = &[_]u21{
0x002E,
} });
try instance.map.put(0xFE54, .{ .compat = &[_]u21{
0x003B,
} });
try instance.map.put(0xFE55, .{ .compat = &[_]u21{
0x003A,
} });
try instance.map.put(0xFE56, .{ .compat = &[_]u21{
0x003F,
} });
try instance.map.put(0xFE57, .{ .compat = &[_]u21{
0x0021,
} });
try instance.map.put(0xFE58, .{ .compat = &[_]u21{
0x2014,
} });
try instance.map.put(0xFE59, .{ .compat = &[_]u21{
0x0028,
} });
try instance.map.put(0xFE5A, .{ .compat = &[_]u21{
0x0029,
} });
try instance.map.put(0xFE5B, .{ .compat = &[_]u21{
0x007B,
} });
try instance.map.put(0xFE5C, .{ .compat = &[_]u21{
0x007D,
} });
try instance.map.put(0xFE5D, .{ .compat = &[_]u21{
0x3014,
} });
try instance.map.put(0xFE5E, .{ .compat = &[_]u21{
0x3015,
} });
try instance.map.put(0xFE5F, .{ .compat = &[_]u21{
0x0023,
} });
try instance.map.put(0xFE60, .{ .compat = &[_]u21{
0x0026,
} });
try instance.map.put(0xFE61, .{ .compat = &[_]u21{
0x002A,
} });
try instance.map.put(0xFE62, .{ .compat = &[_]u21{
0x002B,
} });
try instance.map.put(0xFE63, .{ .compat = &[_]u21{
0x002D,
} });
try instance.map.put(0xFE64, .{ .compat = &[_]u21{
0x003C,
} });
try instance.map.put(0xFE65, .{ .compat = &[_]u21{
0x003E,
} });
try instance.map.put(0xFE66, .{ .compat = &[_]u21{
0x003D,
} });
try instance.map.put(0xFE68, .{ .compat = &[_]u21{
0x005C,
} });
try instance.map.put(0xFE69, .{ .compat = &[_]u21{
0x0024,
} });
try instance.map.put(0xFE6A, .{ .compat = &[_]u21{
0x0025,
} });
try instance.map.put(0xFE6B, .{ .compat = &[_]u21{
0x0040,
} });
try instance.map.put(0xFE70, .{ .compat = &[_]u21{
0x0020,
0x064B,
} });
try instance.map.put(0xFE71, .{ .compat = &[_]u21{
0x0640,
0x064B,
} });
try instance.map.put(0xFE72, .{ .compat = &[_]u21{
0x0020,
0x064C,
} });
try instance.map.put(0xFE74, .{ .compat = &[_]u21{
0x0020,
0x064D,
} });
try instance.map.put(0xFE76, .{ .compat = &[_]u21{
0x0020,
0x064E,
} });
try instance.map.put(0xFE77, .{ .compat = &[_]u21{
0x0640,
0x064E,
} });
try instance.map.put(0xFE78, .{ .compat = &[_]u21{
0x0020,
0x064F,
} });
try instance.map.put(0xFE79, .{ .compat = &[_]u21{
0x0640,
0x064F,
} });
try instance.map.put(0xFE7A, .{ .compat = &[_]u21{
0x0020,
0x0650,
} });
try instance.map.put(0xFE7B, .{ .compat = &[_]u21{
0x0640,
0x0650,
} });
try instance.map.put(0xFE7C, .{ .compat = &[_]u21{
0x0020,
0x0651,
} });
try instance.map.put(0xFE7D, .{ .compat = &[_]u21{
0x0640,
0x0651,
} });
try instance.map.put(0xFE7E, .{ .compat = &[_]u21{
0x0020,
0x0652,
} });
try instance.map.put(0xFE7F, .{ .compat = &[_]u21{
0x0640,
0x0652,
} });
try instance.map.put(0xFE80, .{ .compat = &[_]u21{
0x0621,
} });
try instance.map.put(0xFE81, .{ .compat = &[_]u21{
0x0622,
} });
try instance.map.put(0xFE82, .{ .compat = &[_]u21{
0x0622,
} });
try instance.map.put(0xFE83, .{ .compat = &[_]u21{
0x0623,
} });
try instance.map.put(0xFE84, .{ .compat = &[_]u21{
0x0623,
} });
try instance.map.put(0xFE85, .{ .compat = &[_]u21{
0x0624,
} });
try instance.map.put(0xFE86, .{ .compat = &[_]u21{
0x0624,
} });
try instance.map.put(0xFE87, .{ .compat = &[_]u21{
0x0625,
} });
try instance.map.put(0xFE88, .{ .compat = &[_]u21{
0x0625,
} });
try instance.map.put(0xFE89, .{ .compat = &[_]u21{
0x0626,
} });
try instance.map.put(0xFE8A, .{ .compat = &[_]u21{
0x0626,
} });
try instance.map.put(0xFE8B, .{ .compat = &[_]u21{
0x0626,
} });
try instance.map.put(0xFE8C, .{ .compat = &[_]u21{
0x0626,
} });
try instance.map.put(0xFE8D, .{ .compat = &[_]u21{
0x0627,
} });
try instance.map.put(0xFE8E, .{ .compat = &[_]u21{
0x0627,
} });
try instance.map.put(0xFE8F, .{ .compat = &[_]u21{
0x0628,
} });
try instance.map.put(0xFE90, .{ .compat = &[_]u21{
0x0628,
} });
try instance.map.put(0xFE91, .{ .compat = &[_]u21{
0x0628,
} });
try instance.map.put(0xFE92, .{ .compat = &[_]u21{
0x0628,
} });
try instance.map.put(0xFE93, .{ .compat = &[_]u21{
0x0629,
} });
try instance.map.put(0xFE94, .{ .compat = &[_]u21{
0x0629,
} });
try instance.map.put(0xFE95, .{ .compat = &[_]u21{
0x062A,
} });
try instance.map.put(0xFE96, .{ .compat = &[_]u21{
0x062A,
} });
try instance.map.put(0xFE97, .{ .compat = &[_]u21{
0x062A,
} });
try instance.map.put(0xFE98, .{ .compat = &[_]u21{
0x062A,
} });
try instance.map.put(0xFE99, .{ .compat = &[_]u21{
0x062B,
} });
try instance.map.put(0xFE9A, .{ .compat = &[_]u21{
0x062B,
} });
try instance.map.put(0xFE9B, .{ .compat = &[_]u21{
0x062B,
} });
try instance.map.put(0xFE9C, .{ .compat = &[_]u21{
0x062B,
} });
try instance.map.put(0xFE9D, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0xFE9E, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0xFE9F, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0xFEA0, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0xFEA1, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0xFEA2, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0xFEA3, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0xFEA4, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0xFEA5, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0xFEA6, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0xFEA7, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0xFEA8, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0xFEA9, .{ .compat = &[_]u21{
0x062F,
} });
try instance.map.put(0xFEAA, .{ .compat = &[_]u21{
0x062F,
} });
try instance.map.put(0xFEAB, .{ .compat = &[_]u21{
0x0630,
} });
try instance.map.put(0xFEAC, .{ .compat = &[_]u21{
0x0630,
} });
try instance.map.put(0xFEAD, .{ .compat = &[_]u21{
0x0631,
} });
try instance.map.put(0xFEAE, .{ .compat = &[_]u21{
0x0631,
} });
try instance.map.put(0xFEAF, .{ .compat = &[_]u21{
0x0632,
} });
try instance.map.put(0xFEB0, .{ .compat = &[_]u21{
0x0632,
} });
try instance.map.put(0xFEB1, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0xFEB2, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0xFEB3, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0xFEB4, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0xFEB5, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0xFEB6, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0xFEB7, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0xFEB8, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0xFEB9, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0xFEBA, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0xFEBB, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0xFEBC, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0xFEBD, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0xFEBE, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0xFEBF, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0xFEC0, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0xFEC1, .{ .compat = &[_]u21{
0x0637,
} });
try instance.map.put(0xFEC2, .{ .compat = &[_]u21{
0x0637,
} });
try instance.map.put(0xFEC3, .{ .compat = &[_]u21{
0x0637,
} });
try instance.map.put(0xFEC4, .{ .compat = &[_]u21{
0x0637,
} });
try instance.map.put(0xFEC5, .{ .compat = &[_]u21{
0x0638,
} });
try instance.map.put(0xFEC6, .{ .compat = &[_]u21{
0x0638,
} });
try instance.map.put(0xFEC7, .{ .compat = &[_]u21{
0x0638,
} });
try instance.map.put(0xFEC8, .{ .compat = &[_]u21{
0x0638,
} });
try instance.map.put(0xFEC9, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0xFECA, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0xFECB, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0xFECC, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0xFECD, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0xFECE, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0xFECF, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0xFED0, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0xFED1, .{ .compat = &[_]u21{
0x0641,
} });
try instance.map.put(0xFED2, .{ .compat = &[_]u21{
0x0641,
} });
try instance.map.put(0xFED3, .{ .compat = &[_]u21{
0x0641,
} });
try instance.map.put(0xFED4, .{ .compat = &[_]u21{
0x0641,
} });
try instance.map.put(0xFED5, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0xFED6, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0xFED7, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0xFED8, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0xFED9, .{ .compat = &[_]u21{
0x0643,
} });
try instance.map.put(0xFEDA, .{ .compat = &[_]u21{
0x0643,
} });
try instance.map.put(0xFEDB, .{ .compat = &[_]u21{
0x0643,
} });
try instance.map.put(0xFEDC, .{ .compat = &[_]u21{
0x0643,
} });
try instance.map.put(0xFEDD, .{ .compat = &[_]u21{
0x0644,
} });
try instance.map.put(0xFEDE, .{ .compat = &[_]u21{
0x0644,
} });
try instance.map.put(0xFEDF, .{ .compat = &[_]u21{
0x0644,
} });
try instance.map.put(0xFEE0, .{ .compat = &[_]u21{
0x0644,
} });
try instance.map.put(0xFEE1, .{ .compat = &[_]u21{
0x0645,
} });
try instance.map.put(0xFEE2, .{ .compat = &[_]u21{
0x0645,
} });
try instance.map.put(0xFEE3, .{ .compat = &[_]u21{
0x0645,
} });
try instance.map.put(0xFEE4, .{ .compat = &[_]u21{
0x0645,
} });
try instance.map.put(0xFEE5, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0xFEE6, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0xFEE7, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0xFEE8, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0xFEE9, .{ .compat = &[_]u21{
0x0647,
} });
try instance.map.put(0xFEEA, .{ .compat = &[_]u21{
0x0647,
} });
try instance.map.put(0xFEEB, .{ .compat = &[_]u21{
0x0647,
} });
try instance.map.put(0xFEEC, .{ .compat = &[_]u21{
0x0647,
} });
try instance.map.put(0xFEED, .{ .compat = &[_]u21{
0x0648,
} });
try instance.map.put(0xFEEE, .{ .compat = &[_]u21{
0x0648,
} });
try instance.map.put(0xFEEF, .{ .compat = &[_]u21{
0x0649,
} });
try instance.map.put(0xFEF0, .{ .compat = &[_]u21{
0x0649,
} });
try instance.map.put(0xFEF1, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0xFEF2, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0xFEF3, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0xFEF4, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0xFEF5, .{ .compat = &[_]u21{
0x0644,
0x0622,
} });
try instance.map.put(0xFEF6, .{ .compat = &[_]u21{
0x0644,
0x0622,
} });
try instance.map.put(0xFEF7, .{ .compat = &[_]u21{
0x0644,
0x0623,
} });
try instance.map.put(0xFEF8, .{ .compat = &[_]u21{
0x0644,
0x0623,
} });
try instance.map.put(0xFEF9, .{ .compat = &[_]u21{
0x0644,
0x0625,
} });
try instance.map.put(0xFEFA, .{ .compat = &[_]u21{
0x0644,
0x0625,
} });
try instance.map.put(0xFEFB, .{ .compat = &[_]u21{
0x0644,
0x0627,
} });
try instance.map.put(0xFEFC, .{ .compat = &[_]u21{
0x0644,
0x0627,
} });
try instance.map.put(0xFF01, .{ .compat = &[_]u21{
0x0021,
} });
try instance.map.put(0xFF02, .{ .compat = &[_]u21{
0x0022,
} });
try instance.map.put(0xFF03, .{ .compat = &[_]u21{
0x0023,
} });
try instance.map.put(0xFF04, .{ .compat = &[_]u21{
0x0024,
} });
try instance.map.put(0xFF05, .{ .compat = &[_]u21{
0x0025,
} });
try instance.map.put(0xFF06, .{ .compat = &[_]u21{
0x0026,
} });
try instance.map.put(0xFF07, .{ .compat = &[_]u21{
0x0027,
} });
try instance.map.put(0xFF08, .{ .compat = &[_]u21{
0x0028,
} });
try instance.map.put(0xFF09, .{ .compat = &[_]u21{
0x0029,
} });
try instance.map.put(0xFF0A, .{ .compat = &[_]u21{
0x002A,
} });
try instance.map.put(0xFF0B, .{ .compat = &[_]u21{
0x002B,
} });
try instance.map.put(0xFF0C, .{ .compat = &[_]u21{
0x002C,
} });
try instance.map.put(0xFF0D, .{ .compat = &[_]u21{
0x002D,
} });
try instance.map.put(0xFF0E, .{ .compat = &[_]u21{
0x002E,
} });
try instance.map.put(0xFF0F, .{ .compat = &[_]u21{
0x002F,
} });
try instance.map.put(0xFF10, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0xFF11, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0xFF12, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0xFF13, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0xFF14, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0xFF15, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0xFF16, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0xFF17, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0xFF18, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0xFF19, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0xFF1A, .{ .compat = &[_]u21{
0x003A,
} });
try instance.map.put(0xFF1B, .{ .compat = &[_]u21{
0x003B,
} });
try instance.map.put(0xFF1C, .{ .compat = &[_]u21{
0x003C,
} });
try instance.map.put(0xFF1D, .{ .compat = &[_]u21{
0x003D,
} });
try instance.map.put(0xFF1E, .{ .compat = &[_]u21{
0x003E,
} });
try instance.map.put(0xFF1F, .{ .compat = &[_]u21{
0x003F,
} });
try instance.map.put(0xFF20, .{ .compat = &[_]u21{
0x0040,
} });
try instance.map.put(0xFF21, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0xFF22, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0xFF23, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0xFF24, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0xFF25, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0xFF26, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0xFF27, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0xFF28, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0xFF29, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0xFF2A, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0xFF2B, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0xFF2C, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0xFF2D, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0xFF2E, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0xFF2F, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0xFF30, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0xFF31, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0xFF32, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0xFF33, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0xFF34, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0xFF35, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0xFF36, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0xFF37, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0xFF38, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0xFF39, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0xFF3A, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0xFF3B, .{ .compat = &[_]u21{
0x005B,
} });
try instance.map.put(0xFF3C, .{ .compat = &[_]u21{
0x005C,
} });
try instance.map.put(0xFF3D, .{ .compat = &[_]u21{
0x005D,
} });
try instance.map.put(0xFF3E, .{ .compat = &[_]u21{
0x005E,
} });
try instance.map.put(0xFF3F, .{ .compat = &[_]u21{
0x005F,
} });
try instance.map.put(0xFF40, .{ .compat = &[_]u21{
0x0060,
} });
try instance.map.put(0xFF41, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0xFF42, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0xFF43, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0xFF44, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0xFF45, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0xFF46, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0xFF47, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0xFF48, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0xFF49, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0xFF4A, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0xFF4B, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0xFF4C, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0xFF4D, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0xFF4E, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0xFF4F, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0xFF50, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0xFF51, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0xFF52, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0xFF53, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0xFF54, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0xFF55, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0xFF56, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0xFF57, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0xFF58, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0xFF59, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0xFF5A, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0xFF5B, .{ .compat = &[_]u21{
0x007B,
} });
try instance.map.put(0xFF5C, .{ .compat = &[_]u21{
0x007C,
} });
try instance.map.put(0xFF5D, .{ .compat = &[_]u21{
0x007D,
} });
try instance.map.put(0xFF5E, .{ .compat = &[_]u21{
0x007E,
} });
try instance.map.put(0xFF5F, .{ .compat = &[_]u21{
0x2985,
} });
try instance.map.put(0xFF60, .{ .compat = &[_]u21{
0x2986,
} });
try instance.map.put(0xFF61, .{ .compat = &[_]u21{
0x3002,
} });
try instance.map.put(0xFF62, .{ .compat = &[_]u21{
0x300C,
} });
try instance.map.put(0xFF63, .{ .compat = &[_]u21{
0x300D,
} });
try instance.map.put(0xFF64, .{ .compat = &[_]u21{
0x3001,
} });
try instance.map.put(0xFF65, .{ .compat = &[_]u21{
0x30FB,
} });
try instance.map.put(0xFF66, .{ .compat = &[_]u21{
0x30F2,
} });
try instance.map.put(0xFF67, .{ .compat = &[_]u21{
0x30A1,
} });
try instance.map.put(0xFF68, .{ .compat = &[_]u21{
0x30A3,
} });
try instance.map.put(0xFF69, .{ .compat = &[_]u21{
0x30A5,
} });
try instance.map.put(0xFF6A, .{ .compat = &[_]u21{
0x30A7,
} });
try instance.map.put(0xFF6B, .{ .compat = &[_]u21{
0x30A9,
} });
try instance.map.put(0xFF6C, .{ .compat = &[_]u21{
0x30E3,
} });
try instance.map.put(0xFF6D, .{ .compat = &[_]u21{
0x30E5,
} });
try instance.map.put(0xFF6E, .{ .compat = &[_]u21{
0x30E7,
} });
try instance.map.put(0xFF6F, .{ .compat = &[_]u21{
0x30C3,
} });
try instance.map.put(0xFF70, .{ .compat = &[_]u21{
0x30FC,
} });
try instance.map.put(0xFF71, .{ .compat = &[_]u21{
0x30A2,
} });
try instance.map.put(0xFF72, .{ .compat = &[_]u21{
0x30A4,
} });
try instance.map.put(0xFF73, .{ .compat = &[_]u21{
0x30A6,
} });
try instance.map.put(0xFF74, .{ .compat = &[_]u21{
0x30A8,
} });
try instance.map.put(0xFF75, .{ .compat = &[_]u21{
0x30AA,
} });
try instance.map.put(0xFF76, .{ .compat = &[_]u21{
0x30AB,
} });
try instance.map.put(0xFF77, .{ .compat = &[_]u21{
0x30AD,
} });
try instance.map.put(0xFF78, .{ .compat = &[_]u21{
0x30AF,
} });
try instance.map.put(0xFF79, .{ .compat = &[_]u21{
0x30B1,
} });
try instance.map.put(0xFF7A, .{ .compat = &[_]u21{
0x30B3,
} });
try instance.map.put(0xFF7B, .{ .compat = &[_]u21{
0x30B5,
} });
try instance.map.put(0xFF7C, .{ .compat = &[_]u21{
0x30B7,
} });
try instance.map.put(0xFF7D, .{ .compat = &[_]u21{
0x30B9,
} });
try instance.map.put(0xFF7E, .{ .compat = &[_]u21{
0x30BB,
} });
try instance.map.put(0xFF7F, .{ .compat = &[_]u21{
0x30BD,
} });
try instance.map.put(0xFF80, .{ .compat = &[_]u21{
0x30BF,
} });
try instance.map.put(0xFF81, .{ .compat = &[_]u21{
0x30C1,
} });
try instance.map.put(0xFF82, .{ .compat = &[_]u21{
0x30C4,
} });
try instance.map.put(0xFF83, .{ .compat = &[_]u21{
0x30C6,
} });
try instance.map.put(0xFF84, .{ .compat = &[_]u21{
0x30C8,
} });
try instance.map.put(0xFF85, .{ .compat = &[_]u21{
0x30CA,
} });
try instance.map.put(0xFF86, .{ .compat = &[_]u21{
0x30CB,
} });
try instance.map.put(0xFF87, .{ .compat = &[_]u21{
0x30CC,
} });
try instance.map.put(0xFF88, .{ .compat = &[_]u21{
0x30CD,
} });
try instance.map.put(0xFF89, .{ .compat = &[_]u21{
0x30CE,
} });
try instance.map.put(0xFF8A, .{ .compat = &[_]u21{
0x30CF,
} });
try instance.map.put(0xFF8B, .{ .compat = &[_]u21{
0x30D2,
} });
try instance.map.put(0xFF8C, .{ .compat = &[_]u21{
0x30D5,
} });
try instance.map.put(0xFF8D, .{ .compat = &[_]u21{
0x30D8,
} });
try instance.map.put(0xFF8E, .{ .compat = &[_]u21{
0x30DB,
} });
try instance.map.put(0xFF8F, .{ .compat = &[_]u21{
0x30DE,
} });
try instance.map.put(0xFF90, .{ .compat = &[_]u21{
0x30DF,
} });
try instance.map.put(0xFF91, .{ .compat = &[_]u21{
0x30E0,
} });
try instance.map.put(0xFF92, .{ .compat = &[_]u21{
0x30E1,
} });
try instance.map.put(0xFF93, .{ .compat = &[_]u21{
0x30E2,
} });
try instance.map.put(0xFF94, .{ .compat = &[_]u21{
0x30E4,
} });
try instance.map.put(0xFF95, .{ .compat = &[_]u21{
0x30E6,
} });
try instance.map.put(0xFF96, .{ .compat = &[_]u21{
0x30E8,
} });
try instance.map.put(0xFF97, .{ .compat = &[_]u21{
0x30E9,
} });
try instance.map.put(0xFF98, .{ .compat = &[_]u21{
0x30EA,
} });
try instance.map.put(0xFF99, .{ .compat = &[_]u21{
0x30EB,
} });
try instance.map.put(0xFF9A, .{ .compat = &[_]u21{
0x30EC,
} });
try instance.map.put(0xFF9B, .{ .compat = &[_]u21{
0x30ED,
} });
try instance.map.put(0xFF9C, .{ .compat = &[_]u21{
0x30EF,
} });
try instance.map.put(0xFF9D, .{ .compat = &[_]u21{
0x30F3,
} });
try instance.map.put(0xFF9E, .{ .compat = &[_]u21{
0x3099,
} });
try instance.map.put(0xFF9F, .{ .compat = &[_]u21{
0x309A,
} });
try instance.map.put(0xFFA0, .{ .compat = &[_]u21{
0x3164,
} });
try instance.map.put(0xFFA1, .{ .compat = &[_]u21{
0x3131,
} });
try instance.map.put(0xFFA2, .{ .compat = &[_]u21{
0x3132,
} });
try instance.map.put(0xFFA3, .{ .compat = &[_]u21{
0x3133,
} });
try instance.map.put(0xFFA4, .{ .compat = &[_]u21{
0x3134,
} });
try instance.map.put(0xFFA5, .{ .compat = &[_]u21{
0x3135,
} });
try instance.map.put(0xFFA6, .{ .compat = &[_]u21{
0x3136,
} });
try instance.map.put(0xFFA7, .{ .compat = &[_]u21{
0x3137,
} });
try instance.map.put(0xFFA8, .{ .compat = &[_]u21{
0x3138,
} });
try instance.map.put(0xFFA9, .{ .compat = &[_]u21{
0x3139,
} });
try instance.map.put(0xFFAA, .{ .compat = &[_]u21{
0x313A,
} });
try instance.map.put(0xFFAB, .{ .compat = &[_]u21{
0x313B,
} });
try instance.map.put(0xFFAC, .{ .compat = &[_]u21{
0x313C,
} });
try instance.map.put(0xFFAD, .{ .compat = &[_]u21{
0x313D,
} });
try instance.map.put(0xFFAE, .{ .compat = &[_]u21{
0x313E,
} });
try instance.map.put(0xFFAF, .{ .compat = &[_]u21{
0x313F,
} });
try instance.map.put(0xFFB0, .{ .compat = &[_]u21{
0x3140,
} });
try instance.map.put(0xFFB1, .{ .compat = &[_]u21{
0x3141,
} });
try instance.map.put(0xFFB2, .{ .compat = &[_]u21{
0x3142,
} });
try instance.map.put(0xFFB3, .{ .compat = &[_]u21{
0x3143,
} });
try instance.map.put(0xFFB4, .{ .compat = &[_]u21{
0x3144,
} });
try instance.map.put(0xFFB5, .{ .compat = &[_]u21{
0x3145,
} });
try instance.map.put(0xFFB6, .{ .compat = &[_]u21{
0x3146,
} });
try instance.map.put(0xFFB7, .{ .compat = &[_]u21{
0x3147,
} });
try instance.map.put(0xFFB8, .{ .compat = &[_]u21{
0x3148,
} });
try instance.map.put(0xFFB9, .{ .compat = &[_]u21{
0x3149,
} });
try instance.map.put(0xFFBA, .{ .compat = &[_]u21{
0x314A,
} });
try instance.map.put(0xFFBB, .{ .compat = &[_]u21{
0x314B,
} });
try instance.map.put(0xFFBC, .{ .compat = &[_]u21{
0x314C,
} });
try instance.map.put(0xFFBD, .{ .compat = &[_]u21{
0x314D,
} });
try instance.map.put(0xFFBE, .{ .compat = &[_]u21{
0x314E,
} });
try instance.map.put(0xFFC2, .{ .compat = &[_]u21{
0x314F,
} });
try instance.map.put(0xFFC3, .{ .compat = &[_]u21{
0x3150,
} });
try instance.map.put(0xFFC4, .{ .compat = &[_]u21{
0x3151,
} });
try instance.map.put(0xFFC5, .{ .compat = &[_]u21{
0x3152,
} });
try instance.map.put(0xFFC6, .{ .compat = &[_]u21{
0x3153,
} });
try instance.map.put(0xFFC7, .{ .compat = &[_]u21{
0x3154,
} });
try instance.map.put(0xFFCA, .{ .compat = &[_]u21{
0x3155,
} });
try instance.map.put(0xFFCB, .{ .compat = &[_]u21{
0x3156,
} });
try instance.map.put(0xFFCC, .{ .compat = &[_]u21{
0x3157,
} });
try instance.map.put(0xFFCD, .{ .compat = &[_]u21{
0x3158,
} });
try instance.map.put(0xFFCE, .{ .compat = &[_]u21{
0x3159,
} });
try instance.map.put(0xFFCF, .{ .compat = &[_]u21{
0x315A,
} });
try instance.map.put(0xFFD2, .{ .compat = &[_]u21{
0x315B,
} });
try instance.map.put(0xFFD3, .{ .compat = &[_]u21{
0x315C,
} });
try instance.map.put(0xFFD4, .{ .compat = &[_]u21{
0x315D,
} });
try instance.map.put(0xFFD5, .{ .compat = &[_]u21{
0x315E,
} });
try instance.map.put(0xFFD6, .{ .compat = &[_]u21{
0x315F,
} });
try instance.map.put(0xFFD7, .{ .compat = &[_]u21{
0x3160,
} });
try instance.map.put(0xFFDA, .{ .compat = &[_]u21{
0x3161,
} });
try instance.map.put(0xFFDB, .{ .compat = &[_]u21{
0x3162,
} });
try instance.map.put(0xFFDC, .{ .compat = &[_]u21{
0x3163,
} });
try instance.map.put(0xFFE0, .{ .compat = &[_]u21{
0x00A2,
} });
try instance.map.put(0xFFE1, .{ .compat = &[_]u21{
0x00A3,
} });
try instance.map.put(0xFFE2, .{ .compat = &[_]u21{
0x00AC,
} });
try instance.map.put(0xFFE3, .{ .compat = &[_]u21{
0x00AF,
} });
try instance.map.put(0xFFE4, .{ .compat = &[_]u21{
0x00A6,
} });
try instance.map.put(0xFFE5, .{ .compat = &[_]u21{
0x00A5,
} });
try instance.map.put(0xFFE6, .{ .compat = &[_]u21{
0x20A9,
} });
try instance.map.put(0xFFE8, .{ .compat = &[_]u21{
0x2502,
} });
try instance.map.put(0xFFE9, .{ .compat = &[_]u21{
0x2190,
} });
try instance.map.put(0xFFEA, .{ .compat = &[_]u21{
0x2191,
} });
try instance.map.put(0xFFEB, .{ .compat = &[_]u21{
0x2192,
} });
try instance.map.put(0xFFEC, .{ .compat = &[_]u21{
0x2193,
} });
try instance.map.put(0xFFED, .{ .compat = &[_]u21{
0x25A0,
} });
try instance.map.put(0xFFEE, .{ .compat = &[_]u21{
0x25CB,
} });
try instance.map.put(0x1109A, .{ .canon = [2]u21{
0x11099,
0x110BA,
} });
try instance.map.put(0x1109C, .{ .canon = [2]u21{
0x1109B,
0x110BA,
} });
try instance.map.put(0x110AB, .{ .canon = [2]u21{
0x110A5,
0x110BA,
} });
try instance.map.put(0x1112E, .{ .canon = [2]u21{
0x11131,
0x11127,
} });
try instance.map.put(0x1112F, .{ .canon = [2]u21{
0x11132,
0x11127,
} });
try instance.map.put(0x1134B, .{ .canon = [2]u21{
0x11347,
0x1133E,
} });
try instance.map.put(0x1134C, .{ .canon = [2]u21{
0x11347,
0x11357,
} });
try instance.map.put(0x114BB, .{ .canon = [2]u21{
0x114B9,
0x114BA,
} });
try instance.map.put(0x114BC, .{ .canon = [2]u21{
0x114B9,
0x114B0,
} });
try instance.map.put(0x114BE, .{ .canon = [2]u21{
0x114B9,
0x114BD,
} });
try instance.map.put(0x115BA, .{ .canon = [2]u21{
0x115B8,
0x115AF,
} });
try instance.map.put(0x115BB, .{ .canon = [2]u21{
0x115B9,
0x115AF,
} });
try instance.map.put(0x11938, .{ .canon = [2]u21{
0x11935,
0x11930,
} });
try instance.map.put(0x1D15E, .{ .canon = [2]u21{
0x1D157,
0x1D165,
} });
try instance.map.put(0x1D15F, .{ .canon = [2]u21{
0x1D158,
0x1D165,
} });
try instance.map.put(0x1D160, .{ .canon = [2]u21{
0x1D15F,
0x1D16E,
} });
try instance.map.put(0x1D161, .{ .canon = [2]u21{
0x1D15F,
0x1D16F,
} });
try instance.map.put(0x1D162, .{ .canon = [2]u21{
0x1D15F,
0x1D170,
} });
try instance.map.put(0x1D163, .{ .canon = [2]u21{
0x1D15F,
0x1D171,
} });
try instance.map.put(0x1D164, .{ .canon = [2]u21{
0x1D15F,
0x1D172,
} });
try instance.map.put(0x1D1BB, .{ .canon = [2]u21{
0x1D1B9,
0x1D165,
} });
try instance.map.put(0x1D1BC, .{ .canon = [2]u21{
0x1D1BA,
0x1D165,
} });
try instance.map.put(0x1D1BD, .{ .canon = [2]u21{
0x1D1BB,
0x1D16E,
} });
try instance.map.put(0x1D1BE, .{ .canon = [2]u21{
0x1D1BC,
0x1D16E,
} });
try instance.map.put(0x1D1BF, .{ .canon = [2]u21{
0x1D1BB,
0x1D16F,
} });
try instance.map.put(0x1D1C0, .{ .canon = [2]u21{
0x1D1BC,
0x1D16F,
} });
try instance.map.put(0x1D400, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D401, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D402, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D403, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D404, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D405, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D406, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D407, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D408, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D409, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D40A, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D40B, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D40C, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D40D, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D40E, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D40F, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D410, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D411, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D412, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D413, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D414, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D415, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D416, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D417, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D418, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D419, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D41A, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D41B, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D41C, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D41D, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D41E, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D41F, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D420, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D421, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D422, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D423, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D424, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D425, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D426, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D427, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D428, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D429, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D42A, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D42B, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D42C, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D42D, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D42E, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D42F, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D430, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D431, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D432, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D433, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D434, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D435, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D436, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D437, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D438, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D439, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D43A, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D43B, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D43C, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D43D, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D43E, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D43F, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D440, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D441, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D442, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D443, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D444, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D445, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D446, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D447, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D448, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D449, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D44A, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D44B, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D44C, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D44D, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D44E, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D44F, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D450, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D451, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D452, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D453, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D454, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D456, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D457, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D458, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D459, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D45A, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D45B, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D45C, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D45D, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D45E, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D45F, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D460, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D461, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D462, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D463, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D464, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D465, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D466, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D467, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D468, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D469, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D46A, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D46B, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D46C, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D46D, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D46E, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D46F, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D470, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D471, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D472, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D473, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D474, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D475, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D476, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D477, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D478, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D479, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D47A, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D47B, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D47C, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D47D, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D47E, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D47F, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D480, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D481, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D482, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D483, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D484, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D485, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D486, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D487, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D488, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D489, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D48A, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D48B, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D48C, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D48D, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D48E, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D48F, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D490, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D491, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D492, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D493, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D494, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D495, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D496, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D497, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D498, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D499, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D49A, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D49B, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D49C, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D49E, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D49F, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D4A2, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D4A5, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D4A6, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D4A9, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D4AA, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D4AB, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D4AC, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D4AE, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D4AF, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D4B0, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D4B1, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D4B2, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D4B3, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D4B4, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D4B5, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D4B6, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D4B7, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D4B8, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D4B9, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D4BB, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D4BD, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D4BE, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D4BF, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D4C0, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D4C1, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D4C2, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D4C3, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D4C5, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D4C6, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D4C7, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D4C8, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D4C9, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D4CA, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D4CB, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D4CC, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D4CD, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D4CE, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D4CF, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D4D0, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D4D1, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D4D2, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D4D3, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D4D4, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D4D5, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D4D6, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D4D7, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D4D8, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D4D9, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D4DA, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D4DB, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D4DC, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D4DD, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D4DE, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D4DF, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D4E0, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D4E1, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D4E2, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D4E3, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D4E4, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D4E5, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D4E6, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D4E7, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D4E8, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D4E9, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D4EA, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D4EB, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D4EC, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D4ED, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D4EE, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D4EF, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D4F0, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D4F1, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D4F2, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D4F3, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D4F4, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D4F5, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D4F6, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D4F7, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D4F8, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D4F9, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D4FA, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D4FB, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D4FC, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D4FD, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D4FE, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D4FF, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D500, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D501, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D502, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D503, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D504, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D505, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D507, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D508, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D509, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D50A, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D50D, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D50E, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D50F, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D510, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D511, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D512, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D513, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D514, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D516, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D517, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D518, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D519, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D51A, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D51B, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D51C, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D51E, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D51F, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D520, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D521, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D522, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D523, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D524, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D525, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D526, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D527, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D528, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D529, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D52A, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D52B, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D52C, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D52D, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D52E, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D52F, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D530, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D531, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D532, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D533, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D534, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D535, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D536, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D537, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D538, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D539, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D53B, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D53C, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D53D, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D53E, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D540, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D541, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D542, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D543, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D544, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D546, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D54A, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D54B, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D54C, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D54D, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D54E, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D54F, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D550, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D552, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D553, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D554, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D555, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D556, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D557, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D558, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D559, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D55A, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D55B, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D55C, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D55D, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D55E, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D55F, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D560, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D561, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D562, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D563, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D564, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D565, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D566, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D567, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D568, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D569, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D56A, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D56B, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D56C, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D56D, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D56E, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D56F, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D570, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D571, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D572, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D573, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D574, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D575, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D576, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D577, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D578, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D579, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D57A, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D57B, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D57C, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D57D, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D57E, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D57F, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D580, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D581, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D582, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D583, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D584, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D585, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D586, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D587, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D588, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D589, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D58A, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D58B, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D58C, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D58D, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D58E, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D58F, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D590, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D591, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D592, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D593, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D594, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D595, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D596, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D597, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D598, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D599, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D59A, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D59B, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D59C, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D59D, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D59E, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D59F, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D5A0, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D5A1, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D5A2, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D5A3, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D5A4, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D5A5, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D5A6, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D5A7, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D5A8, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D5A9, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D5AA, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D5AB, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D5AC, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D5AD, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D5AE, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D5AF, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D5B0, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D5B1, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D5B2, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D5B3, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D5B4, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D5B5, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D5B6, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D5B7, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D5B8, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D5B9, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D5BA, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D5BB, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D5BC, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D5BD, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D5BE, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D5BF, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D5C0, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D5C1, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D5C2, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D5C3, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D5C4, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D5C5, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D5C6, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D5C7, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D5C8, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D5C9, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D5CA, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D5CB, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D5CC, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D5CD, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D5CE, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D5CF, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D5D0, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D5D1, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D5D2, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D5D3, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D5D4, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D5D5, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D5D6, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D5D7, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D5D8, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D5D9, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D5DA, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D5DB, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D5DC, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D5DD, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D5DE, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D5DF, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D5E0, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D5E1, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D5E2, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D5E3, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D5E4, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D5E5, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D5E6, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D5E7, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D5E8, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D5E9, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D5EA, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D5EB, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D5EC, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D5ED, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D5EE, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D5EF, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D5F0, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D5F1, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D5F2, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D5F3, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D5F4, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D5F5, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D5F6, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D5F7, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D5F8, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D5F9, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D5FA, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D5FB, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D5FC, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D5FD, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D5FE, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D5FF, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D600, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D601, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D602, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D603, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D604, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D605, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D606, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D607, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D608, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D609, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D60A, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D60B, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D60C, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D60D, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D60E, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D60F, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D610, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D611, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D612, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D613, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D614, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D615, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D616, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D617, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D618, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D619, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D61A, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D61B, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D61C, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D61D, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D61E, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D61F, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D620, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D621, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D622, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D623, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D624, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D625, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D626, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D627, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D628, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D629, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D62A, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D62B, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D62C, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D62D, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D62E, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D62F, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D630, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D631, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D632, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D633, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D634, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D635, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D636, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D637, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D638, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D639, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D63A, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D63B, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D63C, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D63D, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D63E, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D63F, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D640, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D641, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D642, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D643, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D644, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D645, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D646, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D647, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D648, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D649, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D64A, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D64B, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D64C, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D64D, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D64E, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D64F, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D650, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D651, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D652, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D653, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D654, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D655, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D656, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D657, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D658, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D659, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D65A, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D65B, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D65C, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D65D, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D65E, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D65F, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D660, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D661, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D662, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D663, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D664, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D665, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D666, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D667, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D668, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D669, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D66A, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D66B, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D66C, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D66D, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D66E, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D66F, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D670, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1D671, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1D672, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1D673, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1D674, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1D675, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1D676, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1D677, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1D678, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1D679, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1D67A, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1D67B, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1D67C, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1D67D, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1D67E, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1D67F, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1D680, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1D681, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1D682, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1D683, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1D684, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1D685, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1D686, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1D687, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1D688, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1D689, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1D68A, .{ .compat = &[_]u21{
0x0061,
} });
try instance.map.put(0x1D68B, .{ .compat = &[_]u21{
0x0062,
} });
try instance.map.put(0x1D68C, .{ .compat = &[_]u21{
0x0063,
} });
try instance.map.put(0x1D68D, .{ .compat = &[_]u21{
0x0064,
} });
try instance.map.put(0x1D68E, .{ .compat = &[_]u21{
0x0065,
} });
try instance.map.put(0x1D68F, .{ .compat = &[_]u21{
0x0066,
} });
try instance.map.put(0x1D690, .{ .compat = &[_]u21{
0x0067,
} });
try instance.map.put(0x1D691, .{ .compat = &[_]u21{
0x0068,
} });
try instance.map.put(0x1D692, .{ .compat = &[_]u21{
0x0069,
} });
try instance.map.put(0x1D693, .{ .compat = &[_]u21{
0x006A,
} });
try instance.map.put(0x1D694, .{ .compat = &[_]u21{
0x006B,
} });
try instance.map.put(0x1D695, .{ .compat = &[_]u21{
0x006C,
} });
try instance.map.put(0x1D696, .{ .compat = &[_]u21{
0x006D,
} });
try instance.map.put(0x1D697, .{ .compat = &[_]u21{
0x006E,
} });
try instance.map.put(0x1D698, .{ .compat = &[_]u21{
0x006F,
} });
try instance.map.put(0x1D699, .{ .compat = &[_]u21{
0x0070,
} });
try instance.map.put(0x1D69A, .{ .compat = &[_]u21{
0x0071,
} });
try instance.map.put(0x1D69B, .{ .compat = &[_]u21{
0x0072,
} });
try instance.map.put(0x1D69C, .{ .compat = &[_]u21{
0x0073,
} });
try instance.map.put(0x1D69D, .{ .compat = &[_]u21{
0x0074,
} });
try instance.map.put(0x1D69E, .{ .compat = &[_]u21{
0x0075,
} });
try instance.map.put(0x1D69F, .{ .compat = &[_]u21{
0x0076,
} });
try instance.map.put(0x1D6A0, .{ .compat = &[_]u21{
0x0077,
} });
try instance.map.put(0x1D6A1, .{ .compat = &[_]u21{
0x0078,
} });
try instance.map.put(0x1D6A2, .{ .compat = &[_]u21{
0x0079,
} });
try instance.map.put(0x1D6A3, .{ .compat = &[_]u21{
0x007A,
} });
try instance.map.put(0x1D6A4, .{ .compat = &[_]u21{
0x0131,
} });
try instance.map.put(0x1D6A5, .{ .compat = &[_]u21{
0x0237,
} });
try instance.map.put(0x1D6A8, .{ .compat = &[_]u21{
0x0391,
} });
try instance.map.put(0x1D6A9, .{ .compat = &[_]u21{
0x0392,
} });
try instance.map.put(0x1D6AA, .{ .compat = &[_]u21{
0x0393,
} });
try instance.map.put(0x1D6AB, .{ .compat = &[_]u21{
0x0394,
} });
try instance.map.put(0x1D6AC, .{ .compat = &[_]u21{
0x0395,
} });
try instance.map.put(0x1D6AD, .{ .compat = &[_]u21{
0x0396,
} });
try instance.map.put(0x1D6AE, .{ .compat = &[_]u21{
0x0397,
} });
try instance.map.put(0x1D6AF, .{ .compat = &[_]u21{
0x0398,
} });
try instance.map.put(0x1D6B0, .{ .compat = &[_]u21{
0x0399,
} });
try instance.map.put(0x1D6B1, .{ .compat = &[_]u21{
0x039A,
} });
try instance.map.put(0x1D6B2, .{ .compat = &[_]u21{
0x039B,
} });
try instance.map.put(0x1D6B3, .{ .compat = &[_]u21{
0x039C,
} });
try instance.map.put(0x1D6B4, .{ .compat = &[_]u21{
0x039D,
} });
try instance.map.put(0x1D6B5, .{ .compat = &[_]u21{
0x039E,
} });
try instance.map.put(0x1D6B6, .{ .compat = &[_]u21{
0x039F,
} });
try instance.map.put(0x1D6B7, .{ .compat = &[_]u21{
0x03A0,
} });
try instance.map.put(0x1D6B8, .{ .compat = &[_]u21{
0x03A1,
} });
try instance.map.put(0x1D6B9, .{ .compat = &[_]u21{
0x03F4,
} });
try instance.map.put(0x1D6BA, .{ .compat = &[_]u21{
0x03A3,
} });
try instance.map.put(0x1D6BB, .{ .compat = &[_]u21{
0x03A4,
} });
try instance.map.put(0x1D6BC, .{ .compat = &[_]u21{
0x03A5,
} });
try instance.map.put(0x1D6BD, .{ .compat = &[_]u21{
0x03A6,
} });
try instance.map.put(0x1D6BE, .{ .compat = &[_]u21{
0x03A7,
} });
try instance.map.put(0x1D6BF, .{ .compat = &[_]u21{
0x03A8,
} });
try instance.map.put(0x1D6C0, .{ .compat = &[_]u21{
0x03A9,
} });
try instance.map.put(0x1D6C1, .{ .compat = &[_]u21{
0x2207,
} });
try instance.map.put(0x1D6C2, .{ .compat = &[_]u21{
0x03B1,
} });
try instance.map.put(0x1D6C3, .{ .compat = &[_]u21{
0x03B2,
} });
try instance.map.put(0x1D6C4, .{ .compat = &[_]u21{
0x03B3,
} });
try instance.map.put(0x1D6C5, .{ .compat = &[_]u21{
0x03B4,
} });
try instance.map.put(0x1D6C6, .{ .compat = &[_]u21{
0x03B5,
} });
try instance.map.put(0x1D6C7, .{ .compat = &[_]u21{
0x03B6,
} });
try instance.map.put(0x1D6C8, .{ .compat = &[_]u21{
0x03B7,
} });
try instance.map.put(0x1D6C9, .{ .compat = &[_]u21{
0x03B8,
} });
try instance.map.put(0x1D6CA, .{ .compat = &[_]u21{
0x03B9,
} });
try instance.map.put(0x1D6CB, .{ .compat = &[_]u21{
0x03BA,
} });
try instance.map.put(0x1D6CC, .{ .compat = &[_]u21{
0x03BB,
} });
try instance.map.put(0x1D6CD, .{ .compat = &[_]u21{
0x03BC,
} });
try instance.map.put(0x1D6CE, .{ .compat = &[_]u21{
0x03BD,
} });
try instance.map.put(0x1D6CF, .{ .compat = &[_]u21{
0x03BE,
} });
try instance.map.put(0x1D6D0, .{ .compat = &[_]u21{
0x03BF,
} });
try instance.map.put(0x1D6D1, .{ .compat = &[_]u21{
0x03C0,
} });
try instance.map.put(0x1D6D2, .{ .compat = &[_]u21{
0x03C1,
} });
try instance.map.put(0x1D6D3, .{ .compat = &[_]u21{
0x03C2,
} });
try instance.map.put(0x1D6D4, .{ .compat = &[_]u21{
0x03C3,
} });
try instance.map.put(0x1D6D5, .{ .compat = &[_]u21{
0x03C4,
} });
try instance.map.put(0x1D6D6, .{ .compat = &[_]u21{
0x03C5,
} });
try instance.map.put(0x1D6D7, .{ .compat = &[_]u21{
0x03C6,
} });
try instance.map.put(0x1D6D8, .{ .compat = &[_]u21{
0x03C7,
} });
try instance.map.put(0x1D6D9, .{ .compat = &[_]u21{
0x03C8,
} });
try instance.map.put(0x1D6DA, .{ .compat = &[_]u21{
0x03C9,
} });
try instance.map.put(0x1D6DB, .{ .compat = &[_]u21{
0x2202,
} });
try instance.map.put(0x1D6DC, .{ .compat = &[_]u21{
0x03F5,
} });
try instance.map.put(0x1D6DD, .{ .compat = &[_]u21{
0x03D1,
} });
try instance.map.put(0x1D6DE, .{ .compat = &[_]u21{
0x03F0,
} });
try instance.map.put(0x1D6DF, .{ .compat = &[_]u21{
0x03D5,
} });
try instance.map.put(0x1D6E0, .{ .compat = &[_]u21{
0x03F1,
} });
try instance.map.put(0x1D6E1, .{ .compat = &[_]u21{
0x03D6,
} });
try instance.map.put(0x1D6E2, .{ .compat = &[_]u21{
0x0391,
} });
try instance.map.put(0x1D6E3, .{ .compat = &[_]u21{
0x0392,
} });
try instance.map.put(0x1D6E4, .{ .compat = &[_]u21{
0x0393,
} });
try instance.map.put(0x1D6E5, .{ .compat = &[_]u21{
0x0394,
} });
try instance.map.put(0x1D6E6, .{ .compat = &[_]u21{
0x0395,
} });
try instance.map.put(0x1D6E7, .{ .compat = &[_]u21{
0x0396,
} });
try instance.map.put(0x1D6E8, .{ .compat = &[_]u21{
0x0397,
} });
try instance.map.put(0x1D6E9, .{ .compat = &[_]u21{
0x0398,
} });
try instance.map.put(0x1D6EA, .{ .compat = &[_]u21{
0x0399,
} });
try instance.map.put(0x1D6EB, .{ .compat = &[_]u21{
0x039A,
} });
try instance.map.put(0x1D6EC, .{ .compat = &[_]u21{
0x039B,
} });
try instance.map.put(0x1D6ED, .{ .compat = &[_]u21{
0x039C,
} });
try instance.map.put(0x1D6EE, .{ .compat = &[_]u21{
0x039D,
} });
try instance.map.put(0x1D6EF, .{ .compat = &[_]u21{
0x039E,
} });
try instance.map.put(0x1D6F0, .{ .compat = &[_]u21{
0x039F,
} });
try instance.map.put(0x1D6F1, .{ .compat = &[_]u21{
0x03A0,
} });
try instance.map.put(0x1D6F2, .{ .compat = &[_]u21{
0x03A1,
} });
try instance.map.put(0x1D6F3, .{ .compat = &[_]u21{
0x03F4,
} });
try instance.map.put(0x1D6F4, .{ .compat = &[_]u21{
0x03A3,
} });
try instance.map.put(0x1D6F5, .{ .compat = &[_]u21{
0x03A4,
} });
try instance.map.put(0x1D6F6, .{ .compat = &[_]u21{
0x03A5,
} });
try instance.map.put(0x1D6F7, .{ .compat = &[_]u21{
0x03A6,
} });
try instance.map.put(0x1D6F8, .{ .compat = &[_]u21{
0x03A7,
} });
try instance.map.put(0x1D6F9, .{ .compat = &[_]u21{
0x03A8,
} });
try instance.map.put(0x1D6FA, .{ .compat = &[_]u21{
0x03A9,
} });
try instance.map.put(0x1D6FB, .{ .compat = &[_]u21{
0x2207,
} });
try instance.map.put(0x1D6FC, .{ .compat = &[_]u21{
0x03B1,
} });
try instance.map.put(0x1D6FD, .{ .compat = &[_]u21{
0x03B2,
} });
try instance.map.put(0x1D6FE, .{ .compat = &[_]u21{
0x03B3,
} });
try instance.map.put(0x1D6FF, .{ .compat = &[_]u21{
0x03B4,
} });
try instance.map.put(0x1D700, .{ .compat = &[_]u21{
0x03B5,
} });
try instance.map.put(0x1D701, .{ .compat = &[_]u21{
0x03B6,
} });
try instance.map.put(0x1D702, .{ .compat = &[_]u21{
0x03B7,
} });
try instance.map.put(0x1D703, .{ .compat = &[_]u21{
0x03B8,
} });
try instance.map.put(0x1D704, .{ .compat = &[_]u21{
0x03B9,
} });
try instance.map.put(0x1D705, .{ .compat = &[_]u21{
0x03BA,
} });
try instance.map.put(0x1D706, .{ .compat = &[_]u21{
0x03BB,
} });
try instance.map.put(0x1D707, .{ .compat = &[_]u21{
0x03BC,
} });
try instance.map.put(0x1D708, .{ .compat = &[_]u21{
0x03BD,
} });
try instance.map.put(0x1D709, .{ .compat = &[_]u21{
0x03BE,
} });
try instance.map.put(0x1D70A, .{ .compat = &[_]u21{
0x03BF,
} });
try instance.map.put(0x1D70B, .{ .compat = &[_]u21{
0x03C0,
} });
try instance.map.put(0x1D70C, .{ .compat = &[_]u21{
0x03C1,
} });
try instance.map.put(0x1D70D, .{ .compat = &[_]u21{
0x03C2,
} });
try instance.map.put(0x1D70E, .{ .compat = &[_]u21{
0x03C3,
} });
try instance.map.put(0x1D70F, .{ .compat = &[_]u21{
0x03C4,
} });
try instance.map.put(0x1D710, .{ .compat = &[_]u21{
0x03C5,
} });
try instance.map.put(0x1D711, .{ .compat = &[_]u21{
0x03C6,
} });
try instance.map.put(0x1D712, .{ .compat = &[_]u21{
0x03C7,
} });
try instance.map.put(0x1D713, .{ .compat = &[_]u21{
0x03C8,
} });
try instance.map.put(0x1D714, .{ .compat = &[_]u21{
0x03C9,
} });
try instance.map.put(0x1D715, .{ .compat = &[_]u21{
0x2202,
} });
try instance.map.put(0x1D716, .{ .compat = &[_]u21{
0x03F5,
} });
try instance.map.put(0x1D717, .{ .compat = &[_]u21{
0x03D1,
} });
try instance.map.put(0x1D718, .{ .compat = &[_]u21{
0x03F0,
} });
try instance.map.put(0x1D719, .{ .compat = &[_]u21{
0x03D5,
} });
try instance.map.put(0x1D71A, .{ .compat = &[_]u21{
0x03F1,
} });
try instance.map.put(0x1D71B, .{ .compat = &[_]u21{
0x03D6,
} });
try instance.map.put(0x1D71C, .{ .compat = &[_]u21{
0x0391,
} });
try instance.map.put(0x1D71D, .{ .compat = &[_]u21{
0x0392,
} });
try instance.map.put(0x1D71E, .{ .compat = &[_]u21{
0x0393,
} });
try instance.map.put(0x1D71F, .{ .compat = &[_]u21{
0x0394,
} });
try instance.map.put(0x1D720, .{ .compat = &[_]u21{
0x0395,
} });
try instance.map.put(0x1D721, .{ .compat = &[_]u21{
0x0396,
} });
try instance.map.put(0x1D722, .{ .compat = &[_]u21{
0x0397,
} });
try instance.map.put(0x1D723, .{ .compat = &[_]u21{
0x0398,
} });
try instance.map.put(0x1D724, .{ .compat = &[_]u21{
0x0399,
} });
try instance.map.put(0x1D725, .{ .compat = &[_]u21{
0x039A,
} });
try instance.map.put(0x1D726, .{ .compat = &[_]u21{
0x039B,
} });
try instance.map.put(0x1D727, .{ .compat = &[_]u21{
0x039C,
} });
try instance.map.put(0x1D728, .{ .compat = &[_]u21{
0x039D,
} });
try instance.map.put(0x1D729, .{ .compat = &[_]u21{
0x039E,
} });
try instance.map.put(0x1D72A, .{ .compat = &[_]u21{
0x039F,
} });
try instance.map.put(0x1D72B, .{ .compat = &[_]u21{
0x03A0,
} });
try instance.map.put(0x1D72C, .{ .compat = &[_]u21{
0x03A1,
} });
try instance.map.put(0x1D72D, .{ .compat = &[_]u21{
0x03F4,
} });
try instance.map.put(0x1D72E, .{ .compat = &[_]u21{
0x03A3,
} });
try instance.map.put(0x1D72F, .{ .compat = &[_]u21{
0x03A4,
} });
try instance.map.put(0x1D730, .{ .compat = &[_]u21{
0x03A5,
} });
try instance.map.put(0x1D731, .{ .compat = &[_]u21{
0x03A6,
} });
try instance.map.put(0x1D732, .{ .compat = &[_]u21{
0x03A7,
} });
try instance.map.put(0x1D733, .{ .compat = &[_]u21{
0x03A8,
} });
try instance.map.put(0x1D734, .{ .compat = &[_]u21{
0x03A9,
} });
try instance.map.put(0x1D735, .{ .compat = &[_]u21{
0x2207,
} });
try instance.map.put(0x1D736, .{ .compat = &[_]u21{
0x03B1,
} });
try instance.map.put(0x1D737, .{ .compat = &[_]u21{
0x03B2,
} });
try instance.map.put(0x1D738, .{ .compat = &[_]u21{
0x03B3,
} });
try instance.map.put(0x1D739, .{ .compat = &[_]u21{
0x03B4,
} });
try instance.map.put(0x1D73A, .{ .compat = &[_]u21{
0x03B5,
} });
try instance.map.put(0x1D73B, .{ .compat = &[_]u21{
0x03B6,
} });
try instance.map.put(0x1D73C, .{ .compat = &[_]u21{
0x03B7,
} });
try instance.map.put(0x1D73D, .{ .compat = &[_]u21{
0x03B8,
} });
try instance.map.put(0x1D73E, .{ .compat = &[_]u21{
0x03B9,
} });
try instance.map.put(0x1D73F, .{ .compat = &[_]u21{
0x03BA,
} });
try instance.map.put(0x1D740, .{ .compat = &[_]u21{
0x03BB,
} });
try instance.map.put(0x1D741, .{ .compat = &[_]u21{
0x03BC,
} });
try instance.map.put(0x1D742, .{ .compat = &[_]u21{
0x03BD,
} });
try instance.map.put(0x1D743, .{ .compat = &[_]u21{
0x03BE,
} });
try instance.map.put(0x1D744, .{ .compat = &[_]u21{
0x03BF,
} });
try instance.map.put(0x1D745, .{ .compat = &[_]u21{
0x03C0,
} });
try instance.map.put(0x1D746, .{ .compat = &[_]u21{
0x03C1,
} });
try instance.map.put(0x1D747, .{ .compat = &[_]u21{
0x03C2,
} });
try instance.map.put(0x1D748, .{ .compat = &[_]u21{
0x03C3,
} });
try instance.map.put(0x1D749, .{ .compat = &[_]u21{
0x03C4,
} });
try instance.map.put(0x1D74A, .{ .compat = &[_]u21{
0x03C5,
} });
try instance.map.put(0x1D74B, .{ .compat = &[_]u21{
0x03C6,
} });
try instance.map.put(0x1D74C, .{ .compat = &[_]u21{
0x03C7,
} });
try instance.map.put(0x1D74D, .{ .compat = &[_]u21{
0x03C8,
} });
try instance.map.put(0x1D74E, .{ .compat = &[_]u21{
0x03C9,
} });
try instance.map.put(0x1D74F, .{ .compat = &[_]u21{
0x2202,
} });
try instance.map.put(0x1D750, .{ .compat = &[_]u21{
0x03F5,
} });
try instance.map.put(0x1D751, .{ .compat = &[_]u21{
0x03D1,
} });
try instance.map.put(0x1D752, .{ .compat = &[_]u21{
0x03F0,
} });
try instance.map.put(0x1D753, .{ .compat = &[_]u21{
0x03D5,
} });
try instance.map.put(0x1D754, .{ .compat = &[_]u21{
0x03F1,
} });
try instance.map.put(0x1D755, .{ .compat = &[_]u21{
0x03D6,
} });
try instance.map.put(0x1D756, .{ .compat = &[_]u21{
0x0391,
} });
try instance.map.put(0x1D757, .{ .compat = &[_]u21{
0x0392,
} });
try instance.map.put(0x1D758, .{ .compat = &[_]u21{
0x0393,
} });
try instance.map.put(0x1D759, .{ .compat = &[_]u21{
0x0394,
} });
try instance.map.put(0x1D75A, .{ .compat = &[_]u21{
0x0395,
} });
try instance.map.put(0x1D75B, .{ .compat = &[_]u21{
0x0396,
} });
try instance.map.put(0x1D75C, .{ .compat = &[_]u21{
0x0397,
} });
try instance.map.put(0x1D75D, .{ .compat = &[_]u21{
0x0398,
} });
try instance.map.put(0x1D75E, .{ .compat = &[_]u21{
0x0399,
} });
try instance.map.put(0x1D75F, .{ .compat = &[_]u21{
0x039A,
} });
try instance.map.put(0x1D760, .{ .compat = &[_]u21{
0x039B,
} });
try instance.map.put(0x1D761, .{ .compat = &[_]u21{
0x039C,
} });
try instance.map.put(0x1D762, .{ .compat = &[_]u21{
0x039D,
} });
try instance.map.put(0x1D763, .{ .compat = &[_]u21{
0x039E,
} });
try instance.map.put(0x1D764, .{ .compat = &[_]u21{
0x039F,
} });
try instance.map.put(0x1D765, .{ .compat = &[_]u21{
0x03A0,
} });
try instance.map.put(0x1D766, .{ .compat = &[_]u21{
0x03A1,
} });
try instance.map.put(0x1D767, .{ .compat = &[_]u21{
0x03F4,
} });
try instance.map.put(0x1D768, .{ .compat = &[_]u21{
0x03A3,
} });
try instance.map.put(0x1D769, .{ .compat = &[_]u21{
0x03A4,
} });
try instance.map.put(0x1D76A, .{ .compat = &[_]u21{
0x03A5,
} });
try instance.map.put(0x1D76B, .{ .compat = &[_]u21{
0x03A6,
} });
try instance.map.put(0x1D76C, .{ .compat = &[_]u21{
0x03A7,
} });
try instance.map.put(0x1D76D, .{ .compat = &[_]u21{
0x03A8,
} });
try instance.map.put(0x1D76E, .{ .compat = &[_]u21{
0x03A9,
} });
try instance.map.put(0x1D76F, .{ .compat = &[_]u21{
0x2207,
} });
try instance.map.put(0x1D770, .{ .compat = &[_]u21{
0x03B1,
} });
try instance.map.put(0x1D771, .{ .compat = &[_]u21{
0x03B2,
} });
try instance.map.put(0x1D772, .{ .compat = &[_]u21{
0x03B3,
} });
try instance.map.put(0x1D773, .{ .compat = &[_]u21{
0x03B4,
} });
try instance.map.put(0x1D774, .{ .compat = &[_]u21{
0x03B5,
} });
try instance.map.put(0x1D775, .{ .compat = &[_]u21{
0x03B6,
} });
try instance.map.put(0x1D776, .{ .compat = &[_]u21{
0x03B7,
} });
try instance.map.put(0x1D777, .{ .compat = &[_]u21{
0x03B8,
} });
try instance.map.put(0x1D778, .{ .compat = &[_]u21{
0x03B9,
} });
try instance.map.put(0x1D779, .{ .compat = &[_]u21{
0x03BA,
} });
try instance.map.put(0x1D77A, .{ .compat = &[_]u21{
0x03BB,
} });
try instance.map.put(0x1D77B, .{ .compat = &[_]u21{
0x03BC,
} });
try instance.map.put(0x1D77C, .{ .compat = &[_]u21{
0x03BD,
} });
try instance.map.put(0x1D77D, .{ .compat = &[_]u21{
0x03BE,
} });
try instance.map.put(0x1D77E, .{ .compat = &[_]u21{
0x03BF,
} });
try instance.map.put(0x1D77F, .{ .compat = &[_]u21{
0x03C0,
} });
try instance.map.put(0x1D780, .{ .compat = &[_]u21{
0x03C1,
} });
try instance.map.put(0x1D781, .{ .compat = &[_]u21{
0x03C2,
} });
try instance.map.put(0x1D782, .{ .compat = &[_]u21{
0x03C3,
} });
try instance.map.put(0x1D783, .{ .compat = &[_]u21{
0x03C4,
} });
try instance.map.put(0x1D784, .{ .compat = &[_]u21{
0x03C5,
} });
try instance.map.put(0x1D785, .{ .compat = &[_]u21{
0x03C6,
} });
try instance.map.put(0x1D786, .{ .compat = &[_]u21{
0x03C7,
} });
try instance.map.put(0x1D787, .{ .compat = &[_]u21{
0x03C8,
} });
try instance.map.put(0x1D788, .{ .compat = &[_]u21{
0x03C9,
} });
try instance.map.put(0x1D789, .{ .compat = &[_]u21{
0x2202,
} });
try instance.map.put(0x1D78A, .{ .compat = &[_]u21{
0x03F5,
} });
try instance.map.put(0x1D78B, .{ .compat = &[_]u21{
0x03D1,
} });
try instance.map.put(0x1D78C, .{ .compat = &[_]u21{
0x03F0,
} });
try instance.map.put(0x1D78D, .{ .compat = &[_]u21{
0x03D5,
} });
try instance.map.put(0x1D78E, .{ .compat = &[_]u21{
0x03F1,
} });
try instance.map.put(0x1D78F, .{ .compat = &[_]u21{
0x03D6,
} });
try instance.map.put(0x1D790, .{ .compat = &[_]u21{
0x0391,
} });
try instance.map.put(0x1D791, .{ .compat = &[_]u21{
0x0392,
} });
try instance.map.put(0x1D792, .{ .compat = &[_]u21{
0x0393,
} });
try instance.map.put(0x1D793, .{ .compat = &[_]u21{
0x0394,
} });
try instance.map.put(0x1D794, .{ .compat = &[_]u21{
0x0395,
} });
try instance.map.put(0x1D795, .{ .compat = &[_]u21{
0x0396,
} });
try instance.map.put(0x1D796, .{ .compat = &[_]u21{
0x0397,
} });
try instance.map.put(0x1D797, .{ .compat = &[_]u21{
0x0398,
} });
try instance.map.put(0x1D798, .{ .compat = &[_]u21{
0x0399,
} });
try instance.map.put(0x1D799, .{ .compat = &[_]u21{
0x039A,
} });
try instance.map.put(0x1D79A, .{ .compat = &[_]u21{
0x039B,
} });
try instance.map.put(0x1D79B, .{ .compat = &[_]u21{
0x039C,
} });
try instance.map.put(0x1D79C, .{ .compat = &[_]u21{
0x039D,
} });
try instance.map.put(0x1D79D, .{ .compat = &[_]u21{
0x039E,
} });
try instance.map.put(0x1D79E, .{ .compat = &[_]u21{
0x039F,
} });
try instance.map.put(0x1D79F, .{ .compat = &[_]u21{
0x03A0,
} });
try instance.map.put(0x1D7A0, .{ .compat = &[_]u21{
0x03A1,
} });
try instance.map.put(0x1D7A1, .{ .compat = &[_]u21{
0x03F4,
} });
try instance.map.put(0x1D7A2, .{ .compat = &[_]u21{
0x03A3,
} });
try instance.map.put(0x1D7A3, .{ .compat = &[_]u21{
0x03A4,
} });
try instance.map.put(0x1D7A4, .{ .compat = &[_]u21{
0x03A5,
} });
try instance.map.put(0x1D7A5, .{ .compat = &[_]u21{
0x03A6,
} });
try instance.map.put(0x1D7A6, .{ .compat = &[_]u21{
0x03A7,
} });
try instance.map.put(0x1D7A7, .{ .compat = &[_]u21{
0x03A8,
} });
try instance.map.put(0x1D7A8, .{ .compat = &[_]u21{
0x03A9,
} });
try instance.map.put(0x1D7A9, .{ .compat = &[_]u21{
0x2207,
} });
try instance.map.put(0x1D7AA, .{ .compat = &[_]u21{
0x03B1,
} });
try instance.map.put(0x1D7AB, .{ .compat = &[_]u21{
0x03B2,
} });
try instance.map.put(0x1D7AC, .{ .compat = &[_]u21{
0x03B3,
} });
try instance.map.put(0x1D7AD, .{ .compat = &[_]u21{
0x03B4,
} });
try instance.map.put(0x1D7AE, .{ .compat = &[_]u21{
0x03B5,
} });
try instance.map.put(0x1D7AF, .{ .compat = &[_]u21{
0x03B6,
} });
try instance.map.put(0x1D7B0, .{ .compat = &[_]u21{
0x03B7,
} });
try instance.map.put(0x1D7B1, .{ .compat = &[_]u21{
0x03B8,
} });
try instance.map.put(0x1D7B2, .{ .compat = &[_]u21{
0x03B9,
} });
try instance.map.put(0x1D7B3, .{ .compat = &[_]u21{
0x03BA,
} });
try instance.map.put(0x1D7B4, .{ .compat = &[_]u21{
0x03BB,
} });
try instance.map.put(0x1D7B5, .{ .compat = &[_]u21{
0x03BC,
} });
try instance.map.put(0x1D7B6, .{ .compat = &[_]u21{
0x03BD,
} });
try instance.map.put(0x1D7B7, .{ .compat = &[_]u21{
0x03BE,
} });
try instance.map.put(0x1D7B8, .{ .compat = &[_]u21{
0x03BF,
} });
try instance.map.put(0x1D7B9, .{ .compat = &[_]u21{
0x03C0,
} });
try instance.map.put(0x1D7BA, .{ .compat = &[_]u21{
0x03C1,
} });
try instance.map.put(0x1D7BB, .{ .compat = &[_]u21{
0x03C2,
} });
try instance.map.put(0x1D7BC, .{ .compat = &[_]u21{
0x03C3,
} });
try instance.map.put(0x1D7BD, .{ .compat = &[_]u21{
0x03C4,
} });
try instance.map.put(0x1D7BE, .{ .compat = &[_]u21{
0x03C5,
} });
try instance.map.put(0x1D7BF, .{ .compat = &[_]u21{
0x03C6,
} });
try instance.map.put(0x1D7C0, .{ .compat = &[_]u21{
0x03C7,
} });
try instance.map.put(0x1D7C1, .{ .compat = &[_]u21{
0x03C8,
} });
try instance.map.put(0x1D7C2, .{ .compat = &[_]u21{
0x03C9,
} });
try instance.map.put(0x1D7C3, .{ .compat = &[_]u21{
0x2202,
} });
try instance.map.put(0x1D7C4, .{ .compat = &[_]u21{
0x03F5,
} });
try instance.map.put(0x1D7C5, .{ .compat = &[_]u21{
0x03D1,
} });
try instance.map.put(0x1D7C6, .{ .compat = &[_]u21{
0x03F0,
} });
try instance.map.put(0x1D7C7, .{ .compat = &[_]u21{
0x03D5,
} });
try instance.map.put(0x1D7C8, .{ .compat = &[_]u21{
0x03F1,
} });
try instance.map.put(0x1D7C9, .{ .compat = &[_]u21{
0x03D6,
} });
try instance.map.put(0x1D7CA, .{ .compat = &[_]u21{
0x03DC,
} });
try instance.map.put(0x1D7CB, .{ .compat = &[_]u21{
0x03DD,
} });
try instance.map.put(0x1D7CE, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0x1D7CF, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0x1D7D0, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0x1D7D1, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0x1D7D2, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0x1D7D3, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0x1D7D4, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0x1D7D5, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0x1D7D6, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0x1D7D7, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0x1D7D8, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0x1D7D9, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0x1D7DA, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0x1D7DB, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0x1D7DC, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0x1D7DD, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0x1D7DE, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0x1D7DF, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0x1D7E0, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0x1D7E1, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0x1D7E2, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0x1D7E3, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0x1D7E4, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0x1D7E5, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0x1D7E6, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0x1D7E7, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0x1D7E8, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0x1D7E9, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0x1D7EA, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0x1D7EB, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0x1D7EC, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0x1D7ED, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0x1D7EE, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0x1D7EF, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0x1D7F0, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0x1D7F1, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0x1D7F2, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0x1D7F3, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0x1D7F4, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0x1D7F5, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0x1D7F6, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0x1D7F7, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0x1D7F8, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0x1D7F9, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0x1D7FA, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0x1D7FB, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0x1D7FC, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0x1D7FD, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0x1D7FE, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0x1D7FF, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0x1EE00, .{ .compat = &[_]u21{
0x0627,
} });
try instance.map.put(0x1EE01, .{ .compat = &[_]u21{
0x0628,
} });
try instance.map.put(0x1EE02, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0x1EE03, .{ .compat = &[_]u21{
0x062F,
} });
try instance.map.put(0x1EE05, .{ .compat = &[_]u21{
0x0648,
} });
try instance.map.put(0x1EE06, .{ .compat = &[_]u21{
0x0632,
} });
try instance.map.put(0x1EE07, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0x1EE08, .{ .compat = &[_]u21{
0x0637,
} });
try instance.map.put(0x1EE09, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0x1EE0A, .{ .compat = &[_]u21{
0x0643,
} });
try instance.map.put(0x1EE0B, .{ .compat = &[_]u21{
0x0644,
} });
try instance.map.put(0x1EE0C, .{ .compat = &[_]u21{
0x0645,
} });
try instance.map.put(0x1EE0D, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0x1EE0E, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0x1EE0F, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0x1EE10, .{ .compat = &[_]u21{
0x0641,
} });
try instance.map.put(0x1EE11, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0x1EE12, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0x1EE13, .{ .compat = &[_]u21{
0x0631,
} });
try instance.map.put(0x1EE14, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0x1EE15, .{ .compat = &[_]u21{
0x062A,
} });
try instance.map.put(0x1EE16, .{ .compat = &[_]u21{
0x062B,
} });
try instance.map.put(0x1EE17, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0x1EE18, .{ .compat = &[_]u21{
0x0630,
} });
try instance.map.put(0x1EE19, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0x1EE1A, .{ .compat = &[_]u21{
0x0638,
} });
try instance.map.put(0x1EE1B, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0x1EE1C, .{ .compat = &[_]u21{
0x066E,
} });
try instance.map.put(0x1EE1D, .{ .compat = &[_]u21{
0x06BA,
} });
try instance.map.put(0x1EE1E, .{ .compat = &[_]u21{
0x06A1,
} });
try instance.map.put(0x1EE1F, .{ .compat = &[_]u21{
0x066F,
} });
try instance.map.put(0x1EE21, .{ .compat = &[_]u21{
0x0628,
} });
try instance.map.put(0x1EE22, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0x1EE24, .{ .compat = &[_]u21{
0x0647,
} });
try instance.map.put(0x1EE27, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0x1EE29, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0x1EE2A, .{ .compat = &[_]u21{
0x0643,
} });
try instance.map.put(0x1EE2B, .{ .compat = &[_]u21{
0x0644,
} });
try instance.map.put(0x1EE2C, .{ .compat = &[_]u21{
0x0645,
} });
try instance.map.put(0x1EE2D, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0x1EE2E, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0x1EE2F, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0x1EE30, .{ .compat = &[_]u21{
0x0641,
} });
try instance.map.put(0x1EE31, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0x1EE32, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0x1EE34, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0x1EE35, .{ .compat = &[_]u21{
0x062A,
} });
try instance.map.put(0x1EE36, .{ .compat = &[_]u21{
0x062B,
} });
try instance.map.put(0x1EE37, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0x1EE39, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0x1EE3B, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0x1EE42, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0x1EE47, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0x1EE49, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0x1EE4B, .{ .compat = &[_]u21{
0x0644,
} });
try instance.map.put(0x1EE4D, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0x1EE4E, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0x1EE4F, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0x1EE51, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0x1EE52, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0x1EE54, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0x1EE57, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0x1EE59, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0x1EE5B, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0x1EE5D, .{ .compat = &[_]u21{
0x06BA,
} });
try instance.map.put(0x1EE5F, .{ .compat = &[_]u21{
0x066F,
} });
try instance.map.put(0x1EE61, .{ .compat = &[_]u21{
0x0628,
} });
try instance.map.put(0x1EE62, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0x1EE64, .{ .compat = &[_]u21{
0x0647,
} });
try instance.map.put(0x1EE67, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0x1EE68, .{ .compat = &[_]u21{
0x0637,
} });
try instance.map.put(0x1EE69, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0x1EE6A, .{ .compat = &[_]u21{
0x0643,
} });
try instance.map.put(0x1EE6C, .{ .compat = &[_]u21{
0x0645,
} });
try instance.map.put(0x1EE6D, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0x1EE6E, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0x1EE6F, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0x1EE70, .{ .compat = &[_]u21{
0x0641,
} });
try instance.map.put(0x1EE71, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0x1EE72, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0x1EE74, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0x1EE75, .{ .compat = &[_]u21{
0x062A,
} });
try instance.map.put(0x1EE76, .{ .compat = &[_]u21{
0x062B,
} });
try instance.map.put(0x1EE77, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0x1EE79, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0x1EE7A, .{ .compat = &[_]u21{
0x0638,
} });
try instance.map.put(0x1EE7B, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0x1EE7C, .{ .compat = &[_]u21{
0x066E,
} });
try instance.map.put(0x1EE7E, .{ .compat = &[_]u21{
0x06A1,
} });
try instance.map.put(0x1EE80, .{ .compat = &[_]u21{
0x0627,
} });
try instance.map.put(0x1EE81, .{ .compat = &[_]u21{
0x0628,
} });
try instance.map.put(0x1EE82, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0x1EE83, .{ .compat = &[_]u21{
0x062F,
} });
try instance.map.put(0x1EE84, .{ .compat = &[_]u21{
0x0647,
} });
try instance.map.put(0x1EE85, .{ .compat = &[_]u21{
0x0648,
} });
try instance.map.put(0x1EE86, .{ .compat = &[_]u21{
0x0632,
} });
try instance.map.put(0x1EE87, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0x1EE88, .{ .compat = &[_]u21{
0x0637,
} });
try instance.map.put(0x1EE89, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0x1EE8B, .{ .compat = &[_]u21{
0x0644,
} });
try instance.map.put(0x1EE8C, .{ .compat = &[_]u21{
0x0645,
} });
try instance.map.put(0x1EE8D, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0x1EE8E, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0x1EE8F, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0x1EE90, .{ .compat = &[_]u21{
0x0641,
} });
try instance.map.put(0x1EE91, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0x1EE92, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0x1EE93, .{ .compat = &[_]u21{
0x0631,
} });
try instance.map.put(0x1EE94, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0x1EE95, .{ .compat = &[_]u21{
0x062A,
} });
try instance.map.put(0x1EE96, .{ .compat = &[_]u21{
0x062B,
} });
try instance.map.put(0x1EE97, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0x1EE98, .{ .compat = &[_]u21{
0x0630,
} });
try instance.map.put(0x1EE99, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0x1EE9A, .{ .compat = &[_]u21{
0x0638,
} });
try instance.map.put(0x1EE9B, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0x1EEA1, .{ .compat = &[_]u21{
0x0628,
} });
try instance.map.put(0x1EEA2, .{ .compat = &[_]u21{
0x062C,
} });
try instance.map.put(0x1EEA3, .{ .compat = &[_]u21{
0x062F,
} });
try instance.map.put(0x1EEA5, .{ .compat = &[_]u21{
0x0648,
} });
try instance.map.put(0x1EEA6, .{ .compat = &[_]u21{
0x0632,
} });
try instance.map.put(0x1EEA7, .{ .compat = &[_]u21{
0x062D,
} });
try instance.map.put(0x1EEA8, .{ .compat = &[_]u21{
0x0637,
} });
try instance.map.put(0x1EEA9, .{ .compat = &[_]u21{
0x064A,
} });
try instance.map.put(0x1EEAB, .{ .compat = &[_]u21{
0x0644,
} });
try instance.map.put(0x1EEAC, .{ .compat = &[_]u21{
0x0645,
} });
try instance.map.put(0x1EEAD, .{ .compat = &[_]u21{
0x0646,
} });
try instance.map.put(0x1EEAE, .{ .compat = &[_]u21{
0x0633,
} });
try instance.map.put(0x1EEAF, .{ .compat = &[_]u21{
0x0639,
} });
try instance.map.put(0x1EEB0, .{ .compat = &[_]u21{
0x0641,
} });
try instance.map.put(0x1EEB1, .{ .compat = &[_]u21{
0x0635,
} });
try instance.map.put(0x1EEB2, .{ .compat = &[_]u21{
0x0642,
} });
try instance.map.put(0x1EEB3, .{ .compat = &[_]u21{
0x0631,
} });
try instance.map.put(0x1EEB4, .{ .compat = &[_]u21{
0x0634,
} });
try instance.map.put(0x1EEB5, .{ .compat = &[_]u21{
0x062A,
} });
try instance.map.put(0x1EEB6, .{ .compat = &[_]u21{
0x062B,
} });
try instance.map.put(0x1EEB7, .{ .compat = &[_]u21{
0x062E,
} });
try instance.map.put(0x1EEB8, .{ .compat = &[_]u21{
0x0630,
} });
try instance.map.put(0x1EEB9, .{ .compat = &[_]u21{
0x0636,
} });
try instance.map.put(0x1EEBA, .{ .compat = &[_]u21{
0x0638,
} });
try instance.map.put(0x1EEBB, .{ .compat = &[_]u21{
0x063A,
} });
try instance.map.put(0x1F100, .{ .compat = &[_]u21{
0x0030,
0x002E,
} });
try instance.map.put(0x1F101, .{ .compat = &[_]u21{
0x0030,
0x002C,
} });
try instance.map.put(0x1F102, .{ .compat = &[_]u21{
0x0031,
0x002C,
} });
try instance.map.put(0x1F103, .{ .compat = &[_]u21{
0x0032,
0x002C,
} });
try instance.map.put(0x1F104, .{ .compat = &[_]u21{
0x0033,
0x002C,
} });
try instance.map.put(0x1F105, .{ .compat = &[_]u21{
0x0034,
0x002C,
} });
try instance.map.put(0x1F106, .{ .compat = &[_]u21{
0x0035,
0x002C,
} });
try instance.map.put(0x1F107, .{ .compat = &[_]u21{
0x0036,
0x002C,
} });
try instance.map.put(0x1F108, .{ .compat = &[_]u21{
0x0037,
0x002C,
} });
try instance.map.put(0x1F109, .{ .compat = &[_]u21{
0x0038,
0x002C,
} });
try instance.map.put(0x1F10A, .{ .compat = &[_]u21{
0x0039,
0x002C,
} });
try instance.map.put(0x1F110, .{ .compat = &[_]u21{
0x0028,
0x0041,
0x0029,
} });
try instance.map.put(0x1F111, .{ .compat = &[_]u21{
0x0028,
0x0042,
0x0029,
} });
try instance.map.put(0x1F112, .{ .compat = &[_]u21{
0x0028,
0x0043,
0x0029,
} });
try instance.map.put(0x1F113, .{ .compat = &[_]u21{
0x0028,
0x0044,
0x0029,
} });
try instance.map.put(0x1F114, .{ .compat = &[_]u21{
0x0028,
0x0045,
0x0029,
} });
try instance.map.put(0x1F115, .{ .compat = &[_]u21{
0x0028,
0x0046,
0x0029,
} });
try instance.map.put(0x1F116, .{ .compat = &[_]u21{
0x0028,
0x0047,
0x0029,
} });
try instance.map.put(0x1F117, .{ .compat = &[_]u21{
0x0028,
0x0048,
0x0029,
} });
try instance.map.put(0x1F118, .{ .compat = &[_]u21{
0x0028,
0x0049,
0x0029,
} });
try instance.map.put(0x1F119, .{ .compat = &[_]u21{
0x0028,
0x004A,
0x0029,
} });
try instance.map.put(0x1F11A, .{ .compat = &[_]u21{
0x0028,
0x004B,
0x0029,
} });
try instance.map.put(0x1F11B, .{ .compat = &[_]u21{
0x0028,
0x004C,
0x0029,
} });
try instance.map.put(0x1F11C, .{ .compat = &[_]u21{
0x0028,
0x004D,
0x0029,
} });
try instance.map.put(0x1F11D, .{ .compat = &[_]u21{
0x0028,
0x004E,
0x0029,
} });
try instance.map.put(0x1F11E, .{ .compat = &[_]u21{
0x0028,
0x004F,
0x0029,
} });
try instance.map.put(0x1F11F, .{ .compat = &[_]u21{
0x0028,
0x0050,
0x0029,
} });
try instance.map.put(0x1F120, .{ .compat = &[_]u21{
0x0028,
0x0051,
0x0029,
} });
try instance.map.put(0x1F121, .{ .compat = &[_]u21{
0x0028,
0x0052,
0x0029,
} });
try instance.map.put(0x1F122, .{ .compat = &[_]u21{
0x0028,
0x0053,
0x0029,
} });
try instance.map.put(0x1F123, .{ .compat = &[_]u21{
0x0028,
0x0054,
0x0029,
} });
try instance.map.put(0x1F124, .{ .compat = &[_]u21{
0x0028,
0x0055,
0x0029,
} });
try instance.map.put(0x1F125, .{ .compat = &[_]u21{
0x0028,
0x0056,
0x0029,
} });
try instance.map.put(0x1F126, .{ .compat = &[_]u21{
0x0028,
0x0057,
0x0029,
} });
try instance.map.put(0x1F127, .{ .compat = &[_]u21{
0x0028,
0x0058,
0x0029,
} });
try instance.map.put(0x1F128, .{ .compat = &[_]u21{
0x0028,
0x0059,
0x0029,
} });
try instance.map.put(0x1F129, .{ .compat = &[_]u21{
0x0028,
0x005A,
0x0029,
} });
try instance.map.put(0x1F12A, .{ .compat = &[_]u21{
0x3014,
0x0053,
0x3015,
} });
try instance.map.put(0x1F12B, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1F12C, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1F12D, .{ .compat = &[_]u21{
0x0043,
0x0044,
} });
try instance.map.put(0x1F12E, .{ .compat = &[_]u21{
0x0057,
0x005A,
} });
try instance.map.put(0x1F130, .{ .compat = &[_]u21{
0x0041,
} });
try instance.map.put(0x1F131, .{ .compat = &[_]u21{
0x0042,
} });
try instance.map.put(0x1F132, .{ .compat = &[_]u21{
0x0043,
} });
try instance.map.put(0x1F133, .{ .compat = &[_]u21{
0x0044,
} });
try instance.map.put(0x1F134, .{ .compat = &[_]u21{
0x0045,
} });
try instance.map.put(0x1F135, .{ .compat = &[_]u21{
0x0046,
} });
try instance.map.put(0x1F136, .{ .compat = &[_]u21{
0x0047,
} });
try instance.map.put(0x1F137, .{ .compat = &[_]u21{
0x0048,
} });
try instance.map.put(0x1F138, .{ .compat = &[_]u21{
0x0049,
} });
try instance.map.put(0x1F139, .{ .compat = &[_]u21{
0x004A,
} });
try instance.map.put(0x1F13A, .{ .compat = &[_]u21{
0x004B,
} });
try instance.map.put(0x1F13B, .{ .compat = &[_]u21{
0x004C,
} });
try instance.map.put(0x1F13C, .{ .compat = &[_]u21{
0x004D,
} });
try instance.map.put(0x1F13D, .{ .compat = &[_]u21{
0x004E,
} });
try instance.map.put(0x1F13E, .{ .compat = &[_]u21{
0x004F,
} });
try instance.map.put(0x1F13F, .{ .compat = &[_]u21{
0x0050,
} });
try instance.map.put(0x1F140, .{ .compat = &[_]u21{
0x0051,
} });
try instance.map.put(0x1F141, .{ .compat = &[_]u21{
0x0052,
} });
try instance.map.put(0x1F142, .{ .compat = &[_]u21{
0x0053,
} });
try instance.map.put(0x1F143, .{ .compat = &[_]u21{
0x0054,
} });
try instance.map.put(0x1F144, .{ .compat = &[_]u21{
0x0055,
} });
try instance.map.put(0x1F145, .{ .compat = &[_]u21{
0x0056,
} });
try instance.map.put(0x1F146, .{ .compat = &[_]u21{
0x0057,
} });
try instance.map.put(0x1F147, .{ .compat = &[_]u21{
0x0058,
} });
try instance.map.put(0x1F148, .{ .compat = &[_]u21{
0x0059,
} });
try instance.map.put(0x1F149, .{ .compat = &[_]u21{
0x005A,
} });
try instance.map.put(0x1F14A, .{ .compat = &[_]u21{
0x0048,
0x0056,
} });
try instance.map.put(0x1F14B, .{ .compat = &[_]u21{
0x004D,
0x0056,
} });
try instance.map.put(0x1F14C, .{ .compat = &[_]u21{
0x0053,
0x0044,
} });
try instance.map.put(0x1F14D, .{ .compat = &[_]u21{
0x0053,
0x0053,
} });
try instance.map.put(0x1F14E, .{ .compat = &[_]u21{
0x0050,
0x0050,
0x0056,
} });
try instance.map.put(0x1F14F, .{ .compat = &[_]u21{
0x0057,
0x0043,
} });
try instance.map.put(0x1F16A, .{ .compat = &[_]u21{
0x004D,
0x0043,
} });
try instance.map.put(0x1F16B, .{ .compat = &[_]u21{
0x004D,
0x0044,
} });
try instance.map.put(0x1F16C, .{ .compat = &[_]u21{
0x004D,
0x0052,
} });
try instance.map.put(0x1F190, .{ .compat = &[_]u21{
0x0044,
0x004A,
} });
try instance.map.put(0x1F200, .{ .compat = &[_]u21{
0x307B,
0x304B,
} });
try instance.map.put(0x1F201, .{ .compat = &[_]u21{
0x30B3,
0x30B3,
} });
try instance.map.put(0x1F202, .{ .compat = &[_]u21{
0x30B5,
} });
try instance.map.put(0x1F210, .{ .compat = &[_]u21{
0x624B,
} });
try instance.map.put(0x1F211, .{ .compat = &[_]u21{
0x5B57,
} });
try instance.map.put(0x1F212, .{ .compat = &[_]u21{
0x53CC,
} });
try instance.map.put(0x1F213, .{ .compat = &[_]u21{
0x30C7,
} });
try instance.map.put(0x1F214, .{ .compat = &[_]u21{
0x4E8C,
} });
try instance.map.put(0x1F215, .{ .compat = &[_]u21{
0x591A,
} });
try instance.map.put(0x1F216, .{ .compat = &[_]u21{
0x89E3,
} });
try instance.map.put(0x1F217, .{ .compat = &[_]u21{
0x5929,
} });
try instance.map.put(0x1F218, .{ .compat = &[_]u21{
0x4EA4,
} });
try instance.map.put(0x1F219, .{ .compat = &[_]u21{
0x6620,
} });
try instance.map.put(0x1F21A, .{ .compat = &[_]u21{
0x7121,
} });
try instance.map.put(0x1F21B, .{ .compat = &[_]u21{
0x6599,
} });
try instance.map.put(0x1F21C, .{ .compat = &[_]u21{
0x524D,
} });
try instance.map.put(0x1F21D, .{ .compat = &[_]u21{
0x5F8C,
} });
try instance.map.put(0x1F21E, .{ .compat = &[_]u21{
0x518D,
} });
try instance.map.put(0x1F21F, .{ .compat = &[_]u21{
0x65B0,
} });
try instance.map.put(0x1F220, .{ .compat = &[_]u21{
0x521D,
} });
try instance.map.put(0x1F221, .{ .compat = &[_]u21{
0x7D42,
} });
try instance.map.put(0x1F222, .{ .compat = &[_]u21{
0x751F,
} });
try instance.map.put(0x1F223, .{ .compat = &[_]u21{
0x8CA9,
} });
try instance.map.put(0x1F224, .{ .compat = &[_]u21{
0x58F0,
} });
try instance.map.put(0x1F225, .{ .compat = &[_]u21{
0x5439,
} });
try instance.map.put(0x1F226, .{ .compat = &[_]u21{
0x6F14,
} });
try instance.map.put(0x1F227, .{ .compat = &[_]u21{
0x6295,
} });
try instance.map.put(0x1F228, .{ .compat = &[_]u21{
0x6355,
} });
try instance.map.put(0x1F229, .{ .compat = &[_]u21{
0x4E00,
} });
try instance.map.put(0x1F22A, .{ .compat = &[_]u21{
0x4E09,
} });
try instance.map.put(0x1F22B, .{ .compat = &[_]u21{
0x904A,
} });
try instance.map.put(0x1F22C, .{ .compat = &[_]u21{
0x5DE6,
} });
try instance.map.put(0x1F22D, .{ .compat = &[_]u21{
0x4E2D,
} });
try instance.map.put(0x1F22E, .{ .compat = &[_]u21{
0x53F3,
} });
try instance.map.put(0x1F22F, .{ .compat = &[_]u21{
0x6307,
} });
try instance.map.put(0x1F230, .{ .compat = &[_]u21{
0x8D70,
} });
try instance.map.put(0x1F231, .{ .compat = &[_]u21{
0x6253,
} });
try instance.map.put(0x1F232, .{ .compat = &[_]u21{
0x7981,
} });
try instance.map.put(0x1F233, .{ .compat = &[_]u21{
0x7A7A,
} });
try instance.map.put(0x1F234, .{ .compat = &[_]u21{
0x5408,
} });
try instance.map.put(0x1F235, .{ .compat = &[_]u21{
0x6E80,
} });
try instance.map.put(0x1F236, .{ .compat = &[_]u21{
0x6709,
} });
try instance.map.put(0x1F237, .{ .compat = &[_]u21{
0x6708,
} });
try instance.map.put(0x1F238, .{ .compat = &[_]u21{
0x7533,
} });
try instance.map.put(0x1F239, .{ .compat = &[_]u21{
0x5272,
} });
try instance.map.put(0x1F23A, .{ .compat = &[_]u21{
0x55B6,
} });
try instance.map.put(0x1F23B, .{ .compat = &[_]u21{
0x914D,
} });
try instance.map.put(0x1F240, .{ .compat = &[_]u21{
0x3014,
0x672C,
0x3015,
} });
try instance.map.put(0x1F241, .{ .compat = &[_]u21{
0x3014,
0x4E09,
0x3015,
} });
try instance.map.put(0x1F242, .{ .compat = &[_]u21{
0x3014,
0x4E8C,
0x3015,
} });
try instance.map.put(0x1F243, .{ .compat = &[_]u21{
0x3014,
0x5B89,
0x3015,
} });
try instance.map.put(0x1F244, .{ .compat = &[_]u21{
0x3014,
0x70B9,
0x3015,
} });
try instance.map.put(0x1F245, .{ .compat = &[_]u21{
0x3014,
0x6253,
0x3015,
} });
try instance.map.put(0x1F246, .{ .compat = &[_]u21{
0x3014,
0x76D7,
0x3015,
} });
try instance.map.put(0x1F247, .{ .compat = &[_]u21{
0x3014,
0x52DD,
0x3015,
} });
try instance.map.put(0x1F248, .{ .compat = &[_]u21{
0x3014,
0x6557,
0x3015,
} });
try instance.map.put(0x1F250, .{ .compat = &[_]u21{
0x5F97,
} });
try instance.map.put(0x1F251, .{ .compat = &[_]u21{
0x53EF,
} });
try instance.map.put(0x1FBF0, .{ .compat = &[_]u21{
0x0030,
} });
try instance.map.put(0x1FBF1, .{ .compat = &[_]u21{
0x0031,
} });
try instance.map.put(0x1FBF2, .{ .compat = &[_]u21{
0x0032,
} });
try instance.map.put(0x1FBF3, .{ .compat = &[_]u21{
0x0033,
} });
try instance.map.put(0x1FBF4, .{ .compat = &[_]u21{
0x0034,
} });
try instance.map.put(0x1FBF5, .{ .compat = &[_]u21{
0x0035,
} });
try instance.map.put(0x1FBF6, .{ .compat = &[_]u21{
0x0036,
} });
try instance.map.put(0x1FBF7, .{ .compat = &[_]u21{
0x0037,
} });
try instance.map.put(0x1FBF8, .{ .compat = &[_]u21{
0x0038,
} });
try instance.map.put(0x1FBF9, .{ .compat = &[_]u21{
0x0039,
} });
try instance.map.put(0x2F800, .{ .single = 0x4E3D });
try instance.map.put(0x2F801, .{ .single = 0x4E38 });
try instance.map.put(0x2F802, .{ .single = 0x4E41 });
try instance.map.put(0x2F803, .{ .single = 0x20122 });
try instance.map.put(0x2F804, .{ .single = 0x4F60 });
try instance.map.put(0x2F805, .{ .single = 0x4FAE });
try instance.map.put(0x2F806, .{ .single = 0x4FBB });
try instance.map.put(0x2F807, .{ .single = 0x5002 });
try instance.map.put(0x2F808, .{ .single = 0x507A });
try instance.map.put(0x2F809, .{ .single = 0x5099 });
try instance.map.put(0x2F80A, .{ .single = 0x50E7 });
try instance.map.put(0x2F80B, .{ .single = 0x50CF });
try instance.map.put(0x2F80C, .{ .single = 0x349E });
try instance.map.put(0x2F80D, .{ .single = 0x2063A });
try instance.map.put(0x2F80E, .{ .single = 0x514D });
try instance.map.put(0x2F80F, .{ .single = 0x5154 });
try instance.map.put(0x2F810, .{ .single = 0x5164 });
try instance.map.put(0x2F811, .{ .single = 0x5177 });
try instance.map.put(0x2F812, .{ .single = 0x2051C });
try instance.map.put(0x2F813, .{ .single = 0x34B9 });
try instance.map.put(0x2F814, .{ .single = 0x5167 });
try instance.map.put(0x2F815, .{ .single = 0x518D });
try instance.map.put(0x2F816, .{ .single = 0x2054B });
try instance.map.put(0x2F817, .{ .single = 0x5197 });
try instance.map.put(0x2F818, .{ .single = 0x51A4 });
try instance.map.put(0x2F819, .{ .single = 0x4ECC });
try instance.map.put(0x2F81A, .{ .single = 0x51AC });
try instance.map.put(0x2F81B, .{ .single = 0x51B5 });
try instance.map.put(0x2F81C, .{ .single = 0x291DF });
try instance.map.put(0x2F81D, .{ .single = 0x51F5 });
try instance.map.put(0x2F81E, .{ .single = 0x5203 });
try instance.map.put(0x2F81F, .{ .single = 0x34DF });
try instance.map.put(0x2F820, .{ .single = 0x523B });
try instance.map.put(0x2F821, .{ .single = 0x5246 });
try instance.map.put(0x2F822, .{ .single = 0x5272 });
try instance.map.put(0x2F823, .{ .single = 0x5277 });
try instance.map.put(0x2F824, .{ .single = 0x3515 });
try instance.map.put(0x2F825, .{ .single = 0x52C7 });
try instance.map.put(0x2F826, .{ .single = 0x52C9 });
try instance.map.put(0x2F827, .{ .single = 0x52E4 });
try instance.map.put(0x2F828, .{ .single = 0x52FA });
try instance.map.put(0x2F829, .{ .single = 0x5305 });
try instance.map.put(0x2F82A, .{ .single = 0x5306 });
try instance.map.put(0x2F82B, .{ .single = 0x5317 });
try instance.map.put(0x2F82C, .{ .single = 0x5349 });
try instance.map.put(0x2F82D, .{ .single = 0x5351 });
try instance.map.put(0x2F82E, .{ .single = 0x535A });
try instance.map.put(0x2F82F, .{ .single = 0x5373 });
try instance.map.put(0x2F830, .{ .single = 0x537D });
try instance.map.put(0x2F831, .{ .single = 0x537F });
try instance.map.put(0x2F832, .{ .single = 0x537F });
try instance.map.put(0x2F833, .{ .single = 0x537F });
try instance.map.put(0x2F834, .{ .single = 0x20A2C });
try instance.map.put(0x2F835, .{ .single = 0x7070 });
try instance.map.put(0x2F836, .{ .single = 0x53CA });
try instance.map.put(0x2F837, .{ .single = 0x53DF });
try instance.map.put(0x2F838, .{ .single = 0x20B63 });
try instance.map.put(0x2F839, .{ .single = 0x53EB });
try instance.map.put(0x2F83A, .{ .single = 0x53F1 });
try instance.map.put(0x2F83B, .{ .single = 0x5406 });
try instance.map.put(0x2F83C, .{ .single = 0x549E });
try instance.map.put(0x2F83D, .{ .single = 0x5438 });
try instance.map.put(0x2F83E, .{ .single = 0x5448 });
try instance.map.put(0x2F83F, .{ .single = 0x5468 });
try instance.map.put(0x2F840, .{ .single = 0x54A2 });
try instance.map.put(0x2F841, .{ .single = 0x54F6 });
try instance.map.put(0x2F842, .{ .single = 0x5510 });
try instance.map.put(0x2F843, .{ .single = 0x5553 });
try instance.map.put(0x2F844, .{ .single = 0x5563 });
try instance.map.put(0x2F845, .{ .single = 0x5584 });
try instance.map.put(0x2F846, .{ .single = 0x5584 });
try instance.map.put(0x2F847, .{ .single = 0x5599 });
try instance.map.put(0x2F848, .{ .single = 0x55AB });
try instance.map.put(0x2F849, .{ .single = 0x55B3 });
try instance.map.put(0x2F84A, .{ .single = 0x55C2 });
try instance.map.put(0x2F84B, .{ .single = 0x5716 });
try instance.map.put(0x2F84C, .{ .single = 0x5606 });
try instance.map.put(0x2F84D, .{ .single = 0x5717 });
try instance.map.put(0x2F84E, .{ .single = 0x5651 });
try instance.map.put(0x2F84F, .{ .single = 0x5674 });
try instance.map.put(0x2F850, .{ .single = 0x5207 });
try instance.map.put(0x2F851, .{ .single = 0x58EE });
try instance.map.put(0x2F852, .{ .single = 0x57CE });
try instance.map.put(0x2F853, .{ .single = 0x57F4 });
try instance.map.put(0x2F854, .{ .single = 0x580D });
try instance.map.put(0x2F855, .{ .single = 0x578B });
try instance.map.put(0x2F856, .{ .single = 0x5832 });
try instance.map.put(0x2F857, .{ .single = 0x5831 });
try instance.map.put(0x2F858, .{ .single = 0x58AC });
try instance.map.put(0x2F859, .{ .single = 0x214E4 });
try instance.map.put(0x2F85A, .{ .single = 0x58F2 });
try instance.map.put(0x2F85B, .{ .single = 0x58F7 });
try instance.map.put(0x2F85C, .{ .single = 0x5906 });
try instance.map.put(0x2F85D, .{ .single = 0x591A });
try instance.map.put(0x2F85E, .{ .single = 0x5922 });
try instance.map.put(0x2F85F, .{ .single = 0x5962 });
try instance.map.put(0x2F860, .{ .single = 0x216A8 });
try instance.map.put(0x2F861, .{ .single = 0x216EA });
try instance.map.put(0x2F862, .{ .single = 0x59EC });
try instance.map.put(0x2F863, .{ .single = 0x5A1B });
try instance.map.put(0x2F864, .{ .single = 0x5A27 });
try instance.map.put(0x2F865, .{ .single = 0x59D8 });
try instance.map.put(0x2F866, .{ .single = 0x5A66 });
try instance.map.put(0x2F867, .{ .single = 0x36EE });
try instance.map.put(0x2F868, .{ .single = 0x36FC });
try instance.map.put(0x2F869, .{ .single = 0x5B08 });
try instance.map.put(0x2F86A, .{ .single = 0x5B3E });
try instance.map.put(0x2F86B, .{ .single = 0x5B3E });
try instance.map.put(0x2F86C, .{ .single = 0x219C8 });
try instance.map.put(0x2F86D, .{ .single = 0x5BC3 });
try instance.map.put(0x2F86E, .{ .single = 0x5BD8 });
try instance.map.put(0x2F86F, .{ .single = 0x5BE7 });
try instance.map.put(0x2F870, .{ .single = 0x5BF3 });
try instance.map.put(0x2F871, .{ .single = 0x21B18 });
try instance.map.put(0x2F872, .{ .single = 0x5BFF });
try instance.map.put(0x2F873, .{ .single = 0x5C06 });
try instance.map.put(0x2F874, .{ .single = 0x5F53 });
try instance.map.put(0x2F875, .{ .single = 0x5C22 });
try instance.map.put(0x2F876, .{ .single = 0x3781 });
try instance.map.put(0x2F877, .{ .single = 0x5C60 });
try instance.map.put(0x2F878, .{ .single = 0x5C6E });
try instance.map.put(0x2F879, .{ .single = 0x5CC0 });
try instance.map.put(0x2F87A, .{ .single = 0x5C8D });
try instance.map.put(0x2F87B, .{ .single = 0x21DE4 });
try instance.map.put(0x2F87C, .{ .single = 0x5D43 });
try instance.map.put(0x2F87D, .{ .single = 0x21DE6 });
try instance.map.put(0x2F87E, .{ .single = 0x5D6E });
try instance.map.put(0x2F87F, .{ .single = 0x5D6B });
try instance.map.put(0x2F880, .{ .single = 0x5D7C });
try instance.map.put(0x2F881, .{ .single = 0x5DE1 });
try instance.map.put(0x2F882, .{ .single = 0x5DE2 });
try instance.map.put(0x2F883, .{ .single = 0x382F });
try instance.map.put(0x2F884, .{ .single = 0x5DFD });
try instance.map.put(0x2F885, .{ .single = 0x5E28 });
try instance.map.put(0x2F886, .{ .single = 0x5E3D });
try instance.map.put(0x2F887, .{ .single = 0x5E69 });
try instance.map.put(0x2F888, .{ .single = 0x3862 });
try instance.map.put(0x2F889, .{ .single = 0x22183 });
try instance.map.put(0x2F88A, .{ .single = 0x387C });
try instance.map.put(0x2F88B, .{ .single = 0x5EB0 });
try instance.map.put(0x2F88C, .{ .single = 0x5EB3 });
try instance.map.put(0x2F88D, .{ .single = 0x5EB6 });
try instance.map.put(0x2F88E, .{ .single = 0x5ECA });
try instance.map.put(0x2F88F, .{ .single = 0x2A392 });
try instance.map.put(0x2F890, .{ .single = 0x5EFE });
try instance.map.put(0x2F891, .{ .single = 0x22331 });
try instance.map.put(0x2F892, .{ .single = 0x22331 });
try instance.map.put(0x2F893, .{ .single = 0x8201 });
try instance.map.put(0x2F894, .{ .single = 0x5F22 });
try instance.map.put(0x2F895, .{ .single = 0x5F22 });
try instance.map.put(0x2F896, .{ .single = 0x38C7 });
try instance.map.put(0x2F897, .{ .single = 0x232B8 });
try instance.map.put(0x2F898, .{ .single = 0x261DA });
try instance.map.put(0x2F899, .{ .single = 0x5F62 });
try instance.map.put(0x2F89A, .{ .single = 0x5F6B });
try instance.map.put(0x2F89B, .{ .single = 0x38E3 });
try instance.map.put(0x2F89C, .{ .single = 0x5F9A });
try instance.map.put(0x2F89D, .{ .single = 0x5FCD });
try instance.map.put(0x2F89E, .{ .single = 0x5FD7 });
try instance.map.put(0x2F89F, .{ .single = 0x5FF9 });
try instance.map.put(0x2F8A0, .{ .single = 0x6081 });
try instance.map.put(0x2F8A1, .{ .single = 0x393A });
try instance.map.put(0x2F8A2, .{ .single = 0x391C });
try instance.map.put(0x2F8A3, .{ .single = 0x6094 });
try instance.map.put(0x2F8A4, .{ .single = 0x226D4 });
try instance.map.put(0x2F8A5, .{ .single = 0x60C7 });
try instance.map.put(0x2F8A6, .{ .single = 0x6148 });
try instance.map.put(0x2F8A7, .{ .single = 0x614C });
try instance.map.put(0x2F8A8, .{ .single = 0x614E });
try instance.map.put(0x2F8A9, .{ .single = 0x614C });
try instance.map.put(0x2F8AA, .{ .single = 0x617A });
try instance.map.put(0x2F8AB, .{ .single = 0x618E });
try instance.map.put(0x2F8AC, .{ .single = 0x61B2 });
try instance.map.put(0x2F8AD, .{ .single = 0x61A4 });
try instance.map.put(0x2F8AE, .{ .single = 0x61AF });
try instance.map.put(0x2F8AF, .{ .single = 0x61DE });
try instance.map.put(0x2F8B0, .{ .single = 0x61F2 });
try instance.map.put(0x2F8B1, .{ .single = 0x61F6 });
try instance.map.put(0x2F8B2, .{ .single = 0x6210 });
try instance.map.put(0x2F8B3, .{ .single = 0x621B });
try instance.map.put(0x2F8B4, .{ .single = 0x625D });
try instance.map.put(0x2F8B5, .{ .single = 0x62B1 });
try instance.map.put(0x2F8B6, .{ .single = 0x62D4 });
try instance.map.put(0x2F8B7, .{ .single = 0x6350 });
try instance.map.put(0x2F8B8, .{ .single = 0x22B0C });
try instance.map.put(0x2F8B9, .{ .single = 0x633D });
try instance.map.put(0x2F8BA, .{ .single = 0x62FC });
try instance.map.put(0x2F8BB, .{ .single = 0x6368 });
try instance.map.put(0x2F8BC, .{ .single = 0x6383 });
try instance.map.put(0x2F8BD, .{ .single = 0x63E4 });
try instance.map.put(0x2F8BE, .{ .single = 0x22BF1 });
try instance.map.put(0x2F8BF, .{ .single = 0x6422 });
try instance.map.put(0x2F8C0, .{ .single = 0x63C5 });
try instance.map.put(0x2F8C1, .{ .single = 0x63A9 });
try instance.map.put(0x2F8C2, .{ .single = 0x3A2E });
try instance.map.put(0x2F8C3, .{ .single = 0x6469 });
try instance.map.put(0x2F8C4, .{ .single = 0x647E });
try instance.map.put(0x2F8C5, .{ .single = 0x649D });
try instance.map.put(0x2F8C6, .{ .single = 0x6477 });
try instance.map.put(0x2F8C7, .{ .single = 0x3A6C });
try instance.map.put(0x2F8C8, .{ .single = 0x654F });
try instance.map.put(0x2F8C9, .{ .single = 0x656C });
try instance.map.put(0x2F8CA, .{ .single = 0x2300A });
try instance.map.put(0x2F8CB, .{ .single = 0x65E3 });
try instance.map.put(0x2F8CC, .{ .single = 0x66F8 });
try instance.map.put(0x2F8CD, .{ .single = 0x6649 });
try instance.map.put(0x2F8CE, .{ .single = 0x3B19 });
try instance.map.put(0x2F8CF, .{ .single = 0x6691 });
try instance.map.put(0x2F8D0, .{ .single = 0x3B08 });
try instance.map.put(0x2F8D1, .{ .single = 0x3AE4 });
try instance.map.put(0x2F8D2, .{ .single = 0x5192 });
try instance.map.put(0x2F8D3, .{ .single = 0x5195 });
try instance.map.put(0x2F8D4, .{ .single = 0x6700 });
try instance.map.put(0x2F8D5, .{ .single = 0x669C });
try instance.map.put(0x2F8D6, .{ .single = 0x80AD });
try instance.map.put(0x2F8D7, .{ .single = 0x43D9 });
try instance.map.put(0x2F8D8, .{ .single = 0x6717 });
try instance.map.put(0x2F8D9, .{ .single = 0x671B });
try instance.map.put(0x2F8DA, .{ .single = 0x6721 });
try instance.map.put(0x2F8DB, .{ .single = 0x675E });
try instance.map.put(0x2F8DC, .{ .single = 0x6753 });
try instance.map.put(0x2F8DD, .{ .single = 0x233C3 });
try instance.map.put(0x2F8DE, .{ .single = 0x3B49 });
try instance.map.put(0x2F8DF, .{ .single = 0x67FA });
try instance.map.put(0x2F8E0, .{ .single = 0x6785 });
try instance.map.put(0x2F8E1, .{ .single = 0x6852 });
try instance.map.put(0x2F8E2, .{ .single = 0x6885 });
try instance.map.put(0x2F8E3, .{ .single = 0x2346D });
try instance.map.put(0x2F8E4, .{ .single = 0x688E });
try instance.map.put(0x2F8E5, .{ .single = 0x681F });
try instance.map.put(0x2F8E6, .{ .single = 0x6914 });
try instance.map.put(0x2F8E7, .{ .single = 0x3B9D });
try instance.map.put(0x2F8E8, .{ .single = 0x6942 });
try instance.map.put(0x2F8E9, .{ .single = 0x69A3 });
try instance.map.put(0x2F8EA, .{ .single = 0x69EA });
try instance.map.put(0x2F8EB, .{ .single = 0x6AA8 });
try instance.map.put(0x2F8EC, .{ .single = 0x236A3 });
try instance.map.put(0x2F8ED, .{ .single = 0x6ADB });
try instance.map.put(0x2F8EE, .{ .single = 0x3C18 });
try instance.map.put(0x2F8EF, .{ .single = 0x6B21 });
try instance.map.put(0x2F8F0, .{ .single = 0x238A7 });
try instance.map.put(0x2F8F1, .{ .single = 0x6B54 });
try instance.map.put(0x2F8F2, .{ .single = 0x3C4E });
try instance.map.put(0x2F8F3, .{ .single = 0x6B72 });
try instance.map.put(0x2F8F4, .{ .single = 0x6B9F });
try instance.map.put(0x2F8F5, .{ .single = 0x6BBA });
try instance.map.put(0x2F8F6, .{ .single = 0x6BBB });
try instance.map.put(0x2F8F7, .{ .single = 0x23A8D });
try instance.map.put(0x2F8F8, .{ .single = 0x21D0B });
try instance.map.put(0x2F8F9, .{ .single = 0x23AFA });
try instance.map.put(0x2F8FA, .{ .single = 0x6C4E });
try instance.map.put(0x2F8FB, .{ .single = 0x23CBC });
try instance.map.put(0x2F8FC, .{ .single = 0x6CBF });
try instance.map.put(0x2F8FD, .{ .single = 0x6CCD });
try instance.map.put(0x2F8FE, .{ .single = 0x6C67 });
try instance.map.put(0x2F8FF, .{ .single = 0x6D16 });
try instance.map.put(0x2F900, .{ .single = 0x6D3E });
try instance.map.put(0x2F901, .{ .single = 0x6D77 });
try instance.map.put(0x2F902, .{ .single = 0x6D41 });
try instance.map.put(0x2F903, .{ .single = 0x6D69 });
try instance.map.put(0x2F904, .{ .single = 0x6D78 });
try instance.map.put(0x2F905, .{ .single = 0x6D85 });
try instance.map.put(0x2F906, .{ .single = 0x23D1E });
try instance.map.put(0x2F907, .{ .single = 0x6D34 });
try instance.map.put(0x2F908, .{ .single = 0x6E2F });
try instance.map.put(0x2F909, .{ .single = 0x6E6E });
try instance.map.put(0x2F90A, .{ .single = 0x3D33 });
try instance.map.put(0x2F90B, .{ .single = 0x6ECB });
try instance.map.put(0x2F90C, .{ .single = 0x6EC7 });
try instance.map.put(0x2F90D, .{ .single = 0x23ED1 });
try instance.map.put(0x2F90E, .{ .single = 0x6DF9 });
try instance.map.put(0x2F90F, .{ .single = 0x6F6E });
try instance.map.put(0x2F910, .{ .single = 0x23F5E });
try instance.map.put(0x2F911, .{ .single = 0x23F8E });
try instance.map.put(0x2F912, .{ .single = 0x6FC6 });
try instance.map.put(0x2F913, .{ .single = 0x7039 });
try instance.map.put(0x2F914, .{ .single = 0x701E });
try instance.map.put(0x2F915, .{ .single = 0x701B });
try instance.map.put(0x2F916, .{ .single = 0x3D96 });
try instance.map.put(0x2F917, .{ .single = 0x704A });
try instance.map.put(0x2F918, .{ .single = 0x707D });
try instance.map.put(0x2F919, .{ .single = 0x7077 });
try instance.map.put(0x2F91A, .{ .single = 0x70AD });
try instance.map.put(0x2F91B, .{ .single = 0x20525 });
try instance.map.put(0x2F91C, .{ .single = 0x7145 });
try instance.map.put(0x2F91D, .{ .single = 0x24263 });
try instance.map.put(0x2F91E, .{ .single = 0x719C });
try instance.map.put(0x2F91F, .{ .single = 0x243AB });
try instance.map.put(0x2F920, .{ .single = 0x7228 });
try instance.map.put(0x2F921, .{ .single = 0x7235 });
try instance.map.put(0x2F922, .{ .single = 0x7250 });
try instance.map.put(0x2F923, .{ .single = 0x24608 });
try instance.map.put(0x2F924, .{ .single = 0x7280 });
try instance.map.put(0x2F925, .{ .single = 0x7295 });
try instance.map.put(0x2F926, .{ .single = 0x24735 });
try instance.map.put(0x2F927, .{ .single = 0x24814 });
try instance.map.put(0x2F928, .{ .single = 0x737A });
try instance.map.put(0x2F929, .{ .single = 0x738B });
try instance.map.put(0x2F92A, .{ .single = 0x3EAC });
try instance.map.put(0x2F92B, .{ .single = 0x73A5 });
try instance.map.put(0x2F92C, .{ .single = 0x3EB8 });
try instance.map.put(0x2F92D, .{ .single = 0x3EB8 });
try instance.map.put(0x2F92E, .{ .single = 0x7447 });
try instance.map.put(0x2F92F, .{ .single = 0x745C });
try instance.map.put(0x2F930, .{ .single = 0x7471 });
try instance.map.put(0x2F931, .{ .single = 0x7485 });
try instance.map.put(0x2F932, .{ .single = 0x74CA });
try instance.map.put(0x2F933, .{ .single = 0x3F1B });
try instance.map.put(0x2F934, .{ .single = 0x7524 });
try instance.map.put(0x2F935, .{ .single = 0x24C36 });
try instance.map.put(0x2F936, .{ .single = 0x753E });
try instance.map.put(0x2F937, .{ .single = 0x24C92 });
try instance.map.put(0x2F938, .{ .single = 0x7570 });
try instance.map.put(0x2F939, .{ .single = 0x2219F });
try instance.map.put(0x2F93A, .{ .single = 0x7610 });
try instance.map.put(0x2F93B, .{ .single = 0x24FA1 });
try instance.map.put(0x2F93C, .{ .single = 0x24FB8 });
try instance.map.put(0x2F93D, .{ .single = 0x25044 });
try instance.map.put(0x2F93E, .{ .single = 0x3FFC });
try instance.map.put(0x2F93F, .{ .single = 0x4008 });
try instance.map.put(0x2F940, .{ .single = 0x76F4 });
try instance.map.put(0x2F941, .{ .single = 0x250F3 });
try instance.map.put(0x2F942, .{ .single = 0x250F2 });
try instance.map.put(0x2F943, .{ .single = 0x25119 });
try instance.map.put(0x2F944, .{ .single = 0x25133 });
try instance.map.put(0x2F945, .{ .single = 0x771E });
try instance.map.put(0x2F946, .{ .single = 0x771F });
try instance.map.put(0x2F947, .{ .single = 0x771F });
try instance.map.put(0x2F948, .{ .single = 0x774A });
try instance.map.put(0x2F949, .{ .single = 0x4039 });
try instance.map.put(0x2F94A, .{ .single = 0x778B });
try instance.map.put(0x2F94B, .{ .single = 0x4046 });
try instance.map.put(0x2F94C, .{ .single = 0x4096 });
try instance.map.put(0x2F94D, .{ .single = 0x2541D });
try instance.map.put(0x2F94E, .{ .single = 0x784E });
try instance.map.put(0x2F94F, .{ .single = 0x788C });
try instance.map.put(0x2F950, .{ .single = 0x78CC });
try instance.map.put(0x2F951, .{ .single = 0x40E3 });
try instance.map.put(0x2F952, .{ .single = 0x25626 });
try instance.map.put(0x2F953, .{ .single = 0x7956 });
try instance.map.put(0x2F954, .{ .single = 0x2569A });
try instance.map.put(0x2F955, .{ .single = 0x256C5 });
try instance.map.put(0x2F956, .{ .single = 0x798F });
try instance.map.put(0x2F957, .{ .single = 0x79EB });
try instance.map.put(0x2F958, .{ .single = 0x412F });
try instance.map.put(0x2F959, .{ .single = 0x7A40 });
try instance.map.put(0x2F95A, .{ .single = 0x7A4A });
try instance.map.put(0x2F95B, .{ .single = 0x7A4F });
try instance.map.put(0x2F95C, .{ .single = 0x2597C });
try instance.map.put(0x2F95D, .{ .single = 0x25AA7 });
try instance.map.put(0x2F95E, .{ .single = 0x25AA7 });
try instance.map.put(0x2F95F, .{ .single = 0x7AEE });
try instance.map.put(0x2F960, .{ .single = 0x4202 });
try instance.map.put(0x2F961, .{ .single = 0x25BAB });
try instance.map.put(0x2F962, .{ .single = 0x7BC6 });
try instance.map.put(0x2F963, .{ .single = 0x7BC9 });
try instance.map.put(0x2F964, .{ .single = 0x4227 });
try instance.map.put(0x2F965, .{ .single = 0x25C80 });
try instance.map.put(0x2F966, .{ .single = 0x7CD2 });
try instance.map.put(0x2F967, .{ .single = 0x42A0 });
try instance.map.put(0x2F968, .{ .single = 0x7CE8 });
try instance.map.put(0x2F969, .{ .single = 0x7CE3 });
try instance.map.put(0x2F96A, .{ .single = 0x7D00 });
try instance.map.put(0x2F96B, .{ .single = 0x25F86 });
try instance.map.put(0x2F96C, .{ .single = 0x7D63 });
try instance.map.put(0x2F96D, .{ .single = 0x4301 });
try instance.map.put(0x2F96E, .{ .single = 0x7DC7 });
try instance.map.put(0x2F96F, .{ .single = 0x7E02 });
try instance.map.put(0x2F970, .{ .single = 0x7E45 });
try instance.map.put(0x2F971, .{ .single = 0x4334 });
try instance.map.put(0x2F972, .{ .single = 0x26228 });
try instance.map.put(0x2F973, .{ .single = 0x26247 });
try instance.map.put(0x2F974, .{ .single = 0x4359 });
try instance.map.put(0x2F975, .{ .single = 0x262D9 });
try instance.map.put(0x2F976, .{ .single = 0x7F7A });
try instance.map.put(0x2F977, .{ .single = 0x2633E });
try instance.map.put(0x2F978, .{ .single = 0x7F95 });
try instance.map.put(0x2F979, .{ .single = 0x7FFA });
try instance.map.put(0x2F97A, .{ .single = 0x8005 });
try instance.map.put(0x2F97B, .{ .single = 0x264DA });
try instance.map.put(0x2F97C, .{ .single = 0x26523 });
try instance.map.put(0x2F97D, .{ .single = 0x8060 });
try instance.map.put(0x2F97E, .{ .single = 0x265A8 });
try instance.map.put(0x2F97F, .{ .single = 0x8070 });
try instance.map.put(0x2F980, .{ .single = 0x2335F });
try instance.map.put(0x2F981, .{ .single = 0x43D5 });
try instance.map.put(0x2F982, .{ .single = 0x80B2 });
try instance.map.put(0x2F983, .{ .single = 0x8103 });
try instance.map.put(0x2F984, .{ .single = 0x440B });
try instance.map.put(0x2F985, .{ .single = 0x813E });
try instance.map.put(0x2F986, .{ .single = 0x5AB5 });
try instance.map.put(0x2F987, .{ .single = 0x267A7 });
try instance.map.put(0x2F988, .{ .single = 0x267B5 });
try instance.map.put(0x2F989, .{ .single = 0x23393 });
try instance.map.put(0x2F98A, .{ .single = 0x2339C });
try instance.map.put(0x2F98B, .{ .single = 0x8201 });
try instance.map.put(0x2F98C, .{ .single = 0x8204 });
try instance.map.put(0x2F98D, .{ .single = 0x8F9E });
try instance.map.put(0x2F98E, .{ .single = 0x446B });
try instance.map.put(0x2F98F, .{ .single = 0x8291 });
try instance.map.put(0x2F990, .{ .single = 0x828B });
try instance.map.put(0x2F991, .{ .single = 0x829D });
try instance.map.put(0x2F992, .{ .single = 0x52B3 });
try instance.map.put(0x2F993, .{ .single = 0x82B1 });
try instance.map.put(0x2F994, .{ .single = 0x82B3 });
try instance.map.put(0x2F995, .{ .single = 0x82BD });
try instance.map.put(0x2F996, .{ .single = 0x82E6 });
try instance.map.put(0x2F997, .{ .single = 0x26B3C });
try instance.map.put(0x2F998, .{ .single = 0x82E5 });
try instance.map.put(0x2F999, .{ .single = 0x831D });
try instance.map.put(0x2F99A, .{ .single = 0x8363 });
try instance.map.put(0x2F99B, .{ .single = 0x83AD });
try instance.map.put(0x2F99C, .{ .single = 0x8323 });
try instance.map.put(0x2F99D, .{ .single = 0x83BD });
try instance.map.put(0x2F99E, .{ .single = 0x83E7 });
try instance.map.put(0x2F99F, .{ .single = 0x8457 });
try instance.map.put(0x2F9A0, .{ .single = 0x8353 });
try instance.map.put(0x2F9A1, .{ .single = 0x83CA });
try instance.map.put(0x2F9A2, .{ .single = 0x83CC });
try instance.map.put(0x2F9A3, .{ .single = 0x83DC });
try instance.map.put(0x2F9A4, .{ .single = 0x26C36 });
try instance.map.put(0x2F9A5, .{ .single = 0x26D6B });
try instance.map.put(0x2F9A6, .{ .single = 0x26CD5 });
try instance.map.put(0x2F9A7, .{ .single = 0x452B });
try instance.map.put(0x2F9A8, .{ .single = 0x84F1 });
try instance.map.put(0x2F9A9, .{ .single = 0x84F3 });
try instance.map.put(0x2F9AA, .{ .single = 0x8516 });
try instance.map.put(0x2F9AB, .{ .single = 0x273CA });
try instance.map.put(0x2F9AC, .{ .single = 0x8564 });
try instance.map.put(0x2F9AD, .{ .single = 0x26F2C });
try instance.map.put(0x2F9AE, .{ .single = 0x455D });
try instance.map.put(0x2F9AF, .{ .single = 0x4561 });
try instance.map.put(0x2F9B0, .{ .single = 0x26FB1 });
try instance.map.put(0x2F9B1, .{ .single = 0x270D2 });
try instance.map.put(0x2F9B2, .{ .single = 0x456B });
try instance.map.put(0x2F9B3, .{ .single = 0x8650 });
try instance.map.put(0x2F9B4, .{ .single = 0x865C });
try instance.map.put(0x2F9B5, .{ .single = 0x8667 });
try instance.map.put(0x2F9B6, .{ .single = 0x8669 });
try instance.map.put(0x2F9B7, .{ .single = 0x86A9 });
try instance.map.put(0x2F9B8, .{ .single = 0x8688 });
try instance.map.put(0x2F9B9, .{ .single = 0x870E });
try instance.map.put(0x2F9BA, .{ .single = 0x86E2 });
try instance.map.put(0x2F9BB, .{ .single = 0x8779 });
try instance.map.put(0x2F9BC, .{ .single = 0x8728 });
try instance.map.put(0x2F9BD, .{ .single = 0x876B });
try instance.map.put(0x2F9BE, .{ .single = 0x8786 });
try instance.map.put(0x2F9BF, .{ .single = 0x45D7 });
try instance.map.put(0x2F9C0, .{ .single = 0x87E1 });
try instance.map.put(0x2F9C1, .{ .single = 0x8801 });
try instance.map.put(0x2F9C2, .{ .single = 0x45F9 });
try instance.map.put(0x2F9C3, .{ .single = 0x8860 });
try instance.map.put(0x2F9C4, .{ .single = 0x8863 });
try instance.map.put(0x2F9C5, .{ .single = 0x27667 });
try instance.map.put(0x2F9C6, .{ .single = 0x88D7 });
try instance.map.put(0x2F9C7, .{ .single = 0x88DE });
try instance.map.put(0x2F9C8, .{ .single = 0x4635 });
try instance.map.put(0x2F9C9, .{ .single = 0x88FA });
try instance.map.put(0x2F9CA, .{ .single = 0x34BB });
try instance.map.put(0x2F9CB, .{ .single = 0x278AE });
try instance.map.put(0x2F9CC, .{ .single = 0x27966 });
try instance.map.put(0x2F9CD, .{ .single = 0x46BE });
try instance.map.put(0x2F9CE, .{ .single = 0x46C7 });
try instance.map.put(0x2F9CF, .{ .single = 0x8AA0 });
try instance.map.put(0x2F9D0, .{ .single = 0x8AED });
try instance.map.put(0x2F9D1, .{ .single = 0x8B8A });
try instance.map.put(0x2F9D2, .{ .single = 0x8C55 });
try instance.map.put(0x2F9D3, .{ .single = 0x27CA8 });
try instance.map.put(0x2F9D4, .{ .single = 0x8CAB });
try instance.map.put(0x2F9D5, .{ .single = 0x8CC1 });
try instance.map.put(0x2F9D6, .{ .single = 0x8D1B });
try instance.map.put(0x2F9D7, .{ .single = 0x8D77 });
try instance.map.put(0x2F9D8, .{ .single = 0x27F2F });
try instance.map.put(0x2F9D9, .{ .single = 0x20804 });
try instance.map.put(0x2F9DA, .{ .single = 0x8DCB });
try instance.map.put(0x2F9DB, .{ .single = 0x8DBC });
try instance.map.put(0x2F9DC, .{ .single = 0x8DF0 });
try instance.map.put(0x2F9DD, .{ .single = 0x208DE });
try instance.map.put(0x2F9DE, .{ .single = 0x8ED4 });
try instance.map.put(0x2F9DF, .{ .single = 0x8F38 });
try instance.map.put(0x2F9E0, .{ .single = 0x285D2 });
try instance.map.put(0x2F9E1, .{ .single = 0x285ED });
try instance.map.put(0x2F9E2, .{ .single = 0x9094 });
try instance.map.put(0x2F9E3, .{ .single = 0x90F1 });
try instance.map.put(0x2F9E4, .{ .single = 0x9111 });
try instance.map.put(0x2F9E5, .{ .single = 0x2872E });
try instance.map.put(0x2F9E6, .{ .single = 0x911B });
try instance.map.put(0x2F9E7, .{ .single = 0x9238 });
try instance.map.put(0x2F9E8, .{ .single = 0x92D7 });
try instance.map.put(0x2F9E9, .{ .single = 0x92D8 });
try instance.map.put(0x2F9EA, .{ .single = 0x927C });
try instance.map.put(0x2F9EB, .{ .single = 0x93F9 });
try instance.map.put(0x2F9EC, .{ .single = 0x9415 });
try instance.map.put(0x2F9ED, .{ .single = 0x28BFA });
try instance.map.put(0x2F9EE, .{ .single = 0x958B });
try instance.map.put(0x2F9EF, .{ .single = 0x4995 });
try instance.map.put(0x2F9F0, .{ .single = 0x95B7 });
try instance.map.put(0x2F9F1, .{ .single = 0x28D77 });
try instance.map.put(0x2F9F2, .{ .single = 0x49E6 });
try instance.map.put(0x2F9F3, .{ .single = 0x96C3 });
try instance.map.put(0x2F9F4, .{ .single = 0x5DB2 });
try instance.map.put(0x2F9F5, .{ .single = 0x9723 });
try instance.map.put(0x2F9F6, .{ .single = 0x29145 });
try instance.map.put(0x2F9F7, .{ .single = 0x2921A });
try instance.map.put(0x2F9F8, .{ .single = 0x4A6E });
try instance.map.put(0x2F9F9, .{ .single = 0x4A76 });
try instance.map.put(0x2F9FA, .{ .single = 0x97E0 });
try instance.map.put(0x2F9FB, .{ .single = 0x2940A });
try instance.map.put(0x2F9FC, .{ .single = 0x4AB2 });
try instance.map.put(0x2F9FD, .{ .single = 0x29496 });
try instance.map.put(0x2F9FE, .{ .single = 0x980B });
try instance.map.put(0x2F9FF, .{ .single = 0x980B });
try instance.map.put(0x2FA00, .{ .single = 0x9829 });
try instance.map.put(0x2FA01, .{ .single = 0x295B6 });
try instance.map.put(0x2FA02, .{ .single = 0x98E2 });
try instance.map.put(0x2FA03, .{ .single = 0x4B33 });
try instance.map.put(0x2FA04, .{ .single = 0x9929 });
try instance.map.put(0x2FA05, .{ .single = 0x99A7 });
try instance.map.put(0x2FA06, .{ .single = 0x99C2 });
try instance.map.put(0x2FA07, .{ .single = 0x99FE });
try instance.map.put(0x2FA08, .{ .single = 0x4BCE });
try instance.map.put(0x2FA09, .{ .single = 0x29B30 });
try instance.map.put(0x2FA0A, .{ .single = 0x9B12 });
try instance.map.put(0x2FA0B, .{ .single = 0x9C40 });
try instance.map.put(0x2FA0C, .{ .single = 0x9CFD });
try instance.map.put(0x2FA0D, .{ .single = 0x4CCE });
try instance.map.put(0x2FA0E, .{ .single = 0x4CED });
try instance.map.put(0x2FA0F, .{ .single = 0x9D67 });
try instance.map.put(0x2FA10, .{ .single = 0x2A0CE });
try instance.map.put(0x2FA11, .{ .single = 0x4CF8 });
try instance.map.put(0x2FA12, .{ .single = 0x2A105 });
try instance.map.put(0x2FA13, .{ .single = 0x2A20E });
try instance.map.put(0x2FA14, .{ .single = 0x2A291 });
try instance.map.put(0x2FA15, .{ .single = 0x9EBB });
try instance.map.put(0x2FA16, .{ .single = 0x4D56 });
try instance.map.put(0x2FA17, .{ .single = 0x9EF9 });
try instance.map.put(0x2FA18, .{ .single = 0x9EFE });
try instance.map.put(0x2FA19, .{ .single = 0x9F05 });
try instance.map.put(0x2FA1A, .{ .single = 0x9F0F });
try instance.map.put(0x2FA1B, .{ .single = 0x9F16 });
try instance.map.put(0x2FA1C, .{ .single = 0x9F3B });
try instance.map.put(0x2FA1D, .{ .single = 0x2A600 });
return instance;
}
pub fn deinit(self: *Self) void {
self.ccc_map.deinit();
self.han_map.deinit();
self.map.deinit();
}
/// mapping retrieves the decomposition mapping for a code point as per the UCD.
pub fn mapping(self: Self, cp: u21) Decomposed {
return if (self.map.get(cp)) |dc| dc else .{ .same = cp };
}
/// codePointTo takes a code point and returns a sequence of code points that represent its conversion
/// to the specified Form. Caller must free returned bytes.
pub fn codePointTo(self: Self, allocator: *mem.Allocator, form: Form, cp: u21) anyerror![]u21 {
if (form == .D or form == .KD) {
// Decomposition.
if (self.isHangulPrecomposed(cp)) {
// Hangul precomposed syllable full decomposition.
const dcs = self.decomposeHangul(cp);
const len: usize = if (dcs[2] == 0) 2 else 3;
var result = try allocator.alloc(u21, len);
mem.copy(u21, result, dcs[0..len]);
return result;
} else {
// Non-Hangul code points.
const src = [1]Decomposed{.{ .src = cp }};
const dcs = try self.decomposeTo(allocator, form, &src);
defer allocator.free(dcs);
var result = try allocator.alloc(u21, dcs.len);
for (dcs) |dc, index| {
result[index] = dc.same;
}
return result;
}
} else {
return error.FormUnimplemented;
}
}
/// decomposeTo recursively performs decomposition until the specified form is obtained.
/// Caller must free returned bytes.
pub fn decomposeTo(self: Self, allocator: *mem.Allocator, form: Form, dcs: []const Decomposed) anyerror![]const Decomposed {
// Avoid recursive allocation hell with arena.
var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit();
// Freed by arena.
const rdcs = switch (form) {
.D => try self.decompD(&arena.allocator, dcs),
.KD => try self.decompKD(&arena.allocator, dcs),
};
// Freed by caller.
var result = try allocator.alloc(Decomposed, rdcs.len);
for (rdcs) |dc, i| {
result[i] = dc;
}
return result;
}
fn decompD(self: Self, allocator: *mem.Allocator, dcs: []const Decomposed) anyerror![]const Decomposed {
// Base case;
if (allDone(dcs)) return dcs;
var rdcs = std.ArrayList(Decomposed).init(allocator);
defer rdcs.deinit();
for (dcs) |dc| {
switch (dc) {
.src => |cp| {
const next_map = self.mapping(cp);
if (next_map == .same) {
try rdcs.append(next_map);
return rdcs.toOwnedSlice();
} else if (next_map == .compat) {
try rdcs.append(.{ .same = cp });
return rdcs.toOwnedSlice();
} else {
const m = [1]Decomposed{self.mapping(cp)};
try rdcs.appendSlice(try self.decomposeTo(allocator, .D, &m));
}
},
.same => try rdcs.append(dc),
.single => |cp| {
const next_map = self.mapping(cp);
if (next_map == .same or next_map == .compat) {
try rdcs.append(.{ .same = cp });
} else {
const m = [1]Decomposed{self.mapping(cp)};
try rdcs.appendSlice(try self.decomposeTo(allocator, .D, &m));
}
},
.canon => |seq| {
for (seq) |cp| {
const next_map = self.mapping(cp);
if (next_map == .same or next_map == .compat) {
try rdcs.append(.{ .same = cp });
} else {
const m = [1]Decomposed{next_map};
try rdcs.appendSlice(try self.decomposeTo(allocator, .D, &m));
}
}
},
.compat => {},
}
}
return rdcs.toOwnedSlice();
}
fn decompKD(self: Self, allocator: *mem.Allocator, dcs: []const Decomposed) anyerror![]const Decomposed {
// Base case;
if (allDone(dcs)) return dcs;
var rdcs = std.ArrayList(Decomposed).init(allocator);
defer rdcs.deinit();
for (dcs) |dc| {
switch (dc) {
.src => |cp| {
const m = [1]Decomposed{self.mapping(cp)};
try rdcs.appendSlice(try self.decomposeTo(allocator, .KD, &m));
},
.same => try rdcs.append(dc),
.single => |cp| {
const m = [1]Decomposed{self.mapping(cp)};
try rdcs.appendSlice(try self.decomposeTo(allocator, .KD, &m));
},
.canon => |seq| {
for (seq) |cp| {
const m = [1]Decomposed{self.mapping(cp)};
try rdcs.appendSlice(try self.decomposeTo(allocator, .KD, &m));
}
},
.compat => |seq| {
for (seq) |cp| {
const m = [1]Decomposed{self.mapping(cp)};
try rdcs.appendSlice(try self.decomposeTo(allocator, .KD, &m));
}
},
}
}
return rdcs.toOwnedSlice();
}
/// normalizeTo will normalize the code points in str, producing a slice of u8 with the new bytes
/// corresponding to the specified Normalization Form. Caller must free returned bytes.
pub fn normalizeTo(self: *Self, allocator: *mem.Allocator, form: Form, str: []const u8) anyerror![]u8 {
if (form != .D and form != .KD) return error.FormUnimplemented;
var result = std.ArrayList(u8).init(allocator);
defer result.deinit();
var code_points = std.ArrayList(u21).init(self.allocator);
defer code_points.deinit();
// Gather decomposed code points.
var iter = (try unicode.Utf8View.init(str)).iterator();
while (iter.nextCodepoint()) |cp| {
const cp_slice = try self.codePointTo(allocator, form, cp);
defer allocator.free(cp_slice);
try code_points.appendSlice(cp_slice);
}
// Apply canonical sort algorithm.
self.canonicalSort(code_points.items);
// Encode as UTF-8 code units.
var buf: [4]u8 = undefined;
for (code_points.items) |dcp| {
const len = try unicode.utf8Encode(dcp, &buf);
try result.appendSlice(buf[0..len]);
}
// NFKD result.
return result.toOwnedSlice();
}
fn cccLess(self: Self, lhs: u21, rhs: u21) bool {
return self.ccc_map.combiningClass(lhs) < self.ccc_map.combiningClass(rhs);
}
fn canonicalSort(self: Self, cp_list: []u21) void {
var i: usize = 0;
while (true) {
if (i >= cp_list.len) break;
var start: usize = i;
while (i < cp_list.len and self.ccc_map.combiningClass(cp_list[i]) != 0) : (i += 1) {}
sort(u21, cp_list[start..i], self, cccLess);
i += 1;
}
}
fn decomposeHangul(self: Self, cp: u21) [3]u21 {
const SBase: u21 = 0xAC00;
const LBase: u21 = 0x1100;
const VBase: u21 = 0x1161;
const TBase: u21 = 0x11A7;
const LCount: u21 = 19;
const VCount: u21 = 21;
const TCount: u21 = 28;
const NCount: u21 = 588; // VCount * TCount
const SCount: u21 = 11172; // LCount * NCount
const SIndex: u21 = cp - SBase;
const LIndex: u21 = SIndex / NCount;
const VIndex: u21 = (SIndex % NCount) / TCount;
const TIndex: u21 = SIndex % TCount;
const LPart: u21 = LBase + LIndex;
const VPart: u21 = VBase + VIndex;
var TPart: u21 = 0;
if (TIndex != 0) TPart = TBase + TIndex;
return [3]u21{ LPart, VPart, TPart };
}
fn isHangulPrecomposed(self: Self, cp: u21) bool {
if (self.han_map.syllableType(cp)) |kind| {
return switch (kind) {
.LV, .LVT => true,
else => false,
};
} else {
return false;
}
}
fn allDone(dcs: []const Decomposed) bool {
for (dcs) |dc| {
if (dc != .same) return false;
}
return true;
}
test "codePointTo D" {
var allocator = std.testing.allocator;
var decomp_map = try init(allocator);
defer decomp_map.deinit();
var result = try decomp_map.codePointTo(allocator, .D, '\u{00E9}');
defer allocator.free(result);
std.testing.expectEqualSlices(u21, result, &[2]u21{ 0x0065, 0x0301 });
allocator.free(result);
result = try decomp_map.codePointTo(allocator, .D, '\u{03D3}');
std.testing.expectEqualSlices(u21, result, &[2]u21{ 0x03D2, 0x0301 });
}
test "codePointTo KD" {
var allocator = std.testing.allocator;
var decomp_map = try init(allocator);
defer decomp_map.deinit();
var result = try decomp_map.codePointTo(allocator, .KD, '\u{00E9}');
defer allocator.free(result);
std.testing.expectEqualSlices(u21, result, &[2]u21{ 0x0065, 0x0301 });
allocator.free(result);
result = try decomp_map.codePointTo(allocator, .KD, '\u{03D3}');
std.testing.expectEqualSlices(u21, result, &[2]u21{ 0x03A5, 0x0301 });
}
test "normalizeTo" {
var allocator = std.testing.allocator;
var decomp_map = try init(allocator);
defer decomp_map.deinit();
var file = try std.fs.cwd().openFile("src/data/ucd/NormalizationTest.txt", .{});
defer file.close();
var buf_reader = std.io.bufferedReader(file.reader());
var input_stream = buf_reader.reader();
var buf: [640]u8 = undefined;
while (try input_stream.readUntilDelimiterOrEof(&buf, '\n')) |line| {
// Skip comments or empty lines.
if (line.len == 0 or line[0] == '#' or line[0] == '@') continue;
// Iterate over fields.
var fields = mem.split(line, ";");
var field_index: usize = 0;
var input: []u8 = undefined;
defer allocator.free(input);
while (fields.next()) |field| : (field_index += 1) {
if (field_index == 0) {
var i_buf = std.ArrayList(u8).init(allocator);
defer i_buf.deinit();
var i_fields = mem.split(field, " ");
var cp_buf: [4]u8 = undefined;
while (i_fields.next()) |s| {
const icp = try std.fmt.parseInt(u21, s, 16);
const len = try unicode.utf8Encode(icp, &cp_buf);
try i_buf.appendSlice(cp_buf[0..len]);
}
input = i_buf.toOwnedSlice();
} else if (field_index == 2) {
// NFD, time to test.
var w_buf = std.ArrayList(u8).init(allocator);
defer w_buf.deinit();
var w_fields = mem.split(field, " ");
var cp_buf: [4]u8 = undefined;
while (w_fields.next()) |s| {
const wcp = try std.fmt.parseInt(u21, s, 16);
const len = try unicode.utf8Encode(wcp, &cp_buf);
try w_buf.appendSlice(cp_buf[0..len]);
}
const want = w_buf.toOwnedSlice();
defer allocator.free(want);
const got = try decomp_map.normalizeTo(allocator, .D, input);
defer allocator.free(got);
std.testing.expectEqualSlices(u8, want, got);
continue;
} else if (field_index == 4) {
// NFKD, time to test.
var w_buf = std.ArrayList(u8).init(allocator);
defer w_buf.deinit();
var w_fields = mem.split(field, " ");
var cp_buf: [4]u8 = undefined;
while (w_fields.next()) |s| {
const wcp = try std.fmt.parseInt(u21, s, 16);
const len = try unicode.utf8Encode(wcp, &cp_buf);
try w_buf.appendSlice(cp_buf[0..len]);
}
const want = w_buf.toOwnedSlice();
defer allocator.free(want);
const got = try decomp_map.normalizeTo(allocator, .KD, input);
defer allocator.free(got);
std.testing.expectEqualSlices(u8, want, got);
continue;
} else {
continue;
}
}
}
} | src/components/autogen/UnicodeData/DecomposeMap.zig |
pub fn toLower(cp: u21) u21 {
return switch (cp) {
0x41 => 0x61,
0x42 => 0x62,
0x43 => 0x63,
0x44 => 0x64,
0x45 => 0x65,
0x46 => 0x66,
0x47 => 0x67,
0x48 => 0x68,
0x49 => 0x69,
0x4A => 0x6A,
0x4B => 0x6B,
0x4C => 0x6C,
0x4D => 0x6D,
0x4E => 0x6E,
0x4F => 0x6F,
0x50 => 0x70,
0x51 => 0x71,
0x52 => 0x72,
0x53 => 0x73,
0x54 => 0x74,
0x55 => 0x75,
0x56 => 0x76,
0x57 => 0x77,
0x58 => 0x78,
0x59 => 0x79,
0x5A => 0x7A,
0xC0 => 0xE0,
0xC1 => 0xE1,
0xC2 => 0xE2,
0xC3 => 0xE3,
0xC4 => 0xE4,
0xC5 => 0xE5,
0xC6 => 0xE6,
0xC7 => 0xE7,
0xC8 => 0xE8,
0xC9 => 0xE9,
0xCA => 0xEA,
0xCB => 0xEB,
0xCC => 0xEC,
0xCD => 0xED,
0xCE => 0xEE,
0xCF => 0xEF,
0xD0 => 0xF0,
0xD1 => 0xF1,
0xD2 => 0xF2,
0xD3 => 0xF3,
0xD4 => 0xF4,
0xD5 => 0xF5,
0xD6 => 0xF6,
0xD8 => 0xF8,
0xD9 => 0xF9,
0xDA => 0xFA,
0xDB => 0xFB,
0xDC => 0xFC,
0xDD => 0xFD,
0xDE => 0xFE,
0x100 => 0x101,
0x102 => 0x103,
0x104 => 0x105,
0x106 => 0x107,
0x108 => 0x109,
0x10A => 0x10B,
0x10C => 0x10D,
0x10E => 0x10F,
0x110 => 0x111,
0x112 => 0x113,
0x114 => 0x115,
0x116 => 0x117,
0x118 => 0x119,
0x11A => 0x11B,
0x11C => 0x11D,
0x11E => 0x11F,
0x120 => 0x121,
0x122 => 0x123,
0x124 => 0x125,
0x126 => 0x127,
0x128 => 0x129,
0x12A => 0x12B,
0x12C => 0x12D,
0x12E => 0x12F,
0x130 => 0x69,
0x132 => 0x133,
0x134 => 0x135,
0x136 => 0x137,
0x139 => 0x13A,
0x13B => 0x13C,
0x13D => 0x13E,
0x13F => 0x140,
0x141 => 0x142,
0x143 => 0x144,
0x145 => 0x146,
0x147 => 0x148,
0x14A => 0x14B,
0x14C => 0x14D,
0x14E => 0x14F,
0x150 => 0x151,
0x152 => 0x153,
0x154 => 0x155,
0x156 => 0x157,
0x158 => 0x159,
0x15A => 0x15B,
0x15C => 0x15D,
0x15E => 0x15F,
0x160 => 0x161,
0x162 => 0x163,
0x164 => 0x165,
0x166 => 0x167,
0x168 => 0x169,
0x16A => 0x16B,
0x16C => 0x16D,
0x16E => 0x16F,
0x170 => 0x171,
0x172 => 0x173,
0x174 => 0x175,
0x176 => 0x177,
0x178 => 0xFF,
0x179 => 0x17A,
0x17B => 0x17C,
0x17D => 0x17E,
0x181 => 0x253,
0x182 => 0x183,
0x184 => 0x185,
0x186 => 0x254,
0x187 => 0x188,
0x189 => 0x256,
0x18A => 0x257,
0x18B => 0x18C,
0x18E => 0x1DD,
0x18F => 0x259,
0x190 => 0x25B,
0x191 => 0x192,
0x193 => 0x260,
0x194 => 0x263,
0x196 => 0x269,
0x197 => 0x268,
0x198 => 0x199,
0x19C => 0x26F,
0x19D => 0x272,
0x19F => 0x275,
0x1A0 => 0x1A1,
0x1A2 => 0x1A3,
0x1A4 => 0x1A5,
0x1A6 => 0x280,
0x1A7 => 0x1A8,
0x1A9 => 0x283,
0x1AC => 0x1AD,
0x1AE => 0x288,
0x1AF => 0x1B0,
0x1B1 => 0x28A,
0x1B2 => 0x28B,
0x1B3 => 0x1B4,
0x1B5 => 0x1B6,
0x1B7 => 0x292,
0x1B8 => 0x1B9,
0x1BC => 0x1BD,
0x1C4 => 0x1C6,
0x1C5 => 0x1C6,
0x1C7 => 0x1C9,
0x1C8 => 0x1C9,
0x1CA => 0x1CC,
0x1CB => 0x1CC,
0x1CD => 0x1CE,
0x1CF => 0x1D0,
0x1D1 => 0x1D2,
0x1D3 => 0x1D4,
0x1D5 => 0x1D6,
0x1D7 => 0x1D8,
0x1D9 => 0x1DA,
0x1DB => 0x1DC,
0x1DE => 0x1DF,
0x1E0 => 0x1E1,
0x1E2 => 0x1E3,
0x1E4 => 0x1E5,
0x1E6 => 0x1E7,
0x1E8 => 0x1E9,
0x1EA => 0x1EB,
0x1EC => 0x1ED,
0x1EE => 0x1EF,
0x1F1 => 0x1F3,
0x1F2 => 0x1F3,
0x1F4 => 0x1F5,
0x1F6 => 0x195,
0x1F7 => 0x1BF,
0x1F8 => 0x1F9,
0x1FA => 0x1FB,
0x1FC => 0x1FD,
0x1FE => 0x1FF,
0x200 => 0x201,
0x202 => 0x203,
0x204 => 0x205,
0x206 => 0x207,
0x208 => 0x209,
0x20A => 0x20B,
0x20C => 0x20D,
0x20E => 0x20F,
0x210 => 0x211,
0x212 => 0x213,
0x214 => 0x215,
0x216 => 0x217,
0x218 => 0x219,
0x21A => 0x21B,
0x21C => 0x21D,
0x21E => 0x21F,
0x220 => 0x19E,
0x222 => 0x223,
0x224 => 0x225,
0x226 => 0x227,
0x228 => 0x229,
0x22A => 0x22B,
0x22C => 0x22D,
0x22E => 0x22F,
0x230 => 0x231,
0x232 => 0x233,
0x23A => 0x2C65,
0x23B => 0x23C,
0x23D => 0x19A,
0x23E => 0x2C66,
0x241 => 0x242,
0x243 => 0x180,
0x244 => 0x289,
0x245 => 0x28C,
0x246 => 0x247,
0x248 => 0x249,
0x24A => 0x24B,
0x24C => 0x24D,
0x24E => 0x24F,
0x370 => 0x371,
0x372 => 0x373,
0x376 => 0x377,
0x37F => 0x3F3,
0x386 => 0x3AC,
0x388 => 0x3AD,
0x389 => 0x3AE,
0x38A => 0x3AF,
0x38C => 0x3CC,
0x38E => 0x3CD,
0x38F => 0x3CE,
0x391 => 0x3B1,
0x392 => 0x3B2,
0x393 => 0x3B3,
0x394 => 0x3B4,
0x395 => 0x3B5,
0x396 => 0x3B6,
0x397 => 0x3B7,
0x398 => 0x3B8,
0x399 => 0x3B9,
0x39A => 0x3BA,
0x39B => 0x3BB,
0x39C => 0x3BC,
0x39D => 0x3BD,
0x39E => 0x3BE,
0x39F => 0x3BF,
0x3A0 => 0x3C0,
0x3A1 => 0x3C1,
0x3A3 => 0x3C3,
0x3A4 => 0x3C4,
0x3A5 => 0x3C5,
0x3A6 => 0x3C6,
0x3A7 => 0x3C7,
0x3A8 => 0x3C8,
0x3A9 => 0x3C9,
0x3AA => 0x3CA,
0x3AB => 0x3CB,
0x3CF => 0x3D7,
0x3D8 => 0x3D9,
0x3DA => 0x3DB,
0x3DC => 0x3DD,
0x3DE => 0x3DF,
0x3E0 => 0x3E1,
0x3E2 => 0x3E3,
0x3E4 => 0x3E5,
0x3E6 => 0x3E7,
0x3E8 => 0x3E9,
0x3EA => 0x3EB,
0x3EC => 0x3ED,
0x3EE => 0x3EF,
0x3F4 => 0x3B8,
0x3F7 => 0x3F8,
0x3F9 => 0x3F2,
0x3FA => 0x3FB,
0x3FD => 0x37B,
0x3FE => 0x37C,
0x3FF => 0x37D,
0x400 => 0x450,
0x401 => 0x451,
0x402 => 0x452,
0x403 => 0x453,
0x404 => 0x454,
0x405 => 0x455,
0x406 => 0x456,
0x407 => 0x457,
0x408 => 0x458,
0x409 => 0x459,
0x40A => 0x45A,
0x40B => 0x45B,
0x40C => 0x45C,
0x40D => 0x45D,
0x40E => 0x45E,
0x40F => 0x45F,
0x410 => 0x430,
0x411 => 0x431,
0x412 => 0x432,
0x413 => 0x433,
0x414 => 0x434,
0x415 => 0x435,
0x416 => 0x436,
0x417 => 0x437,
0x418 => 0x438,
0x419 => 0x439,
0x41A => 0x43A,
0x41B => 0x43B,
0x41C => 0x43C,
0x41D => 0x43D,
0x41E => 0x43E,
0x41F => 0x43F,
0x420 => 0x440,
0x421 => 0x441,
0x422 => 0x442,
0x423 => 0x443,
0x424 => 0x444,
0x425 => 0x445,
0x426 => 0x446,
0x427 => 0x447,
0x428 => 0x448,
0x429 => 0x449,
0x42A => 0x44A,
0x42B => 0x44B,
0x42C => 0x44C,
0x42D => 0x44D,
0x42E => 0x44E,
0x42F => 0x44F,
0x460 => 0x461,
0x462 => 0x463,
0x464 => 0x465,
0x466 => 0x467,
0x468 => 0x469,
0x46A => 0x46B,
0x46C => 0x46D,
0x46E => 0x46F,
0x470 => 0x471,
0x472 => 0x473,
0x474 => 0x475,
0x476 => 0x477,
0x478 => 0x479,
0x47A => 0x47B,
0x47C => 0x47D,
0x47E => 0x47F,
0x480 => 0x481,
0x48A => 0x48B,
0x48C => 0x48D,
0x48E => 0x48F,
0x490 => 0x491,
0x492 => 0x493,
0x494 => 0x495,
0x496 => 0x497,
0x498 => 0x499,
0x49A => 0x49B,
0x49C => 0x49D,
0x49E => 0x49F,
0x4A0 => 0x4A1,
0x4A2 => 0x4A3,
0x4A4 => 0x4A5,
0x4A6 => 0x4A7,
0x4A8 => 0x4A9,
0x4AA => 0x4AB,
0x4AC => 0x4AD,
0x4AE => 0x4AF,
0x4B0 => 0x4B1,
0x4B2 => 0x4B3,
0x4B4 => 0x4B5,
0x4B6 => 0x4B7,
0x4B8 => 0x4B9,
0x4BA => 0x4BB,
0x4BC => 0x4BD,
0x4BE => 0x4BF,
0x4C0 => 0x4CF,
0x4C1 => 0x4C2,
0x4C3 => 0x4C4,
0x4C5 => 0x4C6,
0x4C7 => 0x4C8,
0x4C9 => 0x4CA,
0x4CB => 0x4CC,
0x4CD => 0x4CE,
0x4D0 => 0x4D1,
0x4D2 => 0x4D3,
0x4D4 => 0x4D5,
0x4D6 => 0x4D7,
0x4D8 => 0x4D9,
0x4DA => 0x4DB,
0x4DC => 0x4DD,
0x4DE => 0x4DF,
0x4E0 => 0x4E1,
0x4E2 => 0x4E3,
0x4E4 => 0x4E5,
0x4E6 => 0x4E7,
0x4E8 => 0x4E9,
0x4EA => 0x4EB,
0x4EC => 0x4ED,
0x4EE => 0x4EF,
0x4F0 => 0x4F1,
0x4F2 => 0x4F3,
0x4F4 => 0x4F5,
0x4F6 => 0x4F7,
0x4F8 => 0x4F9,
0x4FA => 0x4FB,
0x4FC => 0x4FD,
0x4FE => 0x4FF,
0x500 => 0x501,
0x502 => 0x503,
0x504 => 0x505,
0x506 => 0x507,
0x508 => 0x509,
0x50A => 0x50B,
0x50C => 0x50D,
0x50E => 0x50F,
0x510 => 0x511,
0x512 => 0x513,
0x514 => 0x515,
0x516 => 0x517,
0x518 => 0x519,
0x51A => 0x51B,
0x51C => 0x51D,
0x51E => 0x51F,
0x520 => 0x521,
0x522 => 0x523,
0x524 => 0x525,
0x526 => 0x527,
0x528 => 0x529,
0x52A => 0x52B,
0x52C => 0x52D,
0x52E => 0x52F,
0x531 => 0x561,
0x532 => 0x562,
0x533 => 0x563,
0x534 => 0x564,
0x535 => 0x565,
0x536 => 0x566,
0x537 => 0x567,
0x538 => 0x568,
0x539 => 0x569,
0x53A => 0x56A,
0x53B => 0x56B,
0x53C => 0x56C,
0x53D => 0x56D,
0x53E => 0x56E,
0x53F => 0x56F,
0x540 => 0x570,
0x541 => 0x571,
0x542 => 0x572,
0x543 => 0x573,
0x544 => 0x574,
0x545 => 0x575,
0x546 => 0x576,
0x547 => 0x577,
0x548 => 0x578,
0x549 => 0x579,
0x54A => 0x57A,
0x54B => 0x57B,
0x54C => 0x57C,
0x54D => 0x57D,
0x54E => 0x57E,
0x54F => 0x57F,
0x550 => 0x580,
0x551 => 0x581,
0x552 => 0x582,
0x553 => 0x583,
0x554 => 0x584,
0x555 => 0x585,
0x556 => 0x586,
0x10A0 => 0x2D00,
0x10A1 => 0x2D01,
0x10A2 => 0x2D02,
0x10A3 => 0x2D03,
0x10A4 => 0x2D04,
0x10A5 => 0x2D05,
0x10A6 => 0x2D06,
0x10A7 => 0x2D07,
0x10A8 => 0x2D08,
0x10A9 => 0x2D09,
0x10AA => 0x2D0A,
0x10AB => 0x2D0B,
0x10AC => 0x2D0C,
0x10AD => 0x2D0D,
0x10AE => 0x2D0E,
0x10AF => 0x2D0F,
0x10B0 => 0x2D10,
0x10B1 => 0x2D11,
0x10B2 => 0x2D12,
0x10B3 => 0x2D13,
0x10B4 => 0x2D14,
0x10B5 => 0x2D15,
0x10B6 => 0x2D16,
0x10B7 => 0x2D17,
0x10B8 => 0x2D18,
0x10B9 => 0x2D19,
0x10BA => 0x2D1A,
0x10BB => 0x2D1B,
0x10BC => 0x2D1C,
0x10BD => 0x2D1D,
0x10BE => 0x2D1E,
0x10BF => 0x2D1F,
0x10C0 => 0x2D20,
0x10C1 => 0x2D21,
0x10C2 => 0x2D22,
0x10C3 => 0x2D23,
0x10C4 => 0x2D24,
0x10C5 => 0x2D25,
0x10C7 => 0x2D27,
0x10CD => 0x2D2D,
0x13A0 => 0xAB70,
0x13A1 => 0xAB71,
0x13A2 => 0xAB72,
0x13A3 => 0xAB73,
0x13A4 => 0xAB74,
0x13A5 => 0xAB75,
0x13A6 => 0xAB76,
0x13A7 => 0xAB77,
0x13A8 => 0xAB78,
0x13A9 => 0xAB79,
0x13AA => 0xAB7A,
0x13AB => 0xAB7B,
0x13AC => 0xAB7C,
0x13AD => 0xAB7D,
0x13AE => 0xAB7E,
0x13AF => 0xAB7F,
0x13B0 => 0xAB80,
0x13B1 => 0xAB81,
0x13B2 => 0xAB82,
0x13B3 => 0xAB83,
0x13B4 => 0xAB84,
0x13B5 => 0xAB85,
0x13B6 => 0xAB86,
0x13B7 => 0xAB87,
0x13B8 => 0xAB88,
0x13B9 => 0xAB89,
0x13BA => 0xAB8A,
0x13BB => 0xAB8B,
0x13BC => 0xAB8C,
0x13BD => 0xAB8D,
0x13BE => 0xAB8E,
0x13BF => 0xAB8F,
0x13C0 => 0xAB90,
0x13C1 => 0xAB91,
0x13C2 => 0xAB92,
0x13C3 => 0xAB93,
0x13C4 => 0xAB94,
0x13C5 => 0xAB95,
0x13C6 => 0xAB96,
0x13C7 => 0xAB97,
0x13C8 => 0xAB98,
0x13C9 => 0xAB99,
0x13CA => 0xAB9A,
0x13CB => 0xAB9B,
0x13CC => 0xAB9C,
0x13CD => 0xAB9D,
0x13CE => 0xAB9E,
0x13CF => 0xAB9F,
0x13D0 => 0xABA0,
0x13D1 => 0xABA1,
0x13D2 => 0xABA2,
0x13D3 => 0xABA3,
0x13D4 => 0xABA4,
0x13D5 => 0xABA5,
0x13D6 => 0xABA6,
0x13D7 => 0xABA7,
0x13D8 => 0xABA8,
0x13D9 => 0xABA9,
0x13DA => 0xABAA,
0x13DB => 0xABAB,
0x13DC => 0xABAC,
0x13DD => 0xABAD,
0x13DE => 0xABAE,
0x13DF => 0xABAF,
0x13E0 => 0xABB0,
0x13E1 => 0xABB1,
0x13E2 => 0xABB2,
0x13E3 => 0xABB3,
0x13E4 => 0xABB4,
0x13E5 => 0xABB5,
0x13E6 => 0xABB6,
0x13E7 => 0xABB7,
0x13E8 => 0xABB8,
0x13E9 => 0xABB9,
0x13EA => 0xABBA,
0x13EB => 0xABBB,
0x13EC => 0xABBC,
0x13ED => 0xABBD,
0x13EE => 0xABBE,
0x13EF => 0xABBF,
0x13F0 => 0x13F8,
0x13F1 => 0x13F9,
0x13F2 => 0x13FA,
0x13F3 => 0x13FB,
0x13F4 => 0x13FC,
0x13F5 => 0x13FD,
0x1C90 => 0x10D0,
0x1C91 => 0x10D1,
0x1C92 => 0x10D2,
0x1C93 => 0x10D3,
0x1C94 => 0x10D4,
0x1C95 => 0x10D5,
0x1C96 => 0x10D6,
0x1C97 => 0x10D7,
0x1C98 => 0x10D8,
0x1C99 => 0x10D9,
0x1C9A => 0x10DA,
0x1C9B => 0x10DB,
0x1C9C => 0x10DC,
0x1C9D => 0x10DD,
0x1C9E => 0x10DE,
0x1C9F => 0x10DF,
0x1CA0 => 0x10E0,
0x1CA1 => 0x10E1,
0x1CA2 => 0x10E2,
0x1CA3 => 0x10E3,
0x1CA4 => 0x10E4,
0x1CA5 => 0x10E5,
0x1CA6 => 0x10E6,
0x1CA7 => 0x10E7,
0x1CA8 => 0x10E8,
0x1CA9 => 0x10E9,
0x1CAA => 0x10EA,
0x1CAB => 0x10EB,
0x1CAC => 0x10EC,
0x1CAD => 0x10ED,
0x1CAE => 0x10EE,
0x1CAF => 0x10EF,
0x1CB0 => 0x10F0,
0x1CB1 => 0x10F1,
0x1CB2 => 0x10F2,
0x1CB3 => 0x10F3,
0x1CB4 => 0x10F4,
0x1CB5 => 0x10F5,
0x1CB6 => 0x10F6,
0x1CB7 => 0x10F7,
0x1CB8 => 0x10F8,
0x1CB9 => 0x10F9,
0x1CBA => 0x10FA,
0x1CBD => 0x10FD,
0x1CBE => 0x10FE,
0x1CBF => 0x10FF,
0x1E00 => 0x1E01,
0x1E02 => 0x1E03,
0x1E04 => 0x1E05,
0x1E06 => 0x1E07,
0x1E08 => 0x1E09,
0x1E0A => 0x1E0B,
0x1E0C => 0x1E0D,
0x1E0E => 0x1E0F,
0x1E10 => 0x1E11,
0x1E12 => 0x1E13,
0x1E14 => 0x1E15,
0x1E16 => 0x1E17,
0x1E18 => 0x1E19,
0x1E1A => 0x1E1B,
0x1E1C => 0x1E1D,
0x1E1E => 0x1E1F,
0x1E20 => 0x1E21,
0x1E22 => 0x1E23,
0x1E24 => 0x1E25,
0x1E26 => 0x1E27,
0x1E28 => 0x1E29,
0x1E2A => 0x1E2B,
0x1E2C => 0x1E2D,
0x1E2E => 0x1E2F,
0x1E30 => 0x1E31,
0x1E32 => 0x1E33,
0x1E34 => 0x1E35,
0x1E36 => 0x1E37,
0x1E38 => 0x1E39,
0x1E3A => 0x1E3B,
0x1E3C => 0x1E3D,
0x1E3E => 0x1E3F,
0x1E40 => 0x1E41,
0x1E42 => 0x1E43,
0x1E44 => 0x1E45,
0x1E46 => 0x1E47,
0x1E48 => 0x1E49,
0x1E4A => 0x1E4B,
0x1E4C => 0x1E4D,
0x1E4E => 0x1E4F,
0x1E50 => 0x1E51,
0x1E52 => 0x1E53,
0x1E54 => 0x1E55,
0x1E56 => 0x1E57,
0x1E58 => 0x1E59,
0x1E5A => 0x1E5B,
0x1E5C => 0x1E5D,
0x1E5E => 0x1E5F,
0x1E60 => 0x1E61,
0x1E62 => 0x1E63,
0x1E64 => 0x1E65,
0x1E66 => 0x1E67,
0x1E68 => 0x1E69,
0x1E6A => 0x1E6B,
0x1E6C => 0x1E6D,
0x1E6E => 0x1E6F,
0x1E70 => 0x1E71,
0x1E72 => 0x1E73,
0x1E74 => 0x1E75,
0x1E76 => 0x1E77,
0x1E78 => 0x1E79,
0x1E7A => 0x1E7B,
0x1E7C => 0x1E7D,
0x1E7E => 0x1E7F,
0x1E80 => 0x1E81,
0x1E82 => 0x1E83,
0x1E84 => 0x1E85,
0x1E86 => 0x1E87,
0x1E88 => 0x1E89,
0x1E8A => 0x1E8B,
0x1E8C => 0x1E8D,
0x1E8E => 0x1E8F,
0x1E90 => 0x1E91,
0x1E92 => 0x1E93,
0x1E94 => 0x1E95,
0x1E9E => 0xDF,
0x1EA0 => 0x1EA1,
0x1EA2 => 0x1EA3,
0x1EA4 => 0x1EA5,
0x1EA6 => 0x1EA7,
0x1EA8 => 0x1EA9,
0x1EAA => 0x1EAB,
0x1EAC => 0x1EAD,
0x1EAE => 0x1EAF,
0x1EB0 => 0x1EB1,
0x1EB2 => 0x1EB3,
0x1EB4 => 0x1EB5,
0x1EB6 => 0x1EB7,
0x1EB8 => 0x1EB9,
0x1EBA => 0x1EBB,
0x1EBC => 0x1EBD,
0x1EBE => 0x1EBF,
0x1EC0 => 0x1EC1,
0x1EC2 => 0x1EC3,
0x1EC4 => 0x1EC5,
0x1EC6 => 0x1EC7,
0x1EC8 => 0x1EC9,
0x1ECA => 0x1ECB,
0x1ECC => 0x1ECD,
0x1ECE => 0x1ECF,
0x1ED0 => 0x1ED1,
0x1ED2 => 0x1ED3,
0x1ED4 => 0x1ED5,
0x1ED6 => 0x1ED7,
0x1ED8 => 0x1ED9,
0x1EDA => 0x1EDB,
0x1EDC => 0x1EDD,
0x1EDE => 0x1EDF,
0x1EE0 => 0x1EE1,
0x1EE2 => 0x1EE3,
0x1EE4 => 0x1EE5,
0x1EE6 => 0x1EE7,
0x1EE8 => 0x1EE9,
0x1EEA => 0x1EEB,
0x1EEC => 0x1EED,
0x1EEE => 0x1EEF,
0x1EF0 => 0x1EF1,
0x1EF2 => 0x1EF3,
0x1EF4 => 0x1EF5,
0x1EF6 => 0x1EF7,
0x1EF8 => 0x1EF9,
0x1EFA => 0x1EFB,
0x1EFC => 0x1EFD,
0x1EFE => 0x1EFF,
0x1F08 => 0x1F00,
0x1F09 => 0x1F01,
0x1F0A => 0x1F02,
0x1F0B => 0x1F03,
0x1F0C => 0x1F04,
0x1F0D => 0x1F05,
0x1F0E => 0x1F06,
0x1F0F => 0x1F07,
0x1F18 => 0x1F10,
0x1F19 => 0x1F11,
0x1F1A => 0x1F12,
0x1F1B => 0x1F13,
0x1F1C => 0x1F14,
0x1F1D => 0x1F15,
0x1F28 => 0x1F20,
0x1F29 => 0x1F21,
0x1F2A => 0x1F22,
0x1F2B => 0x1F23,
0x1F2C => 0x1F24,
0x1F2D => 0x1F25,
0x1F2E => 0x1F26,
0x1F2F => 0x1F27,
0x1F38 => 0x1F30,
0x1F39 => 0x1F31,
0x1F3A => 0x1F32,
0x1F3B => 0x1F33,
0x1F3C => 0x1F34,
0x1F3D => 0x1F35,
0x1F3E => 0x1F36,
0x1F3F => 0x1F37,
0x1F48 => 0x1F40,
0x1F49 => 0x1F41,
0x1F4A => 0x1F42,
0x1F4B => 0x1F43,
0x1F4C => 0x1F44,
0x1F4D => 0x1F45,
0x1F59 => 0x1F51,
0x1F5B => 0x1F53,
0x1F5D => 0x1F55,
0x1F5F => 0x1F57,
0x1F68 => 0x1F60,
0x1F69 => 0x1F61,
0x1F6A => 0x1F62,
0x1F6B => 0x1F63,
0x1F6C => 0x1F64,
0x1F6D => 0x1F65,
0x1F6E => 0x1F66,
0x1F6F => 0x1F67,
0x1F88 => 0x1F80,
0x1F89 => 0x1F81,
0x1F8A => 0x1F82,
0x1F8B => 0x1F83,
0x1F8C => 0x1F84,
0x1F8D => 0x1F85,
0x1F8E => 0x1F86,
0x1F8F => 0x1F87,
0x1F98 => 0x1F90,
0x1F99 => 0x1F91,
0x1F9A => 0x1F92,
0x1F9B => 0x1F93,
0x1F9C => 0x1F94,
0x1F9D => 0x1F95,
0x1F9E => 0x1F96,
0x1F9F => 0x1F97,
0x1FA8 => 0x1FA0,
0x1FA9 => 0x1FA1,
0x1FAA => 0x1FA2,
0x1FAB => 0x1FA3,
0x1FAC => 0x1FA4,
0x1FAD => 0x1FA5,
0x1FAE => 0x1FA6,
0x1FAF => 0x1FA7,
0x1FB8 => 0x1FB0,
0x1FB9 => 0x1FB1,
0x1FBA => 0x1F70,
0x1FBB => 0x1F71,
0x1FBC => 0x1FB3,
0x1FC8 => 0x1F72,
0x1FC9 => 0x1F73,
0x1FCA => 0x1F74,
0x1FCB => 0x1F75,
0x1FCC => 0x1FC3,
0x1FD8 => 0x1FD0,
0x1FD9 => 0x1FD1,
0x1FDA => 0x1F76,
0x1FDB => 0x1F77,
0x1FE8 => 0x1FE0,
0x1FE9 => 0x1FE1,
0x1FEA => 0x1F7A,
0x1FEB => 0x1F7B,
0x1FEC => 0x1FE5,
0x1FF8 => 0x1F78,
0x1FF9 => 0x1F79,
0x1FFA => 0x1F7C,
0x1FFB => 0x1F7D,
0x1FFC => 0x1FF3,
0x2126 => 0x3C9,
0x212A => 0x6B,
0x212B => 0xE5,
0x2132 => 0x214E,
0x2160 => 0x2170,
0x2161 => 0x2171,
0x2162 => 0x2172,
0x2163 => 0x2173,
0x2164 => 0x2174,
0x2165 => 0x2175,
0x2166 => 0x2176,
0x2167 => 0x2177,
0x2168 => 0x2178,
0x2169 => 0x2179,
0x216A => 0x217A,
0x216B => 0x217B,
0x216C => 0x217C,
0x216D => 0x217D,
0x216E => 0x217E,
0x216F => 0x217F,
0x2183 => 0x2184,
0x24B6 => 0x24D0,
0x24B7 => 0x24D1,
0x24B8 => 0x24D2,
0x24B9 => 0x24D3,
0x24BA => 0x24D4,
0x24BB => 0x24D5,
0x24BC => 0x24D6,
0x24BD => 0x24D7,
0x24BE => 0x24D8,
0x24BF => 0x24D9,
0x24C0 => 0x24DA,
0x24C1 => 0x24DB,
0x24C2 => 0x24DC,
0x24C3 => 0x24DD,
0x24C4 => 0x24DE,
0x24C5 => 0x24DF,
0x24C6 => 0x24E0,
0x24C7 => 0x24E1,
0x24C8 => 0x24E2,
0x24C9 => 0x24E3,
0x24CA => 0x24E4,
0x24CB => 0x24E5,
0x24CC => 0x24E6,
0x24CD => 0x24E7,
0x24CE => 0x24E8,
0x24CF => 0x24E9,
0x2C00 => 0x2C30,
0x2C01 => 0x2C31,
0x2C02 => 0x2C32,
0x2C03 => 0x2C33,
0x2C04 => 0x2C34,
0x2C05 => 0x2C35,
0x2C06 => 0x2C36,
0x2C07 => 0x2C37,
0x2C08 => 0x2C38,
0x2C09 => 0x2C39,
0x2C0A => 0x2C3A,
0x2C0B => 0x2C3B,
0x2C0C => 0x2C3C,
0x2C0D => 0x2C3D,
0x2C0E => 0x2C3E,
0x2C0F => 0x2C3F,
0x2C10 => 0x2C40,
0x2C11 => 0x2C41,
0x2C12 => 0x2C42,
0x2C13 => 0x2C43,
0x2C14 => 0x2C44,
0x2C15 => 0x2C45,
0x2C16 => 0x2C46,
0x2C17 => 0x2C47,
0x2C18 => 0x2C48,
0x2C19 => 0x2C49,
0x2C1A => 0x2C4A,
0x2C1B => 0x2C4B,
0x2C1C => 0x2C4C,
0x2C1D => 0x2C4D,
0x2C1E => 0x2C4E,
0x2C1F => 0x2C4F,
0x2C20 => 0x2C50,
0x2C21 => 0x2C51,
0x2C22 => 0x2C52,
0x2C23 => 0x2C53,
0x2C24 => 0x2C54,
0x2C25 => 0x2C55,
0x2C26 => 0x2C56,
0x2C27 => 0x2C57,
0x2C28 => 0x2C58,
0x2C29 => 0x2C59,
0x2C2A => 0x2C5A,
0x2C2B => 0x2C5B,
0x2C2C => 0x2C5C,
0x2C2D => 0x2C5D,
0x2C2E => 0x2C5E,
0x2C2F => 0x2C5F,
0x2C60 => 0x2C61,
0x2C62 => 0x26B,
0x2C63 => 0x1D7D,
0x2C64 => 0x27D,
0x2C67 => 0x2C68,
0x2C69 => 0x2C6A,
0x2C6B => 0x2C6C,
0x2C6D => 0x251,
0x2C6E => 0x271,
0x2C6F => 0x250,
0x2C70 => 0x252,
0x2C72 => 0x2C73,
0x2C75 => 0x2C76,
0x2C7E => 0x23F,
0x2C7F => 0x240,
0x2C80 => 0x2C81,
0x2C82 => 0x2C83,
0x2C84 => 0x2C85,
0x2C86 => 0x2C87,
0x2C88 => 0x2C89,
0x2C8A => 0x2C8B,
0x2C8C => 0x2C8D,
0x2C8E => 0x2C8F,
0x2C90 => 0x2C91,
0x2C92 => 0x2C93,
0x2C94 => 0x2C95,
0x2C96 => 0x2C97,
0x2C98 => 0x2C99,
0x2C9A => 0x2C9B,
0x2C9C => 0x2C9D,
0x2C9E => 0x2C9F,
0x2CA0 => 0x2CA1,
0x2CA2 => 0x2CA3,
0x2CA4 => 0x2CA5,
0x2CA6 => 0x2CA7,
0x2CA8 => 0x2CA9,
0x2CAA => 0x2CAB,
0x2CAC => 0x2CAD,
0x2CAE => 0x2CAF,
0x2CB0 => 0x2CB1,
0x2CB2 => 0x2CB3,
0x2CB4 => 0x2CB5,
0x2CB6 => 0x2CB7,
0x2CB8 => 0x2CB9,
0x2CBA => 0x2CBB,
0x2CBC => 0x2CBD,
0x2CBE => 0x2CBF,
0x2CC0 => 0x2CC1,
0x2CC2 => 0x2CC3,
0x2CC4 => 0x2CC5,
0x2CC6 => 0x2CC7,
0x2CC8 => 0x2CC9,
0x2CCA => 0x2CCB,
0x2CCC => 0x2CCD,
0x2CCE => 0x2CCF,
0x2CD0 => 0x2CD1,
0x2CD2 => 0x2CD3,
0x2CD4 => 0x2CD5,
0x2CD6 => 0x2CD7,
0x2CD8 => 0x2CD9,
0x2CDA => 0x2CDB,
0x2CDC => 0x2CDD,
0x2CDE => 0x2CDF,
0x2CE0 => 0x2CE1,
0x2CE2 => 0x2CE3,
0x2CEB => 0x2CEC,
0x2CED => 0x2CEE,
0x2CF2 => 0x2CF3,
0xA640 => 0xA641,
0xA642 => 0xA643,
0xA644 => 0xA645,
0xA646 => 0xA647,
0xA648 => 0xA649,
0xA64A => 0xA64B,
0xA64C => 0xA64D,
0xA64E => 0xA64F,
0xA650 => 0xA651,
0xA652 => 0xA653,
0xA654 => 0xA655,
0xA656 => 0xA657,
0xA658 => 0xA659,
0xA65A => 0xA65B,
0xA65C => 0xA65D,
0xA65E => 0xA65F,
0xA660 => 0xA661,
0xA662 => 0xA663,
0xA664 => 0xA665,
0xA666 => 0xA667,
0xA668 => 0xA669,
0xA66A => 0xA66B,
0xA66C => 0xA66D,
0xA680 => 0xA681,
0xA682 => 0xA683,
0xA684 => 0xA685,
0xA686 => 0xA687,
0xA688 => 0xA689,
0xA68A => 0xA68B,
0xA68C => 0xA68D,
0xA68E => 0xA68F,
0xA690 => 0xA691,
0xA692 => 0xA693,
0xA694 => 0xA695,
0xA696 => 0xA697,
0xA698 => 0xA699,
0xA69A => 0xA69B,
0xA722 => 0xA723,
0xA724 => 0xA725,
0xA726 => 0xA727,
0xA728 => 0xA729,
0xA72A => 0xA72B,
0xA72C => 0xA72D,
0xA72E => 0xA72F,
0xA732 => 0xA733,
0xA734 => 0xA735,
0xA736 => 0xA737,
0xA738 => 0xA739,
0xA73A => 0xA73B,
0xA73C => 0xA73D,
0xA73E => 0xA73F,
0xA740 => 0xA741,
0xA742 => 0xA743,
0xA744 => 0xA745,
0xA746 => 0xA747,
0xA748 => 0xA749,
0xA74A => 0xA74B,
0xA74C => 0xA74D,
0xA74E => 0xA74F,
0xA750 => 0xA751,
0xA752 => 0xA753,
0xA754 => 0xA755,
0xA756 => 0xA757,
0xA758 => 0xA759,
0xA75A => 0xA75B,
0xA75C => 0xA75D,
0xA75E => 0xA75F,
0xA760 => 0xA761,
0xA762 => 0xA763,
0xA764 => 0xA765,
0xA766 => 0xA767,
0xA768 => 0xA769,
0xA76A => 0xA76B,
0xA76C => 0xA76D,
0xA76E => 0xA76F,
0xA779 => 0xA77A,
0xA77B => 0xA77C,
0xA77D => 0x1D79,
0xA77E => 0xA77F,
0xA780 => 0xA781,
0xA782 => 0xA783,
0xA784 => 0xA785,
0xA786 => 0xA787,
0xA78B => 0xA78C,
0xA78D => 0x265,
0xA790 => 0xA791,
0xA792 => 0xA793,
0xA796 => 0xA797,
0xA798 => 0xA799,
0xA79A => 0xA79B,
0xA79C => 0xA79D,
0xA79E => 0xA79F,
0xA7A0 => 0xA7A1,
0xA7A2 => 0xA7A3,
0xA7A4 => 0xA7A5,
0xA7A6 => 0xA7A7,
0xA7A8 => 0xA7A9,
0xA7AA => 0x266,
0xA7AB => 0x25C,
0xA7AC => 0x261,
0xA7AD => 0x26C,
0xA7AE => 0x26A,
0xA7B0 => 0x29E,
0xA7B1 => 0x287,
0xA7B2 => 0x29D,
0xA7B3 => 0xAB53,
0xA7B4 => 0xA7B5,
0xA7B6 => 0xA7B7,
0xA7B8 => 0xA7B9,
0xA7BA => 0xA7BB,
0xA7BC => 0xA7BD,
0xA7BE => 0xA7BF,
0xA7C0 => 0xA7C1,
0xA7C2 => 0xA7C3,
0xA7C4 => 0xA794,
0xA7C5 => 0x282,
0xA7C6 => 0x1D8E,
0xA7C7 => 0xA7C8,
0xA7C9 => 0xA7CA,
0xA7D0 => 0xA7D1,
0xA7D6 => 0xA7D7,
0xA7D8 => 0xA7D9,
0xA7F5 => 0xA7F6,
0xFF21 => 0xFF41,
0xFF22 => 0xFF42,
0xFF23 => 0xFF43,
0xFF24 => 0xFF44,
0xFF25 => 0xFF45,
0xFF26 => 0xFF46,
0xFF27 => 0xFF47,
0xFF28 => 0xFF48,
0xFF29 => 0xFF49,
0xFF2A => 0xFF4A,
0xFF2B => 0xFF4B,
0xFF2C => 0xFF4C,
0xFF2D => 0xFF4D,
0xFF2E => 0xFF4E,
0xFF2F => 0xFF4F,
0xFF30 => 0xFF50,
0xFF31 => 0xFF51,
0xFF32 => 0xFF52,
0xFF33 => 0xFF53,
0xFF34 => 0xFF54,
0xFF35 => 0xFF55,
0xFF36 => 0xFF56,
0xFF37 => 0xFF57,
0xFF38 => 0xFF58,
0xFF39 => 0xFF59,
0xFF3A => 0xFF5A,
0x10400 => 0x10428,
0x10401 => 0x10429,
0x10402 => 0x1042A,
0x10403 => 0x1042B,
0x10404 => 0x1042C,
0x10405 => 0x1042D,
0x10406 => 0x1042E,
0x10407 => 0x1042F,
0x10408 => 0x10430,
0x10409 => 0x10431,
0x1040A => 0x10432,
0x1040B => 0x10433,
0x1040C => 0x10434,
0x1040D => 0x10435,
0x1040E => 0x10436,
0x1040F => 0x10437,
0x10410 => 0x10438,
0x10411 => 0x10439,
0x10412 => 0x1043A,
0x10413 => 0x1043B,
0x10414 => 0x1043C,
0x10415 => 0x1043D,
0x10416 => 0x1043E,
0x10417 => 0x1043F,
0x10418 => 0x10440,
0x10419 => 0x10441,
0x1041A => 0x10442,
0x1041B => 0x10443,
0x1041C => 0x10444,
0x1041D => 0x10445,
0x1041E => 0x10446,
0x1041F => 0x10447,
0x10420 => 0x10448,
0x10421 => 0x10449,
0x10422 => 0x1044A,
0x10423 => 0x1044B,
0x10424 => 0x1044C,
0x10425 => 0x1044D,
0x10426 => 0x1044E,
0x10427 => 0x1044F,
0x104B0 => 0x104D8,
0x104B1 => 0x104D9,
0x104B2 => 0x104DA,
0x104B3 => 0x104DB,
0x104B4 => 0x104DC,
0x104B5 => 0x104DD,
0x104B6 => 0x104DE,
0x104B7 => 0x104DF,
0x104B8 => 0x104E0,
0x104B9 => 0x104E1,
0x104BA => 0x104E2,
0x104BB => 0x104E3,
0x104BC => 0x104E4,
0x104BD => 0x104E5,
0x104BE => 0x104E6,
0x104BF => 0x104E7,
0x104C0 => 0x104E8,
0x104C1 => 0x104E9,
0x104C2 => 0x104EA,
0x104C3 => 0x104EB,
0x104C4 => 0x104EC,
0x104C5 => 0x104ED,
0x104C6 => 0x104EE,
0x104C7 => 0x104EF,
0x104C8 => 0x104F0,
0x104C9 => 0x104F1,
0x104CA => 0x104F2,
0x104CB => 0x104F3,
0x104CC => 0x104F4,
0x104CD => 0x104F5,
0x104CE => 0x104F6,
0x104CF => 0x104F7,
0x104D0 => 0x104F8,
0x104D1 => 0x104F9,
0x104D2 => 0x104FA,
0x104D3 => 0x104FB,
0x10570 => 0x10597,
0x10571 => 0x10598,
0x10572 => 0x10599,
0x10573 => 0x1059A,
0x10574 => 0x1059B,
0x10575 => 0x1059C,
0x10576 => 0x1059D,
0x10577 => 0x1059E,
0x10578 => 0x1059F,
0x10579 => 0x105A0,
0x1057A => 0x105A1,
0x1057C => 0x105A3,
0x1057D => 0x105A4,
0x1057E => 0x105A5,
0x1057F => 0x105A6,
0x10580 => 0x105A7,
0x10581 => 0x105A8,
0x10582 => 0x105A9,
0x10583 => 0x105AA,
0x10584 => 0x105AB,
0x10585 => 0x105AC,
0x10586 => 0x105AD,
0x10587 => 0x105AE,
0x10588 => 0x105AF,
0x10589 => 0x105B0,
0x1058A => 0x105B1,
0x1058C => 0x105B3,
0x1058D => 0x105B4,
0x1058E => 0x105B5,
0x1058F => 0x105B6,
0x10590 => 0x105B7,
0x10591 => 0x105B8,
0x10592 => 0x105B9,
0x10594 => 0x105BB,
0x10595 => 0x105BC,
0x10C80 => 0x10CC0,
0x10C81 => 0x10CC1,
0x10C82 => 0x10CC2,
0x10C83 => 0x10CC3,
0x10C84 => 0x10CC4,
0x10C85 => 0x10CC5,
0x10C86 => 0x10CC6,
0x10C87 => 0x10CC7,
0x10C88 => 0x10CC8,
0x10C89 => 0x10CC9,
0x10C8A => 0x10CCA,
0x10C8B => 0x10CCB,
0x10C8C => 0x10CCC,
0x10C8D => 0x10CCD,
0x10C8E => 0x10CCE,
0x10C8F => 0x10CCF,
0x10C90 => 0x10CD0,
0x10C91 => 0x10CD1,
0x10C92 => 0x10CD2,
0x10C93 => 0x10CD3,
0x10C94 => 0x10CD4,
0x10C95 => 0x10CD5,
0x10C96 => 0x10CD6,
0x10C97 => 0x10CD7,
0x10C98 => 0x10CD8,
0x10C99 => 0x10CD9,
0x10C9A => 0x10CDA,
0x10C9B => 0x10CDB,
0x10C9C => 0x10CDC,
0x10C9D => 0x10CDD,
0x10C9E => 0x10CDE,
0x10C9F => 0x10CDF,
0x10CA0 => 0x10CE0,
0x10CA1 => 0x10CE1,
0x10CA2 => 0x10CE2,
0x10CA3 => 0x10CE3,
0x10CA4 => 0x10CE4,
0x10CA5 => 0x10CE5,
0x10CA6 => 0x10CE6,
0x10CA7 => 0x10CE7,
0x10CA8 => 0x10CE8,
0x10CA9 => 0x10CE9,
0x10CAA => 0x10CEA,
0x10CAB => 0x10CEB,
0x10CAC => 0x10CEC,
0x10CAD => 0x10CED,
0x10CAE => 0x10CEE,
0x10CAF => 0x10CEF,
0x10CB0 => 0x10CF0,
0x10CB1 => 0x10CF1,
0x10CB2 => 0x10CF2,
0x118A0 => 0x118C0,
0x118A1 => 0x118C1,
0x118A2 => 0x118C2,
0x118A3 => 0x118C3,
0x118A4 => 0x118C4,
0x118A5 => 0x118C5,
0x118A6 => 0x118C6,
0x118A7 => 0x118C7,
0x118A8 => 0x118C8,
0x118A9 => 0x118C9,
0x118AA => 0x118CA,
0x118AB => 0x118CB,
0x118AC => 0x118CC,
0x118AD => 0x118CD,
0x118AE => 0x118CE,
0x118AF => 0x118CF,
0x118B0 => 0x118D0,
0x118B1 => 0x118D1,
0x118B2 => 0x118D2,
0x118B3 => 0x118D3,
0x118B4 => 0x118D4,
0x118B5 => 0x118D5,
0x118B6 => 0x118D6,
0x118B7 => 0x118D7,
0x118B8 => 0x118D8,
0x118B9 => 0x118D9,
0x118BA => 0x118DA,
0x118BB => 0x118DB,
0x118BC => 0x118DC,
0x118BD => 0x118DD,
0x118BE => 0x118DE,
0x118BF => 0x118DF,
0x16E40 => 0x16E60,
0x16E41 => 0x16E61,
0x16E42 => 0x16E62,
0x16E43 => 0x16E63,
0x16E44 => 0x16E64,
0x16E45 => 0x16E65,
0x16E46 => 0x16E66,
0x16E47 => 0x16E67,
0x16E48 => 0x16E68,
0x16E49 => 0x16E69,
0x16E4A => 0x16E6A,
0x16E4B => 0x16E6B,
0x16E4C => 0x16E6C,
0x16E4D => 0x16E6D,
0x16E4E => 0x16E6E,
0x16E4F => 0x16E6F,
0x16E50 => 0x16E70,
0x16E51 => 0x16E71,
0x16E52 => 0x16E72,
0x16E53 => 0x16E73,
0x16E54 => 0x16E74,
0x16E55 => 0x16E75,
0x16E56 => 0x16E76,
0x16E57 => 0x16E77,
0x16E58 => 0x16E78,
0x16E59 => 0x16E79,
0x16E5A => 0x16E7A,
0x16E5B => 0x16E7B,
0x16E5C => 0x16E7C,
0x16E5D => 0x16E7D,
0x16E5E => 0x16E7E,
0x16E5F => 0x16E7F,
0x1E900 => 0x1E922,
0x1E901 => 0x1E923,
0x1E902 => 0x1E924,
0x1E903 => 0x1E925,
0x1E904 => 0x1E926,
0x1E905 => 0x1E927,
0x1E906 => 0x1E928,
0x1E907 => 0x1E929,
0x1E908 => 0x1E92A,
0x1E909 => 0x1E92B,
0x1E90A => 0x1E92C,
0x1E90B => 0x1E92D,
0x1E90C => 0x1E92E,
0x1E90D => 0x1E92F,
0x1E90E => 0x1E930,
0x1E90F => 0x1E931,
0x1E910 => 0x1E932,
0x1E911 => 0x1E933,
0x1E912 => 0x1E934,
0x1E913 => 0x1E935,
0x1E914 => 0x1E936,
0x1E915 => 0x1E937,
0x1E916 => 0x1E938,
0x1E917 => 0x1E939,
0x1E918 => 0x1E93A,
0x1E919 => 0x1E93B,
0x1E91A => 0x1E93C,
0x1E91B => 0x1E93D,
0x1E91C => 0x1E93E,
0x1E91D => 0x1E93F,
0x1E91E => 0x1E940,
0x1E91F => 0x1E941,
0x1E920 => 0x1E942,
0x1E921 => 0x1E943,
else => cp,
};
} | src/components/autogen/LowerMap.zig |
pub const MAPI_OLE = @as(u32, 1);
pub const MAPI_OLE_STATIC = @as(u32, 2);
pub const MAPI_ORIG = @as(u32, 0);
pub const MAPI_TO = @as(u32, 1);
pub const MAPI_CC = @as(u32, 2);
pub const MAPI_BCC = @as(u32, 3);
pub const MAPI_UNREAD = @as(u32, 1);
pub const MAPI_RECEIPT_REQUESTED = @as(u32, 2);
pub const MAPI_SENT = @as(u32, 4);
pub const MAPI_LOGON_UI = @as(u32, 1);
pub const MAPI_PASSWORD_UI = @as(u32, 131072);
pub const MAPI_NEW_SESSION = @as(u32, 2);
pub const MAPI_FORCE_DOWNLOAD = @as(u32, 4096);
pub const MAPI_EXTENDED = @as(u32, 32);
pub const MAPI_DIALOG = @as(u32, 8);
pub const MAPI_FORCE_UNICODE = @as(u32, 262144);
pub const MAPI_UNREAD_ONLY = @as(u32, 32);
pub const MAPI_GUARANTEE_FIFO = @as(u32, 256);
pub const MAPI_LONG_MSGID = @as(u32, 16384);
pub const MAPI_PEEK = @as(u32, 128);
pub const MAPI_SUPPRESS_ATTACH = @as(u32, 2048);
pub const MAPI_ENVELOPE_ONLY = @as(u32, 64);
pub const MAPI_BODY_AS_FILE = @as(u32, 512);
pub const MAPI_AB_NOMODIFY = @as(u32, 1024);
pub const SUCCESS_SUCCESS = @as(u32, 0);
pub const MAPI_USER_ABORT = @as(u32, 1);
pub const MAPI_E_USER_ABORT = @as(u32, 1);
pub const MAPI_E_FAILURE = @as(u32, 2);
pub const MAPI_E_LOGON_FAILURE = @as(u32, 3);
pub const MAPI_E_LOGIN_FAILURE = @as(u32, 3);
pub const MAPI_E_DISK_FULL = @as(u32, 4);
pub const MAPI_E_INSUFFICIENT_MEMORY = @as(u32, 5);
pub const MAPI_E_ACCESS_DENIED = @as(u32, 6);
pub const MAPI_E_TOO_MANY_SESSIONS = @as(u32, 8);
pub const MAPI_E_TOO_MANY_FILES = @as(u32, 9);
pub const MAPI_E_TOO_MANY_RECIPIENTS = @as(u32, 10);
pub const MAPI_E_ATTACHMENT_NOT_FOUND = @as(u32, 11);
pub const MAPI_E_ATTACHMENT_OPEN_FAILURE = @as(u32, 12);
pub const MAPI_E_ATTACHMENT_WRITE_FAILURE = @as(u32, 13);
pub const MAPI_E_UNKNOWN_RECIPIENT = @as(u32, 14);
pub const MAPI_E_BAD_RECIPTYPE = @as(u32, 15);
pub const MAPI_E_NO_MESSAGES = @as(u32, 16);
pub const MAPI_E_INVALID_MESSAGE = @as(u32, 17);
pub const MAPI_E_TEXT_TOO_LARGE = @as(u32, 18);
pub const MAPI_E_INVALID_SESSION = @as(u32, 19);
pub const MAPI_E_TYPE_NOT_SUPPORTED = @as(u32, 20);
pub const MAPI_E_AMBIGUOUS_RECIPIENT = @as(u32, 21);
pub const MAPI_E_AMBIG_RECIP = @as(u32, 21);
pub const MAPI_E_MESSAGE_IN_USE = @as(u32, 22);
pub const MAPI_E_NETWORK_FAILURE = @as(u32, 23);
pub const MAPI_E_INVALID_EDITFIELDS = @as(u32, 24);
pub const MAPI_E_INVALID_RECIPS = @as(u32, 25);
pub const MAPI_E_NOT_SUPPORTED = @as(u32, 26);
pub const MAPI_E_UNICODE_NOT_SUPPORTED = @as(u32, 27);
pub const MAPI_E_ATTACHMENT_TOO_LARGE = @as(u32, 28);
//--------------------------------------------------------------------------------
// Section: Types (20)
//--------------------------------------------------------------------------------
pub const MapiFileDesc = extern struct {
ulReserved: u32,
flFlags: u32,
nPosition: u32,
lpszPathName: ?PSTR,
lpszFileName: ?PSTR,
lpFileType: ?*anyopaque,
};
pub const MapiFileDescW = extern struct {
ulReserved: u32,
flFlags: u32,
nPosition: u32,
lpszPathName: ?PWSTR,
lpszFileName: ?PWSTR,
lpFileType: ?*anyopaque,
};
pub const MapiFileTagExt = extern struct {
ulReserved: u32,
cbTag: u32,
lpTag: ?*u8,
cbEncoding: u32,
lpEncoding: ?*u8,
};
pub const MapiRecipDesc = extern struct {
ulReserved: u32,
ulRecipClass: u32,
lpszName: ?PSTR,
lpszAddress: ?PSTR,
ulEIDSize: u32,
lpEntryID: ?*anyopaque,
};
pub const MapiRecipDescW = extern struct {
ulReserved: u32,
ulRecipClass: u32,
lpszName: ?PWSTR,
lpszAddress: ?PWSTR,
ulEIDSize: u32,
lpEntryID: ?*anyopaque,
};
pub const MapiMessage = extern struct {
ulReserved: u32,
lpszSubject: ?PSTR,
lpszNoteText: ?PSTR,
lpszMessageType: ?PSTR,
lpszDateReceived: ?PSTR,
lpszConversationID: ?PSTR,
flFlags: u32,
lpOriginator: ?*MapiRecipDesc,
nRecipCount: u32,
lpRecips: ?*MapiRecipDesc,
nFileCount: u32,
lpFiles: ?*MapiFileDesc,
};
pub const MapiMessageW = extern struct {
ulReserved: u32,
lpszSubject: ?PWSTR,
lpszNoteText: ?PWSTR,
lpszMessageType: ?PWSTR,
lpszDateReceived: ?PWSTR,
lpszConversationID: ?PWSTR,
flFlags: u32,
lpOriginator: ?*MapiRecipDescW,
nRecipCount: u32,
lpRecips: ?*MapiRecipDescW,
nFileCount: u32,
lpFiles: ?*MapiFileDescW,
};
pub const LPMAPILOGON = fn(
ulUIParam: usize,
lpszProfileName: ?PSTR,
lpszPassword: ?PSTR,
flFlags: u32,
ulReserved: u32,
lplhSession: ?*usize,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPILOGOFF = fn(
lhSession: usize,
ulUIParam: usize,
flFlags: u32,
ulReserved: u32,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPISENDMAIL = fn(
lhSession: usize,
ulUIParam: usize,
lpMessage: ?*MapiMessage,
flFlags: u32,
ulReserved: u32,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPISENDMAILW = fn(
lhSession: usize,
ulUIParam: usize,
lpMessage: ?*MapiMessageW,
flFlags: u32,
ulReserved: u32,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPISENDDOCUMENTS = fn(
ulUIParam: usize,
lpszDelimChar: ?PSTR,
lpszFilePaths: ?PSTR,
lpszFileNames: ?PSTR,
ulReserved: u32,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPIFINDNEXT = fn(
lhSession: usize,
ulUIParam: usize,
lpszMessageType: ?PSTR,
lpszSeedMessageID: ?PSTR,
flFlags: u32,
ulReserved: u32,
lpszMessageID: ?PSTR,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPIREADMAIL = fn(
lhSession: usize,
ulUIParam: usize,
lpszMessageID: ?PSTR,
flFlags: u32,
ulReserved: u32,
lppMessage: ?*?*MapiMessage,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPISAVEMAIL = fn(
lhSession: usize,
ulUIParam: usize,
lpMessage: ?*MapiMessage,
flFlags: u32,
ulReserved: u32,
lpszMessageID: ?PSTR,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPIDELETEMAIL = fn(
lhSession: usize,
ulUIParam: usize,
lpszMessageID: ?PSTR,
flFlags: u32,
ulReserved: u32,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPIFREEBUFFER = fn(
pv: ?*anyopaque,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPIADDRESS = fn(
lhSession: usize,
ulUIParam: usize,
lpszCaption: ?PSTR,
nEditFields: u32,
lpszLabels: ?PSTR,
nRecips: u32,
lpRecips: ?*MapiRecipDesc,
flFlags: u32,
ulReserved: u32,
lpnNewRecips: ?*u32,
lppNewRecips: ?*?*MapiRecipDesc,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPIDETAILS = fn(
lhSession: usize,
ulUIParam: usize,
lpRecip: ?*MapiRecipDesc,
flFlags: u32,
ulReserved: u32,
) callconv(@import("std").os.windows.WINAPI) u32;
pub const LPMAPIRESOLVENAME = fn(
lhSession: usize,
ulUIParam: usize,
lpszName: ?PSTR,
flFlags: u32,
ulReserved: u32,
lppRecip: ?*?*MapiRecipDesc,
) callconv(@import("std").os.windows.WINAPI) u32;
//--------------------------------------------------------------------------------
// Section: Functions (1)
//--------------------------------------------------------------------------------
pub extern "MAPI32" fn MAPIFreeBuffer(
pv: ?*anyopaque,
) callconv(@import("std").os.windows.WINAPI) u32;
//--------------------------------------------------------------------------------
// Section: Unicode Aliases (0)
//--------------------------------------------------------------------------------
const thismodule = @This();
pub usingnamespace switch (@import("../zig.zig").unicode_mode) {
.ansi => struct {
},
.wide => struct {
},
.unspecified => if (@import("builtin").is_test) struct {
} else struct {
},
};
//--------------------------------------------------------------------------------
// Section: Imports (2)
//--------------------------------------------------------------------------------
const PSTR = @import("../foundation.zig").PSTR;
const PWSTR = @import("../foundation.zig").PWSTR;
test {
// The following '_ = <FuncPtrType>' lines are a workaround for https://github.com/ziglang/zig/issues/4476
if (@hasDecl(@This(), "LPMAPILOGON")) { _ = LPMAPILOGON; }
if (@hasDecl(@This(), "LPMAPILOGOFF")) { _ = LPMAPILOGOFF; }
if (@hasDecl(@This(), "LPMAPISENDMAIL")) { _ = LPMAPISENDMAIL; }
if (@hasDecl(@This(), "LPMAPISENDMAILW")) { _ = LPMAPISENDMAILW; }
if (@hasDecl(@This(), "LPMAPISENDDOCUMENTS")) { _ = LPMAPISENDDOCUMENTS; }
if (@hasDecl(@This(), "LPMAPIFINDNEXT")) { _ = LPMAPIFINDNEXT; }
if (@hasDecl(@This(), "LPMAPIREADMAIL")) { _ = LPMAPIREADMAIL; }
if (@hasDecl(@This(), "LPMAPISAVEMAIL")) { _ = LPMAPISAVEMAIL; }
if (@hasDecl(@This(), "LPMAPIDELETEMAIL")) { _ = LPMAPIDELETEMAIL; }
if (@hasDecl(@This(), "LPMAPIFREEBUFFER")) { _ = LPMAPIFREEBUFFER; }
if (@hasDecl(@This(), "LPMAPIADDRESS")) { _ = LPMAPIADDRESS; }
if (@hasDecl(@This(), "LPMAPIDETAILS")) { _ = LPMAPIDETAILS; }
if (@hasDecl(@This(), "LPMAPIRESOLVENAME")) { _ = LPMAPIRESOLVENAME; }
@setEvalBranchQuota(
@import("std").meta.declarations(@This()).len * 3
);
// reference all the pub declarations
if (!@import("builtin").is_test) return;
inline for (@import("std").meta.declarations(@This())) |decl| {
if (decl.is_pub) {
_ = decl;
}
}
} | win32/system/mapi.zig |
const std = @import("std");
const upaya = @import("upaya_cli.zig");
const Texture = @import("texture.zig").Texture;
const Point = @import("math/point.zig").Point;
/// Image is a CPU side array of color data with some helper methods that can be used to prep data
/// before creating a Texture
pub const Image = struct {
w: usize = 0,
h: usize = 0,
pixels: []u32,
pub fn init(width: usize, height: usize) Image {
return .{ .w = width, .h = height, .pixels = upaya.mem.allocator.alloc(u32, width * height) catch unreachable };
}
pub fn initFromFile(file: []const u8) Image {
const image_contents = upaya.fs.read(upaya.mem.tmp_allocator, file) catch unreachable;
var w: c_int = undefined;
var h: c_int = undefined;
var channels: c_int = undefined;
const load_res = upaya.stb.stbi_load_from_memory(image_contents.ptr, @intCast(c_int, image_contents.len), &w, &h, &channels, 4);
if (load_res == null) unreachable;
defer upaya.stb.stbi_image_free(load_res);
var img = init(@intCast(usize, w), @intCast(usize, h));
var pixels = std.mem.bytesAsSlice(u32, load_res[0..@intCast(usize, w * h * channels)]);
for (pixels) |p, i| {
img.pixels[i] = p;
}
return img;
}
pub fn initFromData(data: [*c]const u8, len: u64) Image {
var w: c_int = undefined;
var h: c_int = undefined;
var channels: c_int = undefined;
const load_res = upaya.stb.stbi_load_from_memory(data, @intCast(c_int, len), &w, &h, &channels, 4);
if (load_res == null) {
std.debug.print("null image!\n", .{});
unreachable;
}
defer upaya.stb.stbi_image_free(load_res);
var img = init(@intCast(usize, w), @intCast(usize, h));
var pixels = std.mem.bytesAsSlice(u32, load_res[0..@intCast(usize, w * h * channels)]);
for (pixels) |p, i| {
img.pixels[i] = p;
}
return img;
}
pub fn deinit(self: Image) void {
upaya.mem.allocator.free(self.pixels);
}
pub fn fillRect(self: *Image, rect: upaya.math.Rect, color: upaya.math.Color) void {
const x = @intCast(usize, rect.x);
var y = @intCast(usize, rect.y);
const w = @intCast(usize, rect.width);
var h = @intCast(usize, rect.height);
var data = self.pixels[x + y * self.w ..];
while (h > 0) : (h -= 1) {
var i: usize = 0;
while (i < w) : (i += 1) {
data[i] = color.value;
}
y += 1;
data = self.pixels[x + y * self.w ..];
}
}
pub fn blit(self: *Image, src: Image, x: usize, y: usize) void {
var yy = y;
var h = src.h;
var data = self.pixels[x + yy * self.w ..];
var src_y: usize = 0;
while (h > 0) : (h -= 1) {
const src_row = src.pixels[src_y * src.w .. (src_y * src.w) + src.w];
std.mem.copy(u32, data, src_row);
// next row and move our slice to it as well
src_y += 1;
yy += 1;
data = self.pixels[x + yy * self.w ..];
}
}
pub fn asTexture(self: Image, filter: Texture.Filter) Texture {
return Texture.initWithColorData(self.pixels, @intCast(i32, self.w), @intCast(i32, self.h), filter, .clamp);
}
pub fn save(self: Image, file: []const u8) void {
var c_file = std.cstr.addNullByte(upaya.mem.tmp_allocator, file) catch unreachable;
var bytes = std.mem.sliceAsBytes(self.pixels);
_ = upaya.stb.stbi_write_png(c_file.ptr, @intCast(c_int, self.w), @intCast(c_int, self.h), 4, bytes.ptr, @intCast(c_int, self.w * 4));
}
/// returns true if the image was loaded successfully
pub fn getTextureSize(file: []const u8, w: *c_int, h: *c_int) bool {
const image_contents = upaya.fs.read(upaya.mem.tmp_allocator, file) catch unreachable;
var comp: c_int = undefined;
if (upaya.stb.stbi_info_from_memory(image_contents.ptr, @intCast(c_int, image_contents.len), w, h, &comp) == 1) {
return true;
}
return false;
}
/// crops image and returns the origin offset of the new image
pub fn crop(self: *Image) Point {
const padding: usize = 1;
var top: usize = 0;
var bottom: usize = self.h;
var x: usize = 0;
var y: usize = 0;
var w = self.w;
var h = self.h;
// find top pixel
topPixelLoop: while (h > 0) : (h -= 1) {
const row = self.pixels[y * w .. (y * w) + w];
for (row) |p| {
if (p & 0xFF000000 != 0) {
// row contains a pixel
break :topPixelLoop;
}
}
y += 1;
top += 1;
}
if (top != 0) {
top -= padding;
//reset h to new h
h = self.h - y;
// pad y
y -= padding;
}
//find bottom pixel
var tempY = self.h - 1;
bottomPixelLoop: while (h > 0) : (h -= 1) {
const row = self.pixels[tempY * w .. (tempY * w) + w];
for (row) |p| {
if (p & 0xFF000000 != 0) {
// row contains a pixel
break :bottomPixelLoop;
}
}
tempY -= 1;
bottom -= 1;
}
if (bottom != self.h) {
h += padding;
}
// create a new image and copy over the vertically cropped pixels
var verticalCroppedImage = Image.init(w, h);
std.mem.copy(u32, verticalCroppedImage.pixels, self.pixels[top * w .. bottom * w]);
//find left pixel
w = verticalCroppedImage.w;
h = verticalCroppedImage.h;
tempY = 0;
var leftPixel: usize = w;
while (h > 0) : (h -= 1) {
// iterate each row and find the one with the
// left most pixel
const row = verticalCroppedImage.pixels[tempY * w .. (tempY * w) + w];
for (row) |p, i| {
if (p & 0xFF000000 != 0) {
if (i < leftPixel)
leftPixel = i;
break;
}
}
tempY += 1;
}
if (leftPixel != 0){
// pad the left pixel
leftPixel -= padding;
}
// x offset is now the leftmost pixel index
x = leftPixel;
// reset height for iteration
h = verticalCroppedImage.h;
var rightPixel: usize = 0;
// find right pixel
tempY = 0;
while (h > 0) : (h -= 1) {
const row = verticalCroppedImage.pixels[tempY * w .. (tempY * w) + w];
var i = row.len - 1;
while (i > 0) : (i -= 1) {
if (row[i] & 0xFF000000 != 0) {
if (i > rightPixel)
rightPixel = i;
break;
}
}
tempY += 1;
}
// pad right pixel
if ( rightPixel != w){
rightPixel += padding;
}
// create final image
h = verticalCroppedImage.h;
w = rightPixel - leftPixel;
var croppedImage = Image.init(w, h);
// copy rows into the final cropped image
tempY = 0;
while (h > 0) : (h -= 1) {
const row = verticalCroppedImage.pixels[tempY * verticalCroppedImage.w .. (tempY * verticalCroppedImage.w) + verticalCroppedImage.w];
const copy = row[leftPixel..rightPixel];
const dest = croppedImage.pixels[tempY * croppedImage.w .. (tempY * croppedImage.w) + croppedImage.w];
std.mem.copy(u32, dest, copy);
tempY += 1;
}
self.w = croppedImage.w;
self.h = croppedImage.h;
// copy pixels into the existing image overwriting
std.mem.copy(u32, self.pixels, croppedImage.pixels);
return .{ .x = @intCast(i32, x), .y = @intCast(i32, y) };
}
}; | src/image.zig |
const std = @import("std");
const analysis = @import("zls/analysis.zig");
const DocumentStore = @import("zls/DocumentStore.zig");
const URI = @import("zls/uri.zig");
const builtins = @import("zls/data/master.zig");
const ast = @import("zls/ast.zig");
const Node = std.zig.Ast.Node;
pub fn getFieldAccessType(
store: *DocumentStore,
arena: *std.heap.ArenaAllocator,
handle: *DocumentStore.Handle,
tokenizer: *std.zig.Tokenizer,
bound_type_params: *analysis.BoundTypeParams,
) !?analysis.DeclWithHandle {
var current_type = analysis.TypeWithHandle.typeVal(.{
.node = 0,
.handle = handle,
});
var result: ?analysis.DeclWithHandle = null;
while (true) {
const tok = tokenizer.next();
switch (tok.tag) {
.eof => return result,
.identifier => {
if (try analysis.lookupSymbolGlobal(
store,
arena,
current_type.handle,
tokenizer.buffer[tok.loc.start..tok.loc.end],
0,
)) |child| {
current_type = (try child.resolveType(store, arena, bound_type_params)) orelse return null;
} else return null;
},
.period => {
const after_period = tokenizer.next();
switch (after_period.tag) {
.eof => return result,
.identifier => {
if (result) |child| {
current_type = (try child.resolveType(store, arena, bound_type_params)) orelse return null;
}
current_type = try analysis.resolveFieldAccessLhsType(store, arena, current_type, bound_type_params);
var current_type_node = switch (current_type.type.data) {
.other => |n| n,
else => return null,
};
var buf: [1]Node.Index = undefined;
if (ast.fnProto(current_type.handle.tree, current_type_node, &buf)) |func| {
// Check if the function has a body and if so, pass it
// so the type can be resolved if it's a generic function returning
// an anonymous struct
const has_body = current_type.handle.tree.nodes.items(.tag)[current_type_node] == .fn_decl;
const body = current_type.handle.tree.nodes.items(.data)[current_type_node].rhs;
if (try analysis.resolveReturnType(
store,
arena,
func,
current_type.handle,
bound_type_params,
if (has_body) body else null,
)) |ret| {
current_type = ret;
current_type_node = switch (current_type.type.data) {
.other => |n| n,
else => return null,
};
} else return null;
}
if (try analysis.lookupSymbolContainer(
store,
arena,
.{ .node = current_type_node, .handle = current_type.handle },
tokenizer.buffer[after_period.loc.start..after_period.loc.end],
true,
)) |child| {
result = child;
} else return null;
},
else => {
return null;
},
}
},
else => {
return null;
},
}
}
return result;
}
const cache_reload_command = ":reload-cached:";
pub const prepare = PrepareResult.init;
pub const PrepareResult = struct {
store: DocumentStore,
root_handle: *DocumentStore.Handle,
lib_uri: []const u8,
var refs: usize = 0;
pub fn init(gpa: *std.mem.Allocator, std_lib_path: []const u8) !PrepareResult {
// This is awful. Upstream needs to get rid of this global reference
if (refs == 0) analysis.init(gpa);
refs += 1;
errdefer refs -= 1;
const resolved_lib_path = try std.fs.path.resolve(gpa, &[_][]const u8{std_lib_path});
defer gpa.free(resolved_lib_path);
std.debug.print("Library path: {s}\n", .{resolved_lib_path});
var result: PrepareResult = undefined;
try result.store.init(gpa, null, "", "", std_lib_path);
errdefer result.store.deinit();
result.lib_uri = try URI.fromPath(gpa, resolved_lib_path);
errdefer gpa.free(result.lib_uri);
result.root_handle = try result.store.openDocument("file://<ROOT>",
\\const std = @import("std");
);
return result;
}
pub fn deinit(self: *PrepareResult) void {
refs -= 1;
if (refs == 0) analysis.deinit();
self.store.allocator.free(self.lib_uri);
self.store.deinit();
}
pub fn reloadCached(self: *PrepareResult, arena: *std.heap.ArenaAllocator) !void {
const gpa = self.store.allocator;
const initial_count = self.store.handles.count();
var reloaded: usize = 0;
var removals = std.ArrayList([]const u8).init(&arena.allocator);
defer removals.deinit();
var it = self.store.handles.iterator();
while (it.next()) |entry| {
if (entry.value_ptr.* == self.root_handle) {
continue;
}
// This was constructed from a path, it will never fail.
const path = URI.parse(&arena.allocator, entry.key_ptr.*) catch |err| switch (err) {
error.OutOfMemory => return err,
else => unreachable,
};
const new_text = std.fs.cwd().readFileAllocOptions(gpa, path, std.math.maxInt(usize), null, @alignOf(u8), 0) catch |err| switch (err) {
error.FileNotFound => {
// self.store
try removals.append(entry.key_ptr.*);
continue;
},
else => |e| return e,
};
// Completely replace the whole text of the document
gpa.free(entry.value_ptr.*.document.mem);
entry.value_ptr.*.document.text = new_text;
entry.value_ptr.*.document.mem = new_text.ptr[0 .. new_text.len + 1];
try self.store.refreshDocument(entry.value_ptr.*);
reloaded += 1;
}
for (removals.items) |rm| {
const entry = self.store.handles.getEntry(rm).?;
entry.value_ptr.*.tree.deinit(gpa);
gpa.free(entry.value_ptr.*.document.mem);
for (entry.value_ptr.*.import_uris) |import_uri| {
self.store.closeDocument(import_uri);
gpa.free(import_uri);
}
gpa.free(entry.value_ptr.*.import_uris);
entry.value_ptr.*.imports_used.deinit(gpa);
entry.value_ptr.*.document_scope.deinit(gpa);
gpa.destroy(entry.value_ptr.*);
const uri_key = entry.key_ptr.*;
std.debug.assert(self.store.handles.remove(rm));
gpa.free(uri_key);
}
std.debug.print("Reloaded {d} of {d} cached documents, removed {d}.\n", .{
reloaded,
initial_count - 1,
removals.items.len,
});
}
pub fn analyse(self: *PrepareResult, arena: *std.heap.ArenaAllocator, line: []const u8) !?[]const u8 {
if (line[0] == '@') {
for (builtins.builtins) |builtin| {
if (std.mem.eql(u8, builtin.name, line)) {
return try std.fmt.allocPrint(&arena.allocator, "https://ziglang.org/documentation/master/#{s}", .{line[1..]});
}
}
return null;
}
var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator);
var tokenizer = std.zig.Tokenizer.init(try arena.allocator.dupeZ(u8, std.mem.trim(u8, line, "\n \t")));
if (try getFieldAccessType(&self.store, arena, self.root_handle, &tokenizer, &bound_type_params)) |result| {
if (result.handle != self.root_handle) {
switch (result.decl.*) {
.ast_node => |n| {
var handle = result.handle;
var node = n;
if (try analysis.resolveVarDeclAlias(
&self.store,
arena,
.{ .node = node, .handle = result.handle },
)) |alias_result| {
switch (alias_result.decl.*) {
.ast_node => |inner| {
handle = alias_result.handle;
node = inner;
},
else => {},
}
} else if (ast.varDecl(result.handle.tree, node)) |vdecl| try_import_resolve: {
if (vdecl.ast.init_node != 0) {
const tree = result.handle.tree;
const node_tags = tree.nodes.items(.tag);
if (ast.isBuiltinCall(tree, vdecl.ast.init_node)) {
const builtin_token = tree.nodes.items(.main_token)[vdecl.ast.init_node];
const call_name = tree.tokenSlice(builtin_token);
if (std.mem.eql(u8, call_name, "@import")) {
const data = tree.nodes.items(.data)[vdecl.ast.init_node];
const params = switch (node_tags[vdecl.ast.init_node]) {
.builtin_call, .builtin_call_comma => tree.extra_data[data.lhs..data.rhs],
.builtin_call_two, .builtin_call_two_comma => if (data.lhs == 0)
&[_]Node.Index{}
else if (data.rhs == 0)
&[_]Node.Index{data.lhs}
else
&[_]Node.Index{ data.lhs, data.rhs },
else => unreachable,
};
if (params.len == 1) {
const import_type = (try result.resolveType(
&self.store,
arena,
&bound_type_params,
)) orelse break :try_import_resolve;
switch (import_type.type.data) {
.other => |resolved_node| {
handle = import_type.handle;
node = resolved_node;
},
else => {},
}
}
}
}
}
}
const start_tok = if (analysis.getDocCommentTokenIndex(handle.tree.tokens.items(.tag), node)) |doc_comment|
doc_comment
else
handle.tree.firstToken(node);
const result_uri = handle.uri()[self.lib_uri.len..];
const start_loc = handle.tree.tokenLocation(0, start_tok);
const end_loc = handle.tree.tokenLocation(0, handle.tree.lastToken(node));
return try std.fmt.allocPrint(&arena.allocator, "https://github.com/ziglang/zig/blob/master/lib{s}#L{d}-L{d}\n", .{ result_uri, start_loc.line + 1, end_loc.line + 1 });
},
else => {},
}
}
}
return null;
}
};
fn getTestZiglib() ![]const u8 {
const static = struct {
var test_ziglib = std.BoundedArray(u8, 0x1000).init(0) catch unreachable;
};
if (static.test_ziglib.len == 0) {
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const result = try std.ChildProcess.exec(.{
.allocator = &arena.allocator,
.argv = &.{ std.testing.zig_exe_path, "env" },
});
var parser = std.json.Parser.init(&arena.allocator, false);
const tree = try parser.parse(result.stdout);
try static.test_ziglib.appendSlice(tree.root.Object.get("lib_dir").?.String);
}
return static.test_ziglib.constSlice();
}
fn expectStartWith(expected: []const u8, actual: []const u8) !void {
const compare = if (actual.len > expected.len) actual[0..expected.len] else actual;
try std.testing.expectEqualStrings(expected, compare);
}
test "reloadCached" {
var prep_result = try prepare(std.testing.allocator, try getTestZiglib());
defer prep_result.deinit();
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
try prep_result.reloadCached(&arena);
}
test "lookup 'std.os'" {
var prep_result = try prepare(std.testing.allocator, try getTestZiglib());
defer prep_result.deinit();
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
if (try prep_result.analyse(&arena, "std.os")) |result| {
try expectStartWith("https://github.com/ziglang/zig/blob/master/lib/std/os.zig#", result);
} else {
return error.TestUnexpectedNull;
}
}
test "lookup '@import'" {
var prep_result = try prepare(std.testing.allocator, try getTestZiglib());
defer prep_result.deinit();
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
if (try prep_result.analyse(&arena, "@import")) |result| {
try expectStartWith("https://ziglang.org/documentation/master/#import", result);
} else {
return error.TestUnexpectedNull;
}
}
pub fn main() anyerror!void {
const gpa = std.heap.page_allocator;
const reader = std.io.getStdIn().reader();
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
var args = std.process.args();
_ = args.skip();
const lib_path = try args.next(gpa) orelse return error.NoLibPathProvided;
defer gpa.free(lib_path);
var prepared = try prepare(gpa, lib_path);
defer prepared.deinit();
var timer = try std.time.Timer.start();
while (true) {
defer {
arena.deinit();
arena.state.buffer_list = .{};
}
const line = reader.readUntilDelimiterAlloc(gpa, '\n', std.math.maxInt(usize)) catch |e| switch (e) {
error.EndOfStream => break,
else => return e,
};
defer gpa.free(line);
timer.reset();
defer {
std.debug.print("Took {} ns to complete request.\n", .{timer.lap()});
}
const trimmed_line = std.mem.trim(u8, line, "\n \t\r");
if (trimmed_line.len == cache_reload_command.len and std.mem.eql(u8, trimmed_line, cache_reload_command)) {
try prepared.reloadCached(&arena);
continue;
}
if (try prepared.analyse(&arena, trimmed_line)) |match| {
try std.io.getStdOut().writeAll("Match: ");
try std.io.getStdOut().writeAll(match);
try std.io.getStdOut().writer().writeByte('\n');
} else {
try std.io.getStdOut().writeAll("No match found.\n");
}
}
} | src/main.zig |
const std = @import("std");
const helper = @import("helper.zig");
const Allocator = std.mem.Allocator;
const StringHashMap = std.StringHashMap;
const HashMap = std.AutoHashMap;
const input = @embedFile("../inputs/day12.txt");
pub fn run(alloc: Allocator, stdout_: anytype) !void {
const graph = try CaveGraph.init(alloc, input);
defer graph.deinit();
var visited = try alloc.alloc(u8, graph.node_num);
defer alloc.free(visited);
const res1 = try graph.countPathsNoRevisitSmall(visited);
const res2 = res1 + try graph.countPathsWithRevisitSmall(visited);
if (stdout_) |stdout| {
try stdout.print("Part 1: {}\n", .{res1});
try stdout.print("Part 2: {}\n", .{res2});
}
}
const CaveGraph = struct {
neighbors: []const []const usize,
neighbor_buffer: []const usize,
big: []const bool,
node_num: usize,
start: usize,
end: usize,
allocator: Allocator,
const Self = @This();
pub fn init(alloc: Allocator, str: []const u8) !Self {
var nodes = StringHashMap(usize).init(alloc);
defer nodes.deinit();
try Self.populateNodesMap(str, &nodes);
const node_num = @intCast(usize, nodes.count());
var adjmat = try alloc.alloc(bool, node_num * node_num);
defer alloc.free(adjmat);
std.mem.set(bool, adjmat, false);
Self.populateAdj(str, adjmat, nodes, node_num);
var big = try alloc.alloc(bool, node_num);
Self.populateBig(big, nodes);
var neighbor_buffer: []usize = undefined;
var neighbors: [][]usize = try alloc.alloc([]usize, node_num);
try Self.populateNeighbors(alloc, adjmat, neighbors, &neighbor_buffer, node_num);
return Self{
.neighbors = neighbors,
.neighbor_buffer = neighbor_buffer,
.big = big,
.node_num = node_num,
.allocator = alloc,
.start = nodes.get("start").?,
.end = nodes.get("end").?,
};
}
fn populateNeighbors(
alloc: Allocator,
adjmat: []const bool,
neighbors: [][]usize,
neighbor_buffer: *[]usize,
node_num: usize,
) !void {
var neighbor_num: usize = 0;
for (adjmat) |val| {
neighbor_num += @intCast(usize, @boolToInt(val));
}
neighbor_buffer.* = try alloc.alloc(usize, neighbor_num);
var start: usize = 0;
var end: usize = 0;
var node: usize = 0;
while (node < node_num) : (node += 1) {
start = end;
var other: usize = 0;
while (other < node_num) : (other += 1) {
if (adjmat[node * node_num + other]) {
neighbor_buffer.*[end] = other;
end += 1;
}
}
neighbors[node] = neighbor_buffer.*[start..end];
}
}
pub fn countPathsNoRevisitSmall(self: *const Self, visited: []u8) !i32 {
std.mem.set(u8, visited, 0);
return self.countPathsInner(self.start, visited, null);
}
pub fn countPathsWithRevisitSmall(self: *const Self, visited: []u8) !i32 {
std.mem.set(u8, visited, 0);
var sum: i32 = 0;
var node: usize = 0;
while (node < self.node_num) : (node += 1) {
if (self.big[node]) continue;
if (node == self.start or node == self.end) continue;
sum += try self.countPathsInner(self.start, visited, node);
}
return sum;
}
pub fn deinit(self: Self) void {
self.allocator.free(self.neighbors);
self.allocator.free(self.neighbor_buffer);
self.allocator.free(self.big);
}
fn countPathsInner(
self: *const Self,
node: usize,
visited: []u8,
may_visit_twice: ?usize,
) Allocator.Error!i32 {
if (node == self.end) {
if (may_visit_twice) |visitor| {
if (visited[visitor] != 2) return 0;
}
return 1;
}
if (!self.big[node]) visited[node] += 1;
defer if (!self.big[node]) {
visited[node] -= 1;
};
var sum: i32 = 0;
for (self.neighbors[node]) |other| {
blk: {
if (visited[other] != 0) {
if (other == may_visit_twice) {
if (visited[other] < 2) break :blk;
}
continue;
}
}
sum += try self.countPathsInner(other, visited, may_visit_twice);
}
return sum;
}
fn populateNodesMap(str: []const u8, nodes: *StringHashMap(usize)) !void {
var lines = tokenize(u8, str, "\r\n");
var counter: usize = 0;
while (lines.next()) |line| {
var splut = split(u8, line, "-");
while (splut.next()) |node_name| {
if (!nodes.contains(node_name)) {
try nodes.put(node_name, counter);
counter += 1;
}
}
}
}
fn populateAdj(str: []const u8, adjmat: []bool, nodes: StringHashMap(usize), node_num: usize) void {
var lines = tokenize(u8, str, "\r\n");
while (lines.next()) |line| {
var splut = split(u8, line, "-");
const fst = splut.next().?;
const snd = splut.next().?;
const i = nodes.get(fst).?;
const j = nodes.get(snd).?;
adjmat[i * node_num + j] = true;
adjmat[j * node_num + i] = true;
}
}
fn populateBig(big: []bool, nodes: StringHashMap(usize)) void {
var iter = nodes.iterator();
while (iter.next()) |entry| {
const i = entry.value_ptr.*;
big[i] = std.ascii.isUpper(entry.key_ptr.*[0]);
}
}
};
const eql = std.mem.eql;
const tokenize = std.mem.tokenize;
const split = std.mem.split;
const count = std.mem.count;
const parseUnsigned = std.fmt.parseUnsigned;
const parseInt = std.fmt.parseInt;
const sort = std.sort.sort; | src/day12.zig |
const std = @import("std");
const panic = std.debug.panic;
const allocator = std.heap.page_allocator;
const utils = @import("utils.zig");
const puts_e = utils.puts_e;
const putskv_e = utils.putskv_e;
pub const NodeKind = enum {
INT,
STR,
LIST,
};
pub const Node = struct {
kind: NodeKind,
int: ?i32,
str: [64]u8,
list: ?*List,
const Self = @This();
pub fn init() *Self {
var obj = allocator.create(Self) catch |err| {
panic("Failed to allocate", .{});
};
obj.int = undefined;
obj.str[0] = 0;
return obj;
}
pub fn initInt(n: i32) *Self {
const node = Self.init();
node.kind = NodeKind.INT;
node.int = n;
return node;
}
pub fn initStr(str: []const u8) *Self {
const node = Self.init();
node.kind = NodeKind.STR;
utils.strcpy(&node.str, str);
return node;
}
pub fn initList(list: *List) *Self {
const node = Self.init();
node.kind = NodeKind.LIST;
node.list = list;
return node;
}
pub fn getInt(self: *Self) i32 {
if (self.kind != NodeKind.INT) {
panic("Invalid node kind", .{});
}
if (self.int) |int| {
return int;
} else {
panic("err", .{});
}
}
pub fn getStr(self: *Self) []const u8 {
if (self.kind != NodeKind.STR) {
panic("Invalid node kind", .{});
}
const len = utils.strlen(&self.str);
return self.str[0..len];
}
pub fn getList(self: *Self) *List {
if (self.kind != NodeKind.LIST) {
panic("Invalid node kind", .{});
}
if (self.list) |_list| {
return _list;
}
panic("must not happen", .{});
}
pub fn kindEq(self: *Self, kind: NodeKind) bool {
return self.kind == kind;
}
};
pub const List = struct {
nodes: [64]*Node,
len: usize,
const Self = @This();
pub fn init() *Self {
var obj = allocator.create(List) catch |err| {
panic("Failed to allocate ({})", .{err});
};
obj.len = 0;
return obj;
}
pub fn empty() *Self {
return Self.init();
}
pub fn size(self: *Self) usize {
return self.len;
}
pub fn add(self: *Self, node: *Node) void {
self.nodes[self.len] = node;
self.len += 1;
}
pub fn addInt(self: *Self, n: i32) void {
const node = Node.initInt(n);
self.add(node);
}
pub fn addStr(self: *Self, str: []const u8) void {
const node = Node.initStr(str);
self.add(node);
}
pub fn addList(self: *Self, list: *List) void {
const node = Node.initList(list);
self.add(node);
}
pub fn addListAll(self: *Self, list: *List) void {
var i: usize = 0;
while (i < list.len) : (i += 1) {
self.add(list.get(i));
}
}
pub fn get(self: *Self, index: usize) *Node {
return self.nodes[index];
}
};
// --------------------------------
const Name = struct {
str: [16]u8,
const Self = @This();
pub fn init() *Self {
var obj = allocator.create(Self) catch |err| {
panic("Failed to allocate", .{});
};
return obj;
}
pub fn initWithStr(str: []const u8) *Self {
var obj = Name.init();
utils.strcpy(&obj.str, str);
return obj;
}
pub fn getStr(self: *Self) []const u8 {
const len = utils.strlen(self.str[0..]);
return self.str[0..len];
}
};
pub const Names = struct {
strs: [8]*Name = []*Name{undefined},
len: usize,
const Self = @This();
pub fn init() *Self {
var obj = allocator.create(Self) catch |err| {
panic("Failed to allocate", .{});
};
obj.len = 0;
return obj;
}
pub fn empty() *Self {
return Self.init();
}
pub fn get(self: *Self, i: usize) *Name {
return self.strs[i];
}
pub fn add(self: *Self, str: []const u8) void {
const name: *Name = Name.initWithStr(str);
self.strs[self.len] = name;
self.len += 1;
}
pub fn indexOf(self: *Self, str: []const u8) i32 {
var i: usize = 0;
while (i < self.len) : (i += 1) {
if (utils.strEq(self.get(i).getStr(), str)) {
return @intCast(i32, i);
}
}
return -1;
}
}; | lib/types.zig |
const std = @import("std");
const tools = @import("tools");
const with_trace = true;
const assert = std.debug.assert;
fn trace(comptime fmt: []const u8, args: anytype) void {
if (with_trace) std.debug.print(fmt, args);
}
pub fn main() anyerror!void {
const stdout = std.io.getStdOut().writer();
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
const limit = 1 * 1024 * 1024 * 1024;
const text = try std.fs.cwd().readFileAlloc(allocator, "day13.txt", limit);
defer allocator.free(text);
var scanners = [1]u32{0} ** 100;
var it = std.mem.split(u8, text, "\n");
while (it.next()) |line0| {
const line = std.mem.trim(u8, line0, " \n\t\r");
if (line.len == 0) continue;
var it2 = std.mem.tokenize(u8, line, ": \t");
const layer = std.fmt.parseInt(u32, it2.next() orelse unreachable, 10) catch unreachable;
const range = std.fmt.parseInt(u32, it2.next() orelse unreachable, 10) catch unreachable;
assert(scanners[layer] == 0);
scanners[layer] = range;
}
var severity: u64 = 0;
for (scanners) |range, depth| {
const t = depth;
if (false and with_trace) {
trace("t={} ------------\n", .{t});
for (scanners) |r2, d2| {
if (r2 == 0) continue;
const step = t % ((r2 - 1) * 2);
const cur = if (step >= r2) ((r2 - 1) * 2) - step else step;
trace("scanner n°{} at {}\n", .{ d2, cur });
}
}
if (range == 0)
continue;
const step = t % ((range - 1) * 2);
const cur = if (step >= range) ((range - 1) * 2) - step else step;
if (cur == 0) {
trace("hit: {},{},{}\n", .{ t, depth, range });
severity += range * depth;
}
}
try stdout.print("severity={}\n", .{severity});
var delay: u32 = 0;
const min_delay = outer: while (true) : (delay += 1) {
for (scanners) |range, depth| {
const t = delay + depth;
if (range == 0)
continue;
const step = t % ((range - 1) * 2);
const cur = if (step >= range) ((range - 1) * 2) - step else step;
if (cur == 0) {
// detected.
continue :outer;
}
} else {
// not detected
break :outer delay;
}
} else {
unreachable;
};
try stdout.print("mindelay={}\n", .{min_delay});
} | 2017/day13.zig |
const std = @import("std");
const tools = @import("tools");
const with_trace = true;
const assert = std.debug.assert;
fn trace(comptime fmt: []const u8, args: anytype) void {
if (with_trace) std.debug.print(fmt, args);
}
const Arg = union(enum) {
reg: u2,
imm: i32,
};
pub fn match_insn(comptime pattern: []const u8, text: []const u8) ?[2]Arg {
if (tools.match_pattern(pattern, text)) |vals| {
var count: usize = 0;
var values: [2]Arg = undefined;
for (values) |*v, i| {
switch (vals[i]) {
.imm => |imm| v.* = .{ .imm = imm },
.name => |name| v.* = .{ .reg = @intCast(u2, name[0] - 'a') },
}
}
return values;
}
return null;
}
pub fn main() anyerror!void {
const stdout = std.io.getStdOut().writer();
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
const limit = 1 * 1024 * 1024 * 1024;
const text = try std.fs.cwd().readFileAlloc(allocator, "day12.txt", limit);
defer allocator.free(text);
const Opcode = enum {
cpy,
add,
jnz,
};
const Insn = struct {
opcode: Opcode,
arg: [2]Arg,
};
var program: [500]Insn = undefined;
var program_len: usize = 0;
var it = std.mem.tokenize(u8, text, "\n");
while (it.next()) |line| {
if (match_insn("cpy {} {}", line)) |vals| {
trace("cpy {} {}\n", .{ vals[0], vals[1] });
program[program_len].opcode = .cpy;
program[program_len].arg[0] = vals[0];
program[program_len].arg[1] = vals[1];
program_len += 1;
} else if (match_insn("inc {}", line)) |vals| {
trace("inc {}\n", .{vals[0]});
program[program_len].opcode = .add;
program[program_len].arg[0] = Arg{ .imm = 1 };
program[program_len].arg[1] = vals[0];
program_len += 1;
} else if (match_insn("dec {}", line)) |vals| {
trace("dec {}\n", .{vals[0]});
program[program_len].opcode = .add;
program[program_len].arg[0] = Arg{ .imm = -1 };
program[program_len].arg[1] = vals[0];
program_len += 1;
} else if (match_insn("jnz {} {}", line)) |vals| {
trace("jnz {} {}\n", .{ vals[0], vals[1] });
program[program_len].opcode = .jnz;
program[program_len].arg[0] = vals[0];
program[program_len].arg[1] = vals[1];
program_len += 1;
} else {
trace("skipping {}\n", .{line});
}
}
const Computer = struct {
pc: usize,
regs: [4]i32,
};
var c = Computer{ .pc = 0, .regs = [_]i32{ 0, 0, 1, 0 } };
while (c.pc < program_len) {
const insn = &program[c.pc];
switch (insn.opcode) {
.cpy => {
c.regs[insn.arg[1].reg] = switch (insn.arg[0]) {
.imm => |imm| imm,
.reg => |reg| c.regs[reg],
};
c.pc += 1;
},
.add => {
c.regs[insn.arg[1].reg] += switch (insn.arg[0]) {
.imm => |imm| imm,
.reg => |reg| c.regs[reg],
};
c.pc += 1;
},
.jnz => {
const val = switch (insn.arg[0]) {
.imm => |imm| imm,
.reg => |reg| c.regs[reg],
};
if (val != 0) {
c.pc = @intCast(usize, @intCast(i32, c.pc) + insn.arg[1].imm);
} else {
c.pc += 1;
}
},
}
}
try stdout.print("a = {}\n", .{c.regs[0]});
} | 2016/day12.zig |
const std = @import("std");
pub const GameOffscreenBuffer = struct {
memory: *?[:0]c_uint,
width: i32,
height: i32,
pitch: usize,
};
pub const GameSoundOutputBuffer = struct {
samples: *[]i16,
samplesPerSecond: u32,
sampleCount: i32,
};
pub const GameButtonState = struct {
halfTransitionCounter: u32,
endedDown: bool,
};
pub const GameButtons = struct {
up: GameButtonState,
down: GameButtonState,
left: GameButtonState,
right: GameButtonState,
leftShoulder: GameButtonState,
rightShoulder: GameButtonState,
};
pub const GameControllerInput = struct {
isAnalog: bool,
startX: f32,
startY: f32,
minX: f32,
minY: f32,
maxX: f32,
maxY: f32,
endX: f32,
endY: f32,
buttons: GameButtons,
};
pub const GameInput = struct {
controllers: [4]GameControllerInput,
};
fn GameOutputSound(soundBuffer: *GameSoundOutputBuffer, toneHz: u32) void {
const S = struct {
var tSine: f32 = 0;
};
const toneVolume: f32 = 2000;
const wavePeriod: f32 = @intToFloat(f32, soundBuffer.samplesPerSecond / toneHz);
var byteIndex: usize = 0;
var sampleIndex: u32 = 0;
while (sampleIndex < soundBuffer.sampleCount) : (sampleIndex += 1) {
const sineValue: f32 = @sin(S.tSine);
const sampleValue: i16 = @floatToInt(i16, sineValue * toneVolume);
soundBuffer.samples.*[byteIndex] = sampleValue;
byteIndex += 1;
soundBuffer.samples.*[byteIndex] = sampleValue;
byteIndex += 1;
S.tSine += 2 * std.math.pi / wavePeriod;
}
}
fn RenderWeirdGradient(buffer: *GameOffscreenBuffer, xOffset: i32, yOffset: i32) void {
var row: usize = 0;
var y: i32 = 0;
while (y < buffer.height) : (y += 1) {
var pixel: usize = row;
var x: i32 = 0;
while (x < buffer.width) : (x += 1) {
var blue: u8 = @bitCast(u8, @truncate(i8, x + xOffset));
var green: u8 = @bitCast(u8, @truncate(i8, y + yOffset));
buffer.memory.*.?[pixel] = (@intCast(c_uint, green) << 8) | blue;
pixel += 1;
}
row += buffer.pitch;
}
}
pub fn GameUpdateAndRender(input: *GameInput, buffer: *GameOffscreenBuffer, soundBuffer: *GameSoundOutputBuffer) void {
const S = struct {
var toneHz: u32 = 256; // Approximation to 261.62 Hz which is middle C
var blueOffset: i32 = 0;
var greenOffset: i32 = 0;
};
var controller0 = input.controllers[0];
if (controller0.buttons.up.endedDown) {
S.greenOffset += 1;
}
if (controller0.isAnalog) {
S.blueOffset += @floatToInt(i32, 4 * controller0.endX);
S.toneHz = @intCast(u32, 256 + @floatToInt(i32, 128 * controller0.endY));
}
// TODO: Allow sample offsets for more robust platform options
GameOutputSound(soundBuffer, S.toneHz);
RenderWeirdGradient(buffer, S.blueOffset, S.greenOffset);
} | src/handmade.zig |
const std = @import("std");
const zen = std.os.zen;
const Message = zen.Message;
const Terminal = zen.Server.Terminal;
// Color codes.
const Color = enum(u4) {
Black = 0,
Blue = 1,
Green = 2,
Cyan = 3,
Red = 4,
Magenta = 5,
Brown = 6,
LightGrey = 7,
DarkGrey = 8,
LightBlue = 9,
LightGreen = 10,
LightCyan = 11,
LightRed = 12,
LightMagenta = 13,
LightBrown = 14,
White = 15,
};
// Character with attributes.
const VGAEntry = packed struct {
char: u8,
foreground: Color,
background: Color,
};
// Screen size.
const VGA_WIDTH = 80;
const VGA_HEIGHT = 25;
// VRAM buffer.
const v_addr = 0x20000000; // TODO: don't hardcode.
const p_addr = 0xB8000;
const size = 0x8000;
const vram = @intToPtr(&VGAEntry, v_addr)[0..(size / @sizeOf(VGAEntry))];
var background = Color.Black; // Background color.
var foreground = Color.LightGrey; // Foreground color.
var cursor = usize(VGA_WIDTH * 16); // Cursor position.
////
// Clear the screen.
//
fn clear() void {
cursor = 0;
while (cursor < VGA_HEIGHT * VGA_WIDTH)
writeChar(' ');
cursor = 0;
}
////
// Scroll the screen one line down.
//
fn scrollDown() void {
// FIXME: express in native Zig.
const vram_raw = @ptrCast(&u8, vram.ptr);
const line_size = VGA_WIDTH * @sizeOf(VGAEntry);
const screen_size = VGA_WIDTH * VGA_HEIGHT * @sizeOf(VGAEntry);
@memcpy(&vram_raw[0], &vram_raw[line_size], screen_size - line_size);
cursor -= VGA_WIDTH;
writeChar('\n');
cursor -= VGA_WIDTH;
}
////
// Print a character to the screen.
//
// Arguments:
// char: Char to be printed.
//
fn writeChar(char: u8) void {
if (cursor == VGA_WIDTH * VGA_HEIGHT) {
scrollDown();
}
switch (char) {
// Newline:
'\n' => {
writeChar(' ');
while (cursor % VGA_WIDTH != 0)
writeChar(' ');
},
// Tab:
'\t' => {
writeChar(' ');
while (cursor % 4 != 0)
writeChar(' ');
},
// Backspace:
// FIXME: hardcoded 8 here is horrible.
8 => {
cursor -= 1;
writeChar(' ');
cursor -= 1;
},
// Any other character:
else => {
vram[cursor] = VGAEntry { .char = char,
.background = background,
.foreground = foreground, };
cursor += 1;
},
}
}
////
// Entry point.
//
pub fn main() void {
zen.createPort(Terminal);
_ = zen.map(v_addr, p_addr, size, true);
while (true) {
var message = Message.from(Terminal);
zen.receive(&message);
switch (message.type) {
0 => clear(),
1 => writeChar(u8(message.payload)),
else => unreachable,
}
}
} | servers/terminal/main.zig |
const std = @import("std");
const math = std.math;
const meta = std.meta;
const fs = std.fs;
const os = std.os;
const assert = std.debug.assert;
const trait = meta.trait;
pub const TextAttributes = struct {
pub const Color = enum {
black,
red,
green,
yellow,
blue,
magenta,
cyan,
white,
};
foreground: Color = .white,
bright: bool = false,
bold: bool = false,
underline: bool = false,
reverse: bool = false,
};
pub const TerminalSize = struct {
width: u16,
height: u16,
};
pub fn FormatType(comptime fmt: []const u8, comptime Tuple: type) type {
assert(trait.isTuple(Tuple));
return struct {
comptime format: []const u8 = fmt,
args: Tuple,
};
}
fn isFormat(comptime T: type) bool {
return trait.is(.Struct)(T) and trait.hasFields(T, .{ "format", "args" });
}
pub fn format(comptime fmt: []const u8, args: anytype) FormatType(fmt, @TypeOf(args)) {
return FormatType(fmt, @TypeOf(args)){
.format = fmt,
.args = args,
};
}
const is_windows = std.Target.current.os.tag == .windows;
pub const Terminal = struct {
pub const WinInterface = enum {
ansi,
winconsole,
};
pub const OtherInterface = enum {
ansi,
};
pub const Interface = if (is_windows) WinInterface else OtherInterface;
stdin: fs.File,
stdout: fs.File,
interface: Interface,
enable_attributes: bool = true,
current_attribute: TextAttributes = TextAttributes{},
window_size: TerminalSize,
pub fn init() Terminal {
const stdin = std.io.getStdIn();
const stdout = std.io.getStdOut();
var interface: Interface = .ansi;
if (is_windows) {
if (!std.os.isCygwinPty(stdin.handle) and !windows.tryPromoteVirtual(stdin, stdout)) {
interface = .winconsole;
}
}
return .{
.stdin = stdin,
.stdout = stdout,
.interface = interface,
.enable_attributes = stdout.supportsAnsiEscapeCodes(),
};
}
pub fn enableAttributes(self: *Terminal) void {
self.enable_attributes = true;
}
pub fn disableAttributes(self: *Terminal) void {
self.enable_attributes = false;
}
pub fn applyAttribute(self: *Terminal, attr: TextAttributes) !void {
self.current_attribute = attr;
if (!self.enable_attributes) return;
if (is_windows and self.interface == .winconsole) return try windows.applyAttribute(self, attr);
return try ansi.applyAttribute(self, attr);
}
pub fn resetAttributes(self: *Terminal) !void {
self.current_attribute = .{};
if (!self.enable_attributes) return;
if (is_windows and self.interface == .winconsole) return try windows.resetAttributes(self);
return try ansi.resetAttributes(self);
}
pub fn switchToAltBuffer(self: *Terminal) !void {
if (is_windows and self.interface == .winconsole) return try windows.switchToAltBuffer(self);
return try ansi.switchToAltBuffer(self);
}
pub fn switchToMainBuffer(self: *Terminal) !void {
if (is_windows and self.interface == .winconsole) return try windows.switchToMainBuffer(self);
return try ansi.switchToMainBuffer(self);
}
pub fn cursorMoveUp(self: *Terminal, num: u16) !void {
if (is_windows and self.interface == .winconsole) return try windows.cursorMoveUp(self, num);
return try ansi.cursorMoveUp(self, num);
}
pub fn cursorMoveDown(self: *Terminal, num: u16) !void {
if (is_windows and self.interface == .winconsole) return try windows.cursorMoveDown(self, num);
return try ansi.cursorMoveDown(self, num);
}
pub fn cursorMoveRight(self: *Terminal, num: u16) !void {
if (is_windows and self.interface == .winconsole) return try windows.cursorMoveRight(self, num);
return try ansi.cursorMoveRight(self, num);
}
pub fn cursorMoveLeft(self: *Terminal, num: u16) !void {
if (is_windows and self.interface == .winconsole) return try windows.cursorMoveLeft(self, num);
return try ansi.cursorMoveLeft(self, num);
}
pub fn setCursorColumn(self: *Terminal, col: u16) !void {
if (is_windows and self.interface == .winconsole) return try windows.setCursorColumn(self, col);
return try ansi.setCursorColumn(self, col);
}
pub fn setCursorRow(self: *Terminal, row: u16) !void {
if (is_windows and self.interface == .winconsole) return try windows.setCursorRow(self, row);
return try ansi.setCursorRow(self, row);
}
pub fn setCursorPosition(self: *Terminal, x: u16, y: u16) !void {
if (is_windows and self.interface == .winconsole) return try windows.setCursorPosition(self, x, y);
return try ansi.setCursorPosition(self, x, y);
}
pub fn getTerminalSize(self: *Terminal) !TerminalSize {
if (is_windows) return try windows.getTerminalSize(self);
return try ioctl.getTerminalSize(self);
}
pub fn printWithAttributes(self: *Terminal, args: anytype) !void {
comptime var i = 0;
inline while (i < args.len) : (i += 1) {
const arg = args[i];
const T = @TypeOf(arg);
const info = @typeInfo(T);
switch (T) {
TextAttributes => {
try self.applyAttribute(arg);
continue;
},
TextAttributes.Color => {
try self.applyAttribute(.{ .foreground = arg });
continue;
},
else => {
if (comptime trait.isZigString(T)) {
try self.stdout.writeAll(arg);
continue;
}
switch (info) {
.EnumLiteral => {
if (arg == .reset) {
try self.resetAttributes();
} else {
try self.applyAttribute(.{ .foreground = arg });
}
continue;
},
.Struct => {
if (comptime trait.isTuple(T) and arg.len == 2 and trait.isZigString(@TypeOf(arg[0])) and trait.isTuple(@TypeOf(arg[1]))) {
try self.writer().print(arg[0], arg[1]);
continue;
}
if (comptime isFormat(T)) {
try self.writer().print(arg.format, arg.args);
continue;
}
var attr = TextAttributes{};
const fields = meta.fields(T);
inline for (fields) |field| {
if (!@hasField(TextAttributes, field.name)) @compileError("Could not cast anonymous struct to TextAttributes, found extraneous field " ++ field.name);
@field(attr, field.name) = @field(arg, field.name);
}
try self.applyAttribute(attr);
continue;
},
else => {},
}
},
}
@compileError("Expected a string, tuple, enum literal or TextAttribute, found " ++ @typeName(T));
}
}
pub fn reader(self: Terminal) fs.File.Reader {
return self.stdin.reader();
}
pub fn writer(self: Terminal) fs.File.Writer {
return self.stdout.writer();
}
};
pub const windows = struct {
const win = std.os.windows;
const HANDLE = win.HANDLE;
const WINAPI = win.WINAPI;
extern "kernel32" fn GetConsoleMode(hConsole: HANDLE, mode: *u16) callconv(WINAPI) c_int;
extern "kernel32" fn SetConsoleMode(hConsole: HANDLE, mode: u16) callconv(WINAPI) c_int;
extern "kernel32" fn GetConsoleScreenBufferInfo(hConsole: HANDLE, consoleScreenBufferInfo: *win.CONSOLE_SCREEN_BUFFER_INFO) callconv(WINAPI) c_int;
extern "kernel32" fn SetConsoleTextAttribute(hConsole: HANDLE, attributes: u16) callconv(WINAPI) c_int;
extern "kernel32" fn SetConsoleCursorPosition(hConsole: HANDLE, cursorPosition: win.COORD) callconv(WINAPI) c_int;
var last_attribute: u16 = 0;
const FG_RED = win.FOREGROUND_RED;
const FG_GREEN = win.FOREGROUND_GREEN;
const FG_BLUE = win.FOREGROUND_BLUE;
const FG_INTENSE = win.FOREGROUND_INTENSITY;
const TXT_REVERSE = 0x4000;
const TXT_UNDERSCORE = 0x8000;
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
const ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;
const DISABLE_NEWLINE_AUTO_RETURN = 0x0008;
const stdout_mode_request = ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
const stdin_mode_request = ENABLE_VIRTUAL_TERMINAL_INPUT;
fn tryPromoteVirtual(stdin: std.fs.File, stdout: std.fs.File) bool {
var stdout_mode: u16 = 0;
var stdin_mode: u16 = 0;
if (GetConsoleMode(stdout.handle, &stdout_mode) == 0) return false;
if (GetConsoleMode(stdin.handle, &stdin_mode) == 0) return false;
if (stdout_mode & stdout_mode_request == stdout_mode_request and stdin_mode & stdin_mode_request == stdin_mode_request) return true;
const new_stdout_mode = stdout_mode | stdout_mode_request;
const new_stdin_mode = stdin_mode | stdin_mode_request;
if (SetConsoleMode(stdout.handle, new_stdout_mode) == 0) return false;
if (SetConsoleMode(stdin.handle, new_stdin_mode) == 0) return false;
return true;
}
fn attrToWord(attr: TextAttributes) u16 {
var base = if (attr.bright or attr.bold) FG_INTENSE else 0;
if (attr.reverse) base |= TXT_REVERSE;
if (attr.underline) base |= TXT_UNDERSCORE;
return switch (attr.foreground) {
.black => base,
.red => base | FG_RED,
.green => base | FG_GREEN,
.yellow => base | FG_RED | FG_GREEN,
.blue => base | FG_BLUE,
.magenta => base | FG_RED | FG_BLUE,
.cyan => base | FG_GREEN | FG_BLUE,
.white => base | FG_RED | FG_GREEN | FG_BLUE,
};
}
pub fn applyAttribute(term: *const Terminal, attr: TextAttributes) !void {
if (windows.SetConsoleTextAttribute(term.stdin.handle, attrToWord(attr)) != 0) {
return error.Unexpected;
}
}
pub fn resetAttributes(term: *const Terminal) !void {
try applyAttribute(term, .{});
}
pub fn switchToAltBuffer(_: *const Terminal) !void {}
pub fn switchToMainBuffer(_: *const Terminal) !void {}
pub fn cursorMoveUp(term: *const Terminal, n: u16) !void {
var info: win.CONSOLE_SCREEN_BUFFER_INFO = undefined;
if (GetConsoleScreenBufferInfo(term.stdout.handle, &info) == 0) return error.Unexpected;
var cursor = info.dwCursorPosition;
cursor.Y -= n;
if (SetConsoleCursorPosition(term.stdout.handle, cursor) == 0) return error.Unexpected;
}
pub fn cursorMoveDown(term: *const Terminal, n: u16) !void {
var info: win.CONSOLE_SCREEN_BUFFER_INFO = undefined;
if (GetConsoleScreenBufferInfo(term.stdout.handle, &info) == 0) return error.Unexpected;
var cursor = info.dwCursorPosition;
cursor.Y += n;
if (SetConsoleCursorPosition(term.stdout.handle, cursor) == 0) return error.Unexpected;
}
pub fn cursorMoveRight(term: *const Terminal, n: u16) !void {
var info: win.CONSOLE_SCREEN_BUFFER_INFO = undefined;
if (GetConsoleScreenBufferInfo(term.stdout.handle, &info) == 0) return error.Unexpected;
var cursor = info.dwCursorPosition;
cursor.X += n;
if (SetConsoleCursorPosition(term.stdout.handle, cursor) == 0) return error.Unexpected;
}
pub fn cursorMoveLeft(term: *const Terminal, n: u16) !void {
var info: win.CONSOLE_SCREEN_BUFFER_INFO = undefined;
if (GetConsoleScreenBufferInfo(term.stdout.handle, &info) == 0) return error.Unexpected;
var cursor = info.dwCursorPosition;
cursor.X -= n;
if (SetConsoleCursorPosition(term.stdout.handle, cursor) == 0) return error.Unexpected;
}
pub fn setCursorColumn(term: *const Terminal, col: u16) !void {
var info: win.CONSOLE_SCREEN_BUFFER_INFO = undefined;
if (GetConsoleScreenBufferInfo(term.stdout.handle, &info) == 0) return error.Unexpected;
var cursor = info.dwCursorPosition;
cursor.X = col;
if (SetConsoleCursorPosition(term.stdout.handle, cursor) == 0) return error.Unexpected;
}
pub fn setCursorRow(term: *const Terminal, row: u16) !void {
var info: win.CONSOLE_SCREEN_BUFFER_INFO = undefined;
if (GetConsoleScreenBufferInfo(term.stdout.handle, &info) == 0) return error.Unexpected;
var cursor = info.dwCursorPosition;
cursor.Y = row;
if (SetConsoleCursorPosition(term.stdout.handle, cursor) == 0) return error.Unexpected;
}
pub fn setCursorPosition(term: *const Terminal, x: u16, y: u16) !void {
const cursor = win.COORD{
.X = x,
.Y = y,
};
if (SetConsoleCursorPosition(term.stdout.handle, cursor) == 0) return error.Unexpected;
}
pub fn getTerminalSize(term: *const Terminal) !TerminalSize {
var info: win.CONSOLE_SCREEN_BUFFER_INFO = undefined;
if (GetConsoleScreenBufferInfo(term.stdout.handle, &info) == 0) return error.Unexpected;
return TerminalSize{
.width = info.dwSize.X,
.height = info.dwSize.Y,
};
}
};
pub const ansi = struct {
fn attrToSgr(attr: TextAttributes) u16 {
const base: u16 = if (attr.bright) 90 else 30;
return switch (attr.foreground) {
.black => base,
.red => base + 1,
.green => base + 2,
.yellow => base + 3,
.blue => base + 4,
.magenta => base + 5,
.cyan => base + 6,
.white => base + 7,
};
}
pub fn applyAttribute(term: *const Terminal, attr: TextAttributes) !void {
try term.stdout.writeAll("\x1b[0;");
if (attr.reverse) try term.stdout.writeAll("7;");
if (attr.underline) try term.stdout.writeAll("4;");
if (attr.bold) try term.stdout.writeAll("1;");
try term.stdout.writer().print("{d}m", .{attrToSgr(attr)});
}
pub fn resetAttributes(term: *const Terminal) !void {
try term.stdout.writeAll("\x1b[0m");
}
pub fn switchToAltBuffer(term: *const Terminal) !void {
try term.stdout.writeAll("\x1b[?1049h");
}
pub fn switchToMainBuffer(term: *const Terminal) !void {
try term.stdout.writeAll("\x1b[?1049l");
}
pub fn cursorMoveUp(term: *const Terminal, n: u16) !void {
try term.stdout.writeAll("\x1b[{d}A", n);
}
pub fn cursorMoveDown(term: *const Terminal, n: u16) !void {
try term.stdout.writeAll("\x1b[{d}B", n);
}
pub fn cursorMoveRight(term: *const Terminal, n: u16) !void {
try term.stdout.writeAll("\x1b[{d}C", n);
}
pub fn cursorMoveLeft(term: *const Terminal, n: u16) !void {
try term.stdout.writeAll("\x1b[{d}D", n);
}
pub fn setCursorColumn(term: *const Terminal, col: u16) !void {
try term.stdout.writeAll("\x1b[{d}G", col);
}
pub fn setCursorRow(term: *const Terminal, row: u16) !void {
try term.stdout.writeAll("\x1b[{d}f", row);
}
pub fn setCursorPosition(term: *const Terminal, x: u16, y: u16) !void {
try term.stdout.writeAll("\x1b[{d};{d}H", y, x);
}
};
pub const ioctl = struct {
pub fn getTerminalSize(term: *const Terminal) !TerminalSize {
var size: os.winsize = undefined;
switch (os.errno(os.ioctl(term.stdout.handle, os.TIOCGWINSZ, @ptrToInt(&size)))) {
0 => return TerminalSize{
.width = size.ws_col,
.height = size.ws_row,
},
os.EBADF => unreachable,
os.EFAULT => unreachable,
os.EINVAL => return error.Unsupported,
os.ENOTTY => return error.Unsupported,
else => |err| return os.unexpectedErrno(err),
}
}
}; | src/main.zig |
const GameState = @import("game.zig").GameState;
const @"u16_2" = @import("game.zig").u16_2;
pub const DiscoverSingleEvent = struct {
location: u16_2,
};
pub const DiscoverManyEvent = struct {
location: u16_2,
children: []u16_2,
};
pub const DiscoverNumberEvent = struct {
location: u16_2,
children: []u16_2,
};
pub const GameResult = enum {
Win,
Lose,
};
pub const GameEndEvent = struct {
result: GameResult,
exploded_mines: []u16_2,
};
pub const GameEventTag = enum {
discover_single,
discover_many,
discover_number,
game_end,
};
pub const GameEvent = union(GameEventTag) {
discover_single: DiscoverSingleEvent,
discover_many: DiscoverManyEvent,
discover_number: DiscoverNumberEvent,
game_end: GameEndEvent,
};
fn allocate_new_event(game: *GameState) *GameEvent {
const new_event = &game.event_history[game.event_history_index];
game.event_history_index += 1;
return new_event;
}
pub fn append_discover_single_event(game: *GameState, location: u16_2) void {
var new_event = allocate_new_event(game);
new_event.* = GameEvent{
.discover_single = DiscoverSingleEvent{
.location = location,
},
};
}
pub fn append_discover_many_event(game: *GameState, location: u16_2, children: []u16_2) void {
var new_event = allocate_new_event(game);
new_event.* = GameEvent{
.discover_many = DiscoverManyEvent{
.location = location,
.children = children,
},
};
}
pub fn append_discover_number_event(game: *GameState, location: u16_2, children: []u16_2) void {
var new_event = allocate_new_event(game);
new_event.* = GameEvent{
.discover_number = DiscoverNumberEvent{
.location = location,
.children = children,
},
};
}
pub fn append_game_end_event(game: *GameState, result: GameResult, exploded_mines: []u16_2) void {
var new_event = allocate_new_event(game);
new_event.* = GameEvent{
.game_end = GameEndEvent{
.result = result,
.exploded_mines = exploded_mines,
},
};
} | src/minesweeper/event.zig |
const std = @import("std");
pub const ByteEnum = enum(u8) {
@"🫂" = 200,
@"💖" = 50,
@"✨" = 10,
@"🥺" = 5,
@",,,," = 4,
@",,," = 3,
@",," = 2,
@"," = 1,
};
/// This is just a namespace for the bottom encoder
pub const BottomEncoder = struct {
pub const max_expansion_per_byte = 40;
pub fn encodeAlloc(str: []const u8, allocator: std.mem.Allocator) std.mem.Allocator.Error![]u8 {
const memory = try allocator.alloc(u8, str.len * max_expansion_per_byte);
return encode(str, memory);
}
/// Encode a stream of bytes to a bottomified version, the caller owns memory
pub fn encode(str: []const u8, memory: []u8) []u8 {
var index: usize = 0;
var buffer: [max_expansion_per_byte]u8 = undefined; // The maximum ammount of bytes per byte is 40
for (str) |v| {
var byte = encodeByte(v, &buffer);
std.mem.copy(u8, memory[index .. index + byte.len], byte);
index += byte.len;
}
return memory[0..index];
}
/// Encode one byte to bottom, the caller owns memory
pub fn encodeByte(byte: u8, buffer: []u8) []u8 {
var b: u8 = byte;
var index: usize = 0;
var passed: bool = false;
if (byte == 0) {
var text = "❤";
std.mem.copy(u8, buffer[index..], text);
index += text.len;
}
while (b != 0) {
passed = false;
inline for (std.meta.fields(ByteEnum)) |f| {
if (b >= f.value and !passed and b != 0) {
b -= f.value;
std.mem.copy(u8, buffer[index .. index + f.name.len], f.name);
index += f.name.len;
passed = true;
}
}
}
var text = "👉👈";
std.mem.copy(u8, buffer[index..], text);
index += text.len;
return buffer[0..index];
}
};
test "encode works" {
if (@import("builtin").os.tag == .windows) {
if (std.os.windows.kernel32.SetConsoleOutputCP(65001) == 0) {
return error.console_not_support_utf8;
}
}
const a = "💖💖,,,,👉👈💖💖,👉👈💖💖🥺,,,👉👈💖💖🥺,,,👉👈💖💖✨,👉👈✨✨✨,,👉👈💖💖✨🥺,,,,👉👈💖💖✨,👉👈💖💖✨,,,,👉👈💖💖🥺,,,👉👈💖💖👉👈✨✨✨,,,👉👈";
const res = try BottomEncoder.encodeAlloc("hello world!", std.testing.allocator);
defer std.testing.allocator.free(res);
try std.testing.expectEqualStrings(a, res);
} | src/encoder.zig |
const std = @import("std");
usingnamespace (@import("../machine.zig"));
usingnamespace (@import("../util.zig"));
// QuickRef: https://www.felixcloutier.com/x86/pop
const reg = Operand.register;
const regRm = Operand.registerRm;
const memSib = Operand.memorySibDef;
test "pop" {
const m16 = Machine.init(.x86_16);
const m32 = Machine.init(.x86_32);
const m64 = Machine.init(.x64);
debugPrint(false);
{
testOp1(m32, .POP, reg(.R15), AsmError.InvalidOperand);
testOp1(m64, .POP, reg(.R15), "41 5F");
}
{
testOp1(m16, .POP, reg(.FS), "0F A1");
testOp1(m32, .POP, reg(.FS), "0F A1");
testOp1(m64, .POP, reg(.FS), "0F A1");
//
testOp1(m16, .POPW, reg(.FS), "0F A1");
testOp1(m32, .POPW, reg(.FS), "66 0F A1");
testOp1(m64, .POPW, reg(.FS), "66 0F A1");
//
testOp1(m16, .POPD, reg(.FS), "66 0F A1");
testOp1(m32, .POPD, reg(.FS), "0F A1");
testOp1(m64, .POPD, reg(.FS), AsmError.InvalidOperand);
//
testOp1(m16, .POPQ, reg(.FS), AsmError.InvalidOperand);
testOp1(m32, .POPQ, reg(.FS), AsmError.InvalidOperand);
testOp1(m64, .POPQ, reg(.FS), "0F A1");
}
{
testOp1(m16, .POP, reg(.DS), "1F");
testOp1(m32, .POP, reg(.DS), "1F");
testOp1(m64, .POP, reg(.DS), AsmError.InvalidOperand);
//
testOp1(m16, .POPW, reg(.DS), "1F");
testOp1(m32, .POPW, reg(.DS), "66 1F");
testOp1(m64, .POPW, reg(.DS), AsmError.InvalidOperand);
//
testOp1(m16, .POPD, reg(.DS), "66 1F");
testOp1(m32, .POPD, reg(.DS), "1F");
testOp1(m64, .POPD, reg(.DS), AsmError.InvalidOperand);
//
testOp1(m16, .POPQ, reg(.DS), AsmError.InvalidOperand);
testOp1(m32, .POPQ, reg(.DS), AsmError.InvalidOperand);
testOp1(m64, .POPQ, reg(.DS), AsmError.InvalidOperand);
}
{
testOp1(m16, .POP, reg(.AX), "58");
testOp1(m32, .POP, reg(.AX), "66 58");
testOp1(m64, .POP, reg(.AX), "66 58");
//
testOp1(m16, .POP, reg(.EAX), "66 58");
testOp1(m32, .POP, reg(.EAX), "58");
testOp1(m64, .POP, reg(.EAX), AsmError.InvalidOperand);
//
testOp1(m16, .POP, reg(.RAX), AsmError.InvalidOperand);
testOp1(m32, .POP, reg(.RAX), AsmError.InvalidOperand);
testOp1(m64, .POP, reg(.RAX), "58");
//
testOp1(m16, .POP, regRm(.RAX), AsmError.InvalidOperand);
testOp1(m32, .POP, regRm(.RAX), AsmError.InvalidOperand);
testOp1(m64, .POP, regRm(.RAX), "8f c0");
//
testOp1(m16, .POP, regRm(.R8), AsmError.InvalidOperand);
testOp1(m32, .POP, regRm(.R8), AsmError.InvalidOperand);
testOp1(m64, .POP, regRm(.R8), "41 8f c0");
}
{
testOp1(m16, .POP, memSib(.WORD, 1, .EAX, .EAX, 0), "67 8F 04 00");
testOp1(m32, .POP, memSib(.WORD, 1, .EAX, .EAX, 0), "66 8F 04 00");
testOp1(m64, .POP, memSib(.WORD, 1, .EAX, .EAX, 0), "66 67 8F 04 00");
//
testOp1(m16, .POP, memSib(.DWORD, 1, .EAX, .EAX, 0), "66 67 8F 04 00");
testOp1(m32, .POP, memSib(.DWORD, 1, .EAX, .EAX, 0), "8F 04 00");
testOp1(m64, .POP, memSib(.DWORD, 1, .EAX, .EAX, 0), AsmError.InvalidOperand);
//
testOp1(m16, .POP, memSib(.QWORD, 1, .RAX, .RAX, 0), AsmError.InvalidOperand);
testOp1(m32, .POP, memSib(.QWORD, 1, .RAX, .RAX, 0), AsmError.InvalidOperand);
testOp1(m64, .POP, memSib(.QWORD, 1, .RAX, .RAX, 0), "8F 04 00");
}
} | src/x86/tests/pop.zig |
const std = @import("std");
const types = @import("types.zig");
const URI = @import("uri.zig");
const analysis = @import("analysis.zig");
const offsets = @import("offsets.zig");
const log = std.log.scoped(.doc_store);
const BuildAssociatedConfig = @import("build_associated_config.zig");
const DocumentStore = @This();
const BuildFile = struct {
const Pkg = struct {
name: []const u8,
uri: []const u8,
};
refs: usize,
uri: []const u8,
packages: std.ArrayListUnmanaged(Pkg),
builtin_uri: ?[]const u8 = null,
pub fn destroy(self: *BuildFile, allocator: *std.mem.Allocator) void {
if (self.builtin_uri) |builtin_uri| allocator.free(builtin_uri);
allocator.destroy(self);
}
};
pub const Handle = struct {
document: types.TextDocument,
count: usize,
/// Contains one entry for every import in the document
import_uris: []const []const u8,
/// Items in this array list come from `import_uris`
imports_used: std.ArrayListUnmanaged([]const u8),
tree: std.zig.ast.Tree,
document_scope: analysis.DocumentScope,
associated_build_file: ?*BuildFile,
is_build_file: ?*BuildFile,
pub fn uri(handle: Handle) []const u8 {
return handle.document.uri;
}
};
allocator: *std.mem.Allocator,
handles: std.StringHashMap(*Handle),
zig_exe_path: ?[]const u8,
build_files: std.ArrayListUnmanaged(*BuildFile),
build_runner_path: []const u8,
build_runner_cache_path: []const u8,
std_uri: ?[]const u8,
pub fn init(
self: *DocumentStore,
allocator: *std.mem.Allocator,
zig_exe_path: ?[]const u8,
build_runner_path: []const u8,
build_runner_cache_path: []const u8,
zig_lib_path: ?[]const u8,
) !void {
self.allocator = allocator;
self.handles = std.StringHashMap(*Handle).init(allocator);
self.zig_exe_path = zig_exe_path;
self.build_files = .{};
self.build_runner_path = build_runner_path;
self.build_runner_cache_path = build_runner_cache_path;
self.std_uri = try stdUriFromLibPath(allocator, zig_lib_path);
}
fn loadBuildAssociatedConfiguration(allocator: *std.mem.Allocator, build_file: *BuildFile, build_file_path: []const u8) !void {
const directory_path = build_file_path[0 .. build_file_path.len - "build.zig".len];
const options = std.json.ParseOptions{ .allocator = allocator };
const build_associated_config = blk: {
const config_file_path = try std.fs.path.join(allocator, &[_][]const u8{ directory_path, "zls.build.json" });
defer allocator.free(config_file_path);
var config_file = std.fs.cwd().openFile(config_file_path, .{}) catch |err| {
if (err == error.FileNotFound) return;
return err;
};
defer config_file.close();
const file_buf = try config_file.readToEndAlloc(allocator, 0x1000000);
defer allocator.free(file_buf);
break :blk try std.json.parse(BuildAssociatedConfig, &std.json.TokenStream.init(file_buf), options);
};
defer std.json.parseFree(BuildAssociatedConfig, build_associated_config, options);
if (build_associated_config.relative_builtin_path) |relative_builtin_path| {
var absolute_builtin_path = try std.mem.concat(allocator, u8, &.{ directory_path, relative_builtin_path });
defer allocator.free(absolute_builtin_path);
build_file.builtin_uri = try URI.fromPath(allocator, absolute_builtin_path);
}
}
const LoadPackagesContext = struct {
build_file: *BuildFile,
allocator: *std.mem.Allocator,
build_runner_path: []const u8,
build_runner_cache_path: []const u8,
zig_exe_path: []const u8,
build_file_path: ?[]const u8 = null,
};
fn loadPackages(context: LoadPackagesContext) !void {
const allocator = context.allocator;
const build_file = context.build_file;
const build_runner_path = context.build_runner_path;
const build_runner_cache_path = context.build_runner_cache_path;
const zig_exe_path = context.zig_exe_path;
const build_file_path = context.build_file_path orelse try URI.parse(allocator, build_file.uri);
defer if (context.build_file_path == null) allocator.free(build_file_path);
const directory_path = build_file_path[0 .. build_file_path.len - "build.zig".len];
const zig_run_result = try std.ChildProcess.exec(.{
.allocator = allocator,
.argv = &[_][]const u8{
zig_exe_path,
"run",
build_runner_path,
"--cache-dir",
build_runner_cache_path,
"--pkg-begin",
"@build@",
build_file_path,
"--pkg-end",
},
});
defer {
allocator.free(zig_run_result.stdout);
allocator.free(zig_run_result.stderr);
}
switch (zig_run_result.term) {
.Exited => |exit_code| {
if (exit_code == 0) {
log.debug("Finished zig run for build file {s}", .{build_file.uri});
for (build_file.packages.items) |old_pkg| {
allocator.free(old_pkg.name);
allocator.free(old_pkg.uri);
}
build_file.packages.shrinkAndFree(allocator, 0);
var line_it = std.mem.split(u8, zig_run_result.stdout, "\n");
while (line_it.next()) |line| {
if (std.mem.indexOfScalar(u8, line, '\x00')) |zero_byte_idx| {
const name = line[0..zero_byte_idx];
const rel_path = line[zero_byte_idx + 1 ..];
const pkg_abs_path = try std.fs.path.resolve(allocator, &[_][]const u8{ directory_path, rel_path });
defer allocator.free(pkg_abs_path);
const pkg_uri = try URI.fromPath(allocator, pkg_abs_path);
errdefer allocator.free(pkg_uri);
const duped_name = try std.mem.dupe(allocator, u8, name);
errdefer allocator.free(duped_name);
(try build_file.packages.addOne(allocator)).* = .{
.name = duped_name,
.uri = pkg_uri,
};
}
}
}
},
else => return error.RunFailed,
}
}
/// This function asserts the document is not open yet and takes ownership
/// of the uri and text passed in.
fn newDocument(self: *DocumentStore, uri: []const u8, text: [:0]u8) anyerror!*Handle {
log.debug("Opened document: {s}", .{uri});
var handle = try self.allocator.create(Handle);
errdefer self.allocator.destroy(handle);
var tree = try std.zig.parse(self.allocator, text);
errdefer tree.deinit(self.allocator);
var document_scope = try analysis.makeDocumentScope(self.allocator, tree);
errdefer document_scope.deinit(self.allocator);
handle.* = Handle{
.count = 1,
.import_uris = &.{},
.imports_used = .{},
.document = .{
.uri = uri,
.text = text,
.mem = text,
},
.tree = tree,
.document_scope = document_scope,
.associated_build_file = null,
.is_build_file = null,
};
// TODO: Better logic for detecting std or subdirectories?
const in_std = std.mem.indexOf(u8, uri, "/std/") != null;
if (self.zig_exe_path != null and std.mem.endsWith(u8, uri, "/build.zig") and !in_std) {
log.debug("Document is a build file, extracting packages...", .{});
// This is a build file.
var build_file = try self.allocator.create(BuildFile);
errdefer build_file.destroy(self.allocator);
build_file.* = .{
.refs = 1,
.uri = try std.mem.dupe(self.allocator, u8, uri),
.packages = .{},
};
const build_file_path = try URI.parse(self.allocator, build_file.uri);
defer self.allocator.free(build_file_path);
loadBuildAssociatedConfiguration(self.allocator, build_file, build_file_path) catch |err| {
log.debug("Failed to load config associated with build file {s} (error: {})", .{ build_file.uri, err });
};
// TODO: Do this in a separate thread?
// It can take quite long.
loadPackages(.{
.build_file = build_file,
.allocator = self.allocator,
.build_runner_path = self.build_runner_path,
.build_runner_cache_path = self.build_runner_cache_path,
.zig_exe_path = self.zig_exe_path.?,
.build_file_path = build_file_path,
}) catch |err| {
log.debug("Failed to load packages of build file {s} (error: {})", .{ build_file.uri, err });
};
try self.build_files.append(self.allocator, build_file);
handle.is_build_file = build_file;
} else if (self.zig_exe_path != null and !in_std) {
// Look into build files and keep the one that lives closest to the document in the directory structure
var candidate: ?*BuildFile = null;
{
var uri_chars_matched: usize = 0;
for (self.build_files.items) |build_file| {
const build_file_base_uri = build_file.uri[0 .. std.mem.lastIndexOfScalar(u8, build_file.uri, '/').? + 1];
if (build_file_base_uri.len > uri_chars_matched and std.mem.startsWith(u8, uri, build_file_base_uri)) {
uri_chars_matched = build_file_base_uri.len;
candidate = build_file;
}
}
if (candidate) |build_file| {
log.debug("Found a candidate associated build file: `{s}`", .{build_file.uri});
}
}
// Then, try to find the closest build file.
var curr_path = try URI.parse(self.allocator, uri);
defer self.allocator.free(curr_path);
while (true) {
if (curr_path.len == 0) break;
if (std.mem.lastIndexOfScalar(u8, curr_path[0 .. curr_path.len - 1], std.fs.path.sep)) |idx| {
// This includes the last separator
curr_path = curr_path[0 .. idx + 1];
// Try to open the folder, then the file.
var folder = std.fs.cwd().openDir(curr_path, .{}) catch |err| switch (err) {
error.FileNotFound => continue,
else => return err,
};
defer folder.close();
var build_file = folder.openFile("build.zig", .{}) catch |err| switch (err) {
error.FileNotFound, error.AccessDenied => continue,
else => return err,
};
defer build_file.close();
// Calculate build file's URI
var candidate_path = try std.mem.concat(self.allocator, u8, &.{ curr_path, "build.zig" });
defer self.allocator.free(candidate_path);
const build_file_uri = try URI.fromPath(self.allocator, candidate_path);
errdefer self.allocator.free(build_file_uri);
if (candidate) |candidate_build_file| {
// Check if it is the same as the current candidate we got from the existing build files.
// If it isn't, we need to read the file and make a new build file.
if (std.mem.eql(u8, candidate_build_file.uri, build_file_uri)) {
self.allocator.free(build_file_uri);
break;
}
}
// Read the build file, create a new document, set the candidate to the new build file.
const build_file_text = try build_file.readToEndAllocOptions(
self.allocator,
std.math.maxInt(usize),
null,
@alignOf(u8),
0,
);
errdefer self.allocator.free(build_file_text);
const build_file_handle = try self.newDocument(build_file_uri, build_file_text);
candidate = build_file_handle.is_build_file.?;
break;
} else break;
}
// Finally, associate the candidate build file, if any, to the new document.
if (candidate) |build_file| {
build_file.refs += 1;
handle.associated_build_file = build_file;
log.debug("Associated build file `{s}` to document `{s}`", .{ build_file.uri, handle.uri() });
}
}
handle.import_uris = try self.collectImportUris(handle);
errdefer {
for (handle.import_uris) |imp_uri| {
self.allocator.free(imp_uri);
}
self.allocator.free(handle.import_uris);
}
try self.handles.putNoClobber(uri, handle);
return handle;
}
pub fn openDocument(self: *DocumentStore, uri: []const u8, text: []const u8) !*Handle {
if (self.handles.getEntry(uri)) |entry| {
log.debug("Document already open: {s}, incrementing count", .{uri});
entry.value_ptr.*.count += 1;
if (entry.value_ptr.*.is_build_file) |build_file| {
build_file.refs += 1;
}
log.debug("New count: {}", .{entry.value_ptr.*.count});
return entry.value_ptr.*;
}
const duped_text = try std.mem.dupeZ(self.allocator, u8, text);
errdefer self.allocator.free(duped_text);
const duped_uri = try std.mem.dupe(self.allocator, u8, uri);
errdefer self.allocator.free(duped_uri);
return try self.newDocument(duped_uri, duped_text);
}
fn decrementBuildFileRefs(self: *DocumentStore, build_file: *BuildFile) void {
build_file.refs -= 1;
if (build_file.refs == 0) {
log.debug("Freeing build file {s}", .{build_file.uri});
for (build_file.packages.items) |pkg| {
self.allocator.free(pkg.name);
self.allocator.free(pkg.uri);
}
build_file.packages.deinit(self.allocator);
// Decrement count of the document since one count comes
// from the build file existing.
self.decrementCount(build_file.uri);
self.allocator.free(build_file.uri);
// Remove the build file from the array list
_ = self.build_files.swapRemove(std.mem.indexOfScalar(*BuildFile, self.build_files.items, build_file).?);
build_file.destroy(self.allocator);
}
}
fn decrementCount(self: *DocumentStore, uri: []const u8) void {
if (self.handles.getEntry(uri)) |entry| {
const handle = entry.value_ptr.*;
if (handle.count == 0) return;
handle.count -= 1;
if (handle.count > 0)
return;
log.debug("Freeing document: {s}", .{uri});
if (handle.associated_build_file) |build_file| {
self.decrementBuildFileRefs(build_file);
}
if (handle.is_build_file) |build_file| {
self.decrementBuildFileRefs(build_file);
}
handle.tree.deinit(self.allocator);
self.allocator.free(handle.document.mem);
for (handle.imports_used.items) |import_uri| {
self.decrementCount(import_uri);
}
for (handle.import_uris) |import_uri| {
self.allocator.free(import_uri);
}
handle.document_scope.deinit(self.allocator);
handle.imports_used.deinit(self.allocator);
self.allocator.free(handle.import_uris);
self.allocator.destroy(handle);
const uri_key = entry.key_ptr.*;
std.debug.assert(self.handles.remove(uri));
self.allocator.free(uri_key);
}
}
pub fn closeDocument(self: *DocumentStore, uri: []const u8) void {
self.decrementCount(uri);
}
pub fn getHandle(self: *DocumentStore, uri: []const u8) ?*Handle {
return self.handles.get(uri);
}
fn collectImportUris(self: *DocumentStore, handle: *Handle) ![]const []const u8 {
var new_imports = std.ArrayList([]const u8).init(self.allocator);
errdefer {
for (new_imports.items) |imp| {
self.allocator.free(imp);
}
new_imports.deinit();
}
try analysis.collectImports(&new_imports, handle.tree);
// Convert to URIs
var i: usize = 0;
while (i < new_imports.items.len) {
if (try self.uriFromImportStr(self.allocator, handle.*, new_imports.items[i])) |uri| {
// The raw import strings are owned by the document and do not need to be freed here.
new_imports.items[i] = uri;
i += 1;
} else {
_ = new_imports.swapRemove(i);
}
}
return new_imports.toOwnedSlice();
}
fn refreshDocument(self: *DocumentStore, handle: *Handle) !void {
log.debug("New text for document {s}", .{handle.uri()});
handle.tree.deinit(self.allocator);
handle.tree = try std.zig.parse(self.allocator, handle.document.text);
handle.document_scope.deinit(self.allocator);
handle.document_scope = try analysis.makeDocumentScope(self.allocator, handle.tree);
const new_imports = try self.collectImportUris(handle);
errdefer {
for (new_imports) |imp| {
self.allocator.free(imp);
}
self.allocator.free(new_imports);
}
const old_imports = handle.import_uris;
handle.import_uris = new_imports;
defer {
for (old_imports) |uri| {
self.allocator.free(uri);
}
self.allocator.free(old_imports);
}
var i: usize = 0;
while (i < handle.imports_used.items.len) {
const old = handle.imports_used.items[i];
still_exists: {
for (new_imports) |new| {
if (std.mem.eql(u8, new, old)) {
handle.imports_used.items[i] = new;
break :still_exists;
}
}
log.debug("Import removed: {s}", .{old});
self.decrementCount(old);
_ = handle.imports_used.swapRemove(i);
continue;
}
i += 1;
}
}
pub fn applySave(self: *DocumentStore, handle: *Handle) !void {
if (handle.is_build_file) |build_file| {
loadPackages(.{
.build_file = build_file,
.allocator = self.allocator,
.build_runner_path = self.build_runner_path,
.build_runner_cache_path = self.build_runner_cache_path,
.zig_exe_path = self.zig_exe_path.?,
}) catch |err| {
log.debug("Failed to load packages of build file {s} (error: {})", .{ build_file.uri, err });
};
}
}
pub fn applyChanges(
self: *DocumentStore,
handle: *Handle,
content_changes: std.json.Array,
offset_encoding: offsets.Encoding,
) !void {
const document = &handle.document;
for (content_changes.items) |change| {
if (change.Object.get("range")) |range| {
std.debug.assert(@ptrCast([*]const u8, document.text.ptr) == document.mem.ptr);
// TODO: add tests and validate the JSON
const start_obj = range.Object.get("start").?.Object;
const start_pos = types.Position{
.line = start_obj.get("line").?.Integer,
.character = start_obj.get("character").?.Integer,
};
const end_obj = range.Object.get("end").?.Object;
const end_pos = types.Position{
.line = end_obj.get("line").?.Integer,
.character = end_obj.get("character").?.Integer,
};
const change_text = change.Object.get("text").?.String;
const start_index = (try offsets.documentPosition(document.*, start_pos, offset_encoding)).absolute_index;
const end_index = (try offsets.documentPosition(document.*, end_pos, offset_encoding)).absolute_index;
const old_len = document.text.len;
const new_len = old_len - (end_index - start_index) + change_text.len;
if (new_len >= document.mem.len) {
// We need to reallocate memory.
// We reallocate twice the current filesize or the new length, if it's more than that
// so that we can reduce the amount of realloc calls.
// We can tune this to find a better size if needed.
const realloc_len = std.math.max(2 * old_len, new_len + 1);
document.mem = try self.allocator.realloc(document.mem, realloc_len);
}
// The first part of the string, [0 .. start_index] need not be changed.
// We then copy the last part of the string, [end_index ..] to its
// new position, [start_index + change_len .. ]
if (new_len < old_len) {
std.mem.copy(u8, document.mem[start_index + change_text.len ..][0 .. old_len - end_index], document.mem[end_index..old_len]);
} else {
std.mem.copyBackwards(u8, document.mem[start_index + change_text.len ..][0 .. old_len - end_index], document.mem[end_index..old_len]);
}
// Finally, we copy the changes over.
std.mem.copy(u8, document.mem[start_index..][0..change_text.len], change_text);
// Reset the text substring.
document.mem[new_len] = 0;
document.text = document.mem[0..new_len :0];
} else {
const change_text = change.Object.get("text").?.String;
const old_len = document.text.len;
if (change_text.len >= document.mem.len) {
// Like above.
const realloc_len = std.math.max(2 * old_len, change_text.len + 1);
document.mem = try self.allocator.realloc(document.mem, realloc_len);
}
std.mem.copy(u8, document.mem[0..change_text.len], change_text);
document.mem[change_text.len] = 0;
document.text = document.mem[0..change_text.len :0];
}
}
try self.refreshDocument(handle);
}
pub fn uriFromImportStr(
self: *DocumentStore,
allocator: *std.mem.Allocator,
handle: Handle,
import_str: []const u8,
) !?[]const u8 {
if (std.mem.eql(u8, import_str, "std")) {
if (self.std_uri) |uri| return try std.mem.dupe(allocator, u8, uri) else {
log.debug("Cannot resolve std library import, path is null.", .{});
return null;
}
} else if (std.mem.eql(u8, import_str, "builtin")) {
if (handle.associated_build_file) |build_file| {
if (build_file.builtin_uri) |builtin_uri| {
return try std.mem.dupe(allocator, u8, builtin_uri);
}
}
return null; // TODO find the correct zig-cache folder
} else if (!std.mem.endsWith(u8, import_str, ".zig")) {
if (handle.associated_build_file) |build_file| {
for (build_file.packages.items) |pkg| {
if (std.mem.eql(u8, import_str, pkg.name)) {
return try std.mem.dupe(allocator, u8, pkg.uri);
}
}
}
return null;
} else {
const base = handle.uri();
var base_len = base.len;
while (base[base_len - 1] != '/' and base_len > 0) {
base_len -= 1;
}
base_len -= 1;
if (base_len <= 0) {
return error.UriBadScheme;
}
return try URI.pathRelative(allocator, base[0..base_len], import_str);
}
}
pub fn resolveImport(self: *DocumentStore, handle: *Handle, import_str: []const u8) !?*Handle {
const allocator = self.allocator;
const final_uri = (try self.uriFromImportStr(
self.allocator,
handle.*,
import_str,
)) orelse return null;
defer allocator.free(final_uri);
for (handle.imports_used.items) |uri| {
if (std.mem.eql(u8, uri, final_uri)) {
return self.getHandle(final_uri).?;
}
}
// The URI must be somewhere in the import_uris or the package uris
const handle_uri = find_uri: {
for (handle.import_uris) |uri| {
if (std.mem.eql(u8, uri, final_uri)) {
break :find_uri uri;
}
}
if (handle.associated_build_file) |bf| {
for (bf.packages.items) |pkg| {
if (std.mem.eql(u8, pkg.uri, final_uri)) {
break :find_uri pkg.uri;
}
}
}
return null;
};
// New import.
// Check if the import is already opened by others.
if (self.getHandle(final_uri)) |new_handle| {
// If it is, append it to our imports, increment the count, set our new handle
// and return the parsed tree root node.
try handle.imports_used.append(self.allocator, handle_uri);
new_handle.count += 1;
return new_handle;
}
// New document, read the file then call into openDocument.
const file_path = try URI.parse(allocator, final_uri);
defer allocator.free(file_path);
var file = std.fs.cwd().openFile(file_path, .{}) catch {
log.debug("Cannot open import file {s}", .{file_path});
return null;
};
defer file.close();
{
const file_contents = file.readToEndAllocOptions(
allocator,
std.math.maxInt(usize),
null,
@alignOf(u8),
0,
) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
else => {
log.debug("Could not read from file {s}", .{file_path});
return null;
},
};
errdefer allocator.free(file_contents);
// Add to import table of current handle.
try handle.imports_used.append(self.allocator, handle_uri);
// Swap handles.
// This takes ownership of the passed uri and text.
const duped_final_uri = try std.mem.dupe(allocator, u8, final_uri);
errdefer allocator.free(duped_final_uri);
return try self.newDocument(duped_final_uri, file_contents);
}
}
fn stdUriFromLibPath(allocator: *std.mem.Allocator, zig_lib_path: ?[]const u8) !?[]const u8 {
if (zig_lib_path) |zpath| {
const std_path = std.fs.path.resolve(allocator, &[_][]const u8{
zpath, "./std/std.zig",
}) catch |err| {
log.debug("Failed to resolve zig std library path, error: {}", .{err});
return null;
};
defer allocator.free(std_path);
// Get the std_path as a URI, so we can just append to it!
return try URI.fromPath(allocator, std_path);
}
return null;
}
pub fn deinit(self: *DocumentStore) void {
var entry_iterator = self.handles.iterator();
while (entry_iterator.next()) |entry| {
entry.value_ptr.*.document_scope.deinit(self.allocator);
entry.value_ptr.*.tree.deinit(self.allocator);
self.allocator.free(entry.value_ptr.*.document.mem);
for (entry.value_ptr.*.import_uris) |uri| {
self.allocator.free(uri);
}
self.allocator.free(entry.value_ptr.*.import_uris);
entry.value_ptr.*.imports_used.deinit(self.allocator);
self.allocator.free(entry.key_ptr.*);
self.allocator.destroy(entry.value_ptr.*);
}
self.handles.deinit();
for (self.build_files.items) |build_file| {
for (build_file.packages.items) |pkg| {
self.allocator.free(pkg.name);
self.allocator.free(pkg.uri);
}
build_file.packages.deinit(self.allocator);
self.allocator.free(build_file.uri);
build_file.destroy(self.allocator);
}
if (self.std_uri) |std_uri| {
self.allocator.free(std_uri);
}
self.allocator.free(self.build_runner_path);
self.allocator.free(self.build_runner_cache_path);
self.build_files.deinit(self.allocator);
}
fn tagStoreCompletionItems(
self: DocumentStore,
arena: *std.heap.ArenaAllocator,
base: *DocumentStore.Handle,
comptime name: []const u8,
) ![]types.CompletionItem {
// TODO Better solution for deciding what tags to include
var max_len: usize = @field(base.document_scope, name).count();
for (base.imports_used.items) |uri| {
max_len += @field(self.handles.get(uri).?.document_scope, name).count();
}
var result_set = analysis.CompletionSet{};
try result_set.ensureCapacity(&arena.allocator, max_len);
for (@field(base.document_scope, name).entries.items(.key)) |completion| {
result_set.putAssumeCapacityNoClobber(completion, {});
}
for (base.imports_used.items) |uri| {
const curr_set = &@field(self.handles.get(uri).?.document_scope, name);
for (curr_set.entries.items(.key)) |completion| {
result_set.putAssumeCapacity(completion, {});
}
}
return result_set.entries.items(.key);
}
pub fn errorCompletionItems(
self: DocumentStore,
arena: *std.heap.ArenaAllocator,
base: *DocumentStore.Handle,
) ![]types.CompletionItem {
return try self.tagStoreCompletionItems(arena, base, "error_completions");
}
pub fn enumCompletionItems(
self: DocumentStore,
arena: *std.heap.ArenaAllocator,
base: *DocumentStore.Handle,
) ![]types.CompletionItem {
return try self.tagStoreCompletionItems(arena, base, "enum_completions");
} | src/document_store.zig |
const std = @import("std");
const math = std.math;
const expect = std.testing.expect;
const trig = @import("trig.zig");
const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
pub fn __sinh(x: f16) callconv(.C) f16 {
// TODO: more efficient implementation
return @floatCast(f16, sinf(x));
}
pub fn sinf(x: f32) callconv(.C) f32 {
// Small multiples of pi/2 rounded to double precision.
const s1pio2: f64 = 1.0 * math.pi / 2.0; // 0x3FF921FB, 0x54442D18
const s2pio2: f64 = 2.0 * math.pi / 2.0; // 0x400921FB, 0x54442D18
const s3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
const s4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
var ix = @bitCast(u32, x);
const sign = ix >> 31 != 0;
ix &= 0x7fffffff;
if (ix <= 0x3f490fda) { // |x| ~<= pi/4
if (ix < 0x39800000) { // |x| < 2**-12
// raise inexact if x!=0 and underflow if subnormal
math.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
return x;
}
return trig.__sindf(x);
}
if (ix <= 0x407b53d1) { // |x| ~<= 5*pi/4
if (ix <= 0x4016cbe3) { // |x| ~<= 3pi/4
if (sign) {
return -trig.__cosdf(x + s1pio2);
} else {
return trig.__cosdf(x - s1pio2);
}
}
return trig.__sindf(if (sign) -(x + s2pio2) else -(x - s2pio2));
}
if (ix <= 0x40e231d5) { // |x| ~<= 9*pi/4
if (ix <= 0x40afeddf) { // |x| ~<= 7*pi/4
if (sign) {
return trig.__cosdf(x + s3pio2);
} else {
return -trig.__cosdf(x - s3pio2);
}
}
return trig.__sindf(if (sign) x + s4pio2 else x - s4pio2);
}
// sin(Inf or NaN) is NaN
if (ix >= 0x7f800000) {
return x - x;
}
var y: f64 = undefined;
const n = rem_pio2f(x, &y);
return switch (n & 3) {
0 => trig.__sindf(y),
1 => trig.__cosdf(y),
2 => trig.__sindf(-y),
else => -trig.__cosdf(y),
};
}
pub fn sin(x: f64) callconv(.C) f64 {
var ix = @bitCast(u64, x) >> 32;
ix &= 0x7fffffff;
// |x| ~< pi/4
if (ix <= 0x3fe921fb) {
if (ix < 0x3e500000) { // |x| < 2**-26
// raise inexact if x != 0 and underflow if subnormal
math.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
return x;
}
return trig.__sin(x, 0.0, 0);
}
// sin(Inf or NaN) is NaN
if (ix >= 0x7ff00000) {
return x - x;
}
var y: [2]f64 = undefined;
const n = rem_pio2(x, &y);
return switch (n & 3) {
0 => trig.__sin(y[0], y[1], 1),
1 => trig.__cos(y[0], y[1]),
2 => -trig.__sin(y[0], y[1], 1),
else => -trig.__cos(y[0], y[1]),
};
}
pub fn __sinx(x: f80) callconv(.C) f80 {
// TODO: more efficient implementation
return @floatCast(f80, sinq(x));
}
pub fn sinq(x: f128) callconv(.C) f128 {
// TODO: more correct implementation
return sin(@floatCast(f64, x));
}
test "sin32" {
const epsilon = 0.00001;
try expect(math.approxEqAbs(f32, sinf(0.0), 0.0, epsilon));
try expect(math.approxEqAbs(f32, sinf(0.2), 0.198669, epsilon));
try expect(math.approxEqAbs(f32, sinf(0.8923), 0.778517, epsilon));
try expect(math.approxEqAbs(f32, sinf(1.5), 0.997495, epsilon));
try expect(math.approxEqAbs(f32, sinf(-1.5), -0.997495, epsilon));
try expect(math.approxEqAbs(f32, sinf(37.45), -0.246544, epsilon));
try expect(math.approxEqAbs(f32, sinf(89.123), 0.916166, epsilon));
}
test "sin64" {
const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, sin(0.0), 0.0, epsilon));
try expect(math.approxEqAbs(f64, sin(0.2), 0.198669, epsilon));
try expect(math.approxEqAbs(f64, sin(0.8923), 0.778517, epsilon));
try expect(math.approxEqAbs(f64, sin(1.5), 0.997495, epsilon));
try expect(math.approxEqAbs(f64, sin(-1.5), -0.997495, epsilon));
try expect(math.approxEqAbs(f64, sin(37.45), -0.246543, epsilon));
try expect(math.approxEqAbs(f64, sin(89.123), 0.916166, epsilon));
}
test "sin32.special" {
try expect(sinf(0.0) == 0.0);
try expect(sinf(-0.0) == -0.0);
try expect(math.isNan(sinf(math.inf(f32))));
try expect(math.isNan(sinf(-math.inf(f32))));
try expect(math.isNan(sinf(math.nan(f32))));
}
test "sin64.special" {
try expect(sin(0.0) == 0.0);
try expect(sin(-0.0) == -0.0);
try expect(math.isNan(sin(math.inf(f64))));
try expect(math.isNan(sin(-math.inf(f64))));
try expect(math.isNan(sin(math.nan(f64))));
}
test "sin32 #9901" {
const float = @bitCast(f32, @as(u32, 0b11100011111111110000000000000000));
_ = sinf(float);
}
test "sin64 #9901" {
const float = @bitCast(f64, @as(u64, 0b1111111101000001000000001111110111111111100000000000000000000001));
_ = sin(float);
} | lib/std/special/compiler_rt/sin.zig |
const std = @import("std");
const Endian = std.builtin.Endian;
const assert = std.debug.assert;
const link = @import("../../link.zig");
const Module = @import("../../Module.zig");
const ErrorMsg = Module.ErrorMsg;
const Liveness = @import("../../Liveness.zig");
const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
const DW = std.dwarf;
const leb128 = std.leb;
const Emit = @This();
const Mir = @import("Mir.zig");
const bits = @import("bits.zig");
const Instruction = bits.Instruction;
const Register = bits.Register;
mir: Mir,
bin_file: *link.File,
debug_output: DebugInfoOutput,
target: *const std.Target,
err_msg: ?*ErrorMsg = null,
src_loc: Module.SrcLoc,
code: *std.ArrayList(u8),
prev_di_line: u32,
prev_di_column: u32,
/// Relative to the beginning of `code`.
prev_di_pc: usize,
const InnerError = error{
OutOfMemory,
EmitFail,
};
pub fn emitMir(
emit: *Emit,
) InnerError!void {
const mir_tags = emit.mir.instructions.items(.tag);
// Emit machine code
for (mir_tags) |tag, index| {
const inst = @intCast(u32, index);
switch (tag) {
.dbg_line => try emit.mirDbgLine(inst),
.dbg_prologue_end => try emit.mirDebugPrologueEnd(),
.dbg_epilogue_begin => try emit.mirDebugEpilogueBegin(),
.add => try emit.mirArithmetic3Op(inst),
.bpcc => @panic("TODO implement sparc64 bpcc"),
.call => @panic("TODO implement sparc64 call"),
.jmpl => try emit.mirArithmetic3Op(inst),
.ldub => try emit.mirArithmetic3Op(inst),
.lduh => try emit.mirArithmetic3Op(inst),
.lduw => try emit.mirArithmetic3Op(inst),
.ldx => try emit.mirArithmetic3Op(inst),
.@"or" => try emit.mirArithmetic3Op(inst),
.nop => try emit.mirNop(),
.@"return" => try emit.mirArithmetic2Op(inst),
.save => try emit.mirArithmetic3Op(inst),
.restore => try emit.mirArithmetic3Op(inst),
.sethi => try emit.mirSethi(inst),
.sllx => @panic("TODO implement sparc64 sllx"),
.stb => try emit.mirArithmetic3Op(inst),
.sth => try emit.mirArithmetic3Op(inst),
.stw => try emit.mirArithmetic3Op(inst),
.stx => try emit.mirArithmetic3Op(inst),
.sub => try emit.mirArithmetic3Op(inst),
.tcc => try emit.mirTrap(inst),
}
}
}
pub fn deinit(emit: *Emit) void {
emit.* = undefined;
}
fn mirDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void {
const tag = emit.mir.instructions.items(.tag)[inst];
const dbg_line_column = emit.mir.instructions.items(.data)[inst].dbg_line_column;
switch (tag) {
.dbg_line => try emit.dbgAdvancePCAndLine(dbg_line_column.line, dbg_line_column.column),
else => unreachable,
}
}
fn mirDebugPrologueEnd(emit: *Emit) !void {
switch (emit.debug_output) {
.dwarf => |dbg_out| {
try dbg_out.dbg_line.append(DW.LNS.set_prologue_end);
try emit.dbgAdvancePCAndLine(emit.prev_di_line, emit.prev_di_column);
},
.plan9 => {},
.none => {},
}
}
fn mirDebugEpilogueBegin(emit: *Emit) !void {
switch (emit.debug_output) {
.dwarf => |dbg_out| {
try dbg_out.dbg_line.append(DW.LNS.set_epilogue_begin);
try emit.dbgAdvancePCAndLine(emit.prev_di_line, emit.prev_di_column);
},
.plan9 => {},
.none => {},
}
}
fn mirArithmetic2Op(emit: *Emit, inst: Mir.Inst.Index) !void {
const tag = emit.mir.instructions.items(.tag)[inst];
const data = emit.mir.instructions.items(.data)[inst].arithmetic_2op;
const rs1 = data.rs1;
if (data.is_imm) {
const imm = data.rs2_or_imm.imm;
switch (tag) {
.@"return" => try emit.writeInstruction(Instruction.@"return"(i13, rs1, imm)),
else => unreachable,
}
} else {
const rs2 = data.rs2_or_imm.rs2;
switch (tag) {
.@"return" => try emit.writeInstruction(Instruction.@"return"(Register, rs1, rs2)),
else => unreachable,
}
}
}
fn mirArithmetic3Op(emit: *Emit, inst: Mir.Inst.Index) !void {
const tag = emit.mir.instructions.items(.tag)[inst];
const data = emit.mir.instructions.items(.data)[inst].arithmetic_3op;
const rd = data.rd;
const rs1 = data.rs1;
if (data.is_imm) {
const imm = data.rs2_or_imm.imm;
switch (tag) {
.add => try emit.writeInstruction(Instruction.add(i13, rs1, imm, rd)),
.jmpl => try emit.writeInstruction(Instruction.jmpl(i13, rs1, imm, rd)),
.ldub => try emit.writeInstruction(Instruction.ldub(i13, rs1, imm, rd)),
.lduh => try emit.writeInstruction(Instruction.lduh(i13, rs1, imm, rd)),
.lduw => try emit.writeInstruction(Instruction.lduw(i13, rs1, imm, rd)),
.ldx => try emit.writeInstruction(Instruction.ldx(i13, rs1, imm, rd)),
.@"or" => try emit.writeInstruction(Instruction.@"or"(i13, rs1, imm, rd)),
.save => try emit.writeInstruction(Instruction.save(i13, rs1, imm, rd)),
.restore => try emit.writeInstruction(Instruction.restore(i13, rs1, imm, rd)),
.stb => try emit.writeInstruction(Instruction.stb(i13, rs1, imm, rd)),
.sth => try emit.writeInstruction(Instruction.sth(i13, rs1, imm, rd)),
.stw => try emit.writeInstruction(Instruction.stw(i13, rs1, imm, rd)),
.stx => try emit.writeInstruction(Instruction.stx(i13, rs1, imm, rd)),
.sub => try emit.writeInstruction(Instruction.sub(i13, rs1, imm, rd)),
else => unreachable,
}
} else {
const rs2 = data.rs2_or_imm.rs2;
switch (tag) {
.add => try emit.writeInstruction(Instruction.add(Register, rs1, rs2, rd)),
.jmpl => try emit.writeInstruction(Instruction.jmpl(Register, rs1, rs2, rd)),
.ldub => try emit.writeInstruction(Instruction.ldub(Register, rs1, rs2, rd)),
.lduh => try emit.writeInstruction(Instruction.lduh(Register, rs1, rs2, rd)),
.lduw => try emit.writeInstruction(Instruction.lduw(Register, rs1, rs2, rd)),
.ldx => try emit.writeInstruction(Instruction.ldx(Register, rs1, rs2, rd)),
.@"or" => try emit.writeInstruction(Instruction.@"or"(Register, rs1, rs2, rd)),
.save => try emit.writeInstruction(Instruction.save(Register, rs1, rs2, rd)),
.restore => try emit.writeInstruction(Instruction.restore(Register, rs1, rs2, rd)),
.stb => try emit.writeInstruction(Instruction.stb(Register, rs1, rs2, rd)),
.sth => try emit.writeInstruction(Instruction.sth(Register, rs1, rs2, rd)),
.stw => try emit.writeInstruction(Instruction.stw(Register, rs1, rs2, rd)),
.stx => try emit.writeInstruction(Instruction.stx(Register, rs1, rs2, rd)),
.sub => try emit.writeInstruction(Instruction.sub(Register, rs1, rs2, rd)),
else => unreachable,
}
}
}
fn mirNop(emit: *Emit) !void {
try emit.writeInstruction(Instruction.nop());
}
fn mirSethi(emit: *Emit, inst: Mir.Inst.Index) !void {
const tag = emit.mir.instructions.items(.tag)[inst];
const data = emit.mir.instructions.items(.data)[inst].sethi;
const imm = data.imm;
const rd = data.rd;
assert(tag == .sethi);
try emit.writeInstruction(Instruction.sethi(imm, rd));
}
fn mirTrap(emit: *Emit, inst: Mir.Inst.Index) !void {
const tag = emit.mir.instructions.items(.tag)[inst];
const data = emit.mir.instructions.items(.data)[inst].trap;
const cond = data.cond;
const ccr = data.ccr;
const rs1 = data.rs1;
if (data.is_imm) {
const imm = data.rs2_or_imm.imm;
switch (tag) {
.tcc => try emit.writeInstruction(Instruction.trap(u7, cond, ccr, rs1, imm)),
else => unreachable,
}
} else {
const rs2 = data.rs2_or_imm.rs2;
switch (tag) {
.tcc => try emit.writeInstruction(Instruction.trap(Register, cond, ccr, rs1, rs2)),
else => unreachable,
}
}
}
// Common helper functions
fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {
const delta_line = @intCast(i32, line) - @intCast(i32, emit.prev_di_line);
const delta_pc: usize = emit.code.items.len - emit.prev_di_pc;
switch (emit.debug_output) {
.dwarf => |dbg_out| {
// TODO Look into using the DWARF special opcodes to compress this data.
// It lets you emit single-byte opcodes that add different numbers to
// both the PC and the line number at the same time.
try dbg_out.dbg_line.ensureUnusedCapacity(11);
dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.advance_pc);
leb128.writeULEB128(dbg_out.dbg_line.writer(), delta_pc) catch unreachable;
if (delta_line != 0) {
dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.advance_line);
leb128.writeILEB128(dbg_out.dbg_line.writer(), delta_line) catch unreachable;
}
dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.copy);
emit.prev_di_pc = emit.code.items.len;
emit.prev_di_line = line;
emit.prev_di_column = column;
emit.prev_di_pc = emit.code.items.len;
},
else => {},
}
}
fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
@setCold(true);
assert(emit.err_msg == null);
emit.err_msg = try ErrorMsg.create(emit.bin_file.allocator, emit.src_loc, format, args);
return error.EmitFail;
}
fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
// SPARCv9 instructions are always arranged in BE regardless of the
// endianness mode the CPU is running in (Section 3.1 of the ISA specification).
// This is to ease porting in case someone wants to do a LE SPARCv9 backend.
const endian = Endian.Big;
std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian);
} | src/arch/sparc64/Emit.zig |
const Object = @This();
const Atom = @import("Atom.zig");
const types = @import("types.zig");
const std = @import("std");
const Wasm = @import("../Wasm.zig");
const Symbol = @import("Symbol.zig");
const Allocator = std.mem.Allocator;
const leb = std.leb;
const meta = std.meta;
const log = std.log.scoped(.link);
/// Wasm spec version used for this `Object`
version: u32 = 0,
/// The file descriptor that represents the wasm object file.
file: ?std.fs.File = null,
/// Name (read path) of the object file.
name: []const u8,
/// Parsed type section
func_types: []const std.wasm.Type = &.{},
/// A list of all imports for this module
imports: []const types.Import = &.{},
/// Parsed function section
functions: []const std.wasm.Func = &.{},
/// Parsed table section
tables: []const std.wasm.Table = &.{},
/// Parsed memory section
memories: []const std.wasm.Memory = &.{},
/// Parsed global section
globals: []const std.wasm.Global = &.{},
/// Parsed export section
exports: []const types.Export = &.{},
/// Parsed element section
elements: []const std.wasm.Element = &.{},
/// Represents the function ID that must be called on startup.
/// This is `null` by default as runtimes may determine the startup
/// function themselves. This is essentially legacy.
start: ?u32 = null,
/// A slice of features that tell the linker what features are mandatory,
/// used (or therefore missing) and must generate an error when another
/// object uses features that are not supported by the other.
features: []const types.Feature = &.{},
/// A table that maps the relocations we must perform where the key represents
/// the section that the list of relocations applies to.
relocations: std.AutoArrayHashMapUnmanaged(u32, []types.Relocation) = .{},
/// Table of symbols belonging to this Object file
symtable: []Symbol = &.{},
/// Extra metadata about the linking section, such as alignment of segments and their name
segment_info: []const types.Segment = &.{},
/// A sequence of function initializers that must be called on startup
init_funcs: []const types.InitFunc = &.{},
/// Comdat information
comdat_info: []const types.Comdat = &.{},
/// Represents non-synthetic sections that can essentially be mem-cpy'd into place
/// after performing relocations.
relocatable_data: []const RelocatableData = &.{},
/// String table for all strings required by the object file, such as symbol names,
/// import name, module name and export names. Each string will be deduplicated
/// and returns an offset into the table.
string_table: Wasm.StringTable = .{},
/// Represents a single item within a section (depending on its `type`)
const RelocatableData = struct {
/// The type of the relocatable data
type: enum { data, code, custom },
/// Pointer to the data of the segment, where it's length is written to `size`
data: [*]u8,
/// The size in bytes of the data representing the segment within the section
size: u32,
/// The index within the section itself
index: u32,
/// The offset within the section where the data starts
offset: u32,
/// Represents the index of the section it belongs to
section_index: u32,
/// Returns the alignment of the segment, by retrieving it from the segment
/// meta data of the given object file.
/// NOTE: Alignment is encoded as a power of 2, so we shift the symbol's
/// alignment to retrieve the natural alignment.
pub fn getAlignment(self: RelocatableData, object: *const Object) u32 {
if (self.type != .data) return 1;
const data_alignment = object.segment_info[self.index].alignment;
if (data_alignment == 0) return 1;
// Decode from power of 2 to natural alignment
return @as(u32, 1) << @intCast(u5, data_alignment);
}
/// Returns the symbol kind that corresponds to the relocatable section
pub fn getSymbolKind(self: RelocatableData) Symbol.Tag {
return switch (self.type) {
.data => .data,
.code => .function,
.custom => .section,
};
}
};
pub const InitError = error{NotObjectFile} || ParseError || std.fs.File.ReadError;
/// Initializes a new `Object` from a wasm object file.
/// This also parses and verifies the object file.
pub fn create(gpa: Allocator, file: std.fs.File, path: []const u8) InitError!Object {
var object: Object = .{
.file = file,
.name = path,
};
var is_object_file: bool = false;
try object.parse(gpa, file.reader(), &is_object_file);
errdefer object.deinit(gpa);
if (!is_object_file) return error.NotObjectFile;
return object;
}
/// Frees all memory of `Object` at once. The given `Allocator` must be
/// the same allocator that was used when `init` was called.
pub fn deinit(self: *Object, gpa: Allocator) void {
for (self.func_types) |func_ty| {
gpa.free(func_ty.params);
gpa.free(func_ty.returns);
}
gpa.free(self.func_types);
gpa.free(self.functions);
gpa.free(self.imports);
gpa.free(self.tables);
gpa.free(self.memories);
gpa.free(self.globals);
gpa.free(self.exports);
for (self.elements) |el| {
gpa.free(el.func_indexes);
}
gpa.free(self.elements);
gpa.free(self.features);
for (self.relocations.values()) |val| {
gpa.free(val);
}
self.relocations.deinit(gpa);
gpa.free(self.symtable);
gpa.free(self.comdat_info);
gpa.free(self.init_funcs);
for (self.segment_info) |info| {
gpa.free(info.name);
}
gpa.free(self.segment_info);
for (self.relocatable_data) |rel_data| {
gpa.free(rel_data.data[0..rel_data.size]);
}
gpa.free(self.relocatable_data);
self.string_table.deinit(gpa);
self.* = undefined;
}
/// Finds the import within the list of imports from a given kind and index of that kind.
/// Asserts the import exists
pub fn findImport(self: *const Object, import_kind: std.wasm.ExternalKind, index: u32) types.Import {
var i: u32 = 0;
return for (self.imports) |import| {
if (std.meta.activeTag(import.kind) == import_kind) {
if (i == index) return import;
i += 1;
}
} else unreachable; // Only existing imports are allowed to be found
}
/// Counts the entries of imported `kind` and returns the result
pub fn importedCountByKind(self: *const Object, kind: std.wasm.ExternalKind) u32 {
var i: u32 = 0;
return for (self.imports) |imp| {
if (@as(std.wasm.ExternalKind, imp.kind) == kind) i += 1;
} else i;
}
/// Checks if the object file is an MVP version.
/// When that's the case, we check if there's an import table definiton with its name
/// set to '__indirect_function_table". When that's also the case,
/// we initialize a new table symbol that corresponds to that import and return that symbol.
///
/// When the object file is *NOT* MVP, we return `null`.
fn checkLegacyIndirectFunctionTable(self: *Object) !?Symbol {
var table_count: usize = 0;
for (self.symtable) |sym| {
if (sym.tag == .table) table_count += 1;
}
const import_table_count = self.importedCountByKind(.table);
// For each import table, we also have a symbol so this is not a legacy object file
if (import_table_count == table_count) return null;
if (table_count != 0) {
log.err("Expected a table entry symbol for each of the {d} table(s), but instead got {d} symbols.", .{
import_table_count,
table_count,
});
return error.MissingTableSymbols;
}
// MVP object files cannot have any table definitions, only imports (for the indirect function table).
if (self.tables.len > 0) {
log.err("Unexpected table definition without representing table symbols.", .{});
return error.UnexpectedTable;
}
if (import_table_count != 1) {
log.err("Found more than one table import, but no representing table symbols", .{});
return error.MissingTableSymbols;
}
var table_import: types.Import = for (self.imports) |imp| {
if (imp.kind == .table) {
break imp;
}
} else unreachable;
if (!std.mem.eql(u8, self.string_table.get(table_import.name), "__indirect_function_table")) {
log.err("Non-indirect function table import '{s}' is missing a corresponding symbol", .{self.string_table.get(table_import.name)});
return error.MissingTableSymbols;
}
var table_symbol: Symbol = .{
.flags = 0,
.name = table_import.name,
.tag = .table,
.index = 0,
};
table_symbol.setFlag(.WASM_SYM_UNDEFINED);
table_symbol.setFlag(.WASM_SYM_NO_STRIP);
return table_symbol;
}
/// Error set containing parsing errors.
/// Merged with reader's errorset by `Parser`
pub const ParseError = error{
/// The magic byte is either missing or does not contain \0Asm
InvalidMagicByte,
/// The wasm version is either missing or does not match the supported version.
InvalidWasmVersion,
/// Expected the functype byte while parsing the Type section but did not find it.
ExpectedFuncType,
/// Missing an 'end' opcode when defining a constant expression.
MissingEndForExpression,
/// Missing an 'end' opcode at the end of a body expression.
MissingEndForBody,
/// The size defined in the section code mismatches with the actual payload size.
MalformedSection,
/// Stream has reached the end. Unreachable for caller and must be handled internally
/// by the parser.
EndOfStream,
/// Ran out of memory when allocating.
OutOfMemory,
/// A non-zero flag was provided for comdat info
UnexpectedValue,
/// An import symbol contains an index to an import that does
/// not exist, or no imports were defined.
InvalidIndex,
/// The section "linking" contains a version that is not supported.
UnsupportedVersion,
/// When reading the data in leb128 compressed format, its value was overflown.
Overflow,
/// Found table definitions but no corresponding table symbols
MissingTableSymbols,
/// Did not expect a table definiton, but did find one
UnexpectedTable,
/// Object file contains a feature that is unknown to the linker
UnknownFeature,
};
fn parse(self: *Object, gpa: Allocator, reader: anytype, is_object_file: *bool) Parser(@TypeOf(reader)).Error!void {
var parser = Parser(@TypeOf(reader)).init(self, reader);
return parser.parseObject(gpa, is_object_file);
}
fn Parser(comptime ReaderType: type) type {
return struct {
const Self = @This();
const Error = ReaderType.Error || ParseError;
reader: std.io.CountingReader(ReaderType),
/// Object file we're building
object: *Object,
fn init(object: *Object, reader: ReaderType) Self {
return .{ .object = object, .reader = std.io.countingReader(reader) };
}
/// Verifies that the first 4 bytes contains \0Asm
fn verifyMagicBytes(self: *Self) Error!void {
var magic_bytes: [4]u8 = undefined;
try self.reader.reader().readNoEof(&magic_bytes);
if (!std.mem.eql(u8, &magic_bytes, &std.wasm.magic)) {
log.debug("Invalid magic bytes '{s}'", .{&magic_bytes});
return error.InvalidMagicByte;
}
}
fn parseObject(self: *Self, gpa: Allocator, is_object_file: *bool) Error!void {
try self.verifyMagicBytes();
const version = try self.reader.reader().readIntLittle(u32);
self.object.version = version;
var relocatable_data = std.ArrayList(RelocatableData).init(gpa);
defer relocatable_data.deinit();
var section_index: u32 = 0;
while (self.reader.reader().readByte()) |byte| : (section_index += 1) {
const len = try readLeb(u32, self.reader.reader());
var limited_reader = std.io.limitedReader(self.reader.reader(), len);
const reader = limited_reader.reader();
switch (@intToEnum(std.wasm.Section, byte)) {
.custom => {
const name_len = try readLeb(u32, reader);
const name = try gpa.alloc(u8, name_len);
defer gpa.free(name);
try reader.readNoEof(name);
if (std.mem.eql(u8, name, "linking")) {
is_object_file.* = true;
try self.parseMetadata(gpa, @intCast(usize, reader.context.bytes_left));
} else if (std.mem.startsWith(u8, name, "reloc")) {
try self.parseRelocations(gpa);
} else if (std.mem.eql(u8, name, "target_features")) {
try self.parseFeatures(gpa);
} else {
try reader.skipBytes(reader.context.bytes_left, .{});
}
},
.type => {
for (try readVec(&self.object.func_types, reader, gpa)) |*type_val| {
if ((try reader.readByte()) != std.wasm.function_type) return error.ExpectedFuncType;
for (try readVec(&type_val.params, reader, gpa)) |*param| {
param.* = try readEnum(std.wasm.Valtype, reader);
}
for (try readVec(&type_val.returns, reader, gpa)) |*result| {
result.* = try readEnum(std.wasm.Valtype, reader);
}
}
try assertEnd(reader);
},
.import => {
for (try readVec(&self.object.imports, reader, gpa)) |*import| {
const module_len = try readLeb(u32, reader);
const module_name = try gpa.alloc(u8, module_len);
defer gpa.free(module_name);
try reader.readNoEof(module_name);
const name_len = try readLeb(u32, reader);
const name = try gpa.alloc(u8, name_len);
defer gpa.free(name);
try reader.readNoEof(name);
const kind = try readEnum(std.wasm.ExternalKind, reader);
const kind_value: std.wasm.Import.Kind = switch (kind) {
.function => .{ .function = try readLeb(u32, reader) },
.memory => .{ .memory = try readLimits(reader) },
.global => .{ .global = .{
.valtype = try readEnum(std.wasm.Valtype, reader),
.mutable = (try reader.readByte()) == 0x01,
} },
.table => .{ .table = .{
.reftype = try readEnum(std.wasm.RefType, reader),
.limits = try readLimits(reader),
} },
};
import.* = .{
.module_name = try self.object.string_table.put(gpa, module_name),
.name = try self.object.string_table.put(gpa, name),
.kind = kind_value,
};
}
try assertEnd(reader);
},
.function => {
for (try readVec(&self.object.functions, reader, gpa)) |*func| {
func.* = .{ .type_index = try readLeb(u32, reader) };
}
try assertEnd(reader);
},
.table => {
for (try readVec(&self.object.tables, reader, gpa)) |*table| {
table.* = .{
.reftype = try readEnum(std.wasm.RefType, reader),
.limits = try readLimits(reader),
};
}
try assertEnd(reader);
},
.memory => {
for (try readVec(&self.object.memories, reader, gpa)) |*memory| {
memory.* = .{ .limits = try readLimits(reader) };
}
try assertEnd(reader);
},
.global => {
for (try readVec(&self.object.globals, reader, gpa)) |*global| {
global.* = .{
.global_type = .{
.valtype = try readEnum(std.wasm.Valtype, reader),
.mutable = (try reader.readByte()) == 0x01,
},
.init = try readInit(reader),
};
}
try assertEnd(reader);
},
.@"export" => {
for (try readVec(&self.object.exports, reader, gpa)) |*exp| {
const name_len = try readLeb(u32, reader);
const name = try gpa.alloc(u8, name_len);
defer gpa.free(name);
try reader.readNoEof(name);
exp.* = .{
.name = try self.object.string_table.put(gpa, name),
.kind = try readEnum(std.wasm.ExternalKind, reader),
.index = try readLeb(u32, reader),
};
}
try assertEnd(reader);
},
.start => {
self.object.start = try readLeb(u32, reader);
try assertEnd(reader);
},
.element => {
for (try readVec(&self.object.elements, reader, gpa)) |*elem| {
elem.table_index = try readLeb(u32, reader);
elem.offset = try readInit(reader);
for (try readVec(&elem.func_indexes, reader, gpa)) |*idx| {
idx.* = try readLeb(u32, reader);
}
}
try assertEnd(reader);
},
.code => {
var start = reader.context.bytes_left;
var index: u32 = 0;
const count = try readLeb(u32, reader);
while (index < count) : (index += 1) {
const code_len = try readLeb(u32, reader);
const offset = @intCast(u32, start - reader.context.bytes_left);
const data = try gpa.alloc(u8, code_len);
errdefer gpa.free(data);
try reader.readNoEof(data);
try relocatable_data.append(.{
.type = .code,
.data = data.ptr,
.size = code_len,
.index = self.object.importedCountByKind(.function) + index,
.offset = offset,
.section_index = section_index,
});
}
},
.data => {
var start = reader.context.bytes_left;
var index: u32 = 0;
const count = try readLeb(u32, reader);
while (index < count) : (index += 1) {
const flags = try readLeb(u32, reader);
const data_offset = try readInit(reader);
_ = flags; // TODO: Do we need to check flags to detect passive/active memory?
_ = data_offset;
const data_len = try readLeb(u32, reader);
const offset = @intCast(u32, start - reader.context.bytes_left);
const data = try gpa.alloc(u8, data_len);
errdefer gpa.free(data);
try reader.readNoEof(data);
try relocatable_data.append(.{
.type = .data,
.data = data.ptr,
.size = data_len,
.index = index,
.offset = offset,
.section_index = section_index,
});
}
},
else => try self.reader.reader().skipBytes(len, .{}),
}
} else |err| switch (err) {
error.EndOfStream => {}, // finished parsing the file
else => |e| return e,
}
self.object.relocatable_data = relocatable_data.toOwnedSlice();
}
/// Based on the "features" custom section, parses it into a list of
/// features that tell the linker what features were enabled and may be mandatory
/// to be able to link.
/// Logs an info message when an undefined feature is detected.
fn parseFeatures(self: *Self, gpa: Allocator) !void {
const reader = self.reader.reader();
for (try readVec(&self.object.features, reader, gpa)) |*feature| {
const prefix = try readEnum(types.Feature.Prefix, reader);
const name_len = try leb.readULEB128(u32, reader);
const name = try gpa.alloc(u8, name_len);
defer gpa.free(name);
try reader.readNoEof(name);
const tag = types.known_features.get(name) orelse {
log.err("Object file contains unknown feature: {s}", .{name});
return error.UnknownFeature;
};
feature.* = .{
.prefix = prefix,
.tag = tag,
};
}
}
/// Parses a "reloc" custom section into a list of relocations.
/// The relocations are mapped into `Object` where the key is the section
/// they apply to.
fn parseRelocations(self: *Self, gpa: Allocator) !void {
const reader = self.reader.reader();
const section = try leb.readULEB128(u32, reader);
const count = try leb.readULEB128(u32, reader);
const relocations = try gpa.alloc(types.Relocation, count);
errdefer gpa.free(relocations);
log.debug("Found {d} relocations for section ({d})", .{
count,
section,
});
for (relocations) |*relocation| {
const rel_type = try leb.readULEB128(u8, reader);
const rel_type_enum = @intToEnum(types.Relocation.RelocationType, rel_type);
relocation.* = .{
.relocation_type = rel_type_enum,
.offset = try leb.readULEB128(u32, reader),
.index = try leb.readULEB128(u32, reader),
.addend = if (rel_type_enum.addendIsPresent()) try leb.readULEB128(u32, reader) else null,
};
log.debug("Found relocation: type({s}) offset({d}) index({d}) addend({?d})", .{
@tagName(relocation.relocation_type),
relocation.offset,
relocation.index,
relocation.addend,
});
}
try self.object.relocations.putNoClobber(gpa, section, relocations);
}
/// Parses the "linking" custom section. Versions that are not
/// supported will be an error. `payload_size` is required to be able
/// to calculate the subsections we need to parse, as that data is not
/// available within the section itself.
fn parseMetadata(self: *Self, gpa: Allocator, payload_size: usize) !void {
var limited = std.io.limitedReader(self.reader.reader(), payload_size);
const limited_reader = limited.reader();
const version = try leb.readULEB128(u32, limited_reader);
log.debug("Link meta data version: {d}", .{version});
if (version != 2) return error.UnsupportedVersion;
while (limited.bytes_left > 0) {
try self.parseSubsection(gpa, limited_reader);
}
}
/// Parses a `spec.Subsection`.
/// The `reader` param for this is to provide a `LimitedReader`, which allows
/// us to only read until a max length.
///
/// `self` is used to provide access to other sections that may be needed,
/// such as access to the `import` section to find the name of a symbol.
fn parseSubsection(self: *Self, gpa: Allocator, reader: anytype) !void {
const sub_type = try leb.readULEB128(u8, reader);
log.debug("Found subsection: {s}", .{@tagName(@intToEnum(types.SubsectionType, sub_type))});
const payload_len = try leb.readULEB128(u32, reader);
if (payload_len == 0) return;
var limited = std.io.limitedReader(reader, payload_len);
const limited_reader = limited.reader();
// every subsection contains a 'count' field
const count = try leb.readULEB128(u32, limited_reader);
switch (@intToEnum(types.SubsectionType, sub_type)) {
.WASM_SEGMENT_INFO => {
const segments = try gpa.alloc(types.Segment, count);
errdefer gpa.free(segments);
for (segments) |*segment| {
const name_len = try leb.readULEB128(u32, reader);
const name = try gpa.alloc(u8, name_len);
errdefer gpa.free(name);
try reader.readNoEof(name);
segment.* = .{
.name = name,
.alignment = try leb.readULEB128(u32, reader),
.flags = try leb.readULEB128(u32, reader),
};
log.debug("Found segment: {s} align({d}) flags({b})", .{
segment.name,
segment.alignment,
segment.flags,
});
}
self.object.segment_info = segments;
},
.WASM_INIT_FUNCS => {
const funcs = try gpa.alloc(types.InitFunc, count);
errdefer gpa.free(funcs);
for (funcs) |*func| {
func.* = .{
.priority = try leb.readULEB128(u32, reader),
.symbol_index = try leb.readULEB128(u32, reader),
};
log.debug("Found function - prio: {d}, index: {d}", .{ func.priority, func.symbol_index });
}
self.object.init_funcs = funcs;
},
.WASM_COMDAT_INFO => {
const comdats = try gpa.alloc(types.Comdat, count);
errdefer gpa.free(comdats);
for (comdats) |*comdat| {
const name_len = try leb.readULEB128(u32, reader);
const name = try gpa.alloc(u8, name_len);
errdefer gpa.free(name);
try reader.readNoEof(name);
const flags = try leb.readULEB128(u32, reader);
if (flags != 0) {
return error.UnexpectedValue;
}
const symbol_count = try leb.readULEB128(u32, reader);
const symbols = try gpa.alloc(types.ComdatSym, symbol_count);
errdefer gpa.free(symbols);
for (symbols) |*symbol| {
symbol.* = .{
.kind = @intToEnum(types.ComdatSym.Type, try leb.readULEB128(u8, reader)),
.index = try leb.readULEB128(u32, reader),
};
}
comdat.* = .{
.name = name,
.flags = flags,
.symbols = symbols,
};
}
self.object.comdat_info = comdats;
},
.WASM_SYMBOL_TABLE => {
var symbols = try std.ArrayList(Symbol).initCapacity(gpa, count);
var i: usize = 0;
while (i < count) : (i += 1) {
const symbol = symbols.addOneAssumeCapacity();
symbol.* = try self.parseSymbol(gpa, reader);
log.debug("Found symbol: type({s}) name({s}) flags(0b{b:0>8})", .{
@tagName(symbol.tag),
self.object.string_table.get(symbol.name),
symbol.flags,
});
}
// we found all symbols, check for indirect function table
// in case of an MVP object file
if (try self.object.checkLegacyIndirectFunctionTable()) |symbol| {
try symbols.append(symbol);
log.debug("Found legacy indirect function table. Created symbol", .{});
}
self.object.symtable = symbols.toOwnedSlice();
},
}
}
/// Parses the symbol information based on its kind,
/// requires access to `Object` to find the name of a symbol when it's
/// an import and flag `WASM_SYM_EXPLICIT_NAME` is not set.
fn parseSymbol(self: *Self, gpa: Allocator, reader: anytype) !Symbol {
const tag = @intToEnum(Symbol.Tag, try leb.readULEB128(u8, reader));
const flags = try leb.readULEB128(u32, reader);
var symbol: Symbol = .{
.flags = flags,
.tag = tag,
.name = undefined,
.index = undefined,
};
switch (tag) {
.data => {
const name_len = try leb.readULEB128(u32, reader);
const name = try gpa.alloc(u8, name_len);
defer gpa.free(name);
try reader.readNoEof(name);
symbol.name = try self.object.string_table.put(gpa, name);
// Data symbols only have the following fields if the symbol is defined
if (symbol.isDefined()) {
symbol.index = try leb.readULEB128(u32, reader);
// @TODO: We should verify those values
_ = try leb.readULEB128(u32, reader);
_ = try leb.readULEB128(u32, reader);
}
},
.section => {
symbol.index = try leb.readULEB128(u32, reader);
symbol.name = try self.object.string_table.put(gpa, @tagName(symbol.tag));
},
else => {
symbol.index = try leb.readULEB128(u32, reader);
var maybe_import: ?types.Import = null;
const is_undefined = symbol.isUndefined();
if (is_undefined) {
maybe_import = self.object.findImport(symbol.tag.externalType(), symbol.index);
}
const explicit_name = symbol.hasFlag(.WASM_SYM_EXPLICIT_NAME);
if (!(is_undefined and !explicit_name)) {
const name_len = try leb.readULEB128(u32, reader);
const name = try gpa.alloc(u8, name_len);
defer gpa.free(name);
try reader.readNoEof(name);
symbol.name = try self.object.string_table.put(gpa, name);
} else {
symbol.name = maybe_import.?.name;
}
},
}
return symbol;
}
};
}
/// First reads the count from the reader and then allocate
/// a slice of ptr child's element type.
fn readVec(ptr: anytype, reader: anytype, gpa: Allocator) ![]ElementType(@TypeOf(ptr)) {
const len = try readLeb(u32, reader);
const slice = try gpa.alloc(ElementType(@TypeOf(ptr)), len);
ptr.* = slice;
return slice;
}
fn ElementType(comptime ptr: type) type {
return meta.Elem(meta.Child(ptr));
}
/// Uses either `readILEB128` or `readULEB128` depending on the
/// signedness of the given type `T`.
/// Asserts `T` is an integer.
fn readLeb(comptime T: type, reader: anytype) !T {
if (comptime std.meta.trait.isSignedInt(T)) {
return try leb.readILEB128(T, reader);
} else {
return try leb.readULEB128(T, reader);
}
}
/// Reads an enum type from the given reader.
/// Asserts `T` is an enum
fn readEnum(comptime T: type, reader: anytype) !T {
switch (@typeInfo(T)) {
.Enum => |enum_type| return @intToEnum(T, try readLeb(enum_type.tag_type, reader)),
else => @compileError("T must be an enum. Instead was given type " ++ @typeName(T)),
}
}
fn readLimits(reader: anytype) !std.wasm.Limits {
const flags = try readLeb(u1, reader);
const min = try readLeb(u32, reader);
return std.wasm.Limits{
.min = min,
.max = if (flags == 0) null else try readLeb(u32, reader),
};
}
fn readInit(reader: anytype) !std.wasm.InitExpression {
const opcode = try reader.readByte();
const init_expr: std.wasm.InitExpression = switch (@intToEnum(std.wasm.Opcode, opcode)) {
.i32_const => .{ .i32_const = try readLeb(i32, reader) },
.global_get => .{ .global_get = try readLeb(u32, reader) },
else => @panic("TODO: initexpression for other opcodes"),
};
if ((try readEnum(std.wasm.Opcode, reader)) != .end) return error.MissingEndForExpression;
return init_expr;
}
fn assertEnd(reader: anytype) !void {
var buf: [1]u8 = undefined;
const len = try reader.read(&buf);
if (len != 0) return error.MalformedSection;
if (reader.context.bytes_left != 0) return error.MalformedSection;
}
/// Parses an object file into atoms, for code and data sections
pub fn parseIntoAtoms(self: *Object, gpa: Allocator, object_index: u16, wasm_bin: *Wasm) !void {
log.debug("Parsing data section into atoms", .{});
const Key = struct {
kind: Symbol.Tag,
index: u32,
};
var symbol_for_segment = std.AutoArrayHashMap(Key, u32).init(gpa);
defer symbol_for_segment.deinit();
for (self.symtable) |symbol, symbol_index| {
switch (symbol.tag) {
.function, .data => if (!symbol.isUndefined()) {
try symbol_for_segment.putNoClobber(
.{ .kind = symbol.tag, .index = symbol.index },
@intCast(u32, symbol_index),
);
},
else => continue,
}
}
for (self.relocatable_data) |relocatable_data, index| {
const sym_index = symbol_for_segment.get(.{
.kind = relocatable_data.getSymbolKind(),
.index = @intCast(u32, relocatable_data.index),
}) orelse continue; // encountered a segment we do not create an atom for
const final_index = try wasm_bin.getMatchingSegment(object_index, @intCast(u32, index));
const atom = try gpa.create(Atom);
atom.* = Atom.empty;
errdefer {
atom.deinit(gpa);
gpa.destroy(atom);
}
try wasm_bin.managed_atoms.append(gpa, atom);
atom.file = object_index;
atom.size = relocatable_data.size;
atom.alignment = relocatable_data.getAlignment(self);
atom.sym_index = sym_index;
const relocations: []types.Relocation = self.relocations.get(relocatable_data.section_index) orelse &.{};
for (relocations) |relocation| {
if (isInbetween(relocatable_data.offset, atom.size, relocation.offset)) {
// set the offset relative to the offset of the segment itself,
// rather than within the entire section.
var reloc = relocation;
reloc.offset -= relocatable_data.offset;
try atom.relocs.append(gpa, reloc);
if (relocation.isTableIndex()) {
try wasm_bin.function_table.putNoClobber(gpa, .{
.file = object_index,
.index = relocation.index,
}, 0);
}
}
}
try atom.code.appendSlice(gpa, relocatable_data.data[0..relocatable_data.size]);
try wasm_bin.symbol_atom.putNoClobber(gpa, atom.symbolLoc(), atom);
const segment: *Wasm.Segment = &wasm_bin.segments.items[final_index];
segment.alignment = std.math.max(segment.alignment, atom.alignment);
if (wasm_bin.atoms.getPtr(final_index)) |last| {
last.*.next = atom;
atom.prev = last.*;
last.* = atom;
} else {
try wasm_bin.atoms.putNoClobber(gpa, final_index, atom);
}
log.debug("Parsed into atom: '{s}'", .{self.string_table.get(self.symtable[atom.sym_index].name)});
}
}
/// Verifies if a given value is in between a minimum -and maximum value.
/// The maxmimum value is calculated using the length, both start and end are inclusive.
inline fn isInbetween(min: u32, length: u32, value: u32) bool {
return value >= min and value <= min + length;
} | src/link/Wasm/Object.zig |
const std = @import("std");
const mem = std.mem;
// Bytes of changeable prefix. This doesn't need to be large, as we
// aren't really using it as a key (it will almost always just be
// '1').
const prefix_length = 4;
// We can use a Sha hasher by appending the prefix to the init.
// For Siphash, the prefix will be used as the prefix of the data.
const Sha256Hasher = struct {
pub const T = std.crypto.hash.sha2.Sha256;
pub const digest_length = T.digest_length;
pub fn init(prefix: *const [prefix_length]u8) T {
var hh = T.init(.{});
hh.update(prefix);
return hh;
}
};
const SipHasher = struct {
pub const T = std.crypto.auth.siphash.SipHash64(2, 4);
pub const digest_length = T.mac_length;
pub fn init(prefix: *const [prefix_length]u8) T {
var buf: [T.key_length]u8 = @splat(T.key_length, @as(u8, 0));
mem.copy(u8, buf[0..prefix_length], prefix);
return T.init(&buf);
}
};
pub const Hasher = if (false) Sha256Hasher else SipHasher;
const config = @import("config.zig");
const sys = @import("sys.zig");
const SimFlash = sys.flash.SimFlash;
const Status = @import("status.zig").Self;
/// Swap manages the operation and progress of the swap operation.
/// This struct is intended to be maintained statically, and the init
/// function initializes an uninitialized variant of the struct.
pub const Swap = struct {
const Self = @This();
/// For now, the page size is shared. If the devices have
/// differing page sizes, this should be set to the larger value.
pub const page_size: usize = 512;
pub const page_shift: std.math.Log2Int(usize) = std.math.log2_int(usize, page_size);
pub const max_pages: usize = config.max_pages;
pub const max_work: usize = max_pages;
/// Hashes are stored with this type.
pub const hash_bytes = 4;
pub const Hash = [hash_bytes]u8;
const WorkArray = std.BoundedArray(Work, max_work);
/// Temporary buffers.
tmp: [page_size]u8 = undefined,
tmp2: [page_size]u8 = undefined,
/// The sizes of the two images. This includes all of the data
/// that needs to be copied: header, image, and TLV/manifest.
sizes: [2]usize,
/// Pointers to the flash areas.
areas: [2]*sys.flash.FlashArea,
/// Local storage for the hashes.
hashes: [2][max_pages]Hash = undefined,
/// To handle hash collisions, this value is prefixed the the data
/// hashed. If we detect a collision, this can be changed, and we
/// restart the operation.
prefix: [4]u8,
/// The manager for the status.
status: [2]Status,
/// The built up work.
work: [2]WorkArray,
/// TODO: work, etc.
/// Like 'init', but initializes an already allocated value.
pub fn init(sim: *sys.flash.SimFlash, sizes: [2]usize, prefix: u32) !Self {
var a = try sim.open(0); // TODO: Better numbers.
var b = try sim.open(1);
var bprefix: [4]u8 = undefined;
mem.copy(u8, bprefix[0..], mem.asBytes(&prefix));
return Self{
.areas = [2]*sys.flash.FlashArea{ a, b },
.sizes = sizes,
.prefix = bprefix,
.status = [2]Status{ try Status.init(a), try Status.init(b) },
.work = .{ try WorkArray.init(0), try WorkArray.init(0) },
};
}
/// Starting process. This attempts to determine what needs to be
/// done based on the status pages.
pub fn startup(self: *Self) !void {
// std.log.info("--- Running startup", .{});
const st0 = try self.status[0].scan();
const st1 = try self.status[1].scan();
var initial = false;
if (st0 == .Unknown and st1 == .Request) {
// Initial request for work. Compute hashes over all of
// the data.
try self.oneHash(0);
try self.oneHash(1);
// Write this status out, which should move us on to the
// first phase.
// std.log.info("Writing initial status", .{});
try self.status[0].startStatus(self);
initial = true;
} else if (st1 == .Request and (st0 == .Slide or st0 == .Swap)) {
// The swap operation was interrupted, load the status so
// that we can then try to recover where we left off.
try self.status[0].loadStatus(self);
} else {
std.log.err("Unsupport status config {},{}", .{ st0, st1 });
return error.StateError;
}
// std.log.warn("Recover at state: {}", .{st0});
// Build the work data.
try self.workSlide0(initial);
try self.workSwap(initial);
// If we didn't just start from "Request", we need to recover
// our state.
var restart = Recovered{ .work = 0, .step = 0 };
if (st0 == .Slide or st0 == .Swap) {
restart = try self.recover(st0);
}
try self.performWork(restart);
}
const Recovered = struct {
work: usize,
step: usize,
};
// Perform recovery. The initial state will tell us what work
// phase we are in, and we will consider that work to be partially
// completed. Within that phase, we scan the work list, looking
// for the first item that clearly has not been performed
// (destination does not match). Once we've found that, back up
// on, if possible, since we don't know if the one we found was
// partially done, or just not done at all.
fn recover(self: *Self, phase: Status.Phase) !Recovered {
const workNo = try phase.whichWork();
// std.log.info("Recovering work: {}", .{workNo});
// Scan through the work list, stopping at the first entry
// where the destination doesn't appear to have been written.
var i: usize = 0;
while (i < self.work[workNo].len) : (i += 1) {
const item = &self.work[workNo].buffer[i];
const wstate = self.areas[item.dest_slot].getState(item.dest_page << page_shift) catch {
break;
};
if (wstate != .Written) {
// If it doesn't look written, assume not, and this is
// valid.
break;
}
// If it is written, check if it has the correctly written
// hash.
// std.log.info("Page {} is {}", .{ i, wstate });
// std.log.info(" work: {s}", .{fmtWork(item)});
var hash: [hash_bytes]u8 = undefined;
if (self.hashPage(&hash, item.dest_slot, item.dest_page << page_shift, item.size)) |_| {} else |_| {
// Consider read errors as just the data not being
// valid. Whether a given page will read as an error
// or not depends on the device.
break;
}
if (!mem.eql(u8, &hash, &item.hash)) {
break;
}
}
// At this point, unless we are on the first work item, go
// backwards one work step, and redo that, if the source is
// still present.
// std.log.info("Recover at {}", .{i});
if (i > 0) {
const item = &self.work[workNo].buffer[i - 1];
if (self.areas[item.src_slot].getState(item.src_page << page_shift)) |rstate| {
if (rstate != .Written) {
// Unreadable, don't back up.
} else {
var hash: [hash_bytes]u8 = undefined;
if (self.hashPage(&hash, item.src_slot, item.src_page << page_shift, item.size)) |_| {
// Only stay back on if the hash didn't work
// out.
if (mem.eql(u8, &hash, &item.hash)) {
i -= 1;
}
} else |_| {}
}
} else |_| {
// Unreadable, don't back up.
}
// std.log.info(" moved to {}", .{i});
}
return Recovered{ .work = workNo, .step = i };
}
fn oneHash(self: *Self, slot: usize) !void {
var pos: usize = 0;
var page: usize = 0;
while (pos < self.sizes[slot]) : (pos += page_size) {
const count = std.math.min(self.sizes[slot] - pos, page_size);
try self.hashPage(self.hashes[slot][page][0..], slot, pos, count);
// std.log.info("Hashed: slot {}, page {}, {s} ({} bytes)", .{
// slot, page,
// std.fmt.fmtSliceHexLower(self.hashes[slot][page][0..]), count,
// });
page += 1;
}
}
// Checking for internal testing.
fn checkHash(self: *Self, item: *const Work, buf: []const u8) !void {
var dest: [Hasher.digest_length]u8 = undefined;
var hh = Hasher.init(&self.prefix);
hh.update(buf[0..item.size]);
hh.final(dest[0..]);
if (std.testing.expectEqualSlices(u8, &item.hash, dest[0..hash_bytes])) |_| {} else |err| {
std.log.warn("Hash mismatch, expect: {s}, got: {s} ({} bytes)", .{
std.fmt.fmtSliceHexLower(item.hash[0..]),
std.fmt.fmtSliceHexLower(dest[0..hash_bytes]),
item.size,
});
return err;
}
}
fn hashPage(self: *Self, dest: []u8, slot: usize, offset: usize, count: usize) !void {
var hh = Hasher.init(&self.prefix);
try self.areas[slot].read(offset, self.tmp[0..count]);
hh.update(self.tmp[0..count]);
var hash: [Hasher.digest_length]u8 = undefined;
hh.final(hash[0..]);
mem.copy(u8, dest[0..], hash[0..hash_bytes]);
}
// This is used by the status code to verify its contents. We
// just use an empty prefix.
pub fn calcHash(data: []const u8) [hash_bytes]u8 {
const prefix: [prefix_length]u8 = @splat(prefix_length, @as(u8, 0));
var hh = Hasher.init(&prefix);
hh.update(data);
var hash: [Hasher.digest_length]u8 = undefined;
hh.final(hash[0..]);
var result: [hash_bytes]u8 = undefined;
mem.copy(u8, result[0..], hash[0..4]);
return result;
}
// Compute the work for sliding slot 0 down by one.
pub fn workSlide0(self: *Self, initial: bool) !void {
const bound = self.calcBound(0);
// Pos is the destination of each page.
var pos: usize = bound.count;
while (pos > 0) : (pos -= 1) {
const size = bound.getSize(pos - 1);
if (pos < bound.count and try self.validateSame(.{ 0, 0 }, .{ pos - 1, pos }, size, initial))
continue;
try self.work[0].append(.{
.src_slot = 0,
.dest_slot = 0,
.size = @intCast(u16, size),
.src_page = pos - 1,
.dest_page = pos,
.hash = self.hashes[0][pos - 1],
});
// self.hashes[0][pos] = self.hashes[0][pos - 1];
}
}
// Compute the work for swapping the two images. For a layout
// such as this:
// slot 0 | slot 1
// X | A1
// A0 | B1
// B0 | C1
// C0 | D1
// we want to move A1 to slot 0, and A0 to slot 1. This
// continues, stopping either the left or right movement when we
// have exceeded the size for that side.
fn workSwap(self: *Self, initial: bool) !void {
const bound0 = self.calcBound(0);
const bound1 = self.calcBound(1);
// std.log.warn("bound0: {}", .{bound0});
// std.log.warn("bound1: {}", .{bound1});
// At a given pos, we move slot1,pos to slot0,pos, and
// slot0,pos+1 to slot1.pos.
var pos: usize = 0;
while (pos < bound0.count or pos < bound1.count) : (pos += 1) {
// Move slot 1 to 0.
if (pos < bound1.count) {
const size = bound1.getSize(pos);
// std.log.info("1->0 {}, {}", .{ pos, size });
if (pos < bound0.count and try self.validateSame(.{ 1, 0 }, .{ pos, pos }, size, initial))
continue;
try self.work[1].append(.{
.src_slot = 1,
.src_page = pos,
.dest_slot = 0,
.dest_page = pos,
.size = @intCast(u16, size),
.hash = self.hashes[1][pos],
});
// self.hashes[0][pos] = self.hashes[1][pos];
}
// Move slot 0 to 1.
if (pos < bound0.count) {
const size = bound0.getSize(pos);
if (pos < bound1.count and try self.validateSame(.{ 0, 1 }, .{ pos + 1, pos }, size, initial))
continue;
try self.work[1].append(.{
.src_slot = 0,
.src_page = pos + 1,
.dest_slot = 1,
.dest_page = pos,
.size = @intCast(u16, size),
.hash = self.hashes[0][pos],
});
// self.hashes[1][pos] = self.hashes[0][pos + 1];
}
}
}
/// Perform the work we've set ourselves to do.
fn performWork(self: *Self, next: Recovered) !void {
// std.log.warn("Performing work", .{});
var i: usize = next.work;
while (i < self.work.len) : (i += 1) {
const work = &self.work[i];
// std.log.warn("Work, phase: {}", .{i});
var step: usize = 0;
if (i == next.work) {
step = next.step;
}
while (step < work.len) : (step += 1) {
const item = &work.buffer[step];
// std.log.warn("Work: {s}", .{fmtWork(item)});
try self.areas[item.dest_slot].erase(item.dest_page << page_shift, page_size);
try self.areas[item.src_slot].read(item.src_page << page_shift, self.tmp[0..]);
try self.checkHash(item, self.tmp[0..]);
try self.areas[item.dest_slot].write(item.dest_page << page_shift, self.tmp[0..]);
}
// If we finish Sliding, we need to write a new status
// page.
if (i == 0) {
try self.status[0].updateStatus(.Swap);
}
}
}
/// Return an iterator over all of the hashes.
pub fn iterHashes(self: *Self) HashIter {
return .{
.state = self,
.phase = 0,
.pos = 0,
};
}
pub const HashIter = struct {
const HSelf = @This();
state: *Self,
phase: usize,
pos: usize,
pub fn next(self: *HSelf) ?*[hash_bytes]u8 {
while (true) {
if (self.phase >= 2)
return null;
if (self.pos >= asPages(self.state.sizes[self.phase])) {
self.pos = 0;
self.phase += 1;
} else {
break;
}
}
const result = &self.state.hashes[self.phase][self.pos];
self.pos += 1;
return result;
}
};
fn asPages(value: usize) usize {
return (value + page_size - 1) >> page_shift;
}
// For testing, set 'sizes' and fill in some hashes for the given
// image "sizes".
pub fn fakeHashes(self: *Self, sizes: [2]usize) !void {
self.sizes = sizes;
self.prefix = [4]u8{ 1, 2, 3, 4 };
var slot: usize = 0;
while (slot < 2) : (slot += 1) {
var pos: usize = 0;
var page: usize = 0;
while (pos < self.sizes[slot]) : (pos += page_size) {
var hh = Hasher.init(&self.prefix);
const num: usize = slot * max_pages * page_size + pos;
hh.update(std.mem.asBytes(&num));
var hash: [Hasher.digest_length]u8 = undefined;
hh.final(hash[0..]);
std.mem.copy(u8, self.hashes[slot][page][0..], hash[0..hash_bytes]);
// std.log.warn("hash: {} 0x{any}", .{ page, self.hashes[slot][page] });
page += 1;
}
}
}
// For testing, compare the generated sizes and hashes to make
// sure they have been recovered correctly.
pub fn checkFakeHashes(self: *Self, sizes: [2]usize) !void {
try std.testing.expectEqualSlices(usize, sizes[0..], self.sizes[0..]);
try std.testing.expectEqual([4]u8{ 1, 2, 3, 4 }, self.prefix);
var slot: usize = 0;
while (slot < 2) : (slot += 1) {
var pos: usize = 0;
var page: usize = 0;
while (pos < self.sizes[slot]) : (pos += page_size) {
var hh = Hasher.init(&self.prefix);
const num: usize = slot * max_pages * page_size + pos;
hh.update(std.mem.asBytes(&num));
var hash: [Hasher.digest_length]u8 = undefined;
hh.final(hash[0..]);
// std.log.warn("Checking: {} in slot {}", .{ page, slot });
try std.testing.expectEqualSlices(u8, hash[0..hash_bytes], self.hashes[slot][page][0..]);
page += 1;
}
}
}
const Bound = struct {
// This is the number of pages in the region to move.
count: usize,
// The number of bytes in the last page. Will be page_size if
// this image is a multiple of the page size.
partial: usize,
fn getSize(self: *const Bound, page: usize) usize {
var size = page_size;
if (page == self.count - 1)
size = self.partial;
// std.log.info("getSize: bound:{}, page:{} -> {}", .{ self, page, size });
return size;
}
};
fn calcBound(self: *const Self, slot: usize) Bound {
const count = (self.sizes[slot] + (page_size - 1)) >> page_shift;
var partial = self.sizes[slot] & (page_size - 1);
if (partial == 0)
partial = page_size;
// std.log.warn("Bound: size: {}, count: {}, partial: {}", .{ self.sizes[slot], count, partial });
return Bound{
.count = count,
.partial = partial,
};
}
// Ensure that two pages that have the same hash are actually the
// same. Returns error.HashCollision if they differ, which will
// result in higher-level code retrying with a different prefix.
fn validateSame(self: *Self, slots: [2]u8, pages: [2]usize, len: usize, initial: bool) !bool {
if (std.mem.eql(
u8,
self.hashes[slots[0]][pages[0]][0..],
self.hashes[slots[1]][pages[1]][0..],
)) {
if (initial)
return true;
// If the hashes match, compare the page contents.
std.log.err("TODO: Page comparison slots {any}, pages {any}", .{ slots, pages });
_ = len;
unreachable;
} else {
return false;
}
}
};
/// A unit of work describes the move of one page of data in flash.
const Work = struct {
src_slot: u8,
dest_slot: u8,
size: u16,
src_page: usize,
dest_page: usize,
// The hash we're intending to move.
hash: Swap.Hash,
};
/// Wrap work with a nicer formatter.
fn fmtWork(w: *const Work) std.fmt.Formatter(formatWork) {
return .{ .data = w };
}
fn formatWork(
data: *const Work,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
_ = data;
_ = fmt;
_ = options;
_ = writer;
try std.fmt.format(writer, "Work{{src:{:>3}/{:>3}, dest:{:>3}/{:>3}, size:{:>3}, hash:{}}}", .{
data.src_slot,
data.src_page,
data.dest_slot,
data.dest_page,
data.size,
std.fmt.fmtSliceHexLower(data.hash[0..]),
});
}
const RecoveryTest = struct {
const Self = @This();
const testing = std.testing;
const BootTest = @import("test.zig").BootTest;
// These are just sizes we will use for testing.
const testSizes = if (true)
[2]usize{ 112 * Swap.page_size + 7, 105 * Swap.page_size + Swap.page_size - 1 }
else
[2]usize{ 2 * Swap.page_size + 7, 1 * Swap.page_size + Swap.page_size - 1 };
bt: BootTest,
fn init() !RecoveryTest {
var bt = try BootTest.init(testing.allocator, BootTest.lpc55s69);
errdefer bt.deinit();
return Self{
.bt = bt,
};
}
fn deinit(self: *Self) void {
self.bt.deinit();
}
fn single(self: *Self, limit: usize, sizes: [2]usize) !void {
var lim: usize = limit;
while (true) : (lim += 1) {
std.log.info("##### Testing limit {} #####", .{lim});
try self.bt.sim.installImages(sizes);
var swap = try Swap.init(&self.bt.sim, sizes, 1);
// Writing the magic to slot 1 initiates an upgrade.
try swap.status[1].writeMagic();
// Set our limit, stopping after that many flash steps.
self.bt.sim.counter.reset();
try self.bt.sim.counter.setLimit(lim);
// TODO: Handle hash collision, restarting as appropriate.
var interrupted = false;
if (swap.startup()) |_| {
std.log.info("Counter reset after {} steps", .{self.bt.sim.counter.current});
} else |err| {
if (err != error.Expired)
return err;
interrupted = true;
// std.log.info("---------------------- Interrupt --------------------", .{});
}
if (interrupted) {
// Retry the startup, as if we reached a fresh start.
self.bt.sim.counter.reset();
swap = try Swap.init(&self.bt.sim, sizes, 1);
// Run a new startup. This should always run to completion.
try swap.startup();
}
// Check that the swap completed.
// std.log.info("Verifying flash", .{});
try self.bt.sim.verifyImages(sizes);
if (!interrupted)
break;
}
}
};
test "Swap recovery" {
std.testing.log_level = .info;
var tt = try RecoveryTest.init();
defer tt.deinit();
try tt.single(1, RecoveryTest.testSizes);
// Write out the swap status.
try (try tt.bt.sim.open(0)).save("swap-0.bin");
try (try tt.bt.sim.open(1)).save("swap-1.bin");
} | src/swap.zig |
const std = @import("std");
const Feature = @import("enums.zig").Feature;
const ErrorType = @import("enums.zig").ErrorType;
const ErrorFilter = @import("enums.zig").ErrorFilter;
const Limits = @import("data.zig").Limits;
const LoggingType = @import("enums.zig").LoggingType;
const ErrorCallback = @import("structs.zig").ErrorCallback;
const LoggingCallback = @import("structs.zig").LoggingCallback;
const Queue = @import("Queue.zig");
const ShaderModule = @import("ShaderModule.zig");
const Surface = @import("Surface.zig");
const SwapChain = @import("SwapChain.zig");
const RenderPipeline = @import("RenderPipeline.zig");
const CommandEncoder = @import("CommandEncoder.zig");
const ComputePipeline = @import("ComputePipeline.zig");
const BindGroup = @import("BindGroup.zig");
const BindGroupLayout = @import("BindGroupLayout.zig");
const Buffer = @import("Buffer.zig");
const ExternalTexture = @import("ExternalTexture.zig");
const PipelineLayout = @import("PipelineLayout.zig");
const QuerySet = @import("QuerySet.zig");
const RenderBundleEncoder = @import("RenderBundleEncoder.zig");
const Sampler = @import("Sampler.zig");
const Texture = @import("Texture.zig");
const Device = @This();
/// The features supported by the device (i.e. the ones with which it was created).
features: []Feature,
_features: [std.enums.values(Feature).len]Feature = undefined,
/// The limits supported by the device (which are exactly the ones with which it was created).
limits: Limits,
/// The type erased pointer to the Device implementation
/// Equal to c.WGPUDevice for NativeInstance.
ptr: *anyopaque,
vtable: *const VTable,
pub const VTable = struct {
reference: fn (ptr: *anyopaque) void,
release: fn (ptr: *anyopaque) void,
createBindGroup: fn (ptr: *anyopaque, descriptor: *const BindGroup.Descriptor) BindGroup,
createBindGroupLayout: fn (ptr: *anyopaque, descriptor: *const BindGroupLayout.Descriptor) BindGroupLayout,
createBuffer: fn (ptr: *anyopaque, descriptor: *const Buffer.Descriptor) Buffer,
createCommandEncoder: fn (ptr: *anyopaque, descriptor: ?*const CommandEncoder.Descriptor) CommandEncoder,
createComputePipeline: fn (ptr: *anyopaque, descriptor: *const ComputePipeline.Descriptor) ComputePipeline,
createComputePipelineAsync: fn (
ptr: *anyopaque,
descriptor: *const ComputePipeline.Descriptor,
callback: *ComputePipeline.CreateCallback,
) void,
createErrorBuffer: fn (ptr: *anyopaque) Buffer,
createExternalTexture: fn (ptr: *anyopaque, descriptor: *const ExternalTexture.Descriptor) ExternalTexture,
createPipelineLayout: fn (ptr: *anyopaque, descriptor: *const PipelineLayout.Descriptor) PipelineLayout,
createQuerySet: fn (ptr: *anyopaque, descriptor: *const QuerySet.Descriptor) QuerySet,
createRenderBundleEncoder: fn (ptr: *anyopaque, descriptor: *const RenderBundleEncoder.Descriptor) RenderBundleEncoder,
createRenderPipeline: fn (ptr: *anyopaque, descriptor: *const RenderPipeline.Descriptor) RenderPipeline,
createRenderPipelineAsync: fn (
ptr: *anyopaque,
descriptor: *const RenderPipeline.Descriptor,
callback: *RenderPipeline.CreateCallback,
) void,
createSampler: fn (ptr: *anyopaque, descriptor: *const Sampler.Descriptor) Sampler,
createShaderModule: fn (ptr: *anyopaque, descriptor: *const ShaderModule.Descriptor) ShaderModule,
nativeCreateSwapChain: fn (ptr: *anyopaque, surface: ?Surface, descriptor: *const SwapChain.Descriptor) SwapChain,
createTexture: fn (ptr: *anyopaque, descriptor: *const Texture.Descriptor) Texture,
destroy: fn (ptr: *anyopaque) void,
getQueue: fn (ptr: *anyopaque) Queue,
injectError: fn (ptr: *anyopaque, type: ErrorType, message: [*:0]const u8) void,
loseForTesting: fn (ptr: *anyopaque) void,
popErrorScope: fn (ptr: *anyopaque, callback: *ErrorCallback) bool,
pushErrorScope: fn (ptr: *anyopaque, filter: ErrorFilter) void,
setLostCallback: fn (ptr: *anyopaque, callback: *LostCallback) void,
setLoggingCallback: fn (ptr: *anyopaque, callback: *LoggingCallback) void,
setUncapturedErrorCallback: fn (ptr: *anyopaque, callback: *ErrorCallback) void,
tick: fn (ptr: *anyopaque) void,
};
pub inline fn reference(device: Device) void {
device.vtable.reference(device.ptr);
}
pub inline fn release(device: Device) void {
device.vtable.release(device.ptr);
}
/// Tests of the device has this feature & was created with it.
pub fn hasFeature(device: Device, feature: Feature) bool {
for (device.features) |f| {
if (f == feature) return true;
}
return false;
}
pub inline fn getQueue(device: Device) Queue {
return device.vtable.getQueue(device.ptr);
}
pub inline fn injectError(device: Device, typ: ErrorType, message: [*:0]const u8) void {
device.vtable.injectError(device.ptr, typ, message);
}
pub inline fn loseForTesting(device: Device) void {
device.vtable.loseForTesting(device.ptr);
}
pub inline fn popErrorScope(device: Device, callback: *ErrorCallback) bool {
return device.vtable.popErrorScope(device.ptr, callback);
}
pub inline fn pushErrorScope(device: Device, filter: ErrorFilter) void {
device.vtable.pushErrorScope(device.ptr, filter);
}
pub inline fn setLostCallback(device: Device, callback: *LostCallback) void {
device.vtable.setLostCallback(device.ptr, callback);
}
pub const LostCallback = struct {
type_erased_ctx: *anyopaque,
type_erased_callback: fn (ctx: *anyopaque, reason: LostReason, message: [*:0]const u8) callconv(.Inline) void,
pub fn init(
comptime Context: type,
ctx: Context,
comptime callback: fn (ctx: Context, reason: LostReason, message: [*:0]const u8) void,
) LostCallback {
const erased = (struct {
pub inline fn erased(type_erased_ctx: *anyopaque, reason: LostReason, message: [*:0]const u8) void {
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), type_erased_ctx)), reason, message);
}
}).erased;
return .{
.type_erased_ctx = if (Context == void) undefined else ctx,
.type_erased_callback = erased,
};
}
};
pub inline fn createBindGroup(device: Device, descriptor: *const BindGroup.Descriptor) BindGroup {
return device.vtable.createBindGroup(device.ptr, descriptor);
}
pub inline fn createBindGroupLayout(device: Device, descriptor: *const BindGroupLayout.Descriptor) BindGroupLayout {
return device.vtable.createBindGroupLayout(device.ptr, descriptor);
}
pub inline fn createSampler(device: Device, descriptor: *const Sampler.Descriptor) Sampler {
return device.vtable.createSampler(device.ptr, descriptor);
}
pub inline fn createShaderModule(device: Device, descriptor: *const ShaderModule.Descriptor) ShaderModule {
return device.vtable.createShaderModule(device.ptr, descriptor);
}
pub inline fn nativeCreateSwapChain(device: Device, surface: ?Surface, descriptor: *const SwapChain.Descriptor) SwapChain {
return device.vtable.nativeCreateSwapChain(device.ptr, surface, descriptor);
}
pub inline fn createTexture(device: Device, descriptor: *const Texture.Descriptor) Texture {
return device.vtable.createTexture(device.ptr, descriptor);
}
pub inline fn destroy(device: Device) void {
device.vtable.destroy(device.ptr);
}
pub inline fn createBuffer(device: Device, descriptor: *const Buffer.Descriptor) Buffer {
return device.vtable.createBuffer(device.ptr, descriptor);
}
pub inline fn createCommandEncoder(device: Device, descriptor: ?*const CommandEncoder.Descriptor) CommandEncoder {
return device.vtable.createCommandEncoder(device.ptr, descriptor);
}
pub inline fn createComputePipeline(
device: Device,
descriptor: *const ComputePipeline.Descriptor,
) ComputePipeline {
return device.vtable.createComputePipeline(device.ptr, descriptor);
}
pub inline fn createComputePipelineAsync(
device: Device,
descriptor: *const ComputePipeline.Descriptor,
callback: *ComputePipeline.CreateCallback,
) void {
device.vtable.createComputePipelineAsync(device.ptr, descriptor, callback);
}
pub inline fn createErrorBuffer(device: Device) Buffer {
return device.vtable.createErrorBuffer(device.ptr);
}
pub inline fn createExternalTexture(device: Device, descriptor: *const ExternalTexture.Descriptor) ExternalTexture {
return device.vtable.createExternalTexture(device.ptr, descriptor);
}
pub inline fn createPipelineLayout(device: Device, descriptor: *const PipelineLayout.Descriptor) PipelineLayout {
return device.vtable.createPipelineLayout(device.ptr, descriptor);
}
pub inline fn createQuerySet(device: Device, descriptor: *const QuerySet.Descriptor) QuerySet {
return device.vtable.createQuerySet(device.ptr, descriptor);
}
pub inline fn createRenderBundleEncoder(device: Device, descriptor: *const RenderBundleEncoder.Descriptor) RenderBundleEncoder {
return device.vtable.createRenderBundleEncoder(device.ptr, descriptor);
}
pub inline fn createRenderPipeline(device: Device, descriptor: *const RenderPipeline.Descriptor) RenderPipeline {
return device.vtable.createRenderPipeline(device.ptr, descriptor);
}
pub inline fn createRenderPipelineAsync(
device: Device,
descriptor: *const RenderPipeline.Descriptor,
callback: *RenderPipeline.CreateCallback,
) void {
device.vtable.createRenderPipelineAsync(device.ptr, descriptor, callback);
}
pub inline fn setLoggingCallback(device: Device, callback: *LoggingCallback) void {
device.vtable.setLoggingCallback(device.ptr, callback);
}
pub inline fn setUncapturedErrorCallback(device: Device, callback: *ErrorCallback) void {
device.vtable.setUncapturedErrorCallback(device.ptr, callback);
}
pub inline fn tick(device: Device) void {
device.vtable.tick(device.ptr);
}
pub const Descriptor = struct {
label: ?[*:0]const u8 = null,
required_features: ?[]Feature = null,
required_limits: ?Limits = null,
};
pub const LostReason = enum(u32) {
none = 0x00000000,
destroyed = 0x00000001,
};
test {
_ = VTable;
_ = reference;
_ = release;
_ = getQueue;
_ = injectError;
_ = loseForTesting;
_ = popErrorScope;
_ = setLostCallback;
_ = createBindGroup;
_ = pushErrorScope;
_ = createBindGroupLayout;
_ = createSampler;
_ = createShaderModule;
_ = nativeCreateSwapChain;
_ = createTexture;
_ = destroy;
_ = createBuffer;
_ = createCommandEncoder;
_ = createComputePipeline;
_ = createComputePipelineAsync;
_ = createErrorBuffer;
_ = createExternalTexture;
_ = createPipelineLayout;
_ = createQuerySet;
_ = createRenderBundleEncoder;
_ = createRenderPipeline;
_ = createRenderPipelineAsync;
_ = setLoggingCallback;
_ = setUncapturedErrorCallback;
_ = tick;
_ = Descriptor;
_ = LostReason;
} | gpu/src/Device.zig |
const std = @import("std");
const mem = std.mem;
const Allocator = mem.Allocator;
const Source = @import("Source.zig");
const Compilation = @import("Compilation.zig");
const Tree = @import("Tree.zig");
const Diagnostics = @This();
pub const Message = struct {
tag: Tag,
loc: Source.Location = .{},
extra: Extra = .{ .none = {} },
pub const Extra = union {
str: []const u8,
tok_id: struct {
expected: Tree.Token.Id,
actual: Tree.Token.Id,
},
arguments: struct {
expected: u32,
actual: u32,
},
unsigned: u64,
signed: i64,
none: void,
};
};
pub const Tag = enum {
// Maybe someday this will no longer be needed.
todo,
error_directive,
elif_without_if,
elif_after_else,
else_without_if,
else_after_else,
endif_without_if,
unsupported_pragma,
line_simple_digit,
line_invalid_filename,
unterminated_conditional_directive,
invalid_preprocessing_directive,
macro_name_missing,
extra_tokens_directive_end,
expected_value_in_expr,
closing_paren,
to_match_paren,
to_match_brace,
to_match_bracket,
header_str_closing,
header_str_match,
string_literal_in_pp_expr,
float_literal_in_pp_expr,
defined_as_macro_name,
macro_name_must_be_identifier,
whitespace_after_macro_name,
hash_hash_at_start,
hash_hash_at_end,
pasting_formed_invalid,
missing_paren_param_list,
unterminated_macro_param_list,
invalid_token_param_list,
hash_not_followed_param,
expected_filename,
empty_filename,
expected_invalid,
expected_token,
expected_expr,
expected_integer_constant_expr,
missing_type_specifier,
multiple_storage_class,
static_assert_failure,
expected_type,
cannot_combine_spec,
duplicate_decl_spec,
restrict_non_pointer,
expected_external_decl,
expected_ident_or_l_paren,
missing_declaration,
func_not_in_root,
illegal_initializer,
extern_initializer,
sepc_from_typedef,
type_is_invalid,
param_before_var_args,
void_only_param,
void_param_qualified,
void_must_be_first_param,
invalid_storage_on_param,
threadlocal_non_var,
func_spec_non_func,
illegal_storage_on_func,
illegal_storage_on_global,
expected_stmt,
func_cannot_return_func,
func_cannot_return_array,
undeclared_identifier,
not_callable,
unsupported_str_cat,
static_func_not_global,
implicit_func_decl,
expected_param_decl,
invalid_old_style_params,
expected_fn_body,
invalid_void_param,
unused_value,
continue_not_in_loop,
break_not_in_loop_or_switch,
unreachable_code,
duplicate_label,
previous_label,
undeclared_label,
case_not_in_switch,
duplicate_switch_case_signed,
duplicate_switch_case_unsigned,
multiple_default,
previous_case,
expected_arguments,
expected_arguments_old,
expected_at_least_arguments,
invalid_static_star,
static_non_param,
array_qualifiers,
star_non_param,
variable_len_array_file_scope,
useless_static,
negative_array_size,
array_incomplete_elem,
array_func_elem,
static_non_outernmost_array,
qualifier_non_outernmost_array,
unterminated_macro_arg_list,
unknown_warning,
overflow_unsigned,
overflow_signed,
int_literal_too_big,
};
const Options = struct {
@"unsupported-pragma": Kind = .warning,
@"c99-extensions": Kind = .warning,
@"implicit-int": Kind = .warning,
@"duplicate-decl-specifier": Kind = .warning,
@"missing-declaration": Kind = .warning,
@"extern-initializer": Kind = .warning,
@"implicit-function-declaration": Kind = .warning,
@"unused-value": Kind = .warning,
@"unreachable-code": Kind = .warning,
@"unknown-warning-option": Kind = .warning,
};
list: std.ArrayList(Message),
color: bool = true,
fatal_errors: bool = false,
options: Options = .{},
errors: u32 = 0,
pub fn set(diag: *Diagnostics, name: []const u8, to: Kind) !void {
if (std.mem.eql(u8, name, "fatal-errors")) {
diag.fatal_errors = to != .off;
return;
}
inline for (std.meta.fields(Options)) |f| {
if (mem.eql(u8, f.name, name)) {
@field(diag.options, f.name) = to;
return;
}
}
try diag.add(.{
.tag = .unknown_warning,
.extra = .{ .str = name },
});
}
pub fn setAll(diag: *Diagnostics, to: Kind) void {
inline for (std.meta.fields(Options)) |f| {
@field(diag.options, f.name) = to;
}
}
pub fn init(gpa: *Allocator) Diagnostics {
return .{
.color = std.io.getStdErr().supportsAnsiEscapeCodes(),
.list = std.ArrayList(Message).init(gpa),
};
}
pub fn deinit(diag: *Diagnostics) void {
diag.list.deinit();
}
pub fn add(diag: *Diagnostics, msg: Message) Compilation.Error!void {
const kind = diag.tagKind(msg.tag);
if (kind == .off) return;
try diag.list.append(msg);
if (kind == .@"fatal error" or (kind == .@"error" and diag.fatal_errors))
return error.FatalError;
}
pub fn fatal(diag: *Diagnostics, path: []const u8, lcs: Source.LCS, comptime fmt: []const u8, args: anytype) Compilation.Error {
var m = MsgWriter.init(diag.color);
defer m.deinit();
m.location(path, lcs);
m.start(.@"fatal error");
m.print(fmt, args);
m.end(lcs);
return error.FatalError;
}
pub fn fatalNoSrc(diag: *Diagnostics, comptime fmt: []const u8, args: anytype) Compilation.Error {
if (std.builtin.os.tag == .windows or !diag.color) {
std.debug.print("fatal error: " ++ fmt ++ "\n", args);
} else {
const RED = "\x1b[31;1m";
const WHITE = "\x1b[37;1m";
const RESET = "\x1b[0m";
std.debug.print(RED ++ "fatal error: " ++ WHITE ++ fmt ++ "\n" ++ RESET, args);
}
return error.FatalError;
}
pub fn render(comp: *Compilation) void {
if (comp.diag.list.items.len == 0) return;
var m = MsgWriter.init(comp.diag.color);
defer m.deinit();
var errors: u32 = 0;
var warnings: u32 = 0;
for (comp.diag.list.items) |msg| {
const kind = comp.diag.tagKind(msg.tag);
switch (kind) {
.@"fatal error", .@"error" => errors += 1,
.warning => warnings += 1,
.note => {},
.off => unreachable,
}
var lcs: ?Source.LCS = null;
if (msg.loc.id != .unused) {
const loc = if (msg.loc.next != null) msg.loc.next.?.* else msg.loc;
const source = comp.getSource(loc.id);
lcs = source.lineColString(loc.byte_offset);
m.location(source.path, lcs.?);
}
m.start(kind);
switch (msg.tag) {
.todo => m.print("TODO: {s}", .{msg.extra.str}),
.error_directive => m.print("{s}", .{msg.extra.str}),
.elif_without_if => m.write("#elif without #if"),
.elif_after_else => m.write("#elif after #else"),
.else_without_if => m.write("#else without #if"),
.else_after_else => m.write("#else after #else"),
.endif_without_if => m.write("#endif without #if"),
.unsupported_pragma => m.print("unsupported #pragma directive '{s}'", .{msg.extra.str}),
.line_simple_digit => m.write("#line directive requires a simple digit sequence"),
.line_invalid_filename => m.write("invalid filename for #line directive"),
.unterminated_conditional_directive => m.write("unterminated conditional directive"),
.invalid_preprocessing_directive => m.write("invalid preprocessing directive"),
.macro_name_missing => m.write("macro name missing"),
.extra_tokens_directive_end => m.write("extra tokens at end of macro directive"),
.expected_value_in_expr => m.write("expected value in expression"),
.closing_paren => m.write("expected closing ')'"),
.to_match_paren => m.write("to match this '('"),
.to_match_brace => m.write("to match this '{'"),
.to_match_bracket => m.write("to match this '['"),
.header_str_closing => m.write("expected closing '>'"),
.header_str_match => m.write("to match this '<'"),
.string_literal_in_pp_expr => m.write("string literal in preprocessor expression"),
.float_literal_in_pp_expr => m.write("floating point literal in preprocessor expression"),
.defined_as_macro_name => m.write("'defined' cannot be used as a macro name"),
.macro_name_must_be_identifier => m.write("macro name must be an identifier"),
.whitespace_after_macro_name => m.write("ISO C99 requires whitespace after the macro name"),
.hash_hash_at_start => m.write("'##' cannot appear at the start of a macro expansion"),
.hash_hash_at_end => m.write("'##' cannot appear at the end of a macro expansion"),
.pasting_formed_invalid => m.print("pasting formed '{s}', an invalid preprocessing token", .{msg.extra.str}),
.missing_paren_param_list => m.write("missing ')' in macro parameter list"),
.unterminated_macro_param_list => m.write("unterminated macro param list"),
.invalid_token_param_list => m.write("invalid token in macro parameter list"),
.hash_not_followed_param => m.write("'#' is not followed by a macro parameter"),
.expected_filename => m.write("expected \"FILENAME\" or <FILENAME>"),
.empty_filename => m.write("empty filename"),
.expected_invalid => m.print("expected '{s}', found invalid bytes", .{msg.extra.tok_id.expected.symbol()}),
.expected_token => m.print("expected '{s}', found '{s}'", .{
msg.extra.tok_id.expected.symbol(),
msg.extra.tok_id.actual.symbol(),
}),
.expected_expr => m.write("expected expression"),
.expected_integer_constant_expr => m.write("expression is not an integer constant expression"),
.missing_type_specifier => m.write("type specifier missing, defaults to 'int'"),
.multiple_storage_class => m.print("cannot combine with previous '{s}' declaration specifier", .{msg.extra.str}),
.static_assert_failure => m.print("static_assert failed due to requirement {s}", .{msg.extra.str}),
.expected_type => m.write("expected a type"),
.cannot_combine_spec => m.print("cannot combine with previous '{s}' specifier", .{msg.extra.str}),
.duplicate_decl_spec => m.print("duplicate '{s}' declaration specifier", .{msg.extra.str}),
.restrict_non_pointer => m.print("restrict requires a pointer or reference ('{s}' is invalid)", .{msg.extra.str}),
.expected_external_decl => m.write("expected external declaration"),
.expected_ident_or_l_paren => m.write("expected identifier or '('"),
.missing_declaration => m.write("declaration does not declare anything"),
.func_not_in_root => m.write("function definition is not allowed here"),
.illegal_initializer => m.write("illegal initializer (only variables can be initialized)"),
.extern_initializer => m.write("extern variable has initializer"),
.sepc_from_typedef => m.print("'{s}' came from typedef", .{msg.extra.str}),
.type_is_invalid => m.print("'{s}' is invalid", .{msg.extra.str}),
.param_before_var_args => m.write("ISO C requires a named parameter before '...'"),
.void_only_param => m.write("'void' must be the only parameter if specified"),
.void_param_qualified => m.write("'void' parameter cannot be qualified"),
.void_must_be_first_param => m.write("'void' must be the first parameter if specified"),
.invalid_storage_on_param => m.write("invalid storage class on function parameter"),
.threadlocal_non_var => m.write("_Thread_local only allowed on variables"),
.func_spec_non_func => m.print("'{s}' can only appear on functions", .{msg.extra.str}),
.illegal_storage_on_func => m.write("illegal storage class on function"),
.illegal_storage_on_global => m.write("illegal storage class on global variable"),
.expected_stmt => m.write("expected statement"),
.func_cannot_return_func => m.write("function cannot return a function"),
.func_cannot_return_array => m.write("function cannot return an array"),
.undeclared_identifier => m.print("use of undeclared identifier '{s}'", .{msg.extra.str}),
.not_callable => m.print("cannot call non function type '{s}'", .{msg.extra.str}),
.unsupported_str_cat => m.write("unsupported string literal concatenation"),
.static_func_not_global => m.write("static functions must be global"),
.implicit_func_decl => m.print("implicit declaration of function '{s}' is invalid in C99", .{msg.extra.str}),
.expected_param_decl => m.write("expected parameter declaration"),
.invalid_old_style_params => m.write("identifier parameter lists are only allowed in function definitions"),
.expected_fn_body => m.write("expected function body after function declaration"),
.invalid_void_param => m.write("parameter cannot have void type"),
.unused_value => m.write("expression result unused"),
.continue_not_in_loop => m.write("'continue' statement not in a loop"),
.break_not_in_loop_or_switch => m.write("'break' statement not in a loop or a switch"),
.unreachable_code => m.write("unreachable code"),
.duplicate_label => m.print("duplicate label '{s}'", .{msg.extra.str}),
.previous_label => m.print("previous definition of label '{s}' was here", .{msg.extra.str}),
.undeclared_label => m.print("use of undeclared label '{s}'", .{msg.extra.str}),
.case_not_in_switch => m.print("'{s}' statement not in a switch statement", .{msg.extra.str}),
.duplicate_switch_case_signed => m.print("duplicate case value '{d}'", .{msg.extra.signed}),
.duplicate_switch_case_unsigned => m.print("duplicate case value '{d}'", .{msg.extra.unsigned}),
.multiple_default => m.write("multiple default cases in the same switch"),
.previous_case => m.write("previous case defined here"),
.expected_arguments, .expected_arguments_old => m.print("expected {d} argument(s) got {d}", .{ msg.extra.arguments.expected, msg.extra.arguments.actual }),
.expected_at_least_arguments => m.print("expected at least {d} argument(s) got {d}", .{ msg.extra.arguments.expected, msg.extra.arguments.actual }),
.invalid_static_star => m.write("'static' may not be used with an unspecified variable length array size"),
.static_non_param => m.write("'static' used outside of function parameters"),
.array_qualifiers => m.write("type qualifier in non parameter array type"),
.star_non_param => m.write("star modifier used outside of function parameters"),
.variable_len_array_file_scope => m.write("variable length arrays not allowed at file scope"),
.useless_static => m.write("'static' useless without a constant size"),
.negative_array_size => m.write("array size must be 0 or greater"),
.array_incomplete_elem => m.write("array has incomplete element type"),
.array_func_elem => m.write("arrays cannot have functions as their element type"),
.static_non_outernmost_array => m.write("'static' used in non-outernmost array type"),
.qualifier_non_outernmost_array => m.write("type qualifier used in non-outernmost array type"),
.unterminated_macro_arg_list => m.write("unterminated function macro argument list"),
.unknown_warning => m.print("unknown warning '{s}'", .{msg.extra.str}),
.overflow_signed => m.print("overflow in expression; result is'{d}'", .{msg.extra.signed}),
.overflow_unsigned => m.print("overflow in expression; result is '{d}'", .{msg.extra.unsigned}),
.int_literal_too_big => m.write("integer literal is too large to be represented in any integer type"),
}
m.end(lcs);
if (msg.loc.id != .unused) {
var maybe_loc = msg.loc.next;
if (msg.loc.next != null) maybe_loc = maybe_loc.?.next;
while (maybe_loc) |loc| {
const source = comp.getSource(loc.id);
const e_lcs = source.lineColString(loc.byte_offset);
m.location(source.path, e_lcs);
m.start(.note);
m.write("expanded from here");
m.end(e_lcs);
maybe_loc = loc.next;
}
}
}
const w_s: []const u8 = if (warnings == 1) "" else "s";
const e_s: []const u8 = if (errors == 1) "" else "s";
if (errors != 0 and warnings != 0) {
m.print("{d} warning{s} and {d} error{s} generated.\n", .{ warnings, w_s, errors, e_s });
} else if (warnings != 0) {
m.print("{d} warning{s} generated.\n", .{ warnings, w_s });
} else if (errors != 0) {
m.print("{d} error{s} generated.\n", .{ errors, e_s });
}
comp.diag.list.items.len = 0;
comp.diag.errors += errors;
}
const Kind = enum { @"fatal error", @"error", note, warning, off };
fn tagKind(diag: *Diagnostics, tag: Tag) Kind {
var kind: Kind = switch (tag) {
.todo,
.error_directive,
.elif_without_if,
.elif_after_else,
.else_without_if,
.else_after_else,
.endif_without_if,
.line_simple_digit,
.line_invalid_filename,
.unterminated_conditional_directive,
.invalid_preprocessing_directive,
.macro_name_missing,
.extra_tokens_directive_end,
.expected_value_in_expr,
.closing_paren,
.header_str_closing,
.string_literal_in_pp_expr,
.float_literal_in_pp_expr,
.defined_as_macro_name,
.macro_name_must_be_identifier,
.hash_hash_at_start,
.hash_hash_at_end,
.pasting_formed_invalid,
.missing_paren_param_list,
.unterminated_macro_param_list,
.invalid_token_param_list,
.hash_not_followed_param,
.expected_filename,
.empty_filename,
.expected_invalid,
.expected_token,
.expected_expr,
.expected_integer_constant_expr,
.multiple_storage_class,
.static_assert_failure,
.expected_type,
.cannot_combine_spec,
.restrict_non_pointer,
.expected_external_decl,
.expected_ident_or_l_paren,
.func_not_in_root,
.illegal_initializer,
.type_is_invalid,
.param_before_var_args,
.void_only_param,
.void_param_qualified,
.void_must_be_first_param,
.invalid_storage_on_param,
.threadlocal_non_var,
.func_spec_non_func,
.illegal_storage_on_func,
.illegal_storage_on_global,
.expected_stmt,
.func_cannot_return_func,
.func_cannot_return_array,
.undeclared_identifier,
.not_callable,
.unsupported_str_cat,
.static_func_not_global,
.expected_param_decl,
.expected_fn_body,
.invalid_void_param,
.continue_not_in_loop,
.break_not_in_loop_or_switch,
.duplicate_label,
.undeclared_label,
.case_not_in_switch,
.duplicate_switch_case_signed,
.duplicate_switch_case_unsigned,
.multiple_default,
.expected_arguments,
.expected_at_least_arguments,
.invalid_static_star,
.static_non_param,
.array_qualifiers,
.star_non_param,
.variable_len_array_file_scope,
.negative_array_size,
.array_incomplete_elem,
.array_func_elem,
.static_non_outernmost_array,
.qualifier_non_outernmost_array,
.unterminated_macro_arg_list,
.int_literal_too_big,
=> .@"error",
.to_match_paren,
.to_match_brace,
.to_match_bracket,
.header_str_match,
.sepc_from_typedef,
.previous_label,
.previous_case,
=> .note,
.invalid_old_style_params,
.expected_arguments_old,
.useless_static,
.overflow_unsigned,
.overflow_signed,
=> .warning,
.unsupported_pragma => diag.options.@"unsupported-pragma",
.whitespace_after_macro_name => diag.options.@"c99-extensions",
.missing_type_specifier => diag.options.@"implicit-int",
.duplicate_decl_spec => diag.options.@"duplicate-decl-specifier",
.missing_declaration => diag.options.@"missing-declaration",
.extern_initializer => diag.options.@"extern-initializer",
.implicit_func_decl => diag.options.@"implicit-function-declaration",
.unused_value => diag.options.@"unused-value",
.unreachable_code => diag.options.@"unreachable-code",
.unknown_warning => diag.options.@"unknown-warning-option",
};
if (kind == .@"error" and diag.fatal_errors) kind = .@"fatal error";
return kind;
}
const MsgWriter = struct {
// TODO Impl is private
held: @typeInfo(@TypeOf(std.Thread.Mutex.acquire)).Fn.return_type.?,
w: std.fs.File.Writer,
color: bool,
fn init(color: bool) MsgWriter {
return .{
.held = std.debug.getStderrMutex().acquire(),
.w = std.io.getStdErr().writer(),
.color = color,
};
}
fn deinit(m: *MsgWriter) void {
m.held.release();
}
fn print(m: *MsgWriter, comptime fmt: []const u8, args: anytype) void {
m.w.print(fmt, args) catch {};
}
fn write(m: *MsgWriter, msg: []const u8) void {
m.w.writeAll(msg) catch {};
}
fn location(m: *MsgWriter, path: []const u8, lcs: Source.LCS) void {
if (std.builtin.os.tag == .windows or !m.color) {
m.print("{s}:{d}:{d}: ", .{ path, lcs.line, lcs.col });
} else {
const WHITE = "\x1b[37;1m";
m.print(WHITE ++ "{s}:{d}:{d}: ", .{ path, lcs.line, lcs.col });
}
}
fn start(m: *MsgWriter, kind: Kind) void {
if (std.builtin.os.tag == .windows or !m.color) {
m.print("{s}: ", .{@tagName(kind)});
} else {
const PURPLE = "\x1b[35;1m";
const CYAN = "\x1b[36;1m";
const RED = "\x1b[31;1m";
const WHITE = "\x1b[37;1m";
const msg_kind_str = switch (kind) {
.@"fatal error" => RED ++ "fatal error: " ++ WHITE,
.@"error" => RED ++ "error: " ++ WHITE,
.note => CYAN ++ "note: " ++ WHITE,
.warning => PURPLE ++ "warning: " ++ WHITE,
.off => unreachable,
};
m.write(msg_kind_str);
}
}
fn end(m: *MsgWriter, lcs: ?Source.LCS) void {
if (std.builtin.os.tag == .windows or !m.color) {
if (lcs == null) {
m.write("\n");
return;
}
m.print("\n{s}\n", .{lcs.?.str});
m.print("{s: >[1]}^\n", .{ "", lcs.?.col - 1 });
} else {
const GREEN = "\x1b[32;1m";
const RESET = "\x1b[0m";
if (lcs == null) {
m.write("\n" ++ RESET);
return;
}
m.print("\n" ++ RESET ++ "{s}\n", .{lcs.?.str});
m.print("{s: >[1]}" ++ GREEN ++ "^" ++ RESET ++ "\n", .{ "", lcs.?.col - 1 });
}
}
}; | src/Diagnostics.zig |
const builtin = @import("builtin");
const std = @import("std");
const maxInt = std.math.maxInt;
const FLT_MANT_DIG = 24;
pub fn __floatundisf(arg: u64) callconv(.C) f32 {
@setRuntimeSafety(builtin.is_test);
if (arg == 0) return 0;
var a = arg;
const N: usize = @TypeOf(a).bit_count;
// Number of significant digits
const sd = N - @clz(u64, a);
// 8 exponent
var e = @intCast(u32, sd) - 1;
if (sd > FLT_MANT_DIG) {
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
// 12345678901234567890123456
// 1 = msb 1 bit
// P = bit FLT_MANT_DIG-1 bits to the right of 1
// Q = bit FLT_MANT_DIG bits to the right of 1
// R = "or" of all bits to the right of Q
switch (sd) {
FLT_MANT_DIG + 1 => a <<= 1,
FLT_MANT_DIG + 2 => {},
else => {
const shift_amt = @intCast(u6, ((N + FLT_MANT_DIG + 2) - sd));
const all_ones: u64 = maxInt(u64);
a = (a >> @intCast(u6, sd - (FLT_MANT_DIG + 2))) |
@boolToInt(a & (all_ones >> shift_amt) != 0);
},
}
// Or P into R
a |= @boolToInt((a & 4) != 0);
// round - this step may add a significant bit
a += 1;
// dump Q and R
a >>= 2;
// a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
if ((a & (@as(u64, 1) << FLT_MANT_DIG)) != 0) {
a >>= 1;
e += 1;
}
// a is now rounded to FLT_MANT_DIG bits
} else {
a <<= @intCast(u6, FLT_MANT_DIG - sd);
// a is now rounded to FLT_MANT_DIG bits
}
const result: u32 = ((e + 127) << 23) | // exponent
@truncate(u32, a & 0x007FFFFF); // mantissa
return @bitCast(f32, result);
}
pub fn __aeabi_ul2f(arg: u64) callconv(.AAPCS) f32 {
@setRuntimeSafety(false);
return @call(.{ .modifier = .always_inline }, __floatundisf, .{arg});
}
fn test__floatundisf(a: u64, expected: f32) void {
std.testing.expectEqual(expected, __floatundisf(a));
}
test "floatundisf" {
test__floatundisf(0, 0.0);
test__floatundisf(1, 1.0);
test__floatundisf(2, 2.0);
test__floatundisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
test__floatundisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
test__floatundisf(0x8000008000000000, 0x1p+63);
test__floatundisf(0x8000010000000000, 0x1.000002p+63);
test__floatundisf(0x8000000000000000, 0x1p+63);
test__floatundisf(0x8000000000000001, 0x1p+63);
test__floatundisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
test__floatundisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
test__floatundisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
test__floatundisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
test__floatundisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
test__floatundisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
test__floatundisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
test__floatundisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
test__floatundisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
test__floatundisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
test__floatundisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
test__floatundisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
test__floatundisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
} | lib/std/special/compiler_rt/floatundisf.zig |
const std = @import("std");
const assert = std.debug.assert;
const config = @import("config.zig");
const cli = @import("cli.zig");
const IO = @import("io.zig").IO;
const MessageBus = @import("message_bus.zig").MessageBusClient;
const StateMachine = @import("state_machine.zig").StateMachine;
const Operation = StateMachine.Operation;
const RingBuffer = @import("ring_buffer.zig").RingBuffer;
const vsr = @import("vsr.zig");
const Header = vsr.Header;
const Client = vsr.Client(StateMachine, MessageBus);
const tb = @import("tigerbeetle.zig");
const Transfer = tb.Transfer;
const Commit = tb.Commit;
const Account = tb.Account;
const CreateAccountsResult = tb.CreateAccountsResult;
const CreateTransfersResult = tb.CreateTransfersResult;
const MAX_TRANSFERS: u32 = 1_000_000;
const BATCH_SIZE: u32 = 5_000;
const IS_TWO_PHASE_COMMIT = false;
const BENCHMARK = if (IS_TWO_PHASE_COMMIT) 500_000 else 1_000_000;
const RESULT_TOLERANCE = 10; // percent
const BATCHES: f32 = MAX_TRANSFERS / BATCH_SIZE;
const TOTAL_BATCHES = @ceil(BATCHES);
const log = std.log;
pub const log_level: std.log.Level = .notice;
var accounts = [_]Account{
Account{
.id = 1,
.user_data = 0,
.reserved = [_]u8{0} ** 48,
.unit = 2,
.code = 0,
.flags = .{},
.debits_reserved = 0,
.debits_accepted = 0,
.credits_reserved = 0,
.credits_accepted = 0,
},
Account{
.id = 2,
.user_data = 0,
.reserved = [_]u8{0} ** 48,
.unit = 2,
.code = 0,
.flags = .{},
.debits_reserved = 0,
.debits_accepted = 0,
.credits_reserved = 0,
.credits_accepted = 0,
},
};
var max_create_transfers_latency: i64 = 0;
var max_commit_transfers_latency: i64 = 0;
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
const stderr = std.io.getStdErr().writer();
if (std.builtin.mode != .ReleaseSafe and std.builtin.mode != .ReleaseFast) {
try stderr.print("Benchmark must be built as ReleaseSafe for minimum performance.\n", .{});
}
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
const client_id = std.crypto.random.int(u128);
const cluster_id: u32 = 0;
var address = [_]std.net.Address{try std.net.Address.parseIp4("127.0.0.1", config.port)};
var io = try IO.init(32, 0);
var message_bus = try MessageBus.init(allocator, cluster_id, address[0..], client_id, &io);
defer message_bus.deinit();
var client = try Client.init(
allocator,
client_id,
cluster_id,
@intCast(u8, address.len),
&message_bus,
);
defer client.deinit();
message_bus.set_on_message(*Client, &client, Client.on_message);
// Pre-allocate a million transfers:
var transfers = try arena.allocator.alloc(Transfer, MAX_TRANSFERS);
for (transfers) |*transfer, index| {
transfer.* = .{
.id = index,
.debit_account_id = accounts[0].id,
.credit_account_id = accounts[1].id,
.user_data = 0,
.reserved = [_]u8{0} ** 32,
.code = 0,
.flags = if (IS_TWO_PHASE_COMMIT) .{ .two_phase_commit = true } else .{},
.amount = 1,
.timeout = if (IS_TWO_PHASE_COMMIT) std.time.ns_per_hour else 0,
};
}
// Pre-allocate a million commits:
var commits: ?[]Commit = if (IS_TWO_PHASE_COMMIT) try arena.allocator.alloc(Commit, MAX_TRANSFERS) else null;
if (commits) |all_commits| {
for (all_commits) |*commit, index| {
commit.* = .{
.id = index,
.reserved = [_]u8{0} ** 32,
.code = 0,
.flags = .{},
};
}
}
try wait_for_connect(&client, &io);
try stdout.print("creating accounts...\n", .{});
var queue = TimedQueue.init(&client, &io);
try queue.push(.{
.operation = Operation.create_accounts,
.data = std.mem.sliceAsBytes(accounts[0..]),
});
try queue.execute();
assert(queue.end != null);
assert(queue.batches.empty());
try stdout.print("batching transfers...\n", .{});
var count: u64 = 0;
queue.reset();
while (count < transfers.len) {
try queue.push(.{
.operation = .create_transfers,
.data = std.mem.sliceAsBytes(transfers[count..][0..BATCH_SIZE]),
});
if (IS_TWO_PHASE_COMMIT) {
try queue.push(.{
.operation = .commit_transfers,
.data = std.mem.sliceAsBytes(commits.?[count..][0..BATCH_SIZE]),
});
}
count += BATCH_SIZE;
}
assert(count == MAX_TRANSFERS);
try stdout.print("starting benchmark...\n", .{});
try queue.execute();
assert(queue.end != null);
assert(queue.batches.empty());
var ms = queue.end.? - queue.start.?;
const transfer_type = if (IS_TWO_PHASE_COMMIT) "two-phase commit " else "";
const result: i64 = @divFloor(@intCast(i64, transfers.len * 1000), ms);
try stdout.print("============================================\n", .{});
try stdout.print("{} {s}transfers per second\n\n", .{
result,
transfer_type,
});
try stdout.print("create_transfers max p100 latency per {} transfers = {}ms\n", .{
BATCH_SIZE,
queue.max_transfers_latency,
});
try stdout.print("commit_transfers max p100 latency per {} transfers = {}ms\n", .{
BATCH_SIZE,
queue.max_commits_latency,
});
}
const Batch = struct {
operation: Operation,
data: []u8,
};
const TimedQueue = struct {
batch_start: ?i64,
start: ?i64,
end: ?i64,
max_transfers_latency: i64,
max_commits_latency: i64,
client: *Client,
io: *IO,
batches: if (IS_TWO_PHASE_COMMIT) RingBuffer(Batch, 2 * TOTAL_BATCHES) else RingBuffer(Batch, TOTAL_BATCHES),
pub fn init(client: *Client, io: *IO) TimedQueue {
var self = TimedQueue{
.batch_start = null,
.start = null,
.end = null,
.max_transfers_latency = 0,
.max_commits_latency = 0,
.client = client,
.io = io,
.batches = .{},
};
return self;
}
pub fn reset(self: *TimedQueue) void {
self.batch_start = null;
self.start = null;
self.end = null;
self.max_transfers_latency = 0;
self.max_commits_latency = 0;
}
pub fn push(self: *TimedQueue, batch: Batch) !void {
try self.batches.push(batch);
}
pub fn execute(self: *TimedQueue) !void {
assert(self.start == null);
assert(!self.batches.empty());
self.reset();
log.debug("executing batches...", .{});
const now = std.time.milliTimestamp();
self.start = now;
if (self.batches.head_ptr()) |starting_batch| {
log.debug("sending first batch...", .{});
self.batch_start = now;
var message = self.client.get_message() orelse {
@panic("Client message pool has been exhausted. Cannot execute batch.");
};
defer self.client.unref(message);
std.mem.copy(
u8,
message.buffer[@sizeOf(Header)..],
std.mem.sliceAsBytes(starting_batch.data),
);
self.client.request(
@intCast(u128, @ptrToInt(self)),
TimedQueue.lap,
starting_batch.operation,
message,
starting_batch.data.len,
);
}
while (!self.batches.empty()) {
self.client.tick();
try self.io.run_for_ns(5 * std.time.ns_per_ms);
}
}
pub fn lap(user_data: u128, operation: Operation, results: Client.Error![]const u8) void {
const now = std.time.milliTimestamp();
const value = results catch |err| {
log.emerg("Client returned error={o}", .{@errorName(err)});
@panic("Client returned error during benchmarking.");
};
log.debug("response={s}", .{std.mem.bytesAsSlice(CreateAccountsResult, value)});
const self: *TimedQueue = @intToPtr(*TimedQueue, @intCast(usize, user_data));
const completed_batch: ?Batch = self.batches.pop();
assert(completed_batch != null);
assert(completed_batch.?.operation == operation);
log.debug("completed batch operation={} start={}", .{
completed_batch.?.operation,
self.batch_start,
});
const latency = now - self.batch_start.?;
switch (operation) {
.create_accounts => {},
.create_transfers => {
if (latency > self.max_transfers_latency) {
self.max_transfers_latency = latency;
}
},
.commit_transfers => {
if (latency > self.max_commits_latency) {
self.max_commits_latency = latency;
}
},
else => unreachable,
}
if (self.batches.head_ptr()) |next_batch| {
var message = self.client.get_message() orelse {
@panic("Client message pool has been exhausted.");
};
defer self.client.unref(message);
std.mem.copy(
u8,
message.buffer[@sizeOf(Header)..],
std.mem.sliceAsBytes(next_batch.data),
);
self.batch_start = std.time.milliTimestamp();
self.client.request(
@intCast(u128, @ptrToInt(self)),
TimedQueue.lap,
next_batch.operation,
message,
next_batch.data.len,
);
} else {
log.debug("stopping timer...", .{});
self.end = now;
}
}
};
fn wait_for_connect(client: *Client, io: *IO) !void {
var ticks: u32 = 0;
while (ticks < 20) : (ticks += 1) {
client.tick();
// We tick IO outside of client so that an IO instance can be shared by multiple clients:
// Otherwise we will hit io_uring memory restrictions too quickly.
try io.tick();
std.time.sleep(10 * std.time.ns_per_ms);
}
} | src/benchmark.zig |
const std = @import("std");
const testing = std.testing;
const f128math = @import("f128math");
const math = f128math;
const inf_f32 = math.inf_f32;
const nan_f32 = math.qnan_f32;
const inf_f64 = math.inf_f64;
const nan_f64 = math.qnan_f64;
const inf_f128 = math.inf_f128;
const nan_f128 = math.qnan_f128;
const test_util = @import("util.zig");
const TestcaseExp32 = test_util.Testcase(math.exp, "exp", f32);
const TestcaseExp64 = test_util.Testcase(math.exp, "exp", f64);
const TestcaseExp128 = test_util.Testcase(math.exp, "exp", f128);
fn tc32(input: f32, exp_output: f32) TestcaseExp32 {
return .{ .input = input, .exp_output = exp_output };
}
fn tc64(input: f64, exp_output: f64) TestcaseExp64 {
return .{ .input = input, .exp_output = exp_output };
}
fn tc128(input: f128, exp_output: f128) TestcaseExp128 {
return .{ .input = input, .exp_output = exp_output };
}
const testcases32 = [_]TestcaseExp32{
// zig fmt: off
// Special cases
tc32( 0, 1 ),
tc32(-0, 1 ),
tc32( inf_f32, inf_f32 ),
tc32(-inf_f32, 0 ),
tc32( nan_f32, nan_f32 ),
tc32(-nan_f32, nan_f32 ),
tc32( @bitCast(f32, @as(u32, 0x7ff01234)), nan_f32 ),
tc32( @bitCast(f32, @as(u32, 0xfff01234)), nan_f32 ),
// Sanity cases
tc32(-0x1.0223a0p+3, 0x1.490320p-12 ),
tc32( 0x1.161868p+2, 0x1.34712ap+6 ),
tc32(-0x1.0c34b4p+3, 0x1.e06b1ap-13 ),
tc32(-0x1.a206f0p+2, 0x1.7dd484p-10 ),
tc32( 0x1.288bbcp+3, 0x1.4abc80p+13 ),
tc32( 0x1.52efd0p-1, 0x1.f04a9cp+0 ),
tc32(-0x1.a05cc8p-2, 0x1.54f1e0p-1 ),
tc32( 0x1.1f9efap-1, 0x1.c0f628p+0 ),
tc32( 0x1.8c5db0p-1, 0x1.1599b2p+1 ),
tc32(-0x1.5b86eap-1, 0x1.03b572p-1 ),
tc32(-0x1.57f25cp+2, 0x1.2fbea2p-8 ),
tc32( 0x1.c7d310p+3, 0x1.76eefp+20 ),
tc32( 0x1.19be70p+4, 0x1.52d3dep+25 ),
tc32(-0x1.ab6d70p+3, 0x1.a88adep-20 ),
tc32(-0x1.5ac18ep+2, 0x1.22b328p-8 ),
tc32(-0x1.925982p-1, 0x1.d2acc0p-2 ),
tc32( 0x1.7221cep+3, 0x1.9c2ceap+16 ),
tc32( 0x1.11a0d4p+4, 0x1.980ee6p+24 ),
tc32(-0x1.ae41a2p+1, 0x1.1c28d0p-5 ),
tc32(-0x1.329154p+4, 0x1.47ef94p-28 ),
// Boundary cases
tc32( 0x1.62e42ep+6, 0x1.ffff08p+127 ), // The last value before the exp gets infinite
tc32( 0x1.62e430p+6, inf_f32 ), // The first value that gives infinite exp
tc32( 0x1.fffffep+127, inf_f32 ), // Max input value
tc32( 0x1p-149, 1 ), // Tiny input values
tc32(-0x1p-149, 1 ),
tc32( 0x1p-126, 1 ),
tc32(-0x1p-126, 1 ),
tc32(-0x1.9fe368p+6, 0x1p-149 ), // The last value before the exp flushes to zero
tc32(-0x1.9fe36ap+6, 0 ), // The first value at which the exp flushes to zero
tc32(-0x1.5d589ep+6, 0x1.00004cp-126 ), // The last value before the exp flushes to subnormal
tc32(-0x1.5d58a0p+6, 0x1.ffff98p-127 ), // The first value for which exp flushes to subnormal
// zig fmt: on
};
const testcases64 = [_]TestcaseExp64{
// zig fmt: off
// Special cases
tc64( 0, 1 ),
tc64(-0, 1 ),
tc64( 0x1p-1074, 1 ), // Smallest denorm positive
tc64(-0x1p-1074, 1 ), // Smallest denorm negative
tc64( inf_f64, inf_f64 ),
tc64(-inf_f64, 0 ),
tc64( nan_f64, nan_f64 ),
// Sanity cases
tc64(-0x1.02239f3c6a8f1p+3, 0x1.490327ea61235p-12 ),
tc64( 0x1.161868e18bc67p+2, 0x1.34712ed238c04p+6 ),
tc64(-0x1.0c34b3e01e6e7p+3, 0x1.e06b1b6c18e64p-13 ),
tc64(-0x1.a206f0a19dcc4p+2, 0x1.7dd47f810e68cp-10 ),
tc64( 0x1.288bbb0d6a1e6p+3, 0x1.4abc77496e07ep+13 ),
tc64( 0x1.52efd0cd80497p-1, 0x1.f04a9c1080500p+0 ),
tc64(-0x1.a05cc754481d1p-2, 0x1.54f1e0fd3ea0dp-1 ),
tc64( 0x1.1f9ef934745cbp-1, 0x1.c0f6266a6a547p+0 ),
tc64( 0x1.8c5db097f7442p-1, 0x1.1599b1d4a25fbp+1 ),
tc64(-0x1.5b86ea8118a0ep-1, 0x1.03b5728a00229p-1 ),
tc64(-0x1.57f25b2b5006dp+2, 0x1.2fbea6a01cab9p-8 ),
tc64( 0x1.c7d30fb825911p+3, 0x1.76eeed45a0634p+20 ),
tc64( 0x1.19be709de7505p+4, 0x1.52d3eb7be6844p+25 ),
tc64(-0x1.ab6d6fba96889p+3, 0x1.a88ae12f985d6p-20 ),
tc64(-0x1.5ac18e27084ddp+2, 0x1.22b327da9cca6p-8 ),
tc64(-0x1.925981b093c41p-1, 0x1.d2acc046b55f7p-2 ),
tc64( 0x1.7221cd18455f5p+3, 0x1.9c2cde8699cfbp+16 ),
tc64( 0x1.11a0d4a51b239p+4, 0x1.980ef612ff182p+24 ),
tc64(-0x1.ae41a1079de4dp+1, 0x1.1c28d16bb3222p-5 ),
tc64(-0x1.329153103b871p+4, 0x1.47efa6ddd0d22p-28 ),
// Boundary cases
tc64( 0x1.62e42fefa39efp+9, 0x1.fffffffffff2ap+1023 ), // The last value before the exp gets infinite
tc64( 0x1.62e42fefa39f0p+9, inf_f64 ), // The first value that gives infinite exp
tc64( 0x1.fffffffffffffp+127, inf_f64 ), // Max input value
tc64( 0x1p-1074, 1 ), // Tiny input values
tc64(-0x1p-1074, 1 ),
tc64( 0x1p-1022, 1 ),
tc64(-0x1p-1022, 1 ),
tc64(-0x1.74910d52d3051p+9, 0x1p-1074 ), // The last value before the exp flushes to zero
tc64(-0x1.74910d52d3052p+9, 0 ), // The first value at which the exp flushes to zero
tc64(-0x1.6232bdd7abcd2p+9, 0x1.000000000007cp-1022 ), // The last value before the exp flushes to subnormal
tc64(-0x1.6232bdd7abcd3p+9, 0x1.ffffffffffcf8p-1023 ), // The first value for which exp flushes to subnormal
// zig fmt: on
};
const testcases128 = [_]TestcaseExp128{
// zig fmt: off
// Special cases
tc128( 0, 1 ),
tc128(-0, 1 ),
tc128( inf_f128, inf_f128 ),
tc128(-inf_f128, 0 ),
tc128( nan_f128, nan_f128 ),
tc128(-nan_f128, nan_f128 ),
tc128( @bitCast(f128, @as(u128, 0x7fff1234000000000000000000000000)), nan_f128 ),
tc128( @bitCast(f128, @as(u128, 0xffff1234000000000000000000000000)), nan_f128 ),
// Sanity cases
tc128(-0x1.02239f3c6a8f13dep+3, 0x1.490327ea61232c65cff53beed777p-12 ),
tc128( 0x1.161868e18bc67782p+2, 0x1.34712ed238c064a14a59ddb90119p+6 ),
tc128(-0x1.0c34b3e01e6e682cp+3, 0x1.e06b1b6c18e6b9852676f1295765p-13 ),
tc128(-0x1.a206f0a19dcc3948p+2, 0x1.7dd47f810e68efcaa7504b9387d0p-10 ),
tc128( 0x1.288bbb0d6a1e5bdap+3, 0x1.4abc77496e07b24ad548e9379bcap+13 ),
tc128( 0x1.52efd0cd80496a5ap-1, 0x1.f04a9c1080500277b844a5191ca4p+0 ),
tc128(-0x1.a05cc754481d0bd0p-2, 0x1.54f1e0fd3ea0d31771802892d4e9p-1 ),
tc128( 0x1.1f9ef934745cad60p-1, 0x1.c0f6266a6a5473f6d16e0140d987p+0 ),
tc128( 0x1.8c5db097f744257ep-1, 0x1.1599b1d4a25fb7c587a30b9ea597p+1 ),
tc128(-0x1.5b86ea8118a0e2bcp-1, 0x1.03b5728a0022870d16a9c4217353p-1 ),
// Boundary cases
tc128( 0x1.62e42fefa39ef35793c7673007e5p+13, 0x1.ffffffffffffffffffffffffc4a8p+16383 ), // The last value before the exp gets infinite
tc128( 0x1.62e42fefa39ef35793c7673007e6p+13, inf_f128 ), // The first value that gives infinite exp
tc128(-0x1.654bb3b2c73ebb059fabb506ff33p+13, 0x1p-16494 ), // The last value before the exp flushes to zero
tc128(-0x1.654bb3b2c73ebb059fabb506ff34p+13, 0 ), // The first value at which the exp flushes to zero
tc128(-0x1.62d918ce2421d65ff90ac8f4ce65p+13, 0x1.00000000000000000000000015c6p-16382 ), // The last value before the exp flushes to subnormal
tc128(-0x1.62d918ce2421d65ff90ac8f4ce66p+13, 0x1.ffffffffffffffffffffffffeb8cp-16383 ), // The first value for which exp flushes to subnormal
// zig fmt: on
};
test "exp32()" {
try test_util.runTests(testcases32);
}
test "exp64()" {
try test_util.runTests(testcases64);
}
test "exp128()" {
try test_util.runTests(testcases128);
} | tests/exp.zig |
extern fn wl_display_connect(name: ?[*:0]const u8) ?*Display;
pub fn connect(name: ?[*:0]const u8) error{ConnectFailed}!*Display {
return wl_display_connect(name) orelse return error.ConnectFailed;
}
extern fn wl_display_connect_to_fd(fd: c_int) ?*Display;
pub fn connectToFd(fd: os.fd_t) error{ConnectFailed}!*Display {
return wl_display_connect_to_fd(fd) orelse return error.ConnectFailed;
}
extern fn wl_display_disconnect(display: *Display) void;
pub fn disconnect(display: *Display) void {
wl_display_disconnect(display);
}
extern fn wl_display_get_fd(display: *Display) c_int;
pub fn getFd(display: *Display) os.fd_t {
return wl_display_get_fd(display);
}
extern fn wl_display_dispatch(display: *Display) c_int;
pub fn dispatch(display: *Display) !u32 {
const rc = wl_display_dispatch(display);
// poll(2), sendmsg(2), recvmsg(2), EOVERFLOW, E2BIG
return switch (os.errno(rc)) {
0 => @intCast(u32, rc),
os.EFAULT => unreachable,
os.EINTR => unreachable,
os.EINVAL => unreachable,
os.ENOMEM => error.SystemResources,
os.EACCES => error.AccessDenied,
os.EAGAIN => unreachable,
os.EALREADY => error.FastOpenAlreadyInProgress,
os.EBADF => unreachable,
os.ECONNRESET => error.ConnectionResetByPeer,
os.EDESTADDRREQ => unreachable,
os.EISCONN => unreachable,
os.EMSGSIZE => error.MessageTooBig,
os.ENOBUFS => error.SystemResources,
os.ENOTCONN => unreachable,
os.ENOTSOCK => unreachable,
os.EOPNOTSUPP => unreachable,
os.EPIPE => error.BrokenPipe,
os.ECONNREFUSED => error.ConnectionRefused,
os.EOVERFLOW => error.BufferOverflow,
os.E2BIG => error.BufferOverflow,
else => |err| os.unexpectedErrno(err),
};
}
extern fn wl_display_dispatch_queue(display: *Display, queue: *client.wl.EventQueue) c_int;
pub fn dispatchQueue(display: *Display, queue: *client.wl.EventQueue) !u32 {
const rc = wl_display_dispatch_queue(display, queue);
return switch (os.errno(rc)) {
0 => @intCast(u32, rc),
os.EFAULT => unreachable,
os.EINTR => unreachable,
os.EINVAL => unreachable,
os.ENOMEM => error.SystemResources,
os.EACCES => error.AccessDenied,
os.EAGAIN => unreachable,
os.EALREADY => error.FastOpenAlreadyInProgress,
os.EBADF => unreachable,
os.ECONNRESET => error.ConnectionResetByPeer,
os.EDESTADDRREQ => unreachable,
os.EISCONN => unreachable,
os.EMSGSIZE => error.MessageTooBig,
os.ENOBUFS => error.SystemResources,
os.ENOTCONN => unreachable,
os.ENOTSOCK => unreachable,
os.EOPNOTSUPP => unreachable,
os.EPIPE => error.BrokenPipe,
os.ECONNREFUSED => error.ConnectionRefused,
os.EOVERFLOW => error.BufferOverflow,
os.E2BIG => error.BufferOverflow,
else => |err| os.unexpectedErrno(err),
};
}
extern fn wl_display_dispatch_pending(display: *Display) c_int;
pub fn dispatchPending(display: *Display) !u32 {
const rc = wl_display_dispatch_pending(display);
return switch (os.errno(rc)) {
0 => @intCast(u32, rc),
// TODO
else => |err| os.unexpectedErrno(err),
};
}
extern fn wl_display_dispatch_queue_pending(display: *Display, queue: *client.wl.EventQueue) c_int;
pub fn dispatchQueuePending(display: *Display, queue: *client.wl.EventQueue) !u32 {
const rc = wl_display_dispatch_queue_pending(display, queue);
return switch (os.errno(rc)) {
0 => @intCast(u32, rc),
// TODO
else => |err| os.unexpectedErrno(err),
};
}
extern fn wl_display_roundtrip(display: *Display) c_int;
pub fn roundtrip(display: *Display) !u32 {
const rc = wl_display_roundtrip(display);
return switch (os.errno(rc)) {
0 => @intCast(u32, rc),
// TODO
else => |err| os.unexpectedErrno(err),
};
}
extern fn wl_display_roundtrip_queue(display: *Display, queue: *client.wl.EventQueue) c_int;
pub fn roundtripQueue(display: *Display, queue: *client.wl.EventQueue) !u32 {
const rc = wl_display_roundtrip_queue(display, queue);
return switch (os.errno(rc)) {
0 => @intCast(u32, rc),
// TODO
else => |err| os.unexpectedErrno(err),
};
}
extern fn wl_display_flush(display: *Display) c_int;
pub fn flush(display: *Display) error{WouldBlock}!u32 {
const rc = wl_display_dispatch_queue_pending(display, queue);
return switch (os.errno(rc)) {
0 => @intCast(u32, rc),
os.EAGAIN => error.WouldBlock,
else => unreachable,
};
}
extern fn wl_display_create_queue(display: *Display) *client.wl.EventQueue;
pub fn createQueue(display: *Display) error{OutOfMemory}!*client.wl.EventQueue {
return wl_display_create_queue(display) orelse error.OutOfMemory;
}
// TODO: should we interpret this return value?
extern fn wl_display_get_error(display: *Display) c_int;
pub fn getError(display: *Display) c_int {
return wl_display_get_error(display);
} | src/client_display_functions.zig |
const std = @import("std");
const misc = @import("misc.zig");
const NChooseK = misc.NChooseK;
const NChooseKBig = misc.NChooseKBig;
// TODO: benchmark this against previous version from 78b055
pub fn Combinations(comptime Element: type, comptime Set: type) type {
return struct {
nck: Nck,
initial_state: []const Element,
buf: []Element,
const Self = @This();
const Nck = NChooseK(Set);
const SetLog2 = std.math.Log2Int(Set);
pub fn init(initial_state: []const Element, buf: []u8, k: SetLog2) !Self {
if (k > initial_state.len or k > buf.len or initial_state.len > std.math.maxInt(SetLog2)) return error.ArgumentBounds;
return Self{
.nck = try Nck.init(@intCast(SetLog2, initial_state.len), k),
.initial_state = initial_state,
.buf = buf,
};
}
fn next(self: *Self) ?[]Element {
return if (self.nck.next()) |nckbits| blk: {
var bits = nckbits;
std.mem.copy(Element, self.buf, self.initial_state[0..@intCast(usize, self.nck.k)]);
var i: usize = 0;
while (i < self.nck.k) : (i += 1) {
const idx = @ctz(Set, bits);
bits &= ~(@as(Set, 1) << @intCast(SetLog2, idx));
self.buf[i] = self.initial_state[idx];
}
break :blk self.buf[0..@intCast(usize, self.nck.k)];
} else null;
}
};
}
const expecteds_by_len: []const []const []const u8 = &.{
&.{ "A", "B", "C", "A" },
&.{ "AB", "AC", "BC", "AA", "BA", "CA" },
&.{ "ABC", "ABA", "ACA", "BCA" },
&.{"ABCA"},
};
test "iterate" {
for (expecteds_by_len) |expectedslen, len| {
const initial_state = "ABCA";
var buf = initial_state.*;
var it = try Combinations(u8, usize).init(initial_state, &buf, @intCast(u6, len + 1));
for (expectedslen) |expected| {
const actual = it.next().?;
try std.testing.expectEqualStrings(expected, actual);
}
}
}
test "edge cases" {
const initial_state = "ABCA";
var buf = initial_state.*;
// k = 0
{
var it = try Combinations(u8, usize).init(initial_state, &buf, 0);
try std.testing.expectEqual(it.next(), null);
}
// over sized k
{
try std.testing.expectError(
error.ArgumentBounds,
Combinations(u8, usize).init(initial_state, &buf, initial_state.len + 1),
);
}
// zero sized initial_state, or too small
{
try std.testing.expectError(
error.ArgumentBounds,
Combinations(u8, usize).init("", &buf, initial_state.len),
);
try std.testing.expectError(
error.ArgumentBounds,
Combinations(u8, usize).init("A", &buf, initial_state.len),
);
}
// buffer too small
{
var buf2: [1]u8 = undefined;
try std.testing.expectError(
error.ArgumentBounds,
Combinations(u8, usize).init(initial_state, &buf2, initial_state.len),
);
}
}
test "set size 127" {
const initial_state_large = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ++
"a".* ** 23;
try std.testing.expectEqual(127, initial_state_large.len);
{
var buf = initial_state_large.*;
var it = try Combinations(u8, u128).init(initial_state_large, &buf, initial_state_large.len - 1);
while (it.next()) |c| {}
}
{
const init_too_large = initial_state_large ++ "a";
var buf = init_too_large.*;
try std.testing.expectError(error.ArgumentBounds, Combinations(u8, u128).init(
init_too_large,
&buf,
initial_state_large.len - 1,
));
}
}
pub fn CombinationsBig(comptime Element: type) type {
return struct {
nck: Nck,
initial_state: []const Element,
buf: []Element,
const Self = @This();
const Nck = NChooseKBig;
pub fn init(allocator: *std.mem.Allocator, initial_state: []const Element, buf: []u8, k: usize) !Self {
if (k > initial_state.len or k > buf.len or initial_state.len > std.math.maxInt(usize)) return error.ArgumentBounds;
return Self{
.nck = try Nck.init(allocator, initial_state.len, k),
.initial_state = initial_state,
.buf = buf,
};
}
fn next(self: *Self) !?[]Element {
return if (try self.nck.next()) |*bits| blk: {
defer bits.deinit();
std.mem.copy(Element, self.buf, self.initial_state[0..self.nck.k]);
var i: usize = 0;
while (i < self.nck.k) : (i += 1) {
var idx: usize = 0;
for (bits.limbs[0..bits.len()]) |limb| {
idx += @ctz(usize, limb);
if (limb != 0) break;
}
// bits &= ~(1 << idx);
// unset bit at idx
const limb_idx = idx / 64;
const limb_offset = idx % 64;
bits.limbs[limb_idx] &= ~(@as(usize, 1) << @intCast(u6, limb_offset));
self.buf[i] = self.initial_state[idx];
}
break :blk self.buf[0..self.nck.k];
} else null;
}
};
}
test "big iterate" {
for (expecteds_by_len) |expectedslen, len| {
const initial_state = "ABCA";
var buf = initial_state.*;
var it = try CombinationsBig(u8).init(std.testing.allocator, initial_state, &buf, len + 1);
defer it.nck.deinit();
for (expectedslen) |expected| {
var actual = (try it.next()).?;
try std.testing.expectEqualStrings(expected, actual);
}
}
}
test "big set size 127" {
// make sure all combos match normal Combinations iterator
const initial_state_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ++
"a".* ** 23;
try std.testing.expectEqual(127, initial_state_big.len);
{
var buf = initial_state_big.*;
var buf2 = initial_state_big.*;
var it = try CombinationsBig(u8).init(std.testing.allocator, initial_state_big, &buf, initial_state_big.len - 1);
var it2 = try Combinations(u8, u128).init(initial_state_big, &buf2, initial_state_big.len - 1);
defer it.nck.deinit();
while (try it.next()) |actual| {
const expected = it2.next().?;
try std.testing.expectEqualStrings(expected, actual);
}
}
}
test "big set size 256" {
const initial_state_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ** 2 ++
"a".* ** 48;
try std.testing.expectEqual(256, initial_state_big.len);
{
var buf = initial_state_big.*;
var it = try CombinationsBig(u8).init(std.testing.allocator, initial_state_big, &buf, initial_state_big.len - 1);
defer it.nck.deinit();
var i: usize = 0;
while (try it.next()) |actual| : (i += 1) {}
try std.testing.expectEqual(@as(usize, 256), i);
}
}
test "big set size 256 choose 2" {
const expecteds: []const []const u8 = &.{
&.{ 0, 1 },
&.{ 0, 2 },
&.{ 1, 2 },
&.{ 0, 3 },
&.{ 1, 3 },
&.{ 2, 3 },
&.{ 0, 4 },
&.{ 1, 4 },
&.{ 2, 4 },
&.{ 3, 4 },
};
var xs: [256]u8 = undefined;
const k = 2;
var buf: [k]u8 = undefined;
for (xs) |*x, i| x.* = @intCast(u8, i); // xs == 0..255
var it = try CombinationsBig(u8).init(std.testing.allocator, &xs, &buf, k);
defer it.nck.deinit();
var i: usize = 0;
for (expecteds) |expected| {
const actual = (try it.next()).?;
try std.testing.expectEqualSlices(u8, expected, actual);
i += 1;
}
while (try it.next()) |_| : (i += 1) {}
// binomial(256,2 ) == 32640
try std.testing.expectEqual(@as(usize, 32640), i);
} | src/combinations.zig |
const c = @import("c.zig");
const assert = @import("std").debug.assert;
// we wrap the c module for 3 reasons:
// 1. to avoid accidentally calling the non-thread-safe functions
// 2. patch up some of the types to remove nullability
// 3. some functions have been augmented by zig_llvm.cpp to be more powerful,
// such as ZigLLVMTargetMachineEmitToFile
pub const AttributeIndex = c_uint;
pub const Bool = c_int;
pub const Builder = c.LLVMBuilderRef.Child.Child;
pub const Context = c.LLVMContextRef.Child.Child;
pub const Module = c.LLVMModuleRef.Child.Child;
pub const Value = c.LLVMValueRef.Child.Child;
pub const Type = c.LLVMTypeRef.Child.Child;
pub const BasicBlock = c.LLVMBasicBlockRef.Child.Child;
pub const Attribute = c.LLVMAttributeRef.Child.Child;
pub const Target = c.LLVMTargetRef.Child.Child;
pub const TargetMachine = c.LLVMTargetMachineRef.Child.Child;
pub const TargetData = c.LLVMTargetDataRef.Child.Child;
pub const DIBuilder = c.ZigLLVMDIBuilder;
pub const DIFile = c.ZigLLVMDIFile;
pub const DICompileUnit = c.ZigLLVMDICompileUnit;
pub const ABIAlignmentOfType = c.LLVMABIAlignmentOfType;
pub const AddAttributeAtIndex = c.LLVMAddAttributeAtIndex;
pub const AddModuleCodeViewFlag = c.ZigLLVMAddModuleCodeViewFlag;
pub const AddModuleDebugInfoFlag = c.ZigLLVMAddModuleDebugInfoFlag;
pub const ClearCurrentDebugLocation = c.ZigLLVMClearCurrentDebugLocation;
pub const ConstAllOnes = c.LLVMConstAllOnes;
pub const ConstArray = c.LLVMConstArray;
pub const ConstBitCast = c.LLVMConstBitCast;
pub const ConstIntOfArbitraryPrecision = c.LLVMConstIntOfArbitraryPrecision;
pub const ConstNeg = c.LLVMConstNeg;
pub const ConstStructInContext = c.LLVMConstStructInContext;
pub const DIBuilderFinalize = c.ZigLLVMDIBuilderFinalize;
pub const DisposeBuilder = c.LLVMDisposeBuilder;
pub const DisposeDIBuilder = c.ZigLLVMDisposeDIBuilder;
pub const DisposeMessage = c.LLVMDisposeMessage;
pub const DisposeModule = c.LLVMDisposeModule;
pub const DisposeTargetData = c.LLVMDisposeTargetData;
pub const DisposeTargetMachine = c.LLVMDisposeTargetMachine;
pub const DoubleTypeInContext = c.LLVMDoubleTypeInContext;
pub const DumpModule = c.LLVMDumpModule;
pub const FP128TypeInContext = c.LLVMFP128TypeInContext;
pub const FloatTypeInContext = c.LLVMFloatTypeInContext;
pub const GetEnumAttributeKindForName = c.LLVMGetEnumAttributeKindForName;
pub const GetMDKindIDInContext = c.LLVMGetMDKindIDInContext;
pub const GetUndef = c.LLVMGetUndef;
pub const HalfTypeInContext = c.LLVMHalfTypeInContext;
pub const InitializeAllAsmParsers = c.LLVMInitializeAllAsmParsers;
pub const InitializeAllAsmPrinters = c.LLVMInitializeAllAsmPrinters;
pub const InitializeAllTargetInfos = c.LLVMInitializeAllTargetInfos;
pub const InitializeAllTargetMCs = c.LLVMInitializeAllTargetMCs;
pub const InitializeAllTargets = c.LLVMInitializeAllTargets;
pub const InsertBasicBlockInContext = c.LLVMInsertBasicBlockInContext;
pub const Int128TypeInContext = c.LLVMInt128TypeInContext;
pub const Int16TypeInContext = c.LLVMInt16TypeInContext;
pub const Int1TypeInContext = c.LLVMInt1TypeInContext;
pub const Int32TypeInContext = c.LLVMInt32TypeInContext;
pub const Int64TypeInContext = c.LLVMInt64TypeInContext;
pub const Int8TypeInContext = c.LLVMInt8TypeInContext;
pub const IntPtrTypeForASInContext = c.LLVMIntPtrTypeForASInContext;
pub const IntPtrTypeInContext = c.LLVMIntPtrTypeInContext;
pub const LabelTypeInContext = c.LLVMLabelTypeInContext;
pub const MDNodeInContext = c.LLVMMDNodeInContext;
pub const MDStringInContext = c.LLVMMDStringInContext;
pub const MetadataTypeInContext = c.LLVMMetadataTypeInContext;
pub const PPCFP128TypeInContext = c.LLVMPPCFP128TypeInContext;
pub const SetAlignment = c.LLVMSetAlignment;
pub const SetDataLayout = c.LLVMSetDataLayout;
pub const SetGlobalConstant = c.LLVMSetGlobalConstant;
pub const SetInitializer = c.LLVMSetInitializer;
pub const SetLinkage = c.LLVMSetLinkage;
pub const SetTarget = c.LLVMSetTarget;
pub const SetUnnamedAddr = c.LLVMSetUnnamedAddr;
pub const SetVolatile = c.LLVMSetVolatile;
pub const StructTypeInContext = c.LLVMStructTypeInContext;
pub const TokenTypeInContext = c.LLVMTokenTypeInContext;
pub const X86FP80TypeInContext = c.LLVMX86FP80TypeInContext;
pub const X86MMXTypeInContext = c.LLVMX86MMXTypeInContext;
pub const AddGlobal = LLVMAddGlobal;
extern fn LLVMAddGlobal(M: *Module, Ty: *Type, Name: [*:0]const u8) ?*Value;
pub const ConstStringInContext = LLVMConstStringInContext;
extern fn LLVMConstStringInContext(C: *Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value;
pub const ConstInt = LLVMConstInt;
extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) ?*Value;
pub const BuildLoad = LLVMBuildLoad;
extern fn LLVMBuildLoad(arg0: *Builder, PointerVal: *Value, Name: [*:0]const u8) ?*Value;
pub const ConstNull = LLVMConstNull;
extern fn LLVMConstNull(Ty: *Type) ?*Value;
pub const CreateStringAttribute = LLVMCreateStringAttribute;
extern fn LLVMCreateStringAttribute(
C: *Context,
K: [*]const u8,
KLength: c_uint,
V: [*]const u8,
VLength: c_uint,
) ?*Attribute;
pub const CreateEnumAttribute = LLVMCreateEnumAttribute;
extern fn LLVMCreateEnumAttribute(C: *Context, KindID: c_uint, Val: u64) ?*Attribute;
pub const AddFunction = LLVMAddFunction;
extern fn LLVMAddFunction(M: *Module, Name: [*:0]const u8, FunctionTy: *Type) ?*Value;
pub const CreateCompileUnit = ZigLLVMCreateCompileUnit;
extern fn ZigLLVMCreateCompileUnit(
dibuilder: *DIBuilder,
lang: c_uint,
difile: *DIFile,
producer: [*:0]const u8,
is_optimized: bool,
flags: [*:0]const u8,
runtime_version: c_uint,
split_name: [*:0]const u8,
dwo_id: u64,
emit_debug_info: bool,
) ?*DICompileUnit;
pub const CreateFile = ZigLLVMCreateFile;
extern fn ZigLLVMCreateFile(dibuilder: *DIBuilder, filename: [*:0]const u8, directory: [*:0]const u8) ?*DIFile;
pub const ArrayType = LLVMArrayType;
extern fn LLVMArrayType(ElementType: *Type, ElementCount: c_uint) ?*Type;
pub const CreateDIBuilder = ZigLLVMCreateDIBuilder;
extern fn ZigLLVMCreateDIBuilder(module: *Module, allow_unresolved: bool) ?*DIBuilder;
pub const PointerType = LLVMPointerType;
extern fn LLVMPointerType(ElementType: *Type, AddressSpace: c_uint) ?*Type;
pub const CreateBuilderInContext = LLVMCreateBuilderInContext;
extern fn LLVMCreateBuilderInContext(C: *Context) ?*Builder;
pub const IntTypeInContext = LLVMIntTypeInContext;
extern fn LLVMIntTypeInContext(C: *Context, NumBits: c_uint) ?*Type;
pub const ModuleCreateWithNameInContext = LLVMModuleCreateWithNameInContext;
extern fn LLVMModuleCreateWithNameInContext(ModuleID: [*:0]const u8, C: *Context) ?*Module;
pub const VoidTypeInContext = LLVMVoidTypeInContext;
extern fn LLVMVoidTypeInContext(C: *Context) ?*Type;
pub const ContextCreate = LLVMContextCreate;
extern fn LLVMContextCreate() ?*Context;
pub const ContextDispose = LLVMContextDispose;
extern fn LLVMContextDispose(C: *Context) void;
pub const CopyStringRepOfTargetData = LLVMCopyStringRepOfTargetData;
extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) ?[*:0]u8;
pub const CreateTargetDataLayout = LLVMCreateTargetDataLayout;
extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData;
pub const CreateTargetMachine = ZigLLVMCreateTargetMachine;
extern fn ZigLLVMCreateTargetMachine(
T: *Target,
Triple: [*:0]const u8,
CPU: [*:0]const u8,
Features: [*:0]const u8,
Level: CodeGenOptLevel,
Reloc: RelocMode,
CodeModel: CodeModel,
function_sections: bool,
) ?*TargetMachine;
pub const GetHostCPUName = LLVMGetHostCPUName;
extern fn LLVMGetHostCPUName() ?[*:0]u8;
pub const GetNativeFeatures = ZigLLVMGetNativeFeatures;
extern fn ZigLLVMGetNativeFeatures() ?[*:0]u8;
pub const GetElementType = LLVMGetElementType;
extern fn LLVMGetElementType(Ty: *Type) *Type;
pub const TypeOf = LLVMTypeOf;
extern fn LLVMTypeOf(Val: *Value) *Type;
pub const BuildStore = LLVMBuildStore;
extern fn LLVMBuildStore(arg0: *Builder, Val: *Value, Ptr: *Value) ?*Value;
pub const BuildAlloca = LLVMBuildAlloca;
extern fn LLVMBuildAlloca(arg0: *Builder, Ty: *Type, Name: ?[*:0]const u8) ?*Value;
pub const ConstInBoundsGEP = LLVMConstInBoundsGEP;
pub extern fn LLVMConstInBoundsGEP(ConstantVal: *Value, ConstantIndices: [*]*Value, NumIndices: c_uint) ?*Value;
pub const GetTargetFromTriple = LLVMGetTargetFromTriple;
extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **Target, ErrorMessage: ?*[*:0]u8) Bool;
pub const VerifyModule = LLVMVerifyModule;
extern fn LLVMVerifyModule(M: *Module, Action: VerifierFailureAction, OutMessage: *?[*:0]u8) Bool;
pub const GetInsertBlock = LLVMGetInsertBlock;
extern fn LLVMGetInsertBlock(Builder: *Builder) *BasicBlock;
pub const FunctionType = LLVMFunctionType;
extern fn LLVMFunctionType(
ReturnType: *Type,
ParamTypes: [*]*Type,
ParamCount: c_uint,
IsVarArg: Bool,
) ?*Type;
pub const GetParam = LLVMGetParam;
extern fn LLVMGetParam(Fn: *Value, Index: c_uint) *Value;
pub const AppendBasicBlockInContext = LLVMAppendBasicBlockInContext;
extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*:0]const u8) ?*BasicBlock;
pub const PositionBuilderAtEnd = LLVMPositionBuilderAtEnd;
extern fn LLVMPositionBuilderAtEnd(Builder: *Builder, Block: *BasicBlock) void;
pub const AbortProcessAction = VerifierFailureAction.LLVMAbortProcessAction;
pub const PrintMessageAction = VerifierFailureAction.LLVMPrintMessageAction;
pub const ReturnStatusAction = VerifierFailureAction.LLVMReturnStatusAction;
pub const VerifierFailureAction = c.LLVMVerifierFailureAction;
pub const CodeGenLevelNone = CodeGenOptLevel.LLVMCodeGenLevelNone;
pub const CodeGenLevelLess = CodeGenOptLevel.LLVMCodeGenLevelLess;
pub const CodeGenLevelDefault = CodeGenOptLevel.LLVMCodeGenLevelDefault;
pub const CodeGenLevelAggressive = CodeGenOptLevel.LLVMCodeGenLevelAggressive;
pub const CodeGenOptLevel = c.LLVMCodeGenOptLevel;
pub const RelocDefault = RelocMode.LLVMRelocDefault;
pub const RelocStatic = RelocMode.LLVMRelocStatic;
pub const RelocPIC = RelocMode.LLVMRelocPIC;
pub const RelocDynamicNoPic = RelocMode.LLVMRelocDynamicNoPic;
pub const RelocMode = c.LLVMRelocMode;
pub const CodeModelDefault = CodeModel.LLVMCodeModelDefault;
pub const CodeModelJITDefault = CodeModel.LLVMCodeModelJITDefault;
pub const CodeModelSmall = CodeModel.LLVMCodeModelSmall;
pub const CodeModelKernel = CodeModel.LLVMCodeModelKernel;
pub const CodeModelMedium = CodeModel.LLVMCodeModelMedium;
pub const CodeModelLarge = CodeModel.LLVMCodeModelLarge;
pub const CodeModel = c.LLVMCodeModel;
pub const EmitAssembly = EmitOutputType.ZigLLVM_EmitAssembly;
pub const EmitBinary = EmitOutputType.ZigLLVM_EmitBinary;
pub const EmitLLVMIr = EmitOutputType.ZigLLVM_EmitLLVMIr;
pub const EmitOutputType = c.ZigLLVM_EmitOutputType;
pub const CCallConv = CallConv.LLVMCCallConv;
pub const FastCallConv = CallConv.LLVMFastCallConv;
pub const ColdCallConv = CallConv.LLVMColdCallConv;
pub const WebKitJSCallConv = CallConv.LLVMWebKitJSCallConv;
pub const AnyRegCallConv = CallConv.LLVMAnyRegCallConv;
pub const X86StdcallCallConv = CallConv.LLVMX86StdcallCallConv;
pub const X86FastcallCallConv = CallConv.LLVMX86FastcallCallConv;
pub const CallConv = c.LLVMCallConv;
pub const CallAttr = extern enum {
Auto,
NeverTail,
NeverInline,
AlwaysTail,
AlwaysInline,
};
fn removeNullability(comptime T: type) type {
comptime assert(@typeInfo(T).Pointer.size == .C);
return *T.Child;
}
pub const BuildRet = LLVMBuildRet;
extern fn LLVMBuildRet(arg0: *Builder, V: ?*Value) ?*Value;
pub const TargetMachineEmitToFile = ZigLLVMTargetMachineEmitToFile;
extern fn ZigLLVMTargetMachineEmitToFile(
targ_machine_ref: *TargetMachine,
module_ref: *Module,
filename: [*:0]const u8,
output_type: EmitOutputType,
error_message: *[*:0]u8,
is_debug: bool,
is_small: bool,
) bool;
pub const BuildCall = ZigLLVMBuildCall;
extern fn ZigLLVMBuildCall(B: *Builder, Fn: *Value, Args: [*]*Value, NumArgs: c_uint, CC: CallConv, fn_inline: CallAttr, Name: [*:0]const u8) ?*Value;
pub const PrivateLinkage = c.LLVMLinkage.LLVMPrivateLinkage; | src-self-hosted/llvm.zig |
const std = @import("std");
const assert = std.debug.assert;
const warn = std.debug.warn;
// Define three structs each with a method named `returnSomething` then
// in handleReturnType we pass a Type and then use a switch statement
// on @typeOf(s.returnSomething).ReturnType. Then in each arm of the switch
// we match on the actual return type and provide what going to happen at
// runtime.
//
// So when handleReturnType is executed at compile it generates code a routine
// which when executed contains just the code in the selected switch arm.
const S1 = struct {
fn returnSomething(a: bool) u64 {
warn("a={}\n", a);
return @intCast(u64, 1);
}
};
const S2 = struct {
fn returnSomething(a: bool) void {
warn("a={}\n", a);
}
};
const S3 = struct {
fn returnSomething(a: bool) error!u64 {
warn("a={}\n", a);
if (a) {
return error.aIsTrue;
} else {
return @intCast(u64, 1);
}
}
};
fn handleReturnType(comptime s: var) error!void {
switch(@typeOf(s.returnSomething).ReturnType) {
u64 => {
var c = s.returnSomething(true);
warn("s.returnSomething c={}\n", c);
return;
},
void => {
s.returnSomething(true);
warn("s.returnSomething void\n");
return;
},
error!u64 => {
var c = try s.returnSomething(false);
warn("s.returnSomething error!u64 c={}\n", c);
return;
},
else => return error.BadNews,
}
}
test "return-type" {
warn("\n");
assert((try S3.returnSomething(false)) == 1);
try handleReturnType(S1);
// Above generates:
// var c = s.returnSomething(true);
// warn("s.returnSomething c={}\n", c);
try handleReturnType(S2);
// Above generates:
// s.returnSomething(true);
// warn("s.returnSomething void\n");
try handleReturnType(S3);
// Above generates:
//var c = try s.returnSomething(false);
//warn("s.returnSomething error!u64 c={}\n", c);
} | return-type/return-type.zig |
const std = @import("std");
const token = @import("../token.zig");
const ast = @import("../ast.zig");
const fieldNames = std.meta.fieldNames;
const eq = std.mem.eq;
const TokenError = token.TokenError;
const Token = token.Token;
const Ast = ast.Ast;
const Kind = Token.Kind;
const @"Type" = @import("./type.zig").@"Type";
const Op = @import("./op.zig").Op;
const Kw = @import("./kw.zig").Kw;
const enums = std.enums;
pub const Block = union(enum(u8)) {
const Self = @This();
lpar: ?[]const u8,
rpar: ?[]const u8,
lbrace: ?[]const u8,
rbrace: ?[]const u8,
lbracket: ?[]const u8,
rbracket: ?[]const u8,
lstate: ?[]const u8,
rstate: ?[]const u8,
lattr: ?[]const u8,
rattr: ?[]const u8,
ldef: ?[]const u8,
rdef: ?[]const u8,
ltype: ?[]const u8,
rtype: ?[]const u8,
squote,
dquote,
btick,
lcomment, //comment left block
rcomment,
lque,
rque,
ldoc,
rdoc,
lawait,
rawait,
llnquery,
rlnquery,
ldocln,
rdocln,
lawaitque,
rawaitque,
ldata: ?[]const u8,
rdata: ?[]const u8,
lsynth: ?[]const u8,
rsynth: ?[]const u8,
page,
pub const Info = struct {
ident: ?[]const u8,
state: Rel,
pub const Rel = union(enum(u2)) { start, end, outside };
};
pub fn isBlockStart(self: Block) Block.Info.Rel {
return switch (@tagName(self)[0]) {
'l' => .start,
'r' => .end,
else => .outside,
};
}
pub fn closing(self: Block) Block {
return switch (self) {
.lpar => |l| Block{ .rpar = l },
.lbrace => |l| Block{ .rbrace = l },
.ldoc => .rdoc,
.squote => .squote,
.dquote => .dquote,
.lbracket => |l| Block{ .rbracket = l },
.ldata => |l| Block{ .rdata = l },
.lsynth => |l| Block{ .rsynth = l },
.lattr => |l| Block{ .rattr = l },
.lstate => |l| Block{ .rstate = l },
.ldef => |l| Block{ .rdef = l },
.lcomment => .rcomment,
.ltype => |l| Block{ .rtype = l },
.lawait => .rawait,
.btick => .btick,
.lque => .rque,
.lawaitque => .rawaitque,
.llnquery => .rlnquery,
.ldocln => .rdocln,
else => Block{ .rbrace = null },
};
}
pub fn brace(id: ?[]const u8, rel: Block.Rel) Block {
switch (rel) {
.start, .outside => Block{ .lbrace = id },
.end => Block{ .rbrace = id },
}
return Block.lbrace;
}
pub fn state(id: ?[]const u8, rel: Block.Rel) Block {
switch (rel) {
.start, .ambiguous => Block.State{ .lbrace = id },
.end => Block.State{ .rbrace = id },
}
return Block.lbrace;
}
pub const ltypesym = '<';
pub const rtypesym = '>';
// All are used as line statements
pub const sblock = .{ "-|", "|-" };
pub const ablock = .{ "-:", ":-" };
pub const inlque = .{ "-?", "?-" };
pub const doclnc = .{ "-!", "!-" };
pub const databl = .{ ".:", ":." };
pub const bcomment = .{ "--|", "|--" };
pub const dcomment = .{ "--!", "!--" };
pub const defblock = .{ "--:", ":--" };
pub const queblock = .{ "--?", "?--" };
pub const waitblock = .{ "..!", "!.." };
pub const waitquery = .{ "..?", "?.." };
pub const synthesis = .{ "..:", ":.." };
pub fn isBlock(inp: []const u8) Block {
return switch (inp[0]) {
'(' => .lpar,
')' => .rpar,
'[' => .lbracket,
']' => .lbracket,
'{' => .lbrace,
'}' => .rbrace,
'\'' => .squote,
'"' => .dquote,
'`' => .btick,
'-' => {
if (eq(u8, bcomment[0], inp)) {
return .lcomment;
} else if (eq(u8, bcomment[1], inp)) {
return .rcomment;
} else {
return null;
}
},
else => null,
};
}
pub fn toStr(bl: Block) []const u8 {
return @tagName(bl);
}
}; | src/lang/token/block.zig |
const std = @import("std");
pub usingnamespace(@import("types.zig"));
const x86 = @import("machine.zig");
const Operand = x86.operand.Operand;
const OperandType = x86.operand.OperandType;
const ModRm = x86.operand.ModRm;
const ModRmResult = x86.operand.ModRmResult;
const Register = x86.register.Register;
const Machine = x86.Machine;
pub const AvxMagic = enum (u8) {
Vex2 = 0xC4,
Vex3 = 0xC5,
Xop = 0x8F,
Evex = 0x62,
pub fn value(self: AvxMagic) u8 {
return @enumToInt(self);
}
};
/// NOTE: We don't store any of the values like R/X/B inverted, they only
/// get inverted when they get encoded.
pub const AvxResult = struct {
encoding: AvxMagic = undefined,
/// R'
R_: u1 = 0,
R: u1 = 0,
X: u1 = 0,
B: u1 = 0,
W: u1 = 0,
map: u5 = 0,
/// V'
V_: u1 = 0,
vvvv: u4 = 0b0000,
/// L'
L_: u1 = 0,
L: u1 = 0,
pp: u2 = 0b00,
is4: ?u4 = null,
z: u1 = 0,
b: u1 = 0,
aaa: u3 = 0,
pub fn needs64Bit(self: AvxResult) bool {
return (
self.R == 1
or self.X == 1
or self.B == 1
or self.W == 1
or self.R_ == 1
or self.V_ == 1
or self.vvvv > 7
or (self.is4 != null and self.is4.? > 7)
);
}
pub fn addVecLen(self: *AvxResult, machine: Machine, vec_len: EvexLength) void {
switch (vec_len) {
.L128, .LZ => self.L = 0,
.L256, .L1 => self.L = 1,
.L512 => {
self.L = 0;
self.L_ = 1;
},
.LIG => {
self.L = @intCast(u1, (machine.l_fill >> 0) & 0x01);
self.L_ = @intCast(u1, (machine.l_fill >> 1) & 0x01);
},
._11 => unreachable,
.LRC => {
// TODO:
unreachable;
},
}
}
pub fn addModRm(self: *AvxResult, modrm: *const ModRmResult) void {
self.X = modrm.rex_x;
self.B = modrm.rex_b;
self.V_ |= modrm.evex_v;
switch (modrm.data_size) {
.DWORD_BCST, .QWORD_BCST => self.b = 1,
else => {},
}
}
pub fn addPred(self: *AvxResult, mask: MaskRegister, z: ZeroOrMerge) void {
self.aaa = @enumToInt(mask);
self.z = @enumToInt(z);
}
pub fn addSae(self: *AvxResult, sae: SuppressAllExceptions) void {
switch (sae) {
.AE => {},
.SAE => {
self.b = 1;
},
else => {
self.b = 1;
const LL_ = @enumToInt(sae);
self.L = @intCast(u1, (LL_ >> 0) & 0x01);
self.L_ = @intCast(u1, (LL_ >> 1) & 0x01);
},
}
}
pub fn addVecR(self: *AvxResult, num: u8) void {
self.R = @intCast(u1, (num & 0x08) >> 3);
self.R_ = @intCast(u1, (num & 0x10) >> 4);
}
pub fn addVecV(self: *AvxResult, num: u8) void {
self.vvvv = @intCast(u4, (num & 0x0f));
self.V_ = @intCast(u1, (num & 0x10) >> 4);
}
pub fn addVecRm(self: *AvxResult, reg: Register) void {
const reg_num = reg.number();
self.B = @intCast(u1, (reg_num & 0x08) >> 3);
self.X = @intCast(u1, (reg_num & 0x10) >> 4);
}
/// Generate EVEX prefix bytes
///
/// 7 6 5 4 3 2 1 0
/// 62 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 |
/// P0: | R | X | B | R'| 0 | 0 | m | m |
/// P1: | W | v | v | v | v | 1 | p | p |
/// P2: | z | L'| L | b | V'| a | a | a |
pub fn makeEvex(self: AvxResult) [4]u8 {
const P0: u8 = (
(@as(u8, ~self.R) << 7)
| (@as(u8, ~self.X) << 6)
| (@as(u8, ~self.B) << 5)
| (@as(u8, ~self.R_) << 4)
// | (0b00 << 2)
| (@as(u8, self.map) << 0)
);
const P1: u8 = (
(@as(u8, self.W) << 7)
| (@as(u8, ~self.vvvv) << 3)
| (@as(u8, 1) << 2)
| (@as(u8, self.pp) << 0)
);
const P2: u8 = (
(@as(u8, self.z) << 7)
| (@as(u8, self.L_) << 6)
| (@as(u8, self.L) << 5)
| (@as(u8, self.b) << 4)
| (@as(u8, ~self.V_) << 3)
| (@as(u8, self.aaa) << 0)
);
return [4]u8 { 0x62, P0, P1, P2 };
}
/// Generate VEX2 prefix bytes
///
/// 7 6 5 4 3 2 1 0
/// C5 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 |
/// P0: | R | v | v | v | v | L | p | p |
pub fn makeVex2(self: AvxResult) [2]u8 {
const P0: u8 = (
(@as(u8, ~self.R) << 7)
| (@as(u8, ~self.vvvv) << 3)
| (@as(u8, self.L) << 2)
| (@as(u8, self.pp) << 0)
);
return [2]u8 { 0xC5, P0 };
}
fn makeCommonXopVex3(self: AvxResult, magic: u8) [3]u8 {
const P0: u8 = (
(@as(u8, ~self.R) << 7)
| (@as(u8, ~self.X) << 6)
| (@as(u8, ~self.B) << 5)
// | (0b000 << 2)
| (@as(u8, self.map) << 0)
);
const P1: u8 = (
(@as(u8, self.W) << 7)
| (@as(u8, ~self.vvvv) << 3)
| (@as(u8, self.L) << 2)
| (@as(u8, self.pp) << 0)
);
return [3]u8 { magic, P0, P1 };
}
/// Generate VEX3 prefix bytes
///
/// 7 6 5 4 3 2 1 0
/// C4 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
/// P0: | R | X | B | 0 | 0 | 0 | m | m |
/// P1: | W | v | v | v | v | L | p | p |
pub fn makeVex3(self: AvxResult) [3]u8 {
return self.makeCommonXopVex3(0xC4);
}
/// Generate XOP prefix bytes
///
/// 7 6 5 4 3 2 1 0
/// 8F | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
/// P0: | R | X | B | 0 | 0 | 0 | m | m |
/// P1: | W | v | v | v | v | L | p | p |
pub fn makeXop(self: AvxResult) [3]u8 {
return self.makeCommonXopVex3(0x8F);
}
};
pub const AvxEncoding = enum {
VEX,
XOP,
EVEX,
};
pub const VexPrefix = enum(u2) {
/// No prefix
_NP = 0b00,
_66 = 0b01,
_F3 = 0b10,
_F2 = 0b11,
};
// NOTE: Technically this is 5 bit, but 3 high bits are reserved and should be 0
pub const VexEscape = enum (u2) {
_0F = 0b01,
_0F38 = 0b10,
_0F3A = 0b11,
};
pub const XopMapSelect = enum (u5) {
_08h = 0b01000,
_09h = 0b01001,
_0Ah = 0b01010,
};
pub const VexW = enum {
W0 = 0,
W1 = 1,
/// W ignored
WIG,
/// W acts as REX.W
W,
};
pub const VexLength = enum(u8) {
L128 = 0b0,
L256 = 0b1,
/// L ignored
LIG = 0x80,
/// L = 0
LZ = 0x81,
/// L = 1
L1 = 0x82,
};
pub const EvexLength = enum(u8) {
L128 = 0b00,
L256 = 0b01,
L512 = 0b10,
_11 = 0b11,
/// LL ignored
LIG = 0x80,
/// LZ: LL = 0 (used in VEX, not normaly used in EVEX)
LZ = 0x81,
/// L1: LL = 1 (used in VEX, not normaly used in EVEX)
L1 = 0x82,
/// LL is used for rounding control
LRC = 0x83,
};
pub const MaskRegister = enum (u3) {
NoMask = 0b000,
K1 = 0b001,
K2,
K3,
K4,
K5,
K6,
K7 = 0b111,
};
pub const ZeroOrMerge = enum (u1) {
Merge = 0,
Zero = 1,
};
pub const RegisterPredicate = struct {
reg: Register,
mask: MaskRegister,
z: ZeroOrMerge,
pub fn create(r: Register, k: MaskRegister, z: ZeroOrMerge) RegisterPredicate {
return RegisterPredicate {
.reg = r,
.mask = k,
.z = z,
};
}
};
pub const RmPredicate = struct {
rm: ModRm,
mask: MaskRegister,
z: ZeroOrMerge,
pub fn create(rm: ModRm, k: MaskRegister, z: ZeroOrMerge) RmPredicate {
return RmPredicate {
.rm = rm,
.mask = k,
.z = z,
};
}
};
pub const RegisterSae = struct {
reg: Register,
sae: SuppressAllExceptions,
pub fn create(r: Register, sae: SuppressAllExceptions) RegisterSae {
return RegisterSae {
.reg = r,
.sae = sae,
};
}
};
pub const SuppressAllExceptions = enum (u3) {
/// Round toward nearest and SAE
RN_SAE = 0b00,
/// Round toward -inf and SAE
RD_SAE = 0b01,
/// Round toward +inf and SAE
RU_SAE = 0b10,
/// Round toward 0 and SAE
RZ_SAE = 0b11,
/// Allow exceptions (AE)
AE,
/// Suppress all exceptions (SAE)
SAE,
};
pub const TupleType = enum(u8) {
None,
NoMem,
Full,
Half,
Tuple1Scalar,
Tuple1Fixed,
Tuple2,
Tuple4,
Tuple8,
FullMem,
HalfMem,
QuarterMem,
EighthMem,
Mem128,
Movddup,
};
/// Calultate N for disp8*N compressed displacement in AVX512
///
/// NOTE: this does not take into account EVEX.b broadcast bit. If a broadcast
/// is used, should pick N according to:
/// * m32bcst -> N = 4
/// * m64bcst -> N = 8
pub fn calcDispMultiplier(op: AvxOpcode, op_type: OperandType) u8 {
if (op.encoding != .EVEX) {
return 1;
}
const full: u8 = switch (op.vec_len) {
.L128 => 16,
.L256 => 32,
.L512 => 64,
else => 0,
};
const tup_size: u8 = switch (op.vex_w) {
.W0 => 4,
.W1 => 8,
else => 0,
};
const result: u8 = switch (op.tuple_type) {
.None => unreachable,
.NoMem => 0,
.Tuple1Scalar => switch (op_type.getMemClass()) {
.mem8 => 1,
.mem16 => 2,
.mem32 => 4,
.mem64 => 8,
else => tup_size,
},
.Tuple1Fixed => switch (op_type.getMemClass()) {
.mem32 => @as(u8, 4),
.mem64 => @as(u8, 8),
else => unreachable,
},
.Tuple2 => tup_size * 2,
.Tuple4 => tup_size * 4,
.Tuple8 => tup_size * 8,
.Full, .FullMem => full,
.Half, .HalfMem => full / 2,
.QuarterMem => full / 4,
.EighthMem => full / 8,
.Mem128 => 16,
.Movddup => switch (op.vec_len) {
.L128 => @as(u8, 8),
.L256 => @as(u8, 32),
.L512 => @as(u8, 64),
else => unreachable,
},
};
return result;
}
pub const AvxOpcode = struct {
encoding: AvxEncoding,
vec_len: EvexLength,
prefix: VexPrefix,
map_select: u5,
opcode: u8,
reg_bits: ?u3 = null,
vex_w: VexW,
tuple_type: TupleType = .None,
pub fn encode(
self: AvxOpcode,
machine: Machine,
vec1_r: ?*const Operand,
vec2_v: ?*const Operand,
vec3_rm: ?*const Operand,
modrm_result: ?*const ModRmResult,
) AsmError!AvxResult {
var res = AvxResult{};
res.pp = @enumToInt(self.prefix);
res.map = self.map_select;
res.addVecLen(machine, self.vec_len);
// handle (E)VEX modrm.reg register
if (vec1_r) |v| {
switch (v.*) {
.Reg => |reg| {
res.addVecR(reg.number());
},
.RegPred => |reg_pred| {
res.addVecR(reg_pred.reg.number());
res.addPred(reg_pred.mask, reg_pred.z);
},
.RegSae => |reg_sae| {
res.addVecR(reg_sae.reg.number());
res.addSae(reg_sae.sae);
},
else => unreachable,
}
} else if (self.reg_bits) |reg_bits| {
res.addVecR(reg_bits);
} else x: {
res.addVecR(0);
}
// handle (E)VEX.V'vvvv register
if (vec2_v) |v| {
switch (v.*) {
.Reg => |reg| {
res.addVecV(reg.number());
},
.RegPred => |reg_pred| {
res.addVecV(reg_pred.reg.number());
res.addPred(reg_pred.mask, reg_pred.z);
},
else => unreachable,
}
} else {
res.addVecV(0);
}
// handle (E)VEX modrm.rm register
if (vec3_rm) |vec| {
switch (vec.*) {
.Reg => |reg| {
res.addVecRm(reg);
},
.Rm => |rm| switch (rm) {
.Reg => |reg| res.addVecRm(reg),
else => res.addModRm(modrm_result.?),
},
.RegSae => |reg_sae| {
res.addVecRm(reg_sae.reg);
res.addSae(reg_sae.sae);
},
.RmPred => |rm_pred| {
res.addPred(rm_pred.mask, rm_pred.z);
switch (rm_pred.rm) {
.Reg => |reg| res.addVecRm(reg),
else => res.addModRm(modrm_result.?),
}
},
else => unreachable,
}
}
if (machine.mode != .x64 and res.needs64Bit()) {
return AsmError.InvalidMode;
}
switch (self.vex_w) {
.WIG => res.W = machine.w_fill,
.W0 => res.W = 0,
.W1 => res.W = 1,
.W => { unreachable; }, // TODO
}
switch (self.encoding) {
// TODO: some way to force 3 byte Vex encoding
.VEX => {
std.debug.assert(
(res.L_ == 0)
and (res.R_ == 0)
and (vec2_v == null or res.V_ == 0)
and (res.aaa == 0)
and (res.b == 0)
and (res.z == 0)
);
if (res.X == 0 and res.B == 0 and res.W == 0 and res.map == 0b01) {
res.encoding = .Vex2;
} else {
res.encoding = .Vex3;
}
},
.EVEX => res.encoding = .Evex,
.XOP => res.encoding = .Xop,
}
return res;
}
pub fn evex(
len: EvexLength,
pre: VexPrefix,
esc: VexEscape,
w: VexW,
op: u8,
tuple: TupleType,
) AvxOpcode {
return evexr(len, pre, esc, w, op, null, tuple);
}
pub fn evexr(
len: EvexLength,
pre: VexPrefix,
esc: VexEscape,
w: VexW,
op: u8,
reg: ?u3,
tuple: TupleType,
) AvxOpcode {
return AvxOpcode {
.encoding = .EVEX,
.vec_len = len,
.prefix = pre,
.map_select = @enumToInt(esc),
.vex_w = w,
.opcode = op,
.reg_bits = reg,
.tuple_type = tuple,
};
}
pub fn vex(len: VexLength, pre: VexPrefix, esc: VexEscape, w: VexW, op: u8) AvxOpcode {
return vex_r(len, pre, esc, w, op, null);
}
pub fn vexr(len: VexLength, pre: VexPrefix, esc: VexEscape, w: VexW, op: u8, r: u3) AvxOpcode {
return vex_r(len, pre, esc, w, op, r);
}
pub fn vex_r(
len: VexLength,
pre: VexPrefix,
esc: VexEscape,
w: VexW,
op: u8,
reg: ?u3,
) AvxOpcode {
return vex_common(.VEX, len, pre, @enumToInt(esc), w, op, reg);
}
pub fn xop(len: VexLength, pre: VexPrefix, map: XopMapSelect, w: VexW, op: u8,) AvxOpcode {
return xop_r(len, pre, map, w, op, null);
}
pub fn xopr(len: VexLength, pre: VexPrefix, map: XopMapSelect, w: VexW, op: u8, r: u3) AvxOpcode {
return xop_r(len, pre, map, w, op, r);
}
pub fn xop_r(
len: VexLength,
pre: VexPrefix,
map: XopMapSelect,
w: VexW,
op: u8,
reg: ?u3,
) AvxOpcode {
return vex_common(.XOP, len, pre, @enumToInt(map), w, op, reg);
}
pub fn vex_common(
enc: AvxEncoding,
len: VexLength,
pre: VexPrefix,
map_select: u5,
w: VexW,
op: u8,
reg: ?u3,
) AvxOpcode {
return AvxOpcode {
.encoding = enc,
.vec_len = @intToEnum(EvexLength, @enumToInt(len)),
.prefix = pre,
.map_select = map_select,
.vex_w = w,
.opcode = op,
.reg_bits = reg,
};
}
pub fn format(
self: AvxOpcode,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
context: var,
comptime FmtError: type,
output: fn (@TypeOf(context), []const u8) FmtError!void,
) FmtError!void {
try output(context, @tagName(self.encoding));
try output(context, ".");
try output(context, @tagName(self.vec_len));
switch (self.prefix) {
.NP => {},
._66 => try output(context, ".66"),
._F3 => try output(context, ".F3"),
._F2 => try output(context, ".F2"),
}
switch (self.map_select) {
0b01 => try output(context, ".0F."),
0b10 => try output(context, ".0F3A."),
0b11 => try output(context, ".0F38."),
0b01000 => try output(context, ".map(08h)."),
0b01001 => try output(context, ".map(09h)."),
0b01010 => try output(context, ".map(0Ah)."),
}
try output(context, @tagName(self.vex_w));
try std.fmt.format(context, FmtError, output, " {X}", .{self.opcode});
if (self.reg_bits) |r| {
try std.fmt.format(context, FmtError, output, " /{}", .{self.opcode});
} else {
try output(context, " /r");
}
}
}; | src/x86/avx.zig |
const clap = @import("clap");
const std = @import("std");
const debug = std.debug;
const io = std.io;
const mem = std.mem;
const time = std.time;
const fs = std.fs;
const allocator = std.heap.c_allocator;
var timer: ?time.Timer = null;
pub fn main() !void {
timer = try time.Timer.start();
const params = comptime [_]clap.Param(clap.Help) {
clap.parseParam("-h, --help Display this help and exit.") catch unreachable,
clap.parseParam("-i, --inject <STR> The path to the Electron app.") catch unreachable,
clap.parseParam("-u, --uninject <STR> The path to the Electron app.") catch unreachable,
clap.parseParam("-k, --kernel <STR> The path to your Kernel distro. If left out it uses the current directory.") catch unreachable,
};
var diag = clap.Diagnostic{};
var args = clap.parse(clap.Help, ¶ms, .{ .diagnostic = &diag }) catch |err| {
diag.report(io.getStdErr().writer(), err) catch {};
return err;
};
defer args.deinit();
if (args.option("--inject")) |inject| {
if (args.option("--kernel")) |kernel| {
debug.print("Injecting...\n", .{});
const kernel_path = try fs.path.resolve(allocator, &[_][]const u8{ kernel });
const app_path = try fs.path.resolve(allocator, &[_][]const u8{ inject });
var resources_path = try fs.path.join(allocator, &[_][]const u8{ app_path, "resources" });
// Test if the folder is (probably) either a valid electron app path or an app resources path.
_ = fs.openDirAbsolute(resources_path, .{}) catch {
resources_path = app_path;
};
const app_folder_path = try fs.path.join(allocator, &[_][]const u8{ resources_path, "app" });
const app_asar_path = try fs.path.join(allocator, &[_][]const u8{ resources_path, "app.asar" });
const app_folder_index_path = try fs.path.join(allocator, &[_][]const u8{ resources_path, "app", "index.js" });
const app_folder_package_path = try fs.path.join(allocator, &[_][]const u8{ resources_path, "app", "package.json" });
const app_original_folder_path = try fs.path.join(allocator, &[_][]const u8{ resources_path, "app-original" });
const app_original_asar_path = try fs.path.join(allocator, &[_][]const u8{ resources_path, "app-original.asar" });
debug.print("Detecting injection...\n", .{});
var injected = true;
_ = fs.openDirAbsolute(app_original_folder_path, .{}) catch {
injected = false;
};
if (injected) alreadyInjected();
injected = true;
_ = fs.openFileAbsolute(app_original_asar_path, .{}) catch {
injected = false;
};
if (injected) alreadyInjected();
debug.print("No injection visible.\n", .{});
debug.print("Detecting ASAR.\n", .{});
var usesAsar = false;
_ = fs.openDirAbsolute(app_asar_path, .{}) catch {
usesAsar = true;
};
debug.print("Uses ASAR: {s}\n", .{ usesAsar });
debug.print("Renaming...\n", .{});
if (usesAsar) {
fs.renameAbsolute(app_asar_path, app_original_asar_path) catch appRunning();
} else {
fs.renameAbsolute(app_folder_path, app_original_folder_path) catch appRunning();
}
debug.print("Adding files.\n", .{});
try fs.makeDirAbsolute(app_folder_path);
const index = try fs.createFileAbsolute(app_folder_index_path, .{});
const package = try fs.createFileAbsolute(app_folder_package_path, .{});
defer index.close();
defer package.close();
try index.writeAll(
\\const pkg = require("./package.json");
\\const Module = require("module");
\\const path = require("path");
\\
\\try {
\\ const kernel = require(path.join(pkg.location, "kernel.asar"));
\\ if (kernel?.default) kernel.default({ startOriginal: true });
\\} catch(e) {
\\ console.error("Kernel failed to load: ", e.message);
\\ Module._load(path.join(__dirname, "..", "app-original.asar"), null, true);
\\}
);
const package_start = "{\"main\":\"index.js\",\"location\":\"";
const package_end = "\"}";
const package_json = try mem.join(allocator, "", &[_][]const u8{ package_start, kernel_path, package_end });
defer allocator.free(package_json);
try package.writeAll(try replaceSlashes(package_json));
if (timer) |t| {
const end_time = t.read();
debug.print("Done in: {d}\n", .{ std.fmt.fmtDuration(end_time) });
}
return std.os.exit(0);
}
}
try clap.help(
io.getStdErr().writer(),
comptime ¶ms
);
std.os.exit(0);
}
pub fn invalidAppDir() void {
debug.print("Invalid Electron app directory.\n", .{});
std.os.exit(0);
}
pub fn alreadyInjected() void {
debug.print("Something is already injected there.\n", .{});
std.os.exit(0);
}
pub fn appRunning() void {
debug.print("The app is running, close it before injecting.\n", .{});
std.os.exit(0);
}
pub fn replaceSlashes(string: []const u8) ![]u8 {
const result = try allocator.alloc(u8, string.len);
var i: i128 = 0;
for (string) |char| {
if (char == '\\') {
result[@intCast(usize, i)] = '/';
} else {
result[@intCast(usize, i)] = char;
}
i += 1;
}
return result;
} | src/main.zig |
const std = @import("std");
usingnamespace @import("ini.zig");
fn expectNull(record: ?Record) void {
std.testing.expectEqual(@as(?Record, null), record);
}
fn expectSection(heading: []const u8, record: ?Record) void {
std.testing.expectEqualStrings(heading, record.?.section);
}
fn expectKeyValue(key: []const u8, value: []const u8, record: ?Record) void {
std.testing.expectEqualStrings(key, record.?.property.key);
std.testing.expectEqualStrings(value, record.?.property.value);
}
fn expectEnumeration(enumeration: []const u8, record: ?Record) void {
std.testing.expectEqualStrings(enumeration, record.?.enumeration);
}
test "empty file" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream("").reader());
defer parser.deinit();
expectNull(try parser.next());
expectNull(try parser.next());
expectNull(try parser.next());
expectNull(try parser.next());
}
test "section" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream("[Hello]").reader());
defer parser.deinit();
expectSection("Hello", try parser.next());
expectNull(try parser.next());
}
test "key-value-pair" {
for (&[_][]const u8{
"key=value",
" key=value",
"key=value ",
" key=value ",
"key =value",
" key =value",
"key =value ",
" key =value ",
"key= value",
" key= value",
"key= value ",
" key= value ",
"key = value",
" key = value",
"key = value ",
" key = value ",
}) |pattern| {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream(pattern).reader());
defer parser.deinit();
expectKeyValue("key", "value", try parser.next());
expectNull(try parser.next());
}
}
test "enumeration" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream("enum").reader());
defer parser.deinit();
expectEnumeration("enum", try parser.next());
expectNull(try parser.next());
}
test "empty line skipping" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream("item a\r\n\r\n\r\nitem b").reader());
defer parser.deinit();
expectEnumeration("item a", try parser.next());
expectEnumeration("item b", try parser.next());
expectNull(try parser.next());
}
test "multiple sections" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream(" [Hello] \r\n[Foo Bar]\n[Hello!]\n").reader());
defer parser.deinit();
expectSection("Hello", try parser.next());
expectSection("Foo Bar", try parser.next());
expectSection("Hello!", try parser.next());
expectNull(try parser.next());
}
test "multiple properties" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream("a = b\r\nc =\r\nkey value = core property").reader());
defer parser.deinit();
expectKeyValue("a", "b", try parser.next());
expectKeyValue("c", "", try parser.next());
expectKeyValue("key value", "core property", try parser.next());
expectNull(try parser.next());
}
test "multiple enumeration" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream(" a \n b \r\n c ").reader());
defer parser.deinit();
expectEnumeration("a", try parser.next());
expectEnumeration("b", try parser.next());
expectEnumeration("c", try parser.next());
expectNull(try parser.next());
}
test "mixed data" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream(
\\[Meta]
\\author = xq
\\library = ini
\\
\\[Albums]
\\Thriller
\\Back in Black
\\Bat Out of Hell
\\The Dark Side of the Moon
).reader());
defer parser.deinit();
expectSection("Meta", try parser.next());
expectKeyValue("author", "xq", try parser.next());
expectKeyValue("library", "ini", try parser.next());
expectSection("Albums", try parser.next());
expectEnumeration("Thriller", try parser.next());
expectEnumeration("Back in Black", try parser.next());
expectEnumeration("Bat Out of Hell", try parser.next());
expectEnumeration("The Dark Side of the Moon", try parser.next());
expectNull(try parser.next());
}
test "# comments" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream(
\\[section] # comment
\\key = value # comment
\\enum # comment
).reader());
defer parser.deinit();
expectSection("section", try parser.next());
expectKeyValue("key", "value", try parser.next());
expectEnumeration("enum", try parser.next());
expectNull(try parser.next());
}
test "; comments" {
var parser = parse(std.testing.allocator, std.io.fixedBufferStream(
\\[section] ; comment
\\key = value ; comment
\\enum ; comment
).reader());
defer parser.deinit();
expectSection("section", try parser.next());
expectKeyValue("key", "value", try parser.next());
expectEnumeration("enum", try parser.next());
expectNull(try parser.next());
} | src/test.zig |
const std = @import("std");
const build_options = @import("build_options");
const dcommon = @import("../common/dcommon.zig");
const arch = @import("arch.zig");
const hw = @import("../hw.zig");
usingnamespace @import("paging.zig");
fn entryAssert(cond: bool, comptime msg: []const u8) callconv(.Inline) void {
if (!cond) {
hw.entry_uart.carefully(.{ msg, "\r\n" });
while (true) {}
}
}
/// dainboot passes control here. MMU is **off**. We are in S-mode.
pub export fn daintree_mmu_start(entry_data: *dcommon.EntryData) noreturn {
hw.entry_uart.init(entry_data);
const daintree_base = arch.loadAddress("__daintree_base");
const daintree_rodata_base = arch.loadAddress("__daintree_rodata_base");
const daintree_data_base = arch.loadAddress("__daintree_data_base");
const daintree_end = arch.loadAddress("__daintree_end");
const daintree_main = arch.loadAddress("daintree_main");
const trap_entry = arch.loadAddress("__trap_entry");
hw.entry_uart.carefully(.{ "__daintree_base: ", daintree_base, "\r\n" });
hw.entry_uart.carefully(.{ "__daintree_rodata_base: ", daintree_rodata_base, "\r\n" });
hw.entry_uart.carefully(.{ "__daintree_data_base: ", daintree_data_base, "\r\n" });
hw.entry_uart.carefully(.{ "__daintree_end: ", daintree_end, "\r\n" });
hw.entry_uart.carefully(.{ "daintree_main: ", daintree_main, "\r\n" });
hw.entry_uart.carefully(.{ "__trap_entry: ", trap_entry, "\r\n" });
var bump = paging.BumpAllocator{ .next = daintree_end };
K_DIRECTORY = bump.alloc(PageTable);
var l2 = bump.alloc(PageTable);
var l3 = bump.alloc(PageTable);
// XXX add 100MiB to catch page tables
var it = PAGING.range(1, entry_data.conventional_start, entry_data.conventional_bytes + 100 * 1048576);
while (it.next()) |r| {
hw.entry_uart.carefully(.{ "mapping identity: page ", r.page, " address ", r.address, "\r\n" });
K_DIRECTORY.map(r.page, r.address, .kernel_promisc);
}
K_DIRECTORY.map(256, @ptrToInt(l2), .non_leaf);
l2.map(0, @ptrToInt(l3), .non_leaf);
var end: u64 = (daintree_end - daintree_base) >> PAGING.page_bits;
entryAssert(end <= 512, "end got too big (1)");
var i: u64 = 0;
{
var address = daintree_base;
var flags: paging.MapFlags = .kernel_code;
hw.entry_uart.carefully(.{ "MAP: text at ", PAGING.kernelPageAddress(i), "~\r\n" });
while (i < end) : (i += 1) {
if (address >= daintree_data_base) {
if (flags != .kernel_data) {
hw.entry_uart.carefully(.{ "MAP: data at ", PAGING.kernelPageAddress(i), "~\r\n" });
flags = .kernel_data;
}
} else if (address >= daintree_rodata_base) {
if (flags != .kernel_rodata) {
hw.entry_uart.carefully(.{ "MAP: rodata at ", PAGING.kernelPageAddress(i), "~\r\n" });
flags = .kernel_rodata;
}
}
l3.map(i, address, flags);
address += PAGING.page_size;
}
entryAssert(address == daintree_end, "address != daintree_end");
}
hw.entry_uart.carefully(.{ "MAP: null at ", PAGING.kernelPageAddress(i), "\r\n" });
l3.map(i, 0, .kernel_rodata);
i += 1;
end = i + STACK_PAGES;
hw.entry_uart.carefully(.{ "MAP: stack at ", PAGING.kernelPageAddress(i), "~\r\n" });
while (i < end) : (i += 1) {
l3.map(i, bump.allocPage(), .kernel_data);
}
entryAssert(end <= 512, "end got too big (2)");
hw.entry_uart.carefully(.{ "MAP: UART at ", PAGING.kernelPageAddress(i), "\r\n" });
l3.map(i, entry_data.uart_base, .peripheral);
var entry_address = bump.next - @sizeOf(dcommon.EntryData);
entry_address &= ~@as(u64, 15);
var new_entry = @intToPtr(*dcommon.EntryData, entry_address);
new_entry.* = .{
.memory_map = entry_data.memory_map,
.memory_map_size = entry_data.memory_map_size,
.descriptor_size = entry_data.descriptor_size,
.dtb_ptr = undefined,
.dtb_len = entry_data.dtb_len,
.conventional_start = entry_data.conventional_start,
.conventional_bytes = entry_data.conventional_bytes,
.fb = entry_data.fb,
.fb_vert = entry_data.fb_vert,
.fb_horiz = entry_data.fb_horiz,
.uart_base = PAGING.kernelPageAddress(end),
.uart_width = entry_data.uart_width,
.bump_next = undefined,
};
var new_sp = PAGING.kernelPageAddress(end);
new_sp -= @sizeOf(dcommon.EntryData);
new_sp &= ~@as(u64, 15);
{
i += 1;
new_entry.dtb_ptr = @intToPtr([*]const u8, PAGING.kernelPageAddress(i));
var dtb_target = @intToPtr([*]u8, bump.next)[0..entry_data.dtb_len];
// How many pages?
const dtb_pages = (entry_data.dtb_len + PAGING.page_size - 1) / PAGING.page_size;
var new_end = end + 1 + dtb_pages; // Skip 1 page since UART is there
entryAssert(new_end <= 512, "end got too big (3)");
hw.entry_uart.carefully(.{ "MAP: DTB at ", PAGING.kernelPageAddress(i), "~\r\n" });
while (i < new_end) : (i += 1) {
l3.map(i, bump.allocPage(), .kernel_rodata);
}
std.mem.copy(u8, dtb_target, entry_data.dtb_ptr[0..entry_data.dtb_len]);
}
new_entry.bump_next = bump.next;
const satp = (SATP{
.ppn = @truncate(u44, @ptrToInt(K_DIRECTORY) >> PAGING.page_bits),
.asid = 0,
.mode = .sv39,
}).toU64();
hw.entry_uart.carefully(.{ "MAP: end at ", PAGING.kernelPageAddress(i), ".\r\n" });
hw.entry_uart.carefully(.{ "about to install:\r\nsp: ", new_sp, "\r\n" });
hw.entry_uart.carefully(.{ "ra: ", daintree_main - daintree_base + PAGING.kernel_base, "\r\n" });
hw.entry_uart.carefully(.{ "uart mapped to: ", PAGING.kernelPageAddress(end), "\r\n" });
asm volatile (
\\mv sp, %[sp]
\\csrw satp, %[satp]
\\sfence.vma
\\ret
:
: [sp] "{a0}" (new_sp), // Argument to daintree_main.
[satp] "r" (satp),
[ra] "{ra}" (daintree_main - daintree_base + PAGING.kernel_base)
: "memory"
);
unreachable;
} | dainkrnl/src/riscv64/entry.zig |
const std = @import("std");
const Builder = std.build.Builder;
const LibExeObjStep = std.build.LibExeObjStep;
const rl = @import("raylib/src/build.zig");
var ran_git = false;
const srcdir = getSrcDir();
fn getSrcDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
pub fn link(exe: *LibExeObjStep, system_lib: bool) void {
if (system_lib) {
exe.linkSystemLibrary("raylib");
return;
} else {
exe.linkLibrary(rl.addRaylib(exe.builder, exe.target));
}
const target_os = exe.target.toTarget().os.tag;
switch (target_os) {
.windows => {
exe.linkSystemLibrary("winmm");
exe.linkSystemLibrary("gdi32");
exe.linkSystemLibrary("opengl32");
},
.macos => {
exe.linkFramework("OpenGL");
exe.linkFramework("Cocoa");
exe.linkFramework("IOKit");
exe.linkFramework("CoreAudio");
exe.linkFramework("CoreVideo");
},
.freebsd, .openbsd, .netbsd, .dragonfly => {
exe.linkSystemLibrary("GL");
exe.linkSystemLibrary("rt");
exe.linkSystemLibrary("dl");
exe.linkSystemLibrary("m");
exe.linkSystemLibrary("X11");
exe.linkSystemLibrary("Xrandr");
exe.linkSystemLibrary("Xinerama");
exe.linkSystemLibrary("Xi");
exe.linkSystemLibrary("Xxf86vm");
exe.linkSystemLibrary("Xcursor");
},
else => { // linux and possibly others
exe.linkSystemLibrary("GL");
exe.linkSystemLibrary("rt");
exe.linkSystemLibrary("dl");
exe.linkSystemLibrary("m");
exe.linkSystemLibrary("X11");
},
}
}
pub fn addAsPackage(name: []const u8, to: *LibExeObjStep) void {
to.addPackagePath(name, srcdir ++ "/lib/raylib-zig.zig");
}
pub const math = struct {
pub fn addAsPackage(name: []const u8, to: *LibExeObjStep) void {
to.addPackagePath(name, srcdir ++ "/lib/raylib-zig-math.zig");
}
}; | lib.zig |
const Vec2 = @import("vec2.zig").Vec2;
const Color = @import("color.zig").Color;
const std = @import("std");
const imgui = @import("imgui");
const math = std.math;
// 3 row, 2 col 2D matrix
//
// m[0] m[2] m[4]
// m[1] m[3] m[5]
//
// 0: scaleX 2: sin 4: transX
// 1: cos 3: scaleY 5: transY
//
pub const Mat32 = struct {
data: [6]f32 = undefined,
pub const TransformParams = struct { x: f32 = 0, y: f32 = 0, angle: f32 = 0, sx: f32 = 1, sy: f32 = 1, ox: f32 = 0, oy: f32 = 0 };
pub const identity = Mat32{ .data = .{ 1, 0, 0, 1, 0, 0 } };
pub fn format(self: Mat32, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
_ = fmt;
_ = options;
return writer.print("{d:0.6}, {d:0.6}, {d:0.6}, {d:0.6}, {d:0.6}, {d:0.6}", .{ self.data[0], self.data[1], self.data[2], self.data[3], self.data[4], self.data[5] });
}
pub fn init() Mat32 {
return identity;
}
pub fn initTransform(vals: TransformParams) Mat32 {
var mat = Mat32{};
mat.setTransform(vals);
return mat;
}
pub fn initOrtho(width: f32, height: f32) Mat32 {
var result = Mat32{};
result.data[0] = 2 / width;
result.data[3] = -2 / height;
result.data[4] = -1;
result.data[5] = 1;
return result;
}
pub fn initOrthoOffCenter(width: f32, height: f32) Mat32 {
const half_w = @ceil(width / 2);
const half_h = @ceil(height / 2);
var result = identity;
result.data[0] = 2.0 / (half_w + half_w);
result.data[3] = 2.0 / (-half_h - half_h);
result.data[4] = (-half_w + half_w) / (-half_w - half_w);
result.data[5] = (half_h - half_h) / (half_h + half_h);
return result;
}
pub fn setTransform(self: *Mat32, vals: TransformParams) void {
const c = math.cos(vals.angle);
const s = math.sin(vals.angle);
// matrix multiplication carried out on paper:
// |1 x| |c -s | |sx | |1 -ox|
// | 1 y| |s c | | sy | | 1 -oy|
// move rotate scale origin
self.data[0] = c * vals.sx;
self.data[1] = s * vals.sx;
self.data[2] = -s * vals.sy;
self.data[3] = c * vals.sy;
self.data[4] = vals.x - vals.ox * self.data[0] - vals.oy * self.data[2];
self.data[5] = vals.y - vals.ox * self.data[1] - vals.oy * self.data[3];
}
pub fn mul(self: Mat32, r: Mat32) Mat32 {
var result = Mat32{};
result.data[0] = self.data[0] * r.data[0] + self.data[2] * r.data[1];
result.data[1] = self.data[1] * r.data[0] + self.data[3] * r.data[1];
result.data[2] = self.data[0] * r.data[2] + self.data[2] * r.data[3];
result.data[3] = self.data[1] * r.data[2] + self.data[3] * r.data[3];
result.data[4] = self.data[0] * r.data[4] + self.data[2] * r.data[5] + self.data[4];
result.data[5] = self.data[1] * r.data[4] + self.data[3] * r.data[5] + self.data[5];
return result;
}
pub fn translate(self: *Mat32, x: f32, y: f32) void {
self.data[4] = self.data[0] * x + self.data[2] * y + self.data[4];
self.data[5] = self.data[1] * x + self.data[3] * y + self.data[5];
}
pub fn rotate(self: *Mat32, rads: f32) void {
const cos = math.cos(rads);
const sin = math.sin(rads);
const nm0 = m[0] * cos + self.data[2] * sin;
const nm1 = m[1] * cos + self.data[3] * sin;
self.data[2] = m[0] * -sin + self.data[2] * cos;
self.data[3] = m[1] * -sin + self.data[3] * cos;
self.data[0] = nm0;
self.data[1] = nm1;
}
pub fn scale(self: *Mat32, x: f32, y: f32) void {
self.data[0] *= x;
self.data[1] *= x;
self.data[2] *= y;
self.data[3] *= y;
}
pub fn determinant(self: Mat32) f32 {
return self.data[0] * self.data[3] - self.data[2] * self.data[1];
}
pub fn inverse(self: Mat32) Mat32 {
var res = std.mem.zeroes(Mat32);
const s = 1.0 / self.determinant();
res.data[0] = self.data[3] * s;
res.data[1] = -self.data[1] * s;
res.data[2] = -self.data[2] * s;
res.data[3] = self.data[0] * s;
res.data[4] = (self.data[5] * self.data[2] - self.data[4] * self.data[3]) * s;
res.data[5] = -(self.data[5] * self.data[0] - self.data[4] * self.data[1]) * s;
return res;
}
pub fn transformVec2(self: Mat32, pos: Vec2) Vec2 {
return .{
.x = pos.x * self.data[0] + pos.y * self.data[2] + self.data[4],
.y = pos.x * self.data[1] + pos.y * self.data[3] + self.data[5],
};
}
pub fn transformImVec2(self: Mat32, pos: imgui.ImVec2) imgui.ImVec2 {
return .{
.x = pos.x * self.data[0] + pos.y * self.data[2] + self.data[4],
.y = pos.x * self.data[1] + pos.y * self.data[3] + self.data[5],
};
}
pub fn transformVec2Slice(self: Mat32, comptime T: type, dst: []T, src: []Vec2) void {
for (src) |_, i| {
const x = src[i].x * self.data[0] + src[i].y * self.data[2] + self.data[4];
const y = src[i].x * self.data[1] + src[i].y * self.data[3] + self.data[5];
dst[i].x = x;
dst[i].y = y;
}
}
/// transforms the positions in Quad and copies them to dst along with the uvs and color. This could be made generic
/// if we have other common Vertex types
pub fn transformQuad(self: Mat32, dst: []Vertex, quad: Quad, color: Color) void {
_ = self;
_ = dst;
_ = quad;
_ = color;
@compileError("Vertex doesnt exist");
// for (dst) |*item, i| {
// item.*.pos.x = quad.positions[i].x * self.data[0] + quad.positions[i].y * self.data[2] + self.data[4];
// item.*.pos.y = quad.positions[i].x * self.data[1] + quad.positions[i].y * self.data[3] + self.data[5];
// item.*.uv = quad.uvs[i];
// item.*.col = color.value;
// }
}
pub fn transformVertexSlice(self: Mat32, dst: []Vertex) void {
_ = self;
_ = dst;
@compileError("Vertex doesnt exist");
// for (dst) |item, i| {
// const x = dst[i].pos.x * self.data[0] + dst[i].pos.y * self.data[2] + self.data[4];
// const y = dst[i].pos.x * self.data[1] + dst[i].pos.y * self.data[3] + self.data[5];
// // we defer setting because src and dst are the same
// dst[i].pos.x = x;
// dst[i].pos.y = y;
// }
}
};
test "mat32 tests" {
// const i = Mat32.identity;
const mat1 = Mat32.initTransform(.{ .x = 10, .y = 10 });
var mat2 = Mat32{};
mat2.setTransform(.{ .x = 10, .y = 10 });
std.testing.expectEqual(mat2, mat1);
var mat3 = Mat32.init();
mat3.setTransform(.{ .x = 10, .y = 10 });
std.testing.expectEqual(mat3, mat1);
// const mat4 = Mat32.initOrtho(640, 480);
// const mat5 = Mat32.initOrthoOffCenter(640, 480);
var mat6 = Mat32.init();
mat6.translate(10, 20);
std.testing.expectEqual(mat6.data[4], 10);
}
test "mat32 transform tests" {
const i = Mat32.identity;
const vec = Vec2.init(44, 55);
const vec_t = i.transformVec2(vec);
std.testing.expectEqual(vec, vec_t);
}
test "mat32 as camera transform" {
const mat = Mat32.initTransform(.{ .x = 10, .y = 10, .sx = 1, .sy = 1 });
const mat_inv = mat.inverse();
// const vec = Vec2.init(0, 0);
// const vec_t = mat.transformVec2(vec);
std.debug.print("\n-- transform 0, 0: {d}\n", .{mat_inv.transformVec2(.{ .x = 0, .y = 0 })});
std.debug.print("-- transform 10,10: {d}\n", .{mat_inv.transformVec2(.{ .x = 10, .y = 10 })});
std.debug.print("-- transform 20,20: {d}\n", .{mat_inv.transformVec2(.{ .x = 20, .y = 20 })});
} | src/math/mat32.zig |
const std = @import("std");
const mem = std.mem;
const Allocator = mem.Allocator;
const assert = std.debug.assert;
const Compilation = @import("Compilation.zig");
const Error = Compilation.Error;
const Source = @import("Source.zig");
const Tokenizer = @import("Tokenizer.zig");
const RawToken = Tokenizer.Token;
const Parser = @import("Parser.zig");
const Diagnostics = @import("Diagnostics.zig");
const Token = @import("Tree.zig").Token;
const AttrTag = @import("Attribute.zig").Tag;
const features = @import("features.zig");
const Preprocessor = @This();
const DefineMap = std.StringHashMap(Macro);
const RawTokenList = std.ArrayList(RawToken);
const max_include_depth = 200;
/// Errors that can be returned when expanding a macro.
/// error.UnknownPragma can occur within Preprocessor.pragma() but
/// it is handled there and doesn't escape that function
const MacroError = Error || error{StopPreprocessing};
const Macro = struct {
/// Parameters of the function type macro
params: []const []const u8,
/// Token constituting the macro body
tokens: []const RawToken,
/// If the function type macro has variable number of arguments
var_args: bool,
/// Is a function type macro
is_func: bool,
/// Is a predefined macro
is_builtin: bool = false,
/// Location of macro in the source
/// `byte_offset` and `line` are used to define the range of tokens included
/// in the macro.
loc: Source.Location,
fn eql(a: Macro, b: Macro, pp: *Preprocessor) bool {
if (a.tokens.len != b.tokens.len) return false;
if (a.is_builtin != b.is_builtin) return false;
for (a.tokens) |t, i| if (!tokEql(pp, t, b.tokens[i])) return false;
if (a.is_func and b.is_func) {
if (a.var_args != b.var_args) return false;
if (a.params.len != b.params.len) return false;
for (a.params) |p, i| if (!mem.eql(u8, p, b.params[i])) return false;
}
return true;
}
fn tokEql(pp: *Preprocessor, a: RawToken, b: RawToken) bool {
return mem.eql(u8, pp.tokSlice(a), pp.tokSlice(b));
}
};
comp: *Compilation,
arena: std.heap.ArenaAllocator,
defines: DefineMap,
tokens: Token.List = .{},
token_buf: RawTokenList,
char_buf: std.ArrayList(u8),
/// Counter that is incremented each time preprocess() is called
/// Can be used to distinguish multiple preprocessings of the same file
preprocess_count: u32 = 0,
generated_line: u32 = 1,
include_depth: u8 = 0,
counter: u32 = 0,
expansion_source_loc: Source.Location = undefined,
poisoned_identifiers: std.StringHashMap(void),
/// Memory is retained to avoid allocation on every single token.
top_expansion_buf: ExpandBuf,
pub fn init(comp: *Compilation) Preprocessor {
const pp = Preprocessor{
.comp = comp,
.arena = std.heap.ArenaAllocator.init(comp.gpa),
.defines = DefineMap.init(comp.gpa),
.token_buf = RawTokenList.init(comp.gpa),
.char_buf = std.ArrayList(u8).init(comp.gpa),
.poisoned_identifiers = std.StringHashMap(void).init(comp.gpa),
.top_expansion_buf = ExpandBuf.init(comp.gpa),
};
comp.pragmaEvent(.before_preprocess);
return pp;
}
const builtin_macros = struct {
const args = [1][]const u8{"X"};
const has_attribute = [1]RawToken{.{
.id = .macro_param_has_attribute,
.source = .generated,
}};
const has_warning = [1]RawToken{.{
.id = .macro_param_has_warning,
.source = .generated,
}};
const has_feature = [1]RawToken{.{
.id = .macro_param_has_feature,
.source = .generated,
}};
const has_extension = [1]RawToken{.{
.id = .macro_param_has_extension,
.source = .generated,
}};
const is_identifier = [1]RawToken{.{
.id = .macro_param_is_identifier,
.source = .generated,
}};
const pragma_operator = [1]RawToken{.{
.id = .macro_param_pragma_operator,
.source = .generated,
}};
const file = [1]RawToken{.{
.id = .macro_file,
.source = .generated,
}};
const line = [1]RawToken{.{
.id = .macro_line,
.source = .generated,
}};
const counter = [1]RawToken{.{
.id = .macro_counter,
.source = .generated,
}};
};
fn addBuiltinMacro(pp: *Preprocessor, name: []const u8, is_func: bool, tokens: []const RawToken) !void {
try pp.defines.put(name, .{
.params = &builtin_macros.args,
.tokens = tokens,
.var_args = false,
.is_func = is_func,
.loc = .{ .id = .generated },
.is_builtin = true,
});
}
pub fn addBuiltinMacros(pp: *Preprocessor) !void {
try pp.addBuiltinMacro("__has_attribute", true, &builtin_macros.has_attribute);
try pp.addBuiltinMacro("__has_warning", true, &builtin_macros.has_warning);
try pp.addBuiltinMacro("__has_feature", true, &builtin_macros.has_feature);
try pp.addBuiltinMacro("__has_extension", true, &builtin_macros.has_extension);
try pp.addBuiltinMacro("__is_identifier", true, &builtin_macros.is_identifier);
try pp.addBuiltinMacro("_Pragma", true, &builtin_macros.pragma_operator);
try pp.addBuiltinMacro("__FILE__", false, &builtin_macros.file);
try pp.addBuiltinMacro("__LINE__", false, &builtin_macros.line);
try pp.addBuiltinMacro("__COUNTER__", false, &builtin_macros.counter);
}
pub fn deinit(pp: *Preprocessor) void {
pp.defines.deinit();
for (pp.tokens.items(.expansion_locs)) |loc| Token.free(loc, pp.comp.gpa);
pp.tokens.deinit(pp.comp.gpa);
pp.arena.deinit();
pp.token_buf.deinit();
pp.char_buf.deinit();
pp.poisoned_identifiers.deinit();
pp.top_expansion_buf.deinit();
}
/// Preprocess a source file, returns eof token.
pub fn preprocess(pp: *Preprocessor, source: Source) Error!Token {
return pp.preprocessExtra(source) catch |err| switch (err) {
// This cannot occur in the main file and is handled in `include`.
error.StopPreprocessing => unreachable,
else => |e| return e,
};
}
fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!Token {
if (source.invalid_utf8_loc) |loc| {
try pp.comp.diag.add(.{
.tag = .invalid_utf8,
.loc = loc,
}, &.{});
return error.FatalError;
}
pp.preprocess_count += 1;
var tokenizer = Tokenizer{
.buf = source.buf,
.comp = pp.comp,
.source = source.id,
};
const TRAILING_WS = " \r\t\x0B\x0C";
// Estimate how many new tokens this source will contain.
const estimated_token_count = source.buf.len / 8;
try pp.tokens.ensureTotalCapacity(pp.comp.gpa, pp.tokens.len + estimated_token_count);
var if_level: u8 = 0;
var if_kind = std.PackedIntArray(u2, 256).init([1]u2{0} ** 256);
const until_else = 0;
const until_endif = 1;
const until_endif_seen_else = 2;
var start_of_line = true;
while (true) {
var tok = tokenizer.next();
switch (tok.id) {
.hash => if (start_of_line) {
const directive = tokenizer.nextNoWS();
switch (directive.id) {
.keyword_error => {
// #error tokens..
const start = tokenizer.index;
while (tokenizer.index < tokenizer.buf.len) : (tokenizer.index += 1) {
if (tokenizer.buf[tokenizer.index] == '\n') break;
}
var slice = tokenizer.buf[start..tokenizer.index];
slice = mem.trim(u8, slice, TRAILING_WS);
try pp.comp.diag.add(.{
.tag = .error_directive,
.loc = .{ .id = tok.source, .byte_offset = tok.start, .line = directive.line },
.extra = .{ .str = slice },
}, &.{});
},
.keyword_if => {
if (@addWithOverflow(u8, if_level, 1, &if_level))
return pp.fatal(directive, "too many #if nestings", .{});
if (try pp.expr(&tokenizer)) {
if_kind.set(if_level, until_endif);
} else {
if_kind.set(if_level, until_else);
try pp.skip(&tokenizer, .until_else);
}
},
.keyword_ifdef => {
if (@addWithOverflow(u8, if_level, 1, &if_level))
return pp.fatal(directive, "too many #if nestings", .{});
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) != null) {
if_kind.set(if_level, until_endif);
} else {
if_kind.set(if_level, until_else);
try pp.skip(&tokenizer, .until_else);
}
},
.keyword_ifndef => {
if (@addWithOverflow(u8, if_level, 1, &if_level))
return pp.fatal(directive, "too many #if nestings", .{});
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) == null) {
if_kind.set(if_level, until_endif);
} else {
if_kind.set(if_level, until_else);
try pp.skip(&tokenizer, .until_else);
}
},
.keyword_elif => {
if (if_level == 0) {
try pp.err(directive, .elif_without_if);
if_level += 1;
if_kind.set(if_level, until_else);
}
switch (if_kind.get(if_level)) {
until_else => if (try pp.expr(&tokenizer)) {
if_kind.set(if_level, until_endif);
} else {
try pp.skip(&tokenizer, .until_else);
},
until_endif => try pp.skip(&tokenizer, .until_endif),
until_endif_seen_else => {
try pp.err(directive, .elif_after_else);
skipToNl(&tokenizer);
},
else => unreachable,
}
},
.keyword_else => {
try pp.expectNl(&tokenizer);
if (if_level == 0) {
try pp.err(directive, .else_without_if);
continue;
}
switch (if_kind.get(if_level)) {
until_else => if_kind.set(if_level, until_endif_seen_else),
until_endif => try pp.skip(&tokenizer, .until_endif_seen_else),
until_endif_seen_else => {
try pp.err(directive, .else_after_else);
skipToNl(&tokenizer);
},
else => unreachable,
}
},
.keyword_endif => {
try pp.expectNl(&tokenizer);
if (if_level == 0) {
try pp.err(directive, .endif_without_if);
continue;
}
if_level -= 1;
},
.keyword_define => try pp.define(&tokenizer),
.keyword_undef => {
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
_ = pp.defines.remove(macro_name);
try pp.expectNl(&tokenizer);
},
.keyword_include => try pp.include(&tokenizer),
.keyword_pragma => try pp.pragma(&tokenizer, directive, null, &.{}),
.keyword_line => {
// #line number "file"
const digits = tokenizer.nextNoWS();
if (digits.id != .integer_literal) try pp.err(digits, .line_simple_digit);
if (digits.id == .eof or digits.id == .nl) continue;
const name = tokenizer.nextNoWS();
if (name.id == .eof or name.id == .nl) continue;
if (name.id != .string_literal) try pp.err(name, .line_invalid_filename);
try pp.expectNl(&tokenizer);
},
.integer_literal => {
// # number "file" flags
const name = tokenizer.nextNoWS();
if (name.id == .eof or name.id == .nl) continue;
if (name.id != .string_literal) try pp.err(name, .line_invalid_filename);
const flag_1 = tokenizer.nextNoWS();
if (flag_1.id == .eof or flag_1.id == .nl) continue;
const flag_2 = tokenizer.nextNoWS();
if (flag_2.id == .eof or flag_2.id == .nl) continue;
const flag_3 = tokenizer.nextNoWS();
if (flag_3.id == .eof or flag_3.id == .nl) continue;
const flag_4 = tokenizer.nextNoWS();
if (flag_4.id == .eof or flag_4.id == .nl) continue;
try pp.expectNl(&tokenizer);
},
.nl => {},
.eof => {
if (if_level != 0) try pp.err(tok, .unterminated_conditional_directive);
return tokFromRaw(directive);
},
else => {
try pp.err(tok, .invalid_preprocessing_directive);
try pp.expectNl(&tokenizer);
},
}
},
.whitespace => if (pp.comp.only_preprocess) try pp.tokens.append(pp.comp.gpa, tokFromRaw(tok)),
.nl => {
start_of_line = true;
if (pp.comp.only_preprocess) try pp.tokens.append(pp.comp.gpa, tokFromRaw(tok));
},
.eof => {
if (if_level != 0) try pp.err(tok, .unterminated_conditional_directive);
// The following check needs to occur here and not at the top of the function
// because a pragma may change the level during preprocessing
if (source.buf.len > 0 and source.buf[source.buf.len - 1] != '\n') {
try pp.err(tok, .newline_eof);
}
return tokFromRaw(tok);
},
else => {
if (tok.id.isMacroIdentifier() and pp.poisoned_identifiers.get(pp.tokSlice(tok)) != null) {
try pp.err(tok, .poisoned_identifier);
}
// Add the token to the buffer doing any necessary expansions.
start_of_line = false;
tok.id.simplifyMacroKeyword();
try pp.expandMacro(&tokenizer, tok);
},
}
}
}
/// Get raw token source string.
/// Returned slice is invalidated when comp.generated_buf is updated.
pub fn tokSlice(pp: *Preprocessor, token: RawToken) []const u8 {
if (token.id.lexeme()) |some| return some;
const source = pp.comp.getSource(token.source);
return source.buf[token.start..token.end];
}
/// Convert a token from the Tokenizer into a token used by the parser.
fn tokFromRaw(raw: RawToken) Token {
return .{
.id = raw.id,
.loc = .{
.id = raw.source,
.byte_offset = raw.start,
.line = raw.line,
},
};
}
fn err(pp: *Preprocessor, raw: RawToken, tag: Diagnostics.Tag) !void {
try pp.comp.diag.add(.{
.tag = tag,
.loc = .{
.id = raw.source,
.byte_offset = raw.start,
.line = raw.line,
},
}, &.{});
}
fn fatal(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) Compilation.Error {
const source = pp.comp.getSource(raw.source);
const line_col = source.lineCol(raw.start);
return pp.comp.diag.fatal(source.path, line_col.line, raw.line, line_col.col, fmt, args);
}
/// Consume next token, error if it is not an identifier.
fn expectMacroName(pp: *Preprocessor, tokenizer: *Tokenizer) Error!?[]const u8 {
const macro_name = tokenizer.nextNoWS();
if (!macro_name.id.isMacroIdentifier()) {
try pp.err(macro_name, .macro_name_missing);
skipToNl(tokenizer);
return null;
}
return pp.tokSlice(macro_name);
}
/// Skip until after a newline, error if extra tokens before it.
fn expectNl(pp: *Preprocessor, tokenizer: *Tokenizer) Error!void {
var sent_err = false;
while (true) {
const tok = tokenizer.next();
if (tok.id == .nl or tok.id == .eof) return;
if (tok.id == .whitespace) continue;
if (!sent_err) {
sent_err = true;
try pp.err(tok, .extra_tokens_directive_end);
}
}
}
/// Consume all tokens until a newline and parse the result into a boolean.
fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {
const start = pp.tokens.len;
defer {
for (pp.tokens.items(.expansion_locs)[start..]) |loc| Token.free(loc, pp.comp.gpa);
pp.tokens.len = start;
}
while (true) {
var tok = tokenizer.next();
switch (tok.id) {
.nl, .eof => {
if (pp.tokens.len == start) {
try pp.err(tok, .expected_value_in_expr);
try pp.expectNl(tokenizer);
return false;
}
tok.id = .eof;
try pp.tokens.append(pp.comp.gpa, tokFromRaw(tok));
break;
},
.keyword_defined => {
const first = tokenizer.nextNoWS();
const macro_tok = if (first.id == .l_paren) tokenizer.nextNoWS() else first;
if (!macro_tok.id.isMacroIdentifier()) try pp.err(macro_tok, .macro_name_missing);
if (first.id == .l_paren) {
const r_paren = tokenizer.nextNoWS();
if (r_paren.id != .r_paren) {
try pp.err(r_paren, .closing_paren);
try pp.err(first, .to_match_paren);
}
}
tok.id = if (pp.defines.get(pp.tokSlice(macro_tok)) != null) .one else .zero;
},
.whitespace => continue,
else => {},
}
try pp.expandMacro(tokenizer, tok);
}
if (!pp.tokens.items(.id)[start].validPreprocessorExprStart()) {
const tok = pp.tokens.get(0);
try pp.comp.diag.add(.{
.tag = .invalid_preproc_expr_start,
.loc = tok.loc,
}, tok.expansionSlice());
return false;
}
// validate the tokens in the expression
for (pp.tokens.items(.id)[start..]) |*id, i| {
switch (id.*) {
.string_literal,
.string_literal_utf_16,
.string_literal_utf_8,
.string_literal_utf_32,
.string_literal_wide,
=> {
const tok = pp.tokens.get(i);
try pp.comp.diag.add(.{
.tag = .string_literal_in_pp_expr,
.loc = tok.loc,
}, tok.expansionSlice());
return false;
},
.float_literal,
.float_literal_f,
.float_literal_l,
=> {
const tok = pp.tokens.get(i);
try pp.comp.diag.add(.{
.tag = .float_literal_in_pp_expr,
.loc = tok.loc,
}, tok.expansionSlice());
return false;
},
.plus_plus,
.minus_minus,
.plus_equal,
.minus_equal,
.asterisk_equal,
.slash_equal,
.percent_equal,
.angle_bracket_angle_bracket_left_equal,
.angle_bracket_angle_bracket_right_equal,
.ampersand_equal,
.caret_equal,
.pipe_equal,
.l_bracket,
.r_bracket,
.l_brace,
.r_brace,
.ellipsis,
.semicolon,
.hash,
.hash_hash,
.equal,
.arrow,
.period,
=> {
const tok = pp.tokens.get(i);
try pp.comp.diag.add(.{
.tag = .invalid_preproc_operator,
.loc = tok.loc,
}, tok.expansionSlice());
return false;
},
else => if (id.isMacroIdentifier()) {
id.* = .zero; // undefined macro
},
}
}
// Actually parse it.
var parser = Parser{
.pp = pp,
.tok_ids = pp.tokens.items(.id),
.tok_i = @intCast(u32, start),
.arena = pp.arena.allocator(),
.in_macro = true,
.data = undefined,
.strings = undefined,
.value_map = undefined,
.scopes = undefined,
.labels = undefined,
.decl_buf = undefined,
.list_buf = undefined,
.param_buf = undefined,
.enum_buf = undefined,
.record_buf = undefined,
.attr_buf = undefined,
};
return parser.macroExpr();
}
/// Skip until #else #elif #endif, return last directive token id.
/// Also skips nested #if ... #endifs.
fn skip(
pp: *Preprocessor,
tokenizer: *Tokenizer,
cont: enum { until_else, until_endif, until_endif_seen_else },
) Error!void {
var ifs_seen: u32 = 0;
var line_start = true;
while (tokenizer.index < tokenizer.buf.len) {
if (line_start) {
const saved_tokenizer = tokenizer.*;
const hash = tokenizer.nextNoWS();
if (hash.id == .nl) continue;
line_start = false;
if (hash.id != .hash) continue;
const directive = tokenizer.nextNoWS();
switch (directive.id) {
.keyword_else => {
if (ifs_seen != 0) continue;
if (cont == .until_endif_seen_else) {
try pp.err(directive, .else_after_else);
continue;
}
tokenizer.* = saved_tokenizer;
return;
},
.keyword_elif => {
if (ifs_seen != 0 or cont == .until_endif) continue;
if (cont == .until_endif_seen_else) {
try pp.err(directive, .elif_after_else);
continue;
}
tokenizer.* = saved_tokenizer;
return;
},
.keyword_endif => {
if (ifs_seen == 0) {
tokenizer.* = saved_tokenizer;
return;
}
ifs_seen -= 1;
},
.keyword_if, .keyword_ifdef, .keyword_ifndef => ifs_seen += 1,
else => {},
}
} else if (tokenizer.buf[tokenizer.index] == '\n') {
line_start = true;
tokenizer.index += 1;
tokenizer.line += 1;
} else {
line_start = false;
tokenizer.index += 1;
}
} else {
const eof = tokenizer.next();
return pp.err(eof, .unterminated_conditional_directive);
}
}
// Skip until newline, ignore other tokens.
fn skipToNl(tokenizer: *Tokenizer) void {
while (true) {
const tok = tokenizer.next();
if (tok.id == .nl or tok.id == .eof) return;
}
}
const ExpandBuf = std.ArrayList(Token);
const MacroArguments = std.ArrayList([]const Token);
fn deinitMacroArguments(allocator: Allocator, args: *const MacroArguments) void {
for (args.items) |item| {
for (item) |tok| Token.free(tok.expansion_locs, allocator);
allocator.free(item);
}
args.deinit();
}
fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf {
var buf = ExpandBuf.init(pp.comp.gpa);
try buf.ensureTotalCapacity(simple_macro.tokens.len);
// Add all of the simple_macros tokens to the new buffer handling any concats.
var i: usize = 0;
while (i < simple_macro.tokens.len) : (i += 1) {
const raw = simple_macro.tokens[i];
const tok = tokFromRaw(raw);
switch (raw.id) {
.hash_hash => {
var rhs = tokFromRaw(simple_macro.tokens[i + 1]);
i += 1;
while (rhs.id == .whitespace) {
rhs = tokFromRaw(simple_macro.tokens[i + 1]);
i += 1;
}
try pp.pasteTokens(&buf, &.{rhs});
},
.whitespace => if (pp.comp.only_preprocess) buf.appendAssumeCapacity(tok),
.macro_file => {
const start = pp.comp.generated_buf.items.len;
const source = pp.comp.getSource(pp.expansion_source_loc.id);
try pp.comp.generated_buf.writer().print("\"{s}\"\n", .{source.path});
buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
},
.macro_line => {
const start = pp.comp.generated_buf.items.len;
try pp.comp.generated_buf.writer().print("{d}\n", .{pp.expansion_source_loc.line});
buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .integer_literal, tok));
},
.macro_counter => {
defer pp.counter += 1;
const start = pp.comp.generated_buf.items.len;
try pp.comp.generated_buf.writer().print("{d}\n", .{pp.counter});
buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .integer_literal, tok));
},
else => buf.appendAssumeCapacity(tok),
}
}
return buf;
}
/// Join a possibly-parenthesized series of string literal tokens into a single string without
/// leading or trailing quotes. The returned slice is invalidated if pp.char_buf changes.
/// Returns error.ExpectedStringLiteral if parentheses are not balanced, a non-string-literal
/// is encountered, or if no string literals are encountered
/// TODO: destringize (replace all '\\' with a single `\` and all '\"' with a '"')
fn pasteStringsUnsafe(pp: *Preprocessor, toks: []const Token) ![]const u8 {
const char_top = pp.char_buf.items.len;
defer pp.char_buf.items.len = char_top;
var unwrapped = toks;
if (toks.len >= 2 and toks[0].id == .l_paren and toks[toks.len - 1].id == .r_paren) {
unwrapped = toks[1 .. toks.len - 1];
}
if (unwrapped.len == 0) return error.ExpectedStringLiteral;
for (unwrapped) |tok| {
if (tok.id == .whitespace) continue;
if (tok.id != .string_literal) return error.ExpectedStringLiteral;
const str = pp.expandedSlice(tok);
try pp.char_buf.appendSlice(str[1 .. str.len - 1]);
}
return pp.char_buf.items[char_top..];
}
/// Handle the _Pragma operator (implemented as a builtin macro)
fn pragmaOperator(pp: *Preprocessor, arg_tok: Token, operator_loc: Source.Location) !void {
const arg_slice = pp.expandedSlice(arg_tok);
const content = arg_slice[1 .. arg_slice.len - 1];
const directive = "#pragma ";
pp.char_buf.clearRetainingCapacity();
const total_len = directive.len + content.len + 1; // destringify can never grow the string, + 1 for newline
try pp.char_buf.ensureUnusedCapacity(total_len);
pp.char_buf.appendSliceAssumeCapacity(directive);
pp.destringify(content);
pp.char_buf.appendAssumeCapacity('\n');
const start = pp.comp.generated_buf.items.len;
try pp.comp.generated_buf.appendSlice(pp.char_buf.items);
var tmp_tokenizer = Tokenizer{
.buf = pp.comp.generated_buf.items,
.comp = pp.comp,
.index = @intCast(u32, start),
.source = .generated,
.line = pp.generated_line,
};
pp.generated_line += 1;
const hash_tok = tmp_tokenizer.next();
assert(hash_tok.id == .hash);
const pragma_tok = tmp_tokenizer.next();
assert(pragma_tok.id == .keyword_pragma);
try pp.pragma(&tmp_tokenizer, pragma_tok, operator_loc, arg_tok.expansionSlice());
}
/// Inverts the output of the preprocessor stringify (#) operation
/// (except all whitespace is condensed to a single space)
/// writes output to pp.char_buf; assumes capacity is sufficient
/// backslash backslash -> backslash
/// backslash doublequote -> doublequote
/// All other characters remain the same
fn destringify(pp: *Preprocessor, str: []const u8) void {
var state: enum { start, backslash_seen } = .start;
for (str) |c| {
switch (c) {
'\\' => {
if (state == .backslash_seen) pp.char_buf.appendAssumeCapacity(c);
state = if (state == .start) .backslash_seen else .start;
},
else => {
if (state == .backslash_seen and c != '"') pp.char_buf.appendAssumeCapacity('\\');
pp.char_buf.appendAssumeCapacity(c);
state = .start;
},
}
}
}
/// Stringify `tokens` into pp.char_buf.
/// See https://gcc.gnu.org/onlinedocs/gcc-11.2.0/cpp/Stringizing.html#Stringizing
fn stringify(pp: *Preprocessor, tokens: []const Token) !void {
try pp.char_buf.append('"');
var ws_state: enum { start, need, not_needed } = .start;
for (tokens) |tok| {
if (tok.id == .nl) continue;
if (tok.id == .whitespace) {
if (ws_state == .start) continue;
ws_state = .need;
continue;
}
if (ws_state == .need) try pp.char_buf.append(' ');
ws_state = .not_needed;
for (pp.expandedSlice(tok)) |c| {
if (c == '"')
try pp.char_buf.appendSlice("\\\"")
else if (c == '\\')
try pp.char_buf.appendSlice("\\\\")
else
try pp.char_buf.append(c);
}
}
try pp.char_buf.appendSlice("\"\n");
}
fn handleBuiltinMacro(pp: *Preprocessor, builtin: RawToken.Id, param_toks: []const Token, src_loc: Source.Location) Error!bool {
switch (builtin) {
.macro_param_has_attribute,
.macro_param_has_feature,
.macro_param_has_extension,
=> {
var invalid: ?Token = null;
var identifier: ?Token = null;
for (param_toks) |tok| switch (tok.id) {
.identifier, .extended_identifier => {
if (identifier) |_| invalid = tok else identifier = tok;
},
.whitespace => continue,
else => {
invalid = tok;
break;
},
};
if (identifier == null and invalid == null) invalid = .{ .id = .eof, .loc = src_loc };
if (invalid) |some| {
try pp.comp.diag.add(
.{ .tag = .feature_check_requires_identifier, .loc = some.loc },
some.expansionSlice(),
);
return false;
}
const ident_str = pp.expandedSlice(identifier.?);
return switch (builtin) {
.macro_param_has_attribute => AttrTag.fromString(ident_str) != null,
.macro_param_has_feature => features.hasFeature(pp.comp, ident_str),
.macro_param_has_extension => features.hasExtension(pp.comp, ident_str),
else => unreachable,
};
},
.macro_param_has_warning => {
const actual_param = pp.pasteStringsUnsafe(param_toks) catch |err| switch (err) {
error.ExpectedStringLiteral => {
try pp.comp.diag.add(.{
.tag = .expected_str_literal_in,
.loc = param_toks[0].loc,
.extra = .{ .str = "__has_warning" },
}, param_toks[0].expansionSlice());
return false;
},
else => |e| return e,
};
if (!mem.startsWith(u8, actual_param, "-W")) {
try pp.comp.diag.add(.{
.tag = .malformed_warning_check,
.loc = param_toks[0].loc,
.extra = .{ .str = "__has_warning" },
}, param_toks[0].expansionSlice());
return false;
}
const warning_name = actual_param[2..];
return Diagnostics.warningExists(warning_name);
},
.macro_param_is_identifier => {
var invalid: ?Token = null;
var identifier: ?Token = null;
for (param_toks) |tok| switch (tok.id) {
.whitespace => continue,
else => {
if (identifier) |_| invalid = tok else identifier = tok;
},
};
if (identifier == null and invalid == null) invalid = .{ .id = .eof, .loc = src_loc };
if (invalid) |some| {
try pp.comp.diag.add(.{
.tag = .missing_tok_builtin,
.loc = some.loc,
.extra = .{ .tok_id_expected = .r_paren },
}, some.expansionSlice());
return false;
}
const id = identifier.?.id;
return id == .identifier or id == .extended_identifier;
},
else => unreachable,
}
}
fn expandFuncMacro(
pp: *Preprocessor,
loc: Source.Location,
func_macro: *const Macro,
args: *const MacroArguments,
expanded_args: *const MacroArguments,
) MacroError!ExpandBuf {
var buf = ExpandBuf.init(pp.comp.gpa);
try buf.ensureTotalCapacity(func_macro.tokens.len);
errdefer buf.deinit();
var expanded_variable_arguments = ExpandBuf.init(pp.comp.gpa);
defer expanded_variable_arguments.deinit();
var variable_arguments = ExpandBuf.init(pp.comp.gpa);
defer variable_arguments.deinit();
if (func_macro.var_args) {
var i: usize = func_macro.params.len;
while (i < expanded_args.items.len) : (i += 1) {
try variable_arguments.appendSlice(args.items[i]);
try expanded_variable_arguments.appendSlice(expanded_args.items[i]);
if (i != expanded_args.items.len - 1) {
const comma = Token{ .id = .comma, .loc = .{ .id = .generated } };
try variable_arguments.append(comma);
try expanded_variable_arguments.append(comma);
}
}
}
// token concatenation and expansion phase
var tok_i: usize = 0;
while (tok_i < func_macro.tokens.len) : (tok_i += 1) {
const raw = func_macro.tokens[tok_i];
switch (raw.id) {
.hash_hash => while (tok_i + 1 < func_macro.tokens.len) {
const raw_next = func_macro.tokens[tok_i + 1];
tok_i += 1;
const next = switch (raw_next.id) {
.whitespace => continue,
.hash_hash => continue,
.macro_param, .macro_param_no_expand => args.items[raw_next.end],
.keyword_va_args => variable_arguments.items,
else => &[1]Token{tokFromRaw(raw_next)},
};
try pp.pasteTokens(&buf, next);
if (next.len != 0) break;
},
.macro_param_no_expand => {
const slice = args.items[raw.end];
const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
try bufCopyTokens(&buf, slice, &.{raw_loc});
},
.macro_param => {
const arg = expanded_args.items[raw.end];
const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
try bufCopyTokens(&buf, arg, &.{raw_loc});
},
.keyword_va_args => {
const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
try bufCopyTokens(&buf, expanded_variable_arguments.items, &.{raw_loc});
},
.stringify_param, .stringify_va_args => {
const arg = if (raw.id == .stringify_va_args)
variable_arguments.items
else
args.items[raw.end];
pp.char_buf.clearRetainingCapacity();
try pp.stringify(arg);
const start = pp.comp.generated_buf.items.len;
try pp.comp.generated_buf.appendSlice(pp.char_buf.items);
try buf.append(try pp.makeGeneratedToken(start, .string_literal, tokFromRaw(raw)));
},
.macro_param_has_attribute,
.macro_param_has_warning,
.macro_param_has_feature,
.macro_param_has_extension,
.macro_param_is_identifier,
=> {
const arg = expanded_args.items[0];
const result = if (arg.len == 0) blk: {
const extra = Diagnostics.Message.Extra{ .arguments = .{ .expected = 1, .actual = 0 } };
try pp.comp.diag.add(.{ .tag = .expected_arguments, .loc = loc, .extra = extra }, &.{});
break :blk false;
} else try pp.handleBuiltinMacro(raw.id, arg, loc);
const start = pp.comp.generated_buf.items.len;
try pp.comp.generated_buf.writer().print("{}\n", .{@boolToInt(result)});
try buf.append(try pp.makeGeneratedToken(start, .integer_literal, tokFromRaw(raw)));
},
.macro_param_pragma_operator => {
const param_toks = expanded_args.items[0];
// Clang and GCC require exactly one token (so, no parentheses or string pasting)
// even though their error messages indicate otherwise. Ours is slightly more
// descriptive.
var invalid: ?Token = null;
var string: ?Token = null;
for (param_toks) |tok| switch (tok.id) {
.string_literal => {
if (string) |_| invalid = tok else string = tok;
},
.whitespace => continue,
else => {
invalid = tok;
break;
},
};
if (string == null and invalid == null) invalid = .{ .loc = loc, .id = .eof };
if (invalid) |some| try pp.comp.diag.add(
.{ .tag = .pragma_operator_string_literal, .loc = some.loc },
some.expansionSlice(),
) else try pp.pragmaOperator(string.?, loc);
},
.whitespace => if (pp.comp.only_preprocess) try buf.append(tokFromRaw(raw)),
else => try buf.append(tokFromRaw(raw)),
}
}
return buf;
}
fn shouldExpand(tok: Token, macro: *Macro) bool {
if (tok.loc.id == macro.loc.id and
tok.loc.byte_offset >= macro.loc.byte_offset and
tok.loc.byte_offset <= macro.loc.line)
return false;
for (tok.expansionSlice()) |loc| {
if (loc.id == macro.loc.id and
loc.byte_offset >= macro.loc.byte_offset and
loc.byte_offset <= macro.loc.line)
return false;
}
return true;
}
fn bufCopyTokens(buf: *ExpandBuf, tokens: []const Token, src: []const Source.Location) !void {
try buf.ensureUnusedCapacity(tokens.len);
for (tokens) |tok| {
var copy = try tok.dupe(buf.allocator);
try copy.addExpansionLocation(buf.allocator, src);
buf.appendAssumeCapacity(copy);
}
}
fn nextBufToken(
pp: *Preprocessor,
tokenizer: *Tokenizer,
buf: *ExpandBuf,
start_idx: *usize,
end_idx: *usize,
extend_buf: bool,
) Error!Token {
start_idx.* += 1;
if (start_idx.* == buf.items.len and start_idx.* >= end_idx.*) {
if (extend_buf) {
const raw_tok = tokenizer.next();
if (raw_tok.id.isMacroIdentifier() and
pp.poisoned_identifiers.get(pp.tokSlice(raw_tok)) != null)
try pp.err(raw_tok, .poisoned_identifier);
const new_tok = tokFromRaw(raw_tok);
end_idx.* += 1;
try buf.append(new_tok);
return new_tok;
} else {
return Token{ .id = .eof, .loc = .{ .id = .generated } };
}
} else {
return buf.items[start_idx.*];
}
}
fn collectMacroFuncArguments(
pp: *Preprocessor,
tokenizer: *Tokenizer,
buf: *ExpandBuf,
start_idx: *usize,
end_idx: *usize,
extend_buf: bool,
is_builtin: bool,
) Error!(?MacroArguments) {
const name_tok = buf.items[start_idx.*];
const saved_tokenizer = tokenizer.*;
const old_end = end_idx.*;
while (true) {
const tok = try nextBufToken(pp, tokenizer, buf, start_idx, end_idx, extend_buf);
switch (tok.id) {
.nl, .whitespace => {},
.l_paren => break,
else => {
if (is_builtin) {
try pp.comp.diag.add(.{
.tag = .missing_tok_builtin,
.loc = tok.loc,
.extra = .{ .tok_id_expected = .l_paren },
}, tok.expansionSlice());
}
// Not a macro function call, go over normal identifier, rewind
tokenizer.* = saved_tokenizer;
end_idx.* = old_end;
return null;
},
}
}
// collect the arguments.
var parens: u32 = 0;
var args = MacroArguments.init(pp.comp.gpa);
errdefer deinitMacroArguments(pp.comp.gpa, &args);
var curArgument = std.ArrayList(Token).init(pp.comp.gpa);
defer curArgument.deinit();
var done = false;
while (!done) {
var tok = try nextBufToken(pp, tokenizer, buf, start_idx, end_idx, extend_buf);
switch (tok.id) {
.comma => {
if (parens == 0) {
try args.append(curArgument.toOwnedSlice());
} else {
try curArgument.append(try tok.dupe(pp.comp.gpa));
}
},
.l_paren => {
try curArgument.append(try tok.dupe(pp.comp.gpa));
parens += 1;
},
.r_paren => {
if (parens == 0) {
try args.append(curArgument.toOwnedSlice());
break;
} else {
try curArgument.append(try tok.dupe(pp.comp.gpa));
parens -= 1;
}
},
.eof => {
deinitMacroArguments(pp.comp.gpa, &args);
tokenizer.* = saved_tokenizer;
end_idx.* = old_end;
try pp.comp.diag.add(
.{ .tag = .unterminated_macro_arg_list, .loc = name_tok.loc },
name_tok.expansionSlice(),
);
return null;
},
else => {
try curArgument.append(try tok.dupe(pp.comp.gpa));
},
}
}
return args;
}
fn expandMacroExhaustive(
pp: *Preprocessor,
tokenizer: *Tokenizer,
buf: *ExpandBuf,
start_idx: usize,
end_idx: usize,
extend_buf: bool,
) MacroError!void {
var moving_end_idx = end_idx;
var advance_index: usize = 0;
// rescan loop
var do_rescan = true;
while (do_rescan) {
do_rescan = false;
// expansion loop
var idx: usize = start_idx + advance_index;
while (idx < moving_end_idx) {
const macro_tok = buf.items[idx];
const macro_entry = pp.defines.getPtr(pp.expandedSlice(macro_tok));
if (macro_entry == null or !shouldExpand(buf.items[idx], macro_entry.?)) {
idx += 1;
continue;
}
if (macro_entry) |macro| macro_handler: {
if (macro.is_func) {
var macro_scan_idx = idx;
// to be saved in case this doesn't turn out to be a call
const args = (try pp.collectMacroFuncArguments(
tokenizer,
buf,
¯o_scan_idx,
&moving_end_idx,
extend_buf,
macro.is_builtin,
)) orelse {
idx += 1;
break :macro_handler;
};
defer {
for (args.items) |item| {
pp.comp.gpa.free(item);
}
args.deinit();
}
var args_count = @intCast(u32, args.items.len);
// if the macro has zero arguments g() args_count is still 1
if (args_count == 1 and macro.params.len == 0) args_count = 0;
// Validate argument count.
const extra = Diagnostics.Message.Extra{
.arguments = .{ .expected = @intCast(u32, macro.params.len), .actual = args_count },
};
if (macro.var_args and args_count < macro.params.len) {
try pp.comp.diag.add(
.{ .tag = .expected_at_least_arguments, .loc = buf.items[idx].loc, .extra = extra },
buf.items[idx].expansionSlice(),
);
idx += 1;
continue;
}
if (!macro.var_args and args_count != macro.params.len) {
try pp.comp.diag.add(
.{ .tag = .expected_arguments, .loc = buf.items[idx].loc, .extra = extra },
buf.items[idx].expansionSlice(),
);
idx += 1;
continue;
}
var expanded_args = MacroArguments.init(pp.comp.gpa);
defer deinitMacroArguments(pp.comp.gpa, &expanded_args);
try expanded_args.ensureTotalCapacity(args.items.len);
for (args.items) |arg| {
var expand_buf = ExpandBuf.init(pp.comp.gpa);
try expand_buf.appendSlice(arg);
try pp.expandMacroExhaustive(tokenizer, &expand_buf, 0, expand_buf.items.len, false);
expanded_args.appendAssumeCapacity(expand_buf.toOwnedSlice());
}
var res = try pp.expandFuncMacro(macro_tok.loc, macro, &args, &expanded_args);
defer res.deinit();
const macro_expansion_locs = macro_tok.expansionSlice();
for (res.items) |*tok| {
try tok.addExpansionLocation(pp.comp.gpa, &.{macro_tok.loc});
try tok.addExpansionLocation(pp.comp.gpa, macro_expansion_locs);
}
const count = macro_scan_idx - idx + 1;
for (buf.items[idx .. idx + count]) |tok| Token.free(tok.expansion_locs, pp.comp.gpa);
try buf.replaceRange(idx, count, res.items);
// TODO: moving_end_idx += res.items.len - (macro_scan_idx-idx+1)
// doesn't work when the RHS is negative (unsigned!)
moving_end_idx = moving_end_idx + res.items.len - count;
idx += res.items.len;
do_rescan = true;
} else {
const res = try pp.expandObjMacro(macro);
defer res.deinit();
const macro_expansion_locs = macro_tok.expansionSlice();
for (res.items) |*tok| {
try tok.addExpansionLocation(pp.comp.gpa, &.{macro_tok.loc});
try tok.addExpansionLocation(pp.comp.gpa, macro_expansion_locs);
}
Token.free(buf.items[idx].expansion_locs, pp.comp.gpa);
try buf.replaceRange(idx, 1, res.items);
idx += res.items.len;
moving_end_idx = moving_end_idx + res.items.len - 1;
do_rescan = true;
}
}
if (idx - start_idx == advance_index + 1 and !do_rescan) {
advance_index += 1;
}
} // end of replacement phase
}
// end of scanning phase
// trim excess buffer
buf.items.len = moving_end_idx;
}
/// Try to expand a macro after a possible candidate has been read from the `tokenizer`
/// into the `raw` token passed as argument
fn expandMacro(pp: *Preprocessor, tokenizer: *Tokenizer, raw: RawToken) MacroError!void {
const source_tok = tokFromRaw(raw);
if (!raw.id.isMacroIdentifier()) {
return pp.tokens.append(pp.comp.gpa, source_tok);
}
pp.top_expansion_buf.items.len = 0;
try pp.top_expansion_buf.append(source_tok);
pp.expansion_source_loc = source_tok.loc;
try pp.expandMacroExhaustive(tokenizer, &pp.top_expansion_buf, 0, 1, true);
try pp.tokens.ensureUnusedCapacity(pp.comp.gpa, pp.top_expansion_buf.items.len);
for (pp.top_expansion_buf.items) |*tok| {
if (tok.id == .whitespace and !pp.comp.only_preprocess) {
Token.free(tok.expansion_locs, pp.comp.gpa);
continue;
}
pp.tokens.appendAssumeCapacity(tok.*);
}
}
/// Get expanded token source string.
pub fn expandedSlice(pp: *Preprocessor, tok: Token) []const u8 {
if (tok.id.lexeme()) |some| return some;
var tmp_tokenizer = Tokenizer{
.buf = pp.comp.getSource(tok.loc.id).buf,
.comp = pp.comp,
.index = tok.loc.byte_offset,
.source = .generated,
};
if (tok.id == .macro_string) {
while (true) : (tmp_tokenizer.index += 1) {
if (tmp_tokenizer.buf[tmp_tokenizer.index] == '>') break;
}
return tmp_tokenizer.buf[tok.loc.byte_offset .. tmp_tokenizer.index + 1];
}
const res = tmp_tokenizer.next();
return tmp_tokenizer.buf[res.start..res.end];
}
/// Concat two tokens and add the result to pp.generated
fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const Token) Error!void {
const lhs = while (lhs_toks.popOrNull()) |lhs| {
if (lhs.id == .whitespace)
Token.free(lhs.expansion_locs, pp.comp.gpa)
else
break lhs;
} else {
return bufCopyTokens(lhs_toks, rhs_toks, &.{});
};
var rhs_rest: u32 = 1;
const rhs = for (rhs_toks) |rhs| {
if (rhs.id != .whitespace) break rhs;
rhs_rest += 1;
} else {
return lhs_toks.appendAssumeCapacity(lhs);
};
defer Token.free(lhs.expansion_locs, pp.comp.gpa);
const start = pp.comp.generated_buf.items.len;
const end = start + pp.expandedSlice(lhs).len + pp.expandedSlice(rhs).len;
try pp.comp.generated_buf.ensureTotalCapacity(end + 1); // +1 for a newline
// We cannot use the same slices here since they might be invalidated by `ensureCapacity`
pp.comp.generated_buf.appendSliceAssumeCapacity(pp.expandedSlice(lhs));
pp.comp.generated_buf.appendSliceAssumeCapacity(pp.expandedSlice(rhs));
pp.comp.generated_buf.appendAssumeCapacity('\n');
// Try to tokenize the result.
var tmp_tokenizer = Tokenizer{
.buf = pp.comp.generated_buf.items,
.comp = pp.comp,
.index = @intCast(u32, start),
.source = .generated,
};
const pasted_token = tmp_tokenizer.nextNoWS();
const next = tmp_tokenizer.nextNoWS().id;
if (next != .nl and next != .eof) {
try pp.comp.diag.add(.{
.tag = .pasting_formed_invalid,
.loc = lhs.loc,
.extra = .{ .str = try pp.arena.allocator().dupe(u8, pp.comp.generated_buf.items[start..end]) },
}, lhs.expansionSlice());
}
try lhs_toks.append(try pp.makeGeneratedToken(start, pasted_token.id, lhs));
try bufCopyTokens(lhs_toks, rhs_toks[rhs_rest..], &.{});
}
fn makeGeneratedToken(pp: *Preprocessor, start: usize, id: Token.Id, source: Token) !Token {
var pasted_token = Token{ .id = id, .loc = .{
.id = .generated,
.byte_offset = @intCast(u32, start),
.line = pp.generated_line,
} };
pp.generated_line += 1;
try pasted_token.addExpansionLocation(pp.comp.gpa, &.{source.loc});
try pasted_token.addExpansionLocation(pp.comp.gpa, source.expansionSlice());
return pasted_token;
}
/// Defines a new macro and warns if it is a duplicate
fn defineMacro(pp: *Preprocessor, name_tok: RawToken, macro: Macro) Error!void {
const name_str = pp.tokSlice(name_tok);
const gop = try pp.defines.getOrPut(name_str);
if (gop.found_existing and !gop.value_ptr.eql(macro, pp)) {
try pp.comp.diag.add(.{
.tag = if (gop.value_ptr.is_builtin) .builtin_macro_redefined else .macro_redefined,
.loc = .{ .id = name_tok.source, .byte_offset = name_tok.start, .line = name_tok.line },
.extra = .{ .str = name_str },
}, &.{});
// TODO add a previous definition note
}
gop.value_ptr.* = macro;
}
/// Handle a #define directive.
fn define(pp: *Preprocessor, tokenizer: *Tokenizer) Error!void {
// Get macro name and validate it.
const macro_name = tokenizer.nextNoWS();
if (macro_name.id == .keyword_defined) {
try pp.err(macro_name, .defined_as_macro_name);
return skipToNl(tokenizer);
}
if (!macro_name.id.isMacroIdentifier()) {
try pp.err(macro_name, .macro_name_must_be_identifier);
return skipToNl(tokenizer);
}
// Check for function macros and empty defines.
var first = tokenizer.next();
switch (first.id) {
.nl, .eof => return pp.defineMacro(macro_name, .{
.params = undefined,
.tokens = undefined,
.var_args = false,
.loc = undefined,
.is_func = false,
}),
.whitespace => first = tokenizer.next(),
.l_paren => return pp.defineFn(tokenizer, macro_name, first),
else => try pp.err(first, .whitespace_after_macro_name),
}
if (first.id == .hash_hash) {
try pp.err(first, .hash_hash_at_start);
return skipToNl(tokenizer);
}
first.id.simplifyMacroKeyword();
pp.token_buf.items.len = 0; // Safe to use since we can only be in one directive at a time.
var end_index: u32 = undefined;
// Collect the token body and validate any ## found.
var tok = first;
while (true) {
tok.id.simplifyMacroKeyword();
switch (tok.id) {
.hash_hash => {
const next = tokenizer.nextNoWS();
switch (next.id) {
.nl, .eof => {
try pp.err(tok, .hash_hash_at_end);
return;
},
.hash_hash => {
try pp.err(next, .hash_hash_at_end);
return;
},
else => {},
}
try pp.token_buf.append(tok);
try pp.token_buf.append(next);
},
.nl, .eof => {
end_index = tok.start;
break;
},
else => try pp.token_buf.append(tok),
}
tok = tokenizer.next();
}
const list = try pp.arena.allocator().dupe(RawToken, pp.token_buf.items);
try pp.defineMacro(macro_name, .{
.loc = .{
.id = macro_name.source,
.byte_offset = first.start,
.line = end_index,
},
.tokens = list,
.params = undefined,
.is_func = false,
.var_args = false,
});
}
/// Handle a function like #define directive.
fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, macro_name: RawToken, l_paren: RawToken) Error!void {
assert(macro_name.id.isMacroIdentifier());
var params = std.ArrayList([]const u8).init(pp.comp.gpa);
defer params.deinit();
// Parse the parameter list.
var var_args = false;
var start_index: u32 = undefined;
while (true) {
var tok = tokenizer.next();
if (tok.id == .whitespace) continue;
if (tok.id == .r_paren) {
start_index = tok.end;
break;
}
if (params.items.len != 0) {
if (tok.id != .comma) {
try pp.err(tok, .invalid_token_param_list);
return skipToNl(tokenizer);
} else tok = tokenizer.nextNoWS();
}
if (tok.id == .eof) return pp.err(tok, .unterminated_macro_param_list);
if (tok.id == .ellipsis) {
var_args = true;
const r_paren = tokenizer.nextNoWS();
if (r_paren.id != .r_paren) {
try pp.err(r_paren, .missing_paren_param_list);
try pp.err(l_paren, .to_match_paren);
return skipToNl(tokenizer);
}
break;
}
if (!tok.id.isMacroIdentifier()) {
try pp.err(tok, .invalid_token_param_list);
return skipToNl(tokenizer);
}
try params.append(pp.tokSlice(tok));
}
var end_index: u32 = undefined;
// Collect the body tokens and validate # and ##'s found.
pp.token_buf.items.len = 0; // Safe to use since we can only be in one directive at a time.
tok_loop: while (true) {
var tok = tokenizer.next();
switch (tok.id) {
.nl, .eof => {
end_index = tok.start;
break;
},
.whitespace => if (pp.token_buf.items.len != 0) try pp.token_buf.append(tok),
.hash => {
const param = tokenizer.nextNoWS();
blk: {
if (var_args and param.id == .keyword_va_args) {
tok.id = .stringify_va_args;
try pp.token_buf.append(tok);
continue :tok_loop;
}
if (!param.id.isMacroIdentifier()) break :blk;
const s = pp.tokSlice(param);
for (params.items) |p, i| {
if (mem.eql(u8, p, s)) {
tok.id = .stringify_param;
tok.end = @intCast(u32, i);
try pp.token_buf.append(tok);
continue :tok_loop;
}
}
}
try pp.err(param, .hash_not_followed_param);
return skipToNl(tokenizer);
},
.hash_hash => {
// if ## appears at the beginning, the token buf is still empty
// in this case, error out
if (pp.token_buf.items.len == 0) {
try pp.err(tok, .hash_hash_at_start);
return skipToNl(tokenizer);
}
const saved_tokenizer = tokenizer.*;
const next = tokenizer.nextNoWS();
if (next.id == .nl or next.id == .eof) {
try pp.err(tok, .hash_hash_at_end);
return;
}
tokenizer.* = saved_tokenizer;
// convert the previous token to .macro_param_no_expand if it was .macro_param
if (pp.token_buf.items[pp.token_buf.items.len - 1].id == .macro_param) {
pp.token_buf.items[pp.token_buf.items.len - 1].id = .macro_param_no_expand;
}
try pp.token_buf.append(tok);
},
else => {
if (var_args and tok.id == .keyword_va_args) {
// do nothing
} else if (tok.id.isMacroIdentifier()) {
tok.id.simplifyMacroKeyword();
const s = pp.tokSlice(tok);
for (params.items) |param, i| {
if (mem.eql(u8, param, s)) {
// NOTE: it doesn't matter to assign .macro_param_no_expand
// here in case a ## was the previous token, because
// ## processing will eat this token with the same semantics
tok.id = .macro_param;
tok.end = @intCast(u32, i);
break;
}
}
}
try pp.token_buf.append(tok);
},
}
}
const param_list = try pp.arena.allocator().dupe([]const u8, params.items);
const token_list = try pp.arena.allocator().dupe(RawToken, pp.token_buf.items);
try pp.defineMacro(macro_name, .{
.is_func = true,
.params = param_list,
.var_args = var_args,
.tokens = token_list,
.loc = .{
.id = macro_name.source,
.byte_offset = start_index,
.line = end_index,
},
});
}
// Handle a #include directive.
fn include(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {
const new_source = findIncludeSource(pp, tokenizer) catch |er| switch (er) {
error.InvalidInclude => return,
else => |e| return e,
};
// Prevent stack overflow
pp.include_depth += 1;
defer pp.include_depth -= 1;
if (pp.include_depth > max_include_depth) return;
_ = pp.preprocessExtra(new_source) catch |err| switch (err) {
error.StopPreprocessing => {},
else => |e| return e,
};
}
/// tokens that are part of a pragma directive can happen in 3 ways:
/// 1. directly in the text via `#pragma ...`
/// 2. Via a string literal argument to `_Pragma`
/// 3. Via a stringified macro argument which is used as an argument to `_Pragma`
/// operator_loc: Location of `_Pragma`; null if this is from #pragma
/// arg_locs: expansion locations of the argument to _Pragma. empty if #pragma or a raw string literal was used
fn makePragmaToken(pp: *Preprocessor, raw: RawToken, operator_loc: ?Source.Location, arg_locs: []const Source.Location) !Token {
var tok = tokFromRaw(raw);
if (operator_loc) |loc| {
try tok.addExpansionLocation(pp.comp.gpa, &.{loc});
}
try tok.addExpansionLocation(pp.comp.gpa, arg_locs);
return tok;
}
/// Handle a pragma directive
fn pragma(pp: *Preprocessor, tokenizer: *Tokenizer, pragma_tok: RawToken, operator_loc: ?Source.Location, arg_locs: []const Source.Location) !void {
const name_tok = tokenizer.nextNoWS();
if (name_tok.id == .nl or name_tok.id == .eof) return;
const name = pp.tokSlice(name_tok);
try pp.tokens.append(pp.comp.gpa, try pp.makePragmaToken(pragma_tok, operator_loc, arg_locs));
const pragma_start = @intCast(u32, pp.tokens.len);
const pragma_name_tok = try pp.makePragmaToken(name_tok, operator_loc, arg_locs);
try pp.tokens.append(pp.comp.gpa, pragma_name_tok);
while (true) {
const next_tok = tokenizer.next();
if (next_tok.id == .whitespace) continue;
if (next_tok.id == .eof) {
try pp.tokens.append(pp.comp.gpa, .{
.id = .nl,
.loc = .{ .id = .generated },
});
break;
}
try pp.tokens.append(pp.comp.gpa, try pp.makePragmaToken(next_tok, operator_loc, arg_locs));
if (next_tok.id == .nl) break;
}
if (pp.comp.getPragma(name)) |prag| unknown: {
return prag.preprocessorCB(pp, pragma_start) catch |err| switch (err) {
error.UnknownPragma => break :unknown,
else => |e| return e,
};
}
return pp.comp.diag.add(.{
.tag = .unsupported_pragma,
.loc = pragma_name_tok.loc,
.extra = .{ .str = name },
}, pragma_name_tok.expansionSlice());
}
fn findIncludeSource(pp: *Preprocessor, tokenizer: *Tokenizer) !Source {
const start = pp.tokens.len;
defer pp.tokens.len = start;
var first = tokenizer.nextNoWS();
if (first.id == .angle_bracket_left) to_end: {
// The tokenizer does not handle <foo> include strings so do it here.
while (tokenizer.index < tokenizer.buf.len) : (tokenizer.index += 1) {
switch (tokenizer.buf[tokenizer.index]) {
'>' => {
tokenizer.index += 1;
first.end = tokenizer.index;
first.id = .macro_string;
break :to_end;
},
'\n' => break,
else => {},
}
}
try pp.comp.diag.add(.{
.tag = .header_str_closing,
.loc = .{ .id = first.source, .byte_offset = first.start },
}, &.{});
try pp.err(first, .header_str_match);
}
// Try to expand if the argument is a macro.
try pp.expandMacro(tokenizer, first);
// Check that we actually got a string.
const filename_tok = pp.tokens.get(start);
switch (filename_tok.id) {
.string_literal, .macro_string => {},
else => {
try pp.err(first, .expected_filename);
try pp.expectNl(tokenizer);
return error.InvalidInclude;
},
}
// Error on extra tokens.
const nl = tokenizer.nextNoWS();
if ((nl.id != .nl and nl.id != .eof) or pp.tokens.len > start + 1) {
skipToNl(tokenizer);
try pp.err(first, .extra_tokens_directive_end);
}
// Check for empty filename.
const tok_slice = pp.expandedSlice(filename_tok);
if (tok_slice.len < 3) {
try pp.err(first, .empty_filename);
return error.InvalidInclude;
}
// Find the file.
const filename = tok_slice[1 .. tok_slice.len - 1];
return (try pp.comp.findInclude(first, filename, filename_tok.id == .string_literal)) orelse
pp.fatal(first, "'{s}' not found", .{filename});
}
/// Pretty print tokens and try to preserve whitespace.
pub fn prettyPrintTokens(pp: *Preprocessor, w: anytype) !void {
var i: u32 = 0;
while (true) : (i += 1) {
var cur: Token = pp.tokens.get(i);
switch (cur.id) {
.eof => break,
.nl => try w.writeAll("\n"),
.keyword_pragma => {
const pragma_name = pp.expandedSlice(pp.tokens.get(i + 1));
const end_idx = mem.indexOfScalarPos(Token.Id, pp.tokens.items(.id), i, .nl) orelse i + 1;
const pragma_len = @intCast(u32, end_idx) - i;
if (pp.comp.getPragma(pragma_name)) |prag| {
if (!prag.shouldPreserveTokens(pp, i + 1)) {
i += pragma_len;
cur = pp.tokens.get(i);
continue;
}
}
try w.writeAll("#pragma");
i += 1;
while (true) : (i += 1) {
cur = pp.tokens.get(i);
if (cur.id == .nl) {
try w.writeByte('\n');
break;
}
try w.writeByte(' ');
const slice = pp.expandedSlice(cur);
try w.writeAll(slice);
}
},
else => {
const slice = pp.expandedSlice(cur);
try w.writeAll(slice);
},
}
}
}
test "Preserve pragma tokens sometimes" {
const allocator = std.testing.allocator;
const Test = struct {
fn runPreprocessor(source_text: []const u8) ![]const u8 {
var buf = std.ArrayList(u8).init(allocator);
defer buf.deinit();
var comp = Compilation.init(allocator);
defer comp.deinit();
comp.only_preprocess = true;
try comp.addDefaultPragmaHandlers();
var pp = Preprocessor.init(&comp);
defer pp.deinit();
const test_runner_macros = blk: {
const duped_path = try allocator.dupe(u8, "<test_runner>");
errdefer comp.gpa.free(duped_path);
const contents = try allocator.dupe(u8, source_text);
errdefer comp.gpa.free(contents);
const source = Source{
.id = @intToEnum(Source.Id, comp.sources.count() + 2),
.path = duped_path,
.buf = contents,
};
try comp.sources.put(duped_path, source);
break :blk source;
};
const eof = try pp.preprocess(test_runner_macros);
try pp.tokens.append(pp.comp.gpa, eof);
try pp.prettyPrintTokens(buf.writer());
return allocator.dupe(u8, buf.items);
}
fn check(source_text: []const u8, expected: []const u8) !void {
const output = try runPreprocessor(source_text);
defer allocator.free(output);
try std.testing.expectEqualStrings(expected, output);
}
};
const preserve_gcc_diagnostic =
\\#pragma GCC diagnostic error "-Wnewline-eof"
\\#pragma GCC warning error "-Wnewline-eof"
\\int x;
\\#pragma GCC ignored error "-Wnewline-eof"
\\
;
try Test.check(preserve_gcc_diagnostic, preserve_gcc_diagnostic);
const omit_once =
\\#pragma once
\\int x;
\\#pragma once
\\
;
try Test.check(omit_once, "int x;\n");
const omit_poison =
\\#pragma GCC poison foobar
\\
;
try Test.check(omit_poison, "");
}
test "destringify" {
const allocator = std.testing.allocator;
const Test = struct {
fn testDestringify(pp: *Preprocessor, stringified: []const u8, destringified: []const u8) !void {
pp.char_buf.clearRetainingCapacity();
try pp.char_buf.ensureUnusedCapacity(stringified.len);
pp.destringify(stringified);
try std.testing.expectEqualStrings(destringified, pp.char_buf.items);
}
};
var comp = Compilation.init(allocator);
defer comp.deinit();
var pp = Preprocessor.init(&comp);
defer pp.deinit();
try Test.testDestringify(&pp, "hello\tworld\n", "hello\tworld\n");
try Test.testDestringify(&pp,
\\ \"FOO BAR BAZ\"
,
\\ "FOO BAR BAZ"
);
try Test.testDestringify(&pp,
\\ \\t\\n
\\
,
\\ \t\n
\\
);
} | src/Preprocessor.zig |
const high_bit = 1 << @typeInfo(usize).Int.bits - 1;
/// The operation completed successfully.
pub const success: usize = 0;
/// The image failed to load.
pub const load_error: usize = high_bit | 1;
/// A parameter was incorrect.
pub const invalid_parameter: usize = high_bit | 2;
/// The operation is not supported.
pub const unsupported: usize = high_bit | 3;
/// The buffer was not the proper size for the request.
pub const bad_buffer_size: usize = high_bit | 4;
/// The buffer is not large enough to hold the requested data. The required buffer size is returned in the appropriate parameter when this error occurs.
pub const buffer_too_small: usize = high_bit | 5;
/// There is no data pending upon return.
pub const not_ready: usize = high_bit | 6;
/// The physical device reported an error while attempting the operation.
pub const device_error: usize = high_bit | 7;
/// The device cannot be written to.
pub const write_protected: usize = high_bit | 8;
/// A resource has run out.
pub const out_of_resources: usize = high_bit | 9;
/// An inconstancy was detected on the file system causing the operating to fail.
pub const volume_corrupted: usize = high_bit | 10;
/// There is no more space on the file system.
pub const volume_full: usize = high_bit | 11;
/// The device does not contain any medium to perform the operation.
pub const no_media: usize = high_bit | 12;
/// The medium in the device has changed since the last access.
pub const media_changed: usize = high_bit | 13;
/// The item was not found.
pub const not_found: usize = high_bit | 14;
/// Access was denied.
pub const access_denied: usize = high_bit | 15;
/// The server was not found or did not respond to the request.
pub const no_response: usize = high_bit | 16;
/// A mapping to a device does not exist.
pub const no_mapping: usize = high_bit | 17;
/// The timeout time expired.
pub const timeout: usize = high_bit | 18;
/// The protocol has not been started.
pub const not_started: usize = high_bit | 19;
/// The protocol has already been started.
pub const already_started: usize = high_bit | 20;
/// The operation was aborted.
pub const aborted: usize = high_bit | 21;
/// An ICMP error occurred during the network operation.
pub const icmp_error: usize = high_bit | 22;
/// A TFTP error occurred during the network operation.
pub const tftp_error: usize = high_bit | 23;
/// A protocol error occurred during the network operation.
pub const protocol_error: usize = high_bit | 24;
/// The function encountered an internal version that was incompatible with a version requested by the caller.
pub const incompatible_version: usize = high_bit | 25;
/// The function was not performed due to a security violation.
pub const security_violation: usize = high_bit | 26;
/// A CRC error was detected.
pub const crc_error: usize = high_bit | 27;
/// Beginning or end of media was reached
pub const end_of_media: usize = high_bit | 28;
/// The end of the file was reached.
pub const end_of_file: usize = high_bit | 31;
/// The language specified was invalid.
pub const invalid_language: usize = high_bit | 32;
/// The security status of the data is unknown or compromised and the data must be updated or replaced to restore a valid security status.
pub const compromised_data: usize = high_bit | 33;
/// There is an address conflict address allocation
pub const ip_address_conflict: usize = high_bit | 34;
/// A HTTP error occurred during the network operation.
pub const http_error: usize = high_bit | 35;
/// The string contained one or more characters that the device could not render and were skipped.
pub const warn_unknown_glyph: usize = 1;
/// The handle was closed, but the file was not deleted.
pub const warn_delete_failure: usize = 2;
/// The handle was closed, but the data to the file was not flushed properly.
pub const warn_write_failure: usize = 3;
/// The resulting buffer was too small, and the data was truncated to the buffer size.
pub const warn_buffer_too_small: usize = 4;
/// The data has not been updated within the timeframe set by localpolicy for this type of data.
pub const warn_stale_data: usize = 5;
/// The resulting buffer contains UEFI-compliant file system.
pub const warn_file_system: usize = 6;
/// The operation will be processed across a system reset.
pub const warn_reset_required: usize = 7; | lib/std/os/uefi/status.zig |
usingnamespace @import("math3d.zig");
usingnamespace @import("tetris.zig");
const std = @import("std");
const panic = std.debug.panic;
const assert = std.debug.assert;
const bufPrint = std.fmt.bufPrint;
const c = @import("c.zig");
const debug_gl = @import("debug_gl.zig");
const AllShaders = @import("all_shaders.zig").AllShaders;
const StaticGeometry = @import("static_geometry.zig").StaticGeometry;
const pieces = @import("pieces.zig");
const Piece = pieces.Piece;
const Spritesheet = @import("spritesheet.zig").Spritesheet;
var window: *c.GLFWwindow = undefined;
var all_shaders: AllShaders = undefined;
var static_geometry: StaticGeometry = undefined;
var font: Spritesheet = undefined;
fn errorCallback(err: c_int, description: [*c]const u8) callconv(.C) void {
panic("Error: {}\n", .{@as([*:0]const u8, description)});
}
fn keyCallback(win: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void {
if (action != c.GLFW_PRESS) return;
const t = @ptrCast(*Tetris, @alignCast(@alignOf(Tetris), c.glfwGetWindowUserPointer(win).?));
switch (key) {
c.GLFW_KEY_ESCAPE => c.glfwSetWindowShouldClose(win, c.GL_TRUE),
c.GLFW_KEY_SPACE => userDropCurPiece(t),
c.GLFW_KEY_DOWN => userCurPieceFall(t),
c.GLFW_KEY_LEFT => userMoveCurPiece(t, -1),
c.GLFW_KEY_RIGHT => userMoveCurPiece(t, 1),
c.GLFW_KEY_UP => userRotateCurPiece(t, 1),
c.GLFW_KEY_LEFT_SHIFT, c.GLFW_KEY_RIGHT_SHIFT => userRotateCurPiece(t, -1),
c.GLFW_KEY_R => restartGame(t),
c.GLFW_KEY_P => userTogglePause(t),
c.GLFW_KEY_LEFT_CONTROL, c.GLFW_KEY_RIGHT_CONTROL => userSetHoldPiece(t),
else => {},
}
}
var tetris_state: Tetris = undefined;
const font_png = @embedFile("../assets/font.png");
pub fn main() !void {
_ = c.glfwSetErrorCallback(errorCallback);
if (c.glfwInit() == c.GL_FALSE) {
panic("GLFW init failure\n", .{});
}
defer c.glfwTerminate();
c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MAJOR, 3);
c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MINOR, 2);
c.glfwWindowHint(c.GLFW_OPENGL_FORWARD_COMPAT, c.GL_TRUE);
c.glfwWindowHint(c.GLFW_OPENGL_DEBUG_CONTEXT, debug_gl.is_on);
c.glfwWindowHint(c.GLFW_OPENGL_PROFILE, c.GLFW_OPENGL_CORE_PROFILE);
c.glfwWindowHint(c.GLFW_DEPTH_BITS, 0);
c.glfwWindowHint(c.GLFW_STENCIL_BITS, 8);
c.glfwWindowHint(c.GLFW_RESIZABLE, c.GL_FALSE);
window = c.glfwCreateWindow(window_width, window_height, "Tetris", null, null) orelse {
panic("unable to create window\n", .{});
};
defer c.glfwDestroyWindow(window);
_ = c.glfwSetKeyCallback(window, keyCallback);
c.glfwMakeContextCurrent(window);
c.glfwSwapInterval(1);
// create and bind exactly one vertex array per context and use
// glVertexAttribPointer etc every frame.
var vertex_array_object: c.GLuint = undefined;
c.glGenVertexArrays(1, &vertex_array_object);
c.glBindVertexArray(vertex_array_object);
defer c.glDeleteVertexArrays(1, &vertex_array_object);
const t = &tetris_state;
c.glfwGetFramebufferSize(window, &t.framebuffer_width, &t.framebuffer_height);
assert(t.framebuffer_width >= window_width);
assert(t.framebuffer_height >= window_height);
all_shaders = try AllShaders.create();
defer all_shaders.destroy();
static_geometry = StaticGeometry.create();
defer static_geometry.destroy();
font.init(font_png, font_char_width, font_char_height) catch {
panic("unable to read assets\n", .{});
};
defer font.deinit();
var seed_bytes: [@sizeOf(u64)]u8 = undefined;
std.crypto.randomBytes(seed_bytes[0..]) catch |err| {
panic("unable to seed random number generator: {}", .{err});
};
t.prng = std.rand.DefaultPrng.init(std.mem.readIntNative(u64, &seed_bytes));
t.rand = &t.prng.random;
resetProjection(t);
restartGame(t);
c.glClearColor(0.0, 0.0, 0.0, 1.0);
c.glEnable(c.GL_BLEND);
c.glBlendFunc(c.GL_SRC_ALPHA, c.GL_ONE_MINUS_SRC_ALPHA);
c.glPixelStorei(c.GL_UNPACK_ALIGNMENT, 1);
c.glViewport(0, 0, t.framebuffer_width, t.framebuffer_height);
c.glfwSetWindowUserPointer(window, @ptrCast(*c_void, t));
debug_gl.assertNoError();
const start_time = c.glfwGetTime();
var prev_time = start_time;
while (c.glfwWindowShouldClose(window) == c.GL_FALSE) {
c.glClear(c.GL_COLOR_BUFFER_BIT | c.GL_DEPTH_BUFFER_BIT | c.GL_STENCIL_BUFFER_BIT);
const now_time = c.glfwGetTime();
const elapsed = now_time - prev_time;
prev_time = now_time;
nextFrame(t, elapsed);
draw(t, @This());
c.glfwSwapBuffers(window);
c.glfwPollEvents();
}
debug_gl.assertNoError();
}
pub fn fillRectMvp(t: *Tetris, color: Vec4, mvp: Mat4x4) void {
all_shaders.primitive.bind();
all_shaders.primitive.setUniformVec4(all_shaders.primitive_uniform_color, color);
all_shaders.primitive.setUniformMat4x4(all_shaders.primitive_uniform_mvp, mvp);
c.glBindBuffer(c.GL_ARRAY_BUFFER, static_geometry.rect_2d_vertex_buffer);
c.glEnableVertexAttribArray(@intCast(c.GLuint, all_shaders.primitive_attrib_position));
c.glVertexAttribPointer(@intCast(c.GLuint, all_shaders.primitive_attrib_position), 3, c.GL_FLOAT, c.GL_FALSE, 0, null);
c.glDrawArrays(c.GL_TRIANGLE_STRIP, 0, 4);
}
pub fn drawParticle(t: *Tetris, p: Particle) void {
const model = mat4x4_identity.translateByVec(p.pos).rotate(p.angle, p.axis).scale(p.scale_w, p.scale_h, 0.0);
const mvp = t.projection.mult(model);
all_shaders.primitive.bind();
all_shaders.primitive.setUniformVec4(all_shaders.primitive_uniform_color, p.color);
all_shaders.primitive.setUniformMat4x4(all_shaders.primitive_uniform_mvp, mvp);
c.glBindBuffer(c.GL_ARRAY_BUFFER, static_geometry.triangle_2d_vertex_buffer);
c.glEnableVertexAttribArray(@intCast(c.GLuint, all_shaders.primitive_attrib_position));
c.glVertexAttribPointer(@intCast(c.GLuint, all_shaders.primitive_attrib_position), 3, c.GL_FLOAT, c.GL_FALSE, 0, null);
c.glDrawArrays(c.GL_TRIANGLE_STRIP, 0, 3);
}
pub fn drawText(t: *Tetris, text: []const u8, left: i32, top: i32, size: f32) void {
for (text) |col, i| {
if (col <= '~') {
const char_left = @intToFloat(f32, left) + @intToFloat(f32, i * font_char_width) * size;
const model = mat4x4_identity.translate(char_left, @intToFloat(f32, top), 0.0).scale(size, size, 0.0);
const mvp = t.projection.mult(model);
font.draw(all_shaders, col, mvp);
} else {
unreachable;
}
}
} | src/main.zig |
const std = @import("std");
const with_trace = true;
const assert = std.debug.assert;
fn trace(comptime fmt: []const u8, args: anytype) void {
if (with_trace) std.debug.print(fmt, args);
}
const Operation = enum {
NONE,
AND,
OR,
NOT,
LSHIFT,
RSHIFT,
};
const Wire = [2]u8;
const Input = union(enum) {
immediate: u16,
wire: Wire,
};
fn parse_line(line: []const u8, op: *Operation, in: []Input, out: *Wire) void {
var index_in: u32 = 0;
var arrow_found: bool = false;
op.* = .NONE;
var it = std.mem.split(u8, line, " ");
while (it.next()) |par| {
if (std.mem.eql(u8, "AND", par)) {
op.* = .AND;
} else if (std.mem.eql(u8, "OR", par)) {
op.* = .OR;
} else if (std.mem.eql(u8, "NOT", par)) {
op.* = .NOT;
} else if (std.mem.eql(u8, "LSHIFT", par)) {
op.* = .LSHIFT;
} else if (std.mem.eql(u8, "RSHIFT", par)) {
op.* = .RSHIFT;
} else if (std.mem.eql(u8, "->", par)) {
arrow_found = true;
} else if (std.fmt.parseInt(u16, par, 10)) |imm| {
assert(!arrow_found);
in[index_in] = Input{ .immediate = imm };
index_in += 1;
} else |err| {
assert(par.len <= 2);
const wire = Wire{ par[0], if (par.len > 1) par[1] else ' ' };
if (!arrow_found) {
in[index_in] = Input{ .wire = wire };
index_in += 1;
} else {
out.* = wire;
}
}
}
}
const Gate = struct {
op: Operation,
in: [2]Input,
out: Wire,
val: ?u16,
};
fn getgate(gates: []Gate, w: Wire) *Gate {
var g_maybe: ?*Gate = null;
for (gates) |*it| {
if (it.out[0] == w[0] and it.out[1] == w[1]) {
g_maybe = it;
break;
}
}
assert(g_maybe != null);
return g_maybe.?;
}
fn compute(gates: []Gate, w: Wire) u16 {
const g = getgate(gates, w);
if (g.val) |v|
return v;
// recusrse
const ninputs: u32 = if (g.op == .NONE or g.op == .NOT) 1 else 2;
var in: [2]u16 = undefined;
var i: u32 = 0;
while (i < ninputs) : (i += 1) {
switch (g.in[i]) {
.wire => |wi| in[i] = compute(gates, wi),
.immediate => |imm| in[i] = imm,
}
}
trace("computed {} -> {}\n", w, in[0]);
var v: u16 = 0;
// applyop
switch (g.op) {
.NONE => v = in[0],
.NOT => v = ~in[0],
.AND => v = in[0] & in[1],
.OR => v = in[0] | in[1],
.LSHIFT => v = in[0] << @intCast(u4, in[1]),
.RSHIFT => v = in[0] >> @intCast(u4, in[1]),
}
g.val = v;
return v;
}
pub fn main() anyerror!void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
const limit = 1 * 1024 * 1024 * 1024;
const text = try std.fs.cwd().readFileAlloc(allocator, "day7.txt", limit);
const gates = try allocator.alloc(Gate, 1000);
var igate: u32 = 0;
var it = std.mem.split(u8, text, "\n");
while (it.next()) |line_full| {
const line = std.mem.trim(u8, line_full, " \n\r\t");
if (line.len == 0)
continue;
var op: Operation = undefined;
var in: [2]Input = undefined;
var out: Wire = undefined;
const g = &gates[igate];
igate += 1;
parse_line(line, &g.op, &g.in, &g.out);
//trace("'{}' : {}, {}, {}\n", line, g.op, g.in[0], g.out);
}
const force_wire = Wire{ 'b', ' ' };
getgate(gates, force_wire).val = 3176;
const out = std.io.getStdOut().writer();
const w = Wire{ 'a', ' ' };
try out.print("lights={} \n", compute(gates, w));
// return error.SolutionNotFound;
} | 2015/day7.zig |
const std = @import("std");
const assert = std.debug.assert;
const log = std.log.scoped(.parse);
const mem = std.mem;
const testing = std.testing;
const Allocator = mem.Allocator;
const Tokenizer = @import("Tokenizer.zig");
const Token = Tokenizer.Token;
const TokenIndex = Tokenizer.TokenIndex;
const TokenIterator = Tokenizer.TokenIterator;
pub const ParseError = error{
MalformedYaml,
NestedDocuments,
UnexpectedTag,
UnexpectedEof,
UnexpectedToken,
Unhandled,
} || Allocator.Error;
pub const Node = struct {
tag: Tag,
tree: *const Tree,
pub const Tag = enum {
doc,
map,
list,
value,
};
pub fn cast(self: *const Node, comptime T: type) ?*const T {
if (self.tag != T.base_tag) {
return null;
}
return @fieldParentPtr(T, "base", self);
}
pub fn deinit(self: *Node, allocator: *Allocator) void {
switch (self.tag) {
.doc => @fieldParentPtr(Node.Doc, "base", self).deinit(allocator),
.map => @fieldParentPtr(Node.Map, "base", self).deinit(allocator),
.list => @fieldParentPtr(Node.List, "base", self).deinit(allocator),
.value => @fieldParentPtr(Node.Value, "base", self).deinit(allocator),
}
}
pub fn format(
self: *const Node,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
return switch (self.tag) {
.doc => @fieldParentPtr(Node.Doc, "base", self).format(fmt, options, writer),
.map => @fieldParentPtr(Node.Map, "base", self).format(fmt, options, writer),
.list => @fieldParentPtr(Node.List, "base", self).format(fmt, options, writer),
.value => @fieldParentPtr(Node.Value, "base", self).format(fmt, options, writer),
};
}
pub const Doc = struct {
base: Node = Node{ .tag = Tag.doc, .tree = undefined },
start: ?TokenIndex = null,
end: ?TokenIndex = null,
directive: ?TokenIndex = null,
value: ?*Node = null,
pub const base_tag: Node.Tag = .doc;
pub fn deinit(self: *Doc, allocator: *Allocator) void {
if (self.value) |node| {
node.deinit(allocator);
allocator.destroy(node);
}
}
pub fn format(
self: *const Doc,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
try std.fmt.format(writer, "Doc {{ ", .{});
if (self.directive) |id| {
const directive = self.base.tree.tokens[id];
try std.fmt.format(writer, ".directive = {s}, ", .{
self.base.tree.source[directive.start..directive.end],
});
}
if (self.value) |node| {
try std.fmt.format(writer, ".value = {}", .{node});
}
return std.fmt.format(writer, " }}", .{});
}
};
pub const Map = struct {
base: Node = Node{ .tag = Tag.map, .tree = undefined },
start: ?TokenIndex = null,
end: ?TokenIndex = null,
values: std.ArrayListUnmanaged(Entry) = .{},
pub const base_tag: Node.Tag = .map;
pub const Entry = struct {
key: TokenIndex,
value: *Node,
};
pub fn deinit(self: *Map, allocator: *Allocator) void {
for (self.values.items) |entry| {
entry.value.deinit(allocator);
allocator.destroy(entry.value);
}
self.values.deinit(allocator);
}
pub fn format(
self: *const Map,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
try std.fmt.format(writer, "Map {{ .values = {{ ", .{});
for (self.values.items) |entry| {
const key = self.base.tree.tokens[entry.key];
try std.fmt.format(writer, "{s} => {}, ", .{
self.base.tree.source[key.start..key.end],
entry.value,
});
}
return std.fmt.format(writer, " }}", .{});
}
};
pub const List = struct {
base: Node = Node{ .tag = Tag.list, .tree = undefined },
start: ?TokenIndex = null,
end: ?TokenIndex = null,
values: std.ArrayListUnmanaged(*Node) = .{},
pub const base_tag: Node.Tag = .list;
pub fn deinit(self: *List, allocator: *Allocator) void {
for (self.values.items) |node| {
node.deinit(allocator);
allocator.destroy(node);
}
self.values.deinit(allocator);
}
pub fn format(
self: *const List,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
try std.fmt.format(writer, "List {{ .values = [ ", .{});
for (self.values.items) |node| {
try std.fmt.format(writer, "{}, ", .{node});
}
return std.fmt.format(writer, "] }}", .{});
}
};
pub const Value = struct {
base: Node = Node{ .tag = Tag.value, .tree = undefined },
start: ?TokenIndex = null,
end: ?TokenIndex = null,
pub const base_tag: Node.Tag = .value;
pub fn deinit(self: *Value, allocator: *Allocator) void {}
pub fn format(
self: *const Value,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
const start = self.base.tree.tokens[self.start.?];
const end = self.base.tree.tokens[self.end.?];
return std.fmt.format(writer, "Value {{ .value = {s} }}", .{
self.base.tree.source[start.start..end.end],
});
}
};
};
pub const Tree = struct {
allocator: *Allocator,
source: []const u8,
tokens: []Token,
docs: std.ArrayListUnmanaged(*Node) = .{},
pub fn init(allocator: *Allocator) Tree {
return .{
.allocator = allocator,
.source = undefined,
.tokens = undefined,
};
}
pub fn deinit(self: *Tree) void {
self.allocator.free(self.tokens);
for (self.docs.items) |doc| {
doc.deinit(self.allocator);
self.allocator.destroy(doc);
}
self.docs.deinit(self.allocator);
}
pub fn parse(self: *Tree, source: []const u8) !void {
var tokenizer = Tokenizer{ .buffer = source };
var tokens = std.ArrayList(Token).init(self.allocator);
errdefer tokens.deinit();
while (true) {
const token = tokenizer.next();
try tokens.append(token);
if (token.id == .Eof) break;
}
self.source = source;
self.tokens = tokens.toOwnedSlice();
var it = TokenIterator{ .buffer = self.tokens };
var parser = Parser{
.allocator = self.allocator,
.tree = self,
.token_it = &it,
};
defer parser.deinit();
try parser.scopes.append(self.allocator, .{
.indent = 0,
});
while (true) {
if (parser.token_it.peek() == null) return;
const pos = parser.token_it.pos;
const token = parser.token_it.next();
log.debug("Next token: {}, {}", .{ pos, token });
switch (token.id) {
.Space, .Comment, .NewLine => {},
.Eof => break,
else => {
const doc = try parser.doc(pos);
try self.docs.append(self.allocator, &doc.base);
},
}
}
}
};
const Parser = struct {
allocator: *Allocator,
tree: *Tree,
token_it: *TokenIterator,
scopes: std.ArrayListUnmanaged(Scope) = .{},
const Scope = struct {
indent: usize,
};
fn deinit(self: *Parser) void {
self.scopes.deinit(self.allocator);
}
fn doc(self: *Parser, start: TokenIndex) ParseError!*Node.Doc {
const node = try self.allocator.create(Node.Doc);
errdefer self.allocator.destroy(node);
node.* = .{
.start = start,
};
node.base.tree = self.tree;
self.token_it.seekTo(start);
log.debug("Doc start: {}, {}", .{ start, self.tree.tokens[start] });
const explicit_doc: bool = if (self.eatToken(.DocStart)) |_| explicit_doc: {
if (self.eatToken(.Tag)) |_| {
node.directive = try self.expectToken(.Literal);
}
_ = try self.expectToken(.NewLine);
break :explicit_doc true;
} else false;
while (true) {
const pos = self.token_it.pos;
const token = self.token_it.next();
log.debug("Next token: {}, {}", .{ pos, token });
switch (token.id) {
.Tag => {
return error.UnexpectedTag;
},
.Literal, .SingleQuote, .DoubleQuote => {
_ = try self.expectToken(.MapValueInd);
const map_node = try self.map(pos);
node.value = &map_node.base;
},
.SeqItemInd => {
const list_node = try self.list(pos);
node.value = &list_node.base;
},
.FlowSeqStart => {
const list_node = try self.list_bracketed(pos);
node.value = &list_node.base;
},
.DocEnd => {
if (explicit_doc) break;
return error.UnexpectedToken;
},
.DocStart, .Eof => {
self.token_it.seekBy(-1);
break;
},
else => {
return error.UnexpectedToken;
},
}
}
node.end = self.token_it.pos - 1;
log.debug("Doc end: {}, {}", .{ node.end.?, self.tree.tokens[node.end.?] });
return node;
}
fn map(self: *Parser, start: TokenIndex) ParseError!*Node.Map {
const node = try self.allocator.create(Node.Map);
errdefer self.allocator.destroy(node);
node.* = .{
.start = start,
};
node.base.tree = self.tree;
self.token_it.seekTo(start);
log.debug("Map start: {}, {}", .{ start, self.tree.tokens[start] });
log.debug("Current scope: {}", .{self.scopes.items[self.scopes.items.len - 1]});
while (true) {
// Parse key.
const key_pos = self.token_it.pos;
const key = self.token_it.next();
switch (key.id) {
.Literal => {},
else => {
self.token_it.seekBy(-1);
break;
},
}
log.debug("Map key: {}, '{s}'", .{ key, self.tree.source[key.start..key.end] });
// Separator
_ = try self.expectToken(.MapValueInd);
self.eatCommentsAndSpace();
// Parse value.
const value: *Node = value: {
if (self.eatToken(.NewLine)) |_| {
// Explicit, complex value such as list or map.
try self.openScope();
const value_pos = self.token_it.pos;
const value = self.token_it.next();
switch (value.id) {
.Literal, .SingleQuote, .DoubleQuote => {
// Assume nested map.
const map_node = try self.map(value_pos);
break :value &map_node.base;
},
.SeqItemInd => {
// Assume list of values.
const list_node = try self.list(value_pos);
break :value &list_node.base;
},
else => {
log.err("{}", .{key});
return error.Unhandled;
},
}
} else {
const value_pos = self.token_it.pos;
const value = self.token_it.next();
switch (value.id) {
.Literal, .SingleQuote, .DoubleQuote => {
// Assume leaf value.
const leaf_node = try self.leaf_value(value_pos);
break :value &leaf_node.base;
},
.FlowSeqStart => {
const list_node = try self.list_bracketed(value_pos);
break :value &list_node.base;
},
else => {
log.err("{}", .{key});
return error.Unhandled;
},
}
}
};
log.debug("Map value: {}", .{value});
try node.values.append(self.allocator, .{
.key = key_pos,
.value = value,
});
if (self.eatToken(.NewLine)) |_| {
if (try self.closeScope()) {
break;
}
}
}
node.end = self.token_it.pos - 1;
log.debug("Map end: {}, {}", .{ node.end.?, self.tree.tokens[node.end.?] });
return node;
}
fn list(self: *Parser, start: TokenIndex) ParseError!*Node.List {
const node = try self.allocator.create(Node.List);
errdefer self.allocator.destroy(node);
node.* = .{
.start = start,
};
node.base.tree = self.tree;
self.token_it.seekTo(start);
log.debug("List start: {}, {}", .{ start, self.tree.tokens[start] });
log.debug("Current scope: {}", .{self.scopes.items[self.scopes.items.len - 1]});
while (true) {
_ = self.eatToken(.SeqItemInd) orelse {
_ = try self.closeScope();
break;
};
self.eatCommentsAndSpace();
const pos = self.token_it.pos;
const token = self.token_it.next();
const value: *Node = value: {
switch (token.id) {
.Literal, .SingleQuote, .DoubleQuote => {
if (self.eatToken(.MapValueInd)) |_| {
if (self.eatToken(.NewLine)) |_| {
try self.openScope();
}
// nested map
const map_node = try self.map(pos);
break :value &map_node.base;
} else {
// standalone (leaf) value
const leaf_node = try self.leaf_value(pos);
break :value &leaf_node.base;
}
},
.FlowSeqStart => {
const list_node = try self.list_bracketed(pos);
break :value &list_node.base;
},
else => {
log.err("{}", .{token});
return error.Unhandled;
},
}
};
try node.values.append(self.allocator, value);
_ = self.eatToken(.NewLine);
}
node.end = self.token_it.pos - 1;
log.debug("List end: {}, {}", .{ node.end.?, self.tree.tokens[node.end.?] });
return node;
}
fn list_bracketed(self: *Parser, start: TokenIndex) ParseError!*Node.List {
const node = try self.allocator.create(Node.List);
errdefer self.allocator.destroy(node);
node.* = .{
.start = start,
};
node.base.tree = self.tree;
self.token_it.seekTo(start);
log.debug("List start: {}, {}", .{ start, self.tree.tokens[start] });
log.debug("Current scope: {}", .{self.scopes.items[self.scopes.items.len - 1]});
_ = try self.expectToken(.FlowSeqStart);
while (true) {
_ = self.eatToken(.NewLine);
self.eatCommentsAndSpace();
const pos = self.token_it.pos;
const token = self.token_it.next();
log.debug("Next token: {}, {}", .{ pos, token });
const value: *Node = value: {
switch (token.id) {
.FlowSeqStart => {
const list_node = try self.list_bracketed(pos);
break :value &list_node.base;
},
.FlowSeqEnd => {
_ = self.eatToken(.NewLine);
break;
},
.Literal, .SingleQuote, .DoubleQuote => {
const leaf_node = try self.leaf_value(pos);
_ = self.eatToken(.Comma);
// TODO newline
break :value &leaf_node.base;
},
else => {
log.err("{}", .{token});
return error.Unhandled;
},
}
};
try node.values.append(self.allocator, value);
}
node.end = self.token_it.pos - 1;
log.debug("List end: {}, {}", .{ node.end.?, self.tree.tokens[node.end.?] });
return node;
}
fn leaf_value(self: *Parser, start: TokenIndex) ParseError!*Node.Value {
const node = try self.allocator.create(Node.Value);
errdefer self.allocator.destroy(node);
node.* = .{
.start = start,
};
node.base.tree = self.tree;
self.token_it.seekTo(start);
log.debug("Leaf start: {}, {}", .{ node.start.?, self.tree.tokens[node.start.?] });
parse: {
if (self.eatToken(.SingleQuote)) |_| {
node.start = node.start.? + 1;
while (true) {
const pos = self.token_it.pos;
const tok = self.token_it.next();
switch (tok.id) {
.SingleQuote => {
node.end = self.token_it.pos - 2;
break :parse;
},
.NewLine => return error.UnexpectedToken,
else => {},
}
}
}
if (self.eatToken(.DoubleQuote)) |_| {
node.start = node.start.? + 1;
while (true) {
const pos = self.token_it.pos;
const tok = self.token_it.next();
switch (tok.id) {
.DoubleQuote => {
node.end = self.token_it.pos - 2;
break :parse;
},
.NewLine => return error.UnexpectedToken,
else => {},
}
}
}
// TODO handle multiline strings in new block scope
while (true) {
const pos = self.token_it.pos;
const tok = self.token_it.next();
switch (tok.id) {
.Literal => {},
.Space => {
const trailing = self.token_it.pos - 2;
self.eatCommentsAndSpace();
if (self.token_it.peek()) |peek| {
if (peek.id != .Literal) {
node.end = trailing;
break;
}
}
},
else => {
self.token_it.seekBy(-1);
node.end = self.token_it.pos - 1;
break;
},
}
}
}
log.debug("Leaf end: {}, {}", .{ node.end.?, self.tree.tokens[node.end.?] });
return node;
}
fn openScope(self: *Parser) !void {
const peek = self.token_it.peek() orelse return error.UnexpectedEof;
if (peek.id != .Space and peek.id != .Tab) {
// No need to open scope.
return;
}
const indent = self.token_it.next().count.?;
const prev_scope = self.scopes.items[self.scopes.items.len - 1];
if (indent < prev_scope.indent) {
return error.MalformedYaml;
}
log.debug("Opening scope...", .{});
try self.scopes.append(self.allocator, .{
.indent = indent,
});
}
fn closeScope(self: *Parser) !bool {
const indent = indent: {
const peek = self.token_it.peek() orelse return error.UnexpectedEof;
switch (peek.id) {
.Space, .Tab => {
break :indent self.token_it.next().count.?;
},
else => {
break :indent 0;
},
}
};
const scope = self.scopes.items[self.scopes.items.len - 1];
if (indent < scope.indent) {
log.debug("Closing scope...", .{});
_ = self.scopes.pop();
return true;
}
return false;
}
fn eatCommentsAndSpace(self: *Parser) void {
while (true) {
_ = self.token_it.peek() orelse return;
const token = self.token_it.next();
switch (token.id) {
.Comment, .Space => {},
else => {
self.token_it.seekBy(-1);
break;
},
}
}
}
fn eatToken(self: *Parser, id: Token.Id) ?TokenIndex {
while (true) {
const pos = self.token_it.pos;
_ = self.token_it.peek() orelse return null;
const token = self.token_it.next();
switch (token.id) {
.Comment, .Space => continue,
else => |next_id| if (next_id == id) {
return pos;
} else {
self.token_it.seekTo(pos);
return null;
},
}
}
}
fn expectToken(self: *Parser, id: Token.Id) ParseError!TokenIndex {
return self.eatToken(id) orelse error.UnexpectedToken;
}
};
test {
_ = @import("parse/test.zig");
} | src/parse.zig |
const std = @import("std");
const log = std.log.scoped(.SPU_2_Interpreter);
const spu = @import("../spu-mk2.zig");
const FlagRegister = spu.FlagRegister;
const Instruction = spu.Instruction;
const ExecutionCondition = spu.ExecutionCondition;
pub fn Interpreter(comptime Bus: type) type {
return struct {
ip: u16 = 0,
sp: u16 = undefined,
bp: u16 = undefined,
fr: FlagRegister = @bitCast(FlagRegister, @as(u16, 0)),
/// This is set to true when we hit an undefined0 instruction, allowing it to
/// be used as a trap for testing purposes
undefined0: bool = false,
/// This is set to true when we hit an undefined1 instruction, allowing it to
/// be used as a trap for testing purposes. undefined1 is used as a breakpoint.
undefined1: bool = false,
bus: Bus,
pub fn ExecuteBlock(self: *@This(), comptime size: ?u32) !void {
var count: usize = 0;
while (size == null or count < size.?) {
count += 1;
var instruction = @bitCast(Instruction, self.bus.read16(self.ip));
log.debug("Executing {}\n", .{instruction});
self.ip +%= 2;
const execute = switch (instruction.condition) {
.always => true,
.not_zero => !self.fr.zero,
.when_zero => self.fr.zero,
.overflow => self.fr.carry,
ExecutionCondition.greater_or_equal_zero => !self.fr.negative,
else => return error.Unimplemented,
};
if (execute) {
const val0 = switch (instruction.input0) {
.zero => @as(u16, 0),
.immediate => i: {
const val = self.bus.read16(@intCast(u16, self.ip));
self.ip +%= 2;
break :i val;
},
else => |e| e: {
// peek or pop; show value at current SP, and if pop, increment sp
const val = self.bus.read16(self.sp);
if (e == .pop) {
self.sp +%= 2;
}
break :e val;
},
};
const val1 = switch (instruction.input1) {
.zero => @as(u16, 0),
.immediate => i: {
const val = self.bus.read16(@intCast(u16, self.ip));
self.ip +%= 2;
break :i val;
},
else => |e| e: {
// peek or pop; show value at current SP, and if pop, increment sp
const val = self.bus.read16(self.sp);
if (e == .pop) {
self.sp +%= 2;
}
break :e val;
},
};
const output: u16 = switch (instruction.command) {
.get => self.bus.read16(self.bp +% (2 *% val0)),
.set => a: {
self.bus.write16(self.bp +% 2 *% val0, val1);
break :a val1;
},
.load8 => self.bus.read8(val0),
.load16 => self.bus.read16(val0),
.store8 => a: {
const val = @truncate(u8, val1);
self.bus.write8(val0, val);
break :a val;
},
.store16 => a: {
self.bus.write16(val0, val1);
break :a val1;
},
.copy => val0,
.add => a: {
var val: u16 = undefined;
self.fr.carry = @addWithOverflow(u16, val0, val1, &val);
break :a val;
},
.sub => a: {
var val: u16 = undefined;
self.fr.carry = @subWithOverflow(u16, val0, val1, &val);
break :a val;
},
.spset => a: {
self.sp = val0;
break :a val0;
},
.bpset => a: {
self.bp = val0;
break :a val0;
},
.frset => a: {
const val = (@bitCast(u16, self.fr) & val1) | (val0 & ~val1);
self.fr = @bitCast(FlagRegister, val);
break :a val;
},
.bswap => (val0 >> 8) | (val0 << 8),
.bpget => self.bp,
.spget => self.sp,
.ipget => self.ip +% (2 *% val0),
.lsl => val0 << 1,
.lsr => val0 >> 1,
.@"and" => val0 & val1,
.@"or" => val0 | val1,
.xor => val0 ^ val1,
.not => ~val0,
.undefined0 => {
self.undefined0 = true;
// Break out of the loop, and let the caller decide what to do
return;
},
.undefined1 => {
self.undefined1 = true;
// Break out of the loop, and let the caller decide what to do
return;
},
.signext => if ((val0 & 0x80) != 0)
(val0 & 0xFF) | 0xFF00
else
(val0 & 0xFF),
else => return error.Unimplemented,
};
switch (instruction.output) {
.discard => {},
.push => {
self.sp -%= 2;
self.bus.write16(self.sp, output);
},
.jump => {
self.ip = output;
},
else => return error.Unimplemented,
}
if (instruction.modify_flags) {
self.fr.negative = (output & 0x8000) != 0;
self.fr.zero = (output == 0x0000);
}
} else {
if (instruction.input0 == .immediate) self.ip +%= 2;
if (instruction.input1 == .immediate) self.ip +%= 2;
break;
}
}
}
};
} | src/codegen/spu-mk2/interpreter.zig |
const std = @import("std");
/// Resolves a unix-like path and removes all "." and ".." from it. Will not escape the root and can be used to sanitize inputs.
pub fn resolvePath(buffer: []u8, src_path: []const u8) error{BufferTooSmall}![]u8 {
if (buffer.len == 0)
return error.BufferTooSmall;
if (src_path.len == 0) {
buffer[0] = '/';
return buffer[0..1];
}
var end: usize = 0;
buffer[0] = '/';
var iter = std.mem.tokenize(src_path, "/");
while (iter.next()) |segment| {
if (std.mem.eql(u8, segment, ".")) {
continue;
} else if (std.mem.eql(u8, segment, "..")) {
while (true) {
if (end == 0)
break;
if (buffer[end] == '/') {
break;
}
end -= 1;
}
} else {
if (end + segment.len + 1 > buffer.len)
return error.BufferTooSmall;
const start = end;
buffer[end] = '/';
end += segment.len + 1;
std.mem.copy(u8, buffer[start + 1 .. end], segment);
}
}
return if (end == 0)
buffer[0 .. end + 1]
else
buffer[0..end];
}
fn testResolve(expected: []const u8, input: []const u8) !void {
var buffer: [1024]u8 = undefined;
const actual = try resolvePath(&buffer, input);
std.testing.expectEqualStrings(expected, actual);
}
test "resolvePath" {
try testResolve("/", "");
try testResolve("/", "/");
try testResolve("/", "////////////");
try testResolve("/a", "a");
try testResolve("/a", "/a");
try testResolve("/a", "////////////a");
try testResolve("/a", "////////////a///");
try testResolve("/a/b/c/d", "/a/b/c/d");
try testResolve("/a/b/d", "/a/b/c/../d");
try testResolve("/", "..");
try testResolve("/", "/..");
try testResolve("/", "/../../../..");
try testResolve("/a/b/c", "a/b/c/");
try testResolve("/new/date.txt", "/new/../../new/date.txt");
}
test "resolvePath overflow" {
var buf: [1]u8 = undefined;
std.testing.expectEqualStrings("/", try resolvePath(&buf, "/"));
std.testing.expectError(error.BufferTooSmall, resolvePath(&buf, "a")); // will resolve to "/a"
} | src/resolvePath.zig |
const std = @import("std");
const math = std.math;
pub fn GridSize(comptime width_: usize, comptime height_: usize) type {
return struct {
const GS = @This();
pub const width = width_;
pub const height = height_;
pub const len = width * height;
pub const widthf = @intToFloat(f64, width);
pub const heightf = @intToFloat(f64, height);
pub const lenf = @intToFloat(f64, len);
pub const xs = @intToFloat(f64, width);
pub const ys = @intToFloat(f64, height);
pub const xu = 1.0 / xs;
pub const yu = 1.0 / ys;
pub const Cell = struct {
x: isize,
y: isize,
pub fn isInside(self: *const Cell) bool {
return self.x >= 0 and self.y >= 0 and self.x < width and self.y < height;
}
pub fn inside(self: *const Cell) ?InsideCell {
return if (self.isInside()) InsideCell{ .x = @intCast(usize, self.x), .y = @intCast(usize, self.y) } else null;
}
pub fn index(self: *const Cell) ?usize {
return GS.index(self.x, self.y);
}
pub fn checked(self: *const Cell, a: anytype, b: @TypeOf(a)) @TypeOf(a) {
return if (self.x & 1 == self.y & 1) a else b;
}
};
pub const InsideCell = struct {
x: usize,
y: usize,
pub fn index(self: *const InsideCell) usize {
return self.y * width + self.x;
}
};
pub fn index(x: anytype, y: anytype) ?usize {
if (x >= 0 and y >= 0 and @intCast(isize, x) < @intCast(isize, width) and @intCast(isize, y) < @intCast(isize, height)) {
return @intCast(usize, y) * width + @intCast(usize, x);
}
return null;
}
pub fn indexToCell(idx: usize) Cell {
return .{
.x = @rem(@intCast(isize, idx), @intCast(isize, width)),
.y = @divTrunc(@intCast(isize, idx), @intCast(isize, width)),
};
}
pub fn cell(x: f64, y: f64) Cell {
return Cell{
.x = @floatToInt(isize, math.floor(x * xs)),
.y = @floatToInt(isize, math.floor(y * ys)),
};
}
pub const pos = Pos.ofF64;
pub fn cellx(x: f64) f64 {
return @mod(x * xs, 1);
}
pub fn celly(y: f64) f64 {
return @mod(y * ys, 1);
}
pub fn floatIterator() FloatIterator(width, height) {
return FloatIterator(width, height).init();
}
pub fn floatIndexIterator() FloatIndexIterator(width, height) {
return FloatIndexIterator(width, height).init();
}
pub fn intIterator() IntIterator(width, height) {
return IntIterator(width, height).init();
}
pub fn intIndexIterator() IntIndexIterator(width, height) {
return IntIndexIterator(width, height).init();
}
pub fn northIndex(index: usize) ?usize {
return if (index < width) null else index - width;
}
pub fn southIndex(index: usize) ?usize {
const result = index + width;
return if (result >= len) null else result;
}
pub fn westIndex(index: usize) ?usize {
const x = @rem(index, width);
return if (x == 0) null else x - 1;
}
pub fn eastIndex(index: usize) ?usize {
const x = @rem(index, width);
const result = x + 1;
return if (result >= width) null else result;
}
pub const Pos = struct {
const Self = @This();
index: usize,
x: usize,
y: usize,
pub const first = Self{ .index = 0, .x = 0, .y = 0 };
pub const last = Self{ .index = len - 1, .x = width - 1, .y = height - 1 };
pub fn ofIndex(index: usize) ?Self {
return if (index >= len) null else .{
.index = index,
.x = @rem(index, width),
.y = @divTrunc(index, width),
};
}
pub fn ofXy(x: usize, y: usize) ?Self {
return if (x >= width or y >= height) null else .{
.index = y * width + x,
.x = x,
.y = y,
};
}
pub fn ofF64(x: f64, y: f64) ?Self {
if (x < 0 or y < 0) {
return null;
} else {
const xi = @floatToInt(usize, math.floor(x * xs));
const yi = @floatToInt(usize, math.floor(y * ys));
return ofXy(xi, yi);
}
}
pub fn cellx(self: Self, x: f64) f64 {
return (x * xs) - @intToFloat(f64, self.x);
}
pub fn celly(self: Self, y: f64) f64 {
return (y * ys) - @intToFloat(f64, self.y);
}
pub fn north(self: Self) ?Self {
return if (self.y == 0) null else .{
.index = self.index - width,
.x = self.x,
.y = self.y - 1,
};
}
pub fn south(self: Self) ?Self {
return if (self.y == height - 1) null else .{
.index = self.index + width,
.x = self.x,
.y = self.y + 1,
};
}
pub fn west(self: Self) ?Self {
return if (self.x == 0) null else .{
.index = self.index - 1,
.x = self.x - 1,
.y = self.y,
};
}
pub fn east(self: Self) ?Self {
return if (self.x == width - 1) null else .{
.index = self.index + 1,
.x = self.x + 1,
.y = self.y,
};
}
pub fn northwest(self: Self) ?Self {
return if (self.north()) |p| p.west() else null;
}
pub fn northeast(self: Self) ?Self {
return if (self.north()) |p| p.east() else null;
}
pub fn southwest(self: Self) ?Self {
return if (self.south()) |p| p.west() else null;
}
pub fn southeast(self: Self) ?Self {
return if (self.south()) |p| p.east() else null;
}
pub fn neighbors4(self: Self) [4]?Self {
return [4]?Self{ self.north(), self.west(), self.east(), self.south() };
}
pub fn neighbors8(self: Self) [8]?Self {
return [8]?Self{ self.northwest(), self.north(), self.northeast(), self.west(), self.east(), self.southwest(), self.south(), self.southeast() };
}
pub fn neighbors9(self: Self) [9]?Self {
return [9]?Self{ self.northwest(), self.north(), self.northeast(), self.west(), self, self.east(), self.southwest(), self.south(), self.southeast() };
}
pub fn next(self: Self) ?Self {
return if (self.index == len - 1) null else if (self.x == width - 1) .{
.index = self.index + 1,
.x = 0,
.y = self.y + 1,
} else .{
.index = self.index + 1,
.x = self.x + 1,
.y = self.y,
};
}
pub fn prev(self: Self) ?Self {
return if (self.index == 0) null else if (self.x == 0) .{
.index = self.index - 1,
.x = self.width - 1,
.y = self.y - 1,
} else .{
.index = self.index - 1,
.x = self.x - 1,
.y = self.y,
};
}
};
};
}
pub fn FloatIndexIterator(comptime width: usize, comptime height: usize) type {
return struct {
const Self = @This();
floatIt: FloatIterator(width, height),
index: usize,
pub fn init() Self {
return Self{
.floatIt = FloatIterator(width, height).init(),
.index = 0,
};
}
pub fn next(self: *Self) ?Cell {
if (self.floatIt.next()) |cell| {
var result = Cell{
.index = self.index,
.x = cell.x,
.y = cell.y,
};
self.index += 1;
return result;
}
return null;
}
pub const Cell = struct {
index: usize,
x: f64,
y: f64,
};
};
}
pub fn FloatIterator(comptime width: usize, comptime height: usize) type {
const wd = 1 / @intToFloat(f64, width);
const hd = 1 / @intToFloat(f64, height);
return struct {
const Self = @This();
intIt: IntIterator(width, height),
yf: f64,
pub fn init() Self {
return Self{
.intIt = IntIterator(width, height).init(),
.yf = 0,
};
}
pub fn next(self: *Self) ?Cell {
if (self.intIt.next()) |cell| {
if (cell.x == 0) {
self.yf = @intToFloat(f64, cell.y) * hd;
}
return Cell{
.x = @intToFloat(f64, cell.x) * wd,
.y = self.yf,
};
} else {
return null;
}
}
pub fn skipRows(self: *Self, rows: usize) void {
self.intIt.skipRows(rows);
}
pub const Cell = struct {
x: f64,
y: f64,
};
};
}
pub fn IntIterator(comptime width: usize, comptime height: usize) type {
return struct {
const Self = @This();
x: usize,
y: usize,
pub fn init() Self {
return Self{
.x = 0,
.y = 0,
};
}
pub fn next(self: *Self) ?Cell {
if (self.y >= height) {
return null;
}
var result = Cell{
.x = self.x,
.y = self.y,
};
self.x += 1;
if (self.x >= width) {
self.x = 0;
self.y += 1;
}
return result;
}
pub fn skipRows(self: *Self, rows: usize) void {
self.y += rows;
}
pub const Cell = struct {
x: usize = 0,
y: usize = 0,
};
};
}
pub fn IntIndexIterator(comptime width: usize, comptime height: usize) type {
return struct {
const Self = @This();
x: usize,
y: usize,
index: usize,
pub fn init() Self {
return Self{
.x = 0,
.y = 0,
.index = 0,
};
}
pub fn next(self: *Self) ?Cell {
if (self.y >= height) {
return null;
}
var result = Cell{
.index = self.index,
.x = self.x,
.y = self.y,
};
self.index += 1;
self.x += 1;
if (self.x >= width) {
self.x = 0;
self.y += 1;
}
return result;
}
pub const Cell = struct {
index: usize,
x: usize,
y: usize,
};
};
} | lib/gridsize.zig |
const std = @import("std");
const alphabet = @import("alphabet.zig");
pub fn KmerInfo(comptime A: type, comptime NumLettersPerKmer: comptime_int) type {
return struct {
pub const NumLettersPerKmer = NumLettersPerKmer;
pub const Alphabet = A;
pub const LetterToBitMapType = @typeInfo(@typeInfo(@TypeOf(A.mapToBits)).Fn.return_type.?).Optional.child; // ?u2 -> u2
pub const NumBitsPerLetter = @bitSizeOf(LetterToBitMapType);
pub const NumBitsPerKmer = (NumLettersPerKmer * NumBitsPerLetter) + 1; // +1 for ambiguous kmer
pub const KmerType = @Type(.{
.Int = .{
.signedness = .unsigned,
.bits = NumBitsPerKmer, // save ambiguous kmer
},
});
pub const MaxKmers = (1 << (NumBitsPerKmer - 1)) + 1;
pub const AmbiguousKmer = (1 << NumBitsPerKmer) - 1;
pub const KmerMask = AmbiguousKmer >> 1;
};
}
pub fn Iterator(comptime kmerInfo: type) type {
return struct {
const Self = @This();
const A = kmerInfo.Alphabet;
pos: usize,
letters: []const u8,
val: kmerInfo.KmerType = 0,
ambiguity_count: usize = 0,
pub fn init(letters: []const u8) Self {
return Self{
.pos = 0,
.letters = letters,
};
}
pub fn num_total(self: *Self) usize {
if (kmerInfo.NumLettersPerKmer > self.letters.len) {
return 0;
} else {
return self.letters.len - kmerInfo.NumLettersPerKmer + 1;
}
}
pub fn next(self: *Self) ?kmerInfo.KmerType {
while (self.pos + 1 < kmerInfo.NumLettersPerKmer and self.consumeNext()) {
// advance up to pos - 1 for the initial kmer
}
if (!self.consumeNext())
return null;
return if (self.ambiguity_count > 0) kmerInfo.AmbiguousKmer else self.val;
}
fn consumeNext(self: *Self) bool {
if (self.pos >= self.letters.len) {
return false;
}
// evaluate current letter
const letterBits = A.mapToBits(self.letters[self.pos]);
if (letterBits == null) {
// the next X kmers are considered to be ambiguous
self.ambiguity_count = kmerInfo.NumLettersPerKmer + 1;
} else {
// map current letter
self.val = ((self.val << @bitSizeOf(kmerInfo.LetterToBitMapType)) | letterBits.?) & kmerInfo.KmerMask;
}
// advance
self.pos += 1;
// in ambiguous region?
if (self.ambiguity_count > 0) {
self.ambiguity_count -= 1;
}
return true;
}
};
}
test "info" {
const a = KmerInfo(alphabet.DNA, 8);
try std.testing.expectEqual(8, a.NumLettersPerKmer);
try std.testing.expectEqual(17, a.NumBitsPerKmer); //2*8+1
try std.testing.expectEqual(u2, a.LetterToBitMapType);
try std.testing.expectEqual(u17, a.KmerType);
try std.testing.expectEqual(65537, a.MaxKmers);
try std.testing.expectEqual(0b1_11_11_11_11_11_11_11_11, a.AmbiguousKmer); // ambiguous flag active
try std.testing.expectEqual(0b0_11_11_11_11_11_11_11_11, a.KmerMask);
}
test "basic test" {
const kmerInfo = KmerInfo(alphabet.DNA, 3);
var it = Iterator(kmerInfo).init("ATCGGG");
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b00_10_01), it.next().?);
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b10_01_11), it.next().?);
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b01_11_11), it.next().?);
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b11_11_11), it.next().?);
try std.testing.expect(it.next() == null);
try std.testing.expectEqual(@as(usize, 4), it.num_total());
}
test "ambiguous nucleotides" {
const kmerInfo = KmerInfo(alphabet.DNA, 3);
var it = Iterator(kmerInfo).init("ATCGNGTTNAAGN");
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b00_10_01), it.next().?); // ATC
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b10_01_11), it.next().?); // TCG
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b1_11_11_11), it.next().?); // CGN ambiguous
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b1_11_11_11), it.next().?); // GNG skipped
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b1_11_11_11), it.next().?); // NGT skipped
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b11_10_10), it.next().?); // GTT
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b1_11_11_11), it.next().?); // TTN skipped
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b1_11_11_11), it.next().?); // TNA skipped
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b1_11_11_11), it.next().?); // NAA skipped
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b00_00_11), it.next().?); // AAG
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b1_11_11_11), it.next().?); // AGN skipped
try std.testing.expect(it.next() == null);
}
test "too short" {
const kmerInfo = KmerInfo(alphabet.DNA, 4);
var it = Iterator(kmerInfo).init("ATT");
try std.testing.expectEqual(@as(usize, 0), it.num_total());
try std.testing.expect(it.next() == null);
}
test "just right" {
const kmerInfo = KmerInfo(alphabet.DNA, 4);
var it = Iterator(kmerInfo).init("ATTG");
try std.testing.expectEqual(@as(usize, 1), it.num_total());
try std.testing.expectEqual(@as(kmerInfo.KmerType, 0b00_10_10_11), it.next().?);
try std.testing.expect(it.next() == null);
} | src/bio/kmer.zig |
const std = @import("std");
const utils = @import("../utils.zig");
pub const CompressionMethod = enum(u16) {
none = 0,
shrunk,
reduced1,
reduced2,
reduced3,
reduced4,
imploded,
deflated = 8,
enhanced_deflated,
dcl_imploded,
bzip2 = 12,
lzma = 14,
ibm_terse = 18,
ibm_lz77_z,
zstd_deprecated,
zstd = 93,
mp3,
xz,
jepg,
wavpack,
ppmd_1_1,
aex_encryption,
pub fn read(self: *CompressionMethod, reader: anytype) !void {
const data = try reader.readIntLittle(u16);
self.* = @intToEnum(CompressionMethod, data);
}
pub fn write(self: CompressionMethod, writer: anytype) !void {
const data = @enumToInt(self);
try writer.writeIntLittle(u16, data);
}
};
pub const Version = struct {
pub const Vendor = enum(u8) {
dos = 0,
amiga,
openvms,
unix,
vm,
atari,
os2_hpfs,
macintosh,
z_system,
cp_m,
ntfs,
mvs,
vse,
acorn,
vfat,
alt_mvs,
beos,
tandem,
os400,
osx,
_,
};
vendor: Vendor,
major: u8,
minor: u8,
pub fn read(self: *Version, reader: anytype) !void {
const data = try reader.readIntLittle(u16);
self.major = @truncate(u8, data) / 10;
self.minor = @truncate(u8, data) % 10;
self.vendor = @intToEnum(Vendor, @truncate(u8, data >> 8));
}
pub fn write(self: Version, writer: anytype) !void {
const version = @as(u16, self.major * 10 + self.minor);
const vendor = @as(u16, @enumToInt(self.vendor)) << 8;
try writer.writeIntLittle(u16, version | vendor);
}
};
pub const GeneralPurposeBitFlag = packed struct {
encrypted: bool,
compression1: u1,
compression2: u1,
data_descriptor: bool,
enhanced_deflation: u1,
compressed_patched: bool,
strong_encryption: bool,
__7_reserved: u1,
__8_reserved: u1,
__9_reserved: u1,
__10_reserved: u1,
is_utf8: bool,
__12_reserved: u1,
mask_headers: bool,
__14_reserved: u1,
__15_reserved: u1,
pub fn read(self: *GeneralPurposeBitFlag, reader: anytype) !void {
const data = try reader.readIntLittle(u16);
self.* = @bitCast(GeneralPurposeBitFlag, data);
}
pub fn write(self: GeneralPurposeBitFlag, writer: anytype) !void {
const data = @bitCast(u16, self);
try writer.writeIntLittle(u16, data);
}
};
pub const InternalAttributes = packed struct {
apparent_text: bool,
__1_reserved: u1,
control_before_logical: bool,
__3_7_reserved: u5,
__8_15_reserved: u8,
pub fn read(self: *InternalAttributes, reader: anytype) !void {
const data = try reader.readIntLittle(u16);
self.* = @bitCast(GeneralPurposeBitFlag, data);
}
pub fn write(self: InternalAttributes, writer: anytype) !void {
const data = @bitCast(u16, self);
try writer.writeIntLittle(u16, data);
}
};
pub const DosTimestamp = struct {
second: u6,
minute: u6,
hour: u5,
day: u5,
month: u4,
year: u12,
pub fn read(self: *DosTimestamp, reader: anytype) !void {
const time = try reader.readIntLittle(u16);
self.second = @as(u6, @truncate(u5, time)) << 1;
self.minute = @truncate(u6, time >> 5);
self.hour = @truncate(u5, time >> 11);
const date = try reader.readIntLittle(u16);
self.day = @truncate(u5, date);
self.month = @truncate(u4, date >> 5);
self.year = @as(u12, @truncate(u7, date >> 9)) + 1980;
}
pub fn write(self: DosTimestamp, writer: anytype) !void {
const second = @as(u16, @truncate(u5, self.second >> 1));
const minute = @as(u16, @truncate(u5, self.minute) << 5);
const hour = @as(u16, @truncate(u5, self.hour) << 11);
try writer.writeIntLittle(u16, second | minute | hour);
const day = self.day;
const month = self.month << 5;
const year = (self.year - 1980) << 11;
try writer.writeIntLittle(u16, day | month | year);
}
};
pub const LocalFileHeader = struct {
pub const Signature = 0x04034b50;
pub const size = 26;
version_needed: Version,
flags: GeneralPurposeBitFlag,
compression: CompressionMethod,
mtime: DosTimestamp,
checksum: u32,
compressed_size: u64,
uncompressed_size: u64,
filename_len: u16,
extrafield_len: u16,
central_header: *const CentralDirectoryHeader,
data_descriptor: ?DataDescriptor,
offset: usize,
const ReadError = error{ MalformedLocalFileHeader, MultidiskUnsupported };
pub fn read(self: *LocalFileHeader, central_header: *const CentralDirectoryHeader, parser: anytype, reader: anytype) !void {
try self.version_needed.read(reader);
try self.flags.read(reader);
try self.compression.read(reader);
try self.mtime.read(reader);
self.checksum = try reader.readIntLittle(u32);
self.compressed_size = try reader.readIntLittle(u32);
self.uncompressed_size = try reader.readIntLittle(u32);
self.filename_len = try reader.readIntLittle(u16);
self.extrafield_len = try reader.readIntLittle(u16);
self.offset = central_header.offset + 30 + self.filename_len + self.extrafield_len;
self.central_header = central_header;
if (self.filename_len != central_header.filename_len) return error.MalformedLocalFileHeader;
try parser.bufferedSeekBy(reader.context, @intCast(i64, self.filename_len));
var is_zip64 = false;
var extra_read: u32 = 0;
const needs_uncompressed_size = self.uncompressed_size == 0xFFFFFFFF;
const needs_compressed_size = self.compressed_size == 0xFFFFFFFF;
const required_zip64_size = (@as(u5, @boolToInt(needs_uncompressed_size)) + @as(u5, @boolToInt(needs_compressed_size))) * 8;
while (extra_read < self.extrafield_len) {
const field_id = try reader.readIntLittle(u16);
const field_size = try reader.readIntLittle(u16);
extra_read += 4;
if (field_id == 0x0001) {
if (field_size < required_zip64_size) return error.MalformedExtraField;
if (needs_uncompressed_size) self.uncompressed_size = try reader.readIntLittle(u64);
if (needs_compressed_size) self.compressed_size = try reader.readIntLittle(u64);
extra_read += required_zip64_size;
try parser.bufferedSeekBy(reader.context, field_size - required_zip64_size);
break;
} else {
try parser.bufferedSeekBy(reader.context, field_size);
extra_read += field_size;
}
}
const left = self.extrafield_len - extra_read;
if (self.flags.data_descriptor) {
try parser.bufferedSeekBy(reader.context, @intCast(i64, left + self.compressed_size));
self.data_descriptor = @as(DataDescriptor, undefined);
try self.data_descriptor.?.read(reader, is_zip64);
}
}
};
pub const DataDescriptor = struct {
pub const Signature = 0x04034b50;
pub const size = 12;
checksum: u64,
compressed_size: u64,
uncompressed_size: u64,
pub fn read(self: *DataDescriptor, reader: anytype, zip64: bool) !void {
const signature = try reader.readIntLittle(u32);
if (signature == DataDescriptor.Signature) {
if (zip64) {
self.checksum = try reader.readIntLittle(u64);
self.compressed_size = try reader.readIntLittle(u64);
self.uncompressed_size = try reader.readIntLittle(u64);
} else {
self.checksum = try reader.readIntLittle(u32);
self.compressed_size = try reader.readIntLittle(u32);
self.uncompressed_size = try reader.readIntLittle(u32);
}
} else {
if (zip64) {
const next_u32 = try reader.readIntLittle(u32);
self.checksum = @as(u64, next_u32) << 32 | signature;
self.compressed_size = try reader.readIntLittle(u64);
self.uncompressed_size = try reader.readIntLittle(u64);
} else {
self.checksum = signature;
self.compressed_size = try reader.readIntLittle(u32);
self.uncompressed_size = try reader.readIntLittle(u32);
}
}
}
};
pub const CentralDirectoryHeader = struct {
pub const Signature = 0x02014b50;
pub const size = 42;
version_made: Version,
version_needed: Version,
flags: GeneralPurposeBitFlag,
compression: CompressionMethod,
mtime: DosTimestamp,
checksum: u32,
compressed_size: u64,
uncompressed_size: u64,
disk_start: u16,
internal_attributes: InternalAttributes,
external_attributes: u32,
offset: u64,
filename_len: u16,
extrafield_len: u16,
file_comment_len: u16,
filename: []const u8,
local_header: LocalFileHeader,
const ReadInitialError = error{MultidiskUnsupported};
pub fn readInitial(self: *CentralDirectoryHeader, parser: anytype, reader: anytype) !void {
try self.version_made.read(reader);
try self.version_needed.read(reader);
try self.flags.read(reader);
try self.compression.read(reader);
try self.mtime.read(reader);
self.checksum = try reader.readIntLittle(u32);
self.compressed_size = try reader.readIntLittle(u32);
self.uncompressed_size = try reader.readIntLittle(u32);
self.filename_len = try reader.readIntLittle(u16);
self.extrafield_len = try reader.readIntLittle(u16);
self.file_comment_len = try reader.readIntLittle(u16);
self.disk_start = try reader.readIntLittle(u16);
try self.internal_attributes.read(reader);
self.external_attributes = try reader.readIntLittle(u32);
self.offset = try reader.readIntLittle(u32);
if (self.disk_start != parser.ecd.disk_number) return error.MultidiskUnsupported;
try parser.bufferedSeekBy(reader.context, @intCast(i64, self.filename_len + self.extrafield_len + self.file_comment_len));
}
const ReadSecondaryError = error{MalformedExtraField};
pub fn readSecondary(self: *CentralDirectoryHeader, parser: anytype, reader: anytype) !void {
try parser.bufferedSeekBy(reader.context, 46);
self.filename = try parser.readFilename(reader, self.filename_len);
const needs_uncompressed_size = self.uncompressed_size == 0xFFFFFFFF;
const needs_compressed_size = self.compressed_size == 0xFFFFFFFF;
const needs_header_offset = self.offset == 0xFFFFFFFF;
const required_zip64_size = (@as(u5, @boolToInt(needs_uncompressed_size)) + @as(u5, @boolToInt(needs_compressed_size)) + @as(u5, @boolToInt(needs_header_offset))) * 8;
const needs_zip64 = needs_uncompressed_size or needs_compressed_size or needs_header_offset;
if (needs_zip64) {
var read: usize = 0;
while (read < self.extrafield_len) {
const field_id = try reader.readIntLittle(u16);
const field_size = try reader.readIntLittle(u16);
read += 4;
if (field_id == 0x0001) {
if (field_size < required_zip64_size) return error.MalformedExtraField;
if (needs_uncompressed_size) self.uncompressed_size = try reader.readIntLittle(u64);
if (needs_compressed_size) self.compressed_size = try reader.readIntLittle(u64);
if (needs_header_offset) self.offset = try reader.readIntLittle(u64);
read += required_zip64_size;
break;
} else {
try parser.bufferedSeekBy(reader.context, field_size);
read += field_size;
}
}
const left = self.extrafield_len - read;
try parser.bufferedSeekBy(reader.context, @intCast(i64, self.file_comment_len + left));
} else {
try parser.bufferedSeekBy(reader.context, @intCast(i64, self.extrafield_len + self.file_comment_len));
}
}
const ReadLocalError = LocalFileHeader.ReadError || error{MalformedLocalFileHeader};
pub fn readLocal(self: *CentralDirectoryHeader, parser: anytype, reader: anytype) !void {
try parser.bufferedSeekTo(reader.context, parser.start_offset + self.offset);
const signature = try reader.readIntLittle(u32);
if (signature != LocalFileHeader.Signature) return error.MalformedLocalFileHeader;
try self.local_header.read(self, parser, reader);
}
};
pub const EndCentralDirectory64Record = struct {
pub const Signature = 0x06064b50;
pub const size = 52;
record_size: u64,
version_made: Version,
version_needed: Version,
disk_number: u32,
disk_start_directory: u32,
disk_directory_entries: u64,
directory_entry_count: u64,
directory_size: u64,
directory_offset: u64,
pub fn parse(self: *EndCentralDirectory64Record, reader: anytype) (@TypeOf(reader).Error || error{EndOfStream})!void {
self.record_size = try reader.readIntLittle(u64);
try self.version_made.read(reader);
try self.version_needed.read(reader);
self.disk_number = try reader.readIntLittle(u32);
self.disk_start_directory = try reader.readIntLittle(u32);
self.disk_directory_entries = try reader.readIntLittle(u64);
self.directory_entry_count = try reader.readIntLittle(u64);
self.directory_size = try reader.readIntLittle(u64);
self.directory_offset = try reader.readIntLittle(u64);
}
};
pub const EndCentralDirectory64Locator = struct {
pub const Signature = 0x07064b50;
pub const size = 16;
directory_disk_number: u32,
directory_offset: u64,
number_of_disks: u32,
pub fn parse(self: *EndCentralDirectory64Locator, reader: anytype) (@TypeOf(reader).Error || error{EndOfStream})!void {
self.directory_disk_number = try reader.readIntLittle(u32);
self.directory_offset = try reader.readIntLittle(u64);
self.number_of_disks = try reader.readIntLittle(u32);
}
};
pub const EndCentralDirectoryRecord = struct {
pub const Signature = 0x06054b50;
pub const size = 18;
disk_number: u16,
disk_start_directory: u16,
disk_directory_entries: u16,
directory_entry_count: u16,
directory_size: u32,
directory_offset: u32,
comment_length: u16,
pub fn parse(self: *EndCentralDirectoryRecord, reader: anytype) (@TypeOf(reader).Error || error{EndOfStream})!void {
self.disk_number = try reader.readIntLittle(u16);
self.disk_start_directory = try reader.readIntLittle(u16);
self.disk_directory_entries = try reader.readIntLittle(u16);
self.directory_entry_count = try reader.readIntLittle(u16);
self.directory_size = try reader.readIntLittle(u32);
self.directory_offset = try reader.readIntLittle(u32);
self.comment_length = try reader.readIntLittle(u16);
}
};
pub fn Parser(comptime Reader: type) type {
const BufferedReader = std.io.BufferedReader(8192, Reader);
// const ReadError = Reader.Error;
const ReaderContext = std.meta.fieldInfo(Reader, .context).field_type;
const isSeekable = @hasDecl(ReaderContext, "seekBy") and @hasDecl(ReaderContext, "seekTo") and @hasDecl(ReaderContext, "getEndPos");
if (!isSeekable) @compileError("Reader must wrap a seekable context");
return struct {
const Self = @This();
allocator: *std.mem.Allocator,
reader: Reader,
is_zip64: bool = false,
ecd: EndCentralDirectoryRecord = undefined,
ecd64: EndCentralDirectory64Record = undefined,
directory: std.ArrayListUnmanaged(CentralDirectoryHeader) = .{},
filename_buffer: std.ArrayListUnmanaged(u8) = .{},
start_offset: u64 = 0,
directory_offset: u64 = 0,
num_entries: u32 = 0,
pub fn init(allocator: *std.mem.Allocator, reader: Reader) Self {
return .{
.allocator = allocator,
.reader = reader,
};
}
pub fn deinit(self: *Self) void {
self.directory.deinit(self.allocator);
self.filename_buffer.deinit(self.allocator);
}
/// Finds and read's the ZIP central directory and local headers.
pub const LoadError = SearchError || ReadDirectoryError;
pub fn load(self: *Self) LoadError!void {
try self.search();
try self.readDirectory();
}
const SearchError = Reader.Error || ReaderContext.SeekError || error{ EndOfStream, FileTooSmall, InvalidZip, InvalidZip64Locator, MultidiskUnsupported, TooManyFiles };
fn search(self: *Self) SearchError!void {
const file_length = try self.reader.context.getEndPos();
const minimum_ecdr_offset: u64 = EndCentralDirectoryRecord.size + 4;
const maximum_ecdr_offset: u64 = EndCentralDirectoryRecord.size + 4 + 0xffff;
if (file_length < minimum_ecdr_offset) return error.FileTooSmall;
// Find the ECDR signature with a broad pass.
var pos = file_length - minimum_ecdr_offset;
var last_pos = if (maximum_ecdr_offset > file_length) file_length else file_length - maximum_ecdr_offset;
var buffer: [4096]u8 = undefined;
find: while (pos > 0) {
try self.reader.context.seekTo(pos);
const read = try self.reader.readAll(&buffer);
if (read == 0) return error.InvalidZip;
var i: usize = 0;
while (i < read - 4) : (i += 1) {
if (std.mem.readIntLittle(u32, buffer[i..][0..4]) == EndCentralDirectoryRecord.Signature) {
pos = pos + i;
try self.reader.context.seekTo(pos + 4);
break :find;
}
}
if (pos < 4096 or pos < last_pos) return error.InvalidZip;
pos -= 4096;
}
try self.ecd.parse(self.reader);
if (pos > EndCentralDirectory64Locator.size + EndCentralDirectory64Record.size + 8) {
const locator_pos = pos - EndCentralDirectory64Locator.size - 4;
try self.reader.context.seekTo(locator_pos);
var locator: EndCentralDirectory64Locator = undefined;
const locator_sig = try self.reader.readIntLittle(u32);
if (locator_sig == EndCentralDirectory64Locator.Signature) {
try locator.parse(self.reader);
if (locator.directory_offset > file_length - EndCentralDirectory64Record.size - 4) return error.InvalidZip64Locator;
try self.reader.context.seekTo(locator.directory_offset);
const ecd64_sig = try self.reader.readIntLittle(u32);
if (ecd64_sig == EndCentralDirectory64Record.Signature) {
try self.ecd64.parse(self.reader);
self.is_zip64 = true;
}
}
}
self.num_entries = self.ecd.directory_entry_count;
self.directory_offset = self.ecd.directory_offset;
var directory_size: u64 = self.ecd.directory_size;
if (self.ecd.disk_number != self.ecd.disk_start_directory) return error.MultidiskUnsupported;
if (self.ecd.disk_directory_entries != self.ecd.directory_entry_count) return error.MultidiskUnsupported;
// Sanity checks
if (self.is_zip64) {
if (self.ecd64.disk_number != self.ecd64.disk_start_directory) return error.MultidiskUnsupported;
if (self.ecd64.disk_directory_entries != self.ecd64.directory_entry_count) return error.MultidiskUnsupported;
if (self.ecd64.directory_entry_count > std.math.maxInt(u32)) return error.TooManyFiles;
self.num_entries = @truncate(u32, self.ecd64.directory_entry_count);
self.directory_offset = self.ecd64.directory_offset;
directory_size = self.ecd64.directory_size;
}
// Gets the start of the actual ZIP.
// This is required because ZIPs can have preambles for self-execution, for example
// so they could actually start anywhere in the file.
self.start_offset = pos - self.ecd.directory_size - self.directory_offset;
}
fn centralHeaderLessThan(_: void, lhs: CentralDirectoryHeader, rhs: CentralDirectoryHeader) bool {
return lhs.offset < rhs.offset;
}
const ReadDirectoryError = std.mem.Allocator.Error || Reader.Error || ReaderContext.SeekError || CentralDirectoryHeader.ReadInitialError || CentralDirectoryHeader.ReadSecondaryError || CentralDirectoryHeader.ReadLocalError || error{ EndOfStream, MalformedCentralDirectoryHeader };
fn readDirectory(self: *Self) ReadDirectoryError!void {
try self.directory.ensureTotalCapacity(self.allocator, self.num_entries);
var index: u32 = 0;
try self.seekTo(self.start_offset + self.directory_offset);
var buffered = BufferedReader{ .unbuffered_reader = self.reader };
const reader = buffered.reader();
var filename_len_total: usize = 0;
while (index < self.num_entries) : (index += 1) {
const sig = try reader.readIntLittle(u32);
if (sig != CentralDirectoryHeader.Signature) return error.MalformedCentralDirectoryHeader;
var hdr = self.directory.addOneAssumeCapacity();
try hdr.readInitial(self, reader);
filename_len_total += hdr.filename_len;
}
try self.filename_buffer.ensureTotalCapacity(self.allocator, filename_len_total);
try self.bufferedSeekTo(reader.context, self.start_offset + self.directory_offset);
for (self.directory.items) |*hdr| {
try hdr.readSecondary(self, reader);
}
std.sort.sort(CentralDirectoryHeader, self.directory.items, {}, centralHeaderLessThan);
for (self.directory.items) |*hdr| {
try hdr.readLocal(self, reader);
}
}
pub fn getFileIndex(self: Self, filename: []const u8) !usize {
for (self.directory.items) |*hdr, i| {
if (std.mem.eql(u8, hdr.filename, filename)) {
return i;
}
}
return error.FileNotFound;
}
pub fn readFileAlloc(self: *Self, allocator: *std.mem.Allocator, index: usize) ![]const u8 {
const header = self.directory.items[index];
try self.seekTo(self.start_offset + header.local_header.offset);
var buffer = try allocator.alloc(u8, header.uncompressed_size);
errdefer allocator.free(buffer);
var read_buffered = BufferedReader{ .unbuffered_reader = self.reader };
var limited_reader = utils.LimitedReader(BufferedReader.Reader).init(read_buffered.reader(), header.compressed_size);
const reader = limited_reader.reader();
var write_stream = std.io.fixedBufferStream(buffer);
const writer = write_stream.writer();
var fifo = std.fifo.LinearFifo(u8, .{ .Static = 8192 }).init();
switch (header.compression) {
.none => {
try fifo.pump(reader, writer);
},
.deflated => {
var window: [0x8000]u8 = undefined;
var stream = std.compress.deflate.inflateStream(reader, &window);
try fifo.pump(stream.reader(), writer);
},
else => return error.CompressionUnsupported,
}
return buffer;
}
pub const ExtractOptions = struct {
skip_components: u16 = 0,
};
pub fn extract(self: *Self, dir: std.fs.Dir, options: ExtractOptions) !usize {
var buffered = BufferedReader{ .unbuffered_reader = self.reader };
const file_reader = buffered.reader();
var written: usize = 0;
extract: for (self.directory.items) |hdr| {
const new_filename = blk: {
var component: usize = 0;
var last_pos: usize = 0;
while (component < options.skip_components) : (component += 1) {
last_pos = std.mem.indexOfPos(u8, hdr.filename, last_pos, "/") orelse continue :extract;
}
if (last_pos + 1 == hdr.filename_len) continue :extract;
break :blk hdr.filename[last_pos + 1 ..];
};
if (std.fs.path.dirnamePosix(new_filename)) |dirname| {
try dir.makePath(dirname);
}
if (new_filename[new_filename.len - 1] == '/') continue;
const fd = try dir.createFile(new_filename, .{});
defer fd.close();
try self.bufferedSeekTo(file_reader.context, self.start_offset + hdr.local_header.offset);
var limited_reader = utils.LimitedReader(BufferedReader.Reader).init(file_reader, hdr.compressed_size);
const reader = limited_reader.reader();
var fifo = std.fifo.LinearFifo(u8, .{ .Static = 8192 }).init();
written += hdr.uncompressed_size;
switch (hdr.compression) {
.none => {
try fifo.pump(reader, fd.writer());
},
.deflated => {
var window: [0x8000]u8 = undefined;
var stream = std.compress.deflate.inflateStream(reader, &window);
try fifo.pump(stream.reader(), fd.writer());
},
else => return error.CompressionUnsupported,
}
}
return written;
}
/// Returns a file tree of this ZIP archive.
/// Useful for plucking specific files out of a ZIP or listing it's contents.
pub fn getFileTree(self: *Self) !FileTree {
var tree = FileTree{};
try tree.entries.ensureTotalCapacity(self.allocator, @intCast(u32, self.directory.items.len));
for (self.directory.items) |*hdr| {
try tree.appendFile(self.allocator, hdr);
}
return tree;
}
fn readFilename(self: *Self, reader: anytype, len: usize) ![]const u8 {
const prev_len = self.filename_buffer.items.len;
self.filename_buffer.items.len += len;
var buf = self.filename_buffer.items[prev_len..][0..len];
_ = try reader.readAll(buf);
return buf;
}
fn seekTo(self: *Self, offset: u64) !void {
try self.reader.context.seekTo(offset);
}
fn seekBy(self: *Self, offset: i64) !void {
try self.reader.context.seekBy(offset);
}
fn bufferedSeekBy(self: *Self, buffered: *BufferedReader, offset: i64) !void {
if (offset == 0) return;
if (offset > 0) {
const u_offset = @intCast(u64, offset);
if (u_offset <= buffered.fifo.count) {
buffered.fifo.discard(u_offset);
} else if (u_offset <= buffered.fifo.count + buffered.fifo.buf.len) {
const left = u_offset - buffered.fifo.count;
buffered.fifo.discard(buffered.fifo.count);
try buffered.reader().skipBytes(left, .{ .buf_size = 8192 });
} else {
const left = u_offset - buffered.fifo.count;
buffered.fifo.discard(buffered.fifo.count);
try self.seekBy(@intCast(i64, left));
}
} else {
const left = offset - @intCast(i64, buffered.fifo.count);
buffered.fifo.discard(buffered.fifo.count);
try self.seekBy(left);
}
}
fn bufferedGetPos(self: *Self, buffered: *BufferedReader) !u64 {
const pos = try self.reader.context.getPos();
return pos - buffered.fifo.count;
}
fn bufferedSeekTo(self: *Self, buffered: *BufferedReader, pos: u64) !void {
const offset = @intCast(i64, pos) - @intCast(i64, try self.bufferedGetPos(buffered));
try self.bufferedSeekBy(buffered, offset);
}
};
}
// High-level constructs
pub const FileTree = struct {
entries: std.StringHashMapUnmanaged(*const CentralDirectoryHeader) = .{},
structure: std.StringHashMapUnmanaged(std.ArrayListUnmanaged(*const CentralDirectoryHeader)) = .{},
pub fn appendFile(self: *FileTree, allocator: *std.mem.Allocator, hdr: *const CentralDirectoryHeader) !void {
// Determines the end of filename. If the filename is a directory, skip the last character as it is an extraenous `/`, else do nothing.
var filename_end_index = hdr.filename.len - if (hdr.filename[hdr.filename.len - 1] == '/') @as(usize, 1) else @as(usize, 0);
var start = if (std.mem.lastIndexOf(u8, hdr.filename[0..filename_end_index], "/")) |ind|
hdr.filename[0..ind]
else
"/";
var gpr = try self.structure.getOrPut(allocator, start);
if (!gpr.found_existing)
gpr.value_ptr.* = std.ArrayListUnmanaged(*const CentralDirectoryHeader){};
try gpr.value_ptr.append(allocator, hdr);
try self.entries.put(allocator, hdr.filename, hdr);
}
pub fn deinit(self: *FileTree, allocator: *std.mem.Allocator) void {
self.entries.deinit(allocator);
var it = self.structure.valueIterator();
while (it.next()) |entry| {
entry.deinit(allocator);
}
self.structure.deinit(allocator);
}
pub fn readDir(self: FileTree, path: []const u8) ?*std.ArrayListUnmanaged(*const CentralDirectoryHeader) {
return if (self.structure.getEntry(path)) |ent| ent.value_ptr else null;
}
pub fn getEntry(self: FileTree, path: []const u8) ?*const CentralDirectoryHeader {
return self.entries.get(path);
}
};
comptime {
std.testing.refAllDecls(@This());
} | src/formats/zip.zig |
const std = @import("std");
const print = std.debug.print;
usingnamespace @import("value.zig");
pub const OpCode = enum(u8) {
OP_CONSTANT,
OP_NIL,
OP_TRUE,
OP_FALSE,
OP_ADD,
OP_SUBTRACT,
OP_MULTIPLY,
OP_DIVIDE,
OP_NOT,
OP_NEGATE,
OP_PRINT,
OP_JUMP,
OP_JUMP_IF_FALSE,
OP_LOOP,
OP_CALL,
OP_CLOSURE,
OP_GET_UPVALUE,
OP_SET_UPVALUE,
OP_CLOSE_UPVALUE,
OP_RETURN,
OP_POP,
OP_GET_LOCAL,
OP_SET_LOCAL,
OP_GET_GLOBAL,
OP_DEFINE_GLOBAL,
OP_SET_GLOBAL,
OP_EQUAL,
OP_GREATER,
OP_LESS,
};
pub const ArrayListOfU8 = std.ArrayList(u8);
pub const ArrayListOfUsize = std.ArrayList(usize);
pub const Chunk = struct {
code: ArrayListOfU8,
constants: ArrayListOfValue,
lines: ArrayListOfUsize,
allocator: *std.mem.Allocator,
pub fn init(allocator: *std.mem.Allocator) !*Chunk {
var chunk = try allocator.create(Chunk);
chunk.code = ArrayListOfU8.init(allocator);
chunk.constants = ArrayListOfValue.init(allocator);
chunk.lines = ArrayListOfUsize.init(allocator);
chunk.allocator = allocator;
return chunk;
}
pub fn deinit(self: *Chunk) void {
self.code.deinit();
self.constants.deinit();
self.lines.deinit();
self.allocator.destroy(self);
}
pub fn writeByte(self: *Chunk, byte: usize, line: usize) !void {
try self.code.append(@intCast(u8, byte));
try self.lines.append(line);
}
pub fn writeOpCode(self: *Chunk, opCode: OpCode, line: usize) !void {
try self.writeByte(@enumToInt(opCode), line);
}
pub fn addConstant(self: *Chunk, value: Value) !usize {
try self.constants.append(value);
return self.constants.items.len - 1;
}
pub fn disassembleChunk(self: *Chunk, name: []const u8) !void {
print("== {} ==\n", .{name});
var offset: usize = 0;
while (offset < self.code.items.len) {
offset = try self.disassembleInstruction(offset);
}
print("== {} ==\n", .{name});
}
pub fn disassembleInstruction(self: *Chunk, offset: usize) !usize {
print("{:0>4} ", .{offset});
if (offset > 0 and self.lines.items[offset] == self.lines.items[offset - 1]) {
print(" | ", .{});
} else {
print("{:4} ", .{self.lines.items[offset]});
}
const instruction = @intToEnum(OpCode, self.code.items[offset]);
return switch (instruction) {
OpCode.OP_RETURN,
OpCode.OP_NEGATE,
OpCode.OP_ADD,
OpCode.OP_SUBTRACT,
OpCode.OP_MULTIPLY,
OpCode.OP_DIVIDE,
OpCode.OP_NIL,
OpCode.OP_TRUE,
OpCode.OP_FALSE,
OpCode.OP_NOT,
OpCode.OP_GREATER,
OpCode.OP_LESS,
OpCode.OP_EQUAL,
OpCode.OP_PRINT,
OpCode.OP_POP,
OpCode.OP_CLOSE_UPVALUE,
=> simpleInstruction(@tagName(instruction), offset),
OpCode.OP_CONSTANT,
OpCode.OP_DEFINE_GLOBAL,
OpCode.OP_GET_GLOBAL,
OpCode.OP_SET_GLOBAL,
=> try self.constantInstruction(@tagName(instruction), offset),
OpCode.OP_GET_LOCAL,
OpCode.OP_SET_LOCAL,
OpCode.OP_CALL,
OpCode.OP_GET_UPVALUE,
OpCode.OP_SET_UPVALUE,
=> self.byteInstruction(@tagName(instruction), offset),
OpCode.OP_JUMP_IF_FALSE, OpCode.OP_JUMP => self.jumInstruction(@tagName(instruction), 1, offset),
OpCode.OP_LOOP => self.jumInstruction(@tagName(instruction), -1, offset),
OpCode.OP_CLOSURE => {
var res = offset + 1;
const constant = self.code.items[res];
res += 1;
print("{s:<16} {:>4} ", .{ @tagName(instruction), constant });
try printValue(self.constants.items[constant]);
print("\n", .{});
const function = asFunction(self.constants.items[constant]);
var j: usize = 0;
while (j < function.upvalueCount) : (j += 1) {
const isLocal = self.code.items[res];
res += 1;
const index = self.code.items[res];
res += 1;
const local: []const u8 = if (isLocal == 1) "local" else "upvalue";
print("{:>4} | {} {}\n", .{ res - 2, local, index });
}
return res;
},
};
}
fn simpleInstruction(name: []const u8, offset: usize) usize {
print("{s:<16}\n", .{name});
return offset + 1;
}
fn constantInstruction(self: *Chunk, name: []const u8, offset: usize) !usize {
const contantIndex = self.code.items[offset + 1];
print("{s:<16} {:>4}(", .{ name, contantIndex });
try printValue(self.constants.items[contantIndex]);
print(")\n", .{});
return offset + 2;
}
fn byteInstruction(self: *Chunk, name: []const u8, offset: usize) usize {
const slot = self.code.items[offset + 1];
print("{s:<16} {:>4}\n", .{ name, slot });
return offset + 2;
}
fn jumInstruction(self: *Chunk, name: []const u8, sign: i32, offset: usize) usize {
var jump = @intCast(u16, self.code.items[offset + 1]) << 8;
jump |= self.code.items[offset + 2];
print("{s:<16} {:>4} -> {}\n", .{ name, offset, @intCast(i32, offset) + 3 + @intCast(i32, sign) * @intCast(i32, jump) });
return offset + 3;
}
};
pub fn printValue(value: Value) anyerror!void {
switch (value) {
.nil => print("nil", .{}),
.boolean => |boolean| print("{}", .{boolean}),
.number => |number| print("{d:.5}", .{number}),
.obj => |obj| {
switch (obj.objType) {
.str => print("'{}'", .{@ptrCast(*ObjString, obj).chars}),
.fun => {
const fun = @ptrCast(*ObjFunction, obj);
if (fun.name) |name| {
print("<fn {}>", .{name.chars});
} else {
print("<script>", .{});
}
},
.closure => {
try printValue(objFunction2Value(@ptrCast(*ObjClosure, obj).fun));
},
.upvalue => print("upvalue", .{}),
}
},
}
} | zvm/src/chunk.zig |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.