├── src ├── translate-c │ ├── input.h │ └── main.zig ├── tetris │ ├── tetris │ │ ├── .gitignore │ │ ├── assets │ │ │ └── font.png │ │ ├── stb_image-2.22 │ │ │ └── stb_image_impl.c │ │ ├── src │ │ │ ├── c.zig │ │ │ ├── debug_gl.zig │ │ │ └── png.zig │ │ ├── LICENSE │ │ ├── README.md │ │ └── build.zig │ ├── main.zig │ └── include │ │ └── epoxy │ │ └── common.h ├── self-hosted-parser │ ├── input_dir │ │ ├── special │ │ │ ├── init-exe │ │ │ │ ├── src │ │ │ │ │ └── main.zig │ │ │ │ └── build.zig │ │ │ ├── init-lib │ │ │ │ ├── src │ │ │ │ │ └── main.zig │ │ │ │ └── build.zig │ │ │ ├── compiler_rt │ │ │ │ ├── fixdfti.zig │ │ │ │ ├── fixsfti.zig │ │ │ │ ├── fixtfdi.zig │ │ │ │ ├── fixtfsi.zig │ │ │ │ ├── fixtfti.zig │ │ │ │ ├── fixunsdfti.zig │ │ │ │ ├── fixunssfti.zig │ │ │ │ ├── fixunstfdi.zig │ │ │ │ ├── fixunstfsi.zig │ │ │ │ ├── fixunstfti.zig │ │ │ │ ├── fixdfdi.zig │ │ │ │ ├── fixdfsi.zig │ │ │ │ ├── fixsfdi.zig │ │ │ │ ├── fixsfsi.zig │ │ │ │ ├── fixunsdfdi.zig │ │ │ │ ├── fixunssfdi.zig │ │ │ │ ├── fixunssfsi.zig │ │ │ │ ├── fixunsdfsi.zig │ │ │ │ ├── udivti3.zig │ │ │ │ ├── umodti3.zig │ │ │ │ ├── udivmodti4.zig │ │ │ │ ├── floatdidf.zig │ │ │ │ ├── floatundidf.zig │ │ │ │ ├── floatunditf.zig │ │ │ │ ├── fixunstfsi_test.zig │ │ │ │ ├── divti3.zig │ │ │ │ ├── floatunsitf.zig │ │ │ │ ├── negXf2.zig │ │ │ │ ├── popcountdi2_test.zig │ │ │ │ ├── divti3_test.zig │ │ │ │ ├── floatunsitf_test.zig │ │ │ │ ├── divsf3_test.zig │ │ │ │ ├── divdf3_test.zig │ │ │ │ ├── popcountdi2.zig │ │ │ │ ├── modti3.zig │ │ │ │ ├── floatditf.zig │ │ │ │ ├── muloti4.zig │ │ │ │ ├── mulodi4.zig │ │ │ │ ├── fixunstfti_test.zig │ │ │ │ ├── floatditf_test.zig │ │ │ │ ├── fixunssfsi_test.zig │ │ │ │ ├── fixunssfdi_test.zig │ │ │ │ ├── floatunditf_test.zig │ │ │ │ ├── modti3_test.zig │ │ │ │ ├── floatunsidf.zig │ │ │ │ ├── fixunsdfsi_test.zig │ │ │ │ ├── fixunsdfdi_test.zig │ │ │ │ ├── floatdisf_test.zig │ │ │ │ ├── fixunssfti_test.zig │ │ │ │ ├── muldi3.zig │ │ │ │ ├── fixunsdfti_test.zig │ │ │ │ ├── fixunstfdi_test.zig │ │ │ │ ├── ashldi3_test.zig │ │ │ │ ├── fixuint.zig │ │ │ │ ├── muldi3_test.zig │ │ │ │ ├── floatunsisf.zig │ │ │ │ ├── multi3.zig │ │ │ │ ├── divtf3_test.zig │ │ │ │ ├── aulldiv.zig │ │ │ │ ├── multi3_test.zig │ │ │ │ ├── aullrem.zig │ │ │ │ ├── floatuntisf.zig │ │ │ │ └── floatuntidf.zig │ │ │ └── c.zig │ │ ├── compress.zig │ │ ├── os │ │ │ ├── uefi │ │ │ │ ├── tables │ │ │ │ │ ├── table_header.zig │ │ │ │ │ └── system_table.zig │ │ │ │ ├── protocols │ │ │ │ │ ├── edid_active_protocol.zig │ │ │ │ │ ├── edid_discovered_protocol.zig │ │ │ │ │ ├── shell_parameters_protocol.zig │ │ │ │ │ ├── simple_file_system_protocol.zig │ │ │ │ │ ├── ip6_service_binding_protocol.zig │ │ │ │ │ ├── udp6_service_binding_protocol.zig │ │ │ │ │ ├── managed_network_service_binding_protocol.zig │ │ │ │ │ ├── simple_text_input_protocol.zig │ │ │ │ │ ├── edid_override_protocol.zig │ │ │ │ │ ├── hii_popup_protocol.zig │ │ │ │ │ ├── loaded_image_protocol.zig │ │ │ │ │ ├── simple_pointer_protocol.zig │ │ │ │ │ ├── absolute_pointer_protocol.zig │ │ │ │ │ ├── ip6_config_protocol.zig │ │ │ │ │ └── hii.zig │ │ │ │ └── tables.zig │ │ │ ├── linux │ │ │ │ ├── bpf │ │ │ │ │ ├── btf_ext.zig │ │ │ │ │ └── kern.zig │ │ │ │ └── ioctl.zig │ │ │ └── windows │ │ │ │ ├── shell32.zig │ │ │ │ ├── ole32.zig │ │ │ │ ├── advapi32.zig │ │ │ │ └── gdi32.zig │ │ ├── c │ │ │ ├── hermit.zig │ │ │ ├── emscripten.zig │ │ │ ├── fuchsia.zig │ │ │ └── minix.zig │ │ ├── crypto │ │ │ ├── pcurves │ │ │ │ └── p256 │ │ │ │ │ └── field.zig │ │ │ ├── test.zig │ │ │ ├── errors.zig │ │ │ └── modes.zig │ │ ├── math │ │ │ ├── inf.zig │ │ │ ├── epsilon.zig │ │ │ ├── complex │ │ │ │ ├── conj.zig │ │ │ │ ├── abs.zig │ │ │ │ ├── arg.zig │ │ │ │ ├── cos.zig │ │ │ │ ├── acosh.zig │ │ │ │ ├── acos.zig │ │ │ │ ├── proj.zig │ │ │ │ ├── sin.zig │ │ │ │ ├── log.zig │ │ │ │ ├── tan.zig │ │ │ │ ├── pow.zig │ │ │ │ ├── asinh.zig │ │ │ │ ├── atanh.zig │ │ │ │ └── asin.zig │ │ │ ├── isnan.zig │ │ │ ├── big.zig │ │ │ ├── nan.zig │ │ │ ├── expo2.zig │ │ │ ├── isnormal.zig │ │ │ ├── signbit.zig │ │ │ └── isfinite.zig │ │ ├── x.zig │ │ ├── Thread │ │ │ └── Semaphore.zig │ │ ├── event.zig │ │ ├── rand │ │ │ └── Gimli.zig │ │ ├── build │ │ │ ├── FmtStep.zig │ │ │ └── CheckFileStep.zig │ │ ├── io │ │ │ ├── seekable_stream.zig │ │ │ ├── counting_writer.zig │ │ │ ├── counting_reader.zig │ │ │ ├── find_byte_writer.zig │ │ │ ├── buffered_writer.zig │ │ │ ├── limited_reader.zig │ │ │ ├── c_writer.zig │ │ │ ├── multi_writer.zig │ │ │ ├── change_detection_stream.zig │ │ │ └── buffered_atomic_file.zig │ │ ├── event │ │ │ ├── locked.zig │ │ │ └── rwlocked.zig │ │ ├── target │ │ │ ├── ve.zig │ │ │ ├── arc.zig │ │ │ └── msp430.zig │ │ ├── hash.zig │ │ ├── hash │ │ │ └── fnv.zig │ │ ├── x │ │ │ └── net │ │ │ │ └── ip.zig │ │ ├── start_windows_tls.zig │ │ └── once.zig │ ├── zigfmt-main.zig │ └── main.zig ├── guid │ ├── comptime-guid-parse.zig │ └── comptime-guid-parse-bench.zig ├── ast-check │ ├── astcheck-os.zig │ ├── astcheck-self.zig │ └── astcheck-sema.zig ├── hello-world │ ├── main-aarch64-linux.zig │ ├── main-x86_64-linux.zig │ ├── hello-x86_64-linux.zig │ └── hello-aarch64-linux.zig ├── build-self-hosted │ └── stage2.zig ├── arena-allocator │ └── main.zig ├── rand │ └── main.zig └── std-hash-map │ └── project-euler-14-main.zig ├── images └── gotta_go_fast.png ├── .gitignore └── LICENSE.md /src/translate-c/input.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /src/tetris/tetris/.gitignore: -------------------------------------------------------------------------------- 1 | zig-cache/ 2 | tetris 3 | -------------------------------------------------------------------------------- /images/gotta_go_fast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziglang/gotta-go-fast/master/images/gotta_go_fast.png -------------------------------------------------------------------------------- /src/tetris/tetris/assets/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziglang/gotta-go-fast/master/src/tetris/tetris/assets/font.png -------------------------------------------------------------------------------- /src/tetris/tetris/stb_image-2.22/stb_image_impl.c: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | #define STBI_ONLY_PNG 3 | #define STBI_NO_STDIO 4 | #include "stb_image.h" 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | zig-cache/ 2 | zig-out/ 3 | stage2/ 4 | zig/ 5 | 6 | hello-aarch64-linux 7 | hello-x86_64-linux 8 | bench 9 | main 10 | 11 | *.csv 12 | *.txt 13 | *.o 14 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/init-exe/src/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub fn main() anyerror!void { 4 | std.log.info("All your codebase are belong to us.", .{}); 5 | } 6 | 7 | test "basic test" { 8 | try std.testing.expectEqual(10, 3 + 7); 9 | } 10 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/init-lib/src/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const testing = std.testing; 3 | 4 | export fn add(a: i32, b: i32) i32 { 5 | return a + b; 6 | } 7 | 8 | test "basic add functionality" { 9 | try testing.expect(add(3, 7) == 10); 10 | } 11 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/compress.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std.zig"); 2 | 3 | pub const deflate = @import("compress/deflate.zig"); 4 | pub const gzip = @import("compress/gzip.zig"); 5 | pub const zlib = @import("compress/zlib.zig"); 6 | 7 | test { 8 | _ = gzip; 9 | _ = zlib; 10 | } 11 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/tables/table_header.zig: -------------------------------------------------------------------------------- 1 | pub const TableHeader = extern struct { 2 | signature: u64, 3 | revision: u32, 4 | 5 | /// The size, in bytes, of the entire table including the TableHeader 6 | header_size: u32, 7 | crc32: u32, 8 | reserved: u32, 9 | }; 10 | -------------------------------------------------------------------------------- /src/tetris/tetris/src/c.zig: -------------------------------------------------------------------------------- 1 | pub usingnamespace @cImport({ 2 | @cInclude("stdio.h"); 3 | @cInclude("math.h"); 4 | @cInclude("time.h"); 5 | @cInclude("epoxy/gl.h"); 6 | @cInclude("GLFW/glfw3.h"); 7 | @cDefine("STBI_ONLY_PNG", ""); 8 | @cDefine("STBI_NO_STDIO", ""); 9 | @cInclude("stb_image.h"); 10 | }); 11 | -------------------------------------------------------------------------------- /src/guid/comptime-guid-parse.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | comptime { 4 | const count = 50; 5 | var guid: [38]u8 = "{00000000-98b5-11cf-bb82-00aa00bdce0b}".*; 6 | 7 | @setEvalBranchQuota(count * 2000); 8 | var i: usize = 0; 9 | while (i < count) : (i += 1) { 10 | _ = std.os.windows.GUID.parse(&guid); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixdfti.zig: -------------------------------------------------------------------------------- 1 | const fixint = @import("fixint.zig").fixint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixdfti(a: f64) callconv(.C) i128 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixint(f64, i128, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixdfti_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixsfti.zig: -------------------------------------------------------------------------------- 1 | const fixint = @import("fixint.zig").fixint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixsfti(a: f32) callconv(.C) i128 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixint(f32, i128, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixsfti_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixtfdi.zig: -------------------------------------------------------------------------------- 1 | const fixint = @import("fixint.zig").fixint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixtfdi(a: f128) callconv(.C) i64 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixint(f128, i64, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixtfdi_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixtfsi.zig: -------------------------------------------------------------------------------- 1 | const fixint = @import("fixint.zig").fixint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixtfsi(a: f128) callconv(.C) i32 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixint(f128, i32, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixtfsi_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixtfti.zig: -------------------------------------------------------------------------------- 1 | const fixint = @import("fixint.zig").fixint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixtfti(a: f128) callconv(.C) i128 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixint(f128, i128, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixtfti_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunsdfti.zig: -------------------------------------------------------------------------------- 1 | const fixuint = @import("fixuint.zig").fixuint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixunsdfti(a: f64) callconv(.C) u128 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixuint(f64, u128, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixunsdfti_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunssfti.zig: -------------------------------------------------------------------------------- 1 | const fixuint = @import("fixuint.zig").fixuint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixunssfti(a: f32) callconv(.C) u128 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixuint(f32, u128, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixunssfti_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunstfdi.zig: -------------------------------------------------------------------------------- 1 | const fixuint = @import("fixuint.zig").fixuint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixunstfdi(a: f128) callconv(.C) u64 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixuint(f128, u64, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixunstfdi_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunstfsi.zig: -------------------------------------------------------------------------------- 1 | const fixuint = @import("fixuint.zig").fixuint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixunstfsi(a: f128) callconv(.C) u32 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixuint(f128, u32, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixunstfsi_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunstfti.zig: -------------------------------------------------------------------------------- 1 | const fixuint = @import("fixuint.zig").fixuint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixunstfti(a: f128) callconv(.C) u128 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixuint(f128, u128, a); 7 | } 8 | 9 | test { 10 | _ = @import("fixunstfti_test.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/c/hermit.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const maxInt = std.math.maxInt; 3 | 4 | pub const pthread_mutex_t = extern struct { 5 | inner: usize = ~@as(usize, 0), 6 | }; 7 | pub const pthread_cond_t = extern struct { 8 | inner: usize = ~@as(usize, 0), 9 | }; 10 | pub const pthread_rwlock_t = extern struct { 11 | ptr: usize = maxInt(usize), 12 | }; 13 | -------------------------------------------------------------------------------- /src/ast-check/astcheck-os.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, options: *bench.Options) ![]const u8 { 5 | options.useChildProcess(); 6 | return options.zig_exe; 7 | } 8 | 9 | pub fn run(gpa: std.mem.Allocator, zig_exe: []const u8) !void { 10 | return bench.exec(gpa, &.{ zig_exe, "ast-check", "src/ast-check/os.zig" }, .{}); 11 | } 12 | -------------------------------------------------------------------------------- /src/ast-check/astcheck-self.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, options: *bench.Options) ![]const u8 { 5 | options.useChildProcess(); 6 | return options.zig_exe; 7 | } 8 | 9 | pub fn run(gpa: std.mem.Allocator, zig_exe: []const u8) !void { 10 | return bench.exec(gpa, &.{ zig_exe, "ast-check", "src/ast-check/AstGen.zig" }, .{}); 11 | } 12 | -------------------------------------------------------------------------------- /src/ast-check/astcheck-sema.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, options: *bench.Options) ![]const u8 { 5 | options.useChildProcess(); 6 | return options.zig_exe; 7 | } 8 | 9 | pub fn run(gpa: std.mem.Allocator, zig_exe: []const u8) !void { 10 | return bench.exec(gpa, &.{ zig_exe, "ast-check", "src/ast-check/Sema.zig" }, .{}); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/zigfmt-main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, options: *bench.Options) ![]const u8 { 5 | options.useChildProcess(); 6 | return options.zig_exe; 7 | } 8 | 9 | pub fn run(gpa: std.mem.Allocator, zig_exe: []const u8) !void { 10 | return bench.exec(gpa, &.{ zig_exe, "fmt", "src/self-hosted-parser/input_dir" }, .{}); 11 | } 12 | -------------------------------------------------------------------------------- /src/guid/comptime-guid-parse-bench.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, options: *bench.Options) ![]const u8 { 5 | options.useChildProcess(); 6 | return options.zig_exe; 7 | } 8 | 9 | pub fn run(gpa: std.mem.Allocator, zig_exe: []const u8) !void { 10 | return bench.exec(gpa, &.{ zig_exe, "build-obj", "src/guid/comptime-guid-parse.zig" }, .{}); 11 | } 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/crypto/pcurves/p256/field.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const common = @import("../common.zig"); 3 | 4 | const Field = common.Field; 5 | 6 | pub const Fe = Field(.{ 7 | .fiat = @import("p256_64.zig"), 8 | .field_order = 115792089210356248762697446949407573530086143415290314195533631308867097853951, 9 | .field_bits = 256, 10 | .saturated_bits = 255, 11 | .encoded_length = 32, 12 | }); 13 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/inf.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const math = std.math; 3 | 4 | /// Returns value inf for the type T. 5 | pub fn inf(comptime T: type) T { 6 | return switch (T) { 7 | f16 => math.inf_f16, 8 | f32 => math.inf_f32, 9 | f64 => math.inf_f64, 10 | f128 => math.inf_f128, 11 | else => @compileError("inf not implemented for " ++ @typeName(T)), 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /src/translate-c/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, options: *bench.Options) ![]const u8 { 5 | options.useChildProcess(); 6 | return options.zig_exe; 7 | } 8 | 9 | pub fn run(gpa: std.mem.Allocator, zig_exe: []const u8) !void { 10 | return bench.exec(gpa, &.{ 11 | zig_exe, "translate-c", "src/translate-c/input.h", "-target", "x86_64-windows-gnu", "-lc", 12 | }, .{ .stdout_behavior = .Ignore }); 13 | } 14 | -------------------------------------------------------------------------------- /src/tetris/tetris/src/debug_gl.zig: -------------------------------------------------------------------------------- 1 | const c = @import("c.zig"); 2 | const std = @import("std"); 3 | const os = std.os; 4 | const builtin = @import("builtin"); 5 | 6 | pub const is_on = if (builtin.mode == .ReleaseFast) c.GL_FALSE else c.GL_TRUE; 7 | 8 | pub fn assertNoError() void { 9 | if (builtin.mode != .ReleaseFast) { 10 | const err = c.glGetError(); 11 | if (err != c.GL_NO_ERROR) { 12 | _ = c.printf("GL error: %s\n", err); 13 | c.abort(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixdfdi.zig: -------------------------------------------------------------------------------- 1 | const fixint = @import("fixint.zig").fixint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixdfdi(a: f64) callconv(.C) i64 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixint(f64, i64, a); 7 | } 8 | 9 | pub fn __aeabi_d2lz(arg: f64) callconv(.AAPCS) i64 { 10 | @setRuntimeSafety(false); 11 | return @call(.{ .modifier = .always_inline }, __fixdfdi, .{arg}); 12 | } 13 | 14 | test { 15 | _ = @import("fixdfdi_test.zig"); 16 | } 17 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixdfsi.zig: -------------------------------------------------------------------------------- 1 | const fixint = @import("fixint.zig").fixint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixdfsi(a: f64) callconv(.C) i32 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixint(f64, i32, a); 7 | } 8 | 9 | pub fn __aeabi_d2iz(a: f64) callconv(.AAPCS) i32 { 10 | @setRuntimeSafety(false); 11 | return @call(.{ .modifier = .always_inline }, __fixdfsi, .{a}); 12 | } 13 | 14 | test { 15 | _ = @import("fixdfsi_test.zig"); 16 | } 17 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixsfdi.zig: -------------------------------------------------------------------------------- 1 | const fixint = @import("fixint.zig").fixint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixsfdi(a: f32) callconv(.C) i64 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixint(f32, i64, a); 7 | } 8 | 9 | pub fn __aeabi_f2lz(arg: f32) callconv(.AAPCS) i64 { 10 | @setRuntimeSafety(false); 11 | return @call(.{ .modifier = .always_inline }, __fixsfdi, .{arg}); 12 | } 13 | 14 | test { 15 | _ = @import("fixsfdi_test.zig"); 16 | } 17 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixsfsi.zig: -------------------------------------------------------------------------------- 1 | const fixint = @import("fixint.zig").fixint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixsfsi(a: f32) callconv(.C) i32 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixint(f32, i32, a); 7 | } 8 | 9 | pub fn __aeabi_f2iz(a: f32) callconv(.AAPCS) i32 { 10 | @setRuntimeSafety(false); 11 | return @call(.{ .modifier = .always_inline }, __fixsfsi, .{a}); 12 | } 13 | 14 | test { 15 | _ = @import("fixsfsi_test.zig"); 16 | } 17 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/c/emscripten.zig: -------------------------------------------------------------------------------- 1 | pub const pthread_mutex_t = extern struct { 2 | size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(4) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T, 3 | }; 4 | pub const pthread_cond_t = extern struct { 5 | size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T, 6 | }; 7 | pub const pthread_rwlock_t = extern struct { 8 | size: [32]u8 align(4) = [_]u8{0} ** 32, 9 | }; 10 | const __SIZEOF_PTHREAD_COND_T = 48; 11 | const __SIZEOF_PTHREAD_MUTEX_T = 28; 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunsdfdi.zig: -------------------------------------------------------------------------------- 1 | const fixuint = @import("fixuint.zig").fixuint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixunsdfdi(a: f64) callconv(.C) u64 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixuint(f64, u64, a); 7 | } 8 | 9 | pub fn __aeabi_d2ulz(a: f64) callconv(.AAPCS) u64 { 10 | @setRuntimeSafety(false); 11 | return @call(.{ .modifier = .always_inline }, __fixunsdfdi, .{a}); 12 | } 13 | 14 | test { 15 | _ = @import("fixunsdfdi_test.zig"); 16 | } 17 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunssfdi.zig: -------------------------------------------------------------------------------- 1 | const fixuint = @import("fixuint.zig").fixuint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixunssfdi(a: f32) callconv(.C) u64 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixuint(f32, u64, a); 7 | } 8 | 9 | pub fn __aeabi_f2ulz(a: f32) callconv(.AAPCS) u64 { 10 | @setRuntimeSafety(false); 11 | return @call(.{ .modifier = .always_inline }, __fixunssfdi, .{a}); 12 | } 13 | 14 | test { 15 | _ = @import("fixunssfdi_test.zig"); 16 | } 17 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunssfsi.zig: -------------------------------------------------------------------------------- 1 | const fixuint = @import("fixuint.zig").fixuint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixunssfsi(a: f32) callconv(.C) u32 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixuint(f32, u32, a); 7 | } 8 | 9 | pub fn __aeabi_f2uiz(a: f32) callconv(.AAPCS) u32 { 10 | @setRuntimeSafety(false); 11 | return @call(.{ .modifier = .always_inline }, __fixunssfsi, .{a}); 12 | } 13 | 14 | test { 15 | _ = @import("fixunssfsi_test.zig"); 16 | } 17 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/x.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std.zig"); 2 | 3 | pub const os = struct { 4 | pub const Socket = @import("x/os/socket.zig").Socket; 5 | pub usingnamespace @import("x/os/io.zig"); 6 | pub usingnamespace @import("x/os/net.zig"); 7 | }; 8 | 9 | pub const net = struct { 10 | pub const ip = @import("x/net/ip.zig"); 11 | pub const tcp = @import("x/net/tcp.zig"); 12 | }; 13 | 14 | test { 15 | inline for (.{ os, net }) |module| { 16 | std.testing.refAllDecls(module); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunsdfsi.zig: -------------------------------------------------------------------------------- 1 | const fixuint = @import("fixuint.zig").fixuint; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __fixunsdfsi(a: f64) callconv(.C) u32 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return fixuint(f64, u32, a); 7 | } 8 | 9 | pub fn __aeabi_d2uiz(arg: f64) callconv(.AAPCS) u32 { 10 | @setRuntimeSafety(false); 11 | return @call(.{ .modifier = .always_inline }, __fixunsdfsi, .{arg}); 12 | } 13 | 14 | test { 15 | _ = @import("fixunsdfsi_test.zig"); 16 | } 17 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/linux/bpf/btf_ext.zig: -------------------------------------------------------------------------------- 1 | pub const Header = packed struct { 2 | magic: u16, 3 | version: u8, 4 | flags: u8, 5 | hdr_len: u32, 6 | 7 | /// All offsets are in bytes relative to the end of this header 8 | func_info_off: u32, 9 | func_info_len: u32, 10 | line_info_off: u32, 11 | line_info_len: u32, 12 | }; 13 | 14 | pub const InfoSec = packed struct { 15 | sec_name_off: u32, 16 | num_info: u32, 17 | // TODO: communicate that there is data here 18 | //data: [0]u8, 19 | }; 20 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/c/fuchsia.zig: -------------------------------------------------------------------------------- 1 | pub const pthread_mutex_t = extern struct { 2 | size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T, 3 | }; 4 | pub const pthread_cond_t = extern struct { 5 | size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T, 6 | }; 7 | pub const pthread_rwlock_t = extern struct { 8 | size: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56, 9 | }; 10 | const __SIZEOF_PTHREAD_COND_T = 48; 11 | const __SIZEOF_PTHREAD_MUTEX_T = 40; 12 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/windows/shell32.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const windows = std.os.windows; 3 | const WINAPI = windows.WINAPI; 4 | const KNOWNFOLDERID = windows.KNOWNFOLDERID; 5 | const DWORD = windows.DWORD; 6 | const HANDLE = windows.HANDLE; 7 | const WCHAR = windows.WCHAR; 8 | const HRESULT = windows.HRESULT; 9 | 10 | pub extern "shell32" fn SHGetKnownFolderPath( 11 | rfid: *const KNOWNFOLDERID, 12 | dwFlags: DWORD, 13 | hToken: ?HANDLE, 14 | ppszPath: *[*:0]WCHAR, 15 | ) callconv(WINAPI) HRESULT; 16 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/epsilon.zig: -------------------------------------------------------------------------------- 1 | const math = @import("../math.zig"); 2 | 3 | /// Returns the machine epsilon for type T. 4 | /// This is the smallest value of type T that satisfies the inequality 1.0 + 5 | /// epsilon != 1.0. 6 | pub fn epsilon(comptime T: type) T { 7 | return switch (T) { 8 | f16 => math.f16_epsilon, 9 | f32 => math.f32_epsilon, 10 | f64 => math.f64_epsilon, 11 | f128 => math.f128_epsilon, 12 | else => @compileError("epsilon not implemented for " ++ @typeName(T)), 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/udivti3.zig: -------------------------------------------------------------------------------- 1 | const udivmodti4 = @import("udivmodti4.zig"); 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 { 5 | @setRuntimeSafety(builtin.is_test); 6 | return udivmodti4.__udivmodti4(a, b, null); 7 | } 8 | 9 | const v128 = @import("std").meta.Vector(2, u64); 10 | pub fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 { 11 | @setRuntimeSafety(builtin.is_test); 12 | return udivmodti4.__udivmodti4_windows_x86_64(a, b, null); 13 | } 14 | -------------------------------------------------------------------------------- /src/hello-world/main-aarch64-linux.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, options: *bench.Options) ![]const u8 { 5 | options.useChildProcess(); 6 | return options.zig_exe; 7 | } 8 | 9 | pub fn run(gpa: std.mem.Allocator, zig_exe: []const u8) !void { 10 | return bench.exec(gpa, &.{ 11 | zig_exe, "build-exe", 12 | "-target", "aarch64-linux", 13 | "src/hello-world/hello-aarch64-linux.zig", 14 | }, .{}); 15 | } 16 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/conj.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the complex conjugate of z. 8 | pub fn conj(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | return Complex(T).init(z.re, -z.im); 11 | } 12 | 13 | test "complex.conj" { 14 | const a = Complex(f32).init(5, 3); 15 | const c = a.conjugate(); 16 | 17 | try testing.expect(c.re == 5 and c.im == -3); 18 | } 19 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/windows/ole32.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const windows = std.os.windows; 3 | const WINAPI = windows.WINAPI; 4 | const LPVOID = windows.LPVOID; 5 | const DWORD = windows.DWORD; 6 | const HRESULT = windows.HRESULT; 7 | 8 | pub extern "ole32" fn CoTaskMemFree(pv: LPVOID) callconv(WINAPI) void; 9 | pub extern "ole32" fn CoUninitialize() callconv(WINAPI) void; 10 | pub extern "ole32" fn CoGetCurrentProcess() callconv(WINAPI) DWORD; 11 | pub extern "ole32" fn CoInitializeEx(pvReserved: ?LPVOID, dwCoInit: DWORD) callconv(WINAPI) HRESULT; 12 | -------------------------------------------------------------------------------- /src/hello-world/main-x86_64-linux.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, options: *bench.Options) ![]const u8 { 5 | options.useChildProcess(); 6 | return options.zig_exe; 7 | } 8 | 9 | pub fn run(gpa: std.mem.Allocator, zig_exe: []const u8) !void { 10 | return bench.exec(gpa, &.{ 11 | zig_exe, "build-exe", 12 | "-target", "x86_64-linux", 13 | "src/hello-world/hello-x86_64-linux.zig", 14 | }, .{}); 15 | } 16 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/abs.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the absolute value (modulus) of z. 8 | pub fn abs(z: anytype) @TypeOf(z.re) { 9 | const T = @TypeOf(z.re); 10 | return math.hypot(T, z.re, z.im); 11 | } 12 | 13 | const epsilon = 0.0001; 14 | 15 | test "complex.cabs" { 16 | const a = Complex(f32).init(5, 3); 17 | const c = abs(a); 18 | try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); 19 | } 20 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/arg.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the angular component (in radians) of z. 8 | pub fn arg(z: anytype) @TypeOf(z.re) { 9 | const T = @TypeOf(z.re); 10 | return math.atan2(T, z.im, z.re); 11 | } 12 | 13 | const epsilon = 0.0001; 14 | 15 | test "complex.carg" { 16 | const a = Complex(f32).init(5, 3); 17 | const c = arg(a); 18 | try testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon)); 19 | } 20 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/edid_active_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Guid = uefi.Guid; 3 | 4 | /// EDID information for an active video output device 5 | pub const EdidActiveProtocol = extern struct { 6 | size_of_edid: u32, 7 | edid: ?[*]u8, 8 | 9 | pub const guid align(8) = Guid{ 10 | .time_low = 0xbd8c1056, 11 | .time_mid = 0x9f36, 12 | .time_high_and_version = 0x44ec, 13 | .clock_seq_high_and_reserved = 0x92, 14 | .clock_seq_low = 0xa8, 15 | .node = [_]u8{ 0xa6, 0x33, 0x7f, 0x81, 0x79, 0x86 }, 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/edid_discovered_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Guid = uefi.Guid; 3 | 4 | /// EDID information for a video output device 5 | pub const EdidDiscoveredProtocol = extern struct { 6 | size_of_edid: u32, 7 | edid: ?[*]u8, 8 | 9 | pub const guid align(8) = Guid{ 10 | .time_low = 0x1c0c34f6, 11 | .time_mid = 0xd380, 12 | .time_high_and_version = 0x41fa, 13 | .clock_seq_high_and_reserved = 0xa0, 14 | .clock_seq_low = 0x49, 15 | .node = [_]u8{ 0x8a, 0xd0, 0x6c, 0x1a, 0x66, 0xaa }, 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/init-lib/build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub fn build(b: *std.build.Builder) void { 4 | // Standard release options allow the person running `zig build` to select 5 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. 6 | const mode = b.standardReleaseOptions(); 7 | 8 | const lib = b.addStaticLibrary("$", "src/main.zig"); 9 | lib.setBuildMode(mode); 10 | lib.install(); 11 | 12 | const main_tests = b.addTest("src/main.zig"); 13 | main_tests.setBuildMode(mode); 14 | 15 | const test_step = b.step("test", "Run library tests"); 16 | test_step.dependOn(&main_tests.step); 17 | } 18 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/shell_parameters_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Guid = uefi.Guid; 3 | const FileHandle = uefi.FileHandle; 4 | 5 | pub const ShellParametersProtocol = extern struct { 6 | argv: [*][*:0]const u16, 7 | argc: usize, 8 | stdin: FileHandle, 9 | stdout: FileHandle, 10 | stderr: FileHandle, 11 | 12 | pub const guid align(8) = Guid{ 13 | .time_low = 0x752f3136, 14 | .time_mid = 0x4e16, 15 | .time_high_and_version = 0x4fdc, 16 | .clock_seq_high_and_reserved = 0xa2, 17 | .clock_seq_low = 0x2a, 18 | .node = [_]u8{ 0xe5, 0xf4, 0x68, 0x12, 0xf4, 0xca }, 19 | }; 20 | }; 21 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/cos.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the cosine of z. 8 | pub fn cos(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | const p = Complex(T).init(-z.im, z.re); 11 | return cmath.cosh(p); 12 | } 13 | 14 | const epsilon = 0.0001; 15 | 16 | test "complex.ccos" { 17 | const a = Complex(f32).init(5, 3); 18 | const c = cos(a); 19 | 20 | try testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon)); 21 | try testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon)); 22 | } 23 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/umodti3.zig: -------------------------------------------------------------------------------- 1 | const udivmodti4 = @import("udivmodti4.zig"); 2 | const builtin = @import("builtin"); 3 | const compiler_rt = @import("../compiler_rt.zig"); 4 | 5 | pub fn __umodti3(a: u128, b: u128) callconv(.C) u128 { 6 | @setRuntimeSafety(builtin.is_test); 7 | var r: u128 = undefined; 8 | _ = udivmodti4.__udivmodti4(a, b, &r); 9 | return r; 10 | } 11 | 12 | const v128 = @import("std").meta.Vector(2, u64); 13 | pub fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 { 14 | return @as(v128, @bitCast(@call(.{ .modifier = .always_inline }, __umodti3, .{ 15 | @as(u128, @bitCast(a)), 16 | @as(u128, @bitCast(b)), 17 | }))); 18 | } 19 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/acosh.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the hyperbolic arc-cosine of z. 8 | pub fn acosh(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | const q = cmath.acos(z); 11 | return Complex(T).init(-q.im, q.re); 12 | } 13 | 14 | const epsilon = 0.0001; 15 | 16 | test "complex.cacosh" { 17 | const a = Complex(f32).init(5, 3); 18 | const c = acosh(a); 19 | 20 | try testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon)); 21 | try testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon)); 22 | } 23 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/acos.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the arc-cosine of z. 8 | pub fn acos(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | const q = cmath.asin(z); 11 | return Complex(T).init(@as(T, math.pi) / 2 - q.re, -q.im); 12 | } 13 | 14 | const epsilon = 0.0001; 15 | 16 | test "complex.cacos" { 17 | const a = Complex(f32).init(5, 3); 18 | const c = acos(a); 19 | 20 | try testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon)); 21 | try testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon)); 22 | } 23 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/proj.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the projection of z onto the riemann sphere. 8 | pub fn proj(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | 11 | if (math.isInf(z.re) or math.isInf(z.im)) { 12 | return Complex(T).init(math.inf(T), math.copysign(T, 0, z.re)); 13 | } 14 | 15 | return Complex(T).init(z.re, z.im); 16 | } 17 | 18 | const epsilon = 0.0001; 19 | 20 | test "complex.cproj" { 21 | const a = Complex(f32).init(5, 3); 22 | const c = proj(a); 23 | 24 | try testing.expect(c.re == 5 and c.im == 3); 25 | } 26 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/sin.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the sine of z. 8 | pub fn sin(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | const p = Complex(T).init(-z.im, z.re); 11 | const q = cmath.sinh(p); 12 | return Complex(T).init(q.im, -q.re); 13 | } 14 | 15 | const epsilon = 0.0001; 16 | 17 | test "complex.csin" { 18 | const a = Complex(f32).init(5, 3); 19 | const c = sin(a); 20 | 21 | try testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon)); 22 | try testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon)); 23 | } 24 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/udivmodti4.zig: -------------------------------------------------------------------------------- 1 | const udivmod = @import("udivmod.zig").udivmod; 2 | const builtin = @import("builtin"); 3 | const compiler_rt = @import("../compiler_rt.zig"); 4 | 5 | pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 { 6 | @setRuntimeSafety(builtin.is_test); 7 | return udivmod(u128, a, b, maybe_rem); 8 | } 9 | 10 | const v128 = @import("std").meta.Vector(2, u64); 11 | pub fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 { 12 | @setRuntimeSafety(builtin.is_test); 13 | return @as(v128, @bitCast(udivmod(u128, @as(u128, @bitCast(a)), @as(u128, @bitCast(b)), maybe_rem))); 14 | } 15 | 16 | test { 17 | _ = @import("udivmodti4_test.zig"); 18 | } 19 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/log.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the natural logarithm of z. 8 | pub fn log(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | const r = cmath.abs(z); 11 | const phi = cmath.arg(z); 12 | 13 | return Complex(T).init(math.ln(r), phi); 14 | } 15 | 16 | const epsilon = 0.0001; 17 | 18 | test "complex.clog" { 19 | const a = Complex(f32).init(5, 3); 20 | const c = log(a); 21 | 22 | try testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon)); 23 | try testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon)); 24 | } 25 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/tan.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the tanget of z. 8 | pub fn tan(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | const q = Complex(T).init(-z.im, z.re); 11 | const r = cmath.tanh(q); 12 | return Complex(T).init(r.im, -r.re); 13 | } 14 | 15 | const epsilon = 0.0001; 16 | 17 | test "complex.ctan" { 18 | const a = Complex(f32).init(5, 3); 19 | const c = tan(a); 20 | 21 | try testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon)); 22 | try testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon)); 23 | } 24 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/pow.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns z raised to the complex power of c. 8 | pub fn pow(comptime T: type, z: T, c: T) T { 9 | const p = cmath.log(z); 10 | const q = c.mul(p); 11 | return cmath.exp(q); 12 | } 13 | 14 | const epsilon = 0.0001; 15 | 16 | test "complex.cpow" { 17 | const a = Complex(f32).init(5, 3); 18 | const b = Complex(f32).init(2.3, -1.3); 19 | const c = pow(Complex(f32), a, b); 20 | 21 | try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon)); 22 | try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon)); 23 | } 24 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/asinh.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the hyperbolic arc-sine of z. 8 | pub fn asinh(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | const q = Complex(T).init(-z.im, z.re); 11 | const r = cmath.asin(q); 12 | return Complex(T).init(r.im, -r.re); 13 | } 14 | 15 | const epsilon = 0.0001; 16 | 17 | test "complex.casinh" { 18 | const a = Complex(f32).init(5, 3); 19 | const c = asinh(a); 20 | 21 | try testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon)); 22 | try testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon)); 23 | } 24 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/atanh.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | /// Returns the hyperbolic arc-tangent of z. 8 | pub fn atanh(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | const q = Complex(T).init(-z.im, z.re); 11 | const r = cmath.atan(q); 12 | return Complex(T).init(r.im, -r.re); 13 | } 14 | 15 | const epsilon = 0.0001; 16 | 17 | test "complex.catanh" { 18 | const a = Complex(f32).init(5, 3); 19 | const c = atanh(a); 20 | 21 | try testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon)); 22 | try testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon)); 23 | } 24 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatdidf.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const std = @import("std"); 3 | 4 | const twop52: f64 = 0x1.0p52; 5 | const twop32: f64 = 0x1.0p32; 6 | 7 | pub fn __floatdidf(a: i64) callconv(.C) f64 { 8 | @setRuntimeSafety(builtin.is_test); 9 | 10 | if (a == 0) return 0; 11 | 12 | var low = @as(i64, @bitCast(twop52)); 13 | const high = @as(f64, @floatFromInt(@as(i32, @truncate(a >> 32)))) * twop32; 14 | 15 | low |= @as(i64, @bitCast(a & 0xFFFFFFFF)); 16 | 17 | return (high - twop52) + @as(f64, @bitCast(low)); 18 | } 19 | 20 | pub fn __aeabi_l2d(arg: i64) callconv(.AAPCS) f64 { 21 | @setRuntimeSafety(false); 22 | return @call(.{ .modifier = .always_inline }, __floatdidf, .{arg}); 23 | } 24 | 25 | test { 26 | _ = @import("floatdidf_test.zig"); 27 | } 28 | -------------------------------------------------------------------------------- /src/tetris/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, options: *bench.Options) ![]const u8 { 5 | options.useChildProcess(); 6 | return options.zig_exe; 7 | } 8 | 9 | pub fn run(gpa: std.mem.Allocator, zig_exe: []const u8) !void { 10 | return bench.exec(gpa, &.{ 11 | zig_exe, 12 | "build-exe", 13 | "src/tetris/tetris/src/main.zig", 14 | "-fllvm", 15 | "-OReleaseFast", 16 | "-fno-lto", 17 | "-lc", 18 | "-Istb_image-2.22", 19 | "--main-pkg-path", 20 | "src/tetris", 21 | "-I", 22 | "src/tetris/include", 23 | "-I", 24 | "src/tetris/tetris/stb_image-2.22", 25 | "src/tetris/tetris/stb_image-2.22/stb_image_impl.c", 26 | "src/tetris/glfw-and-epoxy-stubs.s", 27 | }, .{}); 28 | } 29 | -------------------------------------------------------------------------------- /src/build-self-hosted/stage2.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | const OUTPUT_DIR = "stage2"; 5 | 6 | const Context = struct { 7 | zig_exe: []const u8, 8 | build_file_path: []const u8, 9 | }; 10 | 11 | pub fn setup(gpa: std.mem.Allocator, options: *bench.Options) !Context { 12 | options.useChildProcess(); 13 | 14 | try std.fs.cwd().deleteTree(OUTPUT_DIR); 15 | 16 | return Context{ 17 | .zig_exe = options.zig_exe, 18 | .build_file_path = try std.fs.path.join(gpa, &.{ options.zig_src_root, "build.zig" }), 19 | }; 20 | } 21 | 22 | pub fn run(gpa: std.mem.Allocator, context: Context) !void { 23 | return bench.exec(gpa, &.{ 24 | context.zig_exe, "build", 25 | "--build-file", context.build_file_path, 26 | "-p", OUTPUT_DIR, 27 | "-Dno-lib", 28 | }, .{}); 29 | } 30 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/simple_file_system_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Guid = uefi.Guid; 3 | const FileProtocol = uefi.protocols.FileProtocol; 4 | const Status = uefi.Status; 5 | 6 | pub const SimpleFileSystemProtocol = extern struct { 7 | revision: u64, 8 | _open_volume: fn (*const SimpleFileSystemProtocol, **const FileProtocol) callconv(.C) Status, 9 | 10 | pub fn openVolume(self: *const SimpleFileSystemProtocol, root: **const FileProtocol) Status { 11 | return self._open_volume(self, root); 12 | } 13 | 14 | pub const guid align(8) = Guid{ 15 | .time_low = 0x0964e5b22, 16 | .time_mid = 0x6459, 17 | .time_high_and_version = 0x11d2, 18 | .clock_seq_high_and_reserved = 0x8e, 19 | .clock_seq_low = 0x39, 20 | .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b }, 21 | }; 22 | }; 23 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatundidf.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const std = @import("std"); 3 | 4 | const twop52: f64 = 0x1.0p52; 5 | const twop84: f64 = 0x1.0p84; 6 | const twop84_plus_twop52: f64 = 0x1.00000001p84; 7 | 8 | pub fn __floatundidf(a: u64) callconv(.C) f64 { 9 | @setRuntimeSafety(builtin.is_test); 10 | 11 | if (a == 0) return 0; 12 | 13 | var high = @as(u64, @bitCast(twop84)); 14 | var low = @as(u64, @bitCast(twop52)); 15 | 16 | high |= a >> 32; 17 | low |= a & 0xFFFFFFFF; 18 | 19 | return (@as(f64, @bitCast(high)) - twop84_plus_twop52) + @as(f64, @bitCast(low)); 20 | } 21 | 22 | pub fn __aeabi_ul2d(arg: u64) callconv(.AAPCS) f64 { 23 | @setRuntimeSafety(false); 24 | return @call(.{ .modifier = .always_inline }, __floatundidf, .{arg}); 25 | } 26 | 27 | test { 28 | _ = @import("floatundidf_test.zig"); 29 | } 30 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/complex/asin.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const testing = std.testing; 3 | const math = std.math; 4 | const cmath = math.complex; 5 | const Complex = cmath.Complex; 6 | 7 | // Returns the arc-sine of z. 8 | pub fn asin(z: anytype) Complex(@TypeOf(z.re)) { 9 | const T = @TypeOf(z.re); 10 | const x = z.re; 11 | const y = z.im; 12 | 13 | const p = Complex(T).init(1.0 - (x - y) * (x + y), -2.0 * x * y); 14 | const q = Complex(T).init(-y, x); 15 | const r = cmath.log(q.add(cmath.sqrt(p))); 16 | 17 | return Complex(T).init(r.im, -r.re); 18 | } 19 | 20 | const epsilon = 0.0001; 21 | 22 | test "complex.casin" { 23 | const a = Complex(f32).init(5, 3); 24 | const c = asin(a); 25 | 26 | try testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon)); 27 | try testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon)); 28 | } 29 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/c/minix.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | pub const pthread_mutex_t = extern struct { 3 | size: [__SIZEOF_PTHREAD_MUTEX_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_MUTEX_T, 4 | }; 5 | pub const pthread_cond_t = extern struct { 6 | size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T, 7 | }; 8 | const __SIZEOF_PTHREAD_COND_T = 48; 9 | const __SIZEOF_PTHREAD_MUTEX_T = switch (builtin.abi) { 10 | .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24, 11 | .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (builtin.cpu.arch) { 12 | .aarch64 => 48, 13 | .x86_64 => if (builtin.abi == .gnux32) 40 else 32, 14 | .mips64, .powerpc64, .powerpc64le, .sparcv9 => 40, 15 | else => if (@sizeOf(usize) == 8) 40 else 24, 16 | }, 17 | else => unreachable, 18 | }; 19 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/isnan.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const math = std.math; 3 | const expect = std.testing.expect; 4 | const maxInt = std.math.maxInt; 5 | 6 | /// Returns whether x is a nan. 7 | pub fn isNan(x: anytype) bool { 8 | return x != x; 9 | } 10 | 11 | /// Returns whether x is a signalling nan. 12 | pub fn isSignalNan(x: anytype) bool { 13 | // Note: A signalling nan is identical to a standard nan right now but may have a different bit 14 | // representation in the future when required. 15 | return isNan(x); 16 | } 17 | 18 | test "math.isNan" { 19 | try expect(isNan(math.nan(f16))); 20 | try expect(isNan(math.nan(f32))); 21 | try expect(isNan(math.nan(f64))); 22 | try expect(isNan(math.nan(f128))); 23 | try expect(!isNan(@as(f16, 1.0))); 24 | try expect(!isNan(@as(f32, 1.0))); 25 | try expect(!isNan(@as(f64, 1.0))); 26 | try expect(!isNan(@as(f128, 1.0))); 27 | } 28 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatunditf.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const is_test = builtin.is_test; 3 | const std = @import("std"); 4 | 5 | pub fn __floatunditf(a: u64) callconv(.C) f128 { 6 | @setRuntimeSafety(is_test); 7 | 8 | if (a == 0) { 9 | return 0; 10 | } 11 | 12 | const mantissa_bits = std.math.floatMantissaBits(f128); 13 | const exponent_bits = std.math.floatExponentBits(f128); 14 | const exponent_bias = (1 << (exponent_bits - 1)) - 1; 15 | const implicit_bit = 1 << mantissa_bits; 16 | 17 | const exp: u128 = (64 - 1) - @clz(a); 18 | const shift: u7 = mantissa_bits - @as(u7, @intCast(exp)); 19 | 20 | var result: u128 = (@as(u128, @intCast(a)) << shift) ^ implicit_bit; 21 | result += (exp + exponent_bias) << mantissa_bits; 22 | 23 | return @as(f128, @bitCast(result)); 24 | } 25 | 26 | test { 27 | _ = @import("floatunditf_test.zig"); 28 | } 29 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/crypto/test.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const testing = std.testing; 3 | const fmt = std.fmt; 4 | 5 | // Hash using the specified hasher `H` asserting `expected == H(input)`. 6 | pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) !void { 7 | var h: [Hasher.digest_length]u8 = undefined; 8 | Hasher.hash(input, &h, .{}); 9 | 10 | try assertEqual(expected_hex, &h); 11 | } 12 | 13 | // Assert `expected` == hex(`input`) where `input` is a bytestring 14 | pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) !void { 15 | var expected_bytes: [expected_hex.len / 2]u8 = undefined; 16 | for (expected_bytes, 0..) |*r, i| { 17 | r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable; 18 | } 19 | 20 | try testing.expectEqualSlices(u8, &expected_bytes, input); 21 | } 22 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunstfsi_test.zig: -------------------------------------------------------------------------------- 1 | const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi; 2 | const testing = @import("std").testing; 3 | 4 | fn test__fixunstfsi(a: f128, expected: u32) !void { 5 | const x = __fixunstfsi(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | const inf128 = @as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))); 10 | 11 | test "fixunstfsi" { 12 | try test__fixunstfsi(inf128, 0xffffffff); 13 | try test__fixunstfsi(0, 0x0); 14 | try test__fixunstfsi(0x1.23456789abcdefp+5, 0x24); 15 | try test__fixunstfsi(0x1.23456789abcdefp-3, 0x0); 16 | try test__fixunstfsi(0x1.23456789abcdefp+20, 0x123456); 17 | try test__fixunstfsi(0x1.23456789abcdefp+40, 0xffffffff); 18 | try test__fixunstfsi(0x1.23456789abcdefp+256, 0xffffffff); 19 | try test__fixunstfsi(-0x1.23456789abcdefp+3, 0x0); 20 | 21 | try test__fixunstfsi(0x1p+32, 0xFFFFFFFF); 22 | } 23 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/divti3.zig: -------------------------------------------------------------------------------- 1 | const udivmod = @import("udivmod.zig").udivmod; 2 | const builtin = @import("builtin"); 3 | 4 | pub fn __divti3(a: i128, b: i128) callconv(.C) i128 { 5 | @setRuntimeSafety(builtin.is_test); 6 | 7 | const s_a = a >> (128 - 1); 8 | const s_b = b >> (128 - 1); 9 | 10 | const an = (a ^ s_a) -% s_a; 11 | const bn = (b ^ s_b) -% s_b; 12 | 13 | const r = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), null); 14 | const s = s_a ^ s_b; 15 | return (@as(i128, @bitCast(r)) ^ s) -% s; 16 | } 17 | 18 | const v128 = @import("std").meta.Vector(2, u64); 19 | pub fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 { 20 | return @as(v128, @bitCast(@call(.{ .modifier = .always_inline }, __divti3, .{ 21 | @as(i128, @bitCast(a)), 22 | @as(i128, @bitCast(b)), 23 | }))); 24 | } 25 | 26 | test { 27 | _ = @import("divti3_test.zig"); 28 | } 29 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/big.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const assert = std.debug.assert; 3 | 4 | pub const Rational = @import("big/rational.zig").Rational; 5 | pub const int = @import("big/int.zig"); 6 | pub const Limb = usize; 7 | const limb_info = @typeInfo(Limb).Int; 8 | pub const SignedLimb = std.meta.Int(.signed, limb_info.bits); 9 | pub const DoubleLimb = std.meta.Int(.unsigned, 2 * limb_info.bits); 10 | pub const SignedDoubleLimb = std.meta.Int(.signed, 2 * limb_info.bits); 11 | pub const Log2Limb = std.math.Log2Int(Limb); 12 | 13 | comptime { 14 | assert(std.math.floorPowerOfTwo(usize, limb_info.bits) == limb_info.bits); 15 | assert(limb_info.bits <= 64); // u128 set is unsupported 16 | assert(limb_info.signedness == .unsigned); 17 | } 18 | 19 | test { 20 | _ = int; 21 | _ = Rational; 22 | _ = Limb; 23 | _ = SignedLimb; 24 | _ = DoubleLimb; 25 | _ = SignedDoubleLimb; 26 | _ = Log2Limb; 27 | } 28 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/nan.zig: -------------------------------------------------------------------------------- 1 | const math = @import("../math.zig"); 2 | 3 | /// Returns the nan representation for type T. 4 | pub fn nan(comptime T: type) T { 5 | return switch (T) { 6 | f16 => math.nan_f16, 7 | f32 => math.nan_f32, 8 | f64 => math.nan_f64, 9 | f128 => math.nan_f128, 10 | else => @compileError("nan not implemented for " ++ @typeName(T)), 11 | }; 12 | } 13 | 14 | /// Returns the signalling nan representation for type T. 15 | pub fn snan(comptime T: type) T { 16 | // Note: A signalling nan is identical to a standard right now by may have a different bit 17 | // representation in the future when required. 18 | return switch (T) { 19 | f16 => @as(f16, @bitCast(math.nan_u16)), 20 | f32 => @as(f32, @bitCast(math.nan_u32)), 21 | f64 => @as(f64, @bitCast(math.nan_u64)), 22 | else => @compileError("snan not implemented for " ++ @typeName(T)), 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatunsitf.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const is_test = builtin.is_test; 3 | const std = @import("std"); 4 | 5 | pub fn __floatunsitf(a: u32) callconv(.C) f128 { 6 | @setRuntimeSafety(is_test); 7 | 8 | if (a == 0) { 9 | return 0; 10 | } 11 | 12 | const mantissa_bits = std.math.floatMantissaBits(f128); 13 | const exponent_bits = std.math.floatExponentBits(f128); 14 | const exponent_bias = (1 << (exponent_bits - 1)) - 1; 15 | const implicit_bit = 1 << mantissa_bits; 16 | 17 | const exp = (32 - 1) - @clz(a); 18 | const shift = mantissa_bits - @as(u7, @intCast(exp)); 19 | 20 | // TODO(#1148): @bitCast alignment error 21 | var result align(16) = (@as(u128, @intCast(a)) << shift) ^ implicit_bit; 22 | result += (@as(u128, @intCast(exp)) + exponent_bias) << mantissa_bits; 23 | 24 | return @as(f128, @bitCast(result)); 25 | } 26 | 27 | test { 28 | _ = @import("floatunsitf_test.zig"); 29 | } 30 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/negXf2.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub fn __negsf2(a: f32) callconv(.C) f32 { 4 | return negXf2(f32, a); 5 | } 6 | 7 | pub fn __negdf2(a: f64) callconv(.C) f64 { 8 | return negXf2(f64, a); 9 | } 10 | 11 | pub fn __aeabi_fneg(arg: f32) callconv(.AAPCS) f32 { 12 | @setRuntimeSafety(false); 13 | return @call(.{ .modifier = .always_inline }, __negsf2, .{arg}); 14 | } 15 | 16 | pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 { 17 | @setRuntimeSafety(false); 18 | return @call(.{ .modifier = .always_inline }, __negdf2, .{arg}); 19 | } 20 | 21 | fn negXf2(comptime T: type, a: T) T { 22 | const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); 23 | 24 | const significandBits = std.math.floatMantissaBits(T); 25 | const exponentBits = std.math.floatExponentBits(T); 26 | 27 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); 28 | 29 | return @as(T, @bitCast(@as(Z, @bitCast(a)) ^ signBit)); 30 | } 31 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/Thread/Semaphore.zig: -------------------------------------------------------------------------------- 1 | //! A semaphore is an unsigned integer that blocks the kernel thread if 2 | //! the number would become negative. 3 | //! This API supports static initialization and does not require deinitialization. 4 | 5 | mutex: Mutex = .{}, 6 | cond: Condition = .{}, 7 | /// It is OK to initialize this field to any value. 8 | permits: usize = 0, 9 | 10 | const Semaphore = @This(); 11 | const std = @import("../std.zig"); 12 | const Mutex = std.Thread.Mutex; 13 | const Condition = std.Thread.Condition; 14 | 15 | pub fn wait(sem: *Semaphore) void { 16 | const held = sem.mutex.acquire(); 17 | defer held.release(); 18 | 19 | while (sem.permits == 0) 20 | sem.cond.wait(&sem.mutex); 21 | 22 | sem.permits -= 1; 23 | if (sem.permits > 0) 24 | sem.cond.signal(); 25 | } 26 | 27 | pub fn post(sem: *Semaphore) void { 28 | const held = sem.mutex.acquire(); 29 | defer held.release(); 30 | 31 | sem.permits += 1; 32 | sem.cond.signal(); 33 | } 34 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/popcountdi2_test.zig: -------------------------------------------------------------------------------- 1 | const __popcountdi2 = @import("popcountdi2.zig").__popcountdi2; 2 | const testing = @import("std").testing; 3 | 4 | fn naive_popcount(a_param: i64) i32 { 5 | var a = a_param; 6 | var r: i32 = 0; 7 | while (a != 0) : (a = @as(i64, @bitCast(@as(u64, @bitCast(a)) >> 1))) { 8 | r += @as(i32, @intCast(a & 1)); 9 | } 10 | return r; 11 | } 12 | 13 | fn test__popcountdi2(a: i64) !void { 14 | const x = __popcountdi2(a); 15 | const expected = naive_popcount(a); 16 | try testing.expect(expected == x); 17 | } 18 | 19 | test "popcountdi2" { 20 | try test__popcountdi2(0); 21 | try test__popcountdi2(1); 22 | try test__popcountdi2(2); 23 | try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xFFFFFFFFFFFFFFFD)))); 24 | try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xFFFFFFFFFFFFFFFE)))); 25 | try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xFFFFFFFFFFFFFFFF)))); 26 | // TODO some fuzz testing 27 | } 28 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/divti3_test.zig: -------------------------------------------------------------------------------- 1 | const __divti3 = @import("divti3.zig").__divti3; 2 | const testing = @import("std").testing; 3 | 4 | fn test__divti3(a: i128, b: i128, expected: i128) !void { 5 | const x = __divti3(a, b); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "divti3" { 10 | try test__divti3(0, 1, 0); 11 | try test__divti3(0, -1, 0); 12 | try test__divti3(2, 1, 2); 13 | try test__divti3(2, -1, -2); 14 | try test__divti3(-2, 1, -2); 15 | try test__divti3(-2, -1, 2); 16 | 17 | try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), 1, @as(i128, @bitCast(@as(u128, 0x8 << 124)))); 18 | try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), -1, @as(i128, @bitCast(@as(u128, 0x8 << 124)))); 19 | try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), -2, @as(i128, @bitCast(@as(u128, 0x4 << 124)))); 20 | try test__divti3(@as(i128, @bitCast(@as(u128, 0x8 << 124))), 2, @as(i128, @bitCast(@as(u128, 0xc << 124)))); 21 | } 22 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/event.zig: -------------------------------------------------------------------------------- 1 | pub const Channel = @import("event/channel.zig").Channel; 2 | pub const Future = @import("event/future.zig").Future; 3 | pub const Group = @import("event/group.zig").Group; 4 | pub const Batch = @import("event/batch.zig").Batch; 5 | pub const Lock = @import("event/lock.zig").Lock; 6 | pub const Locked = @import("event/locked.zig").Locked; 7 | pub const RwLock = @import("event/rwlock.zig").RwLock; 8 | pub const RwLocked = @import("event/rwlocked.zig").RwLocked; 9 | pub const Loop = @import("event/loop.zig").Loop; 10 | pub const WaitGroup = @import("event/wait_group.zig").WaitGroup; 11 | 12 | test { 13 | _ = @import("event/channel.zig"); 14 | _ = @import("event/future.zig"); 15 | _ = @import("event/group.zig"); 16 | _ = @import("event/batch.zig"); 17 | _ = @import("event/lock.zig"); 18 | _ = @import("event/locked.zig"); 19 | _ = @import("event/rwlock.zig"); 20 | _ = @import("event/rwlocked.zig"); 21 | _ = @import("event/loop.zig"); 22 | _ = @import("event/wait_group.zig"); 23 | } 24 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/ip6_service_binding_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Handle = uefi.Handle; 3 | const Guid = uefi.Guid; 4 | const Status = uefi.Status; 5 | 6 | pub const Ip6ServiceBindingProtocol = extern struct { 7 | _create_child: fn (*const Ip6ServiceBindingProtocol, *?Handle) callconv(.C) Status, 8 | _destroy_child: fn (*const Ip6ServiceBindingProtocol, Handle) callconv(.C) Status, 9 | 10 | pub fn createChild(self: *const Ip6ServiceBindingProtocol, handle: *?Handle) Status { 11 | return self._create_child(self, handle); 12 | } 13 | 14 | pub fn destroyChild(self: *const Ip6ServiceBindingProtocol, handle: Handle) Status { 15 | return self._destroy_child(self, handle); 16 | } 17 | 18 | pub const guid align(8) = Guid{ 19 | .time_low = 0xec835dd3, 20 | .time_mid = 0xfe0f, 21 | .time_high_and_version = 0x617b, 22 | .clock_seq_high_and_reserved = 0xa6, 23 | .clock_seq_low = 0x21, 24 | .node = [_]u8{ 0xb3, 0x50, 0xc3, 0xe1, 0x33, 0x88 }, 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/rand/Gimli.zig: -------------------------------------------------------------------------------- 1 | //! CSPRNG 2 | 3 | const std = @import("std"); 4 | const Random = std.rand.Random; 5 | const mem = std.mem; 6 | const Gimli = @This(); 7 | 8 | state: std.crypto.core.Gimli, 9 | 10 | pub const secret_seed_length = 32; 11 | 12 | /// The seed must be uniform, secret and `secret_seed_length` bytes long. 13 | pub fn init(secret_seed: [secret_seed_length]u8) Gimli { 14 | var initial_state: [std.crypto.core.Gimli.BLOCKBYTES]u8 = undefined; 15 | mem.copy(u8, initial_state[0..secret_seed_length], &secret_seed); 16 | mem.set(u8, initial_state[secret_seed_length..], 0); 17 | var self = Gimli{ 18 | .state = std.crypto.core.Gimli.init(initial_state), 19 | }; 20 | return self; 21 | } 22 | 23 | pub fn random(self: *Gimli) Random { 24 | return Random.init(self, fill); 25 | } 26 | 27 | pub fn fill(self: *Gimli, buf: []u8) void { 28 | if (buf.len != 0) { 29 | self.state.squeeze(buf); 30 | } else { 31 | self.state.permute(); 32 | } 33 | mem.set(u8, self.state.toSlice()[0..std.crypto.core.Gimli.RATE], 0); 34 | } 35 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatunsitf_test.zig: -------------------------------------------------------------------------------- 1 | const __floatunsitf = @import("floatunsitf.zig").__floatunsitf; 2 | 3 | fn test__floatunsitf(a: u32, expected_hi: u64, expected_lo: u64) !void { 4 | const x = __floatunsitf(a); 5 | 6 | const x_repr = @as(u128, @bitCast(x)); 7 | const x_hi = @as(u64, @intCast(x_repr >> 64)); 8 | const x_lo = @as(u64, @truncate(x_repr)); 9 | 10 | if (x_hi == expected_hi and x_lo == expected_lo) { 11 | return; 12 | } 13 | // nan repr 14 | else if (expected_hi == 0x7fff800000000000 and expected_lo == 0x0) { 15 | if ((x_hi & 0x7fff000000000000) == 0x7fff000000000000 and ((x_hi & 0xffffffffffff) > 0 or x_lo > 0)) { 16 | return; 17 | } 18 | } 19 | 20 | @panic("__floatunsitf test failure"); 21 | } 22 | 23 | test "floatunsitf" { 24 | try test__floatunsitf(0x7fffffff, 0x401dfffffffc0000, 0x0); 25 | try test__floatunsitf(0, 0x0, 0x0); 26 | try test__floatunsitf(0xffffffff, 0x401efffffffe0000, 0x0); 27 | try test__floatunsitf(0x12345678, 0x401b234567800000, 0x0); 28 | } 29 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/udp6_service_binding_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Handle = uefi.Handle; 3 | const Guid = uefi.Guid; 4 | const Status = uefi.Status; 5 | 6 | pub const Udp6ServiceBindingProtocol = extern struct { 7 | _create_child: fn (*const Udp6ServiceBindingProtocol, *?Handle) callconv(.C) Status, 8 | _destroy_child: fn (*const Udp6ServiceBindingProtocol, Handle) callconv(.C) Status, 9 | 10 | pub fn createChild(self: *const Udp6ServiceBindingProtocol, handle: *?Handle) Status { 11 | return self._create_child(self, handle); 12 | } 13 | 14 | pub fn destroyChild(self: *const Udp6ServiceBindingProtocol, handle: Handle) Status { 15 | return self._destroy_child(self, handle); 16 | } 17 | 18 | pub const guid align(8) = Guid{ 19 | .time_low = 0x66ed4721, 20 | .time_mid = 0x3c98, 21 | .time_high_and_version = 0x4d3e, 22 | .clock_seq_high_and_reserved = 0x81, 23 | .clock_seq_low = 0xe3, 24 | .node = [_]u8{ 0xd0, 0x3d, 0xd3, 0x9a, 0x72, 0x54 }, 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/divsf3_test.zig: -------------------------------------------------------------------------------- 1 | // Ported from: 2 | // 3 | // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/divsf3_test.c 4 | 5 | const __divsf3 = @import("divsf3.zig").__divsf3; 6 | const testing = @import("std").testing; 7 | 8 | fn compareResultF(result: f32, expected: u32) bool { 9 | const rep = @as(u32, @bitCast(result)); 10 | 11 | if (rep == expected) { 12 | return true; 13 | } 14 | // test other possible NaN representation(signal NaN) 15 | else if (expected == 0x7fc00000) { 16 | if ((rep & 0x7f800000) == 0x7f800000 and 17 | (rep & 0x7fffff) > 0) 18 | { 19 | return true; 20 | } 21 | } 22 | return false; 23 | } 24 | 25 | fn test__divsf3(a: f32, b: f32, expected: u32) !void { 26 | const x = __divsf3(a, b); 27 | const ret = compareResultF(x, expected); 28 | try testing.expect(ret == true); 29 | } 30 | 31 | test "divsf3" { 32 | try test__divsf3(1.0, 3.0, 0x3EAAAAAB); 33 | try test__divsf3(2.3509887e-38, 2.0, 0x00800000); 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (Expat) 2 | 3 | Copyright (c) 2020 Andrew Kelley 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/build/FmtStep.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const build = @import("../build.zig"); 3 | const Step = build.Step; 4 | const Builder = build.Builder; 5 | const BufMap = std.BufMap; 6 | const mem = std.mem; 7 | 8 | const FmtStep = @This(); 9 | 10 | pub const base_id = .fmt; 11 | 12 | step: Step, 13 | builder: *Builder, 14 | argv: [][]const u8, 15 | 16 | pub fn create(builder: *Builder, paths: []const []const u8) *FmtStep { 17 | const self = builder.allocator.create(FmtStep) catch unreachable; 18 | const name = "zig fmt"; 19 | self.* = FmtStep{ 20 | .step = Step.init(.fmt, name, builder.allocator, make), 21 | .builder = builder, 22 | .argv = builder.allocator.alloc([]u8, paths.len + 2) catch unreachable, 23 | }; 24 | 25 | self.argv[0] = builder.zig_exe; 26 | self.argv[1] = "fmt"; 27 | for (paths, 0..) |path, i| { 28 | self.argv[2 + i] = builder.pathFromRoot(path); 29 | } 30 | return self; 31 | } 32 | 33 | fn make(step: *Step) !void { 34 | const self = @fieldParentPtr(FmtStep, "step", step); 35 | 36 | return self.builder.spawnChild(self.argv); 37 | } 38 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/managed_network_service_binding_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Handle = uefi.Handle; 3 | const Guid = uefi.Guid; 4 | const Status = uefi.Status; 5 | 6 | pub const ManagedNetworkServiceBindingProtocol = extern struct { 7 | _create_child: fn (*const ManagedNetworkServiceBindingProtocol, *?Handle) callconv(.C) Status, 8 | _destroy_child: fn (*const ManagedNetworkServiceBindingProtocol, Handle) callconv(.C) Status, 9 | 10 | pub fn createChild(self: *const ManagedNetworkServiceBindingProtocol, handle: *?Handle) Status { 11 | return self._create_child(self, handle); 12 | } 13 | 14 | pub fn destroyChild(self: *const ManagedNetworkServiceBindingProtocol, handle: Handle) Status { 15 | return self._destroy_child(self, handle); 16 | } 17 | 18 | pub const guid align(8) = Guid{ 19 | .time_low = 0xf36ff770, 20 | .time_mid = 0xa7e1, 21 | .time_high_and_version = 0x42cf, 22 | .clock_seq_high_and_reserved = 0x9e, 23 | .clock_seq_low = 0xd2, 24 | .node = [_]u8{ 0x56, 0xf0, 0xf2, 0x71, 0xf4, 0x4c }, 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/windows/advapi32.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const windows = std.os.windows; 3 | const BOOL = windows.BOOL; 4 | const DWORD = windows.DWORD; 5 | const HKEY = windows.HKEY; 6 | const BYTE = windows.BYTE; 7 | const LPCWSTR = windows.LPCWSTR; 8 | const LSTATUS = windows.LSTATUS; 9 | const REGSAM = windows.REGSAM; 10 | const ULONG = windows.ULONG; 11 | const WINAPI = windows.WINAPI; 12 | 13 | pub extern "advapi32" fn RegOpenKeyExW( 14 | hKey: HKEY, 15 | lpSubKey: LPCWSTR, 16 | ulOptions: DWORD, 17 | samDesired: REGSAM, 18 | phkResult: *HKEY, 19 | ) callconv(WINAPI) LSTATUS; 20 | 21 | pub extern "advapi32" fn RegQueryValueExW( 22 | hKey: HKEY, 23 | lpValueName: LPCWSTR, 24 | lpReserved: *DWORD, 25 | lpType: *DWORD, 26 | lpData: *BYTE, 27 | lpcbData: *DWORD, 28 | ) callconv(WINAPI) LSTATUS; 29 | 30 | // RtlGenRandom is known as SystemFunction036 under advapi32 31 | // http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx */ 32 | pub extern "advapi32" fn SystemFunction036(output: [*]u8, length: ULONG) callconv(WINAPI) BOOL; 33 | pub const RtlGenRandom = SystemFunction036; 34 | -------------------------------------------------------------------------------- /src/tetris/tetris/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (Expat) 2 | 3 | Copyright (c) 2015 Andrew Kelley 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/tetris/tetris/README.md: -------------------------------------------------------------------------------- 1 | # Tetris 2 | 3 | A simple tetris clone written in 4 | [zig programming language](https://github.com/andrewrk/zig). 5 | 6 | [YouTube Demo](https://www.youtube.com/watch?v=AiintPutWrE). 7 | 8 | 9 | ![](http://i.imgur.com/umuNndz.png) 10 | 11 | [Windows 64-bit build](http://superjoe.s3.amazonaws.com/temp/tetris.zip) 12 | 13 | ## Controls 14 | 15 | * Left/Right/Down Arrow - Move piece left/right/down. 16 | * Up Arrow - Rotate piece clockwise. 17 | * Shift - Rotate piece counter clockwise. 18 | * Space - Drop piece immediately. 19 | * Left Ctrl - Hold piece. 20 | * R - Start new game. 21 | * P - Pause and unpause game. 22 | * Escape - Quit. 23 | 24 | ## Dependencies 25 | 26 | * [Zig compiler](https://github.com/andrewrk/zig) - use the debug build. 27 | * [libepoxy](https://github.com/anholt/libepoxy) 28 | * [GLFW](http://www.glfw.org/) 29 | 30 | ## Building and Running 31 | 32 | ``` 33 | zig build play 34 | ``` 35 | 36 | ## Building on windows using vcpkg 37 | 38 | * Install vcpkg https://github.com/microsoft/vcpkg 39 | * Install dependencies using `x64-windows` triplet 40 | * Use the flags `-Dwindows -Dvcpkg` when building the project 41 | 42 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/expo2.zig: -------------------------------------------------------------------------------- 1 | // Ported from musl, which is licensed under the MIT license: 2 | // https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT 3 | // 4 | // https://git.musl-libc.org/cgit/musl/tree/src/math/__expo2f.c 5 | // https://git.musl-libc.org/cgit/musl/tree/src/math/__expo2.c 6 | 7 | const math = @import("../math.zig"); 8 | 9 | /// Returns exp(x) / 2 for x >= log(maxFloat(T)). 10 | pub fn expo2(x: anytype) @TypeOf(x) { 11 | const T = @TypeOf(x); 12 | return switch (T) { 13 | f32 => expo2f(x), 14 | f64 => expo2d(x), 15 | else => @compileError("expo2 not implemented for " ++ @typeName(T)), 16 | }; 17 | } 18 | 19 | fn expo2f(x: f32) f32 { 20 | const k: u32 = 235; 21 | const kln2 = 0x1.45C778p+7; 22 | 23 | const u = (0x7F + k / 2) << 23; 24 | const scale = @as(f32, @bitCast(u)); 25 | return math.exp(x - kln2) * scale * scale; 26 | } 27 | 28 | fn expo2d(x: f64) f64 { 29 | const k: u32 = 2043; 30 | const kln2 = 0x1.62066151ADD8BP+10; 31 | 32 | const u = (0x3FF + k / 2) << 20; 33 | const scale = @as(f64, @bitCast(@as(u64, u) << 32)); 34 | return math.exp(x - kln2) * scale * scale; 35 | } 36 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/divdf3_test.zig: -------------------------------------------------------------------------------- 1 | // Ported from: 2 | // 3 | // https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/divdf3_test.c 4 | 5 | const __divdf3 = @import("divdf3.zig").__divdf3; 6 | const testing = @import("std").testing; 7 | 8 | fn compareResultD(result: f64, expected: u64) bool { 9 | const rep = @as(u64, @bitCast(result)); 10 | 11 | if (rep == expected) { 12 | return true; 13 | } 14 | // test other possible NaN representation(signal NaN) 15 | else if (expected == 0x7ff8000000000000) { 16 | if ((rep & 0x7ff0000000000000) == 0x7ff0000000000000 and 17 | (rep & 0xfffffffffffff) > 0) 18 | { 19 | return true; 20 | } 21 | } 22 | return false; 23 | } 24 | 25 | fn test__divdf3(a: f64, b: f64, expected: u64) !void { 26 | const x = __divdf3(a, b); 27 | const ret = compareResultD(x, expected); 28 | try testing.expect(ret == true); 29 | } 30 | 31 | test "divdf3" { 32 | try test__divdf3(1.0, 3.0, 0x3fd5555555555555); 33 | try test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000); 34 | } 35 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/tables.zig: -------------------------------------------------------------------------------- 1 | pub const AllocateType = @import("tables/boot_services.zig").AllocateType; 2 | pub const BootServices = @import("tables/boot_services.zig").BootServices; 3 | pub const ConfigurationTable = @import("tables/configuration_table.zig").ConfigurationTable; 4 | pub const global_variable align(8) = @import("tables/runtime_services.zig").global_variable; 5 | pub const LocateSearchType = @import("tables/boot_services.zig").LocateSearchType; 6 | pub const MemoryDescriptor = @import("tables/boot_services.zig").MemoryDescriptor; 7 | pub const MemoryType = @import("tables/boot_services.zig").MemoryType; 8 | pub const OpenProtocolAttributes = @import("tables/boot_services.zig").OpenProtocolAttributes; 9 | pub const ProtocolInformationEntry = @import("tables/boot_services.zig").ProtocolInformationEntry; 10 | pub const ResetType = @import("tables/runtime_services.zig").ResetType; 11 | pub const RuntimeServices = @import("tables/runtime_services.zig").RuntimeServices; 12 | pub const SystemTable = @import("tables/system_table.zig").SystemTable; 13 | pub const TableHeader = @import("tables/table_header.zig").TableHeader; 14 | pub const TimerDelay = @import("tables/boot_services.zig").TimerDelay; 15 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/popcountdi2.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const compiler_rt = @import("../compiler_rt.zig"); 3 | 4 | // ported from llvm compiler-rt 8.0.0rc3 95e1c294cb0415a377a7b1d6c7c7d4f89e1c04e4 5 | pub fn __popcountdi2(a: i64) callconv(.C) i32 { 6 | var x2 = @as(u64, @bitCast(a)); 7 | x2 = x2 - ((x2 >> 1) & 0x5555555555555555); 8 | // Every 2 bits holds the sum of every pair of bits (32) 9 | x2 = ((x2 >> 2) & 0x3333333333333333) + (x2 & 0x3333333333333333); 10 | // Every 4 bits holds the sum of every 4-set of bits (3 significant bits) (16) 11 | x2 = (x2 + (x2 >> 4)) & 0x0F0F0F0F0F0F0F0F; 12 | // Every 8 bits holds the sum of every 8-set of bits (4 significant bits) (8) 13 | var x: u32 = @as(u32, @truncate(x2 + (x2 >> 32))); 14 | // The lower 32 bits hold four 16 bit sums (5 significant bits). 15 | // Upper 32 bits are garbage */ 16 | x = x + (x >> 16); 17 | // The lower 16 bits hold two 32 bit sums (6 significant bits). 18 | // Upper 16 bits are garbage */ 19 | return @as(i32, @bitCast((x + (x >> 8)) & 0x0000007F)); // (7 significant bits) 20 | } 21 | 22 | test { 23 | _ = @import("popcountdi2_test.zig"); 24 | } 25 | -------------------------------------------------------------------------------- /src/tetris/tetris/build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const Builder = std.build.Builder; 3 | 4 | pub fn build(b: *Builder) void { 5 | const mode = b.standardReleaseOptions(); 6 | const windows = b.option(bool, "windows", "create windows build") orelse false; 7 | const vcpkg = b.option(bool, "vcpkg", "Add vcpkg paths to the build") orelse false; 8 | 9 | var exe = b.addExecutable("tetris", "src/main.zig"); 10 | exe.addCSourceFile("stb_image-2.22/stb_image_impl.c", &[_][]const u8{"-std=c99"}); 11 | exe.setBuildMode(mode); 12 | 13 | if (windows) { 14 | exe.setTarget(.{ 15 | .cpu_arch = .x86_64, 16 | .os_tag = .windows, 17 | .abi = .gnu, 18 | }); 19 | } 20 | 21 | if (vcpkg) { 22 | exe.addVcpkgPaths(.Static) catch @panic("Cannot add vcpkg paths."); 23 | } 24 | 25 | exe.addIncludeDir("stb_image-2.22"); 26 | 27 | exe.linkSystemLibrary("c"); 28 | exe.linkSystemLibrary("glfw"); 29 | exe.linkSystemLibrary("epoxy"); 30 | exe.install(); 31 | 32 | const play = b.step("play", "Play the game"); 33 | const run = exe.run(); 34 | run.step.dependOn(b.getInstallStep()); 35 | play.dependOn(&run.step); 36 | } 37 | -------------------------------------------------------------------------------- /src/arena-allocator/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | var rng = std.rand.DefaultPrng.init(0x1234); 5 | 6 | pub fn setup(_: std.mem.Allocator, _: *bench.Options) !std.rand.Random { 7 | return rng.random(); 8 | } 9 | 10 | pub fn run(gpa: std.mem.Allocator, random: std.rand.Random) !void { 11 | var arena_state = std.heap.ArenaAllocator.init(gpa); 12 | defer arena_state.deinit(); 13 | const arena = arena_state.allocator(); 14 | 15 | const sizes = 16 | // Some few weird sizes 17 | [_]usize{1} ++ 18 | [_]usize{2} ++ 19 | [_]usize{6} ++ 20 | [_]usize{12} ++ 21 | [_]usize{24} ++ 22 | [_]usize{33} ++ 23 | [_]usize{100} ++ 24 | [_]usize{1000} ++ 25 | // Much more frequent common sizes 26 | ([_]usize{4} ** 10) ++ 27 | ([_]usize{8} ** 20) ++ 28 | ([_]usize{16} ** 100) ++ 29 | ([_]usize{32} ** 100) ++ 30 | ([_]usize{64} ** 50); 31 | 32 | var i: usize = 0; 33 | while (i < 10_000) : (i += 1) { 34 | const alloc_size = random.uintAtMostBiased(usize, sizes.len); 35 | const slice = try arena.alloc(u8, alloc_size); 36 | @memset(slice, 0xff); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/linux/bpf/kern.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../../std.zig"); 2 | const builtin = @import("builtin"); 3 | 4 | const in_bpf_program = switch (builtin.cpu.arch) { 5 | .bpfel, .bpfeb => true, 6 | else => false, 7 | }; 8 | 9 | pub const helpers = if (in_bpf_program) @import("helpers.zig") else struct {}; 10 | 11 | pub const BpfSock = opaque {}; 12 | pub const BpfSockAddr = opaque {}; 13 | pub const FibLookup = opaque {}; 14 | pub const MapDef = opaque {}; 15 | pub const PerfEventData = opaque {}; 16 | pub const PerfEventValue = opaque {}; 17 | pub const PidNsInfo = opaque {}; 18 | pub const SeqFile = opaque {}; 19 | pub const SkBuff = opaque {}; 20 | pub const SkMsgMd = opaque {}; 21 | pub const SkReusePortMd = opaque {}; 22 | pub const Sock = opaque {}; 23 | pub const SockAddr = opaque {}; 24 | pub const SockOps = opaque {}; 25 | pub const SockTuple = opaque {}; 26 | pub const SpinLock = opaque {}; 27 | pub const SysCtl = opaque {}; 28 | pub const Tcp6Sock = opaque {}; 29 | pub const TcpRequestSock = opaque {}; 30 | pub const TcpSock = opaque {}; 31 | pub const TcpTimewaitSock = opaque {}; 32 | pub const TunnelKey = opaque {}; 33 | pub const Udp6Sock = opaque {}; 34 | pub const XdpMd = opaque {}; 35 | pub const XfrmState = opaque {}; 36 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/modti3.zig: -------------------------------------------------------------------------------- 1 | // Ported from: 2 | // 3 | // https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c 4 | 5 | const udivmod = @import("udivmod.zig").udivmod; 6 | const builtin = @import("builtin"); 7 | const compiler_rt = @import("../compiler_rt.zig"); 8 | 9 | pub fn __modti3(a: i128, b: i128) callconv(.C) i128 { 10 | @setRuntimeSafety(builtin.is_test); 11 | 12 | const s_a = a >> (128 - 1); // s = a < 0 ? -1 : 0 13 | const s_b = b >> (128 - 1); // s = b < 0 ? -1 : 0 14 | 15 | const an = (a ^ s_a) -% s_a; // negate if s == -1 16 | const bn = (b ^ s_b) -% s_b; // negate if s == -1 17 | 18 | var r: u128 = undefined; 19 | _ = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), &r); 20 | return (@as(i128, @bitCast(r)) ^ s_a) -% s_a; // negate if s == -1 21 | } 22 | 23 | const v128 = @import("std").meta.Vector(2, u64); 24 | pub fn __modti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 { 25 | return @as(v128, @bitCast(@call(.{ .modifier = .always_inline }, __modti3, .{ 26 | @as(i128, @bitCast(a)), 27 | @as(i128, @bitCast(b)), 28 | }))); 29 | } 30 | 31 | test { 32 | _ = @import("modti3_test.zig"); 33 | } 34 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatditf.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const is_test = builtin.is_test; 3 | const std = @import("std"); 4 | const maxInt = std.math.maxInt; 5 | 6 | const significandBits = 112; 7 | const exponentBias = 16383; 8 | const implicitBit = (@as(u128, 1) << significandBits); 9 | 10 | pub fn __floatditf(arg: i64) callconv(.C) f128 { 11 | @setRuntimeSafety(is_test); 12 | 13 | if (arg == 0) 14 | return 0.0; 15 | 16 | // All other cases begin by extracting the sign and absolute value of a 17 | var sign: u128 = 0; 18 | var aAbs = @as(u64, @bitCast(arg)); 19 | if (arg < 0) { 20 | sign = 1 << 127; 21 | aAbs = ~@as(u64, @bitCast(arg)) + 1; 22 | } 23 | 24 | // Exponent of (fp_t)a is the width of abs(a). 25 | const exponent = 63 - @clz(aAbs); 26 | var result: u128 = undefined; 27 | 28 | // Shift a into the significand field, rounding if it is a right-shift 29 | const shift = significandBits - exponent; 30 | result = @as(u128, aAbs) << shift ^ implicitBit; 31 | 32 | result += (@as(u128, exponent) + exponentBias) << significandBits; 33 | return @as(f128, @bitCast(result | sign)); 34 | } 35 | 36 | test { 37 | _ = @import("floatditf_test.zig"); 38 | } 39 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/muloti4.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const compiler_rt = @import("../compiler_rt.zig"); 3 | 4 | pub fn __muloti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 { 5 | @setRuntimeSafety(builtin.is_test); 6 | 7 | const min = @as(i128, @bitCast(@as(u128, 1 << (128 - 1)))); 8 | const max = ~min; 9 | overflow.* = 0; 10 | 11 | const r = a *% b; 12 | if (a == min) { 13 | if (b != 0 and b != 1) { 14 | overflow.* = 1; 15 | } 16 | return r; 17 | } 18 | if (b == min) { 19 | if (a != 0 and a != 1) { 20 | overflow.* = 1; 21 | } 22 | return r; 23 | } 24 | 25 | const sa = a >> (128 - 1); 26 | const abs_a = (a ^ sa) -% sa; 27 | const sb = b >> (128 - 1); 28 | const abs_b = (b ^ sb) -% sb; 29 | 30 | if (abs_a < 2 or abs_b < 2) { 31 | return r; 32 | } 33 | 34 | if (sa == sb) { 35 | if (abs_a > @divTrunc(max, abs_b)) { 36 | overflow.* = 1; 37 | } 38 | } else { 39 | if (abs_a > @divTrunc(min, -abs_b)) { 40 | overflow.* = 1; 41 | } 42 | } 43 | 44 | return r; 45 | } 46 | 47 | test { 48 | _ = @import("muloti4_test.zig"); 49 | } 50 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/seekable_stream.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | 3 | pub fn SeekableStream( 4 | comptime Context: type, 5 | comptime SeekErrorType: type, 6 | comptime GetSeekPosErrorType: type, 7 | comptime seekToFn: fn (context: Context, pos: u64) SeekErrorType!void, 8 | comptime seekByFn: fn (context: Context, pos: i64) SeekErrorType!void, 9 | comptime getPosFn: fn (context: Context) GetSeekPosErrorType!u64, 10 | comptime getEndPosFn: fn (context: Context) GetSeekPosErrorType!u64, 11 | ) type { 12 | return struct { 13 | context: Context, 14 | 15 | const Self = @This(); 16 | pub const SeekError = SeekErrorType; 17 | pub const GetSeekPosError = GetSeekPosErrorType; 18 | 19 | pub fn seekTo(self: Self, pos: u64) SeekError!void { 20 | return seekToFn(self.context, pos); 21 | } 22 | 23 | pub fn seekBy(self: Self, amt: i64) SeekError!void { 24 | return seekByFn(self.context, amt); 25 | } 26 | 27 | pub fn getEndPos(self: Self) GetSeekPosError!u64 { 28 | return getEndPosFn(self.context); 29 | } 30 | 31 | pub fn getPos(self: Self) GetSeekPosError!u64 { 32 | return getPosFn(self.context); 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/simple_text_input_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Event = uefi.Event; 3 | const Guid = uefi.Guid; 4 | const InputKey = uefi.protocols.InputKey; 5 | const Status = uefi.Status; 6 | 7 | /// Character input devices, e.g. Keyboard 8 | pub const SimpleTextInputProtocol = extern struct { 9 | _reset: fn (*const SimpleTextInputProtocol, bool) callconv(.C) Status, 10 | _read_key_stroke: fn (*const SimpleTextInputProtocol, *InputKey) callconv(.C) Status, 11 | wait_for_key: Event, 12 | 13 | /// Resets the input device hardware. 14 | pub fn reset(self: *const SimpleTextInputProtocol, verify: bool) Status { 15 | return self._reset(self, verify); 16 | } 17 | 18 | /// Reads the next keystroke from the input device. 19 | pub fn readKeyStroke(self: *const SimpleTextInputProtocol, input_key: *InputKey) Status { 20 | return self._read_key_stroke(self, input_key); 21 | } 22 | 23 | pub const guid align(8) = Guid{ 24 | .time_low = 0x387477c1, 25 | .time_mid = 0x69c7, 26 | .time_high_and_version = 0x11d2, 27 | .clock_seq_high_and_reserved = 0x8e, 28 | .clock_seq_low = 0x39, 29 | .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b }, 30 | }; 31 | }; 32 | -------------------------------------------------------------------------------- /src/rand/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | const Rng = std.rand.Xoroshiro128; 5 | 6 | pub fn setup(_: std.mem.Allocator, _: *bench.Options) !void {} 7 | 8 | pub fn run(gpa: std.mem.Allocator, _: void) !void { 9 | const byte_count = 100_000_000; 10 | 11 | try rawBytes(gpa, byte_count); 12 | 13 | const int_types = .{ 14 | .{ .T = u16, .sum = 49_279 }, 15 | .{ .T = u32, .sum = 1_728_230_005 }, 16 | .{ .T = u64, .sum = 8_541_645_926_972_368_502 }, 17 | }; 18 | 19 | inline for (int_types) |t| { 20 | if (integers(t.T, byte_count) != t.sum) @panic("bad sum"); 21 | } 22 | } 23 | 24 | fn rawBytes(gpa: std.mem.Allocator, size: usize) !void { 25 | var buf = try gpa.alignedAlloc(u8, 8, size); 26 | defer gpa.free(buf); 27 | 28 | var rng = Rng.init(123_456_789); 29 | const random = rng.random(); 30 | random.bytes(buf); 31 | 32 | if (buf[size - 1] != 42) @panic("error"); 33 | } 34 | 35 | fn integers(comptime T: type, size: usize) T { 36 | var res: T = 0; 37 | var rng = Rng.init(123_456_789); 38 | const random = rng.random(); 39 | 40 | var i = @as(u32, 0); 41 | while (i < size) : (i += @sizeOf(T)) { 42 | res +%= random.int(T); 43 | } 44 | 45 | return res; 46 | } 47 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/event/locked.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const Lock = std.event.Lock; 3 | 4 | /// Thread-safe async/await lock that protects one piece of data. 5 | /// Functions which are waiting for the lock are suspended, and 6 | /// are resumed when the lock is released, in order. 7 | pub fn Locked(comptime T: type) type { 8 | return struct { 9 | lock: Lock, 10 | private_data: T, 11 | 12 | const Self = @This(); 13 | 14 | pub const HeldLock = struct { 15 | value: *T, 16 | held: Lock.Held, 17 | 18 | pub fn release(self: HeldLock) void { 19 | self.held.release(); 20 | } 21 | }; 22 | 23 | pub fn init(data: T) Self { 24 | return Self{ 25 | .lock = Lock.init(), 26 | .private_data = data, 27 | }; 28 | } 29 | 30 | pub fn deinit(self: *Self) void { 31 | self.lock.deinit(); 32 | } 33 | 34 | pub fn acquire(self: *Self) callconv(.Async) HeldLock { 35 | return HeldLock{ 36 | // TODO guaranteed allocation elision 37 | .held = self.lock.acquire(), 38 | .value = &self.private_data, 39 | }; 40 | } 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/edid_override_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Guid = uefi.Guid; 3 | const Handle = uefi.Handle; 4 | const Status = uefi.Status; 5 | 6 | /// Override EDID information 7 | pub const EdidOverrideProtocol = extern struct { 8 | _get_edid: fn (*const EdidOverrideProtocol, Handle, *u32, *usize, *?[*]u8) callconv(.C) Status, 9 | 10 | /// Returns policy information and potentially a replacement EDID for the specified video output device. 11 | /// attributes must be align(4) 12 | pub fn getEdid(self: *const EdidOverrideProtocol, handle: Handle, attributes: *EdidOverrideProtocolAttributes, edid_size: *usize, edid: *?[*]u8) Status { 13 | return self._get_edid(self, handle, attributes, edid_size, edid); 14 | } 15 | 16 | pub const guid align(8) = Guid{ 17 | .time_low = 0x48ecb431, 18 | .time_mid = 0xfb72, 19 | .time_high_and_version = 0x45c0, 20 | .clock_seq_high_and_reserved = 0xa9, 21 | .clock_seq_low = 0x22, 22 | .node = [_]u8{ 0xf4, 0x58, 0xfe, 0x04, 0x0b, 0xd5 }, 23 | }; 24 | }; 25 | 26 | pub const EdidOverrideProtocolAttributes = packed struct { 27 | dont_override: bool, 28 | enable_hot_plug: bool, 29 | _pad1: u6, 30 | _pad2: u8, 31 | _pad3: u16, 32 | }; 33 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/mulodi4.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const compiler_rt = @import("../compiler_rt.zig"); 3 | 4 | pub fn __mulodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 { 5 | @setRuntimeSafety(builtin.is_test); 6 | 7 | const min = @as(i64, @bitCast(@as(u64, 1 << (64 - 1)))); 8 | const max = ~min; 9 | 10 | overflow.* = 0; 11 | const result = a *% b; 12 | 13 | // Edge cases 14 | if (a == min) { 15 | if (b != 0 and b != 1) overflow.* = 1; 16 | return result; 17 | } 18 | if (b == min) { 19 | if (a != 0 and a != 1) overflow.* = 1; 20 | return result; 21 | } 22 | 23 | // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63). 24 | const abs_a = (a ^ (a >> 63)) -% (a >> 63); 25 | const abs_b = (b ^ (b >> 63)) -% (b >> 63); 26 | 27 | // Unitary magnitude, cannot have overflow 28 | if (abs_a < 2 or abs_b < 2) return result; 29 | 30 | // Compare the signs of the operands 31 | if ((a ^ b) >> 63 != 0) { 32 | if (abs_a > @divTrunc(max, abs_b)) overflow.* = 1; 33 | } else { 34 | if (abs_a > @divTrunc(min, -abs_b)) overflow.* = 1; 35 | } 36 | 37 | return result; 38 | } 39 | 40 | test { 41 | _ = @import("mulodi4_test.zig"); 42 | } 43 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/init-exe/build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub fn build(b: *std.build.Builder) void { 4 | // Standard target options allows the person running `zig build` to choose 5 | // what target to build for. Here we do not override the defaults, which 6 | // means any target is allowed, and the default is native. Other options 7 | // for restricting supported target set are available. 8 | const target = b.standardTargetOptions(.{}); 9 | 10 | // Standard release options allow the person running `zig build` to select 11 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. 12 | const mode = b.standardReleaseOptions(); 13 | 14 | const exe = b.addExecutable("$", "src/main.zig"); 15 | exe.setTarget(target); 16 | exe.setBuildMode(mode); 17 | exe.install(); 18 | 19 | const run_cmd = exe.run(); 20 | run_cmd.step.dependOn(b.getInstallStep()); 21 | if (b.args) |args| { 22 | run_cmd.addArgs(args); 23 | } 24 | 25 | const run_step = b.step("run", "Run the app"); 26 | run_step.dependOn(&run_cmd.step); 27 | 28 | const exe_tests = b.addTest("src/main.zig"); 29 | exe_tests.setBuildMode(mode); 30 | 31 | const test_step = b.step("test", "Run unit tests"); 32 | test_step.dependOn(&exe_tests.step); 33 | } 34 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunstfti_test.zig: -------------------------------------------------------------------------------- 1 | const __fixunstfti = @import("fixunstfti.zig").__fixunstfti; 2 | const testing = @import("std").testing; 3 | 4 | fn test__fixunstfti(a: f128, expected: u128) !void { 5 | const x = __fixunstfti(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | const inf128 = @as(f128, @bitCast(@as(u128, 0x7fff0000000000000000000000000000))); 10 | 11 | test "fixunstfti" { 12 | try test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff); 13 | 14 | try test__fixunstfti(0.0, 0); 15 | 16 | try test__fixunstfti(0.5, 0); 17 | try test__fixunstfti(0.99, 0); 18 | try test__fixunstfti(1.0, 1); 19 | try test__fixunstfti(1.5, 1); 20 | try test__fixunstfti(1.99, 1); 21 | try test__fixunstfti(2.0, 2); 22 | try test__fixunstfti(2.01, 2); 23 | try test__fixunstfti(-0.01, 0); 24 | try test__fixunstfti(-0.99, 0); 25 | 26 | try test__fixunstfti(0x1p+128, 0xffffffffffffffffffffffffffffffff); 27 | 28 | try test__fixunstfti(0x1.FFFFFEp+126, 0x7fffff80000000000000000000000000); 29 | try test__fixunstfti(0x1.FFFFFEp+127, 0xffffff00000000000000000000000000); 30 | try test__fixunstfti(0x1.FFFFFEp+128, 0xffffffffffffffffffffffffffffffff); 31 | try test__fixunstfti(0x1.FFFFFEp+129, 0xffffffffffffffffffffffffffffffff); 32 | } 33 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatditf_test.zig: -------------------------------------------------------------------------------- 1 | const __floatditf = @import("floatditf.zig").__floatditf; 2 | const testing = @import("std").testing; 3 | 4 | fn test__floatditf(a: i64, expected: f128) !void { 5 | const x = __floatditf(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "floatditf" { 10 | try test__floatditf(0x7fffffffffffffff, make_ti(0x403dffffffffffff, 0xfffc000000000000)); 11 | try test__floatditf(0x123456789abcdef1, make_ti(0x403b23456789abcd, 0xef10000000000000)); 12 | try test__floatditf(0x2, make_ti(0x4000000000000000, 0x0)); 13 | try test__floatditf(0x1, make_ti(0x3fff000000000000, 0x0)); 14 | try test__floatditf(0x0, make_ti(0x0, 0x0)); 15 | try test__floatditf(@as(i64, @bitCast(@as(u64, 0xffffffffffffffff))), make_ti(0xbfff000000000000, 0x0)); 16 | try test__floatditf(@as(i64, @bitCast(@as(u64, 0xfffffffffffffffe))), make_ti(0xc000000000000000, 0x0)); 17 | try test__floatditf(-0x123456789abcdef1, make_ti(0xc03b23456789abcd, 0xef10000000000000)); 18 | try test__floatditf(@as(i64, @bitCast(@as(u64, 0x8000000000000000))), make_ti(0xc03e000000000000, 0x0)); 19 | } 20 | 21 | fn make_ti(high: u64, low: u64) f128 { 22 | var result: u128 = high; 23 | result <<= 64; 24 | result |= low; 25 | return @as(f128, @bitCast(result)); 26 | } 27 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunssfsi_test.zig: -------------------------------------------------------------------------------- 1 | const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi; 2 | const testing = @import("std").testing; 3 | 4 | fn test__fixunssfsi(a: f32, expected: u32) !void { 5 | const x = __fixunssfsi(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "fixunssfsi" { 10 | try test__fixunssfsi(0.0, 0); 11 | 12 | try test__fixunssfsi(0.5, 0); 13 | try test__fixunssfsi(0.99, 0); 14 | try test__fixunssfsi(1.0, 1); 15 | try test__fixunssfsi(1.5, 1); 16 | try test__fixunssfsi(1.99, 1); 17 | try test__fixunssfsi(2.0, 2); 18 | try test__fixunssfsi(2.01, 2); 19 | try test__fixunssfsi(-0.5, 0); 20 | try test__fixunssfsi(-0.99, 0); 21 | 22 | try test__fixunssfsi(-1.0, 0); 23 | try test__fixunssfsi(-1.5, 0); 24 | try test__fixunssfsi(-1.99, 0); 25 | try test__fixunssfsi(-2.0, 0); 26 | try test__fixunssfsi(-2.01, 0); 27 | 28 | try test__fixunssfsi(0x1.000000p+31, 0x80000000); 29 | try test__fixunssfsi(0x1.000000p+32, 0xFFFFFFFF); 30 | try test__fixunssfsi(0x1.FFFFFEp+31, 0xFFFFFF00); 31 | try test__fixunssfsi(0x1.FFFFFEp+30, 0x7FFFFF80); 32 | try test__fixunssfsi(0x1.FFFFFCp+30, 0x7FFFFF00); 33 | 34 | try test__fixunssfsi(-0x1.FFFFFEp+30, 0); 35 | try test__fixunssfsi(-0x1.FFFFFCp+30, 0); 36 | } 37 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunssfdi_test.zig: -------------------------------------------------------------------------------- 1 | const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi; 2 | const testing = @import("std").testing; 3 | 4 | fn test__fixunssfdi(a: f32, expected: u64) !void { 5 | const x = __fixunssfdi(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "fixunssfdi" { 10 | try test__fixunssfdi(0.0, 0); 11 | 12 | try test__fixunssfdi(0.5, 0); 13 | try test__fixunssfdi(0.99, 0); 14 | try test__fixunssfdi(1.0, 1); 15 | try test__fixunssfdi(1.5, 1); 16 | try test__fixunssfdi(1.99, 1); 17 | try test__fixunssfdi(2.0, 2); 18 | try test__fixunssfdi(2.01, 2); 19 | try test__fixunssfdi(-0.5, 0); 20 | try test__fixunssfdi(-0.99, 0); 21 | 22 | try test__fixunssfdi(-1.0, 0); 23 | try test__fixunssfdi(-1.5, 0); 24 | try test__fixunssfdi(-1.99, 0); 25 | try test__fixunssfdi(-2.0, 0); 26 | try test__fixunssfdi(-2.01, 0); 27 | 28 | try test__fixunssfdi(0x1.FFFFFEp+63, 0xFFFFFF0000000000); 29 | try test__fixunssfdi(0x1.000000p+63, 0x8000000000000000); 30 | try test__fixunssfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); 31 | try test__fixunssfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); 32 | 33 | try test__fixunssfdi(-0x1.FFFFFEp+62, 0x0000000000000000); 34 | try test__fixunssfdi(-0x1.FFFFFCp+62, 0x0000000000000000); 35 | } 36 | -------------------------------------------------------------------------------- /src/self-hosted-parser/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, _: *bench.Options) !void {} 5 | 6 | pub fn run(gpa: std.mem.Allocator, _: void) !void { 7 | var input_dir = try std.fs.cwd().openIterableDir("src/self-hosted-parser/input_dir", .{}); 8 | defer input_dir.close(); 9 | 10 | var walker = try input_dir.walk(gpa); 11 | defer walker.deinit(); 12 | 13 | var total_count: usize = 0; 14 | var any_bad = false; 15 | while (try walker.next()) |entry| switch (entry.kind) { 16 | .file => { 17 | const source = try entry.dir.readFileAllocOptions(gpa, entry.basename, 30 * 1024 * 1024, null, @alignOf(u8), 0); 18 | defer gpa.free(source); 19 | 20 | var ast = try std.zig.Ast.parse(gpa, source, .zig); 21 | defer ast.deinit(gpa); 22 | 23 | if (ast.errors.len != 0) { 24 | for (ast.errors) |parse_error| { 25 | std.log.err("{s}: {s}", .{ entry.basename, @tagName(parse_error.tag) }); 26 | } 27 | any_bad = true; 28 | } 29 | 30 | total_count += ast.nodes.len; 31 | }, 32 | else => continue, 33 | }; 34 | 35 | try std.testing.expect(!any_bad); 36 | try std.testing.expect(total_count >= 1_000_000); 37 | } 38 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/counting_writer.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const io = std.io; 3 | const testing = std.testing; 4 | 5 | /// A Writer that counts how many bytes has been written to it. 6 | pub fn CountingWriter(comptime WriterType: type) type { 7 | return struct { 8 | bytes_written: u64, 9 | child_stream: WriterType, 10 | 11 | pub const Error = WriterType.Error; 12 | pub const Writer = io.Writer(*Self, Error, write); 13 | 14 | const Self = @This(); 15 | 16 | pub fn write(self: *Self, bytes: []const u8) Error!usize { 17 | const amt = try self.child_stream.write(bytes); 18 | self.bytes_written += amt; 19 | return amt; 20 | } 21 | 22 | pub fn writer(self: *Self) Writer { 23 | return .{ .context = self }; 24 | } 25 | }; 26 | } 27 | 28 | pub fn countingWriter(child_stream: anytype) CountingWriter(@TypeOf(child_stream)) { 29 | return .{ .bytes_written = 0, .child_stream = child_stream }; 30 | } 31 | 32 | test "io.CountingWriter" { 33 | var counting_stream = countingWriter(std.io.null_writer); 34 | const stream = counting_stream.writer(); 35 | 36 | const bytes = "yay" ** 100; 37 | stream.writeAll(bytes) catch unreachable; 38 | try testing.expect(counting_stream.bytes_written == bytes.len); 39 | } 40 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/hii_popup_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Guid = uefi.Guid; 3 | const Status = uefi.Status; 4 | const hii = uefi.protocols.hii; 5 | 6 | /// Display a popup window 7 | pub const HIIPopupProtocol = extern struct { 8 | revision: u64, 9 | _create_popup: fn (*const HIIPopupProtocol, HIIPopupStyle, HIIPopupType, hii.HIIHandle, u16, ?*HIIPopupSelection) callconv(.C) Status, 10 | 11 | /// Displays a popup window. 12 | pub fn createPopup(self: *const HIIPopupProtocol, style: HIIPopupStyle, popup_type: HIIPopupType, handle: hii.HIIHandle, msg: u16, user_selection: ?*HIIPopupSelection) Status { 13 | return self._create_popup(self, style, popup_type, handle, msg, user_selection); 14 | } 15 | 16 | pub const guid align(8) = Guid{ 17 | .time_low = 0x4311edc0, 18 | .time_mid = 0x6054, 19 | .time_high_and_version = 0x46d4, 20 | .clock_seq_high_and_reserved = 0x9e, 21 | .clock_seq_low = 0x40, 22 | .node = [_]u8{ 0x89, 0x3e, 0xa9, 0x52, 0xfc, 0xcc }, 23 | }; 24 | }; 25 | 26 | pub const HIIPopupStyle = enum(u32) { 27 | Info, 28 | Warning, 29 | Error, 30 | }; 31 | 32 | pub const HIIPopupType = enum(u32) { 33 | Ok, 34 | Cancel, 35 | YesNo, 36 | YesNoCancel, 37 | }; 38 | 39 | pub const HIIPopupSelection = enum(u32) { 40 | Ok, 41 | Cancel, 42 | Yes, 43 | No, 44 | }; 45 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/target/ve.zig: -------------------------------------------------------------------------------- 1 | //! This file is auto-generated by tools/update_cpu_features.zig. 2 | 3 | const std = @import("../std.zig"); 4 | const CpuFeature = std.Target.Cpu.Feature; 5 | const CpuModel = std.Target.Cpu.Model; 6 | 7 | pub const Feature = enum { 8 | vpu, 9 | }; 10 | 11 | pub const featureSet = CpuFeature.feature_set_fns(Feature).featureSet; 12 | pub const featureSetHas = CpuFeature.feature_set_fns(Feature).featureSetHas; 13 | pub const featureSetHasAny = CpuFeature.feature_set_fns(Feature).featureSetHasAny; 14 | pub const featureSetHasAll = CpuFeature.feature_set_fns(Feature).featureSetHasAll; 15 | 16 | pub const all_features = blk: { 17 | const len = @typeInfo(Feature).Enum.fields.len; 18 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); 19 | var result: [len]CpuFeature = undefined; 20 | result[@intFromEnum(Feature.vpu)] = .{ 21 | .llvm_name = "vpu", 22 | .description = "Enable the VPU", 23 | .dependencies = featureSet(&[_]Feature{}), 24 | }; 25 | const ti = @typeInfo(Feature); 26 | for (result, 0..) |*elem, i| { 27 | elem.index = i; 28 | elem.name = ti.Enum.fields[i].name; 29 | } 30 | break :blk result; 31 | }; 32 | 33 | pub const cpu = struct { 34 | pub const generic = CpuModel{ 35 | .name = "generic", 36 | .llvm_name = "generic", 37 | .features = featureSet(&[_]Feature{}), 38 | }; 39 | }; 40 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/counting_reader.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const io = std.io; 3 | const testing = std.testing; 4 | 5 | /// A Reader that counts how many bytes has been read from it. 6 | pub fn CountingReader(comptime ReaderType: anytype) type { 7 | return struct { 8 | child_reader: ReaderType, 9 | bytes_read: u64 = 0, 10 | 11 | pub const Error = ReaderType.Error; 12 | pub const Reader = io.Reader(*@This(), Error, read); 13 | 14 | pub fn read(self: *@This(), buf: []u8) Error!usize { 15 | const amt = try self.child_reader.read(buf); 16 | self.bytes_read += amt; 17 | return amt; 18 | } 19 | 20 | pub fn reader(self: *@This()) Reader { 21 | return .{ .context = self }; 22 | } 23 | }; 24 | } 25 | 26 | pub fn countingReader(reader: anytype) CountingReader(@TypeOf(reader)) { 27 | return .{ .child_reader = reader }; 28 | } 29 | 30 | test "io.CountingReader" { 31 | const bytes = "yay" ** 100; 32 | var fbs = io.fixedBufferStream(bytes); 33 | 34 | var counting_stream = countingReader(fbs.reader()); 35 | const stream = counting_stream.reader(); 36 | 37 | //read and discard all bytes 38 | while (stream.readByte()) |_| {} else |err| { 39 | try testing.expect(err == error.EndOfStream); 40 | } 41 | 42 | try testing.expect(counting_stream.bytes_read == bytes.len); 43 | } 44 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatunditf_test.zig: -------------------------------------------------------------------------------- 1 | const __floatunditf = @import("floatunditf.zig").__floatunditf; 2 | 3 | fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void { 4 | const x = __floatunditf(a); 5 | 6 | const x_repr = @as(u128, @bitCast(x)); 7 | const x_hi = @as(u64, @intCast(x_repr >> 64)); 8 | const x_lo = @as(u64, @truncate(x_repr)); 9 | 10 | if (x_hi == expected_hi and x_lo == expected_lo) { 11 | return; 12 | } 13 | // nan repr 14 | else if (expected_hi == 0x7fff800000000000 and expected_lo == 0x0) { 15 | if ((x_hi & 0x7fff000000000000) == 0x7fff000000000000 and ((x_hi & 0xffffffffffff) > 0 or x_lo > 0)) { 16 | return; 17 | } 18 | } 19 | 20 | @panic("__floatunditf test failure"); 21 | } 22 | 23 | test "floatunditf" { 24 | try test__floatunditf(0xffffffffffffffff, 0x403effffffffffff, 0xfffe000000000000); 25 | try test__floatunditf(0xfffffffffffffffe, 0x403effffffffffff, 0xfffc000000000000); 26 | try test__floatunditf(0x8000000000000000, 0x403e000000000000, 0x0); 27 | try test__floatunditf(0x7fffffffffffffff, 0x403dffffffffffff, 0xfffc000000000000); 28 | try test__floatunditf(0x123456789abcdef1, 0x403b23456789abcd, 0xef10000000000000); 29 | try test__floatunditf(0x2, 0x4000000000000000, 0x0); 30 | try test__floatunditf(0x1, 0x3fff000000000000, 0x0); 31 | try test__floatunditf(0x0, 0x0, 0x0); 32 | } 33 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/modti3_test.zig: -------------------------------------------------------------------------------- 1 | const __modti3 = @import("modti3.zig").__modti3; 2 | const testing = @import("std").testing; 3 | 4 | fn test__modti3(a: i128, b: i128, expected: i128) !void { 5 | const x = __modti3(a, b); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "modti3" { 10 | try test__modti3(0, 1, 0); 11 | try test__modti3(0, -1, 0); 12 | try test__modti3(5, 3, 2); 13 | try test__modti3(5, -3, 2); 14 | try test__modti3(-5, 3, -2); 15 | try test__modti3(-5, -3, -2); 16 | 17 | try test__modti3(0x8000000000000000, 1, 0x0); 18 | try test__modti3(0x8000000000000000, -1, 0x0); 19 | try test__modti3(0x8000000000000000, 2, 0x0); 20 | try test__modti3(0x8000000000000000, -2, 0x0); 21 | try test__modti3(0x8000000000000000, 3, 2); 22 | try test__modti3(0x8000000000000000, -3, 2); 23 | 24 | try test__modti3(make_ti(0x8000000000000000, 0), 1, 0x0); 25 | try test__modti3(make_ti(0x8000000000000000, 0), -1, 0x0); 26 | try test__modti3(make_ti(0x8000000000000000, 0), 2, 0x0); 27 | try test__modti3(make_ti(0x8000000000000000, 0), -2, 0x0); 28 | try test__modti3(make_ti(0x8000000000000000, 0), 3, -2); 29 | try test__modti3(make_ti(0x8000000000000000, 0), -3, -2); 30 | } 31 | 32 | fn make_ti(high: u64, low: u64) i128 { 33 | var result: u128 = high; 34 | result <<= 64; 35 | result |= low; 36 | return @as(i128, @bitCast(result)); 37 | } 38 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/target/arc.zig: -------------------------------------------------------------------------------- 1 | //! This file is auto-generated by tools/update_cpu_features.zig. 2 | 3 | const std = @import("../std.zig"); 4 | const CpuFeature = std.Target.Cpu.Feature; 5 | const CpuModel = std.Target.Cpu.Model; 6 | 7 | pub const Feature = enum { 8 | norm, 9 | }; 10 | 11 | pub const featureSet = CpuFeature.feature_set_fns(Feature).featureSet; 12 | pub const featureSetHas = CpuFeature.feature_set_fns(Feature).featureSetHas; 13 | pub const featureSetHasAny = CpuFeature.feature_set_fns(Feature).featureSetHasAny; 14 | pub const featureSetHasAll = CpuFeature.feature_set_fns(Feature).featureSetHasAll; 15 | 16 | pub const all_features = blk: { 17 | const len = @typeInfo(Feature).Enum.fields.len; 18 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); 19 | var result: [len]CpuFeature = undefined; 20 | result[@intFromEnum(Feature.norm)] = .{ 21 | .llvm_name = "norm", 22 | .description = "Enable support for norm instruction.", 23 | .dependencies = featureSet(&[_]Feature{}), 24 | }; 25 | const ti = @typeInfo(Feature); 26 | for (result, 0..) |*elem, i| { 27 | elem.index = i; 28 | elem.name = ti.Enum.fields[i].name; 29 | } 30 | break :blk result; 31 | }; 32 | 33 | pub const cpu = struct { 34 | pub const generic = CpuModel{ 35 | .name = "generic", 36 | .llvm_name = "generic", 37 | .features = featureSet(&[_]Feature{}), 38 | }; 39 | }; 40 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/find_byte_writer.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const io = std.io; 3 | const assert = std.debug.assert; 4 | 5 | /// A Writer that returns whether the given character has been written to it. 6 | /// The contents are not written to anything. 7 | pub fn FindByteWriter(comptime UnderlyingWriter: type) type { 8 | return struct { 9 | const Self = @This(); 10 | pub const Error = UnderlyingWriter.Error; 11 | pub const Writer = io.Writer(*Self, Error, write); 12 | 13 | underlying_writer: UnderlyingWriter, 14 | byte_found: bool, 15 | byte: u8, 16 | 17 | pub fn writer(self: *Self) Writer { 18 | return .{ .context = self }; 19 | } 20 | 21 | fn write(self: *Self, bytes: []const u8) Error!usize { 22 | if (!self.byte_found) { 23 | self.byte_found = blk: { 24 | for (bytes) |b| 25 | if (b == self.byte) break :blk true; 26 | break :blk false; 27 | }; 28 | } 29 | return self.underlying_writer.write(bytes); 30 | } 31 | }; 32 | } 33 | 34 | pub fn findByteWriter(byte: u8, underlying_writer: anytype) FindByteWriter(@TypeOf(underlying_writer)) { 35 | return FindByteWriter(@TypeOf(underlying_writer)){ 36 | .underlying_writer = underlying_writer, 37 | .byte = byte, 38 | .byte_found = false, 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatunsidf.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const std = @import("std"); 3 | const maxInt = std.math.maxInt; 4 | 5 | const implicitBit = @as(u64, 1) << 52; 6 | 7 | pub fn __floatunsidf(arg: u32) callconv(.C) f64 { 8 | @setRuntimeSafety(builtin.is_test); 9 | 10 | if (arg == 0) return 0.0; 11 | 12 | // The exponent is the width of abs(a) 13 | const exp = @as(u64, 31) - @clz(arg); 14 | // Shift a into the significand field and clear the implicit bit 15 | const shift = @as(u6, @intCast(52 - exp)); 16 | const mant = @as(u64, arg) << shift ^ implicitBit; 17 | 18 | return @as(f64, @bitCast(mant | (exp + 1023) << 52)); 19 | } 20 | 21 | pub fn __aeabi_ui2d(arg: u32) callconv(.AAPCS) f64 { 22 | @setRuntimeSafety(false); 23 | return @call(.{ .modifier = .always_inline }, __floatunsidf, .{arg}); 24 | } 25 | 26 | fn test_one_floatunsidf(a: u32, expected: u64) !void { 27 | const r = __floatunsidf(a); 28 | try std.testing.expect(@as(u64, @bitCast(r)) == expected); 29 | } 30 | 31 | test "floatsidf" { 32 | // Test the produced bit pattern 33 | try test_one_floatunsidf(0, 0x0000000000000000); 34 | try test_one_floatunsidf(1, 0x3ff0000000000000); 35 | try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000); 36 | try test_one_floatunsidf(@as(u32, @intCast(0x80000000)), 0x41e0000000000000); 37 | try test_one_floatunsidf(@as(u32, @intCast(0xFFFFFFFF)), 0x41efffffffe00000); 38 | } 39 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/hash.zig: -------------------------------------------------------------------------------- 1 | const adler = @import("hash/adler.zig"); 2 | pub const Adler32 = adler.Adler32; 3 | 4 | const auto_hash = @import("hash/auto_hash.zig"); 5 | pub const autoHash = auto_hash.autoHash; 6 | pub const autoHashStrat = auto_hash.hash; 7 | pub const Strategy = auto_hash.HashStrategy; 8 | 9 | // pub for polynomials + generic crc32 construction 10 | pub const crc = @import("hash/crc.zig"); 11 | pub const Crc32 = crc.Crc32; 12 | 13 | const fnv = @import("hash/fnv.zig"); 14 | pub const Fnv1a_32 = fnv.Fnv1a_32; 15 | pub const Fnv1a_64 = fnv.Fnv1a_64; 16 | pub const Fnv1a_128 = fnv.Fnv1a_128; 17 | 18 | const siphash = @import("crypto/siphash.zig"); 19 | pub const SipHash64 = siphash.SipHash64; 20 | pub const SipHash128 = siphash.SipHash128; 21 | 22 | pub const murmur = @import("hash/murmur.zig"); 23 | pub const Murmur2_32 = murmur.Murmur2_32; 24 | 25 | pub const Murmur2_64 = murmur.Murmur2_64; 26 | pub const Murmur3_32 = murmur.Murmur3_32; 27 | 28 | pub const cityhash = @import("hash/cityhash.zig"); 29 | pub const CityHash32 = cityhash.CityHash32; 30 | pub const CityHash64 = cityhash.CityHash64; 31 | 32 | const wyhash = @import("hash/wyhash.zig"); 33 | pub const Wyhash = wyhash.Wyhash; 34 | 35 | test "hash" { 36 | _ = @import("hash/adler.zig"); 37 | _ = @import("hash/auto_hash.zig"); 38 | _ = @import("hash/crc.zig"); 39 | _ = @import("hash/fnv.zig"); 40 | _ = @import("hash/murmur.zig"); 41 | _ = @import("hash/cityhash.zig"); 42 | _ = @import("hash/wyhash.zig"); 43 | } 44 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunsdfsi_test.zig: -------------------------------------------------------------------------------- 1 | const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi; 2 | const testing = @import("std").testing; 3 | 4 | fn test__fixunsdfsi(a: f64, expected: u32) !void { 5 | const x = __fixunsdfsi(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "fixunsdfsi" { 10 | try test__fixunsdfsi(0.0, 0); 11 | 12 | try test__fixunsdfsi(0.5, 0); 13 | try test__fixunsdfsi(0.99, 0); 14 | try test__fixunsdfsi(1.0, 1); 15 | try test__fixunsdfsi(1.5, 1); 16 | try test__fixunsdfsi(1.99, 1); 17 | try test__fixunsdfsi(2.0, 2); 18 | try test__fixunsdfsi(2.01, 2); 19 | try test__fixunsdfsi(-0.5, 0); 20 | try test__fixunsdfsi(-0.99, 0); 21 | try test__fixunsdfsi(-1.0, 0); 22 | try test__fixunsdfsi(-1.5, 0); 23 | try test__fixunsdfsi(-1.99, 0); 24 | try test__fixunsdfsi(-2.0, 0); 25 | try test__fixunsdfsi(-2.01, 0); 26 | 27 | try test__fixunsdfsi(0x1.000000p+31, 0x80000000); 28 | try test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF); 29 | try test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00); 30 | try test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80); 31 | try test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00); 32 | 33 | try test__fixunsdfsi(-0x1.FFFFFEp+30, 0); 34 | try test__fixunsdfsi(-0x1.FFFFFCp+30, 0); 35 | 36 | try test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF); 37 | try test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF); 38 | try test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE); 39 | } 40 | -------------------------------------------------------------------------------- /src/std-hash-map/project-euler-14-main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const bench = @import("root"); 3 | 4 | pub fn setup(_: std.mem.Allocator, _: *bench.Options) !void {} 5 | 6 | pub fn run(gpa: std.mem.Allocator, _: void) !void { 7 | var cache = std.AutoHashMap(u64, u64).init(gpa); 8 | defer cache.deinit(); 9 | 10 | try cache.ensureTotalCapacity(2_050_000); 11 | 12 | var x: u64 = 0; 13 | var maxx: u64 = 0; 14 | var maxl: u64 = 0; 15 | while (x < 1_000_000) : (x += 1) { 16 | const l = length(&cache, x); 17 | if (l > maxl) { 18 | maxl = l; 19 | maxx = x; 20 | } 21 | } 22 | if (maxx != 837_799) @panic("bad maxx"); 23 | if (maxl != 524) @panic("bad maxl"); 24 | 25 | { 26 | var total: u64 = 0; 27 | var it = cache.iterator(); 28 | while (it.next()) |item| { 29 | total +%= item.key_ptr.*; 30 | total +%= item.value_ptr.*; 31 | } 32 | if (total != 1_238_720_324_0855) @panic("bad total"); 33 | } 34 | } 35 | 36 | fn step(x: u64) u64 { 37 | if (x & 1 > 0) { 38 | return 3 * x + 1; 39 | } else { 40 | return x / 2; 41 | } 42 | } 43 | 44 | fn length(cache: *std.AutoHashMap(u64, u64), x: u64) u64 { 45 | if (x <= 1) return 0; 46 | if (cache.get(x)) |e| { 47 | return e; 48 | } else { 49 | const next = step(x); 50 | const len = 1 + length(cache, next); 51 | cache.putAssumeCapacityNoClobber(x, len); 52 | return len; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/buffered_writer.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const io = std.io; 3 | 4 | pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) type { 5 | return struct { 6 | unbuffered_writer: WriterType, 7 | fifo: FifoType = FifoType.init(), 8 | 9 | pub const Error = WriterType.Error; 10 | pub const Writer = io.Writer(*Self, Error, write); 11 | 12 | const Self = @This(); 13 | const FifoType = std.fifo.LinearFifo(u8, std.fifo.LinearFifoBufferType{ .Static = buffer_size }); 14 | 15 | pub fn flush(self: *Self) !void { 16 | while (true) { 17 | const slice = self.fifo.readableSlice(0); 18 | if (slice.len == 0) break; 19 | try self.unbuffered_writer.writeAll(slice); 20 | self.fifo.discard(slice.len); 21 | } 22 | } 23 | 24 | pub fn writer(self: *Self) Writer { 25 | return .{ .context = self }; 26 | } 27 | 28 | pub fn write(self: *Self, bytes: []const u8) Error!usize { 29 | if (bytes.len >= self.fifo.writableLength()) { 30 | try self.flush(); 31 | return self.unbuffered_writer.write(bytes); 32 | } 33 | self.fifo.writeAssumeCapacity(bytes); 34 | return bytes.len; 35 | } 36 | }; 37 | } 38 | 39 | pub fn bufferedWriter(underlying_stream: anytype) BufferedWriter(4096, @TypeOf(underlying_stream)) { 40 | return .{ .unbuffered_writer = underlying_stream }; 41 | } 42 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunsdfdi_test.zig: -------------------------------------------------------------------------------- 1 | const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi; 2 | const testing = @import("std").testing; 3 | 4 | fn test__fixunsdfdi(a: f64, expected: u64) !void { 5 | const x = __fixunsdfdi(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "fixunsdfdi" { 10 | //test__fixunsdfdi(0.0, 0); 11 | //test__fixunsdfdi(0.5, 0); 12 | //test__fixunsdfdi(0.99, 0); 13 | try test__fixunsdfdi(1.0, 1); 14 | try test__fixunsdfdi(1.5, 1); 15 | try test__fixunsdfdi(1.99, 1); 16 | try test__fixunsdfdi(2.0, 2); 17 | try test__fixunsdfdi(2.01, 2); 18 | try test__fixunsdfdi(-0.5, 0); 19 | try test__fixunsdfdi(-0.99, 0); 20 | try test__fixunsdfdi(-1.0, 0); 21 | try test__fixunsdfdi(-1.5, 0); 22 | try test__fixunsdfdi(-1.99, 0); 23 | try test__fixunsdfdi(-2.0, 0); 24 | try test__fixunsdfdi(-2.01, 0); 25 | 26 | try test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); 27 | try test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); 28 | 29 | try test__fixunsdfdi(-0x1.FFFFFEp+62, 0); 30 | try test__fixunsdfdi(-0x1.FFFFFCp+62, 0); 31 | 32 | try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800); 33 | try test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000); 34 | try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); 35 | try test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); 36 | 37 | try test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0); 38 | try test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0); 39 | } 40 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/linux/ioctl.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | 3 | const bits = switch (@import("builtin").cpu.arch) { 4 | .mips, 5 | .mipsel, 6 | .mips64, 7 | .mips64el, 8 | .powerpc, 9 | .powerpcle, 10 | .powerpc64, 11 | .powerpc64le, 12 | .sparc, 13 | .sparcv9, 14 | .sparcel, 15 | => .{ .size = 13, .dir = 3, .none = 1, .read = 2, .write = 4 }, 16 | else => .{ .size = 14, .dir = 2, .none = 0, .read = 2, .write = 1 }, 17 | }; 18 | 19 | const Direction = std.meta.Int(.unsigned, bits.dir); 20 | 21 | pub const Request = packed struct { 22 | nr: u8, 23 | io_type: u8, 24 | size: std.meta.Int(.unsigned, bits.size), 25 | dir: Direction, 26 | }; 27 | 28 | fn io_impl(dir: Direction, io_type: u8, nr: u8, comptime T: type) u32 { 29 | const request = Request{ 30 | .dir = dir, 31 | .size = @sizeOf(T), 32 | .io_type = io_type, 33 | .nr = nr, 34 | }; 35 | return @as(u32, @bitCast(request)); 36 | } 37 | 38 | pub fn IO(io_type: u8, nr: u8) u32 { 39 | return io_impl(bits.none, io_type, nr, void); 40 | } 41 | 42 | pub fn IOR(io_type: u8, nr: u8, comptime T: type) u32 { 43 | return io_impl(bits.read, io_type, nr, T); 44 | } 45 | 46 | pub fn IOW(io_type: u8, nr: u8, comptime T: type) u32 { 47 | return io_impl(bits.write, io_type, nr, T); 48 | } 49 | 50 | pub fn IOWR(io_type: u8, nr: u8, comptime T: type) u32 { 51 | return io_impl(bits.read | bits.write, io_type, nr, T); 52 | } 53 | 54 | comptime { 55 | std.debug.assert(@bitSizeOf(Request) == 32); 56 | } 57 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatdisf_test.zig: -------------------------------------------------------------------------------- 1 | const __floatdisf = @import("floatXisf.zig").__floatdisf; 2 | const testing = @import("std").testing; 3 | 4 | fn test__floatdisf(a: i64, expected: f32) !void { 5 | const x = __floatdisf(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "floatdisf" { 10 | try test__floatdisf(0, 0.0); 11 | try test__floatdisf(1, 1.0); 12 | try test__floatdisf(2, 2.0); 13 | try test__floatdisf(-1, -1.0); 14 | try test__floatdisf(-2, -2.0); 15 | try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); 16 | try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); 17 | try test__floatdisf(0x8000008000000000, -0x1.FFFFFEp+62); 18 | try test__floatdisf(0x8000010000000000, -0x1.FFFFFCp+62); 19 | try test__floatdisf(0x8000000000000000, -0x1.000000p+63); 20 | try test__floatdisf(0x8000000000000001, -0x1.000000p+63); 21 | try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); 22 | try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); 23 | try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); 24 | try test__floatdisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50); 25 | try test__floatdisf(0x0007FB72EC000000, 0x1.FEDCBCp+50); 26 | try test__floatdisf(0x0007FB72E8000001, 0x1.FEDCBAp+50); 27 | try test__floatdisf(0x0007FB72E6000000, 0x1.FEDCBAp+50); 28 | try test__floatdisf(0x0007FB72E7000000, 0x1.FEDCBAp+50); 29 | try test__floatdisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50); 30 | try test__floatdisf(0x0007FB72E4000001, 0x1.FEDCBAp+50); 31 | try test__floatdisf(0x0007FB72E4000000, 0x1.FEDCB8p+50); 32 | } 33 | -------------------------------------------------------------------------------- /src/tetris/tetris/src/png.zig: -------------------------------------------------------------------------------- 1 | const c = @import("c.zig"); 2 | 3 | pub const PngImage = struct { 4 | width: u32, 5 | height: u32, 6 | pitch: u32, 7 | raw: []u8, 8 | 9 | pub fn destroy(pi: *PngImage) void { 10 | c.stbi_image_free(pi.raw.ptr); 11 | } 12 | 13 | pub fn create(compressed_bytes: []const u8) !PngImage { 14 | var pi: PngImage = undefined; 15 | 16 | var width: c_int = undefined; 17 | var height: c_int = undefined; 18 | 19 | if (c.stbi_info_from_memory(compressed_bytes.ptr, @as(c_int, @intCast(compressed_bytes.len)), &width, &height, null) == 0) { 20 | return error.NotPngFile; 21 | } 22 | 23 | if (width <= 0 or height <= 0) return error.NoPixels; 24 | pi.width = @as(u32, @intCast(width)); 25 | pi.height = @as(u32, @intCast(height)); 26 | 27 | // Not validating channel_count because it gets auto-converted to 4 28 | 29 | if (c.stbi_is_16_bit_from_memory(compressed_bytes.ptr, @as(c_int, @intCast(compressed_bytes.len))) != 0) { 30 | return error.InvalidFormat; 31 | } 32 | const bits_per_channel = 8; 33 | const channel_count = 4; 34 | 35 | c.stbi_set_flip_vertically_on_load(1); 36 | const image_data = c.stbi_load_from_memory(compressed_bytes.ptr, @as(c_int, @intCast(compressed_bytes.len)), &width, &height, null, channel_count); 37 | 38 | if (image_data == null) return error.NoMem; 39 | 40 | pi.pitch = pi.width * bits_per_channel * channel_count / 8; 41 | pi.raw = image_data[0 .. pi.height * pi.pitch]; 42 | 43 | return pi; 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/windows/gdi32.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | const windows = std.os.windows; 3 | const BOOL = windows.BOOL; 4 | const DWORD = windows.DWORD; 5 | const WINAPI = windows.WINAPI; 6 | const HDC = windows.HDC; 7 | const HGLRC = windows.HGLRC; 8 | const WORD = windows.WORD; 9 | const BYTE = windows.BYTE; 10 | 11 | pub const PIXELFORMATDESCRIPTOR = extern struct { 12 | nSize: WORD = @sizeOf(PIXELFORMATDESCRIPTOR), 13 | nVersion: WORD, 14 | dwFlags: DWORD, 15 | iPixelType: BYTE, 16 | cColorBits: BYTE, 17 | cRedBits: BYTE, 18 | cRedShift: BYTE, 19 | cGreenBits: BYTE, 20 | cGreenShift: BYTE, 21 | cBlueBits: BYTE, 22 | cBlueShift: BYTE, 23 | cAlphaBits: BYTE, 24 | cAlphaShift: BYTE, 25 | cAccumBits: BYTE, 26 | cAccumRedBits: BYTE, 27 | cAccumGreenBits: BYTE, 28 | cAccumBlueBits: BYTE, 29 | cAccumAlphaBits: BYTE, 30 | cDepthBits: BYTE, 31 | cStencilBits: BYTE, 32 | cAuxBuffers: BYTE, 33 | iLayerType: BYTE, 34 | bReserved: BYTE, 35 | dwLayerMask: DWORD, 36 | dwVisibleMask: DWORD, 37 | dwDamageMask: DWORD, 38 | }; 39 | 40 | pub extern "gdi32" fn SetPixelFormat( 41 | hdc: ?HDC, 42 | format: i32, 43 | ppfd: ?*const PIXELFORMATDESCRIPTOR, 44 | ) callconv(WINAPI) bool; 45 | 46 | pub extern "gdi32" fn ChoosePixelFormat( 47 | hdc: ?HDC, 48 | ppfd: ?*const PIXELFORMATDESCRIPTOR, 49 | ) callconv(WINAPI) i32; 50 | 51 | pub extern "gdi32" fn SwapBuffers(hdc: ?HDC) callconv(WINAPI) bool; 52 | pub extern "gdi32" fn wglCreateContext(hdc: ?HDC) callconv(WINAPI) ?HGLRC; 53 | pub extern "gdi32" fn wglMakeCurrent(hdc: ?HDC, hglrc: ?HGLRC) callconv(WINAPI) bool; 54 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/loaded_image_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Guid = uefi.Guid; 3 | const Handle = uefi.Handle; 4 | const Status = uefi.Status; 5 | const SystemTable = uefi.tables.SystemTable; 6 | const MemoryType = uefi.tables.MemoryType; 7 | const DevicePathProtocol = uefi.protocols.DevicePathProtocol; 8 | 9 | pub const LoadedImageProtocol = extern struct { 10 | revision: u32, 11 | parent_handle: Handle, 12 | system_table: *SystemTable, 13 | device_handle: ?Handle, 14 | file_path: *DevicePathProtocol, 15 | reserved: *anyopaque, 16 | load_options_size: u32, 17 | load_options: ?*anyopaque, 18 | image_base: [*]u8, 19 | image_size: u64, 20 | image_code_type: MemoryType, 21 | image_data_type: MemoryType, 22 | _unload: fn (*const LoadedImageProtocol, Handle) callconv(.C) Status, 23 | 24 | /// Unloads an image from memory. 25 | pub fn unload(self: *const LoadedImageProtocol, handle: Handle) Status { 26 | return self._unload(self, handle); 27 | } 28 | 29 | pub const guid align(8) = Guid{ 30 | .time_low = 0x5b1b31a1, 31 | .time_mid = 0x9562, 32 | .time_high_and_version = 0x11d2, 33 | .clock_seq_high_and_reserved = 0x8e, 34 | .clock_seq_low = 0x3f, 35 | .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b }, 36 | }; 37 | }; 38 | 39 | pub const loaded_image_device_path_protocol_guid align(8) = Guid{ 40 | .time_low = 0xbc62157e, 41 | .time_mid = 0x3e33, 42 | .time_high_and_version = 0x4fec, 43 | .clock_seq_high_and_reserved = 0x99, 44 | .clock_seq_low = 0x20, 45 | .node = [_]u8{ 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf }, 46 | }; 47 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/simple_pointer_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Event = uefi.Event; 3 | const Guid = uefi.Guid; 4 | const Status = uefi.Status; 5 | 6 | /// Protocol for mice 7 | pub const SimplePointerProtocol = struct { 8 | _reset: fn (*const SimplePointerProtocol, bool) callconv(.C) Status, 9 | _get_state: fn (*const SimplePointerProtocol, *SimplePointerState) callconv(.C) Status, 10 | wait_for_input: Event, 11 | mode: *SimplePointerMode, 12 | 13 | /// Resets the pointer device hardware. 14 | pub fn reset(self: *const SimplePointerProtocol, verify: bool) Status { 15 | return self._reset(self, verify); 16 | } 17 | 18 | /// Retrieves the current state of a pointer device. 19 | pub fn getState(self: *const SimplePointerProtocol, state: *SimplePointerState) Status { 20 | return self._get_state(self, state); 21 | } 22 | 23 | pub const guid align(8) = Guid{ 24 | .time_low = 0x31878c87, 25 | .time_mid = 0x0b75, 26 | .time_high_and_version = 0x11d5, 27 | .clock_seq_high_and_reserved = 0x9a, 28 | .clock_seq_low = 0x4f, 29 | .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, 30 | }; 31 | }; 32 | 33 | pub const SimplePointerMode = struct { 34 | resolution_x: u64, 35 | resolution_y: u64, 36 | resolution_z: u64, 37 | left_button: bool, 38 | right_button: bool, 39 | }; 40 | 41 | pub const SimplePointerState = struct { 42 | relative_movement_x: i32 = undefined, 43 | relative_movement_y: i32 = undefined, 44 | relative_movement_z: i32 = undefined, 45 | left_button: bool = undefined, 46 | right_button: bool = undefined, 47 | }; 48 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/crypto/errors.zig: -------------------------------------------------------------------------------- 1 | /// MAC verification failed - The tag doesn't verify for the given ciphertext and secret key 2 | pub const AuthenticationError = error{AuthenticationFailed}; 3 | 4 | /// The requested output length is too long for the chosen algorithm 5 | pub const OutputTooLongError = error{OutputTooLong}; 6 | 7 | /// Finite field operation returned the identity element 8 | pub const IdentityElementError = error{IdentityElement}; 9 | 10 | /// Encoded input cannot be decoded 11 | pub const EncodingError = error{InvalidEncoding}; 12 | 13 | /// The signature does't verify for the given message and public key 14 | pub const SignatureVerificationError = error{SignatureVerificationFailed}; 15 | 16 | /// Both a public and secret key have been provided, but they are incompatible 17 | pub const KeyMismatchError = error{KeyMismatch}; 18 | 19 | /// Encoded input is not in canonical form 20 | pub const NonCanonicalError = error{NonCanonical}; 21 | 22 | /// Square root has no solutions 23 | pub const NotSquareError = error{NotSquare}; 24 | 25 | /// Verification string doesn't match the provided password and parameters 26 | pub const PasswordVerificationError = error{PasswordVerificationFailed}; 27 | 28 | /// Parameters would be insecure to use 29 | pub const WeakParametersError = error{WeakParameters}; 30 | 31 | /// Public key would be insecure to use 32 | pub const WeakPublicKeyError = error{WeakPublicKey}; 33 | 34 | /// Any error related to cryptography operations 35 | pub const Error = AuthenticationError || OutputTooLongError || IdentityElementError || EncodingError || SignatureVerificationError || KeyMismatchError || NonCanonicalError || NotSquareError || PasswordVerificationError || WeakParametersError || WeakPublicKeyError; 36 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/isnormal.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const math = std.math; 3 | const expect = std.testing.expect; 4 | const maxInt = std.math.maxInt; 5 | 6 | // Returns whether x has a normalized representation (i.e. integer part of mantissa is 1). 7 | pub fn isNormal(x: anytype) bool { 8 | const T = @TypeOf(x); 9 | switch (T) { 10 | f16 => { 11 | const bits = @as(u16, @bitCast(x)); 12 | return (bits + (1 << 10)) & (maxInt(u16) >> 1) >= (1 << 11); 13 | }, 14 | f32 => { 15 | const bits = @as(u32, @bitCast(x)); 16 | return (bits + (1 << 23)) & (maxInt(u32) >> 1) >= (1 << 24); 17 | }, 18 | f64 => { 19 | const bits = @as(u64, @bitCast(x)); 20 | return (bits + (1 << 52)) & (maxInt(u64) >> 1) >= (1 << 53); 21 | }, 22 | f128 => { 23 | const bits = @as(u128, @bitCast(x)); 24 | return (bits + (1 << 112)) & (maxInt(u128) >> 1) >= (1 << 113); 25 | }, 26 | else => { 27 | @compileError("isNormal not implemented for " ++ @typeName(T)); 28 | }, 29 | } 30 | } 31 | 32 | test "math.isNormal" { 33 | try expect(!isNormal(math.nan(f16))); 34 | try expect(!isNormal(math.nan(f32))); 35 | try expect(!isNormal(math.nan(f64))); 36 | try expect(!isNormal(math.nan(f128))); 37 | try expect(!isNormal(@as(f16, 0))); 38 | try expect(!isNormal(@as(f32, 0))); 39 | try expect(!isNormal(@as(f64, 0))); 40 | try expect(!isNormal(@as(f128, 0))); 41 | try expect(isNormal(@as(f16, 1.0))); 42 | try expect(isNormal(@as(f32, 1.0))); 43 | try expect(isNormal(@as(f64, 1.0))); 44 | try expect(isNormal(@as(f128, 1.0))); 45 | } 46 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/limited_reader.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const io = std.io; 3 | const assert = std.debug.assert; 4 | const testing = std.testing; 5 | 6 | pub fn LimitedReader(comptime ReaderType: type) type { 7 | return struct { 8 | inner_reader: ReaderType, 9 | bytes_left: u64, 10 | 11 | pub const Error = ReaderType.Error; 12 | pub const Reader = io.Reader(*Self, Error, read); 13 | 14 | const Self = @This(); 15 | 16 | pub fn read(self: *Self, dest: []u8) Error!usize { 17 | const max_read = std.math.min(self.bytes_left, dest.len); 18 | const n = try self.inner_reader.read(dest[0..max_read]); 19 | self.bytes_left -= n; 20 | return n; 21 | } 22 | 23 | pub fn reader(self: *Self) Reader { 24 | return .{ .context = self }; 25 | } 26 | }; 27 | } 28 | 29 | /// Returns an initialised `LimitedReader` 30 | /// `bytes_left` is a `u64` to be able to take 64 bit file offsets 31 | pub fn limitedReader(inner_reader: anytype, bytes_left: u64) LimitedReader(@TypeOf(inner_reader)) { 32 | return .{ .inner_reader = inner_reader, .bytes_left = bytes_left }; 33 | } 34 | 35 | test "basic usage" { 36 | const data = "hello world"; 37 | var fbs = std.io.fixedBufferStream(data); 38 | var early_stream = limitedReader(fbs.reader(), 3); 39 | 40 | var buf: [5]u8 = undefined; 41 | try testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf)); 42 | try testing.expectEqualSlices(u8, data[0..3], buf[0..3]); 43 | try testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf)); 44 | try testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{})); 45 | } 46 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/signbit.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const math = std.math; 3 | const expect = std.testing.expect; 4 | 5 | /// Returns whether x is negative or negative 0. 6 | pub fn signbit(x: anytype) bool { 7 | const T = @TypeOf(x); 8 | return switch (T) { 9 | f16 => signbit16(x), 10 | f32 => signbit32(x), 11 | f64 => signbit64(x), 12 | f128 => signbit128(x), 13 | else => @compileError("signbit not implemented for " ++ @typeName(T)), 14 | }; 15 | } 16 | 17 | fn signbit16(x: f16) bool { 18 | const bits = @as(u16, @bitCast(x)); 19 | return bits >> 15 != 0; 20 | } 21 | 22 | fn signbit32(x: f32) bool { 23 | const bits = @as(u32, @bitCast(x)); 24 | return bits >> 31 != 0; 25 | } 26 | 27 | fn signbit64(x: f64) bool { 28 | const bits = @as(u64, @bitCast(x)); 29 | return bits >> 63 != 0; 30 | } 31 | 32 | fn signbit128(x: f128) bool { 33 | const bits = @as(u128, @bitCast(x)); 34 | return bits >> 127 != 0; 35 | } 36 | 37 | test "math.signbit" { 38 | try expect(signbit(@as(f16, 4.0)) == signbit16(4.0)); 39 | try expect(signbit(@as(f32, 4.0)) == signbit32(4.0)); 40 | try expect(signbit(@as(f64, 4.0)) == signbit64(4.0)); 41 | try expect(signbit(@as(f128, 4.0)) == signbit128(4.0)); 42 | } 43 | 44 | test "math.signbit16" { 45 | try expect(!signbit16(4.0)); 46 | try expect(signbit16(-3.0)); 47 | } 48 | 49 | test "math.signbit32" { 50 | try expect(!signbit32(4.0)); 51 | try expect(signbit32(-3.0)); 52 | } 53 | 54 | test "math.signbit64" { 55 | try expect(!signbit64(4.0)); 56 | try expect(signbit64(-3.0)); 57 | } 58 | 59 | test "math.signbit128" { 60 | try expect(!signbit128(4.0)); 61 | try expect(signbit128(-3.0)); 62 | } 63 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/c_writer.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const builtin = @import("builtin"); 3 | const io = std.io; 4 | const testing = std.testing; 5 | const os = std.os; 6 | 7 | pub const CWriter = io.Writer(*std.c.FILE, std.fs.File.WriteError, cWriterWrite); 8 | 9 | pub fn cWriter(c_file: *std.c.FILE) CWriter { 10 | return .{ .context = c_file }; 11 | } 12 | 13 | fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize { 14 | const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file); 15 | if (amt_written >= 0) return amt_written; 16 | switch (@as(os.E, @enumFromInt(std.c._errno().*))) { 17 | .SUCCESS => unreachable, 18 | .INVAL => unreachable, 19 | .FAULT => unreachable, 20 | .AGAIN => unreachable, // this is a blocking API 21 | .BADF => unreachable, // always a race condition 22 | .DESTADDRREQ => unreachable, // connect was never called 23 | .DQUOT => return error.DiskQuota, 24 | .FBIG => return error.FileTooBig, 25 | .IO => return error.InputOutput, 26 | .NOSPC => return error.NoSpaceLeft, 27 | .PERM => return error.AccessDenied, 28 | .PIPE => return error.BrokenPipe, 29 | else => |err| return os.unexpectedErrno(err), 30 | } 31 | } 32 | 33 | test { 34 | if (!builtin.link_libc or builtin.os.tag == .wasi) return error.SkipZigTest; 35 | 36 | const filename = "tmp_io_test_file.txt"; 37 | const out_file = std.c.fopen(filename, "w") orelse return error.UnableToOpenTestFile; 38 | defer { 39 | _ = std.c.fclose(out_file); 40 | std.fs.cwd().deleteFileZ(filename) catch {}; 41 | } 42 | 43 | const writer = cWriter(out_file); 44 | try writer.print("hi: {}\n", .{@as(i32, 123)}); 45 | } 46 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunssfti_test.zig: -------------------------------------------------------------------------------- 1 | const __fixunssfti = @import("fixunssfti.zig").__fixunssfti; 2 | const testing = @import("std").testing; 3 | 4 | fn test__fixunssfti(a: f32, expected: u128) !void { 5 | const x = __fixunssfti(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "fixunssfti" { 10 | try test__fixunssfti(0.0, 0); 11 | 12 | try test__fixunssfti(0.5, 0); 13 | try test__fixunssfti(0.99, 0); 14 | try test__fixunssfti(1.0, 1); 15 | try test__fixunssfti(1.5, 1); 16 | try test__fixunssfti(1.99, 1); 17 | try test__fixunssfti(2.0, 2); 18 | try test__fixunssfti(2.01, 2); 19 | try test__fixunssfti(-0.5, 0); 20 | try test__fixunssfti(-0.99, 0); 21 | 22 | try test__fixunssfti(-1.0, 0); 23 | try test__fixunssfti(-1.5, 0); 24 | try test__fixunssfti(-1.99, 0); 25 | try test__fixunssfti(-2.0, 0); 26 | try test__fixunssfti(-2.01, 0); 27 | 28 | try test__fixunssfti(0x1.FFFFFEp+63, 0xFFFFFF0000000000); 29 | try test__fixunssfti(0x1.000000p+63, 0x8000000000000000); 30 | try test__fixunssfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); 31 | try test__fixunssfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); 32 | try test__fixunssfti(0x1.FFFFFEp+127, 0xFFFFFF00000000000000000000000000); 33 | try test__fixunssfti(0x1.000000p+127, 0x80000000000000000000000000000000); 34 | try test__fixunssfti(0x1.FFFFFEp+126, 0x7FFFFF80000000000000000000000000); 35 | try test__fixunssfti(0x1.FFFFFCp+126, 0x7FFFFF00000000000000000000000000); 36 | 37 | try test__fixunssfti(-0x1.FFFFFEp+62, 0x0000000000000000); 38 | try test__fixunssfti(-0x1.FFFFFCp+62, 0x0000000000000000); 39 | try test__fixunssfti(-0x1.FFFFFEp+126, 0x0000000000000000); 40 | try test__fixunssfti(-0x1.FFFFFCp+126, 0x0000000000000000); 41 | } 42 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/event/rwlocked.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const RwLock = std.event.RwLock; 3 | 4 | /// Thread-safe async/await RW lock that protects one piece of data. 5 | /// Functions which are waiting for the lock are suspended, and 6 | /// are resumed when the lock is released, in order. 7 | pub fn RwLocked(comptime T: type) type { 8 | return struct { 9 | lock: RwLock, 10 | locked_data: T, 11 | 12 | const Self = @This(); 13 | 14 | pub const HeldReadLock = struct { 15 | value: *const T, 16 | held: RwLock.HeldRead, 17 | 18 | pub fn release(self: HeldReadLock) void { 19 | self.held.release(); 20 | } 21 | }; 22 | 23 | pub const HeldWriteLock = struct { 24 | value: *T, 25 | held: RwLock.HeldWrite, 26 | 27 | pub fn release(self: HeldWriteLock) void { 28 | self.held.release(); 29 | } 30 | }; 31 | 32 | pub fn init(data: T) Self { 33 | return Self{ 34 | .lock = RwLock.init(), 35 | .locked_data = data, 36 | }; 37 | } 38 | 39 | pub fn deinit(self: *Self) void { 40 | self.lock.deinit(); 41 | } 42 | 43 | pub fn acquireRead(self: *Self) callconv(.Async) HeldReadLock { 44 | return HeldReadLock{ 45 | .held = self.lock.acquireRead(), 46 | .value = &self.locked_data, 47 | }; 48 | } 49 | 50 | pub fn acquireWrite(self: *Self) callconv(.Async) HeldWriteLock { 51 | return HeldWriteLock{ 52 | .held = self.lock.acquireWrite(), 53 | .value = &self.locked_data, 54 | }; 55 | } 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/build/CheckFileStep.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const build = std.build; 3 | const Step = build.Step; 4 | const Builder = build.Builder; 5 | const fs = std.fs; 6 | const mem = std.mem; 7 | const warn = std.debug.warn; 8 | 9 | const CheckFileStep = @This(); 10 | 11 | pub const base_id = .check_file; 12 | 13 | step: Step, 14 | builder: *Builder, 15 | expected_matches: []const []const u8, 16 | source: build.FileSource, 17 | max_bytes: usize = 20 * 1024 * 1024, 18 | 19 | pub fn create( 20 | builder: *Builder, 21 | source: build.FileSource, 22 | expected_matches: []const []const u8, 23 | ) *CheckFileStep { 24 | const self = builder.allocator.create(CheckFileStep) catch unreachable; 25 | self.* = CheckFileStep{ 26 | .builder = builder, 27 | .step = Step.init(.check_file, "CheckFile", builder.allocator, make), 28 | .source = source.dupe(builder), 29 | .expected_matches = builder.dupeStrings(expected_matches), 30 | }; 31 | self.source.addStepDependencies(&self.step); 32 | return self; 33 | } 34 | 35 | fn make(step: *Step) !void { 36 | const self = @fieldParentPtr(CheckFileStep, "step", step); 37 | 38 | const src_path = self.source.getPath(self.builder); 39 | const contents = try fs.cwd().readFileAlloc(self.builder.allocator, src_path, self.max_bytes); 40 | 41 | for (self.expected_matches) |expected_match| { 42 | if (mem.indexOf(u8, contents, expected_match) == null) { 43 | warn( 44 | \\ 45 | \\========= Expected to find: =================== 46 | \\{s} 47 | \\========= But file does not contain it: ======= 48 | \\{s} 49 | \\ 50 | , .{ expected_match, contents }); 51 | return error.TestFailed; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/muldi3.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const builtin = @import("builtin"); 3 | const is_test = builtin.is_test; 4 | const native_endian = builtin.cpu.arch.endian(); 5 | 6 | // Ported from 7 | // https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c 8 | 9 | const dwords = extern union { 10 | all: i64, 11 | s: switch (native_endian) { 12 | .Little => extern struct { 13 | low: u32, 14 | high: u32, 15 | }, 16 | .Big => extern struct { 17 | high: u32, 18 | low: u32, 19 | }, 20 | }, 21 | }; 22 | 23 | fn __muldsi3(a: u32, b: u32) i64 { 24 | @setRuntimeSafety(is_test); 25 | 26 | const bits_in_word_2 = @sizeOf(i32) * 8 / 2; 27 | const lower_mask = (~@as(u32, 0)) >> bits_in_word_2; 28 | 29 | var r: dwords = undefined; 30 | r.s.low = (a & lower_mask) *% (b & lower_mask); 31 | var t: u32 = r.s.low >> bits_in_word_2; 32 | r.s.low &= lower_mask; 33 | t += (a >> bits_in_word_2) *% (b & lower_mask); 34 | r.s.low +%= (t & lower_mask) << bits_in_word_2; 35 | r.s.high = t >> bits_in_word_2; 36 | t = r.s.low >> bits_in_word_2; 37 | r.s.low &= lower_mask; 38 | t +%= (b >> bits_in_word_2) *% (a & lower_mask); 39 | r.s.low +%= (t & lower_mask) << bits_in_word_2; 40 | r.s.high +%= t >> bits_in_word_2; 41 | r.s.high +%= (a >> bits_in_word_2) *% (b >> bits_in_word_2); 42 | return r.all; 43 | } 44 | 45 | pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 { 46 | @setRuntimeSafety(is_test); 47 | 48 | const x = dwords{ .all = a }; 49 | const y = dwords{ .all = b }; 50 | var r = dwords{ .all = __muldsi3(x.s.low, y.s.low) }; 51 | r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high; 52 | return r.all; 53 | } 54 | 55 | test { 56 | _ = @import("muldi3_test.zig"); 57 | } 58 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/hash/fnv.zig: -------------------------------------------------------------------------------- 1 | // FNV1a - Fowler-Noll-Vo hash function 2 | // 3 | // FNV1a is a fast, non-cryptographic hash function with fairly good distribution properties. 4 | // 5 | // https://tools.ietf.org/html/draft-eastlake-fnv-14 6 | 7 | const std = @import("../std.zig"); 8 | const testing = std.testing; 9 | 10 | pub const Fnv1a_32 = Fnv1a(u32, 0x01000193, 0x811c9dc5); 11 | pub const Fnv1a_64 = Fnv1a(u64, 0x100000001b3, 0xcbf29ce484222325); 12 | pub const Fnv1a_128 = Fnv1a(u128, 0x1000000000000000000013b, 0x6c62272e07bb014262b821756295c58d); 13 | 14 | fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type { 15 | return struct { 16 | const Self = @This(); 17 | 18 | value: T, 19 | 20 | pub fn init() Self { 21 | return Self{ .value = offset }; 22 | } 23 | 24 | pub fn update(self: *Self, input: []const u8) void { 25 | for (input) |b| { 26 | self.value ^= b; 27 | self.value *%= prime; 28 | } 29 | } 30 | 31 | pub fn final(self: *Self) T { 32 | return self.value; 33 | } 34 | 35 | pub fn hash(input: []const u8) T { 36 | var c = Self.init(); 37 | c.update(input); 38 | return c.final(); 39 | } 40 | }; 41 | } 42 | 43 | test "fnv1a-32" { 44 | try testing.expect(Fnv1a_32.hash("") == 0x811c9dc5); 45 | try testing.expect(Fnv1a_32.hash("a") == 0xe40c292c); 46 | try testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968); 47 | } 48 | 49 | test "fnv1a-64" { 50 | try testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325); 51 | try testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c); 52 | try testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8); 53 | } 54 | 55 | test "fnv1a-128" { 56 | try testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d); 57 | try testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964); 58 | } 59 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/multi_writer.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const io = std.io; 3 | const testing = std.testing; 4 | 5 | /// Takes a tuple of streams, and constructs a new stream that writes to all of them 6 | pub fn MultiWriter(comptime Writers: type) type { 7 | comptime var ErrSet = error{}; 8 | inline for (@typeInfo(Writers).Struct.fields) |field| { 9 | const StreamType = field.field_type; 10 | ErrSet = ErrSet || StreamType.Error; 11 | } 12 | 13 | return struct { 14 | const Self = @This(); 15 | 16 | streams: Writers, 17 | 18 | pub const Error = ErrSet; 19 | pub const Writer = io.Writer(*Self, Error, write); 20 | 21 | pub fn writer(self: *Self) Writer { 22 | return .{ .context = self }; 23 | } 24 | 25 | pub fn write(self: *Self, bytes: []const u8) Error!usize { 26 | var batch = std.event.Batch(Error!void, self.streams.len, .auto_async).init(); 27 | comptime var i = 0; 28 | inline while (i < self.streams.len) : (i += 1) { 29 | const stream = self.streams[i]; 30 | // TODO: remove ptrCast: https://github.com/ziglang/zig/issues/5258 31 | batch.add(@as(anyframe->Error!void, @ptrCast(&async stream.writeAll(bytes)))); 32 | } 33 | try batch.wait(); 34 | return bytes.len; 35 | } 36 | }; 37 | } 38 | 39 | pub fn multiWriter(streams: anytype) MultiWriter(@TypeOf(streams)) { 40 | return .{ .streams = streams }; 41 | } 42 | 43 | test "MultiWriter" { 44 | var buf1: [255]u8 = undefined; 45 | var fbs1 = io.fixedBufferStream(&buf1); 46 | var buf2: [255]u8 = undefined; 47 | var fbs2 = io.fixedBufferStream(&buf2); 48 | var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() }); 49 | try stream.writer().print("HI", .{}); 50 | try testing.expectEqualSlices(u8, "HI", fbs1.getWritten()); 51 | try testing.expectEqualSlices(u8, "HI", fbs2.getWritten()); 52 | } 53 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/x/net/ip.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../../std.zig"); 2 | 3 | const fmt = std.fmt; 4 | 5 | const IPv4 = std.x.os.IPv4; 6 | const IPv6 = std.x.os.IPv6; 7 | const Socket = std.x.os.Socket; 8 | 9 | /// A generic IP abstraction. 10 | const ip = @This(); 11 | 12 | /// A union of all eligible types of IP addresses. 13 | pub const Address = union(enum) { 14 | ipv4: IPv4.Address, 15 | ipv6: IPv6.Address, 16 | 17 | /// Instantiate a new address with a IPv4 host and port. 18 | pub fn initIPv4(host: IPv4, port: u16) Address { 19 | return .{ .ipv4 = .{ .host = host, .port = port } }; 20 | } 21 | 22 | /// Instantiate a new address with a IPv6 host and port. 23 | pub fn initIPv6(host: IPv6, port: u16) Address { 24 | return .{ .ipv6 = .{ .host = host, .port = port } }; 25 | } 26 | 27 | /// Re-interpret a generic socket address into an IP address. 28 | pub fn from(address: Socket.Address) ip.Address { 29 | return switch (address) { 30 | .ipv4 => |ipv4_address| .{ .ipv4 = ipv4_address }, 31 | .ipv6 => |ipv6_address| .{ .ipv6 = ipv6_address }, 32 | }; 33 | } 34 | 35 | /// Re-interpret an IP address into a generic socket address. 36 | pub fn into(self: ip.Address) Socket.Address { 37 | return switch (self) { 38 | .ipv4 => |ipv4_address| .{ .ipv4 = ipv4_address }, 39 | .ipv6 => |ipv6_address| .{ .ipv6 = ipv6_address }, 40 | }; 41 | } 42 | 43 | /// Implements the `std.fmt.format` API. 44 | pub fn format( 45 | self: ip.Address, 46 | comptime layout: []const u8, 47 | opts: fmt.FormatOptions, 48 | writer: anytype, 49 | ) !void { 50 | _ = opts; 51 | _ = layout; 52 | switch (self) { 53 | .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }), 54 | .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }), 55 | } 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/absolute_pointer_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Event = uefi.Event; 3 | const Guid = uefi.Guid; 4 | const Status = uefi.Status; 5 | 6 | /// Protocol for touchscreens 7 | pub const AbsolutePointerProtocol = extern struct { 8 | _reset: fn (*const AbsolutePointerProtocol, bool) callconv(.C) Status, 9 | _get_state: fn (*const AbsolutePointerProtocol, *AbsolutePointerState) callconv(.C) Status, 10 | wait_for_input: Event, 11 | mode: *AbsolutePointerMode, 12 | 13 | /// Resets the pointer device hardware. 14 | pub fn reset(self: *const AbsolutePointerProtocol, verify: bool) Status { 15 | return self._reset(self, verify); 16 | } 17 | 18 | /// Retrieves the current state of a pointer device. 19 | pub fn getState(self: *const AbsolutePointerProtocol, state: *AbsolutePointerState) Status { 20 | return self._get_state(self, state); 21 | } 22 | 23 | pub const guid align(8) = Guid{ 24 | .time_low = 0x8d59d32b, 25 | .time_mid = 0xc655, 26 | .time_high_and_version = 0x4ae9, 27 | .clock_seq_high_and_reserved = 0x9b, 28 | .clock_seq_low = 0x15, 29 | .node = [_]u8{ 0xf2, 0x59, 0x04, 0x99, 0x2a, 0x43 }, 30 | }; 31 | }; 32 | 33 | pub const AbsolutePointerMode = extern struct { 34 | absolute_min_x: u64, 35 | absolute_min_y: u64, 36 | absolute_min_z: u64, 37 | absolute_max_x: u64, 38 | absolute_max_y: u64, 39 | absolute_max_z: u64, 40 | attributes: packed struct { 41 | supports_alt_active: bool, 42 | supports_pressure_as_z: bool, 43 | _pad1: u6, 44 | _pad2: u8, 45 | _pad3: u16, 46 | }, 47 | }; 48 | 49 | pub const AbsolutePointerState = extern struct { 50 | current_x: u64, 51 | current_y: u64, 52 | current_z: u64, 53 | active_buttons: packed struct { 54 | touch_active: bool, 55 | alt_active: bool, 56 | _pad1: u6, 57 | _pad2: u8, 58 | _pad3: u16, 59 | }, 60 | }; 61 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunsdfti_test.zig: -------------------------------------------------------------------------------- 1 | const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti; 2 | const testing = @import("std").testing; 3 | 4 | fn test__fixunsdfti(a: f64, expected: u128) !void { 5 | const x = __fixunsdfti(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "fixunsdfti" { 10 | try test__fixunsdfti(0.0, 0); 11 | 12 | try test__fixunsdfti(0.5, 0); 13 | try test__fixunsdfti(0.99, 0); 14 | try test__fixunsdfti(1.0, 1); 15 | try test__fixunsdfti(1.5, 1); 16 | try test__fixunsdfti(1.99, 1); 17 | try test__fixunsdfti(2.0, 2); 18 | try test__fixunsdfti(2.01, 2); 19 | try test__fixunsdfti(-0.5, 0); 20 | try test__fixunsdfti(-0.99, 0); 21 | try test__fixunsdfti(-1.0, 0); 22 | try test__fixunsdfti(-1.5, 0); 23 | try test__fixunsdfti(-1.99, 0); 24 | try test__fixunsdfti(-2.0, 0); 25 | try test__fixunsdfti(-2.01, 0); 26 | 27 | try test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); 28 | try test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); 29 | 30 | try test__fixunsdfti(-0x1.FFFFFEp+62, 0); 31 | try test__fixunsdfti(-0x1.FFFFFCp+62, 0); 32 | 33 | try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800); 34 | try test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000); 35 | try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); 36 | try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); 37 | 38 | try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, 0xFFFFFFFFFFFFF8000000000000000000); 39 | try test__fixunsdfti(0x1.0000000000000p+127, 0x80000000000000000000000000000000); 40 | try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000); 41 | try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000); 42 | try test__fixunsdfti(0x1.0000000000000p+128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); 43 | 44 | try test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0); 45 | try test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0); 46 | } 47 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/change_detection_stream.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const io = std.io; 3 | const mem = std.mem; 4 | const assert = std.debug.assert; 5 | 6 | /// Used to detect if the data written to a stream differs from a source buffer 7 | pub fn ChangeDetectionStream(comptime WriterType: type) type { 8 | return struct { 9 | const Self = @This(); 10 | pub const Error = WriterType.Error; 11 | pub const Writer = io.Writer(*Self, Error, write); 12 | 13 | anything_changed: bool, 14 | underlying_writer: WriterType, 15 | source_index: usize, 16 | source: []const u8, 17 | 18 | pub fn writer(self: *Self) Writer { 19 | return .{ .context = self }; 20 | } 21 | 22 | fn write(self: *Self, bytes: []const u8) Error!usize { 23 | if (!self.anything_changed) { 24 | const end = self.source_index + bytes.len; 25 | if (end > self.source.len) { 26 | self.anything_changed = true; 27 | } else { 28 | const src_slice = self.source[self.source_index..end]; 29 | self.source_index += bytes.len; 30 | if (!mem.eql(u8, bytes, src_slice)) { 31 | self.anything_changed = true; 32 | } 33 | } 34 | } 35 | 36 | return self.underlying_writer.write(bytes); 37 | } 38 | 39 | pub fn changeDetected(self: *Self) bool { 40 | return self.anything_changed or (self.source_index != self.source.len); 41 | } 42 | }; 43 | } 44 | 45 | pub fn changeDetectionStream( 46 | source: []const u8, 47 | underlying_writer: anytype, 48 | ) ChangeDetectionStream(@TypeOf(underlying_writer)) { 49 | return ChangeDetectionStream(@TypeOf(underlying_writer)){ 50 | .anything_changed = false, 51 | .underlying_writer = underlying_writer, 52 | .source_index = 0, 53 | .source = source, 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/start_windows_tls.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const builtin = @import("builtin"); 3 | 4 | export var _tls_index: u32 = std.os.windows.TLS_OUT_OF_INDEXES; 5 | export var _tls_start: u8 linksection(".tls") = 0; 6 | export var _tls_end: u8 linksection(".tls$ZZZ") = 0; 7 | export var __xl_a: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLA") = null; 8 | export var __xl_z: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLZ") = null; 9 | 10 | comptime { 11 | if (builtin.target.cpu.arch == .i386) { 12 | // The __tls_array is the offset of the ThreadLocalStoragePointer field 13 | // in the TEB block whose base address held in the %fs segment. 14 | asm ( 15 | \\ .global __tls_array 16 | \\ __tls_array = 0x2C 17 | ); 18 | } 19 | } 20 | 21 | // TODO this is how I would like it to be expressed 22 | // TODO also note, ReactOS has a +1 on StartAddressOfRawData and AddressOfCallBacks. Investigate 23 | // why they do that. 24 | //export const _tls_used linksection(".rdata$T") = std.os.windows.IMAGE_TLS_DIRECTORY { 25 | // .StartAddressOfRawData = @ptrToInt(&_tls_start), 26 | // .EndAddressOfRawData = @ptrToInt(&_tls_end), 27 | // .AddressOfIndex = @ptrToInt(&_tls_index), 28 | // .AddressOfCallBacks = @ptrToInt(__xl_a), 29 | // .SizeOfZeroFill = 0, 30 | // .Characteristics = 0, 31 | //}; 32 | // This is the workaround because we can't do @ptrToInt at comptime like that. 33 | pub const IMAGE_TLS_DIRECTORY = extern struct { 34 | StartAddressOfRawData: *anyopaque, 35 | EndAddressOfRawData: *anyopaque, 36 | AddressOfIndex: *anyopaque, 37 | AddressOfCallBacks: *anyopaque, 38 | SizeOfZeroFill: u32, 39 | Characteristics: u32, 40 | }; 41 | export const _tls_used linksection(".rdata$T") = IMAGE_TLS_DIRECTORY{ 42 | .StartAddressOfRawData = &_tls_start, 43 | .EndAddressOfRawData = &_tls_end, 44 | .AddressOfIndex = &_tls_index, 45 | .AddressOfCallBacks = &__xl_a, 46 | .SizeOfZeroFill = 0, 47 | .Characteristics = 0, 48 | }; 49 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixunstfdi_test.zig: -------------------------------------------------------------------------------- 1 | const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi; 2 | const testing = @import("std").testing; 3 | 4 | fn test__fixunstfdi(a: f128, expected: u64) !void { 5 | const x = __fixunstfdi(a); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "fixunstfdi" { 10 | try test__fixunstfdi(0.0, 0); 11 | 12 | try test__fixunstfdi(0.5, 0); 13 | try test__fixunstfdi(0.99, 0); 14 | try test__fixunstfdi(1.0, 1); 15 | try test__fixunstfdi(1.5, 1); 16 | try test__fixunstfdi(1.99, 1); 17 | try test__fixunstfdi(2.0, 2); 18 | try test__fixunstfdi(2.01, 2); 19 | try test__fixunstfdi(-0.5, 0); 20 | try test__fixunstfdi(-0.99, 0); 21 | try test__fixunstfdi(-1.0, 0); 22 | try test__fixunstfdi(-1.5, 0); 23 | try test__fixunstfdi(-1.99, 0); 24 | try test__fixunstfdi(-2.0, 0); 25 | try test__fixunstfdi(-2.01, 0); 26 | 27 | try test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); 28 | try test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); 29 | 30 | try test__fixunstfdi(-0x1.FFFFFEp+62, 0); 31 | try test__fixunstfdi(-0x1.FFFFFCp+62, 0); 32 | 33 | try test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); 34 | try test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); 35 | 36 | try test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0); 37 | try test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0); 38 | 39 | try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63, 0xFFFFFFFFFFFFFFFF); 40 | try test__fixunstfdi(0x1.0000000000000002p+63, 0x8000000000000001); 41 | try test__fixunstfdi(0x1.0000000000000000p+63, 0x8000000000000000); 42 | try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62, 0x7FFFFFFFFFFFFFFF); 43 | try test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62, 0x7FFFFFFFFFFFFFFE); 44 | try test__fixunstfdi(0x1p+64, 0xFFFFFFFFFFFFFFFF); 45 | 46 | try test__fixunstfdi(-0x1.0000000000000000p+63, 0); 47 | try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62, 0); 48 | try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62, 0); 49 | } 50 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/ip6_config_protocol.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Guid = uefi.Guid; 3 | const Event = uefi.Event; 4 | const Status = uefi.Status; 5 | 6 | pub const Ip6ConfigProtocol = extern struct { 7 | _set_data: fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, usize, *const anyopaque) callconv(.C) Status, 8 | _get_data: fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, *usize, ?*const anyopaque) callconv(.C) Status, 9 | _register_data_notify: fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, Event) callconv(.C) Status, 10 | _unregister_data_notify: fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, Event) callconv(.C) Status, 11 | 12 | pub fn setData(self: *const Ip6ConfigProtocol, data_type: Ip6ConfigDataType, data_size: usize, data: *const anyopaque) Status { 13 | return self._set_data(self, data_type, data_size, data); 14 | } 15 | 16 | pub fn getData(self: *const Ip6ConfigProtocol, data_type: Ip6ConfigDataType, data_size: *usize, data: ?*const anyopaque) Status { 17 | return self._get_data(self, data_type, data_size, data); 18 | } 19 | 20 | pub fn registerDataNotify(self: *const Ip6ConfigProtocol, data_type: Ip6ConfigDataType, event: Event) Status { 21 | return self._register_data_notify(self, data_type, event); 22 | } 23 | 24 | pub fn unregisterDataNotify(self: *const Ip6ConfigProtocol, data_type: Ip6ConfigDataType, event: Event) Status { 25 | return self._unregister_data_notify(self, data_type, event); 26 | } 27 | 28 | pub const guid align(8) = Guid{ 29 | .time_low = 0x937fe521, 30 | .time_mid = 0x95ae, 31 | .time_high_and_version = 0x4d1a, 32 | .clock_seq_high_and_reserved = 0x89, 33 | .clock_seq_low = 0x29, 34 | .node = [_]u8{ 0x48, 0xbc, 0xd9, 0x0a, 0xd3, 0x1a }, 35 | }; 36 | }; 37 | 38 | pub const Ip6ConfigDataType = enum(u32) { 39 | InterfaceInfo, 40 | AltInterfaceId, 41 | Policy, 42 | DupAddrDetectTransmits, 43 | ManualAddress, 44 | Gateway, 45 | DnsServer, 46 | }; 47 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/once.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std.zig"); 2 | const builtin = @import("builtin"); 3 | const testing = std.testing; 4 | 5 | pub fn once(comptime f: fn () void) Once(f) { 6 | return Once(f){}; 7 | } 8 | 9 | /// An object that executes the function `f` just once. 10 | pub fn Once(comptime f: fn () void) type { 11 | return struct { 12 | done: bool = false, 13 | mutex: std.Thread.Mutex = std.Thread.Mutex{}, 14 | 15 | /// Call the function `f`. 16 | /// If `call` is invoked multiple times `f` will be executed only the 17 | /// first time. 18 | /// The invocations are thread-safe. 19 | pub fn call(self: *@This()) void { 20 | if (@atomicLoad(bool, &self.done, .Acquire)) 21 | return; 22 | 23 | return self.callSlow(); 24 | } 25 | 26 | fn callSlow(self: *@This()) void { 27 | @setCold(true); 28 | 29 | const T = self.mutex.acquire(); 30 | defer T.release(); 31 | 32 | // The first thread to acquire the mutex gets to run the initializer 33 | if (!self.done) { 34 | f(); 35 | @atomicStore(bool, &self.done, true, .Release); 36 | } 37 | } 38 | }; 39 | } 40 | 41 | var global_number: i32 = 0; 42 | var global_once = once(incr); 43 | 44 | fn incr() void { 45 | global_number += 1; 46 | } 47 | 48 | test "Once executes its function just once" { 49 | if (builtin.single_threaded) { 50 | global_once.call(); 51 | global_once.call(); 52 | } else { 53 | var threads: [10]std.Thread = undefined; 54 | defer for (threads) |handle| handle.join(); 55 | 56 | for (threads) |*handle| { 57 | handle.* = try std.Thread.spawn(.{}, struct { 58 | fn thread_fn(x: u8) void { 59 | _ = x; 60 | global_once.call(); 61 | } 62 | }.thread_fn, .{0}); 63 | } 64 | } 65 | 66 | try testing.expectEqual(@as(i32, 1), global_number); 67 | } 68 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/io/buffered_atomic_file.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const mem = std.mem; 3 | const fs = std.fs; 4 | const File = std.fs.File; 5 | 6 | pub const BufferedAtomicFile = struct { 7 | atomic_file: fs.AtomicFile, 8 | file_writer: File.Writer, 9 | buffered_writer: BufferedWriter, 10 | allocator: *mem.Allocator, 11 | 12 | pub const buffer_size = 4096; 13 | pub const BufferedWriter = std.io.BufferedWriter(buffer_size, File.Writer); 14 | pub const Writer = std.io.Writer(*BufferedWriter, BufferedWriter.Error, BufferedWriter.write); 15 | 16 | /// TODO when https://github.com/ziglang/zig/issues/2761 is solved 17 | /// this API will not need an allocator 18 | pub fn create( 19 | allocator: *mem.Allocator, 20 | dir: fs.Dir, 21 | dest_path: []const u8, 22 | atomic_file_options: fs.Dir.AtomicFileOptions, 23 | ) !*BufferedAtomicFile { 24 | var self = try allocator.create(BufferedAtomicFile); 25 | self.* = BufferedAtomicFile{ 26 | .atomic_file = undefined, 27 | .file_writer = undefined, 28 | .buffered_writer = undefined, 29 | .allocator = allocator, 30 | }; 31 | errdefer allocator.destroy(self); 32 | 33 | self.atomic_file = try dir.atomicFile(dest_path, atomic_file_options); 34 | errdefer self.atomic_file.deinit(); 35 | 36 | self.file_writer = self.atomic_file.file.writer(); 37 | self.buffered_writer = .{ .unbuffered_writer = self.file_writer }; 38 | return self; 39 | } 40 | 41 | /// always call destroy, even after successful finish() 42 | pub fn destroy(self: *BufferedAtomicFile) void { 43 | self.atomic_file.deinit(); 44 | self.allocator.destroy(self); 45 | } 46 | 47 | pub fn finish(self: *BufferedAtomicFile) !void { 48 | try self.buffered_writer.flush(); 49 | try self.atomic_file.finish(); 50 | } 51 | 52 | pub fn writer(self: *BufferedAtomicFile) Writer { 53 | return .{ .context = &self.buffered_writer }; 54 | } 55 | }; 56 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/ashldi3_test.zig: -------------------------------------------------------------------------------- 1 | const __ashldi3 = @import("shift.zig").__ashldi3; 2 | const testing = @import("std").testing; 3 | 4 | fn test__ashldi3(a: i64, b: i32, expected: u64) !void { 5 | const x = __ashldi3(a, b); 6 | try testing.expectEqual(@as(i64, @bitCast(expected)), x); 7 | } 8 | 9 | test "ashldi3" { 10 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 0, 0x123456789ABCDEF); 11 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 1, 0x2468ACF13579BDE); 12 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 2, 0x48D159E26AF37BC); 13 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 3, 0x91A2B3C4D5E6F78); 14 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 4, 0x123456789ABCDEF0); 15 | 16 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 28, 0x789ABCDEF0000000); 17 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 29, 0xF13579BDE0000000); 18 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 30, 0xE26AF37BC0000000); 19 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 31, 0xC4D5E6F780000000); 20 | 21 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 32, 0x89ABCDEF00000000); 22 | 23 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 33, 0x13579BDE00000000); 24 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 34, 0x26AF37BC00000000); 25 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 35, 0x4D5E6F7800000000); 26 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 36, 0x9ABCDEF000000000); 27 | 28 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 60, 0xF000000000000000); 29 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 61, 0xE000000000000000); 30 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 62, 0xC000000000000000); 31 | try test__ashldi3(@as(i64, @bitCast(@as(u64, 0x0123456789ABCDEF))), 63, 0x8000000000000000); 32 | } 33 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/fixuint.zig: -------------------------------------------------------------------------------- 1 | const is_test = @import("builtin").is_test; 2 | const Log2Int = @import("std").math.Log2Int; 3 | 4 | pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t { 5 | @setRuntimeSafety(is_test); 6 | 7 | const rep_t = switch (fp_t) { 8 | f32 => u32, 9 | f64 => u64, 10 | f128 => u128, 11 | else => unreachable, 12 | }; 13 | const typeWidth = @typeInfo(rep_t).Int.bits; 14 | const significandBits = switch (fp_t) { 15 | f32 => 23, 16 | f64 => 52, 17 | f128 => 112, 18 | else => unreachable, 19 | }; 20 | const exponentBits = (typeWidth - significandBits - 1); 21 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); 22 | const maxExponent = ((1 << exponentBits) - 1); 23 | const exponentBias = (maxExponent >> 1); 24 | 25 | const implicitBit = (@as(rep_t, 1) << significandBits); 26 | const significandMask = (implicitBit - 1); 27 | 28 | // Break a into sign, exponent, significand 29 | const aRep: rep_t = @as(rep_t, @bitCast(a)); 30 | const absMask = signBit - 1; 31 | const aAbs: rep_t = aRep & absMask; 32 | 33 | const sign = if ((aRep & signBit) != 0) @as(i32, -1) else @as(i32, 1); 34 | const exponent = @as(i32, @intCast(aAbs >> significandBits)) - exponentBias; 35 | const significand: rep_t = (aAbs & significandMask) | implicitBit; 36 | 37 | // If either the value or the exponent is negative, the result is zero. 38 | if (sign == -1 or exponent < 0) return 0; 39 | 40 | // If the value is too large for the integer type, saturate. 41 | if (@as(c_uint, @intCast(exponent)) >= @typeInfo(fixuint_t).Int.bits) return ~@as(fixuint_t, 0); 42 | 43 | // If 0 <= exponent < significandBits, right shift to get the result. 44 | // Otherwise, shift left. 45 | if (exponent < significandBits) { 46 | return @as(fixuint_t, @intCast(significand >> @as(Log2Int(rep_t), @intCast(significandBits - exponent)))); 47 | } else { 48 | return @as(fixuint_t, @intCast(significand)) << @as(Log2Int(fixuint_t), @intCast(exponent - significandBits)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/math/isfinite.zig: -------------------------------------------------------------------------------- 1 | const std = @import("../std.zig"); 2 | const math = std.math; 3 | const expect = std.testing.expect; 4 | const maxInt = std.math.maxInt; 5 | 6 | /// Returns whether x is a finite value. 7 | pub fn isFinite(x: anytype) bool { 8 | const T = @TypeOf(x); 9 | switch (T) { 10 | f16 => { 11 | const bits = @as(u16, @bitCast(x)); 12 | return bits & 0x7FFF < 0x7C00; 13 | }, 14 | f32 => { 15 | const bits = @as(u32, @bitCast(x)); 16 | return bits & 0x7FFFFFFF < 0x7F800000; 17 | }, 18 | f64 => { 19 | const bits = @as(u64, @bitCast(x)); 20 | return bits & (maxInt(u64) >> 1) < (0x7FF << 52); 21 | }, 22 | f128 => { 23 | const bits = @as(u128, @bitCast(x)); 24 | return bits & (maxInt(u128) >> 1) < (0x7FFF << 112); 25 | }, 26 | else => { 27 | @compileError("isFinite not implemented for " ++ @typeName(T)); 28 | }, 29 | } 30 | } 31 | 32 | test "math.isFinite" { 33 | try expect(isFinite(@as(f16, 0.0))); 34 | try expect(isFinite(@as(f16, -0.0))); 35 | try expect(isFinite(@as(f32, 0.0))); 36 | try expect(isFinite(@as(f32, -0.0))); 37 | try expect(isFinite(@as(f64, 0.0))); 38 | try expect(isFinite(@as(f64, -0.0))); 39 | try expect(isFinite(@as(f128, 0.0))); 40 | try expect(isFinite(@as(f128, -0.0))); 41 | 42 | try expect(!isFinite(math.inf(f16))); 43 | try expect(!isFinite(-math.inf(f16))); 44 | try expect(!isFinite(math.inf(f32))); 45 | try expect(!isFinite(-math.inf(f32))); 46 | try expect(!isFinite(math.inf(f64))); 47 | try expect(!isFinite(-math.inf(f64))); 48 | try expect(!isFinite(math.inf(f128))); 49 | try expect(!isFinite(-math.inf(f128))); 50 | 51 | try expect(!isFinite(math.nan(f16))); 52 | try expect(!isFinite(-math.nan(f16))); 53 | try expect(!isFinite(math.nan(f32))); 54 | try expect(!isFinite(-math.nan(f32))); 55 | try expect(!isFinite(math.nan(f64))); 56 | try expect(!isFinite(-math.nan(f64))); 57 | try expect(!isFinite(math.nan(f128))); 58 | try expect(!isFinite(-math.nan(f128))); 59 | } 60 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/muldi3_test.zig: -------------------------------------------------------------------------------- 1 | const __muldi3 = @import("muldi3.zig").__muldi3; 2 | const testing = @import("std").testing; 3 | 4 | fn test__muldi3(a: i64, b: i64, expected: i64) !void { 5 | const x = __muldi3(a, b); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "muldi3" { 10 | try test__muldi3(0, 0, 0); 11 | try test__muldi3(0, 1, 0); 12 | try test__muldi3(1, 0, 0); 13 | try test__muldi3(0, 10, 0); 14 | try test__muldi3(10, 0, 0); 15 | try test__muldi3(0, 81985529216486895, 0); 16 | try test__muldi3(81985529216486895, 0, 0); 17 | 18 | try test__muldi3(0, -1, 0); 19 | try test__muldi3(-1, 0, 0); 20 | try test__muldi3(0, -10, 0); 21 | try test__muldi3(-10, 0, 0); 22 | try test__muldi3(0, -81985529216486895, 0); 23 | try test__muldi3(-81985529216486895, 0, 0); 24 | 25 | try test__muldi3(1, 1, 1); 26 | try test__muldi3(1, 10, 10); 27 | try test__muldi3(10, 1, 10); 28 | try test__muldi3(1, 81985529216486895, 81985529216486895); 29 | try test__muldi3(81985529216486895, 1, 81985529216486895); 30 | 31 | try test__muldi3(1, -1, -1); 32 | try test__muldi3(1, -10, -10); 33 | try test__muldi3(-10, 1, -10); 34 | try test__muldi3(1, -81985529216486895, -81985529216486895); 35 | try test__muldi3(-81985529216486895, 1, -81985529216486895); 36 | 37 | try test__muldi3(3037000499, 3037000499, 9223372030926249001); 38 | try test__muldi3(-3037000499, 3037000499, -9223372030926249001); 39 | try test__muldi3(3037000499, -3037000499, -9223372030926249001); 40 | try test__muldi3(-3037000499, -3037000499, 9223372030926249001); 41 | 42 | try test__muldi3(4398046511103, 2097152, 9223372036852678656); 43 | try test__muldi3(-4398046511103, 2097152, -9223372036852678656); 44 | try test__muldi3(4398046511103, -2097152, -9223372036852678656); 45 | try test__muldi3(-4398046511103, -2097152, 9223372036852678656); 46 | 47 | try test__muldi3(2097152, 4398046511103, 9223372036852678656); 48 | try test__muldi3(-2097152, 4398046511103, -9223372036852678656); 49 | try test__muldi3(2097152, -4398046511103, -9223372036852678656); 50 | try test__muldi3(-2097152, -4398046511103, 9223372036852678656); 51 | } 52 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatunsisf.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const std = @import("std"); 3 | const maxInt = std.math.maxInt; 4 | 5 | const significandBits = 23; 6 | const exponentBias = 127; 7 | const implicitBit = @as(u32, 1) << significandBits; 8 | 9 | pub fn __floatunsisf(arg: u32) callconv(.C) f32 { 10 | @setRuntimeSafety(builtin.is_test); 11 | 12 | if (arg == 0) return 0.0; 13 | 14 | // The exponent is the width of abs(a) 15 | const exp = @as(u32, 31) - @clz(arg); 16 | 17 | var mantissa: u32 = undefined; 18 | if (exp <= significandBits) { 19 | // Shift a into the significand field and clear the implicit bit 20 | const shift = @as(u5, @intCast(significandBits - exp)); 21 | mantissa = @as(u32, arg) << shift ^ implicitBit; 22 | } else { 23 | const shift = @as(u5, @intCast(exp - significandBits)); 24 | // Round to the nearest number after truncation 25 | mantissa = @as(u32, arg) >> shift ^ implicitBit; 26 | // Align to the left and check if the truncated part is halfway over 27 | const round = arg << @as(u5, @intCast(31 - shift)); 28 | mantissa += @intFromBool(round > 0x80000000); 29 | // Tie to even 30 | mantissa += mantissa & 1; 31 | } 32 | 33 | // Use the addition instead of a or since we may have a carry from the 34 | // mantissa to the exponent 35 | var result = mantissa; 36 | result += (exp + exponentBias) << significandBits; 37 | 38 | return @as(f32, @bitCast(result)); 39 | } 40 | 41 | pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 { 42 | @setRuntimeSafety(false); 43 | return @call(.{ .modifier = .always_inline }, __floatunsisf, .{arg}); 44 | } 45 | 46 | fn test_one_floatunsisf(a: u32, expected: u32) !void { 47 | const r = __floatunsisf(a); 48 | try std.testing.expect(@as(u32, @bitCast(r)) == expected); 49 | } 50 | 51 | test "floatunsisf" { 52 | // Test the produced bit pattern 53 | try test_one_floatunsisf(0, 0); 54 | try test_one_floatunsisf(1, 0x3f800000); 55 | try test_one_floatunsisf(0x7FFFFFFF, 0x4f000000); 56 | try test_one_floatunsisf(0x80000000, 0x4f000000); 57 | try test_one_floatunsisf(0xFFFFFFFF, 0x4f800000); 58 | } 59 | -------------------------------------------------------------------------------- /src/hello-world/hello-x86_64-linux.zig: -------------------------------------------------------------------------------- 1 | pub fn main() void { 2 | print(); 3 | print(); 4 | print(); 5 | print(); 6 | print(); 7 | print(); 8 | print(); 9 | print(); 10 | print(); 11 | print(); 12 | print(); 13 | print(); 14 | print(); 15 | print(); 16 | print(); 17 | print(); 18 | print(); 19 | print(); 20 | print(); 21 | print(); 22 | print(); 23 | print(); 24 | print(); 25 | print(); 26 | print(); 27 | print(); 28 | print(); 29 | print(); 30 | print(); 31 | print(); 32 | print(); 33 | print(); 34 | print(); 35 | print(); 36 | print(); 37 | print(); 38 | print(); 39 | print(); 40 | print(); 41 | print(); 42 | print(); 43 | print(); 44 | print(); 45 | print(); 46 | print(); 47 | print(); 48 | print(); 49 | print(); 50 | print(); 51 | print(); 52 | print(); 53 | print(); 54 | print(); 55 | print(); 56 | print(); 57 | print(); 58 | print(); 59 | print(); 60 | print(); 61 | print(); 62 | print(); 63 | print(); 64 | print(); 65 | print(); 66 | print(); 67 | print(); 68 | print(); 69 | print(); 70 | print(); 71 | print(); 72 | print(); 73 | print(); 74 | print(); 75 | print(); 76 | print(); 77 | print(); 78 | print(); 79 | print(); 80 | print(); 81 | print(); 82 | print(); 83 | print(); 84 | print(); 85 | print(); 86 | print(); 87 | print(); 88 | print(); 89 | print(); 90 | print(); 91 | print(); 92 | print(); 93 | print(); 94 | print(); 95 | print(); 96 | print(); 97 | print(); 98 | print(); 99 | print(); 100 | print(); 101 | print(); 102 | print(); 103 | } 104 | 105 | fn print() void { 106 | asm volatile ("syscall" 107 | : 108 | : [number] "{rax}" (1), 109 | [arg1] "{rdi}" (1), 110 | [arg2] "{rsi}" (@intFromPtr("Hello, World!\n")), 111 | [arg3] "{rdx}" (14), 112 | : "rcx", "r11", "memory" 113 | ); 114 | return; 115 | } 116 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/multi3.zig: -------------------------------------------------------------------------------- 1 | const compiler_rt = @import("../compiler_rt.zig"); 2 | const std = @import("std"); 3 | const builtin = @import("builtin"); 4 | const is_test = builtin.is_test; 5 | const native_endian = builtin.cpu.arch.endian(); 6 | 7 | // Ported from git@github.com:llvm-project/llvm-project-20170507.git 8 | // ae684fad6d34858c014c94da69c15e7774a633c3 9 | // 2018-08-13 10 | 11 | pub fn __multi3(a: i128, b: i128) callconv(.C) i128 { 12 | @setRuntimeSafety(is_test); 13 | const x = twords{ .all = a }; 14 | const y = twords{ .all = b }; 15 | var r = twords{ .all = __mulddi3(x.s.low, y.s.low) }; 16 | r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high; 17 | return r.all; 18 | } 19 | 20 | const v128 = @import("std").meta.Vector(2, u64); 21 | pub fn __multi3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 { 22 | return @as(v128, @bitCast(@call(.{ .modifier = .always_inline }, __multi3, .{ 23 | @as(i128, @bitCast(a)), 24 | @as(i128, @bitCast(b)), 25 | }))); 26 | } 27 | 28 | fn __mulddi3(a: u64, b: u64) i128 { 29 | const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2; 30 | const lower_mask = ~@as(u64, 0) >> bits_in_dword_2; 31 | var r: twords = undefined; 32 | r.s.low = (a & lower_mask) *% (b & lower_mask); 33 | var t: u64 = r.s.low >> bits_in_dword_2; 34 | r.s.low &= lower_mask; 35 | t +%= (a >> bits_in_dword_2) *% (b & lower_mask); 36 | r.s.low +%= (t & lower_mask) << bits_in_dword_2; 37 | r.s.high = t >> bits_in_dword_2; 38 | t = r.s.low >> bits_in_dword_2; 39 | r.s.low &= lower_mask; 40 | t +%= (b >> bits_in_dword_2) *% (a & lower_mask); 41 | r.s.low +%= (t & lower_mask) << bits_in_dword_2; 42 | r.s.high +%= t >> bits_in_dword_2; 43 | r.s.high +%= (a >> bits_in_dword_2) *% (b >> bits_in_dword_2); 44 | return r.all; 45 | } 46 | 47 | const twords = extern union { 48 | all: i128, 49 | s: S, 50 | 51 | const S = if (native_endian == .Little) 52 | struct { 53 | low: u64, 54 | high: u64, 55 | } 56 | else 57 | struct { 58 | high: u64, 59 | low: u64, 60 | }; 61 | }; 62 | 63 | test { 64 | _ = @import("multi3_test.zig"); 65 | } 66 | -------------------------------------------------------------------------------- /src/tetris/include/epoxy/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Emmanuele Bassi 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice (including the next 12 | * paragraph) shall be included in all copies or substantial portions of the 13 | * Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file common.h 25 | * 26 | * A common header file, used to define macros and shared symbols. 27 | */ 28 | 29 | #ifndef EPOXY_COMMON_H 30 | #define EPOXY_COMMON_H 31 | 32 | #ifdef __cplusplus 33 | # define EPOXY_BEGIN_DECLS extern "C" { 34 | # define EPOXY_END_DECLS } 35 | #else 36 | # define EPOXY_BEGIN_DECLS 37 | # define EPOXY_END_DECLS 38 | #endif 39 | 40 | #ifndef EPOXY_PUBLIC 41 | # if defined(_MSC_VER) 42 | # define EPOXY_PUBLIC __declspec(dllimport) extern 43 | # else 44 | # define EPOXY_PUBLIC extern 45 | # endif 46 | #endif 47 | 48 | #if defined(_MSC_VER) && !defined(__bool_true_false_are_defined) && (_MSC_VER < 1800) 49 | typedef unsigned char bool; 50 | # define false 0 51 | # define true 1 52 | #else 53 | # include 54 | #endif 55 | 56 | EPOXY_BEGIN_DECLS 57 | 58 | EPOXY_PUBLIC bool epoxy_extension_in_string(const char *extension_list, 59 | const char *ext); 60 | 61 | EPOXY_END_DECLS 62 | 63 | #endif /* EPOXY_COMMON_H */ 64 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/divtf3_test.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const math = std.math; 3 | const testing = std.testing; 4 | 5 | const __divtf3 = @import("divtf3.zig").__divtf3; 6 | 7 | fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool { 8 | const rep = @as(u128, @bitCast(result)); 9 | const hi = @as(u64, @truncate(rep >> 64)); 10 | const lo = @as(u64, @truncate(rep)); 11 | 12 | if (hi == expectedHi and lo == expectedLo) { 13 | return true; 14 | } 15 | // test other possible NaN representation(signal NaN) 16 | else if (expectedHi == 0x7fff800000000000 and expectedLo == 0) { 17 | if ((hi & 0x7fff000000000000) == 0x7fff000000000000 and 18 | ((hi & 0xffffffffffff) > 0 or lo > 0)) 19 | { 20 | return true; 21 | } 22 | } 23 | return false; 24 | } 25 | 26 | fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) !void { 27 | const x = __divtf3(a, b); 28 | const ret = compareResultLD(x, expectedHi, expectedLo); 29 | try testing.expect(ret == true); 30 | } 31 | 32 | test "divtf3" { 33 | // qNaN / any = qNaN 34 | try test__divtf3(math.qnan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0); 35 | // NaN / any = NaN 36 | try test__divtf3(math.nan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0); 37 | // inf / any = inf 38 | try test__divtf3(math.inf_f128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0); 39 | 40 | try test__divtf3(0x1.a23b45362464523375893ab4cdefp+5, 0x1.eedcbaba3a94546558237654321fp-1, 0x4004b0b72924d407, 0x0717e84356c6eba2); 41 | try test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50, 0x1.ed2c3ba15935332532287654321fp-9, 0x3fd5b2af3f828c9b, 0x40e51f64cde8b1f2); 42 | try test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456, 0x1.edacbba9874f765463544dd3621fp+6400, 0x28c62e15dc464466, 0xb5a07586348557ac); 43 | try test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234, 0x1.eddcdba39f3c8b7a36564354321fp-4455, 0x507b38442b539266, 0x22ce0f1d024e1252); 44 | try test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078); 45 | try test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0); 46 | } 47 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/protocols/hii.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const Guid = uefi.Guid; 3 | 4 | pub const HIIHandle = *opaque {}; 5 | 6 | /// The header found at the start of each package. 7 | pub const HIIPackageHeader = packed struct { 8 | length: u24, 9 | type: u8, 10 | 11 | pub const type_all: u8 = 0x0; 12 | pub const type_guid: u8 = 0x1; 13 | pub const forms: u8 = 0x2; 14 | pub const strings: u8 = 0x4; 15 | pub const fonts: u8 = 0x5; 16 | pub const images: u8 = 0x6; 17 | pub const simple_fonsts: u8 = 0x7; 18 | pub const device_path: u8 = 0x8; 19 | pub const keyboard_layout: u8 = 0x9; 20 | pub const animations: u8 = 0xa; 21 | pub const end: u8 = 0xdf; 22 | pub const type_system_begin: u8 = 0xe0; 23 | pub const type_system_end: u8 = 0xff; 24 | }; 25 | 26 | /// The header found at the start of each package list. 27 | pub const HIIPackageList = extern struct { 28 | package_list_guid: Guid, 29 | 30 | /// The size of the package list (in bytes), including the header. 31 | package_list_length: u32, 32 | 33 | // TODO implement iterator 34 | }; 35 | 36 | pub const HIISimplifiedFontPackage = extern struct { 37 | header: HIIPackageHeader, 38 | number_of_narrow_glyphs: u16, 39 | number_of_wide_glyphs: u16, 40 | 41 | pub fn getNarrowGlyphs(self: *HIISimplifiedFontPackage) []NarrowGlyph { 42 | return @as([*]NarrowGlyph, @ptrCast(@as([*]u8, @ptrCast(self)) + @sizeOf(HIISimplifiedFontPackage)))[0..self.number_of_narrow_glyphs]; 43 | } 44 | }; 45 | 46 | pub const NarrowGlyph = extern struct { 47 | unicode_weight: u16, 48 | attributes: packed struct { 49 | non_spacing: bool, 50 | wide: bool, 51 | _pad: u6, 52 | }, 53 | glyph_col_1: [19]u8, 54 | }; 55 | 56 | pub const WideGlyph = extern struct { 57 | unicode_weight: u16, 58 | attributes: packed struct { 59 | non_spacing: bool, 60 | wide: bool, 61 | _pad: u6, 62 | }, 63 | glyph_col_1: [19]u8, 64 | glyph_col_2: [19]u8, 65 | _pad: [3]u8, 66 | }; 67 | 68 | pub const HIIStringPackage = extern struct { 69 | header: HIIPackageHeader, 70 | hdr_size: u32, 71 | string_info_offset: u32, 72 | language_window: [16]u16, 73 | language_name: u16, 74 | language: [3]u8, 75 | }; 76 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/aulldiv.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | 3 | pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 { 4 | @setRuntimeSafety(builtin.is_test); 5 | const s_a = a >> (64 - 1); 6 | const s_b = b >> (64 - 1); 7 | 8 | const an = (a ^ s_a) -% s_a; 9 | const bn = (b ^ s_b) -% s_b; 10 | 11 | const r = @as(u64, @bitCast(an)) / @as(u64, @bitCast(bn)); 12 | const s = s_a ^ s_b; 13 | return (@as(i64, @bitCast(r)) ^ s) -% s; 14 | } 15 | 16 | pub fn _aulldiv() callconv(.Naked) void { 17 | @setRuntimeSafety(false); 18 | 19 | // The stack layout is: 20 | // ESP+16 divisor (hi) 21 | // ESP+12 divisor (low) 22 | // ESP+8 dividend (hi) 23 | // ESP+4 dividend (low) 24 | // ESP return address 25 | 26 | asm volatile ( 27 | \\ push %%ebx 28 | \\ push %%esi 29 | \\ mov 0x18(%%esp),%%eax 30 | \\ or %%eax,%%eax 31 | \\ jne 1f 32 | \\ mov 0x14(%%esp),%%ecx 33 | \\ mov 0x10(%%esp),%%eax 34 | \\ xor %%edx,%%edx 35 | \\ div %%ecx 36 | \\ mov %%eax,%%ebx 37 | \\ mov 0xc(%%esp),%%eax 38 | \\ div %%ecx 39 | \\ mov %%ebx,%%edx 40 | \\ jmp 5f 41 | \\ 1: 42 | \\ mov %%eax,%%ecx 43 | \\ mov 0x14(%%esp),%%ebx 44 | \\ mov 0x10(%%esp),%%edx 45 | \\ mov 0xc(%%esp),%%eax 46 | \\ 2: 47 | \\ shr %%ecx 48 | \\ rcr %%ebx 49 | \\ shr %%edx 50 | \\ rcr %%eax 51 | \\ or %%ecx,%%ecx 52 | \\ jne 2b 53 | \\ div %%ebx 54 | \\ mov %%eax,%%esi 55 | \\ mull 0x18(%%esp) 56 | \\ mov %%eax,%%ecx 57 | \\ mov 0x14(%%esp),%%eax 58 | \\ mul %%esi 59 | \\ add %%ecx,%%edx 60 | \\ jb 3f 61 | \\ cmp 0x10(%%esp),%%edx 62 | \\ ja 3f 63 | \\ jb 4f 64 | \\ cmp 0xc(%%esp),%%eax 65 | \\ jbe 4f 66 | \\ 3: 67 | \\ dec %%esi 68 | \\ 4: 69 | \\ xor %%edx,%%edx 70 | \\ mov %%esi,%%eax 71 | \\ 5: 72 | \\ pop %%esi 73 | \\ pop %%ebx 74 | \\ ret $0x10 75 | ); 76 | } 77 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/os/uefi/tables/system_table.zig: -------------------------------------------------------------------------------- 1 | const uefi = @import("std").os.uefi; 2 | const BootServices = uefi.tables.BootServices; 3 | const ConfigurationTable = uefi.tables.ConfigurationTable; 4 | const Handle = uefi.Handle; 5 | const RuntimeServices = uefi.tables.RuntimeServices; 6 | const SimpleTextInputProtocol = uefi.protocols.SimpleTextInputProtocol; 7 | const SimpleTextOutputProtocol = uefi.protocols.SimpleTextOutputProtocol; 8 | const TableHeader = uefi.tables.TableHeader; 9 | 10 | /// The EFI System Table contains pointers to the runtime and boot services tables. 11 | /// 12 | /// As the system_table may grow with new UEFI versions, it is important to check hdr.header_size. 13 | /// 14 | /// After successfully calling boot_services.exitBootServices, console_in_handle, 15 | /// con_in, console_out_handle, con_out, standard_error_handle, std_err, and 16 | /// boot_services should be set to null. After setting these attributes to null, 17 | /// hdr.crc32 must be recomputed. 18 | pub const SystemTable = extern struct { 19 | hdr: TableHeader, 20 | 21 | /// A null-terminated string that identifies the vendor that produces the system firmware of the platform. 22 | firmware_vendor: [*:0]u16, 23 | firmware_revision: u32, 24 | console_in_handle: ?Handle, 25 | con_in: ?*SimpleTextInputProtocol, 26 | console_out_handle: ?Handle, 27 | con_out: ?*SimpleTextOutputProtocol, 28 | standard_error_handle: ?Handle, 29 | std_err: ?*SimpleTextOutputProtocol, 30 | runtime_services: *RuntimeServices, 31 | boot_services: ?*BootServices, 32 | number_of_table_entries: usize, 33 | configuration_table: [*]ConfigurationTable, 34 | 35 | pub const signature: u64 = 0x5453595320494249; 36 | pub const revision_1_02: u32 = (1 << 16) | 2; 37 | pub const revision_1_10: u32 = (1 << 16) | 10; 38 | pub const revision_2_00: u32 = (2 << 16); 39 | pub const revision_2_10: u32 = (2 << 16) | 10; 40 | pub const revision_2_20: u32 = (2 << 16) | 20; 41 | pub const revision_2_30: u32 = (2 << 16) | 30; 42 | pub const revision_2_31: u32 = (2 << 16) | 31; 43 | pub const revision_2_40: u32 = (2 << 16) | 40; 44 | pub const revision_2_50: u32 = (2 << 16) | 50; 45 | pub const revision_2_60: u32 = (2 << 16) | 60; 46 | pub const revision_2_70: u32 = (2 << 16) | 70; 47 | pub const revision_2_80: u32 = (2 << 16) | 80; 48 | }; 49 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/multi3_test.zig: -------------------------------------------------------------------------------- 1 | const __multi3 = @import("multi3.zig").__multi3; 2 | const testing = @import("std").testing; 3 | 4 | fn test__multi3(a: i128, b: i128, expected: i128) !void { 5 | const x = __multi3(a, b); 6 | try testing.expect(x == expected); 7 | } 8 | 9 | test "multi3" { 10 | try test__multi3(0, 0, 0); 11 | try test__multi3(0, 1, 0); 12 | try test__multi3(1, 0, 0); 13 | try test__multi3(0, 10, 0); 14 | try test__multi3(10, 0, 0); 15 | try test__multi3(0, 81985529216486895, 0); 16 | try test__multi3(81985529216486895, 0, 0); 17 | 18 | try test__multi3(0, -1, 0); 19 | try test__multi3(-1, 0, 0); 20 | try test__multi3(0, -10, 0); 21 | try test__multi3(-10, 0, 0); 22 | try test__multi3(0, -81985529216486895, 0); 23 | try test__multi3(-81985529216486895, 0, 0); 24 | 25 | try test__multi3(1, 1, 1); 26 | try test__multi3(1, 10, 10); 27 | try test__multi3(10, 1, 10); 28 | try test__multi3(1, 81985529216486895, 81985529216486895); 29 | try test__multi3(81985529216486895, 1, 81985529216486895); 30 | 31 | try test__multi3(1, -1, -1); 32 | try test__multi3(1, -10, -10); 33 | try test__multi3(-10, 1, -10); 34 | try test__multi3(1, -81985529216486895, -81985529216486895); 35 | try test__multi3(-81985529216486895, 1, -81985529216486895); 36 | 37 | try test__multi3(3037000499, 3037000499, 9223372030926249001); 38 | try test__multi3(-3037000499, 3037000499, -9223372030926249001); 39 | try test__multi3(3037000499, -3037000499, -9223372030926249001); 40 | try test__multi3(-3037000499, -3037000499, 9223372030926249001); 41 | 42 | try test__multi3(4398046511103, 2097152, 9223372036852678656); 43 | try test__multi3(-4398046511103, 2097152, -9223372036852678656); 44 | try test__multi3(4398046511103, -2097152, -9223372036852678656); 45 | try test__multi3(-4398046511103, -2097152, 9223372036852678656); 46 | 47 | try test__multi3(2097152, 4398046511103, 9223372036852678656); 48 | try test__multi3(-2097152, 4398046511103, -9223372036852678656); 49 | try test__multi3(2097152, -4398046511103, -9223372036852678656); 50 | try test__multi3(-2097152, -4398046511103, 9223372036852678656); 51 | 52 | try test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000); 53 | } 54 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/crypto/modes.zig: -------------------------------------------------------------------------------- 1 | // Based on Go stdlib implementation 2 | 3 | const std = @import("../std.zig"); 4 | const mem = std.mem; 5 | const debug = std.debug; 6 | 7 | /// Counter mode. 8 | /// 9 | /// This mode creates a key stream by encrypting an incrementing counter using a block cipher, and adding it to the source material. 10 | /// 11 | /// Important: the counter mode doesn't provide authenticated encryption: the ciphertext can be trivially modified without this being detected. 12 | /// As a result, applications should generally never use it directly, but only in a construction that includes a MAC. 13 | pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8, src: []const u8, iv: [BlockCipher.block_length]u8, endian: std.builtin.Endian) void { 14 | debug.assert(dst.len >= src.len); 15 | const block_length = BlockCipher.block_length; 16 | var counter: [BlockCipher.block_length]u8 = undefined; 17 | var counterInt = mem.readInt(u128, &iv, endian); 18 | var i: usize = 0; 19 | 20 | const parallel_count = BlockCipher.block.parallel.optimal_parallel_blocks; 21 | const wide_block_length = parallel_count * 16; 22 | if (src.len >= wide_block_length) { 23 | var counters: [parallel_count * 16]u8 = undefined; 24 | while (i + wide_block_length <= src.len) : (i += wide_block_length) { 25 | comptime var j = 0; 26 | inline while (j < parallel_count) : (j += 1) { 27 | mem.writeInt(u128, counters[j * 16 .. j * 16 + 16], counterInt, endian); 28 | counterInt +%= 1; 29 | } 30 | block_cipher.xorWide(parallel_count, dst[i .. i + wide_block_length][0..wide_block_length], src[i .. i + wide_block_length][0..wide_block_length], counters); 31 | } 32 | } 33 | while (i + block_length <= src.len) : (i += block_length) { 34 | mem.writeInt(u128, &counter, counterInt, endian); 35 | counterInt +%= 1; 36 | block_cipher.xor(dst[i .. i + block_length][0..block_length], src[i .. i + block_length][0..block_length], counter); 37 | } 38 | if (i < src.len) { 39 | mem.writeInt(u128, &counter, counterInt, endian); 40 | var pad = [_]u8{0} ** block_length; 41 | mem.copy(u8, &pad, src[i..]); 42 | block_cipher.xor(&pad, &pad, counter); 43 | mem.copy(u8, dst[i..], pad[0 .. src.len - i]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/aullrem.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | 3 | pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 { 4 | @setRuntimeSafety(builtin.is_test); 5 | const s_a = a >> (64 - 1); 6 | const s_b = b >> (64 - 1); 7 | 8 | const an = (a ^ s_a) -% s_a; 9 | const bn = (b ^ s_b) -% s_b; 10 | 11 | const r = @as(u64, @bitCast(an)) % @as(u64, @bitCast(bn)); 12 | const s = s_a ^ s_b; 13 | return (@as(i64, @bitCast(r)) ^ s) -% s; 14 | } 15 | 16 | pub fn _aullrem() callconv(.Naked) void { 17 | @setRuntimeSafety(false); 18 | 19 | // The stack layout is: 20 | // ESP+16 divisor (hi) 21 | // ESP+12 divisor (low) 22 | // ESP+8 dividend (hi) 23 | // ESP+4 dividend (low) 24 | // ESP return address 25 | 26 | asm volatile ( 27 | \\ push %%ebx 28 | \\ mov 0x14(%%esp),%%eax 29 | \\ or %%eax,%%eax 30 | \\ jne 1f 31 | \\ mov 0x10(%%esp),%%ecx 32 | \\ mov 0xc(%%esp),%%eax 33 | \\ xor %%edx,%%edx 34 | \\ div %%ecx 35 | \\ mov 0x8(%%esp),%%eax 36 | \\ div %%ecx 37 | \\ mov %%edx,%%eax 38 | \\ xor %%edx,%%edx 39 | \\ jmp 6f 40 | \\ 1: 41 | \\ mov %%eax,%%ecx 42 | \\ mov 0x10(%%esp),%%ebx 43 | \\ mov 0xc(%%esp),%%edx 44 | \\ mov 0x8(%%esp),%%eax 45 | \\ 2: 46 | \\ shr %%ecx 47 | \\ rcr %%ebx 48 | \\ shr %%edx 49 | \\ rcr %%eax 50 | \\ or %%ecx,%%ecx 51 | \\ jne 2b 52 | \\ div %%ebx 53 | \\ mov %%eax,%%ecx 54 | \\ mull 0x14(%%esp) 55 | \\ xchg %%eax,%%ecx 56 | \\ mull 0x10(%%esp) 57 | \\ add %%ecx,%%edx 58 | \\ jb 3f 59 | \\ cmp 0xc(%%esp),%%edx 60 | \\ ja 3f 61 | \\ jb 4f 62 | \\ cmp 0x8(%%esp),%%eax 63 | \\ jbe 4f 64 | \\ 3: 65 | \\ sub 0x10(%%esp),%%eax 66 | \\ sbb 0x14(%%esp),%%edx 67 | \\ 4: 68 | \\ sub 0x8(%%esp),%%eax 69 | \\ sbb 0xc(%%esp),%%edx 70 | \\ neg %%edx 71 | \\ neg %%eax 72 | \\ sbb $0x0,%%edx 73 | \\ 6: 74 | \\ pop %%ebx 75 | \\ ret $0x10 76 | ); 77 | } 78 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatuntisf.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const is_test = builtin.is_test; 3 | const std = @import("std"); 4 | const maxInt = std.math.maxInt; 5 | 6 | const FLT_MANT_DIG = 24; 7 | 8 | pub fn __floatuntisf(arg: u128) callconv(.C) f32 { 9 | @setRuntimeSafety(is_test); 10 | 11 | if (arg == 0) 12 | return 0.0; 13 | 14 | var a = arg; 15 | const N: u32 = @sizeOf(u128) * 8; 16 | const sd = @as(i32, @bitCast(N - @clz(a))); // number of significant digits 17 | var e: i32 = sd - 1; // exponent 18 | if (sd > FLT_MANT_DIG) { 19 | // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx 20 | // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR 21 | // 12345678901234567890123456 22 | // 1 = msb 1 bit 23 | // P = bit FLT_MANT_DIG-1 bits to the right of 1 24 | // Q = bit FLT_MANT_DIG bits to the right of 1 25 | // R = "or" of all bits to the right of Q 26 | switch (sd) { 27 | FLT_MANT_DIG + 1 => { 28 | a <<= 1; 29 | }, 30 | FLT_MANT_DIG + 2 => {}, 31 | else => { 32 | const shift_amt = @as(i32, @bitCast(N + (FLT_MANT_DIG + 2))) - sd; 33 | const shift_amt_u7 = @as(u7, @intCast(shift_amt)); 34 | a = (a >> @as(u7, @intCast(sd - (FLT_MANT_DIG + 2)))) | 35 | @intFromBool((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); 36 | }, 37 | } 38 | // finish 39 | a |= @intFromBool((a & 4) != 0); // Or P into R 40 | a += 1; // round - this step may add a significant bit 41 | a >>= 2; // dump Q and R 42 | // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits 43 | if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) { 44 | a >>= 1; 45 | e += 1; 46 | } 47 | // a is now rounded to FLT_MANT_DIG bits 48 | } else { 49 | a <<= @as(u7, @intCast(FLT_MANT_DIG - sd)); 50 | // a is now rounded to FLT_MANT_DIG bits 51 | } 52 | 53 | const high = @as(u32, @bitCast((e + 127) << 23)); // exponent 54 | const low = @as(u32, @truncate(a)) & 0x007fffff; // mantissa 55 | 56 | return @as(f32, @bitCast(high | low)); 57 | } 58 | 59 | test { 60 | _ = @import("floatuntisf_test.zig"); 61 | } 62 | -------------------------------------------------------------------------------- /src/hello-world/hello-aarch64-linux.zig: -------------------------------------------------------------------------------- 1 | pub export fn _start() noreturn { 2 | print(); 3 | print(); 4 | print(); 5 | print(); 6 | print(); 7 | print(); 8 | print(); 9 | print(); 10 | print(); 11 | print(); 12 | print(); 13 | print(); 14 | print(); 15 | print(); 16 | print(); 17 | print(); 18 | print(); 19 | print(); 20 | print(); 21 | print(); 22 | print(); 23 | print(); 24 | print(); 25 | print(); 26 | print(); 27 | print(); 28 | print(); 29 | print(); 30 | print(); 31 | print(); 32 | print(); 33 | print(); 34 | print(); 35 | print(); 36 | print(); 37 | print(); 38 | print(); 39 | print(); 40 | print(); 41 | print(); 42 | print(); 43 | print(); 44 | print(); 45 | print(); 46 | print(); 47 | print(); 48 | print(); 49 | print(); 50 | print(); 51 | print(); 52 | print(); 53 | print(); 54 | print(); 55 | print(); 56 | print(); 57 | print(); 58 | print(); 59 | print(); 60 | print(); 61 | print(); 62 | print(); 63 | print(); 64 | print(); 65 | print(); 66 | print(); 67 | print(); 68 | print(); 69 | print(); 70 | print(); 71 | print(); 72 | print(); 73 | print(); 74 | print(); 75 | print(); 76 | print(); 77 | print(); 78 | print(); 79 | print(); 80 | print(); 81 | print(); 82 | print(); 83 | print(); 84 | print(); 85 | print(); 86 | print(); 87 | print(); 88 | print(); 89 | print(); 90 | print(); 91 | print(); 92 | print(); 93 | print(); 94 | print(); 95 | print(); 96 | print(); 97 | print(); 98 | print(); 99 | print(); 100 | print(); 101 | print(); 102 | print(); 103 | exit(); 104 | } 105 | 106 | fn print() void { 107 | asm volatile ("svc #0" 108 | : 109 | : [number] "{x8}" (64), 110 | [arg1] "{x0}" (1), 111 | [arg2] "{x1}" (@intFromPtr("Hello, World!\n")), 112 | [arg3] "{x2}" ("Hello, World!\n".len), 113 | : "memory", "cc" 114 | ); 115 | } 116 | 117 | fn exit() noreturn { 118 | asm volatile ("svc #0" 119 | : 120 | : [number] "{x8}" (93), 121 | [arg1] "{x0}" (0), 122 | : "memory", "cc" 123 | ); 124 | unreachable; 125 | } 126 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/c.zig: -------------------------------------------------------------------------------- 1 | //! This is Zig's multi-target implementation of libc. 2 | //! When builtin.link_libc is true, we need to export all the functions and 3 | //! provide an entire C API. 4 | //! Otherwise, only the functions which LLVM generates calls to need to be generated, 5 | //! such as memcpy, memset, and some math functions. 6 | 7 | const std = @import("std"); 8 | const builtin = @import("builtin"); 9 | const native_os = builtin.os.tag; 10 | 11 | comptime { 12 | // When the self-hosted compiler is further along, all the logic from c_stage1.zig will 13 | // be migrated to this file and then c_stage1.zig will be deleted. Until then we have a 14 | // simpler implementation of c.zig that only uses features already implemented in self-hosted. 15 | if (builtin.zig_is_stage2) { 16 | @export(memset, .{ .name = "memset", .linkage = .Strong }); 17 | @export(memcpy, .{ .name = "memcpy", .linkage = .Strong }); 18 | } else { 19 | _ = @import("c_stage1.zig"); 20 | } 21 | } 22 | 23 | // Avoid dragging in the runtime safety mechanisms into this .o file, 24 | // unless we're trying to test this file. 25 | pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { 26 | @setCold(true); 27 | _ = error_return_trace; 28 | if (builtin.zig_is_stage2) { 29 | while (true) { 30 | @breakpoint(); 31 | } 32 | } 33 | if (builtin.is_test) { 34 | std.debug.panic("{s}", .{msg}); 35 | } 36 | if (native_os != .freestanding and native_os != .other) { 37 | std.os.abort(); 38 | } 39 | while (true) {} 40 | } 41 | 42 | fn memset(dest: ?[*]u8, c: u8, len: usize) callconv(.C) ?[*]u8 { 43 | @setRuntimeSafety(false); 44 | 45 | if (len != 0) { 46 | var d = dest.?; 47 | var n = len; 48 | while (true) { 49 | d.* = c; 50 | n -= 1; 51 | if (n == 0) break; 52 | d += 1; 53 | } 54 | } 55 | 56 | return dest; 57 | } 58 | 59 | fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { 60 | @setRuntimeSafety(false); 61 | 62 | if (len != 0) { 63 | var d = dest.?; 64 | var s = src.?; 65 | var n = len; 66 | while (true) { 67 | d.* = s.*; 68 | n -= 1; 69 | if (n == 0) break; 70 | d += 1; 71 | s += 1; 72 | } 73 | } 74 | 75 | return dest; 76 | } 77 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/special/compiler_rt/floatuntidf.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const is_test = builtin.is_test; 3 | const std = @import("std"); 4 | const maxInt = std.math.maxInt; 5 | 6 | const DBL_MANT_DIG = 53; 7 | 8 | pub fn __floatuntidf(arg: u128) callconv(.C) f64 { 9 | @setRuntimeSafety(is_test); 10 | 11 | if (arg == 0) 12 | return 0.0; 13 | 14 | var a = arg; 15 | const N: u32 = @sizeOf(u128) * 8; 16 | const sd = @as(i32, @bitCast(N - @clz(a))); // number of significant digits 17 | var e: i32 = sd - 1; // exponent 18 | if (sd > DBL_MANT_DIG) { 19 | // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx 20 | // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR 21 | // 12345678901234567890123456 22 | // 1 = msb 1 bit 23 | // P = bit DBL_MANT_DIG-1 bits to the right of 1 24 | // Q = bit DBL_MANT_DIG bits to the right of 1 25 | // R = "or" of all bits to the right of Q 26 | switch (sd) { 27 | DBL_MANT_DIG + 1 => { 28 | a <<= 1; 29 | }, 30 | DBL_MANT_DIG + 2 => {}, 31 | else => { 32 | const shift_amt = @as(i32, @bitCast(N + (DBL_MANT_DIG + 2))) - sd; 33 | const shift_amt_u7 = @as(u7, @intCast(shift_amt)); 34 | a = (a >> @as(u7, @intCast(sd - (DBL_MANT_DIG + 2)))) | 35 | @intFromBool((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); 36 | }, 37 | } 38 | // finish 39 | a |= @intFromBool((a & 4) != 0); // Or P into R 40 | a += 1; // round - this step may add a significant bit 41 | a >>= 2; // dump Q and R 42 | // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits 43 | if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) { 44 | a >>= 1; 45 | e += 1; 46 | } 47 | // a is now rounded to DBL_MANT_DIG bits 48 | } else { 49 | a <<= @as(u7, @intCast(DBL_MANT_DIG - sd)); 50 | // a is now rounded to DBL_MANT_DIG bits 51 | } 52 | 53 | const high: u64 = @as(u32, @bitCast((e + 1023) << 20)) | // exponent 54 | (@as(u32, @truncate(a >> 32)) & 0x000FFFFF); // mantissa-high 55 | const low = @as(u32, @truncate(a)); // mantissa-low 56 | 57 | return @as(f64, @bitCast(low | (high << 32))); 58 | } 59 | 60 | test { 61 | _ = @import("floatuntidf_test.zig"); 62 | } 63 | -------------------------------------------------------------------------------- /src/self-hosted-parser/input_dir/target/msp430.zig: -------------------------------------------------------------------------------- 1 | //! This file is auto-generated by tools/update_cpu_features.zig. 2 | 3 | const std = @import("../std.zig"); 4 | const CpuFeature = std.Target.Cpu.Feature; 5 | const CpuModel = std.Target.Cpu.Model; 6 | 7 | pub const Feature = enum { 8 | ext, 9 | hwmult16, 10 | hwmult32, 11 | hwmultf5, 12 | }; 13 | 14 | pub const featureSet = CpuFeature.feature_set_fns(Feature).featureSet; 15 | pub const featureSetHas = CpuFeature.feature_set_fns(Feature).featureSetHas; 16 | pub const featureSetHasAny = CpuFeature.feature_set_fns(Feature).featureSetHasAny; 17 | pub const featureSetHasAll = CpuFeature.feature_set_fns(Feature).featureSetHasAll; 18 | 19 | pub const all_features = blk: { 20 | const len = @typeInfo(Feature).Enum.fields.len; 21 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); 22 | var result: [len]CpuFeature = undefined; 23 | result[@intFromEnum(Feature.ext)] = .{ 24 | .llvm_name = "ext", 25 | .description = "Enable MSP430-X extensions", 26 | .dependencies = featureSet(&[_]Feature{}), 27 | }; 28 | result[@intFromEnum(Feature.hwmult16)] = .{ 29 | .llvm_name = "hwmult16", 30 | .description = "Enable 16-bit hardware multiplier", 31 | .dependencies = featureSet(&[_]Feature{}), 32 | }; 33 | result[@intFromEnum(Feature.hwmult32)] = .{ 34 | .llvm_name = "hwmult32", 35 | .description = "Enable 32-bit hardware multiplier", 36 | .dependencies = featureSet(&[_]Feature{}), 37 | }; 38 | result[@intFromEnum(Feature.hwmultf5)] = .{ 39 | .llvm_name = "hwmultf5", 40 | .description = "Enable F5 series hardware multiplier", 41 | .dependencies = featureSet(&[_]Feature{}), 42 | }; 43 | const ti = @typeInfo(Feature); 44 | for (result, 0..) |*elem, i| { 45 | elem.index = i; 46 | elem.name = ti.Enum.fields[i].name; 47 | } 48 | break :blk result; 49 | }; 50 | 51 | pub const cpu = struct { 52 | pub const generic = CpuModel{ 53 | .name = "generic", 54 | .llvm_name = "generic", 55 | .features = featureSet(&[_]Feature{}), 56 | }; 57 | pub const msp430 = CpuModel{ 58 | .name = "msp430", 59 | .llvm_name = "msp430", 60 | .features = featureSet(&[_]Feature{}), 61 | }; 62 | pub const msp430x = CpuModel{ 63 | .name = "msp430x", 64 | .llvm_name = "msp430x", 65 | .features = featureSet(&[_]Feature{ 66 | .ext, 67 | }), 68 | }; 69 | }; 70 | --------------------------------------------------------------------------------