diff --git a/ci/azure/macos_arm64_script b/ci/azure/macos_arm64_script index 44c5581ad2..8427d07512 100755 --- a/ci/azure/macos_arm64_script +++ b/ci/azure/macos_arm64_script @@ -114,13 +114,12 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1) BYTESIZE=$(wc -c < $TARBALL) - JSONFILE="macos-$GITBRANCH.json" + JSONFILE="tarball.json" touch $JSONFILE echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE - s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE" s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-macos-$VERSION.json" # `set -x` causes these variables to be mangled. diff --git a/ci/azure/pipelines.yml b/ci/azure/pipelines.yml index df7a6e654f..1e281bb8e7 100644 --- a/ci/azure/pipelines.yml +++ b/ci/azure/pipelines.yml @@ -24,7 +24,7 @@ jobs: secureFile: s3cfg - script: ci/azure/macos_arm64_script name: main - displayName: 'Build and cross-compile' + displayName: 'Build' - job: BuildLinux pool: vmImage: 'ubuntu-18.04' @@ -66,6 +66,7 @@ jobs: - job: OnMasterSuccess dependsOn: - BuildMacOS + - BuildMacOS_arm64 - BuildLinux - BuildWindows condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) diff --git a/ci/srht/index.html b/ci/srht/index.html index 353aaf01de..b1fa1af3c2 100644 --- a/ci/srht/index.html +++ b/ci/srht/index.html @@ -199,6 +199,12 @@ {{X86_64_MACOS_BYTESIZE}} {{X86_64_MACOS_SHASUM}} + + {{AARCH64_MACOS_TARBALL}} + Binary + {{AARCH64_MACOS_BYTESIZE}} + {{AARCH64_MACOS_SHASUM}} + {{X86_64_FREEBSD_TARBALL}} Binary diff --git a/ci/srht/index.json b/ci/srht/index.json index a5e89c084d..7cb77f98f0 100644 --- a/ci/srht/index.json +++ b/ci/srht/index.json @@ -19,6 +19,11 @@ "shasum": "{{X86_64_MACOS_SHASUM}}", "size": "{{X86_64_MACOS_BYTESIZE}}" }, + "aarch64-macos": { + "tarball": "https://ziglang.org/builds/{{AARCH64_MACOS_TARBALL}}", + "shasum": "{{AARCH64_MACOS_SHASUM}}", + "size": "{{AARCH64_MACOS_BYTESIZE}}" + }, "x86_64-windows": { "tarball": "https://ziglang.org/builds/{{X86_64_WINDOWS_TARBALL}}", "shasum": "{{X86_64_WINDOWS_SHASUM}}", diff --git a/ci/srht/update_download_page b/ci/srht/update_download_page index 01fa62b911..ebdb3ed6b0 100755 --- a/ci/srht/update_download_page +++ b/ci/srht/update_download_page @@ -12,6 +12,7 @@ NATIVE_TARBALL="zig-linux-$(uname -m)-$VERSION.tar.xz" AARCH64_LINUX_JSON_URL="https://ziglang.org/builds/aarch64-linux-$VERSION.json" X86_64_LINUX_JSON_URL="https://ziglang.org/builds/x86_64-linux-$VERSION.json" X86_64_WINDOWS_JSON_URL="https://ziglang.org/builds/x86_64-windows-$VERSION.json" +AARCH64_MACOS_JSON_URL="https://ziglang.org/builds/aarch64-macos-$VERSION.json" X86_64_MACOS_JSON_URL="https://ziglang.org/builds/x86_64-macos-$VERSION.json" X86_64_FREEBSD_JSON_URL="https://ziglang.org/builds/x86_64-freebsd-$VERSION.json" @@ -20,6 +21,7 @@ X86_64_FREEBSD_JSON_URL="https://ziglang.org/builds/x86_64-freebsd-$VERSION.json curl --fail -I "$AARCH64_LINUX_JSON_URL" >/dev/null || exit 0 curl --fail -I "$X86_64_LINUX_JSON_URL" >/dev/null || exit 0 curl --fail -I "$X86_64_WINDOWS_JSON_URL" >/dev/null || exit 0 +curl --fail -I "$AARCH64_MACOS_JSON_URL" >/dev/null || exit 0 curl --fail -I "$X86_64_MACOS_JSON_URL" >/dev/null || exit 0 curl --fail -I "$X86_64_FREEBSD_JSON_URL" >/dev/null || exit 0 @@ -57,6 +59,11 @@ export X86_64_WINDOWS_TARBALL="$(echo "$X86_64_WINDOWS_JSON" | jq .tarball -r)" export X86_64_WINDOWS_BYTESIZE="$(echo "$X86_64_WINDOWS_JSON" | jq .size -r)" export X86_64_WINDOWS_SHASUM="$(echo "$X86_64_WINDOWS_JSON" | jq .shasum -r)" +AARCH64_MACOS_JSON=$(curl --fail "$AARCH64_MACOS_JSON_URL" || exit 1) +export AARCH64_MACOS_TARBALL="$(echo "$AARCH64_MACOS_JSON" | jq .tarball -r)" +export AARCH64_MACOS_BYTESIZE="$(echo "$AARCH64_MACOS_JSON" | jq .size -r)" +export AARCH64_MACOS_SHASUM="$(echo "$AARCH64_MACOS_JSON" | jq .shasum -r)" + X86_64_MACOS_JSON=$(curl --fail "$X86_64_MACOS_JSON_URL" || exit 1) export X86_64_MACOS_TARBALL="$(echo "$X86_64_MACOS_JSON" | jq .tarball -r)" export X86_64_MACOS_BYTESIZE="$(echo "$X86_64_MACOS_JSON" | jq .size -r)" diff --git a/doc/docgen.zig b/doc/docgen.zig index c77f439f06..8dd299a6c5 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -1023,6 +1023,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any const builtin_code = try getBuiltinCode(allocator, &env_map, zig_exe); for (toc.nodes) |node| { + defer root_node.completeOne(); switch (node) { .Content => |data| { try out.writeAll(data); @@ -1062,8 +1063,6 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any try tokenizeAndPrint(tokenizer, out, content_tok); }, .Code => |code| { - root_node.completeOne(); - const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end]; const trimmed_raw_source = mem.trim(u8, raw_source, " \n"); if (!code.is_inline) { diff --git a/doc/langref.html.in b/doc/langref.html.in index 9aa106fb54..3515875c87 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -85,7 +85,6 @@ #main-wrapper { display: flex; flex-direction: column; - height: 100vh; } #contents-wrapper { @@ -106,6 +105,11 @@ #main-wrapper { flex-direction: row; } + #toc { + height: 100vh; + position: sticky; + top: 0; + } #contents-wrapper, #toc { overflow: auto; } diff --git a/lib/std/build.zig b/lib/std/build.zig index 825312755f..a652de9c12 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1939,6 +1939,15 @@ pub const LibExeObjStep = struct { out.print("pub const {}: []const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable; return; }, + ?[:0]const u8 => { + out.print("pub const {}: ?[:0]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable; + if (value) |payload| { + out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)}) catch unreachable; + } else { + out.writeAll("null;\n") catch unreachable; + } + return; + }, ?[]const u8 => { out.print("pub const {}: ?[]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable; if (value) |payload| { diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index 7169095197..c988d25a7b 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -18,14 +18,14 @@ pub extern "c" fn _lwp_self() lwpid_t; pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void; -pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int; -pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int; +pub extern "c" fn __fstat50(fd: fd_t, buf: *libc_stat) c_int; +pub extern "c" fn __stat50(path: [*:0]const u8, buf: *libc_stat) c_int; pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int; pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int; pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int; pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int; pub extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int; -pub extern "c" fn __sigaction14(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; +pub extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int; pub extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; pub extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; pub extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; @@ -34,7 +34,6 @@ pub extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int; pub extern "c" fn __libc_thr_yield() c_int; pub extern "c" fn posix_memalign(memptr: *?*c_void, alignment: usize, size: usize) c_int; -pub extern "c" fn malloc_usable_size(?*const c_void) usize; pub const pthread_mutex_t = extern struct { ptm_magic: u32 = 0x33330003, @@ -93,3 +92,5 @@ pub const pthread_attr_t = extern struct { pta_flags: i32, pta_private: ?*c_void, }; + +pub const sem_t = ?*opaque {}; diff --git a/lib/std/debug.zig b/lib/std/debug.zig index a7badf7ed1..c84a0e0f18 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -462,7 +462,7 @@ pub const TTY = struct { // TODO give this a payload of file handle windows_api, - fn setColor(conf: Config, out_stream: anytype, color: Color) void { + pub fn setColor(conf: Config, out_stream: anytype, color: Color) void { nosuspend switch (conf) { .no_color => return, .escape_codes => switch (color) { diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index baea3b4e7f..3a8fd9e9a3 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -223,15 +223,15 @@ pub const File = struct { return os.lseek_SET(self.handle, offset); } - pub const GetPosError = os.SeekError || os.FStatError; + pub const GetSeekPosError = os.SeekError || os.FStatError; /// TODO: integrate with async I/O - pub fn getPos(self: File) GetPosError!u64 { + pub fn getPos(self: File) GetSeekPosError!u64 { return os.lseek_CUR_get(self.handle); } /// TODO: integrate with async I/O - pub fn getEndPos(self: File) GetPosError!u64 { + pub fn getEndPos(self: File) GetSeekPosError!u64 { if (builtin.os.tag == .windows) { return windows.GetFileSizeEx(self.handle); } @@ -819,7 +819,7 @@ pub const File = struct { pub const SeekableStream = io.SeekableStream( File, SeekError, - GetPosError, + GetSeekPosError, seekTo, seekBy, getPos, diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 62f430a672..b74144d08b 100644 --- a/lib/std/hash_map.zig +++ b/lib/std/hash_map.zig @@ -398,10 +398,6 @@ pub fn HashMapUnmanaged( return size * 100 < max_load_percentage * cap; } - pub fn init(allocator: *Allocator) Self { - return .{}; - } - pub fn deinit(self: *Self, allocator: *Allocator) void { self.deallocate(allocator); self.* = undefined; diff --git a/lib/std/io/stream_source.zig b/lib/std/io/stream_source.zig index df0d6cd352..0cfe346c6a 100644 --- a/lib/std/io/stream_source.zig +++ b/lib/std/io/stream_source.zig @@ -5,7 +5,6 @@ // and substantial portions of the software. const std = @import("../std.zig"); const io = std.io; -const testing = std.testing; /// Provides `io.Reader`, `io.Writer`, and `io.SeekableStream` for in-memory buffers as /// well as files. @@ -19,7 +18,7 @@ pub const StreamSource = union(enum) { pub const ReadError = std.fs.File.ReadError; pub const WriteError = std.fs.File.WriteError; pub const SeekError = std.fs.File.SeekError; - pub const GetSeekPosError = std.fs.File.GetPosError; + pub const GetSeekPosError = std.fs.File.GetSeekPosError; pub const Reader = io.Reader(*StreamSource, ReadError, read); pub const Writer = io.Writer(*StreamSource, WriteError, write); diff --git a/lib/std/json.zig b/lib/std/json.zig index 96ad066db3..7596631ea2 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1234,7 +1234,7 @@ test "json.validate" { const Allocator = std.mem.Allocator; const ArenaAllocator = std.heap.ArenaAllocator; const ArrayList = std.ArrayList; -const StringHashMap = std.StringHashMap; +const StringArrayHashMap = std.StringArrayHashMap; pub const ValueTree = struct { arena: ArenaAllocator, @@ -1245,7 +1245,7 @@ pub const ValueTree = struct { } }; -pub const ObjectMap = StringHashMap(Value); +pub const ObjectMap = StringArrayHashMap(Value); pub const Array = ArrayList(Value); /// Represents a JSON value diff --git a/lib/std/json/test.zig b/lib/std/json/test.zig index 897e2e3364..b6ff03350c 100644 --- a/lib/std/json/test.zig +++ b/lib/std/json/test.zig @@ -12,7 +12,7 @@ const std = @import("../std.zig"); const json = std.json; const testing = std.testing; -fn testNonStreaming(comptime s: []const u8) !void { +fn testNonStreaming(s: []const u8) !void { var p = json.Parser.init(testing.allocator, false); defer p.deinit(); @@ -20,44 +20,60 @@ fn testNonStreaming(comptime s: []const u8) !void { defer tree.deinit(); } -fn ok(comptime s: []const u8) void { +fn ok(s: []const u8) !void { testing.expect(json.validate(s)); - testNonStreaming(s) catch testing.expect(false); + try testNonStreaming(s); } -fn err(comptime s: []const u8) void { +fn err(s: []const u8) void { testing.expect(!json.validate(s)); testNonStreaming(s) catch return; testing.expect(false); } -fn utf8Error(comptime s: []const u8) void { +fn utf8Error(s: []const u8) void { testing.expect(!json.validate(s)); testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s)); } -fn any(comptime s: []const u8) void { +fn any(s: []const u8) void { _ = json.validate(s); testNonStreaming(s) catch {}; } -fn anyStreamingErrNonStreaming(comptime s: []const u8) void { +fn anyStreamingErrNonStreaming(s: []const u8) void { _ = json.validate(s); testNonStreaming(s) catch return; testing.expect(false); } +fn roundTrip(s: []const u8) !void { + testing.expect(json.validate(s)); + + var p = json.Parser.init(testing.allocator, false); + defer p.deinit(); + + var tree = try p.parse(s); + defer tree.deinit(); + + var buf: [256]u8 = undefined; + var fbs = std.io.fixedBufferStream(&buf); + try tree.root.jsonStringify(.{}, fbs.writer()); + + testing.expectEqualStrings(s, fbs.getWritten()); +} + //////////////////////////////////////////////////////////////////////////////////////////////////// // // Additional tests not part of test JSONTestSuite. test "y_trailing_comma_after_empty" { - ok( + try roundTrip( \\{"1":[],"2":{},"3":"4"} ); } @@ -65,252 +81,252 @@ test "y_trailing_comma_after_empty" { //////////////////////////////////////////////////////////////////////////////////////////////////// test "y_array_arraysWithSpaces" { - ok( + try ok( \\[[] ] ); } test "y_array_empty" { - ok( + try roundTrip( \\[] ); } test "y_array_empty-string" { - ok( + try roundTrip( \\[""] ); } test "y_array_ending_with_newline" { - ok( + try roundTrip( \\["a"] ); } test "y_array_false" { - ok( + try roundTrip( \\[false] ); } test "y_array_heterogeneous" { - ok( + try ok( \\[null, 1, "1", {}] ); } test "y_array_null" { - ok( + try roundTrip( \\[null] ); } test "y_array_with_1_and_newline" { - ok( + try ok( \\[1 \\] ); } test "y_array_with_leading_space" { - ok( + try ok( \\ [1] ); } test "y_array_with_several_null" { - ok( + try roundTrip( \\[1,null,null,null,2] ); } test "y_array_with_trailing_space" { - ok("[2] "); + try ok("[2] "); } test "y_number_0e+1" { - ok( + try ok( \\[0e+1] ); } test "y_number_0e1" { - ok( + try ok( \\[0e1] ); } test "y_number_after_space" { - ok( + try ok( \\[ 4] ); } test "y_number_double_close_to_zero" { - ok( + try ok( \\[-0.000000000000000000000000000000000000000000000000000000000000000000000000000001] ); } test "y_number_int_with_exp" { - ok( + try ok( \\[20e1] ); } test "y_number" { - ok( + try ok( \\[123e65] ); } test "y_number_minus_zero" { - ok( + try ok( \\[-0] ); } test "y_number_negative_int" { - ok( + try roundTrip( \\[-123] ); } test "y_number_negative_one" { - ok( + try roundTrip( \\[-1] ); } test "y_number_negative_zero" { - ok( + try ok( \\[-0] ); } test "y_number_real_capital_e" { - ok( + try ok( \\[1E22] ); } test "y_number_real_capital_e_neg_exp" { - ok( + try ok( \\[1E-2] ); } test "y_number_real_capital_e_pos_exp" { - ok( + try ok( \\[1E+2] ); } test "y_number_real_exponent" { - ok( + try ok( \\[123e45] ); } test "y_number_real_fraction_exponent" { - ok( + try ok( \\[123.456e78] ); } test "y_number_real_neg_exp" { - ok( + try ok( \\[1e-2] ); } test "y_number_real_pos_exponent" { - ok( + try ok( \\[1e+2] ); } test "y_number_simple_int" { - ok( + try roundTrip( \\[123] ); } test "y_number_simple_real" { - ok( + try ok( \\[123.456789] ); } test "y_object_basic" { - ok( + try roundTrip( \\{"asd":"sdf"} ); } test "y_object_duplicated_key_and_value" { - ok( + try ok( \\{"a":"b","a":"b"} ); } test "y_object_duplicated_key" { - ok( + try ok( \\{"a":"b","a":"c"} ); } test "y_object_empty" { - ok( + try roundTrip( \\{} ); } test "y_object_empty_key" { - ok( + try roundTrip( \\{"":0} ); } test "y_object_escaped_null_in_key" { - ok( + try ok( \\{"foo\u0000bar": 42} ); } test "y_object_extreme_numbers" { - ok( + try ok( \\{ "min": -1.0e+28, "max": 1.0e+28 } ); } test "y_object" { - ok( + try ok( \\{"asd":"sdf", "dfg":"fgh"} ); } test "y_object_long_strings" { - ok( + try ok( \\{"x":[{"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}], "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} ); } test "y_object_simple" { - ok( + try roundTrip( \\{"a":[]} ); } test "y_object_string_unicode" { - ok( + try ok( \\{"title":"\u041f\u043e\u043b\u0442\u043e\u0440\u0430 \u0417\u0435\u043c\u043b\u0435\u043a\u043e\u043f\u0430" } ); } test "y_object_with_newlines" { - ok( + try ok( \\{ \\"a": "b" \\} @@ -318,311 +334,311 @@ test "y_object_with_newlines" { } test "y_string_1_2_3_bytes_UTF-8_sequences" { - ok( + try ok( \\["\u0060\u012a\u12AB"] ); } test "y_string_accepted_surrogate_pair" { - ok( + try ok( \\["\uD801\udc37"] ); } test "y_string_accepted_surrogate_pairs" { - ok( + try ok( \\["\ud83d\ude39\ud83d\udc8d"] ); } test "y_string_allowed_escapes" { - ok( + try ok( \\["\"\\\/\b\f\n\r\t"] ); } test "y_string_backslash_and_u_escaped_zero" { - ok( + try ok( \\["\\u0000"] ); } test "y_string_backslash_doublequotes" { - ok( + try roundTrip( \\["\""] ); } test "y_string_comments" { - ok( + try ok( \\["a/*b*/c/*d//e"] ); } test "y_string_double_escape_a" { - ok( + try ok( \\["\\a"] ); } test "y_string_double_escape_n" { - ok( + try roundTrip( \\["\\n"] ); } test "y_string_escaped_control_character" { - ok( + try ok( \\["\u0012"] ); } test "y_string_escaped_noncharacter" { - ok( + try ok( \\["\uFFFF"] ); } test "y_string_in_array" { - ok( + try ok( \\["asd"] ); } test "y_string_in_array_with_leading_space" { - ok( + try ok( \\[ "asd"] ); } test "y_string_last_surrogates_1_and_2" { - ok( + try ok( \\["\uDBFF\uDFFF"] ); } test "y_string_nbsp_uescaped" { - ok( + try ok( \\["new\u00A0line"] ); } test "y_string_nonCharacterInUTF-8_U+10FFFF" { - ok( + try ok( \\["􏿿"] ); } test "y_string_nonCharacterInUTF-8_U+FFFF" { - ok( + try ok( \\["￿"] ); } test "y_string_null_escape" { - ok( + try ok( \\["\u0000"] ); } test "y_string_one-byte-utf-8" { - ok( + try ok( \\["\u002c"] ); } test "y_string_pi" { - ok( + try ok( \\["π"] ); } test "y_string_reservedCharacterInUTF-8_U+1BFFF" { - ok( + try ok( \\["𛿿"] ); } test "y_string_simple_ascii" { - ok( + try ok( \\["asd "] ); } test "y_string_space" { - ok( + try roundTrip( \\" " ); } test "y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF" { - ok( + try ok( \\["\uD834\uDd1e"] ); } test "y_string_three-byte-utf-8" { - ok( + try ok( \\["\u0821"] ); } test "y_string_two-byte-utf-8" { - ok( + try ok( \\["\u0123"] ); } test "y_string_u+2028_line_sep" { - ok("[\"\xe2\x80\xa8\"]"); + try ok("[\"\xe2\x80\xa8\"]"); } test "y_string_u+2029_par_sep" { - ok("[\"\xe2\x80\xa9\"]"); + try ok("[\"\xe2\x80\xa9\"]"); } test "y_string_uescaped_newline" { - ok( + try ok( \\["new\u000Aline"] ); } test "y_string_uEscape" { - ok( + try ok( \\["\u0061\u30af\u30EA\u30b9"] ); } test "y_string_unescaped_char_delete" { - ok("[\"\x7f\"]"); + try ok("[\"\x7f\"]"); } test "y_string_unicode_2" { - ok( + try ok( \\["⍂㈴⍂"] ); } test "y_string_unicodeEscapedBackslash" { - ok( + try ok( \\["\u005C"] ); } test "y_string_unicode_escaped_double_quote" { - ok( + try ok( \\["\u0022"] ); } test "y_string_unicode" { - ok( + try ok( \\["\uA66D"] ); } test "y_string_unicode_U+10FFFE_nonchar" { - ok( + try ok( \\["\uDBFF\uDFFE"] ); } test "y_string_unicode_U+1FFFE_nonchar" { - ok( + try ok( \\["\uD83F\uDFFE"] ); } test "y_string_unicode_U+200B_ZERO_WIDTH_SPACE" { - ok( + try ok( \\["\u200B"] ); } test "y_string_unicode_U+2064_invisible_plus" { - ok( + try ok( \\["\u2064"] ); } test "y_string_unicode_U+FDD0_nonchar" { - ok( + try ok( \\["\uFDD0"] ); } test "y_string_unicode_U+FFFE_nonchar" { - ok( + try ok( \\["\uFFFE"] ); } test "y_string_utf8" { - ok( + try ok( \\["€𝄞"] ); } test "y_string_with_del_character" { - ok("[\"a\x7fa\"]"); + try ok("[\"a\x7fa\"]"); } test "y_structure_lonely_false" { - ok( + try roundTrip( \\false ); } test "y_structure_lonely_int" { - ok( + try roundTrip( \\42 ); } test "y_structure_lonely_negative_real" { - ok( + try ok( \\-0.1 ); } test "y_structure_lonely_null" { - ok( + try roundTrip( \\null ); } test "y_structure_lonely_string" { - ok( + try roundTrip( \\"asd" ); } test "y_structure_lonely_true" { - ok( + try roundTrip( \\true ); } test "y_structure_string_empty" { - ok( + try roundTrip( \\"" ); } test "y_structure_trailing_newline" { - ok( + try roundTrip( \\["a"] ); } test "y_structure_true_in_array" { - ok( + try roundTrip( \\[true] ); } test "y_structure_whitespace_array" { - ok(" [] "); + try ok(" [] "); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/lib/std/math/ln.zig b/lib/std/math/ln.zig index e0ce32a7e1..ce7cb3d882 100644 --- a/lib/std/math/ln.zig +++ b/lib/std/math/ln.zig @@ -36,8 +36,9 @@ pub fn ln(x: anytype) @TypeOf(x) { .ComptimeInt => { return @as(comptime_int, math.floor(ln_64(@as(f64, x)))); }, - .Int => { - return @as(T, math.floor(ln_64(@as(f64, x)))); + .Int => |IntType| switch (IntType.signedness) { + .signed => return @compileError("ln not implemented for signed integers"), + .unsigned => return @as(T, math.floor(ln_64(@as(f64, x)))), }, else => @compileError("ln not implemented for " ++ @typeName(T)), } diff --git a/lib/std/math/log.zig b/lib/std/math/log.zig index ef4d4bbb97..1a8101e67a 100644 --- a/lib/std/math/log.zig +++ b/lib/std/math/log.zig @@ -31,9 +31,11 @@ pub fn log(comptime T: type, base: T, x: T) T { .ComptimeInt => { return @as(comptime_int, math.floor(math.ln(@as(f64, x)) / math.ln(float_base))); }, - .Int => { - // TODO implement integer log without using float math - return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base))); + + // TODO implement integer log without using float math + .Int => |IntType| switch (IntType.signedness) { + .signed => return @compileError("log not implemented for signed integers"), + .unsigned => return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base))), }, .Float => { @@ -53,7 +55,7 @@ pub fn log(comptime T: type, base: T, x: T) T { test "math.log integer" { expect(log(u8, 2, 0x1) == 0); expect(log(u8, 2, 0x2) == 1); - expect(log(i16, 2, 0x72) == 6); + expect(log(u16, 2, 0x72) == 6); expect(log(u32, 2, 0xFFFFFF) == 23); expect(log(u64, 2, 0x7FF0123456789ABC) == 62); } diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig index 719e0cf51d..a8211a7270 100644 --- a/lib/std/math/log10.zig +++ b/lib/std/math/log10.zig @@ -37,8 +37,9 @@ pub fn log10(x: anytype) @TypeOf(x) { .ComptimeInt => { return @as(comptime_int, math.floor(log10_64(@as(f64, x)))); }, - .Int => { - return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); + .Int => |IntType| switch (IntType.signedness) { + .signed => return @compileError("log10 not implemented for signed integers"), + .unsigned => return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))), }, else => @compileError("log10 not implemented for " ++ @typeName(T)), } diff --git a/lib/std/math/log2.zig b/lib/std/math/log2.zig index c44672751e..76bc79407c 100644 --- a/lib/std/math/log2.zig +++ b/lib/std/math/log2.zig @@ -43,8 +43,9 @@ pub fn log2(x: anytype) @TypeOf(x) { }) : (result += 1) {} return result; }, - .Int => { - return math.log2_int(T, x); + .Int => |IntType| switch (IntType.signedness) { + .signed => return @compileError("log2 not implemented for signed integers"), + .unsigned => return math.log2_int(T, x), }, else => @compileError("log2 not implemented for " ++ @typeName(T)), } diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig index 38609115d8..394164ff54 100644 --- a/lib/std/math/sqrt.zig +++ b/lib/std/math/sqrt.zig @@ -31,7 +31,10 @@ pub fn sqrt(x: anytype) Sqrt(@TypeOf(x)) { } return @as(T, sqrt_int(u128, x)); }, - .Int => return sqrt_int(T, x), + .Int => |IntType| switch (IntType.signedness) { + .signed => return @compileError("sqrt not implemented for signed integers"), + .unsigned => return sqrt_int(T, x), + }, else => @compileError("sqrt not implemented for " ++ @typeName(T)), } } diff --git a/lib/std/meta.zig b/lib/std/meta.zig index cdc93e5d33..860b6874c0 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -970,12 +970,15 @@ fn castPtr(comptime DestType: type, target: anytype) DestType { if (source.is_const and !dest.is_const or source.is_volatile and !dest.is_volatile) return @intToPtr(DestType, @ptrToInt(target)) + else if (@typeInfo(dest.child) == .Opaque) + // dest.alignment would error out + return @ptrCast(DestType, target) else return @ptrCast(DestType, @alignCast(dest.alignment, target)); } fn ptrInfo(comptime PtrType: type) TypeInfo.Pointer { - return switch(@typeInfo(PtrType)){ + return switch (@typeInfo(PtrType)) { .Optional => |opt_info| @typeInfo(opt_info.child).Pointer, .Pointer => |ptr_info| ptr_info, else => unreachable, @@ -1010,6 +1013,8 @@ test "std.meta.cast" { testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2))); testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2))); + + testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2))); } /// Given a value returns its size as C's sizeof operator would. @@ -1297,3 +1302,35 @@ pub fn globalOption(comptime name: []const u8, comptime T: type) ?T { return null; return @as(T, @field(root, name)); } + +/// This function is for translate-c and is not intended for general use. +/// Convert from clang __builtin_shufflevector index to Zig @shuffle index +/// clang requires __builtin_shufflevector index arguments to be integer constants. +/// negative values for `this_index` indicate "don't care" so we arbitrarily choose 0 +/// clang enforces that `this_index` is less than the total number of vector elements +/// See https://ziglang.org/documentation/master/#shuffle +/// See https://clang.llvm.org/docs/LanguageExtensions.html#langext-builtin-shufflevector +pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len: usize) i32 { + if (this_index <= 0) return 0; + + const positive_index = @intCast(usize, this_index); + if (positive_index < source_vector_len) return @intCast(i32, this_index); + const b_index = positive_index - source_vector_len; + return ~@intCast(i32, b_index); +} + +test "shuffleVectorIndex" { + const vector_len: usize = 4; + + testing.expect(shuffleVectorIndex(-1, vector_len) == 0); + + testing.expect(shuffleVectorIndex(0, vector_len) == 0); + testing.expect(shuffleVectorIndex(1, vector_len) == 1); + testing.expect(shuffleVectorIndex(2, vector_len) == 2); + testing.expect(shuffleVectorIndex(3, vector_len) == 3); + + testing.expect(shuffleVectorIndex(4, vector_len) == -1); + testing.expect(shuffleVectorIndex(5, vector_len) == -2); + testing.expect(shuffleVectorIndex(6, vector_len) == -3); + testing.expect(shuffleVectorIndex(7, vector_len) == -4); +} diff --git a/lib/std/os.zig b/lib/std/os.zig index e4bd96de05..9826ba46f1 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3254,6 +3254,9 @@ pub const ConnectError = error{ /// Connection was reset by peer before connect could complete. ConnectionResetByPeer, + + /// Socket is non-blocking and already has a pending connection in progress. + ConnectionPending, } || UnexpectedError; /// Initiate a connection on a socket. @@ -3294,7 +3297,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne EADDRNOTAVAIL => return error.AddressNotAvailable, EAFNOSUPPORT => return error.AddressFamilyNotSupported, EAGAIN, EINPROGRESS => return error.WouldBlock, - EALREADY => unreachable, // The socket is nonblocking and a previous connection attempt has not yet been completed. + EALREADY => return error.ConnectionPending, EBADF => unreachable, // sockfd is not a valid open file descriptor. ECONNREFUSED => return error.ConnectionRefused, ECONNRESET => return error.ConnectionResetByPeer, @@ -3325,7 +3328,7 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void { EADDRNOTAVAIL => return error.AddressNotAvailable, EAFNOSUPPORT => return error.AddressFamilyNotSupported, EAGAIN => return error.SystemResources, - EALREADY => unreachable, // The socket is nonblocking and a previous connection attempt has not yet been completed. + EALREADY => return error.ConnectionPending, EBADF => unreachable, // sockfd is not a valid open file descriptor. ECONNREFUSED => return error.ConnectionRefused, EFAULT => unreachable, // The socket structure address is outside the user's address space. diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index 21fa058aef..86d89016f3 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -21,6 +21,7 @@ pub usingnamespace switch (builtin.arch) { .riscv64 => @import("linux/riscv64.zig"), .sparcv9 => @import("linux/sparc64.zig"), .mips, .mipsel => @import("linux/mips.zig"), + .powerpc => @import("linux/powerpc.zig"), .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"), else => struct {}, }; @@ -586,6 +587,92 @@ pub const IP_DEFAULT_MULTICAST_TTL = 1; pub const IP_DEFAULT_MULTICAST_LOOP = 1; pub const IP_MAX_MEMBERSHIPS = 20; +// IPv6 socket options + +pub const IPV6_ADDRFORM = 1; +pub const IPV6_2292PKTINFO = 2; +pub const IPV6_2292HOPOPTS = 3; +pub const IPV6_2292DSTOPTS = 4; +pub const IPV6_2292RTHDR = 5; +pub const IPV6_2292PKTOPTIONS = 6; +pub const IPV6_CHECKSUM = 7; +pub const IPV6_2292HOPLIMIT = 8; +pub const IPV6_NEXTHOP = 9; +pub const IPV6_AUTHHDR = 10; +pub const IPV6_FLOWINFO = 11; + +pub const IPV6_UNICAST_HOPS = 16; +pub const IPV6_MULTICAST_IF = 17; +pub const IPV6_MULTICAST_HOPS = 18; +pub const IPV6_MULTICAST_LOOP = 19; +pub const IPV6_ADD_MEMBERSHIP = 20; +pub const IPV6_DROP_MEMBERSHIP = 21; +pub const IPV6_ROUTER_ALERT = 22; +pub const IPV6_MTU_DISCOVER = 23; +pub const IPV6_MTU = 24; +pub const IPV6_RECVERR = 25; +pub const IPV6_V6ONLY = 26; +pub const IPV6_JOIN_ANYCAST = 27; +pub const IPV6_LEAVE_ANYCAST = 28; + +// IPV6_MTU_DISCOVER values +pub const IPV6_PMTUDISC_DONT = 0; +pub const IPV6_PMTUDISC_WANT = 1; +pub const IPV6_PMTUDISC_DO = 2; +pub const IPV6_PMTUDISC_PROBE = 3; +pub const IPV6_PMTUDISC_INTERFACE = 4; +pub const IPV6_PMTUDISC_OMIT = 5; + +// Flowlabel +pub const IPV6_FLOWLABEL_MGR = 32; +pub const IPV6_FLOWINFO_SEND = 33; +pub const IPV6_IPSEC_POLICY = 34; +pub const IPV6_XFRM_POLICY = 35; +pub const IPV6_HDRINCL = 36; + +// Advanced API (RFC3542) (1) +pub const IPV6_RECVPKTINFO = 49; +pub const IPV6_PKTINFO = 50; +pub const IPV6_RECVHOPLIMIT = 51; +pub const IPV6_HOPLIMIT = 52; +pub const IPV6_RECVHOPOPTS = 53; +pub const IPV6_HOPOPTS = 54; +pub const IPV6_RTHDRDSTOPTS = 55; +pub const IPV6_RECVRTHDR = 56; +pub const IPV6_RTHDR = 57; +pub const IPV6_RECVDSTOPTS = 58; +pub const IPV6_DSTOPTS = 59; +pub const IPV6_RECVPATHMTU = 60; +pub const IPV6_PATHMTU = 61; +pub const IPV6_DONTFRAG = 62; + +// Advanced API (RFC3542) (2) +pub const IPV6_RECVTCLASS = 66; +pub const IPV6_TCLASS = 67; + +pub const IPV6_AUTOFLOWLABEL = 70; + +// RFC5014: Source address selection +pub const IPV6_ADDR_PREFERENCES = 72; + +pub const IPV6_PREFER_SRC_TMP = 0x0001; +pub const IPV6_PREFER_SRC_PUBLIC = 0x0002; +pub const IPV6_PREFER_SRC_PUBTMP_DEFAULT = 0x0100; +pub const IPV6_PREFER_SRC_COA = 0x0004; +pub const IPV6_PREFER_SRC_HOME = 0x0400; +pub const IPV6_PREFER_SRC_CGA = 0x0008; +pub const IPV6_PREFER_SRC_NONCGA = 0x0800; + +// RFC5082: Generalized Ttl Security Mechanism +pub const IPV6_MINHOPCOUNT = 73; + +pub const IPV6_ORIGDSTADDR = 74; +pub const IPV6_RECVORIGDSTADDR = IPV6_ORIGDSTADDR; +pub const IPV6_TRANSPARENT = 75; +pub const IPV6_UNICAST_IF = 76; +pub const IPV6_RECVFRAGSIZE = 77; +pub const IPV6_FREEBIND = 78; + pub const MSG_OOB = 0x0001; pub const MSG_PEEK = 0x0002; pub const MSG_DONTROUTE = 0x0004; diff --git a/lib/std/os/bits/linux/powerpc.zig b/lib/std/os/bits/linux/powerpc.zig new file mode 100644 index 0000000000..baa6a57bcf --- /dev/null +++ b/lib/std/os/bits/linux/powerpc.zig @@ -0,0 +1,635 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), which is MIT licensed. +// The MIT license requires this copyright notice to be included in all copies +// and substantial portions of the software. + +const std = @import("../../../std.zig"); +const linux = std.os.linux; +const socklen_t = linux.socklen_t; +const iovec = linux.iovec; +const iovec_const = linux.iovec_const; +const uid_t = linux.uid_t; +const gid_t = linux.gid_t; +const pid_t = linux.pid_t; +const stack_t = linux.stack_t; +const sigset_t = linux.sigset_t; +pub const SYS = extern enum(usize) { + restart_syscall = 0, + exit = 1, + fork = 2, + read = 3, + write = 4, + open = 5, + close = 6, + waitpid = 7, + creat = 8, + link = 9, + unlink = 10, + execve = 11, + chdir = 12, + time = 13, + mknod = 14, + chmod = 15, + lchown = 16, + @"break" = 17, + oldstat = 18, + lseek = 19, + getpid = 20, + mount = 21, + umount = 22, + setuid = 23, + getuid = 24, + stime = 25, + ptrace = 26, + alarm = 27, + oldfstat = 28, + pause = 29, + utime = 30, + stty = 31, + gtty = 32, + access = 33, + nice = 34, + ftime = 35, + sync = 36, + kill = 37, + rename = 38, + mkdir = 39, + rmdir = 40, + dup = 41, + pipe = 42, + times = 43, + prof = 44, + brk = 45, + setgid = 46, + getgid = 47, + signal = 48, + geteuid = 49, + getegid = 50, + acct = 51, + umount2 = 52, + lock = 53, + ioctl = 54, + fcntl = 55, + mpx = 56, + setpgid = 57, + ulimit = 58, + oldolduname = 59, + umask = 60, + chroot = 61, + ustat = 62, + dup2 = 63, + getppid = 64, + getpgrp = 65, + setsid = 66, + sigaction = 67, + sgetmask = 68, + ssetmask = 69, + setreuid = 70, + setregid = 71, + sigsuspend = 72, + sigpending = 73, + sethostname = 74, + setrlimit = 75, + getrlimit = 76, + getrusage = 77, + gettimeofday = 78, + settimeofday = 79, + getgroups = 80, + setgroups = 81, + select = 82, + symlink = 83, + oldlstat = 84, + readlink = 85, + uselib = 86, + swapon = 87, + reboot = 88, + readdir = 89, + mmap = 90, + munmap = 91, + truncate = 92, + ftruncate = 93, + fchmod = 94, + fchown = 95, + getpriority = 96, + setpriority = 97, + profil = 98, + statfs = 99, + fstatfs = 100, + ioperm = 101, + socketcall = 102, + syslog = 103, + setitimer = 104, + getitimer = 105, + stat = 106, + lstat = 107, + fstat = 108, + olduname = 109, + iopl = 110, + vhangup = 111, + idle = 112, + vm86 = 113, + wait4 = 114, + swapoff = 115, + sysinfo = 116, + ipc = 117, + fsync = 118, + sigreturn = 119, + clone = 120, + setdomainname = 121, + uname = 122, + modify_ldt = 123, + adjtimex = 124, + mprotect = 125, + sigprocmask = 126, + create_module = 127, + init_module = 128, + delete_module = 129, + get_kernel_syms = 130, + quotactl = 131, + getpgid = 132, + fchdir = 133, + bdflush = 134, + sysfs = 135, + personality = 136, + afs_syscall = 137, + setfsuid = 138, + setfsgid = 139, + _llseek = 140, + getdents = 141, + _newselect = 142, + flock = 143, + msync = 144, + readv = 145, + writev = 146, + getsid = 147, + fdatasync = 148, + _sysctl = 149, + mlock = 150, + munlock = 151, + mlockall = 152, + munlockall = 153, + sched_setparam = 154, + sched_getparam = 155, + sched_setscheduler = 156, + sched_getscheduler = 157, + sched_yield = 158, + sched_get_priority_max = 159, + sched_get_priority_min = 160, + sched_rr_get_interval = 161, + nanosleep = 162, + mremap = 163, + setresuid = 164, + getresuid = 165, + query_module = 166, + poll = 167, + nfsservctl = 168, + setresgid = 169, + getresgid = 170, + prctl = 171, + rt_sigreturn = 172, + rt_sigaction = 173, + rt_sigprocmask = 174, + rt_sigpending = 175, + rt_sigtimedwait = 176, + rt_sigqueueinfo = 177, + rt_sigsuspend = 178, + pread64 = 179, + pwrite64 = 180, + chown = 181, + getcwd = 182, + capget = 183, + capset = 184, + sigaltstack = 185, + sendfile = 186, + getpmsg = 187, + putpmsg = 188, + vfork = 189, + ugetrlimit = 190, + readahead = 191, + mmap2 = 192, + truncate64 = 193, + ftruncate64 = 194, + stat64 = 195, + lstat64 = 196, + fstat64 = 197, + pciconfig_read = 198, + pciconfig_write = 199, + pciconfig_iobase = 200, + multiplexer = 201, + getdents64 = 202, + pivot_root = 203, + fcntl64 = 204, + madvise = 205, + mincore = 206, + gettid = 207, + tkill = 208, + setxattr = 209, + lsetxattr = 210, + fsetxattr = 211, + getxattr = 212, + lgetxattr = 213, + fgetxattr = 214, + listxattr = 215, + llistxattr = 216, + flistxattr = 217, + removexattr = 218, + lremovexattr = 219, + fremovexattr = 220, + futex = 221, + sched_setaffinity = 222, + sched_getaffinity = 223, + tuxcall = 225, + sendfile64 = 226, + io_setup = 227, + io_destroy = 228, + io_getevents = 229, + io_submit = 230, + io_cancel = 231, + set_tid_address = 232, + fadvise64 = 233, + exit_group = 234, + lookup_dcookie = 235, + epoll_create = 236, + epoll_ctl = 237, + epoll_wait = 238, + remap_file_pages = 239, + timer_create = 240, + timer_settime = 241, + timer_gettime = 242, + timer_getoverrun = 243, + timer_delete = 244, + clock_settime = 245, + clock_gettime = 246, + clock_getres = 247, + clock_nanosleep = 248, + swapcontext = 249, + tgkill = 250, + utimes = 251, + statfs64 = 252, + fstatfs64 = 253, + fadvise64_64 = 254, + rtas = 255, + sys_debug_setcontext = 256, + migrate_pages = 258, + mbind = 259, + get_mempolicy = 260, + set_mempolicy = 261, + mq_open = 262, + mq_unlink = 263, + mq_timedsend = 264, + mq_timedreceive = 265, + mq_notify = 266, + mq_getsetattr = 267, + kexec_load = 268, + add_key = 269, + request_key = 270, + keyctl = 271, + waitid = 272, + ioprio_set = 273, + ioprio_get = 274, + inotify_init = 275, + inotify_add_watch = 276, + inotify_rm_watch = 277, + spu_run = 278, + spu_create = 279, + pselect6 = 280, + ppoll = 281, + unshare = 282, + splice = 283, + tee = 284, + vmsplice = 285, + openat = 286, + mkdirat = 287, + mknodat = 288, + fchownat = 289, + futimesat = 290, + fstatat64 = 291, + unlinkat = 292, + renameat = 293, + linkat = 294, + symlinkat = 295, + readlinkat = 296, + fchmodat = 297, + faccessat = 298, + get_robust_list = 299, + set_robust_list = 300, + move_pages = 301, + getcpu = 302, + epoll_pwait = 303, + utimensat = 304, + signalfd = 305, + timerfd_create = 306, + eventfd = 307, + sync_file_range2 = 308, + fallocate = 309, + subpage_prot = 310, + timerfd_settime = 311, + timerfd_gettime = 312, + signalfd4 = 313, + eventfd2 = 314, + epoll_create1 = 315, + dup3 = 316, + pipe2 = 317, + inotify_init1 = 318, + perf_event_open = 319, + preadv = 320, + pwritev = 321, + rt_tgsigqueueinfo = 322, + fanotify_init = 323, + fanotify_mark = 324, + prlimit64 = 325, + socket = 326, + bind = 327, + connect = 328, + listen = 329, + accept = 330, + getsockname = 331, + getpeername = 332, + socketpair = 333, + send = 334, + sendto = 335, + recv = 336, + recvfrom = 337, + shutdown = 338, + setsockopt = 339, + getsockopt = 340, + sendmsg = 341, + recvmsg = 342, + recvmmsg = 343, + accept4 = 344, + name_to_handle_at = 345, + open_by_handle_at = 346, + clock_adjtime = 347, + syncfs = 348, + sendmmsg = 349, + setns = 350, + process_vm_readv = 351, + process_vm_writev = 352, + finit_module = 353, + kcmp = 354, + sched_setattr = 355, + sched_getattr = 356, + renameat2 = 357, + seccomp = 358, + getrandom = 359, + memfd_create = 360, + bpf = 361, + execveat = 362, + switch_endian = 363, + userfaultfd = 364, + membarrier = 365, + mlock2 = 378, + copy_file_range = 379, + preadv2 = 380, + pwritev2 = 381, + kexec_file_load = 382, + statx = 383, + pkey_alloc = 384, + pkey_free = 385, + pkey_mprotect = 386, + rseq = 387, + io_pgetevents = 388, + semget = 393, + semctl = 394, + shmget = 395, + shmctl = 396, + shmat = 397, + shmdt = 398, + msgget = 399, + msgsnd = 400, + msgrcv = 401, + msgctl = 402, + clock_gettime64 = 403, + clock_settime64 = 404, + clock_adjtime64 = 405, + clock_getres_time64 = 406, + clock_nanosleep_time64 = 407, + timer_gettime64 = 408, + timer_settime64 = 409, + timerfd_gettime64 = 410, + timerfd_settime64 = 411, + utimensat_time64 = 412, + pselect6_time64 = 413, + ppoll_time64 = 414, + io_pgetevents_time64 = 416, + recvmmsg_time64 = 417, + mq_timedsend_time64 = 418, + mq_timedreceive_time64 = 419, + semtimedop_time64 = 420, + rt_sigtimedwait_time64 = 421, + futex_time64 = 422, + sched_rr_get_interval_time64 = 423, + pidfd_send_signal = 424, + io_uring_setup = 425, + io_uring_enter = 426, + io_uring_register = 427, + open_tree = 428, + move_mount = 429, + fsopen = 430, + fsconfig = 431, + fsmount = 432, + fspick = 433, + pidfd_open = 434, + clone3 = 435, + close_range = 436, + openat2 = 437, + pidfd_getfd = 438, + faccessat2 = 439, + process_madvise = 440, +}; + +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o40000; +pub const O_NOFOLLOW = 0o100000; +pub const O_CLOEXEC = 0o2000000; + +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o400000; +pub const O_LARGEFILE = 0o200000; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20040000; +pub const O_NDELAY = O_NONBLOCK; + +pub const F_DUPFD = 0; +pub const F_GETFD = 1; +pub const F_SETFD = 2; +pub const F_GETFL = 3; +pub const F_SETFL = 4; + +pub const F_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_GETLK = 12; +pub const F_SETLK = 13; +pub const F_SETLKW = 14; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; + +pub const F_RDLCK = 0; +pub const F_WRLCK = 1; +pub const F_UNLCK = 2; + +pub const LOCK_SH = 1; +pub const LOCK_EX = 2; +pub const LOCK_UN = 8; +pub const LOCK_NB = 4; + +/// stack-like segment +pub const MAP_GROWSDOWN = 0x0100; + +/// ETXTBSY +pub const MAP_DENYWRITE = 0x0800; + +/// mark it as an executable +pub const MAP_EXECUTABLE = 0x1000; + +/// pages are locked +pub const MAP_LOCKED = 0x0080; + +/// don't check for reservations +pub const MAP_NORESERVE = 0x0040; + +pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; +pub const VDSO_CGT_VER = "LINUX_2.6.15"; + +pub const Flock = extern struct { + l_type: i16, + l_whence: i16, + l_start: off_t, + l_len: off_t, + l_pid: pid_t, +}; + +pub const msghdr = extern struct { + msg_name: ?*sockaddr, + msg_namelen: socklen_t, + msg_iov: [*]iovec, + msg_iovlen: usize, + msg_control: ?*c_void, + msg_controllen: socklen_t, + msg_flags: i32, +}; + +pub const msghdr_const = extern struct { + msg_name: ?*const sockaddr, + msg_namelen: socklen_t, + msg_iov: [*]iovec_const, + msg_iovlen: usize, + msg_control: ?*c_void, + msg_controllen: socklen_t, + msg_flags: i32, +}; + +pub const blksize_t = i32; +pub const nlink_t = u32; +pub const time_t = isize; +pub const mode_t = u32; +pub const off_t = i64; +pub const ino_t = u64; +pub const dev_t = u64; +pub const blkcnt_t = i64; + +// The `stat` definition used by the Linux kernel. +pub const kernel_stat = extern struct { + dev: dev_t, + ino: ino_t, + mode: mode_t, + nlink: nlink_t, + uid: uid_t, + gid: gid_t, + rdev: dev_t, + __rdev_padding: i16, + size: off_t, + blksize: blksize_t, + blocks: blkcnt_t, + __atim32: timespec32, + __mtim32: timespec32, + __ctim32: timespec32, + __unused: [2]u32, + atim: timespec, + mtim: timespec, + ctim: timespec, + + const timespec32 = extern struct { + tv_sec: i32, + tv_nsec: i32, + }; + + pub fn atime(self: @This()) timespec { + return self.atim; + } + + pub fn mtime(self: @This()) timespec { + return self.mtim; + } + + pub fn ctime(self: @This()) timespec { + return self.ctim; + } +}; + +// The `stat64` definition used by the libc. +pub const libc_stat = kernel_stat; + +pub const timespec = extern struct { + tv_sec: time_t, + tv_nsec: isize, +}; + +pub const timeval = extern struct { + tv_sec: time_t, + tv_usec: isize, +}; + +pub const timezone = extern struct { + tz_minuteswest: i32, + tz_dsttime: i32, +}; + +pub const greg_t = u32; +pub const gregset_t = [48]greg_t; +pub const fpregset_t = [33]f64; + +pub const vrregset = extern struct { + vrregs: [32][4]u32, + vrsave: u32, + _pad: [2]u32, + vscr: u32, +}; +pub const vrregset_t = vrregset; + +pub const mcontext_t = extern struct { + gp_regs: gregset_t, + fp_regs: fpregset_t, + v_regs: vrregset_t align(16), +}; + +pub const ucontext_t = extern struct { + flags: u32, + link: *ucontext_t, + stack: stack_t, + pad: [7]i32, + regs: *mcontext_t, + sigmask: sigset_t, + pad2: [3]i32, + mcontext: mcontext_t, +}; + +pub const Elf_Symndx = u32; + +pub const MMAP2_UNIT = 4096; diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index 57ae70ddbf..dfb6c3bdf9 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -813,10 +813,6 @@ pub const sigset_t = extern struct { __bits: [_SIG_WORDS]u32, }; -pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); -pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); -pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); - pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS }; // XXX x86_64 specific @@ -1219,3 +1215,25 @@ pub const rlimit = extern struct { pub const SHUT_RD = 0; pub const SHUT_WR = 1; pub const SHUT_RDWR = 2; + +pub const nfds_t = u32; + +pub const pollfd = extern struct { + fd: fd_t, + events: i16, + revents: i16, +}; + +/// Testable events (may be specified in events field). +pub const POLLIN = 0x0001; +pub const POLLPRI = 0x0002; +pub const POLLOUT = 0x0004; +pub const POLLRDNORM = 0x0040; +pub const POLLWRNORM = POLLOUT; +pub const POLLRDBAND = 0x0080; +pub const POLLWRBAND = 0x0100; + +/// Non-testable events (may not be specified in events field). +pub const POLLERR = 0x0008; +pub const POLLHUP = 0x0010; +pub const POLLNVAL = 0x0020; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 900e3f2871..ed08438425 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -26,6 +26,7 @@ pub usingnamespace switch (builtin.arch) { .riscv64 => @import("linux/riscv64.zig"), .sparcv9 => @import("linux/sparc64.zig"), .mips, .mipsel => @import("linux/mips.zig"), + .powerpc => @import("linux/powerpc.zig"), .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"), else => struct {}, }; diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index 6ffee12bfd..fc5af34696 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -1354,7 +1354,7 @@ test "timeout (after a relative time)" { .flags = 0, }, cqe); - // Tests should not depend on timings: skip test (result) if outside margin. + // Tests should not depend on timings: skip test if outside margin. if (!std.math.approxEqAbs(f64, ms, @intToFloat(f64, stopped - started), margin)) return error.SkipZigTest; } diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig new file mode 100644 index 0000000000..567ad2bc1f --- /dev/null +++ b/lib/std/os/linux/powerpc.zig @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2015-2021 Zig Contributors +// This file is part of [zig](https://ziglang.org/), which is MIT licensed. +// The MIT license requires this copyright notice to be included in all copies +// and substantial portions of the software. + +usingnamespace @import("../bits.zig"); + +pub fn syscall0(number: SYS) usize { + return asm volatile ( + \\ sc + \\ bns+ 1f + \\ neg 3, 3 + \\ 1: + : [ret] "={r3}" (-> usize) + : [number] "{r0}" (@enumToInt(number)) + : "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" + ); +} + +pub fn syscall1(number: SYS, arg1: usize) usize { + return asm volatile ( + \\ sc + \\ bns+ 1f + \\ neg 3, 3 + \\ 1: + : [ret] "={r3}" (-> usize) + : [number] "{r0}" (@enumToInt(number)), + [arg1] "{r3}" (arg1) + : "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" + ); +} + +pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize { + return asm volatile ( + \\ sc + \\ bns+ 1f + \\ neg 3, 3 + \\ 1: + : [ret] "={r3}" (-> usize) + : [number] "{r0}" (@enumToInt(number)), + [arg1] "{r3}" (arg1), + [arg2] "{r4}" (arg2) + : "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" + ); +} + +pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize { + return asm volatile ( + \\ sc + \\ bns+ 1f + \\ neg 3, 3 + \\ 1: + : [ret] "={r3}" (-> usize) + : [number] "{r0}" (@enumToInt(number)), + [arg1] "{r3}" (arg1), + [arg2] "{r4}" (arg2), + [arg3] "{r5}" (arg3) + : "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" + ); +} + +pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { + return asm volatile ( + \\ sc + \\ bns+ 1f + \\ neg 3, 3 + \\ 1: + : [ret] "={r3}" (-> usize) + : [number] "{r0}" (@enumToInt(number)), + [arg1] "{r3}" (arg1), + [arg2] "{r4}" (arg2), + [arg3] "{r5}" (arg3), + [arg4] "{r6}" (arg4) + : "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" + ); +} + +pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { + return asm volatile ( + \\ sc + \\ bns+ 1f + \\ neg 3, 3 + \\ 1: + : [ret] "={r3}" (-> usize) + : [number] "{r0}" (@enumToInt(number)), + [arg1] "{r3}" (arg1), + [arg2] "{r4}" (arg2), + [arg3] "{r5}" (arg3), + [arg4] "{r6}" (arg4), + [arg5] "{r7}" (arg5) + : "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" + ); +} + +pub fn syscall6( + number: SYS, + arg1: usize, + arg2: usize, + arg3: usize, + arg4: usize, + arg5: usize, + arg6: usize, +) usize { + return asm volatile ( + \\ sc + \\ bns+ 1f + \\ neg 3, 3 + \\ 1: + : [ret] "={r3}" (-> usize) + : [number] "{r0}" (@enumToInt(number)), + [arg1] "{r3}" (arg1), + [arg2] "{r4}" (arg2), + [arg3] "{r5}" (arg3), + [arg4] "{r6}" (arg4), + [arg5] "{r7}" (arg5), + [arg6] "{r8}" (arg6) + : "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" + ); +} + +/// This matches the libc clone function. +pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: usize, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; + +pub const restore = restore_rt; + +pub fn restore_rt() callconv(.Naked) void { + return asm volatile ("sc" + : + : [number] "{r0}" (@enumToInt(SYS.rt_sigreturn)) + : "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" + ); +} diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig index 51cbafc133..4e1b237d0d 100644 --- a/lib/std/special/c.zig +++ b/lib/std/special/c.zig @@ -491,6 +491,71 @@ fn clone() callconv(.Naked) void { \\ syscall ); }, + .powerpc => { + // __clone(func, stack, flags, arg, ptid, tls, ctid) + // 3, 4, 5, 6, 7, 8, 9 + + // syscall(SYS_clone, flags, stack, ptid, tls, ctid) + // 0 3, 4, 5, 6, 7 + asm volatile ( + \\# store non-volatile regs r30, r31 on stack in order to put our + \\# start func and its arg there + \\stwu 30, -16(1) + \\stw 31, 4(1) + \\ + \\# save r3 (func) into r30, and r6(arg) into r31 + \\mr 30, 3 + \\mr 31, 6 + \\ + \\# create initial stack frame for new thread + \\clrrwi 4, 4, 4 + \\li 0, 0 + \\stwu 0, -16(4) + \\ + \\#move c into first arg + \\mr 3, 5 + \\#mr 4, 4 + \\mr 5, 7 + \\mr 6, 8 + \\mr 7, 9 + \\ + \\# move syscall number into r0 + \\li 0, 120 + \\ + \\sc + \\ + \\# check for syscall error + \\bns+ 1f # jump to label 1 if no summary overflow. + \\#else + \\neg 3, 3 #negate the result (errno) + \\1: + \\# compare sc result with 0 + \\cmpwi cr7, 3, 0 + \\ + \\# if not 0, jump to end + \\bne cr7, 2f + \\ + \\#else: we're the child + \\#call funcptr: move arg (d) into r3 + \\mr 3, 31 + \\#move r30 (funcptr) into CTR reg + \\mtctr 30 + \\# call CTR reg + \\bctrl + \\# mov SYS_exit into r0 (the exit param is already in r3) + \\li 0, 1 + \\sc + \\ + \\2: + \\ + \\# restore stack + \\lwz 30, 0(1) + \\lwz 31, 4(1) + \\addi 1, 1, 16 + \\ + \\blr + ); + }, .powerpc64, .powerpc64le => { // __clone(func, stack, flags, arg, ptid, tls, ctid) // 3, 4, 5, 6, 7, 8, 9 diff --git a/lib/std/special/docs/index.html b/lib/std/special/docs/index.html index 98f1938cc6..61e3bb4ed2 100644 --- a/lib/std/special/docs/index.html +++ b/lib/std/special/docs/index.html @@ -43,6 +43,8 @@ /* layout */ .canvas { + display: flex; + flex-direction: column; width: 100vw; height: 100vh; overflow: hidden; @@ -53,12 +55,21 @@ background-color: var(--bg-color); } + .banner { + background-color: darkred; + text-align: center; + color: white; + padding: 15px 5px; + } + + .banner a { + color: bisque; + text-decoration: underline; + } + .flex-main { display: flex; - width: 100%; - height: 100%; - justify-content: center; - + overflow-y: hidden; z-index: 100; } @@ -515,7 +526,7 @@ -
These docs are experimental. Progress depends on the self-hosted compiler, consider reading the stlib source in the meantime.
+