| author | |
| committer | |
| log | 6d5abf87ecd3509c6fb8b9c917b73b4db2ae59ff |
| tree | fcf1f309750159e579bdf99e2f7646c3bbd8a1a9 |
| parent | 6d28b28ccc689e6bf8849b1d39e969e8da760999 |
| parent | f7b1e02158550a8df3c189299da88568b381f5b1 |
| signature |
implement `@as` builtin and fix result location semantics with regards to type coercion221 files changed, 1852 insertions(+), 1705 deletions(-)
build.zig+1-1| ... | @@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { | ... | @@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { |
| 155 | ) catch unreachable; | 155 | ) catch unreachable; |
| 156 | for (dep.system_libs.toSliceConst()) |lib| { | 156 | for (dep.system_libs.toSliceConst()) |lib| { |
| 157 | const static_bare_name = if (mem.eql(u8, lib, "curses")) | 157 | const static_bare_name = if (mem.eql(u8, lib, "curses")) |
| 158 | ([]const u8)("libncurses.a") | 158 | @as([]const u8, "libncurses.a") |
| 159 | else | 159 | else |
| 160 | b.fmt("lib{}.a", lib); | 160 | b.fmt("lib{}.a", lib); |
| 161 | const static_lib_name = fs.path.join( | 161 | const static_lib_name = fs.path.join( |
doc/docgen.zig+2-2| ... | @@ -10,8 +10,8 @@ const testing = std.testing; | ... | @@ -10,8 +10,8 @@ const testing = std.testing; |
| 10 | 10 | ||
| 11 | const max_doc_file_size = 10 * 1024 * 1024; | 11 | const max_doc_file_size = 10 * 1024 * 1024; |
| 12 | 12 | ||
| 13 | const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt(); | 13 | const exe_ext = @as(std.build.Target, std.build.Target.Native).exeFileExt(); |
| 14 | const obj_ext = std.build.Target(std.build.Target.Native).oFileExt(); | 14 | const obj_ext = @as(std.build.Target, std.build.Target.Native).oFileExt(); |
| 15 | const tmp_dir_name = "docgen_tmp"; | 15 | const tmp_dir_name = "docgen_tmp"; |
| 16 | const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext; | 16 | const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext; |
| 17 | 17 |
doc/langref.html.in+78-70| ... | @@ -712,7 +712,7 @@ test "init with undefined" { | ... | @@ -712,7 +712,7 @@ test "init with undefined" { |
| 712 | } | 712 | } |
| 713 | {#code_end#} | 713 | {#code_end#} |
| 714 | <p> | 714 | <p> |
| 715 | {#syntax#}undefined{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to any type. | 715 | {#syntax#}undefined{#endsyntax#} can be {#link|coerced|Type Coercion#} to any type. |
| 716 | Once this happens, it is no longer possible to detect that the value is {#syntax#}undefined{#endsyntax#}. | 716 | Once this happens, it is no longer possible to detect that the value is {#syntax#}undefined{#endsyntax#}. |
| 717 | {#syntax#}undefined{#endsyntax#} means the value could be anything, even something that is nonsense | 717 | {#syntax#}undefined{#endsyntax#} means the value could be anything, even something that is nonsense |
| 718 | according to the type. Translated into English, {#syntax#}undefined{#endsyntax#} means "Not a meaningful | 718 | according to the type. Translated into English, {#syntax#}undefined{#endsyntax#} means "Not a meaningful |
| ... | @@ -920,7 +920,7 @@ fn divide(a: i32, b: i32) i32 { | ... | @@ -920,7 +920,7 @@ fn divide(a: i32, b: i32) i32 { |
| 920 | {#syntax#}f128{#endsyntax#}. | 920 | {#syntax#}f128{#endsyntax#}. |
| 921 | </p> | 921 | </p> |
| 922 | <p> | 922 | <p> |
| 923 | Float literals {#link|implicitly cast|Implicit Casts#} to any floating point type, | 923 | Float literals {#link|coerce|Type Coercion#} to any floating point type, |
| 924 | and to any {#link|integer|Integers#} type when there is no fractional component. | 924 | and to any {#link|integer|Integers#} type when there is no fractional component. |
| 925 | </p> | 925 | </p> |
| 926 | {#code_begin|syntax#} | 926 | {#code_begin|syntax#} |
| ... | @@ -950,7 +950,7 @@ const nan = std.math.nan(f128); | ... | @@ -950,7 +950,7 @@ const nan = std.math.nan(f128); |
| 950 | {#code_begin|obj|foo#} | 950 | {#code_begin|obj|foo#} |
| 951 | {#code_release_fast#} | 951 | {#code_release_fast#} |
| 952 | const builtin = @import("builtin"); | 952 | const builtin = @import("builtin"); |
| 953 | const big = f64(1 << 40); | 953 | const big = @as(f64, 1 << 40); |
| 954 | 954 | ||
| 955 | export fn foo_strict(x: f64) f64 { | 955 | export fn foo_strict(x: f64) f64 { |
| 956 | return x + big - big; | 956 | return x + big - big; |
| ... | @@ -1652,7 +1652,7 @@ test "iterate over an array" { | ... | @@ -1652,7 +1652,7 @@ test "iterate over an array" { |
| 1652 | for (message) |byte| { | 1652 | for (message) |byte| { |
| 1653 | sum += byte; | 1653 | sum += byte; |
| 1654 | } | 1654 | } |
| 1655 | assert(sum == usize('h') + usize('e') + usize('l') * 2 + usize('o')); | 1655 | assert(sum == 'h' + 'e' + 'l' * 2 + 'o'); |
| 1656 | } | 1656 | } |
| 1657 | 1657 | ||
| 1658 | // modifiable array | 1658 | // modifiable array |
| ... | @@ -2003,7 +2003,7 @@ test "variable alignment" { | ... | @@ -2003,7 +2003,7 @@ test "variable alignment" { |
| 2003 | } | 2003 | } |
| 2004 | } | 2004 | } |
| 2005 | {#code_end#} | 2005 | {#code_end#} |
| 2006 | <p>In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to a | 2006 | <p>In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|coerced|Type Coercion#} to a |
| 2007 | {#syntax#}*const i32{#endsyntax#}, a pointer with a larger alignment can be implicitly | 2007 | {#syntax#}*const i32{#endsyntax#}, a pointer with a larger alignment can be implicitly |
| 2008 | cast to a pointer with a smaller alignment, but not vice versa. | 2008 | cast to a pointer with a smaller alignment, but not vice versa. |
| 2009 | </p> | 2009 | </p> |
| ... | @@ -2019,7 +2019,7 @@ var foo: u8 align(4) = 100; | ... | @@ -2019,7 +2019,7 @@ var foo: u8 align(4) = 100; |
| 2019 | test "global variable alignment" { | 2019 | test "global variable alignment" { |
| 2020 | assert(@typeOf(&foo).alignment == 4); | 2020 | assert(@typeOf(&foo).alignment == 4); |
| 2021 | assert(@typeOf(&foo) == *align(4) u8); | 2021 | assert(@typeOf(&foo) == *align(4) u8); |
| 2022 | const slice = (*[1]u8)(&foo)[0..]; | 2022 | const slice = @as(*[1]u8, &foo)[0..]; |
| 2023 | assert(@typeOf(slice) == []align(4) u8); | 2023 | assert(@typeOf(slice) == []align(4) u8); |
| 2024 | } | 2024 | } |
| 2025 | 2025 | ||
| ... | @@ -2114,7 +2114,7 @@ const fmt = @import("std").fmt; | ... | @@ -2114,7 +2114,7 @@ const fmt = @import("std").fmt; |
| 2114 | test "using slices for strings" { | 2114 | test "using slices for strings" { |
| 2115 | // Zig has no concept of strings. String literals are arrays of u8, and | 2115 | // Zig has no concept of strings. String literals are arrays of u8, and |
| 2116 | // in general the string type is []u8 (slice of u8). | 2116 | // in general the string type is []u8 (slice of u8). |
| 2117 | // Here we implicitly cast [5]u8 to []const u8 | 2117 | // Here we coerce [5]u8 to []const u8 |
| 2118 | const hello: []const u8 = "hello"; | 2118 | const hello: []const u8 = "hello"; |
| 2119 | const world: []const u8 = "世界"; | 2119 | const world: []const u8 = "世界"; |
| 2120 | 2120 | ||
| ... | @@ -2778,7 +2778,7 @@ test "simple union" { | ... | @@ -2778,7 +2778,7 @@ test "simple union" { |
| 2778 | This turns the union into a <em>tagged</em> union, which makes it eligible | 2778 | This turns the union into a <em>tagged</em> union, which makes it eligible |
| 2779 | to use with {#link|switch#} expressions. One can use {#link|@TagType#} to | 2779 | to use with {#link|switch#} expressions. One can use {#link|@TagType#} to |
| 2780 | obtain the enum type from the union type. | 2780 | obtain the enum type from the union type. |
| 2781 | Tagged unions implicitly cast to their enum {#link|Implicit Cast: unions and enums#} | 2781 | Tagged unions coerce to their enum {#link|Type Coercion: unions and enums#} |
| 2782 | </p> | 2782 | </p> |
| 2783 | {#code_begin|test#} | 2783 | {#code_begin|test#} |
| 2784 | const std = @import("std"); | 2784 | const std = @import("std"); |
| ... | @@ -2795,7 +2795,7 @@ const ComplexType = union(ComplexTypeTag) { | ... | @@ -2795,7 +2795,7 @@ const ComplexType = union(ComplexTypeTag) { |
| 2795 | 2795 | ||
| 2796 | test "switch on tagged union" { | 2796 | test "switch on tagged union" { |
| 2797 | const c = ComplexType{ .Ok = 42 }; | 2797 | const c = ComplexType{ .Ok = 42 }; |
| 2798 | assert(ComplexTypeTag(c) == ComplexTypeTag.Ok); | 2798 | assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok); |
| 2799 | 2799 | ||
| 2800 | switch (c) { | 2800 | switch (c) { |
| 2801 | ComplexTypeTag.Ok => |value| assert(value == 42), | 2801 | ComplexTypeTag.Ok => |value| assert(value == 42), |
| ... | @@ -2807,7 +2807,7 @@ test "@TagType" { | ... | @@ -2807,7 +2807,7 @@ test "@TagType" { |
| 2807 | assert(@TagType(ComplexType) == ComplexTypeTag); | 2807 | assert(@TagType(ComplexType) == ComplexTypeTag); |
| 2808 | } | 2808 | } |
| 2809 | 2809 | ||
| 2810 | test "implicit cast to enum" { | 2810 | test "coerce to enum" { |
| 2811 | const c1 = ComplexType{ .Ok = 42 }; | 2811 | const c1 = ComplexType{ .Ok = 42 }; |
| 2812 | const c2 = ComplexType.NotOk; | 2812 | const c2 = ComplexType.NotOk; |
| 2813 | 2813 | ||
| ... | @@ -2833,7 +2833,7 @@ const ComplexType = union(ComplexTypeTag) { | ... | @@ -2833,7 +2833,7 @@ const ComplexType = union(ComplexTypeTag) { |
| 2833 | 2833 | ||
| 2834 | test "modify tagged union in switch" { | 2834 | test "modify tagged union in switch" { |
| 2835 | var c = ComplexType{ .Ok = 42 }; | 2835 | var c = ComplexType{ .Ok = 42 }; |
| 2836 | assert(ComplexTypeTag(c) == ComplexTypeTag.Ok); | 2836 | assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok); |
| 2837 | 2837 | ||
| 2838 | switch (c) { | 2838 | switch (c) { |
| 2839 | ComplexTypeTag.Ok => |*value| value.* += 1, | 2839 | ComplexTypeTag.Ok => |*value| value.* += 1, |
| ... | @@ -3943,7 +3943,7 @@ test "fn reflection" { | ... | @@ -3943,7 +3943,7 @@ test "fn reflection" { |
| 3943 | However right now it is hard coded to be a {#syntax#}u16{#endsyntax#}. See <a href="https://github.com/ziglang/zig/issues/786">#768</a>. | 3943 | However right now it is hard coded to be a {#syntax#}u16{#endsyntax#}. See <a href="https://github.com/ziglang/zig/issues/786">#768</a>. |
| 3944 | </p> | 3944 | </p> |
| 3945 | <p> | 3945 | <p> |
| 3946 | You can {#link|implicitly cast|Implicit Casts#} an error from a subset to a superset: | 3946 | You can {#link|coerce|Type Coercion#} an error from a subset to a superset: |
| 3947 | </p> | 3947 | </p> |
| 3948 | {#code_begin|test#} | 3948 | {#code_begin|test#} |
| 3949 | const std = @import("std"); | 3949 | const std = @import("std"); |
| ... | @@ -3958,7 +3958,7 @@ const AllocationError = error { | ... | @@ -3958,7 +3958,7 @@ const AllocationError = error { |
| 3958 | OutOfMemory, | 3958 | OutOfMemory, |
| 3959 | }; | 3959 | }; |
| 3960 | 3960 | ||
| 3961 | test "implicit cast subset to superset" { | 3961 | test "coerce subset to superset" { |
| 3962 | const err = foo(AllocationError.OutOfMemory); | 3962 | const err = foo(AllocationError.OutOfMemory); |
| 3963 | std.debug.assert(err == FileOpenError.OutOfMemory); | 3963 | std.debug.assert(err == FileOpenError.OutOfMemory); |
| 3964 | } | 3964 | } |
| ... | @@ -3968,7 +3968,7 @@ fn foo(err: AllocationError) FileOpenError { | ... | @@ -3968,7 +3968,7 @@ fn foo(err: AllocationError) FileOpenError { |
| 3968 | } | 3968 | } |
| 3969 | {#code_end#} | 3969 | {#code_end#} |
| 3970 | <p> | 3970 | <p> |
| 3971 | But you cannot implicitly cast an error from a superset to a subset: | 3971 | But you cannot {#link|coerce|Type Coercion#} an error from a superset to a subset: |
| 3972 | </p> | 3972 | </p> |
| 3973 | {#code_begin|test_err|not a member of destination error set#} | 3973 | {#code_begin|test_err|not a member of destination error set#} |
| 3974 | const FileOpenError = error { | 3974 | const FileOpenError = error { |
| ... | @@ -3981,7 +3981,7 @@ const AllocationError = error { | ... | @@ -3981,7 +3981,7 @@ const AllocationError = error { |
| 3981 | OutOfMemory, | 3981 | OutOfMemory, |
| 3982 | }; | 3982 | }; |
| 3983 | 3983 | ||
| 3984 | test "implicit cast superset to subset" { | 3984 | test "coerce superset to subset" { |
| 3985 | foo(FileOpenError.OutOfMemory) catch {}; | 3985 | foo(FileOpenError.OutOfMemory) catch {}; |
| 3986 | } | 3986 | } |
| 3987 | 3987 | ||
| ... | @@ -4008,7 +4008,7 @@ const err = (error {FileNotFound}).FileNotFound; | ... | @@ -4008,7 +4008,7 @@ const err = (error {FileNotFound}).FileNotFound; |
| 4008 | It is a superset of all other error sets and a subset of none of them. | 4008 | It is a superset of all other error sets and a subset of none of them. |
| 4009 | </p> | 4009 | </p> |
| 4010 | <p> | 4010 | <p> |
| 4011 | You can implicitly cast any error set to the global one, and you can explicitly | 4011 | You can {#link|coerce|Type Coercion#} any error set to the global one, and you can explicitly |
| 4012 | cast an error of the global error set to a non-global one. This inserts a language-level | 4012 | cast an error of the global error set to a non-global one. This inserts a language-level |
| 4013 | assert to make sure the error value is in fact in the destination error set. | 4013 | assert to make sure the error value is in fact in the destination error set. |
| 4014 | </p> | 4014 | </p> |
| ... | @@ -4079,7 +4079,7 @@ test "parse u64" { | ... | @@ -4079,7 +4079,7 @@ test "parse u64" { |
| 4079 | <p> | 4079 | <p> |
| 4080 | Within the function definition, you can see some return statements that return | 4080 | Within the function definition, you can see some return statements that return |
| 4081 | an error, and at the bottom a return statement that returns a {#syntax#}u64{#endsyntax#}. | 4081 | an error, and at the bottom a return statement that returns a {#syntax#}u64{#endsyntax#}. |
| 4082 | Both types {#link|implicitly cast|Implicit Casts#} to {#syntax#}anyerror!u64{#endsyntax#}. | 4082 | Both types {#link|coerce|Type Coercion#} to {#syntax#}anyerror!u64{#endsyntax#}. |
| 4083 | </p> | 4083 | </p> |
| 4084 | <p> | 4084 | <p> |
| 4085 | What it looks like to use this function varies depending on what you're | 4085 | What it looks like to use this function varies depending on what you're |
| ... | @@ -4218,10 +4218,10 @@ const assert = @import("std").debug.assert; | ... | @@ -4218,10 +4218,10 @@ const assert = @import("std").debug.assert; |
| 4218 | test "error union" { | 4218 | test "error union" { |
| 4219 | var foo: anyerror!i32 = undefined; | 4219 | var foo: anyerror!i32 = undefined; |
| 4220 | 4220 | ||
| 4221 | // Implicitly cast from child type of an error union: | 4221 | // Coerce from child type of an error union: |
| 4222 | foo = 1234; | 4222 | foo = 1234; |
| 4223 | 4223 | ||
| 4224 | // Implicitly cast from an error set: | 4224 | // Coerce from an error set: |
| 4225 | foo = error.SomeError; | 4225 | foo = error.SomeError; |
| 4226 | 4226 | ||
| 4227 | // Use compile-time reflection to access the payload type of an error union: | 4227 | // Use compile-time reflection to access the payload type of an error union: |
| ... | @@ -4598,10 +4598,10 @@ fn doAThing(optional_foo: ?*Foo) void { | ... | @@ -4598,10 +4598,10 @@ fn doAThing(optional_foo: ?*Foo) void { |
| 4598 | const assert = @import("std").debug.assert; | 4598 | const assert = @import("std").debug.assert; |
| 4599 | 4599 | ||
| 4600 | test "optional type" { | 4600 | test "optional type" { |
| 4601 | // Declare an optional and implicitly cast from null: | 4601 | // Declare an optional and coerce from null: |
| 4602 | var foo: ?i32 = null; | 4602 | var foo: ?i32 = null; |
| 4603 | 4603 | ||
| 4604 | // Implicitly cast from child type of an optional | 4604 | // Coerce from child type of an optional |
| 4605 | foo = 1234; | 4605 | foo = 1234; |
| 4606 | 4606 | ||
| 4607 | // Use compile-time reflection to access the child type of the optional: | 4607 | // Use compile-time reflection to access the child type of the optional: |
| ... | @@ -4644,38 +4644,38 @@ test "optional pointers" { | ... | @@ -4644,38 +4644,38 @@ test "optional pointers" { |
| 4644 | {#header_open|Casting#} | 4644 | {#header_open|Casting#} |
| 4645 | <p> | 4645 | <p> |
| 4646 | A <strong>type cast</strong> converts a value of one type to another. | 4646 | A <strong>type cast</strong> converts a value of one type to another. |
| 4647 | Zig has {#link|Implicit Casts#} for conversions that are known to be completely safe and unambiguous, | 4647 | Zig has {#link|Type Coercion#} for conversions that are known to be completely safe and unambiguous, |
| 4648 | and {#link|Explicit Casts#} for conversions that one would not want to happen on accident. | 4648 | and {#link|Explicit Casts#} for conversions that one would not want to happen on accident. |
| 4649 | There is also a third kind of type conversion called {#link|Peer Type Resolution#} for | 4649 | There is also a third kind of type conversion called {#link|Peer Type Resolution#} for |
| 4650 | the case when a result type must be decided given multiple operand types. | 4650 | the case when a result type must be decided given multiple operand types. |
| 4651 | </p> | 4651 | </p> |
| 4652 | {#header_open|Implicit Casts#} | 4652 | {#header_open|Type Coercion#} |
| 4653 | <p> | 4653 | <p> |
| 4654 | An implicit cast occurs when one type is expected, but different type is provided: | 4654 | Type coercion occurs when one type is expected, but different type is provided: |
| 4655 | </p> | 4655 | </p> |
| 4656 | {#code_begin|test#} | 4656 | {#code_begin|test#} |
| 4657 | test "implicit cast - variable declaration" { | 4657 | test "type coercion - variable declaration" { |
| 4658 | var a: u8 = 1; | 4658 | var a: u8 = 1; |
| 4659 | var b: u16 = a; | 4659 | var b: u16 = a; |
| 4660 | } | 4660 | } |
| 4661 | 4661 | ||
| 4662 | test "implicit cast - function call" { | 4662 | test "type coercion - function call" { |
| 4663 | var a: u8 = 1; | 4663 | var a: u8 = 1; |
| 4664 | foo(a); | 4664 | foo(a); |
| 4665 | } | 4665 | } |
| 4666 | 4666 | ||
| 4667 | fn foo(b: u16) void {} | 4667 | fn foo(b: u16) void {} |
| 4668 | 4668 | ||
| 4669 | test "implicit cast - invoke a type as a function" { | 4669 | test "type coercion - @as builtin" { |
| 4670 | var a: u8 = 1; | 4670 | var a: u8 = 1; |
| 4671 | var b = u16(a); | 4671 | var b = @as(u16, a); |
| 4672 | } | 4672 | } |
| 4673 | {#code_end#} | 4673 | {#code_end#} |
| 4674 | <p> | 4674 | <p> |
| 4675 | Implicit casts are only allowed when it is completely unambiguous how to get from one type to another, | 4675 | Type coercions are only allowed when it is completely unambiguous how to get from one type to another, |
| 4676 | and the transformation is guaranteed to be safe. There is one exception, which is {#link|C Pointers#}. | 4676 | and the transformation is guaranteed to be safe. There is one exception, which is {#link|C Pointers#}. |
| 4677 | </p> | 4677 | </p> |
| 4678 | {#header_open|Implicit Cast: Stricter Qualification#} | 4678 | {#header_open|Type Coercion: Stricter Qualification#} |
| 4679 | <p> | 4679 | <p> |
| 4680 | Values which have the same representation at runtime can be cast to increase the strictness | 4680 | Values which have the same representation at runtime can be cast to increase the strictness |
| 4681 | of the qualifiers, no matter how nested the qualifiers are: | 4681 | of the qualifiers, no matter how nested the qualifiers are: |
| ... | @@ -4690,7 +4690,7 @@ test "implicit cast - invoke a type as a function" { | ... | @@ -4690,7 +4690,7 @@ test "implicit cast - invoke a type as a function" { |
| 4690 | These casts are no-ops at runtime since the value representation does not change. | 4690 | These casts are no-ops at runtime since the value representation does not change. |
| 4691 | </p> | 4691 | </p> |
| 4692 | {#code_begin|test#} | 4692 | {#code_begin|test#} |
| 4693 | test "implicit cast - const qualification" { | 4693 | test "type coercion - const qualification" { |
| 4694 | var a: i32 = 1; | 4694 | var a: i32 = 1; |
| 4695 | var b: *i32 = &a; | 4695 | var b: *i32 = &a; |
| 4696 | foo(b); | 4696 | foo(b); |
| ... | @@ -4699,7 +4699,7 @@ test "implicit cast - const qualification" { | ... | @@ -4699,7 +4699,7 @@ test "implicit cast - const qualification" { |
| 4699 | fn foo(a: *const i32) void {} | 4699 | fn foo(a: *const i32) void {} |
| 4700 | {#code_end#} | 4700 | {#code_end#} |
| 4701 | <p> | 4701 | <p> |
| 4702 | In addition, pointers implicitly cast to const optional pointers: | 4702 | In addition, pointers coerce to const optional pointers: |
| 4703 | </p> | 4703 | </p> |
| 4704 | {#code_begin|test#} | 4704 | {#code_begin|test#} |
| 4705 | const std = @import("std"); | 4705 | const std = @import("std"); |
| ... | @@ -4713,10 +4713,10 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" { | ... | @@ -4713,10 +4713,10 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 4713 | } | 4713 | } |
| 4714 | {#code_end#} | 4714 | {#code_end#} |
| 4715 | {#header_close#} | 4715 | {#header_close#} |
| 4716 | {#header_open|Implicit Cast: Integer and Float Widening#} | 4716 | {#header_open|Type Coercion: Integer and Float Widening#} |
| 4717 | <p> | 4717 | <p> |
| 4718 | {#link|Integers#} implicitly cast to integer types which can represent every value of the old type, and likewise | 4718 | {#link|Integers#} coerce to integer types which can represent every value of the old type, and likewise |
| 4719 | {#link|Floats#} implicitly cast to float types which can represent every value of the old type. | 4719 | {#link|Floats#} coerce to float types which can represent every value of the old type. |
| 4720 | </p> | 4720 | </p> |
| 4721 | {#code_begin|test#} | 4721 | {#code_begin|test#} |
| 4722 | const std = @import("std"); | 4722 | const std = @import("std"); |
| ... | @@ -4748,7 +4748,7 @@ test "float widening" { | ... | @@ -4748,7 +4748,7 @@ test "float widening" { |
| 4748 | } | 4748 | } |
| 4749 | {#code_end#} | 4749 | {#code_end#} |
| 4750 | {#header_close#} | 4750 | {#header_close#} |
| 4751 | {#header_open|Implicit Cast: Arrays and Pointers#} | 4751 | {#header_open|Type Coercion: Arrays and Pointers#} |
| 4752 | {#code_begin|test#} | 4752 | {#code_begin|test#} |
| 4753 | const std = @import("std"); | 4753 | const std = @import("std"); |
| 4754 | const assert = std.debug.assert; | 4754 | const assert = std.debug.assert; |
| ... | @@ -4797,7 +4797,7 @@ test "*[N]T to []T" { | ... | @@ -4797,7 +4797,7 @@ test "*[N]T to []T" { |
| 4797 | assert(std.mem.eql(f32, x2, [2]f32{ 1.2, 3.4 })); | 4797 | assert(std.mem.eql(f32, x2, [2]f32{ 1.2, 3.4 })); |
| 4798 | } | 4798 | } |
| 4799 | 4799 | ||
| 4800 | // Single-item pointers to arrays can be implicitly casted to | 4800 | // Single-item pointers to arrays can be coerced to |
| 4801 | // unknown length pointers. | 4801 | // unknown length pointers. |
| 4802 | test "*[N]T to [*]T" { | 4802 | test "*[N]T to [*]T" { |
| 4803 | var buf: [5]u8 = "hello"; | 4803 | var buf: [5]u8 = "hello"; |
| ... | @@ -4823,15 +4823,15 @@ test "*T to *[1]T" { | ... | @@ -4823,15 +4823,15 @@ test "*T to *[1]T" { |
| 4823 | {#code_end#} | 4823 | {#code_end#} |
| 4824 | {#see_also|C Pointers#} | 4824 | {#see_also|C Pointers#} |
| 4825 | {#header_close#} | 4825 | {#header_close#} |
| 4826 | {#header_open|Implicit Cast: Optionals#} | 4826 | {#header_open|Type Coercion: Optionals#} |
| 4827 | <p> | 4827 | <p> |
| 4828 | The payload type of {#link|Optionals#}, as well as {#link|null#}, implicitly cast to the optional type. | 4828 | The payload type of {#link|Optionals#}, as well as {#link|null#}, coerce to the optional type. |
| 4829 | </p> | 4829 | </p> |
| 4830 | {#code_begin|test#} | 4830 | {#code_begin|test#} |
| 4831 | const std = @import("std"); | 4831 | const std = @import("std"); |
| 4832 | const assert = std.debug.assert; | 4832 | const assert = std.debug.assert; |
| 4833 | 4833 | ||
| 4834 | test "implicit casting to optionals" { | 4834 | test "coerce to optionals" { |
| 4835 | const x: ?i32 = 1234; | 4835 | const x: ?i32 = 1234; |
| 4836 | const y: ?i32 = null; | 4836 | const y: ?i32 = null; |
| 4837 | 4837 | ||
| ... | @@ -4844,7 +4844,7 @@ test "implicit casting to optionals" { | ... | @@ -4844,7 +4844,7 @@ test "implicit casting to optionals" { |
| 4844 | const std = @import("std"); | 4844 | const std = @import("std"); |
| 4845 | const assert = std.debug.assert; | 4845 | const assert = std.debug.assert; |
| 4846 | 4846 | ||
| 4847 | test "implicit casting to optionals wrapped in error union" { | 4847 | test "coerce to optionals wrapped in error union" { |
| 4848 | const x: anyerror!?i32 = 1234; | 4848 | const x: anyerror!?i32 = 1234; |
| 4849 | const y: anyerror!?i32 = null; | 4849 | const y: anyerror!?i32 = null; |
| 4850 | 4850 | ||
| ... | @@ -4853,15 +4853,15 @@ test "implicit casting to optionals wrapped in error union" { | ... | @@ -4853,15 +4853,15 @@ test "implicit casting to optionals wrapped in error union" { |
| 4853 | } | 4853 | } |
| 4854 | {#code_end#} | 4854 | {#code_end#} |
| 4855 | {#header_close#} | 4855 | {#header_close#} |
| 4856 | {#header_open|Implicit Cast: Error Unions#} | 4856 | {#header_open|Type Coercion: Error Unions#} |
| 4857 | <p>The payload type of an {#link|Error Union Type#} as well as the {#link|Error Set Type#} | 4857 | <p>The payload type of an {#link|Error Union Type#} as well as the {#link|Error Set Type#} |
| 4858 | implicitly cast to the error union type: | 4858 | coerce to the error union type: |
| 4859 | </p> | 4859 | </p> |
| 4860 | {#code_begin|test#} | 4860 | {#code_begin|test#} |
| 4861 | const std = @import("std"); | 4861 | const std = @import("std"); |
| 4862 | const assert = std.debug.assert; | 4862 | const assert = std.debug.assert; |
| 4863 | 4863 | ||
| 4864 | test "implicit casting to error unions" { | 4864 | test "coercion to error unions" { |
| 4865 | const x: anyerror!i32 = 1234; | 4865 | const x: anyerror!i32 = 1234; |
| 4866 | const y: anyerror!i32 = error.Failure; | 4866 | const y: anyerror!i32 = error.Failure; |
| 4867 | 4867 | ||
| ... | @@ -4870,23 +4870,23 @@ test "implicit casting to error unions" { | ... | @@ -4870,23 +4870,23 @@ test "implicit casting to error unions" { |
| 4870 | } | 4870 | } |
| 4871 | {#code_end#} | 4871 | {#code_end#} |
| 4872 | {#header_close#} | 4872 | {#header_close#} |
| 4873 | {#header_open|Implicit Cast: Compile-Time Known Numbers#} | 4873 | {#header_open|Type Coercion: Compile-Time Known Numbers#} |
| 4874 | <p>When a number is {#link|comptime#}-known to be representable in the destination type, | 4874 | <p>When a number is {#link|comptime#}-known to be representable in the destination type, |
| 4875 | it may be implicitly casted: | 4875 | it may be coerced: |
| 4876 | </p> | 4876 | </p> |
| 4877 | {#code_begin|test#} | 4877 | {#code_begin|test#} |
| 4878 | const std = @import("std"); | 4878 | const std = @import("std"); |
| 4879 | const assert = std.debug.assert; | 4879 | const assert = std.debug.assert; |
| 4880 | 4880 | ||
| 4881 | test "implicit casting large integer type to smaller one when value is comptime known to fit" { | 4881 | test "coercing large integer type to smaller one when value is comptime known to fit" { |
| 4882 | const x: u64 = 255; | 4882 | const x: u64 = 255; |
| 4883 | const y: u8 = x; | 4883 | const y: u8 = x; |
| 4884 | assert(y == 255); | 4884 | assert(y == 255); |
| 4885 | } | 4885 | } |
| 4886 | {#code_end#} | 4886 | {#code_end#} |
| 4887 | {#header_close#} | 4887 | {#header_close#} |
| 4888 | {#header_open|Implicit Cast: unions and enums#} | 4888 | {#header_open|Type Coercion: unions and enums#} |
| 4889 | <p>Tagged unions can be implicitly cast to enums, and enums can be implicitly casted to tagged unions | 4889 | <p>Tagged unions can be coerced to enums, and enums can be coerced to tagged unions |
| 4890 | when they are {#link|comptime#}-known to be a field of the union that has only one possible value, such as | 4890 | when they are {#link|comptime#}-known to be a field of the union that has only one possible value, such as |
| 4891 | {#link|void#}: | 4891 | {#link|void#}: |
| 4892 | </p> | 4892 | </p> |
| ... | @@ -4906,7 +4906,7 @@ const U = union(E) { | ... | @@ -4906,7 +4906,7 @@ const U = union(E) { |
| 4906 | Three, | 4906 | Three, |
| 4907 | }; | 4907 | }; |
| 4908 | 4908 | ||
| 4909 | test "implicit casting between unions and enums" { | 4909 | test "coercion between unions and enums" { |
| 4910 | var u = U{ .Two = 12.34 }; | 4910 | var u = U{ .Two = 12.34 }; |
| 4911 | var e: E = u; | 4911 | var e: E = u; |
| 4912 | assert(e == E.Two); | 4912 | assert(e == E.Two); |
| ... | @@ -4918,20 +4918,20 @@ test "implicit casting between unions and enums" { | ... | @@ -4918,20 +4918,20 @@ test "implicit casting between unions and enums" { |
| 4918 | {#code_end#} | 4918 | {#code_end#} |
| 4919 | {#see_also|union|enum#} | 4919 | {#see_also|union|enum#} |
| 4920 | {#header_close#} | 4920 | {#header_close#} |
| 4921 | {#header_open|Implicit Cast: Zero Bit Types#} | 4921 | {#header_open|Type Coercion: Zero Bit Types#} |
| 4922 | <p>{#link|Zero Bit Types#} may be implicitly casted to single-item {#link|Pointers#}, | 4922 | <p>{#link|Zero Bit Types#} may be coerced to single-item {#link|Pointers#}, |
| 4923 | regardless of const.</p> | 4923 | regardless of const.</p> |
| 4924 | <p>TODO document the reasoning for this</p> | 4924 | <p>TODO document the reasoning for this</p> |
| 4925 | <p>TODO document whether vice versa should work and why</p> | 4925 | <p>TODO document whether vice versa should work and why</p> |
| 4926 | {#code_begin|test#} | 4926 | {#code_begin|test#} |
| 4927 | test "implicit casting of zero bit types" { | 4927 | test "coercion of zero bit types" { |
| 4928 | var x: void = {}; | 4928 | var x: void = {}; |
| 4929 | var y: *void = x; | 4929 | var y: *void = x; |
| 4930 | //var z: void = y; // TODO | 4930 | //var z: void = y; // TODO |
| 4931 | } | 4931 | } |
| 4932 | {#code_end#} | 4932 | {#code_end#} |
| 4933 | {#header_close#} | 4933 | {#header_close#} |
| 4934 | {#header_open|Implicit Cast: undefined#} | 4934 | {#header_open|Type Coercion: undefined#} |
| 4935 | <p>{#link|undefined#} can be cast to any type.</p> | 4935 | <p>{#link|undefined#} can be cast to any type.</p> |
| 4936 | {#header_close#} | 4936 | {#header_close#} |
| 4937 | {#header_close#} | 4937 | {#header_close#} |
| ... | @@ -4976,7 +4976,7 @@ test "implicit casting of zero bit types" { | ... | @@ -4976,7 +4976,7 @@ test "implicit casting of zero bit types" { |
| 4976 | <li>Some {#link|binary operations|Table of Operators#}</li> | 4976 | <li>Some {#link|binary operations|Table of Operators#}</li> |
| 4977 | </ul> | 4977 | </ul> |
| 4978 | <p> | 4978 | <p> |
| 4979 | This kind of type resolution chooses a type that all peer types can implicitly cast into. Here are | 4979 | This kind of type resolution chooses a type that all peer types can coerce into. Here are |
| 4980 | some examples: | 4980 | some examples: |
| 4981 | </p> | 4981 | </p> |
| 4982 | {#code_begin|test#} | 4982 | {#code_begin|test#} |
| ... | @@ -5007,8 +5007,8 @@ test "peer resolve array and const slice" { | ... | @@ -5007,8 +5007,8 @@ test "peer resolve array and const slice" { |
| 5007 | comptime testPeerResolveArrayConstSlice(true); | 5007 | comptime testPeerResolveArrayConstSlice(true); |
| 5008 | } | 5008 | } |
| 5009 | fn testPeerResolveArrayConstSlice(b: bool) void { | 5009 | fn testPeerResolveArrayConstSlice(b: bool) void { |
| 5010 | const value1 = if (b) "aoeu" else ([]const u8)("zz"); | 5010 | const value1 = if (b) "aoeu" else @as([]const u8, "zz"); |
| 5011 | const value2 = if (b) ([]const u8)("zz") else "aoeu"; | 5011 | const value2 = if (b) @as([]const u8, "zz") else "aoeu"; |
| 5012 | assert(mem.eql(u8, value1, "aoeu")); | 5012 | assert(mem.eql(u8, value1, "aoeu")); |
| 5013 | assert(mem.eql(u8, value2, "zz")); | 5013 | assert(mem.eql(u8, value2, "zz")); |
| 5014 | } | 5014 | } |
| ... | @@ -5023,10 +5023,10 @@ test "peer type resolution: ?T and T" { | ... | @@ -5023,10 +5023,10 @@ test "peer type resolution: ?T and T" { |
| 5023 | } | 5023 | } |
| 5024 | fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { | 5024 | fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| 5025 | if (c) { | 5025 | if (c) { |
| 5026 | return if (b) null else usize(0); | 5026 | return if (b) null else @as(usize, 0); |
| 5027 | } | 5027 | } |
| 5028 | 5028 | ||
| 5029 | return usize(3); | 5029 | return @as(usize, 3); |
| 5030 | } | 5030 | } |
| 5031 | 5031 | ||
| 5032 | test "peer type resolution: [0]u8 and []const u8" { | 5032 | test "peer type resolution: [0]u8 and []const u8" { |
| ... | @@ -5815,7 +5815,7 @@ test "printf too many arguments" { | ... | @@ -5815,7 +5815,7 @@ test "printf too many arguments" { |
| 5815 | </p> | 5815 | </p> |
| 5816 | <p> | 5816 | <p> |
| 5817 | Zig doesn't care whether the format argument is a string literal, | 5817 | Zig doesn't care whether the format argument is a string literal, |
| 5818 | only that it is a compile-time known value that is implicitly castable to a {#syntax#}[]const u8{#endsyntax#}: | 5818 | only that it is a compile-time known value that can be coerced to a {#syntax#}[]const u8{#endsyntax#}: |
| 5819 | </p> | 5819 | </p> |
| 5820 | {#code_begin|exe|printf#} | 5820 | {#code_begin|exe|printf#} |
| 5821 | const warn = @import("std").debug.warn; | 5821 | const warn = @import("std").debug.warn; |
| ... | @@ -6185,7 +6185,7 @@ fn func() void { | ... | @@ -6185,7 +6185,7 @@ fn func() void { |
| 6185 | </p> | 6185 | </p> |
| 6186 | <p> | 6186 | <p> |
| 6187 | {#syntax#}await{#endsyntax#} is a suspend point, and takes as an operand anything that | 6187 | {#syntax#}await{#endsyntax#} is a suspend point, and takes as an operand anything that |
| 6188 | implicitly casts to {#syntax#}anyframe->T{#endsyntax#}. | 6188 | coerces to {#syntax#}anyframe->T{#endsyntax#}. |
| 6189 | </p> | 6189 | </p> |
| 6190 | <p> | 6190 | <p> |
| 6191 | There is a common misconception that {#syntax#}await{#endsyntax#} resumes the target function. | 6191 | There is a common misconception that {#syntax#}await{#endsyntax#} resumes the target function. |
| ... | @@ -6445,6 +6445,14 @@ comptime { | ... | @@ -6445,6 +6445,14 @@ comptime { |
| 6445 | </p> | 6445 | </p> |
| 6446 | {#header_close#} | 6446 | {#header_close#} |
| 6447 | 6447 | ||
| 6448 | {#header_open|@as#} | ||
| 6449 | <pre>{#syntax#}@as(comptime T: type, expression) T{#endsyntax#}</pre> | ||
| 6450 | <p> | ||
| 6451 | Performs {#link|Type Coercion#}. This cast is allowed when the conversion is unambiguous and safe, | ||
| 6452 | and is the preferred way to convert between types, whenever possible. | ||
| 6453 | </p> | ||
| 6454 | {#header_close#} | ||
| 6455 | |||
| 6448 | {#header_open|@asyncCall#} | 6456 | {#header_open|@asyncCall#} |
| 6449 | <pre>{#syntax#}@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: ...) anyframe->T{#endsyntax#}</pre> | 6457 | <pre>{#syntax#}@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: ...) anyframe->T{#endsyntax#}</pre> |
| 6450 | <p> | 6458 | <p> |
| ... | @@ -7108,7 +7116,7 @@ test "field access by string" { | ... | @@ -7108,7 +7116,7 @@ test "field access by string" { |
| 7108 | <pre>{#syntax#}@frame() *@Frame(func){#endsyntax#}</pre> | 7116 | <pre>{#syntax#}@frame() *@Frame(func){#endsyntax#}</pre> |
| 7109 | <p> | 7117 | <p> |
| 7110 | This function returns a pointer to the frame for a given function. This type | 7118 | This function returns a pointer to the frame for a given function. This type |
| 7111 | can be {#link|implicitly cast|Implicit Casts#} to {#syntax#}anyframe->T{#endsyntax#} and | 7119 | can be {#link|coerced|Type Coercion#} to {#syntax#}anyframe->T{#endsyntax#} and |
| 7112 | to {#syntax#}anyframe{#endsyntax#}, where {#syntax#}T{#endsyntax#} is the return type | 7120 | to {#syntax#}anyframe{#endsyntax#}, where {#syntax#}T{#endsyntax#} is the return type |
| 7113 | of the function in scope. | 7121 | of the function in scope. |
| 7114 | </p> | 7122 | </p> |
| ... | @@ -7827,7 +7835,7 @@ test "vector @splat" { | ... | @@ -7827,7 +7835,7 @@ test "vector @splat" { |
| 7827 | const scalar: u32 = 5; | 7835 | const scalar: u32 = 5; |
| 7828 | const result = @splat(4, scalar); | 7836 | const result = @splat(4, scalar); |
| 7829 | comptime assert(@typeOf(result) == @Vector(4, u32)); | 7837 | comptime assert(@typeOf(result) == @Vector(4, u32)); |
| 7830 | assert(std.mem.eql(u32, ([4]u32)(result), [_]u32{ 5, 5, 5, 5 })); | 7838 | assert(std.mem.eql(u32, @as([4]u32, result), [_]u32{ 5, 5, 5, 5 })); |
| 7831 | } | 7839 | } |
| 7832 | {#code_end#} | 7840 | {#code_end#} |
| 7833 | <p> | 7841 | <p> |
| ... | @@ -8025,7 +8033,7 @@ test "integer truncation" { | ... | @@ -8025,7 +8033,7 @@ test "integer truncation" { |
| 8025 | </p> | 8033 | </p> |
| 8026 | <p> | 8034 | <p> |
| 8027 | If {#syntax#}T{#endsyntax#} is {#syntax#}comptime_int{#endsyntax#}, | 8035 | If {#syntax#}T{#endsyntax#} is {#syntax#}comptime_int{#endsyntax#}, |
| 8028 | then this is semantically equivalent to an {#link|implicit cast|Implicit Casts#}. | 8036 | then this is semantically equivalent to {#link|Type Coercion#}. |
| 8029 | </p> | 8037 | </p> |
| 8030 | {#header_close#} | 8038 | {#header_close#} |
| 8031 | 8039 | ||
| ... | @@ -8529,7 +8537,7 @@ pub fn main() void { | ... | @@ -8529,7 +8537,7 @@ pub fn main() void { |
| 8529 | {#header_close#} | 8537 | {#header_close#} |
| 8530 | {#header_open|Cast Truncates Data#} | 8538 | {#header_open|Cast Truncates Data#} |
| 8531 | <p>At compile-time:</p> | 8539 | <p>At compile-time:</p> |
| 8532 | {#code_begin|test_err|integer value 300 cannot be implicitly casted to type 'u8'#} | 8540 | {#code_begin|test_err|integer value 300 cannot be coerced to type 'u8'#} |
| 8533 | comptime { | 8541 | comptime { |
| 8534 | const spartan_count: u16 = 300; | 8542 | const spartan_count: u16 = 300; |
| 8535 | const byte = @intCast(u8, spartan_count); | 8543 | const byte = @intCast(u8, spartan_count); |
| ... | @@ -8665,7 +8673,7 @@ test "wraparound addition and subtraction" { | ... | @@ -8665,7 +8673,7 @@ test "wraparound addition and subtraction" { |
| 8665 | <p>At compile-time:</p> | 8673 | <p>At compile-time:</p> |
| 8666 | {#code_begin|test_err|operation caused overflow#} | 8674 | {#code_begin|test_err|operation caused overflow#} |
| 8667 | comptime { | 8675 | comptime { |
| 8668 | const x = @shlExact(u8(0b01010101), 2); | 8676 | const x = @shlExact(@as(u8, 0b01010101), 2); |
| 8669 | } | 8677 | } |
| 8670 | {#code_end#} | 8678 | {#code_end#} |
| 8671 | <p>At runtime:</p> | 8679 | <p>At runtime:</p> |
| ... | @@ -8683,7 +8691,7 @@ pub fn main() void { | ... | @@ -8683,7 +8691,7 @@ pub fn main() void { |
| 8683 | <p>At compile-time:</p> | 8691 | <p>At compile-time:</p> |
| 8684 | {#code_begin|test_err|exact shift shifted out 1 bits#} | 8692 | {#code_begin|test_err|exact shift shifted out 1 bits#} |
| 8685 | comptime { | 8693 | comptime { |
| 8686 | const x = @shrExact(u8(0b10101010), 2); | 8694 | const x = @shrExact(@as(u8, 0b10101010), 2); |
| 8687 | } | 8695 | } |
| 8688 | {#code_end#} | 8696 | {#code_end#} |
| 8689 | <p>At runtime:</p> | 8697 | <p>At runtime:</p> |
| ... | @@ -9535,8 +9543,8 @@ const c = @cImport({ | ... | @@ -9535,8 +9543,8 @@ const c = @cImport({ |
| 9535 | <p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p> | 9543 | <p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p> |
| 9536 | <ul> | 9544 | <ul> |
| 9537 | <li>Supports all the syntax of the other two pointer types.</li> | 9545 | <li>Supports all the syntax of the other two pointer types.</li> |
| 9538 | <li>Implicitly casts to other pointer types, as well as {#link|Optional Pointers#}. | 9546 | <li>Coerces to other pointer types, as well as {#link|Optional Pointers#}. |
| 9539 | When a C pointer is implicitly casted to a non-optional pointer, safety-checked | 9547 | When a C pointer is coerced to a non-optional pointer, safety-checked |
| 9540 | {#link|Undefined Behavior#} occurs if the address is 0. | 9548 | {#link|Undefined Behavior#} occurs if the address is 0. |
| 9541 | </li> | 9549 | </li> |
| 9542 | <li>Allows address 0. On non-freestanding targets, dereferencing address 0 is safety-checked | 9550 | <li>Allows address 0. On non-freestanding targets, dereferencing address 0 is safety-checked |
| ... | @@ -9544,7 +9552,7 @@ const c = @cImport({ | ... | @@ -9544,7 +9552,7 @@ const c = @cImport({ |
| 9544 | null, just like {#syntax#}?usize{#endsyntax#}. Note that creating an optional C pointer | 9552 | null, just like {#syntax#}?usize{#endsyntax#}. Note that creating an optional C pointer |
| 9545 | is unnecessary as one can use normal {#link|Optional Pointers#}. | 9553 | is unnecessary as one can use normal {#link|Optional Pointers#}. |
| 9546 | </li> | 9554 | </li> |
| 9547 | <li>Supports {#link|implicit casting|Implicit Casts#} to and from integers.</li> | 9555 | <li>Supports {#link|Type Coercion#} to and from integers.</li> |
| 9548 | <li>Supports comparison with integers.</li> | 9556 | <li>Supports comparison with integers.</li> |
| 9549 | <li>Does not support Zig-only pointer attributes such as alignment. Use normal {#link|Pointers#} | 9557 | <li>Does not support Zig-only pointer attributes such as alignment. Use normal {#link|Pointers#} |
| 9550 | please!</li> | 9558 | please!</li> |
lib/std/array_list.zig+8-8| ... | @@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" { | ... | @@ -344,18 +344,18 @@ test "std.ArrayList.orderedRemove" { |
| 344 | try list.append(7); | 344 | try list.append(7); |
| 345 | 345 | ||
| 346 | //remove from middle | 346 | //remove from middle |
| 347 | testing.expectEqual(i32(4), list.orderedRemove(3)); | 347 | testing.expectEqual(@as(i32, 4), list.orderedRemove(3)); |
| 348 | testing.expectEqual(i32(5), list.at(3)); | 348 | testing.expectEqual(@as(i32, 5), list.at(3)); |
| 349 | testing.expectEqual(usize(6), list.len); | 349 | testing.expectEqual(@as(usize, 6), list.len); |
| 350 | 350 | ||
| 351 | //remove from end | 351 | //remove from end |
| 352 | testing.expectEqual(i32(7), list.orderedRemove(5)); | 352 | testing.expectEqual(@as(i32, 7), list.orderedRemove(5)); |
| 353 | testing.expectEqual(usize(5), list.len); | 353 | testing.expectEqual(@as(usize, 5), list.len); |
| 354 | 354 | ||
| 355 | //remove from front | 355 | //remove from front |
| 356 | testing.expectEqual(i32(1), list.orderedRemove(0)); | 356 | testing.expectEqual(@as(i32, 1), list.orderedRemove(0)); |
| 357 | testing.expectEqual(i32(2), list.at(0)); | 357 | testing.expectEqual(@as(i32, 2), list.at(0)); |
| 358 | testing.expectEqual(usize(4), list.len); | 358 | testing.expectEqual(@as(usize, 4), list.len); |
| 359 | } | 359 | } |
| 360 | 360 | ||
| 361 | test "std.ArrayList.swapRemove" { | 361 | test "std.ArrayList.swapRemove" { |
lib/std/ascii.zig+11-11| ... | @@ -129,26 +129,26 @@ const combinedTable = init: { | ... | @@ -129,26 +129,26 @@ const combinedTable = init: { |
| 129 | comptime var i = 0; | 129 | comptime var i = 0; |
| 130 | inline while (i < 128) : (i += 1) { | 130 | inline while (i < 128) : (i += 1) { |
| 131 | table[i] = | 131 | table[i] = |
| 132 | u8(alpha[i]) << @enumToInt(tIndex.Alpha) | | 132 | @as(u8, alpha[i]) << @enumToInt(tIndex.Alpha) | |
| 133 | u8(hex[i]) << @enumToInt(tIndex.Hex) | | 133 | @as(u8, hex[i]) << @enumToInt(tIndex.Hex) | |
| 134 | u8(space[i]) << @enumToInt(tIndex.Space) | | 134 | @as(u8, space[i]) << @enumToInt(tIndex.Space) | |
| 135 | u8(digit[i]) << @enumToInt(tIndex.Digit) | | 135 | @as(u8, digit[i]) << @enumToInt(tIndex.Digit) | |
| 136 | u8(lower[i]) << @enumToInt(tIndex.Lower) | | 136 | @as(u8, lower[i]) << @enumToInt(tIndex.Lower) | |
| 137 | u8(upper[i]) << @enumToInt(tIndex.Upper) | | 137 | @as(u8, upper[i]) << @enumToInt(tIndex.Upper) | |
| 138 | u8(punct[i]) << @enumToInt(tIndex.Punct) | | 138 | @as(u8, punct[i]) << @enumToInt(tIndex.Punct) | |
| 139 | u8(graph[i]) << @enumToInt(tIndex.Graph); | 139 | @as(u8, graph[i]) << @enumToInt(tIndex.Graph); |
| 140 | } | 140 | } |
| 141 | mem.set(u8, table[128..256], 0); | 141 | mem.set(u8, table[128..256], 0); |
| 142 | break :init table; | 142 | break :init table; |
| 143 | }; | 143 | }; |
| 144 | 144 | ||
| 145 | fn inTable(c: u8, t: tIndex) bool { | 145 | fn inTable(c: u8, t: tIndex) bool { |
| 146 | return (combinedTable[c] & (u8(1) << @enumToInt(t))) != 0; | 146 | return (combinedTable[c] & (@as(u8, 1) << @enumToInt(t))) != 0; |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | pub fn isAlNum(c: u8) bool { | 149 | pub fn isAlNum(c: u8) bool { |
| 150 | return (combinedTable[c] & ((u8(1) << @enumToInt(tIndex.Alpha)) | | 150 | return (combinedTable[c] & ((@as(u8, 1) << @enumToInt(tIndex.Alpha)) | |
| 151 | u8(1) << @enumToInt(tIndex.Digit))) != 0; | 151 | @as(u8, 1) << @enumToInt(tIndex.Digit))) != 0; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | pub fn isAlpha(c: u8) bool { | 154 | pub fn isAlpha(c: u8) bool { |
lib/std/atomic/queue.zig+2-2| ... | @@ -214,8 +214,8 @@ test "std.atomic.Queue" { | ... | @@ -214,8 +214,8 @@ test "std.atomic.Queue" { |
| 214 | std.debug.panic( | 214 | std.debug.panic( |
| 215 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", | 215 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", |
| 216 | context.get_count, | 216 | context.get_count, |
| 217 | u32(puts_per_thread), | 217 | @as(u32, puts_per_thread), |
| 218 | u32(put_thread_count), | 218 | @as(u32, put_thread_count), |
| 219 | ); | 219 | ); |
| 220 | } | 220 | } |
| 221 | } | 221 | } |
lib/std/atomic/stack.zig+3-3| ... | @@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type { | ... | @@ -11,7 +11,7 @@ pub fn Stack(comptime T: type) type { |
| 11 | root: ?*Node, | 11 | root: ?*Node, |
| 12 | lock: @typeOf(lock_init), | 12 | lock: @typeOf(lock_init), |
| 13 | 13 | ||
| 14 | const lock_init = if (builtin.single_threaded) {} else u8(0); | 14 | const lock_init = if (builtin.single_threaded) {} else @as(u8, 0); |
| 15 | 15 | ||
| 16 | pub const Self = @This(); | 16 | pub const Self = @This(); |
| 17 | 17 | ||
| ... | @@ -141,8 +141,8 @@ test "std.atomic.stack" { | ... | @@ -141,8 +141,8 @@ test "std.atomic.stack" { |
| 141 | std.debug.panic( | 141 | std.debug.panic( |
| 142 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", | 142 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", |
| 143 | context.get_count, | 143 | context.get_count, |
| 144 | u32(puts_per_thread), | 144 | @as(u32, puts_per_thread), |
| 145 | u32(put_thread_count), | 145 | @as(u32, put_thread_count), |
| 146 | ); | 146 | ); |
| 147 | } | 147 | } |
| 148 | } | 148 | } |
lib/std/bloom_filter.zig+11-11| ... | @@ -28,7 +28,7 @@ pub fn BloomFilter( | ... | @@ -28,7 +28,7 @@ pub fn BloomFilter( |
| 28 | assert(n_items > 0); | 28 | assert(n_items > 0); |
| 29 | assert(math.isPowerOfTwo(n_items)); | 29 | assert(math.isPowerOfTwo(n_items)); |
| 30 | assert(K > 0); | 30 | assert(K > 0); |
| 31 | const cellEmpty = if (Cell == bool) false else Cell(0); | 31 | const cellEmpty = if (Cell == bool) false else @as(Cell, 0); |
| 32 | const cellMax = if (Cell == bool) true else math.maxInt(Cell); | 32 | const cellMax = if (Cell == bool) true else math.maxInt(Cell); |
| 33 | const n_bytes = (n_items * comptime std.meta.bitCount(Cell)) / 8; | 33 | const n_bytes = (n_items * comptime std.meta.bitCount(Cell)) / 8; |
| 34 | assert(n_bytes > 0); | 34 | assert(n_bytes > 0); |
| ... | @@ -137,7 +137,7 @@ pub fn BloomFilter( | ... | @@ -137,7 +137,7 @@ pub fn BloomFilter( |
| 137 | var i: usize = 0; | 137 | var i: usize = 0; |
| 138 | while (i < n_items) : (i += 1) { | 138 | while (i < n_items) : (i += 1) { |
| 139 | const cell = self.getCell(@intCast(Index, i)); | 139 | const cell = self.getCell(@intCast(Index, i)); |
| 140 | n += if (if (Cell == bool) cell else cell > 0) Index(1) else Index(0); | 140 | n += if (if (Cell == bool) cell else cell > 0) @as(Index, 1) else @as(Index, 0); |
| 141 | } | 141 | } |
| 142 | } | 142 | } |
| 143 | return n; | 143 | return n; |
| ... | @@ -161,7 +161,7 @@ fn hashFunc(out: []u8, Ki: usize, in: []const u8) void { | ... | @@ -161,7 +161,7 @@ fn hashFunc(out: []u8, Ki: usize, in: []const u8) void { |
| 161 | 161 | ||
| 162 | test "std.BloomFilter" { | 162 | test "std.BloomFilter" { |
| 163 | inline for ([_]type{ bool, u1, u2, u3, u4 }) |Cell| { | 163 | inline for ([_]type{ bool, u1, u2, u3, u4 }) |Cell| { |
| 164 | const emptyCell = if (Cell == bool) false else Cell(0); | 164 | const emptyCell = if (Cell == bool) false else @as(Cell, 0); |
| 165 | const BF = BloomFilter(128 * 8, 8, Cell, builtin.endian, hashFunc); | 165 | const BF = BloomFilter(128 * 8, 8, Cell, builtin.endian, hashFunc); |
| 166 | var bf = BF{}; | 166 | var bf = BF{}; |
| 167 | var i: usize = undefined; | 167 | var i: usize = undefined; |
| ... | @@ -170,8 +170,8 @@ test "std.BloomFilter" { | ... | @@ -170,8 +170,8 @@ test "std.BloomFilter" { |
| 170 | while (i < BF.items) : (i += 1) { | 170 | while (i < BF.items) : (i += 1) { |
| 171 | testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); | 171 | testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); |
| 172 | } | 172 | } |
| 173 | testing.expectEqual(BF.Index(0), bf.popCount()); | 173 | testing.expectEqual(@as(BF.Index, 0), bf.popCount()); |
| 174 | testing.expectEqual(f64(0), bf.estimateItems()); | 174 | testing.expectEqual(@as(f64, 0), bf.estimateItems()); |
| 175 | // fill in a few items | 175 | // fill in a few items |
| 176 | bf.incrementCell(42); | 176 | bf.incrementCell(42); |
| 177 | bf.incrementCell(255); | 177 | bf.incrementCell(255); |
| ... | @@ -196,8 +196,8 @@ test "std.BloomFilter" { | ... | @@ -196,8 +196,8 @@ test "std.BloomFilter" { |
| 196 | while (i < BF.items) : (i += 1) { | 196 | while (i < BF.items) : (i += 1) { |
| 197 | testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); | 197 | testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); |
| 198 | } | 198 | } |
| 199 | testing.expectEqual(BF.Index(0), bf.popCount()); | 199 | testing.expectEqual(@as(BF.Index, 0), bf.popCount()); |
| 200 | testing.expectEqual(f64(0), bf.estimateItems()); | 200 | testing.expectEqual(@as(f64, 0), bf.estimateItems()); |
| 201 | 201 | ||
| 202 | // Lets add a string | 202 | // Lets add a string |
| 203 | bf.add("foo"); | 203 | bf.add("foo"); |
| ... | @@ -218,8 +218,8 @@ test "std.BloomFilter" { | ... | @@ -218,8 +218,8 @@ test "std.BloomFilter" { |
| 218 | while (i < BF.items) : (i += 1) { | 218 | while (i < BF.items) : (i += 1) { |
| 219 | testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); | 219 | testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i))); |
| 220 | } | 220 | } |
| 221 | testing.expectEqual(BF.Index(0), bf.popCount()); | 221 | testing.expectEqual(@as(BF.Index, 0), bf.popCount()); |
| 222 | testing.expectEqual(f64(0), bf.estimateItems()); | 222 | testing.expectEqual(@as(f64, 0), bf.estimateItems()); |
| 223 | 223 | ||
| 224 | comptime var teststrings = [_][]const u8{ | 224 | comptime var teststrings = [_][]const u8{ |
| 225 | "foo", | 225 | "foo", |
| ... | @@ -246,12 +246,12 @@ test "std.BloomFilter" { | ... | @@ -246,12 +246,12 @@ test "std.BloomFilter" { |
| 246 | inline for (teststrings) |str| { | 246 | inline for (teststrings) |str| { |
| 247 | testing.expectEqual(true, larger_bf.contains(str)); | 247 | testing.expectEqual(true, larger_bf.contains(str)); |
| 248 | } | 248 | } |
| 249 | testing.expectEqual(u12(bf.popCount()) * (4096 / 1024), larger_bf.popCount()); | 249 | testing.expectEqual(@as(u12, bf.popCount()) * (4096 / 1024), larger_bf.popCount()); |
| 250 | 250 | ||
| 251 | const smaller_bf = bf.resize(64); | 251 | const smaller_bf = bf.resize(64); |
| 252 | inline for (teststrings) |str| { | 252 | inline for (teststrings) |str| { |
| 253 | testing.expectEqual(true, smaller_bf.contains(str)); | 253 | testing.expectEqual(true, smaller_bf.contains(str)); |
| 254 | } | 254 | } |
| 255 | testing.expect(bf.popCount() <= u10(smaller_bf.popCount()) * (1024 / 64)); | 255 | testing.expect(bf.popCount() <= @as(u10, smaller_bf.popCount()) * (1024 / 64)); |
| 256 | } | 256 | } |
| 257 | } | 257 | } |
lib/std/c/darwin.zig+1-1| ... | @@ -53,7 +53,7 @@ pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clo | ... | @@ -53,7 +53,7 @@ pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clo |
| 53 | pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t; | 53 | pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t; |
| 54 | 54 | ||
| 55 | pub fn sigaddset(set: *sigset_t, signo: u5) void { | 55 | pub fn sigaddset(set: *sigset_t, signo: u5) void { |
| 56 | set.* |= u32(1) << (signo - 1); | 56 | set.* |= @as(u32, 1) << (signo - 1); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; | 59 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
lib/std/child_process.zig+2-2| ... | @@ -219,7 +219,7 @@ pub const ChildProcess = struct { | ... | @@ -219,7 +219,7 @@ pub const ChildProcess = struct { |
| 219 | fn waitUnwrappedWindows(self: *ChildProcess) !void { | 219 | fn waitUnwrappedWindows(self: *ChildProcess) !void { |
| 220 | const result = windows.WaitForSingleObject(self.handle, windows.INFINITE); | 220 | const result = windows.WaitForSingleObject(self.handle, windows.INFINITE); |
| 221 | 221 | ||
| 222 | self.term = (SpawnError!Term)(x: { | 222 | self.term = @as(SpawnError!Term, x: { |
| 223 | var exit_code: windows.DWORD = undefined; | 223 | var exit_code: windows.DWORD = undefined; |
| 224 | if (windows.kernel32.GetExitCodeProcess(self.handle, &exit_code) == 0) { | 224 | if (windows.kernel32.GetExitCodeProcess(self.handle, &exit_code) == 0) { |
| 225 | break :x Term{ .Unknown = 0 }; | 225 | break :x Term{ .Unknown = 0 }; |
| ... | @@ -717,7 +717,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void { | ... | @@ -717,7 +717,7 @@ fn destroyPipe(pipe: [2]os.fd_t) void { |
| 717 | // Child of fork calls this to report an error to the fork parent. | 717 | // Child of fork calls this to report an error to the fork parent. |
| 718 | // Then the child exits. | 718 | // Then the child exits. |
| 719 | fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { | 719 | fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { |
| 720 | writeIntFd(fd, ErrInt(@errorToInt(err))) catch {}; | 720 | writeIntFd(fd, @as(ErrInt,@errorToInt(err))) catch {}; |
| 721 | os.exit(1); | 721 | os.exit(1); |
| 722 | } | 722 | } |
| 723 | 723 |
lib/std/crypto/aes.zig+10-10| ... | @@ -6,7 +6,7 @@ const testing = std.testing; | ... | @@ -6,7 +6,7 @@ const testing = std.testing; |
| 6 | 6 | ||
| 7 | // Apply sbox0 to each byte in w. | 7 | // Apply sbox0 to each byte in w. |
| 8 | fn subw(w: u32) u32 { | 8 | fn subw(w: u32) u32 { |
| 9 | return u32(sbox0[w >> 24]) << 24 | u32(sbox0[w >> 16 & 0xff]) << 16 | u32(sbox0[w >> 8 & 0xff]) << 8 | u32(sbox0[w & 0xff]); | 9 | return @as(u32, sbox0[w >> 24]) << 24 | @as(u32, sbox0[w >> 16 & 0xff]) << 16 | @as(u32, sbox0[w >> 8 & 0xff]) << 8 | @as(u32, sbox0[w & 0xff]); |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | fn rotw(w: u32) u32 { | 12 | fn rotw(w: u32) u32 { |
| ... | @@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { | ... | @@ -48,10 +48,10 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | // Last round uses s-box directly and XORs to produce output. | 50 | // Last round uses s-box directly and XORs to produce output. |
| 51 | s0 = u32(sbox0[t0 >> 24]) << 24 | u32(sbox0[t1 >> 16 & 0xff]) << 16 | u32(sbox0[t2 >> 8 & 0xff]) << 8 | u32(sbox0[t3 & 0xff]); | 51 | s0 = @as(u32, sbox0[t0 >> 24]) << 24 | @as(u32, sbox0[t1 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t2 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t3 & 0xff]); |
| 52 | s1 = u32(sbox0[t1 >> 24]) << 24 | u32(sbox0[t2 >> 16 & 0xff]) << 16 | u32(sbox0[t3 >> 8 & 0xff]) << 8 | u32(sbox0[t0 & 0xff]); | 52 | s1 = @as(u32, sbox0[t1 >> 24]) << 24 | @as(u32, sbox0[t2 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t3 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t0 & 0xff]); |
| 53 | s2 = u32(sbox0[t2 >> 24]) << 24 | u32(sbox0[t3 >> 16 & 0xff]) << 16 | u32(sbox0[t0 >> 8 & 0xff]) << 8 | u32(sbox0[t1 & 0xff]); | 53 | s2 = @as(u32, sbox0[t2 >> 24]) << 24 | @as(u32, sbox0[t3 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t0 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t1 & 0xff]); |
| 54 | s3 = u32(sbox0[t3 >> 24]) << 24 | u32(sbox0[t0 >> 16 & 0xff]) << 16 | u32(sbox0[t1 >> 8 & 0xff]) << 8 | u32(sbox0[t2 & 0xff]); | 54 | s3 = @as(u32, sbox0[t3 >> 24]) << 24 | @as(u32, sbox0[t0 >> 16 & 0xff]) << 16 | @as(u32, sbox0[t1 >> 8 & 0xff]) << 8 | @as(u32, sbox0[t2 & 0xff]); |
| 55 | 55 | ||
| 56 | s0 ^= xk[k + 0]; | 56 | s0 ^= xk[k + 0]; |
| 57 | s1 ^= xk[k + 1]; | 57 | s1 ^= xk[k + 1]; |
| ... | @@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { | ... | @@ -99,10 +99,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | // Last round uses s-box directly and XORs to produce output. | 101 | // Last round uses s-box directly and XORs to produce output. |
| 102 | s0 = u32(sbox1[t0 >> 24]) << 24 | u32(sbox1[t3 >> 16 & 0xff]) << 16 | u32(sbox1[t2 >> 8 & 0xff]) << 8 | u32(sbox1[t1 & 0xff]); | 102 | s0 = @as(u32, sbox1[t0 >> 24]) << 24 | @as(u32, sbox1[t3 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t2 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t1 & 0xff]); |
| 103 | s1 = u32(sbox1[t1 >> 24]) << 24 | u32(sbox1[t0 >> 16 & 0xff]) << 16 | u32(sbox1[t3 >> 8 & 0xff]) << 8 | u32(sbox1[t2 & 0xff]); | 103 | s1 = @as(u32, sbox1[t1 >> 24]) << 24 | @as(u32, sbox1[t0 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t3 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t2 & 0xff]); |
| 104 | s2 = u32(sbox1[t2 >> 24]) << 24 | u32(sbox1[t1 >> 16 & 0xff]) << 16 | u32(sbox1[t0 >> 8 & 0xff]) << 8 | u32(sbox1[t3 & 0xff]); | 104 | s2 = @as(u32, sbox1[t2 >> 24]) << 24 | @as(u32, sbox1[t1 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t0 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t3 & 0xff]); |
| 105 | s3 = u32(sbox1[t3 >> 24]) << 24 | u32(sbox1[t2 >> 16 & 0xff]) << 16 | u32(sbox1[t1 >> 8 & 0xff]) << 8 | u32(sbox1[t0 & 0xff]); | 105 | s3 = @as(u32, sbox1[t3 >> 24]) << 24 | @as(u32, sbox1[t2 >> 16 & 0xff]) << 16 | @as(u32, sbox1[t1 >> 8 & 0xff]) << 8 | @as(u32, sbox1[t0 & 0xff]); |
| 106 | 106 | ||
| 107 | s0 ^= xk[k + 0]; | 107 | s0 ^= xk[k + 0]; |
| 108 | s1 ^= xk[k + 1]; | 108 | s1 ^= xk[k + 1]; |
| ... | @@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void { | ... | @@ -256,7 +256,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void { |
| 256 | while (i < enc.len) : (i += 1) { | 256 | while (i < enc.len) : (i += 1) { |
| 257 | var t = enc[i - 1]; | 257 | var t = enc[i - 1]; |
| 258 | if (i % nk == 0) { | 258 | if (i % nk == 0) { |
| 259 | t = subw(rotw(t)) ^ (u32(powx[i / nk - 1]) << 24); | 259 | t = subw(rotw(t)) ^ (@as(u32, powx[i / nk - 1]) << 24); |
| 260 | } else if (nk > 6 and i % nk == 4) { | 260 | } else if (nk > 6 and i % nk == 4) { |
| 261 | t = subw(t); | 261 | t = subw(t); |
| 262 | } | 262 | } |
lib/std/crypto/blake2.zig+8-8| ... | @@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type { | ... | @@ -164,13 +164,13 @@ fn Blake2s(comptime out_len: usize) type { |
| 164 | inline while (j < 10) : (j += 1) { | 164 | inline while (j < 10) : (j += 1) { |
| 165 | inline for (rounds) |r| { | 165 | inline for (rounds) |r| { |
| 166 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]]; | 166 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]]; |
| 167 | v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(16)); | 167 | v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 16)); |
| 168 | v[r.c] = v[r.c] +% v[r.d]; | 168 | v[r.c] = v[r.c] +% v[r.d]; |
| 169 | v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(12)); | 169 | v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 12)); |
| 170 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]]; | 170 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]]; |
| 171 | v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], usize(8)); | 171 | v[r.d] = math.rotr(u32, v[r.d] ^ v[r.a], @as(usize, 8)); |
| 172 | v[r.c] = v[r.c] +% v[r.d]; | 172 | v[r.c] = v[r.c] +% v[r.d]; |
| 173 | v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], usize(7)); | 173 | v[r.b] = math.rotr(u32, v[r.b] ^ v[r.c], @as(usize, 7)); |
| 174 | } | 174 | } |
| 175 | } | 175 | } |
| 176 | 176 | ||
| ... | @@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type { | ... | @@ -398,13 +398,13 @@ fn Blake2b(comptime out_len: usize) type { |
| 398 | inline while (j < 12) : (j += 1) { | 398 | inline while (j < 12) : (j += 1) { |
| 399 | inline for (rounds) |r| { | 399 | inline for (rounds) |r| { |
| 400 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]]; | 400 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.x]]; |
| 401 | v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(32)); | 401 | v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 32)); |
| 402 | v[r.c] = v[r.c] +% v[r.d]; | 402 | v[r.c] = v[r.c] +% v[r.d]; |
| 403 | v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(24)); | 403 | v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 24)); |
| 404 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]]; | 404 | v[r.a] = v[r.a] +% v[r.b] +% m[sigma[j][r.y]]; |
| 405 | v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], usize(16)); | 405 | v[r.d] = math.rotr(u64, v[r.d] ^ v[r.a], @as(usize, 16)); |
| 406 | v[r.c] = v[r.c] +% v[r.d]; | 406 | v[r.c] = v[r.c] +% v[r.d]; |
| 407 | v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], usize(63)); | 407 | v[r.b] = math.rotr(u64, v[r.b] ^ v[r.c], @as(usize, 63)); |
| 408 | } | 408 | } |
| 409 | } | 409 | } |
| 410 | 410 |
lib/std/crypto/chacha20.zig+4-4| ... | @@ -49,13 +49,13 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void { | ... | @@ -49,13 +49,13 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void { |
| 49 | // two-round cycles | 49 | // two-round cycles |
| 50 | inline for (rounds) |r| { | 50 | inline for (rounds) |r| { |
| 51 | x[r.a] +%= x[r.b]; | 51 | x[r.a] +%= x[r.b]; |
| 52 | x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(16)); | 52 | x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 16)); |
| 53 | x[r.c] +%= x[r.d]; | 53 | x[r.c] +%= x[r.d]; |
| 54 | x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(12)); | 54 | x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 12)); |
| 55 | x[r.a] +%= x[r.b]; | 55 | x[r.a] +%= x[r.b]; |
| 56 | x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], u32(8)); | 56 | x[r.d] = std.math.rotl(u32, x[r.d] ^ x[r.a], @as(u32, 8)); |
| 57 | x[r.c] +%= x[r.d]; | 57 | x[r.c] +%= x[r.d]; |
| 58 | x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], u32(7)); | 58 | x[r.b] = std.math.rotl(u32, x[r.b] ^ x[r.c], @as(u32, 7)); |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | 61 |
lib/std/crypto/gimli.zig+4-4| ... | @@ -34,9 +34,9 @@ pub const State = struct { | ... | @@ -34,9 +34,9 @@ pub const State = struct { |
| 34 | 34 | ||
| 35 | pub fn permute(self: *Self) void { | 35 | pub fn permute(self: *Self) void { |
| 36 | const state = &self.data; | 36 | const state = &self.data; |
| 37 | var round = u32(24); | 37 | var round = @as(u32, 24); |
| 38 | while (round > 0) : (round -= 1) { | 38 | while (round > 0) : (round -= 1) { |
| 39 | var column = usize(0); | 39 | var column = @as(usize, 0); |
| 40 | while (column < 4) : (column += 1) { | 40 | while (column < 4) : (column += 1) { |
| 41 | const x = math.rotl(u32, state[column], 24); | 41 | const x = math.rotl(u32, state[column], 24); |
| 42 | const y = math.rotl(u32, state[4 + column], 9); | 42 | const y = math.rotl(u32, state[4 + column], 9); |
| ... | @@ -61,7 +61,7 @@ pub const State = struct { | ... | @@ -61,7 +61,7 @@ pub const State = struct { |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | pub fn squeeze(self: *Self, out: []u8) void { | 63 | pub fn squeeze(self: *Self, out: []u8) void { |
| 64 | var i = usize(0); | 64 | var i = @as(usize, 0); |
| 65 | while (i + RATE <= out.len) : (i += RATE) { | 65 | while (i + RATE <= out.len) : (i += RATE) { |
| 66 | self.permute(); | 66 | self.permute(); |
| 67 | mem.copy(u8, out[i..], self.toSliceConst()[0..RATE]); | 67 | mem.copy(u8, out[i..], self.toSliceConst()[0..RATE]); |
| ... | @@ -79,7 +79,7 @@ test "permute" { | ... | @@ -79,7 +79,7 @@ test "permute" { |
| 79 | var state = State{ | 79 | var state = State{ |
| 80 | .data = blk: { | 80 | .data = blk: { |
| 81 | var input: [12]u32 = undefined; | 81 | var input: [12]u32 = undefined; |
| 82 | var i = u32(0); | 82 | var i = @as(u32, 0); |
| 83 | while (i < 12) : (i += 1) { | 83 | while (i < 12) : (i += 1) { |
| 84 | input[i] = i * i * i + i *% 0x9e3779b9; | 84 | input[i] = i * i * i + i *% 0x9e3779b9; |
| 85 | } | 85 | } |
lib/std/crypto/md5.zig+4-4| ... | @@ -126,10 +126,10 @@ pub const Md5 = struct { | ... | @@ -126,10 +126,10 @@ pub const Md5 = struct { |
| 126 | while (i < 16) : (i += 1) { | 126 | while (i < 16) : (i += 1) { |
| 127 | // NOTE: Performing or's separately improves perf by ~10% | 127 | // NOTE: Performing or's separately improves perf by ~10% |
| 128 | s[i] = 0; | 128 | s[i] = 0; |
| 129 | s[i] |= u32(b[i * 4 + 0]); | 129 | s[i] |= @as(u32, b[i * 4 + 0]); |
| 130 | s[i] |= u32(b[i * 4 + 1]) << 8; | 130 | s[i] |= @as(u32, b[i * 4 + 1]) << 8; |
| 131 | s[i] |= u32(b[i * 4 + 2]) << 16; | 131 | s[i] |= @as(u32, b[i * 4 + 2]) << 16; |
| 132 | s[i] |= u32(b[i * 4 + 3]) << 24; | 132 | s[i] |= @as(u32, b[i * 4 + 3]) << 24; |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | var v: [4]u32 = [_]u32{ | 135 | var v: [4]u32 = [_]u32{ |
lib/std/crypto/poly1305.zig+6-6| ... | @@ -87,11 +87,11 @@ pub const Poly1305 = struct { | ... | @@ -87,11 +87,11 @@ pub const Poly1305 = struct { |
| 87 | // ctx->h <= 4_ffffffff_ffffffff_ffffffff_ffffffff | 87 | // ctx->h <= 4_ffffffff_ffffffff_ffffffff_ffffffff |
| 88 | fn polyBlock(ctx: *Self) void { | 88 | fn polyBlock(ctx: *Self) void { |
| 89 | // s = h + c, without carry propagation | 89 | // s = h + c, without carry propagation |
| 90 | const s0 = u64(ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe | 90 | const s0 = @as(u64, ctx.h[0]) + ctx.c[0]; // s0 <= 1_fffffffe |
| 91 | const s1 = u64(ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe | 91 | const s1 = @as(u64, ctx.h[1]) + ctx.c[1]; // s1 <= 1_fffffffe |
| 92 | const s2 = u64(ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe | 92 | const s2 = @as(u64, ctx.h[2]) + ctx.c[2]; // s2 <= 1_fffffffe |
| 93 | const s3 = u64(ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe | 93 | const s3 = @as(u64, ctx.h[3]) + ctx.c[3]; // s3 <= 1_fffffffe |
| 94 | const s4 = u64(ctx.h[4]) + ctx.c[4]; // s4 <= 5 | 94 | const s4 = @as(u64, ctx.h[4]) + ctx.c[4]; // s4 <= 5 |
| 95 | 95 | ||
| 96 | // Local all the things! | 96 | // Local all the things! |
| 97 | const r0 = ctx.r[0]; // r0 <= 0fffffff | 97 | const r0 = ctx.r[0]; // r0 <= 0fffffff |
| ... | @@ -197,7 +197,7 @@ pub const Poly1305 = struct { | ... | @@ -197,7 +197,7 @@ pub const Poly1305 = struct { |
| 197 | 197 | ||
| 198 | // check if we should subtract 2^130-5 by performing the | 198 | // check if we should subtract 2^130-5 by performing the |
| 199 | // corresponding carry propagation. | 199 | // corresponding carry propagation. |
| 200 | const _u0 = u64(5) + ctx.h[0]; // <= 1_00000004 | 200 | const _u0 = @as(u64, 5) + ctx.h[0]; // <= 1_00000004 |
| 201 | const _u1 = (_u0 >> 32) + ctx.h[1]; // <= 1_00000000 | 201 | const _u1 = (_u0 >> 32) + ctx.h[1]; // <= 1_00000000 |
| 202 | const _u2 = (_u1 >> 32) + ctx.h[2]; // <= 1_00000000 | 202 | const _u2 = (_u1 >> 32) + ctx.h[2]; // <= 1_00000000 |
| 203 | const _u3 = (_u2 >> 32) + ctx.h[3]; // <= 1_00000000 | 203 | const _u3 = (_u2 >> 32) + ctx.h[3]; // <= 1_00000000 |
lib/std/crypto/sha1.zig+15-15| ... | @@ -146,10 +146,10 @@ pub const Sha1 = struct { | ... | @@ -146,10 +146,10 @@ pub const Sha1 = struct { |
| 146 | Rp(0, 1, 2, 3, 4, 15), | 146 | Rp(0, 1, 2, 3, 4, 15), |
| 147 | }; | 147 | }; |
| 148 | inline for (round0a) |r| { | 148 | inline for (round0a) |r| { |
| 149 | s[r.i] = (u32(b[r.i * 4 + 0]) << 24) | (u32(b[r.i * 4 + 1]) << 16) | (u32(b[r.i * 4 + 2]) << 8) | (u32(b[r.i * 4 + 3]) << 0); | 149 | s[r.i] = (@as(u32, b[r.i * 4 + 0]) << 24) | (@as(u32, b[r.i * 4 + 1]) << 16) | (@as(u32, b[r.i * 4 + 2]) << 8) | (@as(u32, b[r.i * 4 + 3]) << 0); |
| 150 | 150 | ||
| 151 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); | 151 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); |
| 152 | v[r.b] = math.rotl(u32, v[r.b], u32(30)); | 152 | v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | const round0b = comptime [_]RoundParam{ | 155 | const round0b = comptime [_]RoundParam{ |
| ... | @@ -160,10 +160,10 @@ pub const Sha1 = struct { | ... | @@ -160,10 +160,10 @@ pub const Sha1 = struct { |
| 160 | }; | 160 | }; |
| 161 | inline for (round0b) |r| { | 161 | inline for (round0b) |r| { |
| 162 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; | 162 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; |
| 163 | s[r.i & 0xf] = math.rotl(u32, t, u32(1)); | 163 | s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); |
| 164 | 164 | ||
| 165 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); | 165 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); |
| 166 | v[r.b] = math.rotl(u32, v[r.b], u32(30)); | 166 | v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | const round1 = comptime [_]RoundParam{ | 169 | const round1 = comptime [_]RoundParam{ |
| ... | @@ -190,10 +190,10 @@ pub const Sha1 = struct { | ... | @@ -190,10 +190,10 @@ pub const Sha1 = struct { |
| 190 | }; | 190 | }; |
| 191 | inline for (round1) |r| { | 191 | inline for (round1) |r| { |
| 192 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; | 192 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; |
| 193 | s[r.i & 0xf] = math.rotl(u32, t, u32(1)); | 193 | s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); |
| 194 | 194 | ||
| 195 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x6ED9EBA1 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]); | 195 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x6ED9EBA1 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]); |
| 196 | v[r.b] = math.rotl(u32, v[r.b], u32(30)); | 196 | v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | const round2 = comptime [_]RoundParam{ | 199 | const round2 = comptime [_]RoundParam{ |
| ... | @@ -220,10 +220,10 @@ pub const Sha1 = struct { | ... | @@ -220,10 +220,10 @@ pub const Sha1 = struct { |
| 220 | }; | 220 | }; |
| 221 | inline for (round2) |r| { | 221 | inline for (round2) |r| { |
| 222 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; | 222 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; |
| 223 | s[r.i & 0xf] = math.rotl(u32, t, u32(1)); | 223 | s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); |
| 224 | 224 | ||
| 225 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0x8F1BBCDC +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) ^ (v[r.b] & v[r.d]) ^ (v[r.c] & v[r.d])); | 225 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x8F1BBCDC +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) ^ (v[r.b] & v[r.d]) ^ (v[r.c] & v[r.d])); |
| 226 | v[r.b] = math.rotl(u32, v[r.b], u32(30)); | 226 | v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | const round3 = comptime [_]RoundParam{ | 229 | const round3 = comptime [_]RoundParam{ |
| ... | @@ -250,10 +250,10 @@ pub const Sha1 = struct { | ... | @@ -250,10 +250,10 @@ pub const Sha1 = struct { |
| 250 | }; | 250 | }; |
| 251 | inline for (round3) |r| { | 251 | inline for (round3) |r| { |
| 252 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; | 252 | const t = s[(r.i - 3) & 0xf] ^ s[(r.i - 8) & 0xf] ^ s[(r.i - 14) & 0xf] ^ s[(r.i - 16) & 0xf]; |
| 253 | s[r.i & 0xf] = math.rotl(u32, t, u32(1)); | 253 | s[r.i & 0xf] = math.rotl(u32, t, @as(u32, 1)); |
| 254 | 254 | ||
| 255 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], u32(5)) +% 0xCA62C1D6 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]); | 255 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0xCA62C1D6 +% s[r.i & 0xf] +% (v[r.b] ^ v[r.c] ^ v[r.d]); |
| 256 | v[r.b] = math.rotl(u32, v[r.b], u32(30)); | 256 | v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | d.s[0] +%= v[0]; | 259 | d.s[0] +%= v[0]; |
lib/std/crypto/sha2.zig+20-18| ... | @@ -180,13 +180,13 @@ fn Sha2_32(comptime params: Sha2Params32) type { | ... | @@ -180,13 +180,13 @@ fn Sha2_32(comptime params: Sha2Params32) type { |
| 180 | var i: usize = 0; | 180 | var i: usize = 0; |
| 181 | while (i < 16) : (i += 1) { | 181 | while (i < 16) : (i += 1) { |
| 182 | s[i] = 0; | 182 | s[i] = 0; |
| 183 | s[i] |= u32(b[i * 4 + 0]) << 24; | 183 | s[i] |= @as(u32, b[i * 4 + 0]) << 24; |
| 184 | s[i] |= u32(b[i * 4 + 1]) << 16; | 184 | s[i] |= @as(u32, b[i * 4 + 1]) << 16; |
| 185 | s[i] |= u32(b[i * 4 + 2]) << 8; | 185 | s[i] |= @as(u32, b[i * 4 + 2]) << 8; |
| 186 | s[i] |= u32(b[i * 4 + 3]) << 0; | 186 | s[i] |= @as(u32, b[i * 4 + 3]) << 0; |
| 187 | } | 187 | } |
| 188 | while (i < 64) : (i += 1) { | 188 | while (i < 64) : (i += 1) { |
| 189 | s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], u32(7)) ^ math.rotr(u32, s[i - 15], u32(18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], u32(17)) ^ math.rotr(u32, s[i - 2], u32(19)) ^ (s[i - 2] >> 10)); | 189 | s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], @as(u32, 7)) ^ math.rotr(u32, s[i - 15], @as(u32, 18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], @as(u32, 17)) ^ math.rotr(u32, s[i - 2], @as(u32, 19)) ^ (s[i - 2] >> 10)); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | var v: [8]u32 = [_]u32{ | 192 | var v: [8]u32 = [_]u32{ |
| ... | @@ -267,11 +267,11 @@ fn Sha2_32(comptime params: Sha2Params32) type { | ... | @@ -267,11 +267,11 @@ fn Sha2_32(comptime params: Sha2Params32) type { |
| 267 | Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2), | 267 | Rp256(1, 2, 3, 4, 5, 6, 7, 0, 63, 0xC67178F2), |
| 268 | }; | 268 | }; |
| 269 | inline for (round0) |r| { | 269 | inline for (round0) |r| { |
| 270 | v[r.h] = v[r.h] +% (math.rotr(u32, v[r.e], u32(6)) ^ math.rotr(u32, v[r.e], u32(11)) ^ math.rotr(u32, v[r.e], u32(25))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; | 270 | v[r.h] = v[r.h] +% (math.rotr(u32, v[r.e], @as(u32, 6)) ^ math.rotr(u32, v[r.e], @as(u32, 11)) ^ math.rotr(u32, v[r.e], @as(u32, 25))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; |
| 271 | 271 | ||
| 272 | v[r.d] = v[r.d] +% v[r.h]; | 272 | v[r.d] = v[r.d] +% v[r.h]; |
| 273 | 273 | ||
| 274 | v[r.h] = v[r.h] +% (math.rotr(u32, v[r.a], u32(2)) ^ math.rotr(u32, v[r.a], u32(13)) ^ math.rotr(u32, v[r.a], u32(22))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); | 274 | v[r.h] = v[r.h] +% (math.rotr(u32, v[r.a], @as(u32, 2)) ^ math.rotr(u32, v[r.a], @as(u32, 13)) ^ math.rotr(u32, v[r.a], @as(u32, 22))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | d.s[0] +%= v[0]; | 277 | d.s[0] +%= v[0]; |
| ... | @@ -522,17 +522,19 @@ fn Sha2_64(comptime params: Sha2Params64) type { | ... | @@ -522,17 +522,19 @@ fn Sha2_64(comptime params: Sha2Params64) type { |
| 522 | var i: usize = 0; | 522 | var i: usize = 0; |
| 523 | while (i < 16) : (i += 1) { | 523 | while (i < 16) : (i += 1) { |
| 524 | s[i] = 0; | 524 | s[i] = 0; |
| 525 | s[i] |= u64(b[i * 8 + 0]) << 56; | 525 | s[i] |= @as(u64, b[i * 8 + 0]) << 56; |
| 526 | s[i] |= u64(b[i * 8 + 1]) << 48; | 526 | s[i] |= @as(u64, b[i * 8 + 1]) << 48; |
| 527 | s[i] |= u64(b[i * 8 + 2]) << 40; | 527 | s[i] |= @as(u64, b[i * 8 + 2]) << 40; |
| 528 | s[i] |= u64(b[i * 8 + 3]) << 32; | 528 | s[i] |= @as(u64, b[i * 8 + 3]) << 32; |
| 529 | s[i] |= u64(b[i * 8 + 4]) << 24; | 529 | s[i] |= @as(u64, b[i * 8 + 4]) << 24; |
| 530 | s[i] |= u64(b[i * 8 + 5]) << 16; | 530 | s[i] |= @as(u64, b[i * 8 + 5]) << 16; |
| 531 | s[i] |= u64(b[i * 8 + 6]) << 8; | 531 | s[i] |= @as(u64, b[i * 8 + 6]) << 8; |
| 532 | s[i] |= u64(b[i * 8 + 7]) << 0; | 532 | s[i] |= @as(u64, b[i * 8 + 7]) << 0; |
| 533 | } | 533 | } |
| 534 | while (i < 80) : (i += 1) { | 534 | while (i < 80) : (i += 1) { |
| 535 | s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u64, s[i - 15], u64(1)) ^ math.rotr(u64, s[i - 15], u64(8)) ^ (s[i - 15] >> 7)) +% (math.rotr(u64, s[i - 2], u64(19)) ^ math.rotr(u64, s[i - 2], u64(61)) ^ (s[i - 2] >> 6)); | 535 | s[i] = s[i - 16] +% s[i - 7] +% |
| 536 | (math.rotr(u64, s[i - 15], @as(u64, 1)) ^ math.rotr(u64, s[i - 15], @as(u64, 8)) ^ (s[i - 15] >> 7)) +% | ||
| 537 | (math.rotr(u64, s[i - 2], @as(u64, 19)) ^ math.rotr(u64, s[i - 2], @as(u64, 61)) ^ (s[i - 2] >> 6)); | ||
| 536 | } | 538 | } |
| 537 | 539 | ||
| 538 | var v: [8]u64 = [_]u64{ | 540 | var v: [8]u64 = [_]u64{ |
| ... | @@ -629,11 +631,11 @@ fn Sha2_64(comptime params: Sha2Params64) type { | ... | @@ -629,11 +631,11 @@ fn Sha2_64(comptime params: Sha2Params64) type { |
| 629 | Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817), | 631 | Rp512(1, 2, 3, 4, 5, 6, 7, 0, 79, 0x6C44198C4A475817), |
| 630 | }; | 632 | }; |
| 631 | inline for (round0) |r| { | 633 | inline for (round0) |r| { |
| 632 | v[r.h] = v[r.h] +% (math.rotr(u64, v[r.e], u64(14)) ^ math.rotr(u64, v[r.e], u64(18)) ^ math.rotr(u64, v[r.e], u64(41))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; | 634 | v[r.h] = v[r.h] +% (math.rotr(u64, v[r.e], @as(u64, 14)) ^ math.rotr(u64, v[r.e], @as(u64, 18)) ^ math.rotr(u64, v[r.e], @as(u64, 41))) +% (v[r.g] ^ (v[r.e] & (v[r.f] ^ v[r.g]))) +% r.k +% s[r.i]; |
| 633 | 635 | ||
| 634 | v[r.d] = v[r.d] +% v[r.h]; | 636 | v[r.d] = v[r.d] +% v[r.h]; |
| 635 | 637 | ||
| 636 | v[r.h] = v[r.h] +% (math.rotr(u64, v[r.a], u64(28)) ^ math.rotr(u64, v[r.a], u64(34)) ^ math.rotr(u64, v[r.a], u64(39))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); | 638 | v[r.h] = v[r.h] +% (math.rotr(u64, v[r.a], @as(u64, 28)) ^ math.rotr(u64, v[r.a], @as(u64, 34)) ^ math.rotr(u64, v[r.a], @as(u64, 39))) +% ((v[r.a] & (v[r.b] | v[r.c])) | (v[r.b] & v[r.c])); |
| 637 | } | 639 | } |
| 638 | 640 | ||
| 639 | d.s[0] +%= v[0]; | 641 | d.s[0] +%= v[0]; |
lib/std/crypto/sha3.zig+1-1| ... | @@ -133,7 +133,7 @@ fn keccak_f(comptime F: usize, d: []u8) void { | ... | @@ -133,7 +133,7 @@ fn keccak_f(comptime F: usize, d: []u8) void { |
| 133 | } | 133 | } |
| 134 | x = 0; | 134 | x = 0; |
| 135 | inline while (x < 5) : (x += 1) { | 135 | inline while (x < 5) : (x += 1) { |
| 136 | t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], usize(1)); | 136 | t[0] = c[M5[x + 4]] ^ math.rotl(u64, c[M5[x + 1]], @as(usize, 1)); |
| 137 | y = 0; | 137 | y = 0; |
| 138 | inline while (y < 5) : (y += 1) { | 138 | inline while (y < 5) : (y += 1) { |
| 139 | s[x + y * 5] ^= t[0]; | 139 | s[x + y * 5] ^= t[0]; |
lib/std/crypto/x25519.zig+33-33| ... | @@ -199,9 +199,9 @@ const Fe = struct { | ... | @@ -199,9 +199,9 @@ const Fe = struct { |
| 199 | inline fn carryRound(c: []i64, t: []i64, comptime i: comptime_int, comptime shift: comptime_int, comptime mult: comptime_int) void { | 199 | inline fn carryRound(c: []i64, t: []i64, comptime i: comptime_int, comptime shift: comptime_int, comptime mult: comptime_int) void { |
| 200 | const j = (i + 1) % 10; | 200 | const j = (i + 1) % 10; |
| 201 | 201 | ||
| 202 | c[i] = (t[i] + (i64(1) << shift)) >> (shift + 1); | 202 | c[i] = (t[i] + (@as(i64, 1) << shift)) >> (shift + 1); |
| 203 | t[j] += c[i] * mult; | 203 | t[j] += c[i] * mult; |
| 204 | t[i] -= c[i] * (i64(1) << (shift + 1)); | 204 | t[i] -= c[i] * (@as(i64, 1) << (shift + 1)); |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | fn carry1(h: *Fe, t: []i64) void { | 207 | fn carry1(h: *Fe, t: []i64) void { |
| ... | @@ -256,15 +256,15 @@ const Fe = struct { | ... | @@ -256,15 +256,15 @@ const Fe = struct { |
| 256 | var t: [10]i64 = undefined; | 256 | var t: [10]i64 = undefined; |
| 257 | 257 | ||
| 258 | t[0] = readIntSliceLittle(u32, s[0..4]); | 258 | t[0] = readIntSliceLittle(u32, s[0..4]); |
| 259 | t[1] = u32(readIntSliceLittle(u24, s[4..7])) << 6; | 259 | t[1] = @as(u32, readIntSliceLittle(u24, s[4..7])) << 6; |
| 260 | t[2] = u32(readIntSliceLittle(u24, s[7..10])) << 5; | 260 | t[2] = @as(u32, readIntSliceLittle(u24, s[7..10])) << 5; |
| 261 | t[3] = u32(readIntSliceLittle(u24, s[10..13])) << 3; | 261 | t[3] = @as(u32, readIntSliceLittle(u24, s[10..13])) << 3; |
| 262 | t[4] = u32(readIntSliceLittle(u24, s[13..16])) << 2; | 262 | t[4] = @as(u32, readIntSliceLittle(u24, s[13..16])) << 2; |
| 263 | t[5] = readIntSliceLittle(u32, s[16..20]); | 263 | t[5] = readIntSliceLittle(u32, s[16..20]); |
| 264 | t[6] = u32(readIntSliceLittle(u24, s[20..23])) << 7; | 264 | t[6] = @as(u32, readIntSliceLittle(u24, s[20..23])) << 7; |
| 265 | t[7] = u32(readIntSliceLittle(u24, s[23..26])) << 5; | 265 | t[7] = @as(u32, readIntSliceLittle(u24, s[23..26])) << 5; |
| 266 | t[8] = u32(readIntSliceLittle(u24, s[26..29])) << 4; | 266 | t[8] = @as(u32, readIntSliceLittle(u24, s[26..29])) << 4; |
| 267 | t[9] = (u32(readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2; | 267 | t[9] = (@as(u32, readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2; |
| 268 | 268 | ||
| 269 | carry1(h, t[0..]); | 269 | carry1(h, t[0..]); |
| 270 | } | 270 | } |
| ... | @@ -273,7 +273,7 @@ const Fe = struct { | ... | @@ -273,7 +273,7 @@ const Fe = struct { |
| 273 | var t: [10]i64 = undefined; | 273 | var t: [10]i64 = undefined; |
| 274 | 274 | ||
| 275 | for (t[0..]) |_, i| { | 275 | for (t[0..]) |_, i| { |
| 276 | t[i] = i64(f.b[i]) * g; | 276 | t[i] = @as(i64, f.b[i]) * g; |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | carry1(h, t[0..]); | 279 | carry1(h, t[0..]); |
| ... | @@ -305,16 +305,16 @@ const Fe = struct { | ... | @@ -305,16 +305,16 @@ const Fe = struct { |
| 305 | // t's become h | 305 | // t's become h |
| 306 | var t: [10]i64 = undefined; | 306 | var t: [10]i64 = undefined; |
| 307 | 307 | ||
| 308 | t[0] = f[0] * i64(g[0]) + F[1] * i64(G[9]) + f[2] * i64(G[8]) + F[3] * i64(G[7]) + f[4] * i64(G[6]) + F[5] * i64(G[5]) + f[6] * i64(G[4]) + F[7] * i64(G[3]) + f[8] * i64(G[2]) + F[9] * i64(G[1]); | 308 | t[0] = f[0] * @as(i64, g[0]) + F[1] * @as(i64, G[9]) + f[2] * @as(i64, G[8]) + F[3] * @as(i64, G[7]) + f[4] * @as(i64, G[6]) + F[5] * @as(i64, G[5]) + f[6] * @as(i64, G[4]) + F[7] * @as(i64, G[3]) + f[8] * @as(i64, G[2]) + F[9] * @as(i64, G[1]); |
| 309 | t[1] = f[0] * i64(g[1]) + f[1] * i64(g[0]) + f[2] * i64(G[9]) + f[3] * i64(G[8]) + f[4] * i64(G[7]) + f[5] * i64(G[6]) + f[6] * i64(G[5]) + f[7] * i64(G[4]) + f[8] * i64(G[3]) + f[9] * i64(G[2]); | 309 | t[1] = f[0] * @as(i64, g[1]) + f[1] * @as(i64, g[0]) + f[2] * @as(i64, G[9]) + f[3] * @as(i64, G[8]) + f[4] * @as(i64, G[7]) + f[5] * @as(i64, G[6]) + f[6] * @as(i64, G[5]) + f[7] * @as(i64, G[4]) + f[8] * @as(i64, G[3]) + f[9] * @as(i64, G[2]); |
| 310 | t[2] = f[0] * i64(g[2]) + F[1] * i64(g[1]) + f[2] * i64(g[0]) + F[3] * i64(G[9]) + f[4] * i64(G[8]) + F[5] * i64(G[7]) + f[6] * i64(G[6]) + F[7] * i64(G[5]) + f[8] * i64(G[4]) + F[9] * i64(G[3]); | 310 | t[2] = f[0] * @as(i64, g[2]) + F[1] * @as(i64, g[1]) + f[2] * @as(i64, g[0]) + F[3] * @as(i64, G[9]) + f[4] * @as(i64, G[8]) + F[5] * @as(i64, G[7]) + f[6] * @as(i64, G[6]) + F[7] * @as(i64, G[5]) + f[8] * @as(i64, G[4]) + F[9] * @as(i64, G[3]); |
| 311 | t[3] = f[0] * i64(g[3]) + f[1] * i64(g[2]) + f[2] * i64(g[1]) + f[3] * i64(g[0]) + f[4] * i64(G[9]) + f[5] * i64(G[8]) + f[6] * i64(G[7]) + f[7] * i64(G[6]) + f[8] * i64(G[5]) + f[9] * i64(G[4]); | 311 | t[3] = f[0] * @as(i64, g[3]) + f[1] * @as(i64, g[2]) + f[2] * @as(i64, g[1]) + f[3] * @as(i64, g[0]) + f[4] * @as(i64, G[9]) + f[5] * @as(i64, G[8]) + f[6] * @as(i64, G[7]) + f[7] * @as(i64, G[6]) + f[8] * @as(i64, G[5]) + f[9] * @as(i64, G[4]); |
| 312 | t[4] = f[0] * i64(g[4]) + F[1] * i64(g[3]) + f[2] * i64(g[2]) + F[3] * i64(g[1]) + f[4] * i64(g[0]) + F[5] * i64(G[9]) + f[6] * i64(G[8]) + F[7] * i64(G[7]) + f[8] * i64(G[6]) + F[9] * i64(G[5]); | 312 | t[4] = f[0] * @as(i64, g[4]) + F[1] * @as(i64, g[3]) + f[2] * @as(i64, g[2]) + F[3] * @as(i64, g[1]) + f[4] * @as(i64, g[0]) + F[5] * @as(i64, G[9]) + f[6] * @as(i64, G[8]) + F[7] * @as(i64, G[7]) + f[8] * @as(i64, G[6]) + F[9] * @as(i64, G[5]); |
| 313 | t[5] = f[0] * i64(g[5]) + f[1] * i64(g[4]) + f[2] * i64(g[3]) + f[3] * i64(g[2]) + f[4] * i64(g[1]) + f[5] * i64(g[0]) + f[6] * i64(G[9]) + f[7] * i64(G[8]) + f[8] * i64(G[7]) + f[9] * i64(G[6]); | 313 | t[5] = f[0] * @as(i64, g[5]) + f[1] * @as(i64, g[4]) + f[2] * @as(i64, g[3]) + f[3] * @as(i64, g[2]) + f[4] * @as(i64, g[1]) + f[5] * @as(i64, g[0]) + f[6] * @as(i64, G[9]) + f[7] * @as(i64, G[8]) + f[8] * @as(i64, G[7]) + f[9] * @as(i64, G[6]); |
| 314 | t[6] = f[0] * i64(g[6]) + F[1] * i64(g[5]) + f[2] * i64(g[4]) + F[3] * i64(g[3]) + f[4] * i64(g[2]) + F[5] * i64(g[1]) + f[6] * i64(g[0]) + F[7] * i64(G[9]) + f[8] * i64(G[8]) + F[9] * i64(G[7]); | 314 | t[6] = f[0] * @as(i64, g[6]) + F[1] * @as(i64, g[5]) + f[2] * @as(i64, g[4]) + F[3] * @as(i64, g[3]) + f[4] * @as(i64, g[2]) + F[5] * @as(i64, g[1]) + f[6] * @as(i64, g[0]) + F[7] * @as(i64, G[9]) + f[8] * @as(i64, G[8]) + F[9] * @as(i64, G[7]); |
| 315 | t[7] = f[0] * i64(g[7]) + f[1] * i64(g[6]) + f[2] * i64(g[5]) + f[3] * i64(g[4]) + f[4] * i64(g[3]) + f[5] * i64(g[2]) + f[6] * i64(g[1]) + f[7] * i64(g[0]) + f[8] * i64(G[9]) + f[9] * i64(G[8]); | 315 | t[7] = f[0] * @as(i64, g[7]) + f[1] * @as(i64, g[6]) + f[2] * @as(i64, g[5]) + f[3] * @as(i64, g[4]) + f[4] * @as(i64, g[3]) + f[5] * @as(i64, g[2]) + f[6] * @as(i64, g[1]) + f[7] * @as(i64, g[0]) + f[8] * @as(i64, G[9]) + f[9] * @as(i64, G[8]); |
| 316 | t[8] = f[0] * i64(g[8]) + F[1] * i64(g[7]) + f[2] * i64(g[6]) + F[3] * i64(g[5]) + f[4] * i64(g[4]) + F[5] * i64(g[3]) + f[6] * i64(g[2]) + F[7] * i64(g[1]) + f[8] * i64(g[0]) + F[9] * i64(G[9]); | 316 | t[8] = f[0] * @as(i64, g[8]) + F[1] * @as(i64, g[7]) + f[2] * @as(i64, g[6]) + F[3] * @as(i64, g[5]) + f[4] * @as(i64, g[4]) + F[5] * @as(i64, g[3]) + f[6] * @as(i64, g[2]) + F[7] * @as(i64, g[1]) + f[8] * @as(i64, g[0]) + F[9] * @as(i64, G[9]); |
| 317 | t[9] = f[0] * i64(g[9]) + f[1] * i64(g[8]) + f[2] * i64(g[7]) + f[3] * i64(g[6]) + f[4] * i64(g[5]) + f[5] * i64(g[4]) + f[6] * i64(g[3]) + f[7] * i64(g[2]) + f[8] * i64(g[1]) + f[9] * i64(g[0]); | 317 | t[9] = f[0] * @as(i64, g[9]) + f[1] * @as(i64, g[8]) + f[2] * @as(i64, g[7]) + f[3] * @as(i64, g[6]) + f[4] * @as(i64, g[5]) + f[5] * @as(i64, g[4]) + f[6] * @as(i64, g[3]) + f[7] * @as(i64, g[2]) + f[8] * @as(i64, g[1]) + f[9] * @as(i64, g[0]); |
| 318 | 318 | ||
| 319 | carry2(h, t[0..]); | 319 | carry2(h, t[0..]); |
| 320 | } | 320 | } |
| ... | @@ -348,16 +348,16 @@ const Fe = struct { | ... | @@ -348,16 +348,16 @@ const Fe = struct { |
| 348 | 348 | ||
| 349 | var t: [10]i64 = undefined; | 349 | var t: [10]i64 = undefined; |
| 350 | 350 | ||
| 351 | t[0] = f0 * i64(f0) + f1_2 * i64(f9_38) + f2_2 * i64(f8_19) + f3_2 * i64(f7_38) + f4_2 * i64(f6_19) + f5 * i64(f5_38); | 351 | t[0] = f0 * @as(i64, f0) + f1_2 * @as(i64, f9_38) + f2_2 * @as(i64, f8_19) + f3_2 * @as(i64, f7_38) + f4_2 * @as(i64, f6_19) + f5 * @as(i64, f5_38); |
| 352 | t[1] = f0_2 * i64(f1) + f2 * i64(f9_38) + f3_2 * i64(f8_19) + f4 * i64(f7_38) + f5_2 * i64(f6_19); | 352 | t[1] = f0_2 * @as(i64, f1) + f2 * @as(i64, f9_38) + f3_2 * @as(i64, f8_19) + f4 * @as(i64, f7_38) + f5_2 * @as(i64, f6_19); |
| 353 | t[2] = f0_2 * i64(f2) + f1_2 * i64(f1) + f3_2 * i64(f9_38) + f4_2 * i64(f8_19) + f5_2 * i64(f7_38) + f6 * i64(f6_19); | 353 | t[2] = f0_2 * @as(i64, f2) + f1_2 * @as(i64, f1) + f3_2 * @as(i64, f9_38) + f4_2 * @as(i64, f8_19) + f5_2 * @as(i64, f7_38) + f6 * @as(i64, f6_19); |
| 354 | t[3] = f0_2 * i64(f3) + f1_2 * i64(f2) + f4 * i64(f9_38) + f5_2 * i64(f8_19) + f6 * i64(f7_38); | 354 | t[3] = f0_2 * @as(i64, f3) + f1_2 * @as(i64, f2) + f4 * @as(i64, f9_38) + f5_2 * @as(i64, f8_19) + f6 * @as(i64, f7_38); |
| 355 | t[4] = f0_2 * i64(f4) + f1_2 * i64(f3_2) + f2 * i64(f2) + f5_2 * i64(f9_38) + f6_2 * i64(f8_19) + f7 * i64(f7_38); | 355 | t[4] = f0_2 * @as(i64, f4) + f1_2 * @as(i64, f3_2) + f2 * @as(i64, f2) + f5_2 * @as(i64, f9_38) + f6_2 * @as(i64, f8_19) + f7 * @as(i64, f7_38); |
| 356 | t[5] = f0_2 * i64(f5) + f1_2 * i64(f4) + f2_2 * i64(f3) + f6 * i64(f9_38) + f7_2 * i64(f8_19); | 356 | t[5] = f0_2 * @as(i64, f5) + f1_2 * @as(i64, f4) + f2_2 * @as(i64, f3) + f6 * @as(i64, f9_38) + f7_2 * @as(i64, f8_19); |
| 357 | t[6] = f0_2 * i64(f6) + f1_2 * i64(f5_2) + f2_2 * i64(f4) + f3_2 * i64(f3) + f7_2 * i64(f9_38) + f8 * i64(f8_19); | 357 | t[6] = f0_2 * @as(i64, f6) + f1_2 * @as(i64, f5_2) + f2_2 * @as(i64, f4) + f3_2 * @as(i64, f3) + f7_2 * @as(i64, f9_38) + f8 * @as(i64, f8_19); |
| 358 | t[7] = f0_2 * i64(f7) + f1_2 * i64(f6) + f2_2 * i64(f5) + f3_2 * i64(f4) + f8 * i64(f9_38); | 358 | t[7] = f0_2 * @as(i64, f7) + f1_2 * @as(i64, f6) + f2_2 * @as(i64, f5) + f3_2 * @as(i64, f4) + f8 * @as(i64, f9_38); |
| 359 | t[8] = f0_2 * i64(f8) + f1_2 * i64(f7_2) + f2_2 * i64(f6) + f3_2 * i64(f5_2) + f4 * i64(f4) + f9 * i64(f9_38); | 359 | t[8] = f0_2 * @as(i64, f8) + f1_2 * @as(i64, f7_2) + f2_2 * @as(i64, f6) + f3_2 * @as(i64, f5_2) + f4 * @as(i64, f4) + f9 * @as(i64, f9_38); |
| 360 | t[9] = f0_2 * i64(f9) + f1_2 * i64(f8) + f2_2 * i64(f7) + f3_2 * i64(f6) + f4 * i64(f5_2); | 360 | t[9] = f0_2 * @as(i64, f9) + f1_2 * @as(i64, f8) + f2_2 * @as(i64, f7) + f3_2 * @as(i64, f6) + f4 * @as(i64, f5_2); |
| 361 | 361 | ||
| 362 | carry2(h, t[0..]); | 362 | carry2(h, t[0..]); |
| 363 | } | 363 | } |
| ... | @@ -500,7 +500,7 @@ const Fe = struct { | ... | @@ -500,7 +500,7 @@ const Fe = struct { |
| 500 | if (i + 1 < 10) { | 500 | if (i + 1 < 10) { |
| 501 | t[i + 1] += c[i]; | 501 | t[i + 1] += c[i]; |
| 502 | } | 502 | } |
| 503 | t[i] -= c[i] * (i32(1) << shift); | 503 | t[i] -= c[i] * (@as(i32, 1) << shift); |
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | fn toBytes(s: []u8, h: *const Fe) void { | 506 | fn toBytes(s: []u8, h: *const Fe) void { |
| ... | @@ -511,7 +511,7 @@ const Fe = struct { | ... | @@ -511,7 +511,7 @@ const Fe = struct { |
| 511 | t[i] = h.b[i]; | 511 | t[i] = h.b[i]; |
| 512 | } | 512 | } |
| 513 | 513 | ||
| 514 | var q = (19 * t[9] + ((i32(1) << 24))) >> 25; | 514 | var q = (19 * t[9] + ((@as(i32, 1) << 24))) >> 25; |
| 515 | { | 515 | { |
| 516 | var i: usize = 0; | 516 | var i: usize = 0; |
| 517 | while (i < 5) : (i += 1) { | 517 | while (i < 5) : (i += 1) { |
lib/std/debug.zig+13-10| ... | @@ -1008,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize { | ... | @@ -1008,7 +1008,7 @@ fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize { |
| 1008 | const word = try stream.readIntLittle(u32); | 1008 | const word = try stream.readIntLittle(u32); |
| 1009 | var bit_i: u5 = 0; | 1009 | var bit_i: u5 = 0; |
| 1010 | while (true) : (bit_i += 1) { | 1010 | while (true) : (bit_i += 1) { |
| 1011 | if (word & (u32(1) << bit_i) != 0) { | 1011 | if (word & (@as(u32, 1) << bit_i) != 0) { |
| 1012 | try list.append(word_i * 32 + bit_i); | 1012 | try list.append(word_i * 32 + bit_i); |
| 1013 | } | 1013 | } |
| 1014 | if (bit_i == maxInt(u5)) break; | 1014 | if (bit_i == maxInt(u5)) break; |
| ... | @@ -1556,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo | ... | @@ -1556,13 +1556,14 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo |
| 1556 | 1556 | ||
| 1557 | // TODO the noasyncs here are workarounds | 1557 | // TODO the noasyncs here are workarounds |
| 1558 | fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 { | 1558 | fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 { |
| 1559 | return if (is_64) try noasync in_stream.readIntLittle(u64) else u64(try noasync in_stream.readIntLittle(u32)); | 1559 | return if (is_64) try noasync in_stream.readIntLittle(u64) else @as(u64, try noasync in_stream.readIntLittle(u32)); |
| 1560 | } | 1560 | } |
| 1561 | 1561 | ||
| 1562 | // TODO the noasyncs here are workarounds | 1562 | // TODO the noasyncs here are workarounds |
| 1563 | fn parseFormValueTargetAddrSize(in_stream: var) !u64 { | 1563 | fn parseFormValueTargetAddrSize(in_stream: var) !u64 { |
| 1564 | if (@sizeOf(usize) == 4) { | 1564 | if (@sizeOf(usize) == 4) { |
| 1565 | return u64(try noasync in_stream.readIntLittle(u32)); | 1565 | // TODO this cast should not be needed |
| 1566 | return @as(u64, try noasync in_stream.readIntLittle(u32)); | ||
| 1566 | } else if (@sizeOf(usize) == 8) { | 1567 | } else if (@sizeOf(usize) == 8) { |
| 1567 | return noasync in_stream.readIntLittle(u64); | 1568 | return noasync in_stream.readIntLittle(u64); |
| 1568 | } else { | 1569 | } else { |
| ... | @@ -1846,7 +1847,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u | ... | @@ -1846,7 +1847,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u |
| 1846 | // special opcodes | 1847 | // special opcodes |
| 1847 | const adjusted_opcode = opcode - opcode_base; | 1848 | const adjusted_opcode = opcode - opcode_base; |
| 1848 | const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range); | 1849 | const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range); |
| 1849 | const inc_line = i32(line_base) + i32(adjusted_opcode % line_range); | 1850 | const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range); |
| 1850 | prog.line += inc_line; | 1851 | prog.line += inc_line; |
| 1851 | prog.address += inc_addr; | 1852 | prog.address += inc_addr; |
| 1852 | if (try prog.checkLineMatch()) |info| return info; | 1853 | if (try prog.checkLineMatch()) |info| return info; |
| ... | @@ -1913,7 +1914,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr | ... | @@ -1913,7 +1914,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr |
| 1913 | if (unit_length == 0) { | 1914 | if (unit_length == 0) { |
| 1914 | return error.MissingDebugInfo; | 1915 | return error.MissingDebugInfo; |
| 1915 | } | 1916 | } |
| 1916 | const next_offset = unit_length + (if (is_64) usize(12) else usize(4)); | 1917 | const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); |
| 1917 | 1918 | ||
| 1918 | const version = try di.dwarf_in_stream.readInt(u16, di.endian); | 1919 | const version = try di.dwarf_in_stream.readInt(u16, di.endian); |
| 1919 | // TODO support 3 and 5 | 1920 | // TODO support 3 and 5 |
| ... | @@ -2012,7 +2013,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr | ... | @@ -2012,7 +2013,7 @@ fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit: CompileUnit, target_addr |
| 2012 | // special opcodes | 2013 | // special opcodes |
| 2013 | const adjusted_opcode = opcode - opcode_base; | 2014 | const adjusted_opcode = opcode - opcode_base; |
| 2014 | const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range); | 2015 | const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range); |
| 2015 | const inc_line = i32(line_base) + i32(adjusted_opcode % line_range); | 2016 | const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range); |
| 2016 | prog.line += inc_line; | 2017 | prog.line += inc_line; |
| 2017 | prog.address += inc_addr; | 2018 | prog.address += inc_addr; |
| 2018 | if (try prog.checkLineMatch()) |info| return info; | 2019 | if (try prog.checkLineMatch()) |info| return info; |
| ... | @@ -2093,7 +2094,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void { | ... | @@ -2093,7 +2094,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void { |
| 2093 | var is_64: bool = undefined; | 2094 | var is_64: bool = undefined; |
| 2094 | const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); | 2095 | const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); |
| 2095 | if (unit_length == 0) return; | 2096 | if (unit_length == 0) return; |
| 2096 | const next_offset = unit_length + (if (is_64) usize(12) else usize(4)); | 2097 | const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); |
| 2097 | 2098 | ||
| 2098 | const version = try di.dwarf_in_stream.readInt(u16, di.endian); | 2099 | const version = try di.dwarf_in_stream.readInt(u16, di.endian); |
| 2099 | if (version < 2 or version > 5) return error.InvalidDebugInfo; | 2100 | if (version < 2 or version > 5) return error.InvalidDebugInfo; |
| ... | @@ -2195,7 +2196,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void { | ... | @@ -2195,7 +2196,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void { |
| 2195 | var is_64: bool = undefined; | 2196 | var is_64: bool = undefined; |
| 2196 | const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); | 2197 | const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); |
| 2197 | if (unit_length == 0) return; | 2198 | if (unit_length == 0) return; |
| 2198 | const next_offset = unit_length + (if (is_64) usize(12) else usize(4)); | 2199 | const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); |
| 2199 | 2200 | ||
| 2200 | const version = try di.dwarf_in_stream.readInt(u16, di.endian); | 2201 | const version = try di.dwarf_in_stream.readInt(u16, di.endian); |
| 2201 | if (version < 2 or version > 5) return error.InvalidDebugInfo; | 2202 | if (version < 2 or version > 5) return error.InvalidDebugInfo; |
| ... | @@ -2312,7 +2313,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 { | ... | @@ -2312,7 +2313,8 @@ fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 { |
| 2312 | } else { | 2313 | } else { |
| 2313 | if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo; | 2314 | if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo; |
| 2314 | ptr.* += 4; | 2315 | ptr.* += 4; |
| 2315 | return u64(first_32_bits); | 2316 | // TODO this cast should not be needed |
| 2317 | return @as(u64, first_32_bits); | ||
| 2316 | } | 2318 | } |
| 2317 | } | 2319 | } |
| 2318 | 2320 | ||
| ... | @@ -2329,7 +2331,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool) | ... | @@ -2329,7 +2331,8 @@ fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool) |
| 2329 | return in_stream.readIntLittle(u64); | 2331 | return in_stream.readIntLittle(u64); |
| 2330 | } else { | 2332 | } else { |
| 2331 | if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo; | 2333 | if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo; |
| 2332 | return u64(first_32_bits); | 2334 | // TODO this cast should not be needed |
| 2335 | return @as(u64, first_32_bits); | ||
| 2333 | } | 2336 | } |
| 2334 | } | 2337 | } |
| 2335 | 2338 |
lib/std/debug/leb128.zig+3-3| ... | @@ -62,13 +62,13 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T { | ... | @@ -62,13 +62,13 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T { |
| 62 | var shift: usize = 0; | 62 | var shift: usize = 0; |
| 63 | 63 | ||
| 64 | while (true) { | 64 | while (true) { |
| 65 | const byte = u8(try in_stream.readByte()); | 65 | const byte: u8 = try in_stream.readByte(); |
| 66 | 66 | ||
| 67 | if (shift > T.bit_count) | 67 | if (shift > T.bit_count) |
| 68 | return error.Overflow; | 68 | return error.Overflow; |
| 69 | 69 | ||
| 70 | var operand: UT = undefined; | 70 | var operand: UT = undefined; |
| 71 | if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) { | 71 | if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) { |
| 72 | if (byte != 0x7f) | 72 | if (byte != 0x7f) |
| 73 | return error.Overflow; | 73 | return error.Overflow; |
| 74 | } | 74 | } |
| ... | @@ -101,7 +101,7 @@ pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T { | ... | @@ -101,7 +101,7 @@ pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T { |
| 101 | return error.Overflow; | 101 | return error.Overflow; |
| 102 | 102 | ||
| 103 | var operand: UT = undefined; | 103 | var operand: UT = undefined; |
| 104 | if (@shlWithOverflow(UT, UT(byte & 0x7f), @intCast(ShiftT, shift), &operand)) { | 104 | if (@shlWithOverflow(UT, @as(UT, byte & 0x7f), @intCast(ShiftT, shift), &operand)) { |
| 105 | if (byte != 0x7f) | 105 | if (byte != 0x7f) |
| 106 | return error.Overflow; | 106 | return error.Overflow; |
| 107 | } | 107 | } |
lib/std/dynamic_library.zig+2-2| ... | @@ -215,8 +215,8 @@ pub const ElfLib = struct { | ... | @@ -215,8 +215,8 @@ pub const ElfLib = struct { |
| 215 | 215 | ||
| 216 | var i: usize = 0; | 216 | var i: usize = 0; |
| 217 | while (i < self.hashtab[1]) : (i += 1) { | 217 | while (i < self.hashtab[1]) : (i += 1) { |
| 218 | if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue; | 218 | if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue; |
| 219 | if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue; | 219 | if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue; |
| 220 | if (0 == self.syms[i].st_shndx) continue; | 220 | if (0 == self.syms[i].st_shndx) continue; |
| 221 | if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue; | 221 | if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue; |
| 222 | if (maybe_versym) |versym| { | 222 | if (maybe_versym) |versym| { |
lib/std/elf.zig+12-12| ... | @@ -441,9 +441,9 @@ pub const Elf = struct { | ... | @@ -441,9 +441,9 @@ pub const Elf = struct { |
| 441 | elf.program_header_offset = try in.readInt(u64, elf.endian); | 441 | elf.program_header_offset = try in.readInt(u64, elf.endian); |
| 442 | elf.section_header_offset = try in.readInt(u64, elf.endian); | 442 | elf.section_header_offset = try in.readInt(u64, elf.endian); |
| 443 | } else { | 443 | } else { |
| 444 | elf.entry_addr = u64(try in.readInt(u32, elf.endian)); | 444 | elf.entry_addr = @as(u64, try in.readInt(u32, elf.endian)); |
| 445 | elf.program_header_offset = u64(try in.readInt(u32, elf.endian)); | 445 | elf.program_header_offset = @as(u64, try in.readInt(u32, elf.endian)); |
| 446 | elf.section_header_offset = u64(try in.readInt(u32, elf.endian)); | 446 | elf.section_header_offset = @as(u64, try in.readInt(u32, elf.endian)); |
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | // skip over flags | 449 | // skip over flags |
| ... | @@ -458,13 +458,13 @@ pub const Elf = struct { | ... | @@ -458,13 +458,13 @@ pub const Elf = struct { |
| 458 | const ph_entry_count = try in.readInt(u16, elf.endian); | 458 | const ph_entry_count = try in.readInt(u16, elf.endian); |
| 459 | const sh_entry_size = try in.readInt(u16, elf.endian); | 459 | const sh_entry_size = try in.readInt(u16, elf.endian); |
| 460 | const sh_entry_count = try in.readInt(u16, elf.endian); | 460 | const sh_entry_count = try in.readInt(u16, elf.endian); |
| 461 | elf.string_section_index = usize(try in.readInt(u16, elf.endian)); | 461 | elf.string_section_index = @as(usize, try in.readInt(u16, elf.endian)); |
| 462 | 462 | ||
| 463 | if (elf.string_section_index >= sh_entry_count) return error.InvalidFormat; | 463 | if (elf.string_section_index >= sh_entry_count) return error.InvalidFormat; |
| 464 | 464 | ||
| 465 | const sh_byte_count = u64(sh_entry_size) * u64(sh_entry_count); | 465 | const sh_byte_count = @as(u64, sh_entry_size) * @as(u64, sh_entry_count); |
| 466 | const end_sh = try math.add(u64, elf.section_header_offset, sh_byte_count); | 466 | const end_sh = try math.add(u64, elf.section_header_offset, sh_byte_count); |
| 467 | const ph_byte_count = u64(ph_entry_size) * u64(ph_entry_count); | 467 | const ph_byte_count = @as(u64, ph_entry_size) * @as(u64, ph_entry_count); |
| 468 | const end_ph = try math.add(u64, elf.program_header_offset, ph_byte_count); | 468 | const end_ph = try math.add(u64, elf.program_header_offset, ph_byte_count); |
| 469 | 469 | ||
| 470 | const stream_end = try seekable_stream.getEndPos(); | 470 | const stream_end = try seekable_stream.getEndPos(); |
| ... | @@ -499,14 +499,14 @@ pub const Elf = struct { | ... | @@ -499,14 +499,14 @@ pub const Elf = struct { |
| 499 | // TODO (multiple occurrences) allow implicit cast from %u32 -> %u64 ? | 499 | // TODO (multiple occurrences) allow implicit cast from %u32 -> %u64 ? |
| 500 | elf_section.name = try in.readInt(u32, elf.endian); | 500 | elf_section.name = try in.readInt(u32, elf.endian); |
| 501 | elf_section.sh_type = try in.readInt(u32, elf.endian); | 501 | elf_section.sh_type = try in.readInt(u32, elf.endian); |
| 502 | elf_section.flags = u64(try in.readInt(u32, elf.endian)); | 502 | elf_section.flags = @as(u64, try in.readInt(u32, elf.endian)); |
| 503 | elf_section.addr = u64(try in.readInt(u32, elf.endian)); | 503 | elf_section.addr = @as(u64, try in.readInt(u32, elf.endian)); |
| 504 | elf_section.offset = u64(try in.readInt(u32, elf.endian)); | 504 | elf_section.offset = @as(u64, try in.readInt(u32, elf.endian)); |
| 505 | elf_section.size = u64(try in.readInt(u32, elf.endian)); | 505 | elf_section.size = @as(u64, try in.readInt(u32, elf.endian)); |
| 506 | elf_section.link = try in.readInt(u32, elf.endian); | 506 | elf_section.link = try in.readInt(u32, elf.endian); |
| 507 | elf_section.info = try in.readInt(u32, elf.endian); | 507 | elf_section.info = try in.readInt(u32, elf.endian); |
| 508 | elf_section.addr_align = u64(try in.readInt(u32, elf.endian)); | 508 | elf_section.addr_align = @as(u64, try in.readInt(u32, elf.endian)); |
| 509 | elf_section.ent_size = u64(try in.readInt(u32, elf.endian)); | 509 | elf_section.ent_size = @as(u64, try in.readInt(u32, elf.endian)); |
| 510 | } | 510 | } |
| 511 | } | 511 | } |
| 512 | 512 |
lib/std/event/fs.zig+2-2| ... | @@ -328,11 +328,11 @@ pub fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize { | ... | @@ -328,11 +328,11 @@ pub fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize { |
| 328 | windows.ERROR.IO_PENDING => unreachable, | 328 | windows.ERROR.IO_PENDING => unreachable, |
| 329 | windows.ERROR.OPERATION_ABORTED => return error.OperationAborted, | 329 | windows.ERROR.OPERATION_ABORTED => return error.OperationAborted, |
| 330 | windows.ERROR.BROKEN_PIPE => return error.BrokenPipe, | 330 | windows.ERROR.BROKEN_PIPE => return error.BrokenPipe, |
| 331 | windows.ERROR.HANDLE_EOF => return usize(bytes_transferred), | 331 | windows.ERROR.HANDLE_EOF => return @as(usize, bytes_transferred), |
| 332 | else => |err| return windows.unexpectedError(err), | 332 | else => |err| return windows.unexpectedError(err), |
| 333 | } | 333 | } |
| 334 | } | 334 | } |
| 335 | return usize(bytes_transferred); | 335 | return @as(usize, bytes_transferred); |
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | /// iovecs must live until preadv frame completes | 338 | /// iovecs must live until preadv frame completes |
lib/std/event/loop.zig+11-11| ... | @@ -266,7 +266,7 @@ pub const Loop = struct { | ... | @@ -266,7 +266,7 @@ pub const Loop = struct { |
| 266 | }, | 266 | }, |
| 267 | }; | 267 | }; |
| 268 | 268 | ||
| 269 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; | 269 | const empty_kevs = &[0]os.Kevent{}; |
| 270 | 270 | ||
| 271 | for (self.eventfd_resume_nodes) |*eventfd_node, i| { | 271 | for (self.eventfd_resume_nodes) |*eventfd_node, i| { |
| 272 | eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{ | 272 | eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{ |
| ... | @@ -289,7 +289,7 @@ pub const Loop = struct { | ... | @@ -289,7 +289,7 @@ pub const Loop = struct { |
| 289 | .next = undefined, | 289 | .next = undefined, |
| 290 | }; | 290 | }; |
| 291 | self.available_eventfd_resume_nodes.push(eventfd_node); | 291 | self.available_eventfd_resume_nodes.push(eventfd_node); |
| 292 | const kevent_array = (*const [1]os.Kevent)(&eventfd_node.data.kevent); | 292 | const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.data.kevent); |
| 293 | _ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null); | 293 | _ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null); |
| 294 | eventfd_node.data.kevent.flags = os.EV_CLEAR | os.EV_ENABLE; | 294 | eventfd_node.data.kevent.flags = os.EV_CLEAR | os.EV_ENABLE; |
| 295 | eventfd_node.data.kevent.fflags = os.NOTE_TRIGGER; | 295 | eventfd_node.data.kevent.fflags = os.NOTE_TRIGGER; |
| ... | @@ -305,7 +305,7 @@ pub const Loop = struct { | ... | @@ -305,7 +305,7 @@ pub const Loop = struct { |
| 305 | .data = 0, | 305 | .data = 0, |
| 306 | .udata = @ptrToInt(&self.final_resume_node), | 306 | .udata = @ptrToInt(&self.final_resume_node), |
| 307 | }; | 307 | }; |
| 308 | const final_kev_arr = (*const [1]os.Kevent)(&self.os_data.final_kevent); | 308 | const final_kev_arr = @as(*const [1]os.Kevent, &self.os_data.final_kevent); |
| 309 | _ = try os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null); | 309 | _ = try os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null); |
| 310 | self.os_data.final_kevent.flags = os.EV_ENABLE; | 310 | self.os_data.final_kevent.flags = os.EV_ENABLE; |
| 311 | self.os_data.final_kevent.fflags = os.NOTE_TRIGGER; | 311 | self.os_data.final_kevent.fflags = os.NOTE_TRIGGER; |
| ... | @@ -572,8 +572,8 @@ pub const Loop = struct { | ... | @@ -572,8 +572,8 @@ pub const Loop = struct { |
| 572 | eventfd_node.base.handle = next_tick_node.data; | 572 | eventfd_node.base.handle = next_tick_node.data; |
| 573 | switch (builtin.os) { | 573 | switch (builtin.os) { |
| 574 | .macosx, .freebsd, .netbsd, .dragonfly => { | 574 | .macosx, .freebsd, .netbsd, .dragonfly => { |
| 575 | const kevent_array = (*const [1]os.Kevent)(&eventfd_node.kevent); | 575 | const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.kevent); |
| 576 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; | 576 | const empty_kevs = &[0]os.Kevent{}; |
| 577 | _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { | 577 | _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { |
| 578 | self.next_tick_queue.unget(next_tick_node); | 578 | self.next_tick_queue.unget(next_tick_node); |
| 579 | self.available_eventfd_resume_nodes.push(resume_stack_node); | 579 | self.available_eventfd_resume_nodes.push(resume_stack_node); |
| ... | @@ -695,8 +695,8 @@ pub const Loop = struct { | ... | @@ -695,8 +695,8 @@ pub const Loop = struct { |
| 695 | }, | 695 | }, |
| 696 | .macosx, .freebsd, .netbsd, .dragonfly => { | 696 | .macosx, .freebsd, .netbsd, .dragonfly => { |
| 697 | self.posixFsRequest(&self.os_data.fs_end_request); | 697 | self.posixFsRequest(&self.os_data.fs_end_request); |
| 698 | const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent); | 698 | const final_kevent = @as(*const [1]os.Kevent, &self.os_data.final_kevent); |
| 699 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; | 699 | const empty_kevs = &[0]os.Kevent{}; |
| 700 | // cannot fail because we already added it and this just enables it | 700 | // cannot fail because we already added it and this just enables it |
| 701 | _ = os.kevent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable; | 701 | _ = os.kevent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable; |
| 702 | return; | 702 | return; |
| ... | @@ -753,7 +753,7 @@ pub const Loop = struct { | ... | @@ -753,7 +753,7 @@ pub const Loop = struct { |
| 753 | }, | 753 | }, |
| 754 | .macosx, .freebsd, .netbsd, .dragonfly => { | 754 | .macosx, .freebsd, .netbsd, .dragonfly => { |
| 755 | var eventlist: [1]os.Kevent = undefined; | 755 | var eventlist: [1]os.Kevent = undefined; |
| 756 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; | 756 | const empty_kevs = &[0]os.Kevent{}; |
| 757 | const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; | 757 | const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; |
| 758 | for (eventlist[0..count]) |ev| { | 758 | for (eventlist[0..count]) |ev| { |
| 759 | const resume_node = @intToPtr(*ResumeNode, ev.udata); | 759 | const resume_node = @intToPtr(*ResumeNode, ev.udata); |
| ... | @@ -815,8 +815,8 @@ pub const Loop = struct { | ... | @@ -815,8 +815,8 @@ pub const Loop = struct { |
| 815 | self.os_data.fs_queue.put(request_node); | 815 | self.os_data.fs_queue.put(request_node); |
| 816 | switch (builtin.os) { | 816 | switch (builtin.os) { |
| 817 | .macosx, .freebsd, .netbsd, .dragonfly => { | 817 | .macosx, .freebsd, .netbsd, .dragonfly => { |
| 818 | const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wake); | 818 | const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wake); |
| 819 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; | 819 | const empty_kevs = &[0]os.Kevent{}; |
| 820 | _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; | 820 | _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; |
| 821 | }, | 821 | }, |
| 822 | .linux => { | 822 | .linux => { |
| ... | @@ -890,7 +890,7 @@ pub const Loop = struct { | ... | @@ -890,7 +890,7 @@ pub const Loop = struct { |
| 890 | } | 890 | } |
| 891 | }, | 891 | }, |
| 892 | .macosx, .freebsd, .netbsd, .dragonfly => { | 892 | .macosx, .freebsd, .netbsd, .dragonfly => { |
| 893 | const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wait); | 893 | const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wait); |
| 894 | var out_kevs: [1]os.Kevent = undefined; | 894 | var out_kevs: [1]os.Kevent = undefined; |
| 895 | _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; | 895 | _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; |
| 896 | }, | 896 | }, |
lib/std/fifo.zig+13-13| ... | @@ -257,7 +257,7 @@ test "ByteFifo" { | ... | @@ -257,7 +257,7 @@ test "ByteFifo" { |
| 257 | defer fifo.deinit(); | 257 | defer fifo.deinit(); |
| 258 | 258 | ||
| 259 | try fifo.write("HELLO"); | 259 | try fifo.write("HELLO"); |
| 260 | testing.expectEqual(usize(5), fifo.readableLength()); | 260 | testing.expectEqual(@as(usize, 5), fifo.readableLength()); |
| 261 | testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0)); | 261 | testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0)); |
| 262 | 262 | ||
| 263 | { | 263 | { |
| ... | @@ -265,34 +265,34 @@ test "ByteFifo" { | ... | @@ -265,34 +265,34 @@ test "ByteFifo" { |
| 265 | while (i < 5) : (i += 1) { | 265 | while (i < 5) : (i += 1) { |
| 266 | try fifo.write([_]u8{try fifo.peekItem(i)}); | 266 | try fifo.write([_]u8{try fifo.peekItem(i)}); |
| 267 | } | 267 | } |
| 268 | testing.expectEqual(usize(10), fifo.readableLength()); | 268 | testing.expectEqual(@as(usize, 10), fifo.readableLength()); |
| 269 | testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0)); | 269 | testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0)); |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | { | 272 | { |
| 273 | testing.expectEqual(u8('H'), try fifo.readItem()); | 273 | testing.expectEqual(@as(u8, 'H'), try fifo.readItem()); |
| 274 | testing.expectEqual(u8('E'), try fifo.readItem()); | 274 | testing.expectEqual(@as(u8, 'E'), try fifo.readItem()); |
| 275 | testing.expectEqual(u8('L'), try fifo.readItem()); | 275 | testing.expectEqual(@as(u8, 'L'), try fifo.readItem()); |
| 276 | testing.expectEqual(u8('L'), try fifo.readItem()); | 276 | testing.expectEqual(@as(u8, 'L'), try fifo.readItem()); |
| 277 | testing.expectEqual(u8('O'), try fifo.readItem()); | 277 | testing.expectEqual(@as(u8, 'O'), try fifo.readItem()); |
| 278 | } | 278 | } |
| 279 | testing.expectEqual(usize(5), fifo.readableLength()); | 279 | testing.expectEqual(@as(usize, 5), fifo.readableLength()); |
| 280 | 280 | ||
| 281 | { // Writes that wrap around | 281 | { // Writes that wrap around |
| 282 | testing.expectEqual(usize(11), fifo.writableLength()); | 282 | testing.expectEqual(@as(usize, 11), fifo.writableLength()); |
| 283 | testing.expectEqual(usize(6), fifo.writableSlice(0).len); | 283 | testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len); |
| 284 | fifo.writeAssumeCapacity("6<chars<11"); | 284 | fifo.writeAssumeCapacity("6<chars<11"); |
| 285 | testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0)); | 285 | testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0)); |
| 286 | testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11)); | 286 | testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11)); |
| 287 | fifo.discard(11); | 287 | fifo.discard(11); |
| 288 | testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0)); | 288 | testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0)); |
| 289 | fifo.discard(4); | 289 | fifo.discard(4); |
| 290 | testing.expectEqual(usize(0), fifo.readableLength()); | 290 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | { | 293 | { |
| 294 | const buf = try fifo.writeableWithSize(12); | 294 | const buf = try fifo.writeableWithSize(12); |
| 295 | testing.expectEqual(usize(12), buf.len); | 295 | testing.expectEqual(@as(usize, 12), buf.len); |
| 296 | var i: u8 = 0; | 296 | var i: u8 = 0; |
| 297 | while (i < 10) : (i += 1) { | 297 | while (i < 10) : (i += 1) { |
| 298 | buf[i] = i + 'a'; | 298 | buf[i] = i + 'a'; |
| ... | @@ -313,6 +313,6 @@ test "ByteFifo" { | ... | @@ -313,6 +313,6 @@ test "ByteFifo" { |
| 313 | try fifo.print("{}, {}!", "Hello", "World"); | 313 | try fifo.print("{}, {}!", "Hello", "World"); |
| 314 | var result: [30]u8 = undefined; | 314 | var result: [30]u8 = undefined; |
| 315 | testing.expectEqualSlices(u8, "Hello, World!", fifo.read(&result)); | 315 | testing.expectEqualSlices(u8, "Hello, World!", fifo.read(&result)); |
| 316 | testing.expectEqual(usize(0), fifo.readableLength()); | 316 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); |
| 317 | } | 317 | } |
| 318 | } | 318 | } |
lib/std/fmt.zig+62-62| ... | @@ -382,10 +382,10 @@ pub fn formatType( | ... | @@ -382,10 +382,10 @@ pub fn formatType( |
| 382 | const info = @typeInfo(T).Union; | 382 | const info = @typeInfo(T).Union; |
| 383 | if (info.tag_type) |UnionTagType| { | 383 | if (info.tag_type) |UnionTagType| { |
| 384 | try output(context, "{ ."); | 384 | try output(context, "{ ."); |
| 385 | try output(context, @tagName(UnionTagType(value))); | 385 | try output(context, @tagName(@as(UnionTagType, value))); |
| 386 | try output(context, " = "); | 386 | try output(context, " = "); |
| 387 | inline for (info.fields) |u_field| { | 387 | inline for (info.fields) |u_field| { |
| 388 | if (@enumToInt(UnionTagType(value)) == u_field.enum_field.?.value) { | 388 | if (@enumToInt(@as(UnionTagType, value)) == u_field.enum_field.?.value) { |
| 389 | try formatType(@field(value, u_field.name), "", options, context, Errors, output, max_depth - 1); | 389 | try formatType(@field(value, u_field.name), "", options, context, Errors, output, max_depth - 1); |
| 390 | } | 390 | } |
| 391 | } | 391 | } |
| ... | @@ -503,7 +503,7 @@ pub fn formatIntValue( | ... | @@ -503,7 +503,7 @@ pub fn formatIntValue( |
| 503 | 503 | ||
| 504 | const int_value = if (@typeOf(value) == comptime_int) blk: { | 504 | const int_value = if (@typeOf(value) == comptime_int) blk: { |
| 505 | const Int = math.IntFittingRange(value, value); | 505 | const Int = math.IntFittingRange(value, value); |
| 506 | break :blk Int(value); | 506 | break :blk @as(Int, value); |
| 507 | } else | 507 | } else |
| 508 | value; | 508 | value; |
| 509 | 509 | ||
| ... | @@ -512,7 +512,7 @@ pub fn formatIntValue( | ... | @@ -512,7 +512,7 @@ pub fn formatIntValue( |
| 512 | uppercase = false; | 512 | uppercase = false; |
| 513 | } else if (comptime std.mem.eql(u8, fmt, "c")) { | 513 | } else if (comptime std.mem.eql(u8, fmt, "c")) { |
| 514 | if (@typeOf(int_value).bit_count <= 8) { | 514 | if (@typeOf(int_value).bit_count <= 8) { |
| 515 | return formatAsciiChar(u8(int_value), options, context, Errors, output); | 515 | return formatAsciiChar(@as(u8, int_value), options, context, Errors, output); |
| 516 | } else { | 516 | } else { |
| 517 | @compileError("Cannot print integer that is larger than 8 bits as a ascii"); | 517 | @compileError("Cannot print integer that is larger than 8 bits as a ascii"); |
| 518 | } | 518 | } |
| ... | @@ -578,7 +578,7 @@ pub fn formatAsciiChar( | ... | @@ -578,7 +578,7 @@ pub fn formatAsciiChar( |
| 578 | comptime Errors: type, | 578 | comptime Errors: type, |
| 579 | output: fn (@typeOf(context), []const u8) Errors!void, | 579 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 580 | ) Errors!void { | 580 | ) Errors!void { |
| 581 | return output(context, (*const [1]u8)(&c)[0..]); | 581 | return output(context, @as(*const [1]u8, &c)[0..]); |
| 582 | } | 582 | } |
| 583 | 583 | ||
| 584 | pub fn formatBuf( | 584 | pub fn formatBuf( |
| ... | @@ -594,7 +594,7 @@ pub fn formatBuf( | ... | @@ -594,7 +594,7 @@ pub fn formatBuf( |
| 594 | var leftover_padding = if (width > buf.len) (width - buf.len) else return; | 594 | var leftover_padding = if (width > buf.len) (width - buf.len) else return; |
| 595 | const pad_byte: u8 = options.fill; | 595 | const pad_byte: u8 = options.fill; |
| 596 | while (leftover_padding > 0) : (leftover_padding -= 1) { | 596 | while (leftover_padding > 0) : (leftover_padding -= 1) { |
| 597 | try output(context, (*const [1]u8)(&pad_byte)[0..1]); | 597 | try output(context, @as(*const [1]u8, &pad_byte)[0..1]); |
| 598 | } | 598 | } |
| 599 | } | 599 | } |
| 600 | 600 | ||
| ... | @@ -668,7 +668,7 @@ pub fn formatFloatScientific( | ... | @@ -668,7 +668,7 @@ pub fn formatFloatScientific( |
| 668 | try output(context, float_decimal.digits[0..1]); | 668 | try output(context, float_decimal.digits[0..1]); |
| 669 | try output(context, "."); | 669 | try output(context, "."); |
| 670 | if (float_decimal.digits.len > 1) { | 670 | if (float_decimal.digits.len > 1) { |
| 671 | const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len; | 671 | const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len; |
| 672 | 672 | ||
| 673 | try output(context, float_decimal.digits[1..num_digits]); | 673 | try output(context, float_decimal.digits[1..num_digits]); |
| 674 | } else { | 674 | } else { |
| ... | @@ -703,7 +703,7 @@ pub fn formatFloatDecimal( | ... | @@ -703,7 +703,7 @@ pub fn formatFloatDecimal( |
| 703 | comptime Errors: type, | 703 | comptime Errors: type, |
| 704 | output: fn (@typeOf(context), []const u8) Errors!void, | 704 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 705 | ) Errors!void { | 705 | ) Errors!void { |
| 706 | var x = f64(value); | 706 | var x = @as(f64, value); |
| 707 | 707 | ||
| 708 | // Errol doesn't handle these special cases. | 708 | // Errol doesn't handle these special cases. |
| 709 | if (math.signbit(x)) { | 709 | if (math.signbit(x)) { |
| ... | @@ -921,14 +921,14 @@ fn formatIntSigned( | ... | @@ -921,14 +921,14 @@ fn formatIntSigned( |
| 921 | const uint = @IntType(false, @typeOf(value).bit_count); | 921 | const uint = @IntType(false, @typeOf(value).bit_count); |
| 922 | if (value < 0) { | 922 | if (value < 0) { |
| 923 | const minus_sign: u8 = '-'; | 923 | const minus_sign: u8 = '-'; |
| 924 | try output(context, (*const [1]u8)(&minus_sign)[0..]); | 924 | try output(context, @as(*const [1]u8, &minus_sign)[0..]); |
| 925 | const new_value = @intCast(uint, -(value + 1)) + 1; | 925 | const new_value = @intCast(uint, -(value + 1)) + 1; |
| 926 | return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); | 926 | return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); |
| 927 | } else if (options.width == null or options.width.? == 0) { | 927 | } else if (options.width == null or options.width.? == 0) { |
| 928 | return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output); | 928 | return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output); |
| 929 | } else { | 929 | } else { |
| 930 | const plus_sign: u8 = '+'; | 930 | const plus_sign: u8 = '+'; |
| 931 | try output(context, (*const [1]u8)(&plus_sign)[0..]); | 931 | try output(context, @as(*const [1]u8, &plus_sign)[0..]); |
| 932 | const new_value = @intCast(uint, value); | 932 | const new_value = @intCast(uint, value); |
| 933 | return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); | 933 | return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); |
| 934 | } | 934 | } |
| ... | @@ -966,7 +966,7 @@ fn formatIntUnsigned( | ... | @@ -966,7 +966,7 @@ fn formatIntUnsigned( |
| 966 | const zero_byte: u8 = options.fill; | 966 | const zero_byte: u8 = options.fill; |
| 967 | var leftover_padding = padding - index; | 967 | var leftover_padding = padding - index; |
| 968 | while (true) { | 968 | while (true) { |
| 969 | try output(context, (*const [1]u8)(&zero_byte)[0..]); | 969 | try output(context, @as(*const [1]u8, &zero_byte)[0..]); |
| 970 | leftover_padding -= 1; | 970 | leftover_padding -= 1; |
| 971 | if (leftover_padding == 0) break; | 971 | if (leftover_padding == 0) break; |
| 972 | } | 972 | } |
| ... | @@ -998,7 +998,7 @@ fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) { | ... | @@ -998,7 +998,7 @@ fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) { |
| 998 | 998 | ||
| 999 | pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T { | 999 | pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T { |
| 1000 | if (!T.is_signed) return parseUnsigned(T, buf, radix); | 1000 | if (!T.is_signed) return parseUnsigned(T, buf, radix); |
| 1001 | if (buf.len == 0) return T(0); | 1001 | if (buf.len == 0) return @as(T, 0); |
| 1002 | if (buf[0] == '-') { | 1002 | if (buf[0] == '-') { |
| 1003 | return math.negate(try parseUnsigned(T, buf[1..], radix)); | 1003 | return math.negate(try parseUnsigned(T, buf[1..], radix)); |
| 1004 | } else if (buf[0] == '+') { | 1004 | } else if (buf[0] == '+') { |
| ... | @@ -1088,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) { | ... | @@ -1088,7 +1088,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) { |
| 1088 | fn digitToChar(digit: u8, uppercase: bool) u8 { | 1088 | fn digitToChar(digit: u8, uppercase: bool) u8 { |
| 1089 | return switch (digit) { | 1089 | return switch (digit) { |
| 1090 | 0...9 => digit + '0', | 1090 | 0...9 => digit + '0', |
| 1091 | 10...35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10), | 1091 | 10...35 => digit + ((if (uppercase) @as(u8, 'A') else @as(u8, 'a')) - 10), |
| 1092 | else => unreachable, | 1092 | else => unreachable, |
| 1093 | }; | 1093 | }; |
| 1094 | } | 1094 | } |
| ... | @@ -1134,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) { | ... | @@ -1134,19 +1134,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) { |
| 1134 | test "bufPrintInt" { | 1134 | test "bufPrintInt" { |
| 1135 | var buffer: [100]u8 = undefined; | 1135 | var buffer: [100]u8 = undefined; |
| 1136 | const buf = buffer[0..]; | 1136 | const buf = buffer[0..]; |
| 1137 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, FormatOptions{}), "-101111000110000101001110")); | 1137 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}), "-101111000110000101001110")); |
| 1138 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, FormatOptions{}), "-12345678")); | 1138 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}), "-12345678")); |
| 1139 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, FormatOptions{}), "-bc614e")); | 1139 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}), "-bc614e")); |
| 1140 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, FormatOptions{}), "-BC614E")); | 1140 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}), "-BC614E")); |
| 1141 | 1141 | ||
| 1142 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(12345678), 10, true, FormatOptions{}), "12345678")); | 1142 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}), "12345678")); |
| 1143 | 1143 | ||
| 1144 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, FormatOptions{ .width = 6 }), " 666")); | 1144 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }), " 666")); |
| 1145 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234")); | 1145 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234")); |
| 1146 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, FormatOptions{ .width = 1 }), "1234")); | 1146 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }), "1234")); |
| 1147 | 1147 | ||
| 1148 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, FormatOptions{ .width = 3 }), "+42")); | 1148 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }), "+42")); |
| 1149 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, FormatOptions{ .width = 3 }), "-42")); | 1149 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }), "-42")); |
| 1150 | } | 1150 | } |
| 1151 | 1151 | ||
| 1152 | fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 { | 1152 | fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 { |
| ... | @@ -1208,8 +1208,8 @@ test "int.specifier" { | ... | @@ -1208,8 +1208,8 @@ test "int.specifier" { |
| 1208 | } | 1208 | } |
| 1209 | 1209 | ||
| 1210 | test "int.padded" { | 1210 | test "int.padded" { |
| 1211 | try testFmt("u8: ' 1'", "u8: '{:4}'", u8(1)); | 1211 | try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1)); |
| 1212 | try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", u8(1)); | 1212 | try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1)); |
| 1213 | } | 1213 | } |
| 1214 | 1214 | ||
| 1215 | test "buffer" { | 1215 | test "buffer" { |
| ... | @@ -1287,8 +1287,8 @@ test "filesize" { | ... | @@ -1287,8 +1287,8 @@ test "filesize" { |
| 1287 | // TODO https://github.com/ziglang/zig/issues/3289 | 1287 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1288 | return error.SkipZigTest; | 1288 | return error.SkipZigTest; |
| 1289 | } | 1289 | } |
| 1290 | try testFmt("file size: 63MiB\n", "file size: {Bi}\n", usize(63 * 1024 * 1024)); | 1290 | try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024)); |
| 1291 | try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", usize(63 * 1024 * 1024)); | 1291 | try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024)); |
| 1292 | } | 1292 | } |
| 1293 | 1293 | ||
| 1294 | test "struct" { | 1294 | test "struct" { |
| ... | @@ -1325,10 +1325,10 @@ test "float.scientific" { | ... | @@ -1325,10 +1325,10 @@ test "float.scientific" { |
| 1325 | // TODO https://github.com/ziglang/zig/issues/3289 | 1325 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1326 | return error.SkipZigTest; | 1326 | return error.SkipZigTest; |
| 1327 | } | 1327 | } |
| 1328 | try testFmt("f32: 1.34000003e+00", "f32: {e}", f32(1.34)); | 1328 | try testFmt("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34)); |
| 1329 | try testFmt("f32: 1.23400001e+01", "f32: {e}", f32(12.34)); | 1329 | try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34)); |
| 1330 | try testFmt("f64: -1.234e+11", "f64: {e}", f64(-12.34e10)); | 1330 | try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10)); |
| 1331 | try testFmt("f64: 9.99996e-40", "f64: {e}", f64(9.999960e-40)); | 1331 | try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40)); |
| 1332 | } | 1332 | } |
| 1333 | 1333 | ||
| 1334 | test "float.scientific.precision" { | 1334 | test "float.scientific.precision" { |
| ... | @@ -1336,12 +1336,12 @@ test "float.scientific.precision" { | ... | @@ -1336,12 +1336,12 @@ test "float.scientific.precision" { |
| 1336 | // TODO https://github.com/ziglang/zig/issues/3289 | 1336 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1337 | return error.SkipZigTest; | 1337 | return error.SkipZigTest; |
| 1338 | } | 1338 | } |
| 1339 | try testFmt("f64: 1.40971e-42", "f64: {e:.5}", f64(1.409706e-42)); | 1339 | try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42)); |
| 1340 | try testFmt("f64: 1.00000e-09", "f64: {e:.5}", f64(@bitCast(f32, u32(814313563)))); | 1340 | try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563)))); |
| 1341 | try testFmt("f64: 7.81250e-03", "f64: {e:.5}", f64(@bitCast(f32, u32(1006632960)))); | 1341 | try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960)))); |
| 1342 | // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. | 1342 | // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. |
| 1343 | // In fact, libc doesn't round a lot of 5 cases up when one past the precision point. | 1343 | // In fact, libc doesn't round a lot of 5 cases up when one past the precision point. |
| 1344 | try testFmt("f64: 1.00001e+05", "f64: {e:.5}", f64(@bitCast(f32, u32(1203982400)))); | 1344 | try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400)))); |
| 1345 | } | 1345 | } |
| 1346 | 1346 | ||
| 1347 | test "float.special" { | 1347 | test "float.special" { |
| ... | @@ -1364,21 +1364,21 @@ test "float.decimal" { | ... | @@ -1364,21 +1364,21 @@ test "float.decimal" { |
| 1364 | // TODO https://github.com/ziglang/zig/issues/3289 | 1364 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1365 | return error.SkipZigTest; | 1365 | return error.SkipZigTest; |
| 1366 | } | 1366 | } |
| 1367 | try testFmt("f64: 152314000000000000000000000000", "f64: {d}", f64(1.52314e+29)); | 1367 | try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29)); |
| 1368 | try testFmt("f32: 1.1", "f32: {d:.1}", f32(1.1234)); | 1368 | try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234)); |
| 1369 | try testFmt("f32: 1234.57", "f32: {d:.2}", f32(1234.567)); | 1369 | try testFmt("f32: 1234.57", "f32: {d:.2}", @as(f32, 1234.567)); |
| 1370 | // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). | 1370 | // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). |
| 1371 | // -11.12339... is rounded back up to -11.1234 | 1371 | // -11.12339... is rounded back up to -11.1234 |
| 1372 | try testFmt("f32: -11.1234", "f32: {d:.4}", f32(-11.1234)); | 1372 | try testFmt("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234)); |
| 1373 | try testFmt("f32: 91.12345", "f32: {d:.5}", f32(91.12345)); | 1373 | try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345)); |
| 1374 | try testFmt("f64: 91.1234567890", "f64: {d:.10}", f64(91.12345678901235)); | 1374 | try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235)); |
| 1375 | try testFmt("f64: 0.00000", "f64: {d:.5}", f64(0.0)); | 1375 | try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0)); |
| 1376 | try testFmt("f64: 6", "f64: {d:.0}", f64(5.700)); | 1376 | try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700)); |
| 1377 | try testFmt("f64: 10.0", "f64: {d:.1}", f64(9.999)); | 1377 | try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999)); |
| 1378 | try testFmt("f64: 1.000", "f64: {d:.3}", f64(1.0)); | 1378 | try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0)); |
| 1379 | try testFmt("f64: 0.00030000", "f64: {d:.8}", f64(0.0003)); | 1379 | try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003)); |
| 1380 | try testFmt("f64: 0.00000", "f64: {d:.5}", f64(1.40130e-45)); | 1380 | try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45)); |
| 1381 | try testFmt("f64: 0.00000", "f64: {d:.5}", f64(9.999960e-40)); | 1381 | try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40)); |
| 1382 | } | 1382 | } |
| 1383 | 1383 | ||
| 1384 | test "float.libc.sanity" { | 1384 | test "float.libc.sanity" { |
| ... | @@ -1386,22 +1386,22 @@ test "float.libc.sanity" { | ... | @@ -1386,22 +1386,22 @@ test "float.libc.sanity" { |
| 1386 | // TODO https://github.com/ziglang/zig/issues/3289 | 1386 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1387 | return error.SkipZigTest; | 1387 | return error.SkipZigTest; |
| 1388 | } | 1388 | } |
| 1389 | try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(916964781)))); | 1389 | try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781)))); |
| 1390 | try testFmt("f64: 0.00001", "f64: {d:.5}", f64(@bitCast(f32, u32(925353389)))); | 1390 | try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389)))); |
| 1391 | try testFmt("f64: 0.10000", "f64: {d:.5}", f64(@bitCast(f32, u32(1036831278)))); | 1391 | try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278)))); |
| 1392 | try testFmt("f64: 1.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1065353133)))); | 1392 | try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133)))); |
| 1393 | try testFmt("f64: 10.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1092616192)))); | 1393 | try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192)))); |
| 1394 | 1394 | ||
| 1395 | // libc differences | 1395 | // libc differences |
| 1396 | // | 1396 | // |
| 1397 | // This is 0.015625 exactly according to gdb. We thus round down, | 1397 | // This is 0.015625 exactly according to gdb. We thus round down, |
| 1398 | // however glibc rounds up for some reason. This occurs for all | 1398 | // however glibc rounds up for some reason. This occurs for all |
| 1399 | // floats of the form x.yyyy25 on a precision point. | 1399 | // floats of the form x.yyyy25 on a precision point. |
| 1400 | try testFmt("f64: 0.01563", "f64: {d:.5}", f64(@bitCast(f32, u32(1015021568)))); | 1400 | try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568)))); |
| 1401 | // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3 | 1401 | // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3 |
| 1402 | // also rounds to 630 so I'm inclined to believe libc is not | 1402 | // also rounds to 630 so I'm inclined to believe libc is not |
| 1403 | // optimal here. | 1403 | // optimal here. |
| 1404 | try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", f64(@bitCast(f32, u32(1518338049)))); | 1404 | try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049)))); |
| 1405 | } | 1405 | } |
| 1406 | 1406 | ||
| 1407 | test "custom" { | 1407 | test "custom" { |
| ... | @@ -1677,17 +1677,17 @@ test "formatType max_depth" { | ... | @@ -1677,17 +1677,17 @@ test "formatType max_depth" { |
| 1677 | } | 1677 | } |
| 1678 | 1678 | ||
| 1679 | test "positional" { | 1679 | test "positional" { |
| 1680 | try testFmt("2 1 0", "{2} {1} {0}", usize(0), usize(1), usize(2)); | 1680 | try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2)); |
| 1681 | try testFmt("2 1 0", "{2} {1} {}", usize(0), usize(1), usize(2)); | 1681 | try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2)); |
| 1682 | try testFmt("0 0", "{0} {0}", usize(0)); | 1682 | try testFmt("0 0", "{0} {0}", @as(usize, 0)); |
| 1683 | try testFmt("0 1", "{} {1}", usize(0), usize(1)); | 1683 | try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1)); |
| 1684 | try testFmt("1 0 0 1", "{1} {} {0} {}", usize(0), usize(1)); | 1684 | try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1)); |
| 1685 | } | 1685 | } |
| 1686 | 1686 | ||
| 1687 | test "positional with specifier" { | 1687 | test "positional with specifier" { |
| 1688 | try testFmt("10.0", "{0d:.1}", f64(9.999)); | 1688 | try testFmt("10.0", "{0d:.1}", @as(f64, 9.999)); |
| 1689 | } | 1689 | } |
| 1690 | 1690 | ||
| 1691 | test "positional/alignment/width/precision" { | 1691 | test "positional/alignment/width/precision" { |
| 1692 | try testFmt("10.0", "{0d: >3.1}", f64(9.999)); | 1692 | try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999)); |
| 1693 | } | 1693 | } |
lib/std/fmt/errol.zig+2-2| ... | @@ -296,7 +296,7 @@ fn hpMul10(hp: *HP) void { | ... | @@ -296,7 +296,7 @@ fn hpMul10(hp: *HP) void { |
| 296 | /// @buf: The output buffer. | 296 | /// @buf: The output buffer. |
| 297 | /// &return: The exponent. | 297 | /// &return: The exponent. |
| 298 | fn errolInt(val: f64, buffer: []u8) FloatDecimal { | 298 | fn errolInt(val: f64, buffer: []u8) FloatDecimal { |
| 299 | const pow19 = u128(1e19); | 299 | const pow19 = @as(u128, 1e19); |
| 300 | 300 | ||
| 301 | assert((val > 9.007199254740992e15) and val < (3.40282366920938e38)); | 301 | assert((val > 9.007199254740992e15) and val < (3.40282366920938e38)); |
| 302 | 302 | ||
| ... | @@ -670,7 +670,7 @@ fn fpeint(from: f64) u128 { | ... | @@ -670,7 +670,7 @@ fn fpeint(from: f64) u128 { |
| 670 | const bits = @bitCast(u64, from); | 670 | const bits = @bitCast(u64, from); |
| 671 | assert((bits & ((1 << 52) - 1)) == 0); | 671 | assert((bits & ((1 << 52) - 1)) == 0); |
| 672 | 672 | ||
| 673 | return u128(1) << @truncate(u7, (bits >> 52) -% 1023); | 673 | return @as(u128, 1) << @truncate(u7, (bits >> 52) -% 1023); |
| 674 | } | 674 | } |
| 675 | 675 | ||
| 676 | /// Given two different integers with the same length in terms of the number | 676 | /// Given two different integers with the same length in terms of the number |
lib/std/fmt/parse_float.zig+10-10| ... | @@ -59,29 +59,29 @@ const Z96 = struct { | ... | @@ -59,29 +59,29 @@ const Z96 = struct { |
| 59 | 59 | ||
| 60 | // d += s | 60 | // d += s |
| 61 | inline fn add(d: *Z96, s: Z96) void { | 61 | inline fn add(d: *Z96, s: Z96) void { |
| 62 | var w = u64(d.d0) + u64(s.d0); | 62 | var w = @as(u64, d.d0) + @as(u64, s.d0); |
| 63 | d.d0 = @truncate(u32, w); | 63 | d.d0 = @truncate(u32, w); |
| 64 | 64 | ||
| 65 | w >>= 32; | 65 | w >>= 32; |
| 66 | w += u64(d.d1) + u64(s.d1); | 66 | w += @as(u64, d.d1) + @as(u64, s.d1); |
| 67 | d.d1 = @truncate(u32, w); | 67 | d.d1 = @truncate(u32, w); |
| 68 | 68 | ||
| 69 | w >>= 32; | 69 | w >>= 32; |
| 70 | w += u64(d.d2) + u64(s.d2); | 70 | w += @as(u64, d.d2) + @as(u64, s.d2); |
| 71 | d.d2 = @truncate(u32, w); | 71 | d.d2 = @truncate(u32, w); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | // d -= s | 74 | // d -= s |
| 75 | inline fn sub(d: *Z96, s: Z96) void { | 75 | inline fn sub(d: *Z96, s: Z96) void { |
| 76 | var w = u64(d.d0) -% u64(s.d0); | 76 | var w = @as(u64, d.d0) -% @as(u64, s.d0); |
| 77 | d.d0 = @truncate(u32, w); | 77 | d.d0 = @truncate(u32, w); |
| 78 | 78 | ||
| 79 | w >>= 32; | 79 | w >>= 32; |
| 80 | w += u64(d.d1) -% u64(s.d1); | 80 | w += @as(u64, d.d1) -% @as(u64, s.d1); |
| 81 | d.d1 = @truncate(u32, w); | 81 | d.d1 = @truncate(u32, w); |
| 82 | 82 | ||
| 83 | w >>= 32; | 83 | w >>= 32; |
| 84 | w += u64(d.d2) -% u64(s.d2); | 84 | w += @as(u64, d.d2) -% @as(u64, s.d2); |
| 85 | d.d2 = @truncate(u32, w); | 85 | d.d2 = @truncate(u32, w); |
| 86 | } | 86 | } |
| 87 | }; | 87 | }; |
| ... | @@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T { | ... | @@ -160,7 +160,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T { |
| 160 | break :blk if (n.negative) f64_minus_zero else f64_plus_zero; | 160 | break :blk if (n.negative) f64_minus_zero else f64_plus_zero; |
| 161 | } else if (s.d2 != 0) { | 161 | } else if (s.d2 != 0) { |
| 162 | const binexs2 = @intCast(u64, binary_exponent) << 52; | 162 | const binexs2 = @intCast(u64, binary_exponent) << 52; |
| 163 | const rr = (u64(s.d2 & ~mask28) << 24) | ((u64(s.d1) + 128) >> 8) | binexs2; | 163 | const rr = (@as(u64, s.d2 & ~mask28) << 24) | ((@as(u64, s.d1) + 128) >> 8) | binexs2; |
| 164 | break :blk if (n.negative) rr | (1 << 63) else rr; | 164 | break :blk if (n.negative) rr | (1 << 63) else rr; |
| 165 | } else { | 165 | } else { |
| 166 | break :blk 0; | 166 | break :blk 0; |
| ... | @@ -375,7 +375,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T { | ... | @@ -375,7 +375,7 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T { |
| 375 | return switch (try parseRepr(s, &r)) { | 375 | return switch (try parseRepr(s, &r)) { |
| 376 | ParseResult.Ok => convertRepr(T, r), | 376 | ParseResult.Ok => convertRepr(T, r), |
| 377 | ParseResult.PlusZero => 0.0, | 377 | ParseResult.PlusZero => 0.0, |
| 378 | ParseResult.MinusZero => -T(0.0), | 378 | ParseResult.MinusZero => -@as(T, 0.0), |
| 379 | ParseResult.PlusInf => std.math.inf(T), | 379 | ParseResult.PlusInf => std.math.inf(T), |
| 380 | ParseResult.MinusInf => -std.math.inf(T), | 380 | ParseResult.MinusInf => -std.math.inf(T), |
| 381 | }; | 381 | }; |
| ... | @@ -426,8 +426,8 @@ test "fmt.parseFloat" { | ... | @@ -426,8 +426,8 @@ test "fmt.parseFloat" { |
| 426 | expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon)); | 426 | expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon)); |
| 427 | 427 | ||
| 428 | expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon)); | 428 | expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon)); |
| 429 | expect(approxEq(T, try parseFloat(T, "-123142.1124"), T(-123142.1124), epsilon)); | 429 | expect(approxEq(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon)); |
| 430 | expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), T(0.7062146892655368), epsilon)); | 430 | expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon)); |
| 431 | } | 431 | } |
| 432 | } | 432 | } |
| 433 | } | 433 | } |
lib/std/fs.zig+1-1| ... | @@ -584,7 +584,7 @@ pub const Dir = struct { | ... | @@ -584,7 +584,7 @@ pub const Dir = struct { |
| 584 | .FileBothDirectoryInformation, | 584 | .FileBothDirectoryInformation, |
| 585 | w.FALSE, | 585 | w.FALSE, |
| 586 | null, | 586 | null, |
| 587 | if (self.first) w.BOOLEAN(w.TRUE) else w.BOOLEAN(w.FALSE), | 587 | if (self.first) @as(w.BOOLEAN, w.TRUE) else @as(w.BOOLEAN, w.FALSE), |
| 588 | ); | 588 | ); |
| 589 | self.first = false; | 589 | self.first = false; |
| 590 | if (io.Information == 0) return null; | 590 | if (io.Information == 0) return null; |
lib/std/fs/file.zig+3-3| ... | @@ -272,9 +272,9 @@ pub const File = struct { | ... | @@ -272,9 +272,9 @@ pub const File = struct { |
| 272 | return Stat{ | 272 | return Stat{ |
| 273 | .size = @bitCast(u64, st.size), | 273 | .size = @bitCast(u64, st.size), |
| 274 | .mode = st.mode, | 274 | .mode = st.mode, |
| 275 | .atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, | 275 | .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, |
| 276 | .mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, | 276 | .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, |
| 277 | .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, | 277 | .ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, |
| 278 | }; | 278 | }; |
| 279 | } | 279 | } |
| 280 | 280 |
lib/std/hash/auto_hash.zig+7-7| ... | @@ -306,7 +306,7 @@ test "hash struct deep" { | ... | @@ -306,7 +306,7 @@ test "hash struct deep" { |
| 306 | test "testHash optional" { | 306 | test "testHash optional" { |
| 307 | const a: ?u32 = 123; | 307 | const a: ?u32 = 123; |
| 308 | const b: ?u32 = null; | 308 | const b: ?u32 = null; |
| 309 | testing.expectEqual(testHash(a), testHash(u32(123))); | 309 | testing.expectEqual(testHash(a), testHash(@as(u32, 123))); |
| 310 | testing.expect(testHash(a) != testHash(b)); | 310 | testing.expect(testHash(a) != testHash(b)); |
| 311 | testing.expectEqual(testHash(b), 0); | 311 | testing.expectEqual(testHash(b), 0); |
| 312 | } | 312 | } |
| ... | @@ -315,9 +315,9 @@ test "testHash array" { | ... | @@ -315,9 +315,9 @@ test "testHash array" { |
| 315 | const a = [_]u32{ 1, 2, 3 }; | 315 | const a = [_]u32{ 1, 2, 3 }; |
| 316 | const h = testHash(a); | 316 | const h = testHash(a); |
| 317 | var hasher = Wyhash.init(0); | 317 | var hasher = Wyhash.init(0); |
| 318 | autoHash(&hasher, u32(1)); | 318 | autoHash(&hasher, @as(u32, 1)); |
| 319 | autoHash(&hasher, u32(2)); | 319 | autoHash(&hasher, @as(u32, 2)); |
| 320 | autoHash(&hasher, u32(3)); | 320 | autoHash(&hasher, @as(u32, 3)); |
| 321 | testing.expectEqual(h, hasher.final()); | 321 | testing.expectEqual(h, hasher.final()); |
| 322 | } | 322 | } |
| 323 | 323 | ||
| ... | @@ -330,9 +330,9 @@ test "testHash struct" { | ... | @@ -330,9 +330,9 @@ test "testHash struct" { |
| 330 | const f = Foo{}; | 330 | const f = Foo{}; |
| 331 | const h = testHash(f); | 331 | const h = testHash(f); |
| 332 | var hasher = Wyhash.init(0); | 332 | var hasher = Wyhash.init(0); |
| 333 | autoHash(&hasher, u32(1)); | 333 | autoHash(&hasher, @as(u32, 1)); |
| 334 | autoHash(&hasher, u32(2)); | 334 | autoHash(&hasher, @as(u32, 2)); |
| 335 | autoHash(&hasher, u32(3)); | 335 | autoHash(&hasher, @as(u32, 3)); |
| 336 | testing.expectEqual(h, hasher.final()); | 336 | testing.expectEqual(h, hasher.final()); |
| 337 | } | 337 | } |
| 338 | 338 |
lib/std/hash/cityhash.zig+4-4| ... | @@ -214,7 +214,7 @@ pub const CityHash64 = struct { | ... | @@ -214,7 +214,7 @@ pub const CityHash64 = struct { |
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | fn hashLen0To16(str: []const u8) u64 { | 216 | fn hashLen0To16(str: []const u8) u64 { |
| 217 | const len: u64 = u64(str.len); | 217 | const len: u64 = @as(u64, str.len); |
| 218 | if (len >= 8) { | 218 | if (len >= 8) { |
| 219 | const mul: u64 = k2 +% len *% 2; | 219 | const mul: u64 = k2 +% len *% 2; |
| 220 | const a: u64 = fetch64(str.ptr) +% k2; | 220 | const a: u64 = fetch64(str.ptr) +% k2; |
| ... | @@ -240,7 +240,7 @@ pub const CityHash64 = struct { | ... | @@ -240,7 +240,7 @@ pub const CityHash64 = struct { |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | fn hashLen17To32(str: []const u8) u64 { | 242 | fn hashLen17To32(str: []const u8) u64 { |
| 243 | const len: u64 = u64(str.len); | 243 | const len: u64 = @as(u64, str.len); |
| 244 | const mul: u64 = k2 +% len *% 2; | 244 | const mul: u64 = k2 +% len *% 2; |
| 245 | const a: u64 = fetch64(str.ptr) *% k1; | 245 | const a: u64 = fetch64(str.ptr) *% k1; |
| 246 | const b: u64 = fetch64(str.ptr + 8); | 246 | const b: u64 = fetch64(str.ptr + 8); |
| ... | @@ -251,7 +251,7 @@ pub const CityHash64 = struct { | ... | @@ -251,7 +251,7 @@ pub const CityHash64 = struct { |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | fn hashLen33To64(str: []const u8) u64 { | 253 | fn hashLen33To64(str: []const u8) u64 { |
| 254 | const len: u64 = u64(str.len); | 254 | const len: u64 = @as(u64, str.len); |
| 255 | const mul: u64 = k2 +% len *% 2; | 255 | const mul: u64 = k2 +% len *% 2; |
| 256 | const a: u64 = fetch64(str.ptr) *% k2; | 256 | const a: u64 = fetch64(str.ptr) *% k2; |
| 257 | const b: u64 = fetch64(str.ptr + 8); | 257 | const b: u64 = fetch64(str.ptr + 8); |
| ... | @@ -305,7 +305,7 @@ pub const CityHash64 = struct { | ... | @@ -305,7 +305,7 @@ pub const CityHash64 = struct { |
| 305 | return hashLen33To64(str); | 305 | return hashLen33To64(str); |
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | var len: u64 = u64(str.len); | 308 | var len: u64 = @as(u64, str.len); |
| 309 | 309 | ||
| 310 | var x: u64 = fetch64(str.ptr + str.len - 40); | 310 | var x: u64 = fetch64(str.ptr + str.len - 40); |
| 311 | var y: u64 = fetch64(str.ptr + str.len - 16) +% fetch64(str.ptr + str.len - 56); | 311 | var y: u64 = fetch64(str.ptr + str.len - 16) +% fetch64(str.ptr + str.len - 56); |
lib/std/hash/crc.zig+4-4| ... | @@ -65,10 +65,10 @@ pub fn Crc32WithPoly(comptime poly: u32) type { | ... | @@ -65,10 +65,10 @@ pub fn Crc32WithPoly(comptime poly: u32) type { |
| 65 | const p = input[i .. i + 8]; | 65 | const p = input[i .. i + 8]; |
| 66 | 66 | ||
| 67 | // Unrolling this way gives ~50Mb/s increase | 67 | // Unrolling this way gives ~50Mb/s increase |
| 68 | self.crc ^= (u32(p[0]) << 0); | 68 | self.crc ^= (@as(u32, p[0]) << 0); |
| 69 | self.crc ^= (u32(p[1]) << 8); | 69 | self.crc ^= (@as(u32, p[1]) << 8); |
| 70 | self.crc ^= (u32(p[2]) << 16); | 70 | self.crc ^= (@as(u32, p[2]) << 16); |
| 71 | self.crc ^= (u32(p[3]) << 24); | 71 | self.crc ^= (@as(u32, p[3]) << 24); |
| 72 | 72 | ||
| 73 | self.crc = | 73 | self.crc = |
| 74 | lookup_tables[0][p[7]] ^ | 74 | lookup_tables[0][p[7]] ^ |
lib/std/hash/murmur.zig+1-1| ... | @@ -98,7 +98,7 @@ pub const Murmur2_64 = struct { | ... | @@ -98,7 +98,7 @@ pub const Murmur2_64 = struct { |
| 98 | 98 | ||
| 99 | pub fn hashWithSeed(str: []const u8, seed: u64) u64 { | 99 | pub fn hashWithSeed(str: []const u8, seed: u64) u64 { |
| 100 | const m: u64 = 0xc6a4a7935bd1e995; | 100 | const m: u64 = 0xc6a4a7935bd1e995; |
| 101 | const len = u64(str.len); | 101 | const len = @as(u64, str.len); |
| 102 | var h1: u64 = seed ^ (len *% m); | 102 | var h1: u64 = seed ^ (len *% m); |
| 103 | for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| { | 103 | for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| { |
| 104 | var k1: u64 = v; | 104 | var k1: u64 = v; |
lib/std/hash/siphash.zig+7-7| ... | @@ -102,7 +102,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round | ... | @@ -102,7 +102,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3; | 104 | const b2 = self.v0 ^ self.v1 ^ self.v2 ^ self.v3; |
| 105 | return (u128(b2) << 64) | b1; | 105 | return (@as(u128, b2) << 64) | b1; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | fn round(self: *Self, b: []const u8) void { | 108 | fn round(self: *Self, b: []const u8) void { |
| ... | @@ -121,19 +121,19 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round | ... | @@ -121,19 +121,19 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 121 | 121 | ||
| 122 | fn sipRound(d: *Self) void { | 122 | fn sipRound(d: *Self) void { |
| 123 | d.v0 +%= d.v1; | 123 | d.v0 +%= d.v1; |
| 124 | d.v1 = math.rotl(u64, d.v1, u64(13)); | 124 | d.v1 = math.rotl(u64, d.v1, @as(u64, 13)); |
| 125 | d.v1 ^= d.v0; | 125 | d.v1 ^= d.v0; |
| 126 | d.v0 = math.rotl(u64, d.v0, u64(32)); | 126 | d.v0 = math.rotl(u64, d.v0, @as(u64, 32)); |
| 127 | d.v2 +%= d.v3; | 127 | d.v2 +%= d.v3; |
| 128 | d.v3 = math.rotl(u64, d.v3, u64(16)); | 128 | d.v3 = math.rotl(u64, d.v3, @as(u64, 16)); |
| 129 | d.v3 ^= d.v2; | 129 | d.v3 ^= d.v2; |
| 130 | d.v0 +%= d.v3; | 130 | d.v0 +%= d.v3; |
| 131 | d.v3 = math.rotl(u64, d.v3, u64(21)); | 131 | d.v3 = math.rotl(u64, d.v3, @as(u64, 21)); |
| 132 | d.v3 ^= d.v0; | 132 | d.v3 ^= d.v0; |
| 133 | d.v2 +%= d.v1; | 133 | d.v2 +%= d.v1; |
| 134 | d.v1 = math.rotl(u64, d.v1, u64(17)); | 134 | d.v1 = math.rotl(u64, d.v1, @as(u64, 17)); |
| 135 | d.v1 ^= d.v2; | 135 | d.v1 ^= d.v2; |
| 136 | d.v2 = math.rotl(u64, d.v2, u64(32)); | 136 | d.v2 = math.rotl(u64, d.v2, @as(u64, 32)); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | pub fn hash(key: []const u8, input: []const u8) T { | 139 | pub fn hash(key: []const u8, input: []const u8) T { |
lib/std/hash_map.zig+1-1| ... | @@ -402,7 +402,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 | ... | @@ -402,7 +402,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 |
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | fn keyToIndex(hm: Self, key: K) usize { | 404 | fn keyToIndex(hm: Self, key: K) usize { |
| 405 | return hm.constrainIndex(usize(hash(key))); | 405 | return hm.constrainIndex(@as(usize, hash(key))); |
| 406 | } | 406 | } |
| 407 | 407 | ||
| 408 | fn constrainIndex(hm: Self, i: usize) usize { | 408 | fn constrainIndex(hm: Self, i: usize) usize { |
lib/std/heap.zig+2-2| ... | @@ -893,10 +893,10 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo | ... | @@ -893,10 +893,10 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo |
| 893 | if (mem.page_size << 2 > maxInt(usize)) return; | 893 | if (mem.page_size << 2 > maxInt(usize)) return; |
| 894 | 894 | ||
| 895 | const USizeShift = @IntType(false, std.math.log2(usize.bit_count)); | 895 | const USizeShift = @IntType(false, std.math.log2(usize.bit_count)); |
| 896 | const large_align = u29(mem.page_size << 2); | 896 | const large_align = @as(u29, mem.page_size << 2); |
| 897 | 897 | ||
| 898 | var align_mask: usize = undefined; | 898 | var align_mask: usize = undefined; |
| 899 | _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(u29, large_align)), &align_mask); | 899 | _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask); |
| 900 | 900 | ||
| 901 | var slice = try allocator.alignedAlloc(u8, large_align, 500); | 901 | var slice = try allocator.alignedAlloc(u8, large_align, 500); |
| 902 | testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | 902 | testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); |
lib/std/http/headers.zig+5-5| ... | @@ -399,7 +399,7 @@ test "Headers.iterator" { | ... | @@ -399,7 +399,7 @@ test "Headers.iterator" { |
| 399 | } | 399 | } |
| 400 | count += 1; | 400 | count += 1; |
| 401 | } | 401 | } |
| 402 | testing.expectEqual(i32(2), count); | 402 | testing.expectEqual(@as(i32, 2), count); |
| 403 | } | 403 | } |
| 404 | 404 | ||
| 405 | test "Headers.contains" { | 405 | test "Headers.contains" { |
| ... | @@ -420,10 +420,10 @@ test "Headers.delete" { | ... | @@ -420,10 +420,10 @@ test "Headers.delete" { |
| 420 | try h.append("cookie", "somevalue", null); | 420 | try h.append("cookie", "somevalue", null); |
| 421 | 421 | ||
| 422 | testing.expectEqual(false, h.delete("not-present")); | 422 | testing.expectEqual(false, h.delete("not-present")); |
| 423 | testing.expectEqual(usize(3), h.count()); | 423 | testing.expectEqual(@as(usize, 3), h.count()); |
| 424 | 424 | ||
| 425 | testing.expectEqual(true, h.delete("foo")); | 425 | testing.expectEqual(true, h.delete("foo")); |
| 426 | testing.expectEqual(usize(2), h.count()); | 426 | testing.expectEqual(@as(usize, 2), h.count()); |
| 427 | { | 427 | { |
| 428 | const e = h.at(0); | 428 | const e = h.at(0); |
| 429 | testing.expectEqualSlices(u8, "baz", e.name); | 429 | testing.expectEqualSlices(u8, "baz", e.name); |
| ... | @@ -448,7 +448,7 @@ test "Headers.orderedRemove" { | ... | @@ -448,7 +448,7 @@ test "Headers.orderedRemove" { |
| 448 | try h.append("cookie", "somevalue", null); | 448 | try h.append("cookie", "somevalue", null); |
| 449 | 449 | ||
| 450 | h.orderedRemove(0); | 450 | h.orderedRemove(0); |
| 451 | testing.expectEqual(usize(2), h.count()); | 451 | testing.expectEqual(@as(usize, 2), h.count()); |
| 452 | { | 452 | { |
| 453 | const e = h.at(0); | 453 | const e = h.at(0); |
| 454 | testing.expectEqualSlices(u8, "baz", e.name); | 454 | testing.expectEqualSlices(u8, "baz", e.name); |
| ... | @@ -471,7 +471,7 @@ test "Headers.swapRemove" { | ... | @@ -471,7 +471,7 @@ test "Headers.swapRemove" { |
| 471 | try h.append("cookie", "somevalue", null); | 471 | try h.append("cookie", "somevalue", null); |
| 472 | 472 | ||
| 473 | h.swapRemove(0); | 473 | h.swapRemove(0); |
| 474 | testing.expectEqual(usize(2), h.count()); | 474 | testing.expectEqual(@as(usize, 2), h.count()); |
| 475 | { | 475 | { |
| 476 | const e = h.at(0); | 476 | const e = h.at(0); |
| 477 | testing.expectEqualSlices(u8, "cookie", e.name); | 477 | testing.expectEqualSlices(u8, "cookie", e.name); |
lib/std/io.zig+15-15| ... | @@ -353,21 +353,21 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { | ... | @@ -353,21 +353,21 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { |
| 353 | const Buf = @IntType(false, buf_bit_count); | 353 | const Buf = @IntType(false, buf_bit_count); |
| 354 | const BufShift = math.Log2Int(Buf); | 354 | const BufShift = math.Log2Int(Buf); |
| 355 | 355 | ||
| 356 | out_bits.* = usize(0); | 356 | out_bits.* = @as(usize, 0); |
| 357 | if (U == u0 or bits == 0) return 0; | 357 | if (U == u0 or bits == 0) return 0; |
| 358 | var out_buffer = Buf(0); | 358 | var out_buffer = @as(Buf, 0); |
| 359 | 359 | ||
| 360 | if (self.bit_count > 0) { | 360 | if (self.bit_count > 0) { |
| 361 | const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count; | 361 | const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count; |
| 362 | const shift = u7_bit_count - n; | 362 | const shift = u7_bit_count - n; |
| 363 | switch (endian) { | 363 | switch (endian) { |
| 364 | builtin.Endian.Big => { | 364 | builtin.Endian.Big => { |
| 365 | out_buffer = Buf(self.bit_buffer >> shift); | 365 | out_buffer = @as(Buf, self.bit_buffer >> shift); |
| 366 | self.bit_buffer <<= n; | 366 | self.bit_buffer <<= n; |
| 367 | }, | 367 | }, |
| 368 | builtin.Endian.Little => { | 368 | builtin.Endian.Little => { |
| 369 | const value = (self.bit_buffer << shift) >> shift; | 369 | const value = (self.bit_buffer << shift) >> shift; |
| 370 | out_buffer = Buf(value); | 370 | out_buffer = @as(Buf, value); |
| 371 | self.bit_buffer >>= n; | 371 | self.bit_buffer >>= n; |
| 372 | }, | 372 | }, |
| 373 | } | 373 | } |
| ... | @@ -393,28 +393,28 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { | ... | @@ -393,28 +393,28 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { |
| 393 | if (n >= u8_bit_count) { | 393 | if (n >= u8_bit_count) { |
| 394 | out_buffer <<= @intCast(u3, u8_bit_count - 1); | 394 | out_buffer <<= @intCast(u3, u8_bit_count - 1); |
| 395 | out_buffer <<= 1; | 395 | out_buffer <<= 1; |
| 396 | out_buffer |= Buf(next_byte); | 396 | out_buffer |= @as(Buf, next_byte); |
| 397 | out_bits.* += u8_bit_count; | 397 | out_bits.* += u8_bit_count; |
| 398 | continue; | 398 | continue; |
| 399 | } | 399 | } |
| 400 | 400 | ||
| 401 | const shift = @intCast(u3, u8_bit_count - n); | 401 | const shift = @intCast(u3, u8_bit_count - n); |
| 402 | out_buffer <<= @intCast(BufShift, n); | 402 | out_buffer <<= @intCast(BufShift, n); |
| 403 | out_buffer |= Buf(next_byte >> shift); | 403 | out_buffer |= @as(Buf, next_byte >> shift); |
| 404 | out_bits.* += n; | 404 | out_bits.* += n; |
| 405 | self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1)); | 405 | self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1)); |
| 406 | self.bit_count = shift; | 406 | self.bit_count = shift; |
| 407 | }, | 407 | }, |
| 408 | builtin.Endian.Little => { | 408 | builtin.Endian.Little => { |
| 409 | if (n >= u8_bit_count) { | 409 | if (n >= u8_bit_count) { |
| 410 | out_buffer |= Buf(next_byte) << @intCast(BufShift, out_bits.*); | 410 | out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*); |
| 411 | out_bits.* += u8_bit_count; | 411 | out_bits.* += u8_bit_count; |
| 412 | continue; | 412 | continue; |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | const shift = @intCast(u3, u8_bit_count - n); | 415 | const shift = @intCast(u3, u8_bit_count - n); |
| 416 | const value = (next_byte << shift) >> shift; | 416 | const value = (next_byte << shift) >> shift; |
| 417 | out_buffer |= Buf(value) << @intCast(BufShift, out_bits.*); | 417 | out_buffer |= @as(Buf, value) << @intCast(BufShift, out_bits.*); |
| 418 | out_bits.* += n; | 418 | out_bits.* += n; |
| 419 | self.bit_buffer = @truncate(u7, next_byte >> @intCast(u3, n)); | 419 | self.bit_buffer = @truncate(u7, next_byte >> @intCast(u3, n)); |
| 420 | self.bit_count = shift; | 420 | self.bit_count = shift; |
| ... | @@ -434,7 +434,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { | ... | @@ -434,7 +434,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { |
| 434 | var self = @fieldParentPtr(Self, "stream", self_stream); | 434 | var self = @fieldParentPtr(Self, "stream", self_stream); |
| 435 | 435 | ||
| 436 | var out_bits: usize = undefined; | 436 | var out_bits: usize = undefined; |
| 437 | var out_bits_total = usize(0); | 437 | var out_bits_total = @as(usize, 0); |
| 438 | //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced | 438 | //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced |
| 439 | if (self.bit_count > 0) { | 439 | if (self.bit_count > 0) { |
| 440 | for (buffer) |*b, i| { | 440 | for (buffer) |*b, i| { |
| ... | @@ -949,14 +949,14 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, | ... | @@ -949,14 +949,14 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 949 | return @truncate(T, @bitCast(PossiblySignedByte, buffer[0])); | 949 | return @truncate(T, @bitCast(PossiblySignedByte, buffer[0])); |
| 950 | } | 950 | } |
| 951 | 951 | ||
| 952 | var result = U(0); | 952 | var result = @as(U, 0); |
| 953 | for (buffer) |byte, i| { | 953 | for (buffer) |byte, i| { |
| 954 | switch (endian) { | 954 | switch (endian) { |
| 955 | builtin.Endian.Big => { | 955 | builtin.Endian.Big => { |
| 956 | result = (result << u8_bit_count) | byte; | 956 | result = (result << u8_bit_count) | byte; |
| 957 | }, | 957 | }, |
| 958 | builtin.Endian.Little => { | 958 | builtin.Endian.Little => { |
| 959 | result |= U(byte) << @intCast(Log2U, u8_bit_count * i); | 959 | result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i); |
| 960 | }, | 960 | }, |
| 961 | } | 961 | } |
| 962 | } | 962 | } |
| ... | @@ -1050,7 +1050,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, | ... | @@ -1050,7 +1050,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 1050 | return; | 1050 | return; |
| 1051 | } | 1051 | } |
| 1052 | 1052 | ||
| 1053 | ptr.* = OC(undefined); //make it non-null so the following .? is guaranteed safe | 1053 | ptr.* = @as(OC, undefined); //make it non-null so the following .? is guaranteed safe |
| 1054 | const val_ptr = &ptr.*.?; | 1054 | const val_ptr = &ptr.*.?; |
| 1055 | try self.deserializeInto(val_ptr); | 1055 | try self.deserializeInto(val_ptr); |
| 1056 | }, | 1056 | }, |
| ... | @@ -1154,7 +1154,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co | ... | @@ -1154,7 +1154,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1154 | 1154 | ||
| 1155 | switch (@typeId(T)) { | 1155 | switch (@typeId(T)) { |
| 1156 | builtin.TypeId.Void => return, | 1156 | builtin.TypeId.Void => return, |
| 1157 | builtin.TypeId.Bool => try self.serializeInt(u1(@boolToInt(value))), | 1157 | builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))), |
| 1158 | builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value), | 1158 | builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value), |
| 1159 | builtin.TypeId.Struct => { | 1159 | builtin.TypeId.Struct => { |
| 1160 | const info = @typeInfo(T); | 1160 | const info = @typeInfo(T); |
| ... | @@ -1197,10 +1197,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co | ... | @@ -1197,10 +1197,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1197 | }, | 1197 | }, |
| 1198 | builtin.TypeId.Optional => { | 1198 | builtin.TypeId.Optional => { |
| 1199 | if (value == null) { | 1199 | if (value == null) { |
| 1200 | try self.serializeInt(u1(@boolToInt(false))); | 1200 | try self.serializeInt(@as(u1, @boolToInt(false))); |
| 1201 | return; | 1201 | return; |
| 1202 | } | 1202 | } |
| 1203 | try self.serializeInt(u1(@boolToInt(true))); | 1203 | try self.serializeInt(@as(u1, @boolToInt(true))); |
| 1204 | 1204 | ||
| 1205 | const OC = comptime meta.Child(T); | 1205 | const OC = comptime meta.Child(T); |
| 1206 | const val_ptr = &value.?; | 1206 | const val_ptr = &value.?; |
lib/std/io/out_stream.zig+2-2| ... | @@ -40,12 +40,12 @@ pub fn OutStream(comptime WriteError: type) type { | ... | @@ -40,12 +40,12 @@ pub fn OutStream(comptime WriteError: type) type { |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | pub fn writeByte(self: *Self, byte: u8) Error!void { | 42 | pub fn writeByte(self: *Self, byte: u8) Error!void { |
| 43 | const slice = (*const [1]u8)(&byte)[0..]; | 43 | const slice = @as(*const [1]u8, &byte)[0..]; |
| 44 | return self.writeFn(self, slice); | 44 | return self.writeFn(self, slice); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void { | 47 | pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void { |
| 48 | const slice = (*const [1]u8)(&byte)[0..]; | 48 | const slice = @as(*const [1]u8, &byte)[0..]; |
| 49 | var i: usize = 0; | 49 | var i: usize = 0; |
| 50 | while (i < n) : (i += 1) { | 50 | while (i < n) : (i += 1) { |
| 51 | try self.writeFn(self, slice); | 51 | try self.writeFn(self, slice); |
lib/std/io/test.zig+32-32| ... | @@ -226,49 +226,49 @@ test "BitOutStream" { | ... | @@ -226,49 +226,49 @@ test "BitOutStream" { |
| 226 | const OutError = io.SliceOutStream.Error; | 226 | const OutError = io.SliceOutStream.Error; |
| 227 | var bit_stream_be = io.BitOutStream(builtin.Endian.Big, OutError).init(&mem_out_be.stream); | 227 | var bit_stream_be = io.BitOutStream(builtin.Endian.Big, OutError).init(&mem_out_be.stream); |
| 228 | 228 | ||
| 229 | try bit_stream_be.writeBits(u2(1), 1); | 229 | try bit_stream_be.writeBits(@as(u2, 1), 1); |
| 230 | try bit_stream_be.writeBits(u5(2), 2); | 230 | try bit_stream_be.writeBits(@as(u5, 2), 2); |
| 231 | try bit_stream_be.writeBits(u128(3), 3); | 231 | try bit_stream_be.writeBits(@as(u128, 3), 3); |
| 232 | try bit_stream_be.writeBits(u8(4), 4); | 232 | try bit_stream_be.writeBits(@as(u8, 4), 4); |
| 233 | try bit_stream_be.writeBits(u9(5), 5); | 233 | try bit_stream_be.writeBits(@as(u9, 5), 5); |
| 234 | try bit_stream_be.writeBits(u1(1), 1); | 234 | try bit_stream_be.writeBits(@as(u1, 1), 1); |
| 235 | 235 | ||
| 236 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011); | 236 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011); |
| 237 | 237 | ||
| 238 | mem_out_be.pos = 0; | 238 | mem_out_be.pos = 0; |
| 239 | 239 | ||
| 240 | try bit_stream_be.writeBits(u15(0b110011010000101), 15); | 240 | try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15); |
| 241 | try bit_stream_be.flushBits(); | 241 | try bit_stream_be.flushBits(); |
| 242 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010); | 242 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010); |
| 243 | 243 | ||
| 244 | mem_out_be.pos = 0; | 244 | mem_out_be.pos = 0; |
| 245 | try bit_stream_be.writeBits(u32(0b110011010000101), 16); | 245 | try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16); |
| 246 | expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101); | 246 | expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101); |
| 247 | 247 | ||
| 248 | try bit_stream_be.writeBits(u0(0), 0); | 248 | try bit_stream_be.writeBits(@as(u0, 0), 0); |
| 249 | 249 | ||
| 250 | var mem_out_le = io.SliceOutStream.init(mem_le[0..]); | 250 | var mem_out_le = io.SliceOutStream.init(mem_le[0..]); |
| 251 | var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream); | 251 | var bit_stream_le = io.BitOutStream(builtin.Endian.Little, OutError).init(&mem_out_le.stream); |
| 252 | 252 | ||
| 253 | try bit_stream_le.writeBits(u2(1), 1); | 253 | try bit_stream_le.writeBits(@as(u2, 1), 1); |
| 254 | try bit_stream_le.writeBits(u5(2), 2); | 254 | try bit_stream_le.writeBits(@as(u5, 2), 2); |
| 255 | try bit_stream_le.writeBits(u128(3), 3); | 255 | try bit_stream_le.writeBits(@as(u128, 3), 3); |
| 256 | try bit_stream_le.writeBits(u8(4), 4); | 256 | try bit_stream_le.writeBits(@as(u8, 4), 4); |
| 257 | try bit_stream_le.writeBits(u9(5), 5); | 257 | try bit_stream_le.writeBits(@as(u9, 5), 5); |
| 258 | try bit_stream_le.writeBits(u1(1), 1); | 258 | try bit_stream_le.writeBits(@as(u1, 1), 1); |
| 259 | 259 | ||
| 260 | expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101); | 260 | expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101); |
| 261 | 261 | ||
| 262 | mem_out_le.pos = 0; | 262 | mem_out_le.pos = 0; |
| 263 | try bit_stream_le.writeBits(u15(0b110011010000101), 15); | 263 | try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15); |
| 264 | try bit_stream_le.flushBits(); | 264 | try bit_stream_le.flushBits(); |
| 265 | expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110); | 265 | expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110); |
| 266 | 266 | ||
| 267 | mem_out_le.pos = 0; | 267 | mem_out_le.pos = 0; |
| 268 | try bit_stream_le.writeBits(u32(0b1100110100001011), 16); | 268 | try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16); |
| 269 | expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101); | 269 | expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101); |
| 270 | 270 | ||
| 271 | try bit_stream_le.writeBits(u0(0), 0); | 271 | try bit_stream_le.writeBits(@as(u0, 0), 0); |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | test "BitStreams with File Stream" { | 274 | test "BitStreams with File Stream" { |
| ... | @@ -282,12 +282,12 @@ test "BitStreams with File Stream" { | ... | @@ -282,12 +282,12 @@ test "BitStreams with File Stream" { |
| 282 | const OutError = File.WriteError; | 282 | const OutError = File.WriteError; |
| 283 | var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream); | 283 | var bit_stream = io.BitOutStream(builtin.endian, OutError).init(file_out_stream); |
| 284 | 284 | ||
| 285 | try bit_stream.writeBits(u2(1), 1); | 285 | try bit_stream.writeBits(@as(u2, 1), 1); |
| 286 | try bit_stream.writeBits(u5(2), 2); | 286 | try bit_stream.writeBits(@as(u5, 2), 2); |
| 287 | try bit_stream.writeBits(u128(3), 3); | 287 | try bit_stream.writeBits(@as(u128, 3), 3); |
| 288 | try bit_stream.writeBits(u8(4), 4); | 288 | try bit_stream.writeBits(@as(u8, 4), 4); |
| 289 | try bit_stream.writeBits(u9(5), 5); | 289 | try bit_stream.writeBits(@as(u9, 5), 5); |
| 290 | try bit_stream.writeBits(u1(1), 1); | 290 | try bit_stream.writeBits(@as(u1, 1), 1); |
| 291 | try bit_stream.flushBits(); | 291 | try bit_stream.flushBits(); |
| 292 | } | 292 | } |
| 293 | { | 293 | { |
| ... | @@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi | ... | @@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi |
| 345 | inline while (i <= max_test_bitsize) : (i += 1) { | 345 | inline while (i <= max_test_bitsize) : (i += 1) { |
| 346 | const U = @IntType(false, i); | 346 | const U = @IntType(false, i); |
| 347 | const S = @IntType(true, i); | 347 | const S = @IntType(true, i); |
| 348 | try serializer.serializeInt(U(i)); | 348 | try serializer.serializeInt(@as(U, i)); |
| 349 | if (i != 0) try serializer.serializeInt(S(-1)) else try serializer.serialize(S(0)); | 349 | if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0)); |
| 350 | } | 350 | } |
| 351 | try serializer.flush(); | 351 | try serializer.flush(); |
| 352 | 352 | ||
| ... | @@ -356,8 +356,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi | ... | @@ -356,8 +356,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi |
| 356 | const S = @IntType(true, i); | 356 | const S = @IntType(true, i); |
| 357 | const x = try deserializer.deserializeInt(U); | 357 | const x = try deserializer.deserializeInt(U); |
| 358 | const y = try deserializer.deserializeInt(S); | 358 | const y = try deserializer.deserializeInt(S); |
| 359 | expect(x == U(i)); | 359 | expect(x == @as(U, i)); |
| 360 | if (i != 0) expect(y == S(-1)) else expect(y == 0); | 360 | if (i != 0) expect(y == @as(S, -1)) else expect(y == 0); |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | const u8_bit_count = comptime meta.bitCount(u8); | 363 | const u8_bit_count = comptime meta.bitCount(u8); |
| ... | @@ -577,11 +577,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !v | ... | @@ -577,11 +577,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !v |
| 577 | var in_stream = &in.stream; | 577 | var in_stream = &in.stream; |
| 578 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); | 578 | var deserializer = io.Deserializer(endian, packing, InError).init(in_stream); |
| 579 | 579 | ||
| 580 | try serializer.serialize(u14(3)); | 580 | try serializer.serialize(@as(u14, 3)); |
| 581 | expectError(error.InvalidEnumTag, deserializer.deserialize(A)); | 581 | expectError(error.InvalidEnumTag, deserializer.deserialize(A)); |
| 582 | out.pos = 0; | 582 | out.pos = 0; |
| 583 | try serializer.serialize(u14(3)); | 583 | try serializer.serialize(@as(u14, 3)); |
| 584 | try serializer.serialize(u14(88)); | 584 | try serializer.serialize(@as(u14, 88)); |
| 585 | expectError(error.InvalidEnumTag, deserializer.deserialize(C)); | 585 | expectError(error.InvalidEnumTag, deserializer.deserialize(C)); |
| 586 | } | 586 | } |
| 587 | 587 | ||
| ... | @@ -603,7 +603,7 @@ test "c out stream" { | ... | @@ -603,7 +603,7 @@ test "c out stream" { |
| 603 | } | 603 | } |
| 604 | 604 | ||
| 605 | const out_stream = &io.COutStream.init(out_file).stream; | 605 | const out_stream = &io.COutStream.init(out_file).stream; |
| 606 | try out_stream.print("hi: {}\n", i32(123)); | 606 | try out_stream.print("hi: {}\n", @as(i32, 123)); |
| 607 | } | 607 | } |
| 608 | 608 | ||
| 609 | test "File seek ops" { | 609 | test "File seek ops" { |
lib/std/json.zig+2-2| ... | @@ -1343,7 +1343,7 @@ test "write json then parse it" { | ... | @@ -1343,7 +1343,7 @@ test "write json then parse it" { |
| 1343 | try jw.emitBool(true); | 1343 | try jw.emitBool(true); |
| 1344 | 1344 | ||
| 1345 | try jw.objectField("int"); | 1345 | try jw.objectField("int"); |
| 1346 | try jw.emitNumber(i32(1234)); | 1346 | try jw.emitNumber(@as(i32, 1234)); |
| 1347 | 1347 | ||
| 1348 | try jw.objectField("array"); | 1348 | try jw.objectField("array"); |
| 1349 | try jw.beginArray(); | 1349 | try jw.beginArray(); |
| ... | @@ -1352,7 +1352,7 @@ test "write json then parse it" { | ... | @@ -1352,7 +1352,7 @@ test "write json then parse it" { |
| 1352 | try jw.emitNull(); | 1352 | try jw.emitNull(); |
| 1353 | 1353 | ||
| 1354 | try jw.arrayElem(); | 1354 | try jw.arrayElem(); |
| 1355 | try jw.emitNumber(f64(12.34)); | 1355 | try jw.emitNumber(@as(f64, 12.34)); |
| 1356 | 1356 | ||
| 1357 | try jw.endArray(); | 1357 | try jw.endArray(); |
| 1358 | 1358 |
lib/std/lazy_init.zig+1-1| ... | @@ -39,7 +39,7 @@ fn LazyInit(comptime T: type) type { | ... | @@ -39,7 +39,7 @@ fn LazyInit(comptime T: type) type { |
| 39 | }, | 39 | }, |
| 40 | 2 => { | 40 | 2 => { |
| 41 | if (@sizeOf(T) == 0) { | 41 | if (@sizeOf(T) == 0) { |
| 42 | return T(undefined); | 42 | return @as(T, undefined); |
| 43 | } else { | 43 | } else { |
| 44 | return &self.data; | 44 | return &self.data; |
| 45 | } | 45 | } |
lib/std/math.zig+80-80| ... | @@ -44,10 +44,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079; | ... | @@ -44,10 +44,10 @@ pub const sqrt2 = 1.414213562373095048801688724209698079; |
| 44 | pub const sqrt1_2 = 0.707106781186547524400844362104849039; | 44 | pub const sqrt1_2 = 0.707106781186547524400844362104849039; |
| 45 | 45 | ||
| 46 | // From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128) | 46 | // From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128) |
| 47 | pub const f128_true_min = @bitCast(f128, u128(0x00000000000000000000000000000001)); | 47 | pub const f128_true_min = @bitCast(f128, @as(u128, 0x00000000000000000000000000000001)); |
| 48 | pub const f128_min = @bitCast(f128, u128(0x00010000000000000000000000000000)); | 48 | pub const f128_min = @bitCast(f128, @as(u128, 0x00010000000000000000000000000000)); |
| 49 | pub const f128_max = @bitCast(f128, u128(0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF)); | 49 | pub const f128_max = @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF)); |
| 50 | pub const f128_epsilon = @bitCast(f128, u128(0x3F8F0000000000000000000000000000)); | 50 | pub const f128_epsilon = @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000)); |
| 51 | pub const f128_toint = 1.0 / f128_epsilon; | 51 | pub const f128_toint = 1.0 / f128_epsilon; |
| 52 | 52 | ||
| 53 | // float.h details | 53 | // float.h details |
| ... | @@ -69,28 +69,28 @@ pub const f16_max = 65504; | ... | @@ -69,28 +69,28 @@ pub const f16_max = 65504; |
| 69 | pub const f16_epsilon = 0.0009765625; // 2**-10 | 69 | pub const f16_epsilon = 0.0009765625; // 2**-10 |
| 70 | pub const f16_toint = 1.0 / f16_epsilon; | 70 | pub const f16_toint = 1.0 / f16_epsilon; |
| 71 | 71 | ||
| 72 | pub const nan_u16 = u16(0x7C01); | 72 | pub const nan_u16 = @as(u16, 0x7C01); |
| 73 | pub const nan_f16 = @bitCast(f16, nan_u16); | 73 | pub const nan_f16 = @bitCast(f16, nan_u16); |
| 74 | 74 | ||
| 75 | pub const inf_u16 = u16(0x7C00); | 75 | pub const inf_u16 = @as(u16, 0x7C00); |
| 76 | pub const inf_f16 = @bitCast(f16, inf_u16); | 76 | pub const inf_f16 = @bitCast(f16, inf_u16); |
| 77 | 77 | ||
| 78 | pub const nan_u32 = u32(0x7F800001); | 78 | pub const nan_u32 = @as(u32, 0x7F800001); |
| 79 | pub const nan_f32 = @bitCast(f32, nan_u32); | 79 | pub const nan_f32 = @bitCast(f32, nan_u32); |
| 80 | 80 | ||
| 81 | pub const inf_u32 = u32(0x7F800000); | 81 | pub const inf_u32 = @as(u32, 0x7F800000); |
| 82 | pub const inf_f32 = @bitCast(f32, inf_u32); | 82 | pub const inf_f32 = @bitCast(f32, inf_u32); |
| 83 | 83 | ||
| 84 | pub const nan_u64 = u64(0x7FF << 52) | 1; | 84 | pub const nan_u64 = @as(u64, 0x7FF << 52) | 1; |
| 85 | pub const nan_f64 = @bitCast(f64, nan_u64); | 85 | pub const nan_f64 = @bitCast(f64, nan_u64); |
| 86 | 86 | ||
| 87 | pub const inf_u64 = u64(0x7FF << 52); | 87 | pub const inf_u64 = @as(u64, 0x7FF << 52); |
| 88 | pub const inf_f64 = @bitCast(f64, inf_u64); | 88 | pub const inf_f64 = @bitCast(f64, inf_u64); |
| 89 | 89 | ||
| 90 | pub const nan_u128 = u128(0x7fff0000000000000000000000000001); | 90 | pub const nan_u128 = @as(u128, 0x7fff0000000000000000000000000001); |
| 91 | pub const nan_f128 = @bitCast(f128, nan_u128); | 91 | pub const nan_f128 = @bitCast(f128, nan_u128); |
| 92 | 92 | ||
| 93 | pub const inf_u128 = u128(0x7fff0000000000000000000000000000); | 93 | pub const inf_u128 = @as(u128, 0x7fff0000000000000000000000000000); |
| 94 | pub const inf_f128 = @bitCast(f128, inf_u128); | 94 | pub const inf_f128 = @bitCast(f128, inf_u128); |
| 95 | 95 | ||
| 96 | pub const nan = @import("math/nan.zig").nan; | 96 | pub const nan = @import("math/nan.zig").nan; |
| ... | @@ -248,7 +248,7 @@ pub fn Min(comptime A: type, comptime B: type) type { | ... | @@ -248,7 +248,7 @@ pub fn Min(comptime A: type, comptime B: type) type { |
| 248 | }, | 248 | }, |
| 249 | else => {}, | 249 | else => {}, |
| 250 | } | 250 | } |
| 251 | return @typeOf(A(0) + B(0)); | 251 | return @typeOf(@as(A, 0) + @as(B, 0)); |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | /// Returns the smaller number. When one of the parameter's type's full range fits in the other, | 254 | /// Returns the smaller number. When one of the parameter's type's full range fits in the other, |
| ... | @@ -273,7 +273,7 @@ pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) { | ... | @@ -273,7 +273,7 @@ pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) { |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | test "math.min" { | 275 | test "math.min" { |
| 276 | testing.expect(min(i32(-1), i32(2)) == -1); | 276 | testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1); |
| 277 | { | 277 | { |
| 278 | var a: u16 = 999; | 278 | var a: u16 = 999; |
| 279 | var b: u32 = 10; | 279 | var b: u32 = 10; |
| ... | @@ -309,7 +309,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) { | ... | @@ -309,7 +309,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) { |
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | test "math.max" { | 311 | test "math.max" { |
| 312 | testing.expect(max(i32(-1), i32(2)) == 2); | 312 | testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2); |
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) { | 315 | pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) { |
| ... | @@ -352,10 +352,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T { | ... | @@ -352,10 +352,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T { |
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | test "math.shl" { | 354 | test "math.shl" { |
| 355 | testing.expect(shl(u8, 0b11111111, usize(3)) == 0b11111000); | 355 | testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000); |
| 356 | testing.expect(shl(u8, 0b11111111, usize(8)) == 0); | 356 | testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0); |
| 357 | testing.expect(shl(u8, 0b11111111, usize(9)) == 0); | 357 | testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0); |
| 358 | testing.expect(shl(u8, 0b11111111, isize(-2)) == 0b00111111); | 358 | testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111); |
| 359 | testing.expect(shl(u8, 0b11111111, 3) == 0b11111000); | 359 | testing.expect(shl(u8, 0b11111111, 3) == 0b11111000); |
| 360 | testing.expect(shl(u8, 0b11111111, 8) == 0); | 360 | testing.expect(shl(u8, 0b11111111, 8) == 0); |
| 361 | testing.expect(shl(u8, 0b11111111, 9) == 0); | 361 | testing.expect(shl(u8, 0b11111111, 9) == 0); |
| ... | @@ -380,10 +380,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T { | ... | @@ -380,10 +380,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T { |
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | test "math.shr" { | 382 | test "math.shr" { |
| 383 | testing.expect(shr(u8, 0b11111111, usize(3)) == 0b00011111); | 383 | testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111); |
| 384 | testing.expect(shr(u8, 0b11111111, usize(8)) == 0); | 384 | testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0); |
| 385 | testing.expect(shr(u8, 0b11111111, usize(9)) == 0); | 385 | testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0); |
| 386 | testing.expect(shr(u8, 0b11111111, isize(-2)) == 0b11111100); | 386 | testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100); |
| 387 | testing.expect(shr(u8, 0b11111111, 3) == 0b00011111); | 387 | testing.expect(shr(u8, 0b11111111, 3) == 0b00011111); |
| 388 | testing.expect(shr(u8, 0b11111111, 8) == 0); | 388 | testing.expect(shr(u8, 0b11111111, 8) == 0); |
| 389 | testing.expect(shr(u8, 0b11111111, 9) == 0); | 389 | testing.expect(shr(u8, 0b11111111, 9) == 0); |
| ... | @@ -402,11 +402,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T { | ... | @@ -402,11 +402,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T { |
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | test "math.rotr" { | 404 | test "math.rotr" { |
| 405 | testing.expect(rotr(u8, 0b00000001, usize(0)) == 0b00000001); | 405 | testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001); |
| 406 | testing.expect(rotr(u8, 0b00000001, usize(9)) == 0b10000000); | 406 | testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000); |
| 407 | testing.expect(rotr(u8, 0b00000001, usize(8)) == 0b00000001); | 407 | testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001); |
| 408 | testing.expect(rotr(u8, 0b00000001, usize(4)) == 0b00010000); | 408 | testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000); |
| 409 | testing.expect(rotr(u8, 0b00000001, isize(-1)) == 0b00000010); | 409 | testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010); |
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | /// Rotates left. Only unsigned values can be rotated. | 412 | /// Rotates left. Only unsigned values can be rotated. |
| ... | @@ -421,11 +421,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T { | ... | @@ -421,11 +421,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T { |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | test "math.rotl" { | 423 | test "math.rotl" { |
| 424 | testing.expect(rotl(u8, 0b00000001, usize(0)) == 0b00000001); | 424 | testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001); |
| 425 | testing.expect(rotl(u8, 0b00000001, usize(9)) == 0b00000010); | 425 | testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010); |
| 426 | testing.expect(rotl(u8, 0b00000001, usize(8)) == 0b00000001); | 426 | testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001); |
| 427 | testing.expect(rotl(u8, 0b00000001, usize(4)) == 0b00010000); | 427 | testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000); |
| 428 | testing.expect(rotl(u8, 0b00000001, isize(-1)) == 0b10000000); | 428 | testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000); |
| 429 | } | 429 | } |
| 430 | 430 | ||
| 431 | pub fn Log2Int(comptime T: type) type { | 431 | pub fn Log2Int(comptime T: type) type { |
| ... | @@ -532,8 +532,8 @@ test "math.absInt" { | ... | @@ -532,8 +532,8 @@ test "math.absInt" { |
| 532 | comptime testAbsInt(); | 532 | comptime testAbsInt(); |
| 533 | } | 533 | } |
| 534 | fn testAbsInt() void { | 534 | fn testAbsInt() void { |
| 535 | testing.expect((absInt(i32(-10)) catch unreachable) == 10); | 535 | testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10); |
| 536 | testing.expect((absInt(i32(10)) catch unreachable) == 10); | 536 | testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10); |
| 537 | } | 537 | } |
| 538 | 538 | ||
| 539 | pub const absFloat = fabs; | 539 | pub const absFloat = fabs; |
| ... | @@ -543,8 +543,8 @@ test "math.absFloat" { | ... | @@ -543,8 +543,8 @@ test "math.absFloat" { |
| 543 | comptime testAbsFloat(); | 543 | comptime testAbsFloat(); |
| 544 | } | 544 | } |
| 545 | fn testAbsFloat() void { | 545 | fn testAbsFloat() void { |
| 546 | testing.expect(absFloat(f32(-10.05)) == 10.05); | 546 | testing.expect(absFloat(@as(f32, -10.05)) == 10.05); |
| 547 | testing.expect(absFloat(f32(10.05)) == 10.05); | 547 | testing.expect(absFloat(@as(f32, 10.05)) == 10.05); |
| 548 | } | 548 | } |
| 549 | 549 | ||
| 550 | pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { | 550 | pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { |
| ... | @@ -679,14 +679,14 @@ pub fn absCast(x: var) t: { | ... | @@ -679,14 +679,14 @@ pub fn absCast(x: var) t: { |
| 679 | } | 679 | } |
| 680 | 680 | ||
| 681 | test "math.absCast" { | 681 | test "math.absCast" { |
| 682 | testing.expect(absCast(i32(-999)) == 999); | 682 | testing.expect(absCast(@as(i32, -999)) == 999); |
| 683 | testing.expect(@typeOf(absCast(i32(-999))) == u32); | 683 | testing.expect(@typeOf(absCast(@as(i32, -999))) == u32); |
| 684 | 684 | ||
| 685 | testing.expect(absCast(i32(999)) == 999); | 685 | testing.expect(absCast(@as(i32, 999)) == 999); |
| 686 | testing.expect(@typeOf(absCast(i32(999))) == u32); | 686 | testing.expect(@typeOf(absCast(@as(i32, 999))) == u32); |
| 687 | 687 | ||
| 688 | testing.expect(absCast(i32(minInt(i32))) == -minInt(i32)); | 688 | testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32)); |
| 689 | testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32); | 689 | testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32); |
| 690 | 690 | ||
| 691 | testing.expect(absCast(-999) == 999); | 691 | testing.expect(absCast(-999) == 999); |
| 692 | } | 692 | } |
| ... | @@ -705,13 +705,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { | ... | @@ -705,13 +705,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { |
| 705 | } | 705 | } |
| 706 | 706 | ||
| 707 | test "math.negateCast" { | 707 | test "math.negateCast" { |
| 708 | testing.expect((negateCast(u32(999)) catch unreachable) == -999); | 708 | testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999); |
| 709 | testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32); | 709 | testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); |
| 710 | 710 | ||
| 711 | testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32)); | 711 | testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32)); |
| 712 | testing.expect(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32); | 712 | testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32); |
| 713 | 713 | ||
| 714 | testing.expectError(error.Overflow, negateCast(u32(maxInt(i32) + 10))); | 714 | testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10))); |
| 715 | } | 715 | } |
| 716 | 716 | ||
| 717 | /// Cast an integer to a different integer type. If the value doesn't fit, | 717 | /// Cast an integer to a different integer type. If the value doesn't fit, |
| ... | @@ -729,13 +729,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) { | ... | @@ -729,13 +729,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) { |
| 729 | } | 729 | } |
| 730 | 730 | ||
| 731 | test "math.cast" { | 731 | test "math.cast" { |
| 732 | testing.expectError(error.Overflow, cast(u8, u32(300))); | 732 | testing.expectError(error.Overflow, cast(u8, @as(u32, 300))); |
| 733 | testing.expectError(error.Overflow, cast(i8, i32(-200))); | 733 | testing.expectError(error.Overflow, cast(i8, @as(i32, -200))); |
| 734 | testing.expectError(error.Overflow, cast(u8, i8(-1))); | 734 | testing.expectError(error.Overflow, cast(u8, @as(i8, -1))); |
| 735 | testing.expectError(error.Overflow, cast(u64, i8(-1))); | 735 | testing.expectError(error.Overflow, cast(u64, @as(i8, -1))); |
| 736 | 736 | ||
| 737 | testing.expect((try cast(u8, u32(255))) == u8(255)); | 737 | testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255)); |
| 738 | testing.expect(@typeOf(try cast(u8, u32(255))) == u8); | 738 | testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8); |
| 739 | } | 739 | } |
| 740 | 740 | ||
| 741 | pub const AlignCastError = error{UnalignedMemory}; | 741 | pub const AlignCastError = error{UnalignedMemory}; |
| ... | @@ -786,9 +786,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T | ... | @@ -786,9 +786,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T |
| 786 | comptime assert(@typeId(T) == builtin.TypeId.Int); | 786 | comptime assert(@typeId(T) == builtin.TypeId.Int); |
| 787 | comptime assert(!T.is_signed); | 787 | comptime assert(!T.is_signed); |
| 788 | assert(value != 0); | 788 | assert(value != 0); |
| 789 | comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1); | 789 | comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1); |
| 790 | comptime const shiftType = std.math.Log2Int(promotedType); | 790 | comptime const shiftType = std.math.Log2Int(PromotedType); |
| 791 | return promotedType(1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1)); | 791 | return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1)); |
| 792 | } | 792 | } |
| 793 | 793 | ||
| 794 | /// Returns the next power of two (if the value is not already a power of two). | 794 | /// Returns the next power of two (if the value is not already a power of two). |
| ... | @@ -797,8 +797,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T | ... | @@ -797,8 +797,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T |
| 797 | pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { | 797 | pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { |
| 798 | comptime assert(@typeId(T) == builtin.TypeId.Int); | 798 | comptime assert(@typeId(T) == builtin.TypeId.Int); |
| 799 | comptime assert(!T.is_signed); | 799 | comptime assert(!T.is_signed); |
| 800 | comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1); | 800 | comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1); |
| 801 | comptime const overflowBit = promotedType(1) << T.bit_count; | 801 | comptime const overflowBit = @as(PromotedType, 1) << T.bit_count; |
| 802 | var x = ceilPowerOfTwoPromote(T, value); | 802 | var x = ceilPowerOfTwoPromote(T, value); |
| 803 | if (overflowBit & x != 0) { | 803 | if (overflowBit & x != 0) { |
| 804 | return error.Overflow; | 804 | return error.Overflow; |
| ... | @@ -812,15 +812,15 @@ test "math.ceilPowerOfTwoPromote" { | ... | @@ -812,15 +812,15 @@ test "math.ceilPowerOfTwoPromote" { |
| 812 | } | 812 | } |
| 813 | 813 | ||
| 814 | fn testCeilPowerOfTwoPromote() void { | 814 | fn testCeilPowerOfTwoPromote() void { |
| 815 | testing.expectEqual(u33(1), ceilPowerOfTwoPromote(u32, 1)); | 815 | testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1)); |
| 816 | testing.expectEqual(u33(2), ceilPowerOfTwoPromote(u32, 2)); | 816 | testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2)); |
| 817 | testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 63)); | 817 | testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63)); |
| 818 | testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 64)); | 818 | testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64)); |
| 819 | testing.expectEqual(u33(128), ceilPowerOfTwoPromote(u32, 65)); | 819 | testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65)); |
| 820 | testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 7)); | 820 | testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7)); |
| 821 | testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 8)); | 821 | testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8)); |
| 822 | testing.expectEqual(u6(16), ceilPowerOfTwoPromote(u5, 9)); | 822 | testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9)); |
| 823 | testing.expectEqual(u5(16), ceilPowerOfTwoPromote(u4, 9)); | 823 | testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9)); |
| 824 | } | 824 | } |
| 825 | 825 | ||
| 826 | test "math.ceilPowerOfTwo" { | 826 | test "math.ceilPowerOfTwo" { |
| ... | @@ -829,14 +829,14 @@ test "math.ceilPowerOfTwo" { | ... | @@ -829,14 +829,14 @@ test "math.ceilPowerOfTwo" { |
| 829 | } | 829 | } |
| 830 | 830 | ||
| 831 | fn testCeilPowerOfTwo() !void { | 831 | fn testCeilPowerOfTwo() !void { |
| 832 | testing.expectEqual(u32(1), try ceilPowerOfTwo(u32, 1)); | 832 | testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1)); |
| 833 | testing.expectEqual(u32(2), try ceilPowerOfTwo(u32, 2)); | 833 | testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2)); |
| 834 | testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 63)); | 834 | testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63)); |
| 835 | testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 64)); | 835 | testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64)); |
| 836 | testing.expectEqual(u32(128), try ceilPowerOfTwo(u32, 65)); | 836 | testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65)); |
| 837 | testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 7)); | 837 | testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7)); |
| 838 | testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 8)); | 838 | testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8)); |
| 839 | testing.expectEqual(u5(16), try ceilPowerOfTwo(u5, 9)); | 839 | testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9)); |
| 840 | testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9)); | 840 | testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9)); |
| 841 | } | 841 | } |
| 842 | 842 | ||
| ... | @@ -848,7 +848,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) { | ... | @@ -848,7 +848,7 @@ pub fn log2_int(comptime T: type, x: T) Log2Int(T) { |
| 848 | pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) { | 848 | pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) { |
| 849 | assert(x != 0); | 849 | assert(x != 0); |
| 850 | const log2_val = log2_int(T, x); | 850 | const log2_val = log2_int(T, x); |
| 851 | if (T(1) << log2_val == x) | 851 | if (@as(T, 1) << log2_val == x) |
| 852 | return log2_val; | 852 | return log2_val; |
| 853 | return log2_val + 1; | 853 | return log2_val + 1; |
| 854 | } | 854 | } |
| ... | @@ -870,8 +870,8 @@ pub fn lossyCast(comptime T: type, value: var) T { | ... | @@ -870,8 +870,8 @@ pub fn lossyCast(comptime T: type, value: var) T { |
| 870 | switch (@typeInfo(@typeOf(value))) { | 870 | switch (@typeInfo(@typeOf(value))) { |
| 871 | builtin.TypeId.Int => return @intToFloat(T, value), | 871 | builtin.TypeId.Int => return @intToFloat(T, value), |
| 872 | builtin.TypeId.Float => return @floatCast(T, value), | 872 | builtin.TypeId.Float => return @floatCast(T, value), |
| 873 | builtin.TypeId.ComptimeInt => return T(value), | 873 | builtin.TypeId.ComptimeInt => return @as(T, value), |
| 874 | builtin.TypeId.ComptimeFloat => return T(value), | 874 | builtin.TypeId.ComptimeFloat => return @as(T, value), |
| 875 | else => @compileError("bad type"), | 875 | else => @compileError("bad type"), |
| 876 | } | 876 | } |
| 877 | } | 877 | } |
| ... | @@ -944,7 +944,7 @@ test "max value type" { | ... | @@ -944,7 +944,7 @@ test "max value type" { |
| 944 | 944 | ||
| 945 | pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) { | 945 | pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) { |
| 946 | const ResultInt = @IntType(T.is_signed, T.bit_count * 2); | 946 | const ResultInt = @IntType(T.is_signed, T.bit_count * 2); |
| 947 | return ResultInt(a) * ResultInt(b); | 947 | return @as(ResultInt, a) * @as(ResultInt, b); |
| 948 | } | 948 | } |
| 949 | 949 | ||
| 950 | test "math.mulWide" { | 950 | test "math.mulWide" { |
lib/std/math/acos.zig+2-2| ... | @@ -149,8 +149,8 @@ fn acos64(x: f64) f64 { | ... | @@ -149,8 +149,8 @@ fn acos64(x: f64) f64 { |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | test "math.acos" { | 151 | test "math.acos" { |
| 152 | expect(acos(f32(0.0)) == acos32(0.0)); | 152 | expect(acos(@as(f32, 0.0)) == acos32(0.0)); |
| 153 | expect(acos(f64(0.0)) == acos64(0.0)); | 153 | expect(acos(@as(f64, 0.0)) == acos64(0.0)); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | test "math.acos32" { | 156 | test "math.acos32" { |
lib/std/math/acosh.zig+2-2| ... | @@ -61,8 +61,8 @@ fn acosh64(x: f64) f64 { | ... | @@ -61,8 +61,8 @@ fn acosh64(x: f64) f64 { |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | test "math.acosh" { | 63 | test "math.acosh" { |
| 64 | expect(acosh(f32(1.5)) == acosh32(1.5)); | 64 | expect(acosh(@as(f32, 1.5)) == acosh32(1.5)); |
| 65 | expect(acosh(f64(1.5)) == acosh64(1.5)); | 65 | expect(acosh(@as(f64, 1.5)) == acosh64(1.5)); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | test "math.acosh32" { | 68 | test "math.acosh32" { |
lib/std/math/asin.zig+2-2| ... | @@ -142,8 +142,8 @@ fn asin64(x: f64) f64 { | ... | @@ -142,8 +142,8 @@ fn asin64(x: f64) f64 { |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | test "math.asin" { | 144 | test "math.asin" { |
| 145 | expect(asin(f32(0.0)) == asin32(0.0)); | 145 | expect(asin(@as(f32, 0.0)) == asin32(0.0)); |
| 146 | expect(asin(f64(0.0)) == asin64(0.0)); | 146 | expect(asin(@as(f64, 0.0)) == asin64(0.0)); |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | test "math.asin32" { | 149 | test "math.asin32" { |
lib/std/math/asinh.zig+2-2| ... | @@ -89,8 +89,8 @@ fn asinh64(x: f64) f64 { | ... | @@ -89,8 +89,8 @@ fn asinh64(x: f64) f64 { |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | test "math.asinh" { | 91 | test "math.asinh" { |
| 92 | expect(asinh(f32(0.0)) == asinh32(0.0)); | 92 | expect(asinh(@as(f32, 0.0)) == asinh32(0.0)); |
| 93 | expect(asinh(f64(0.0)) == asinh64(0.0)); | 93 | expect(asinh(@as(f64, 0.0)) == asinh64(0.0)); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | test "math.asinh32" { | 96 | test "math.asinh32" { |
lib/std/math/atan.zig+2-2| ... | @@ -212,8 +212,8 @@ fn atan64(x_: f64) f64 { | ... | @@ -212,8 +212,8 @@ fn atan64(x_: f64) f64 { |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | test "math.atan" { | 214 | test "math.atan" { |
| 215 | expect(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2))); | 215 | expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2))); |
| 216 | expect(atan(f64(0.2)) == atan64(0.2)); | 216 | expect(atan(@as(f64, 0.2)) == atan64(0.2)); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | test "math.atan32" { | 219 | test "math.atan32" { |
lib/std/math/atanh.zig+2-2| ... | @@ -84,8 +84,8 @@ fn atanh_64(x: f64) f64 { | ... | @@ -84,8 +84,8 @@ fn atanh_64(x: f64) f64 { |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | test "math.atanh" { | 86 | test "math.atanh" { |
| 87 | expect(atanh(f32(0.0)) == atanh_32(0.0)); | 87 | expect(atanh(@as(f32, 0.0)) == atanh_32(0.0)); |
| 88 | expect(atanh(f64(0.0)) == atanh_64(0.0)); | 88 | expect(atanh(@as(f64, 0.0)) == atanh_64(0.0)); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | test "math.atanh_32" { | 91 | test "math.atanh_32" { |
lib/std/math/big/int.zig+11-11| ... | @@ -261,7 +261,7 @@ pub const Int = struct { | ... | @@ -261,7 +261,7 @@ pub const Int = struct { |
| 261 | /// the minus sign. This is used for determining the number of characters needed to print the | 261 | /// the minus sign. This is used for determining the number of characters needed to print the |
| 262 | /// value. It is inexact and may exceed the given value by ~1-2 bytes. | 262 | /// value. It is inexact and may exceed the given value by ~1-2 bytes. |
| 263 | pub fn sizeInBase(self: Int, base: usize) usize { | 263 | pub fn sizeInBase(self: Int, base: usize) usize { |
| 264 | const bit_count = usize(@boolToInt(!self.isPositive())) + self.bitCountAbs(); | 264 | const bit_count = @as(usize, @boolToInt(!self.isPositive())) + self.bitCountAbs(); |
| 265 | return (bit_count / math.log2(base)) + 1; | 265 | return (bit_count / math.log2(base)) + 1; |
| 266 | } | 266 | } |
| 267 | 267 | ||
| ... | @@ -281,7 +281,7 @@ pub const Int = struct { | ... | @@ -281,7 +281,7 @@ pub const Int = struct { |
| 281 | var w_value: UT = if (value < 0) @intCast(UT, -value) else @intCast(UT, value); | 281 | var w_value: UT = if (value < 0) @intCast(UT, -value) else @intCast(UT, value); |
| 282 | 282 | ||
| 283 | if (info.bits <= Limb.bit_count) { | 283 | if (info.bits <= Limb.bit_count) { |
| 284 | self.limbs[0] = Limb(w_value); | 284 | self.limbs[0] = @as(Limb, w_value); |
| 285 | self.metadata += 1; | 285 | self.metadata += 1; |
| 286 | } else { | 286 | } else { |
| 287 | var i: usize = 0; | 287 | var i: usize = 0; |
| ... | @@ -453,7 +453,7 @@ pub const Int = struct { | ... | @@ -453,7 +453,7 @@ pub const Int = struct { |
| 453 | for (self.limbs[0..self.len()]) |limb| { | 453 | for (self.limbs[0..self.len()]) |limb| { |
| 454 | var shift: usize = 0; | 454 | var shift: usize = 0; |
| 455 | while (shift < Limb.bit_count) : (shift += base_shift) { | 455 | while (shift < Limb.bit_count) : (shift += base_shift) { |
| 456 | const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & Limb(base - 1)); | 456 | const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & @as(Limb, base - 1)); |
| 457 | const ch = try digitToChar(r, base); | 457 | const ch = try digitToChar(r, base); |
| 458 | try digits.append(ch); | 458 | try digits.append(ch); |
| 459 | } | 459 | } |
| ... | @@ -560,7 +560,7 @@ pub const Int = struct { | ... | @@ -560,7 +560,7 @@ pub const Int = struct { |
| 560 | /// Returns -1, 0, 1 if a < b, a == b or a > b respectively. | 560 | /// Returns -1, 0, 1 if a < b, a == b or a > b respectively. |
| 561 | pub fn cmp(a: Int, b: Int) i8 { | 561 | pub fn cmp(a: Int, b: Int) i8 { |
| 562 | if (a.isPositive() != b.isPositive()) { | 562 | if (a.isPositive() != b.isPositive()) { |
| 563 | return if (a.isPositive()) i8(1) else -1; | 563 | return if (a.isPositive()) @as(i8, 1) else -1; |
| 564 | } else { | 564 | } else { |
| 565 | const r = cmpAbs(a, b); | 565 | const r = cmpAbs(a, b); |
| 566 | return if (a.isPositive()) r else -r; | 566 | return if (a.isPositive()) r else -r; |
| ... | @@ -785,7 +785,7 @@ pub const Int = struct { | ... | @@ -785,7 +785,7 @@ pub const Int = struct { |
| 785 | const c1: Limb = @boolToInt(@addWithOverflow(Limb, a, carry.*, &r1)); | 785 | const c1: Limb = @boolToInt(@addWithOverflow(Limb, a, carry.*, &r1)); |
| 786 | 786 | ||
| 787 | // r2 = b * c | 787 | // r2 = b * c |
| 788 | const bc = DoubleLimb(math.mulWide(Limb, b, c)); | 788 | const bc = @as(DoubleLimb, math.mulWide(Limb, b, c)); |
| 789 | const r2 = @truncate(Limb, bc); | 789 | const r2 = @truncate(Limb, bc); |
| 790 | const c2 = @truncate(Limb, bc >> Limb.bit_count); | 790 | const c2 = @truncate(Limb, bc >> Limb.bit_count); |
| 791 | 791 | ||
| ... | @@ -1084,7 +1084,7 @@ pub const Int = struct { | ... | @@ -1084,7 +1084,7 @@ pub const Int = struct { |
| 1084 | rem.* = 0; | 1084 | rem.* = 0; |
| 1085 | for (a) |_, ri| { | 1085 | for (a) |_, ri| { |
| 1086 | const i = a.len - ri - 1; | 1086 | const i = a.len - ri - 1; |
| 1087 | const pdiv = ((DoubleLimb(rem.*) << Limb.bit_count) | a[i]); | 1087 | const pdiv = ((@as(DoubleLimb, rem.*) << Limb.bit_count) | a[i]); |
| 1088 | 1088 | ||
| 1089 | if (pdiv == 0) { | 1089 | if (pdiv == 0) { |
| 1090 | quo[i] = 0; | 1090 | quo[i] = 0; |
| ... | @@ -1143,9 +1143,9 @@ pub const Int = struct { | ... | @@ -1143,9 +1143,9 @@ pub const Int = struct { |
| 1143 | if (x.limbs[i] == y.limbs[t]) { | 1143 | if (x.limbs[i] == y.limbs[t]) { |
| 1144 | q.limbs[i - t - 1] = maxInt(Limb); | 1144 | q.limbs[i - t - 1] = maxInt(Limb); |
| 1145 | } else { | 1145 | } else { |
| 1146 | const num = (DoubleLimb(x.limbs[i]) << Limb.bit_count) | DoubleLimb(x.limbs[i - 1]); | 1146 | const num = (@as(DoubleLimb, x.limbs[i]) << Limb.bit_count) | @as(DoubleLimb, x.limbs[i - 1]); |
| 1147 | const z = @intCast(Limb, num / DoubleLimb(y.limbs[t])); | 1147 | const z = @intCast(Limb, num / @as(DoubleLimb, y.limbs[t])); |
| 1148 | q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else Limb(z); | 1148 | q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else @as(Limb, z); |
| 1149 | } | 1149 | } |
| 1150 | 1150 | ||
| 1151 | // 3.2 | 1151 | // 3.2 |
| ... | @@ -1362,7 +1362,7 @@ test "big.int comptime_int set" { | ... | @@ -1362,7 +1362,7 @@ test "big.int comptime_int set" { |
| 1362 | 1362 | ||
| 1363 | comptime var i: usize = 0; | 1363 | comptime var i: usize = 0; |
| 1364 | inline while (i < s_limb_count) : (i += 1) { | 1364 | inline while (i < s_limb_count) : (i += 1) { |
| 1365 | const result = Limb(s & maxInt(Limb)); | 1365 | const result = @as(Limb, s & maxInt(Limb)); |
| 1366 | s >>= Limb.bit_count / 2; | 1366 | s >>= Limb.bit_count / 2; |
| 1367 | s >>= Limb.bit_count / 2; | 1367 | s >>= Limb.bit_count / 2; |
| 1368 | testing.expect(a.limbs[i] == result); | 1368 | testing.expect(a.limbs[i] == result); |
| ... | @@ -1377,7 +1377,7 @@ test "big.int comptime_int set negative" { | ... | @@ -1377,7 +1377,7 @@ test "big.int comptime_int set negative" { |
| 1377 | } | 1377 | } |
| 1378 | 1378 | ||
| 1379 | test "big.int int set unaligned small" { | 1379 | test "big.int int set unaligned small" { |
| 1380 | var a = try Int.initSet(al, u7(45)); | 1380 | var a = try Int.initSet(al, @as(u7, 45)); |
| 1381 | 1381 | ||
| 1382 | testing.expect(a.limbs[0] == 45); | 1382 | testing.expect(a.limbs[0] == 45); |
| 1383 | testing.expect(a.isPositive() == true); | 1383 | testing.expect(a.isPositive() == true); |
lib/std/math/cbrt.zig+5-5| ... | @@ -54,11 +54,11 @@ fn cbrt32(x: f32) f32 { | ... | @@ -54,11 +54,11 @@ fn cbrt32(x: f32) f32 { |
| 54 | // first step newton to 16 bits | 54 | // first step newton to 16 bits |
| 55 | var t: f64 = @bitCast(f32, u); | 55 | var t: f64 = @bitCast(f32, u); |
| 56 | var r: f64 = t * t * t; | 56 | var r: f64 = t * t * t; |
| 57 | t = t * (f64(x) + x + r) / (x + r + r); | 57 | t = t * (@as(f64, x) + x + r) / (x + r + r); |
| 58 | 58 | ||
| 59 | // second step newton to 47 bits | 59 | // second step newton to 47 bits |
| 60 | r = t * t * t; | 60 | r = t * t * t; |
| 61 | t = t * (f64(x) + x + r) / (x + r + r); | 61 | t = t * (@as(f64, x) + x + r) / (x + r + r); |
| 62 | 62 | ||
| 63 | return @floatCast(f32, t); | 63 | return @floatCast(f32, t); |
| 64 | } | 64 | } |
| ... | @@ -97,7 +97,7 @@ fn cbrt64(x: f64) f64 { | ... | @@ -97,7 +97,7 @@ fn cbrt64(x: f64) f64 { |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | u &= 1 << 63; | 99 | u &= 1 << 63; |
| 100 | u |= u64(hx) << 32; | 100 | u |= @as(u64, hx) << 32; |
| 101 | var t = @bitCast(f64, u); | 101 | var t = @bitCast(f64, u); |
| 102 | 102 | ||
| 103 | // cbrt to 23 bits | 103 | // cbrt to 23 bits |
| ... | @@ -120,8 +120,8 @@ fn cbrt64(x: f64) f64 { | ... | @@ -120,8 +120,8 @@ fn cbrt64(x: f64) f64 { |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | test "math.cbrt" { | 122 | test "math.cbrt" { |
| 123 | expect(cbrt(f32(0.0)) == cbrt32(0.0)); | 123 | expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0)); |
| 124 | expect(cbrt(f64(0.0)) == cbrt64(0.0)); | 124 | expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0)); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | test "math.cbrt32" { | 127 | test "math.cbrt32" { |
lib/std/math/ceil.zig+3-3| ... | @@ -37,7 +37,7 @@ fn ceil32(x: f32) f32 { | ... | @@ -37,7 +37,7 @@ fn ceil32(x: f32) f32 { |
| 37 | if (e >= 23) { | 37 | if (e >= 23) { |
| 38 | return x; | 38 | return x; |
| 39 | } else if (e >= 0) { | 39 | } else if (e >= 0) { |
| 40 | m = u32(0x007FFFFF) >> @intCast(u5, e); | 40 | m = @as(u32, 0x007FFFFF) >> @intCast(u5, e); |
| 41 | if (u & m == 0) { | 41 | if (u & m == 0) { |
| 42 | return x; | 42 | return x; |
| 43 | } | 43 | } |
| ... | @@ -87,8 +87,8 @@ fn ceil64(x: f64) f64 { | ... | @@ -87,8 +87,8 @@ fn ceil64(x: f64) f64 { |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | test "math.ceil" { | 89 | test "math.ceil" { |
| 90 | expect(ceil(f32(0.0)) == ceil32(0.0)); | 90 | expect(ceil(@as(f32, 0.0)) == ceil32(0.0)); |
| 91 | expect(ceil(f64(0.0)) == ceil64(0.0)); | 91 | expect(ceil(@as(f64, 0.0)) == ceil64(0.0)); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | test "math.ceil32" { | 94 | test "math.ceil32" { |
lib/std/math/complex.zig+4-4| ... | @@ -133,8 +133,8 @@ test "complex.div" { | ... | @@ -133,8 +133,8 @@ test "complex.div" { |
| 133 | const b = Complex(f32).new(2, 7); | 133 | const b = Complex(f32).new(2, 7); |
| 134 | const c = a.div(b); | 134 | const c = a.div(b); |
| 135 | 135 | ||
| 136 | testing.expect(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and | 136 | testing.expect(math.approxEq(f32, c.re, @as(f32, 31) / 53, epsilon) and |
| 137 | math.approxEq(f32, c.im, f32(-29) / 53, epsilon)); | 137 | math.approxEq(f32, c.im, @as(f32, -29) / 53, epsilon)); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | test "complex.conjugate" { | 140 | test "complex.conjugate" { |
| ... | @@ -148,8 +148,8 @@ test "complex.reciprocal" { | ... | @@ -148,8 +148,8 @@ test "complex.reciprocal" { |
| 148 | const a = Complex(f32).new(5, 3); | 148 | const a = Complex(f32).new(5, 3); |
| 149 | const c = a.reciprocal(); | 149 | const c = a.reciprocal(); |
| 150 | 150 | ||
| 151 | testing.expect(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and | 151 | testing.expect(math.approxEq(f32, c.re, @as(f32, 5) / 34, epsilon) and |
| 152 | math.approxEq(f32, c.im, f32(-3) / 34, epsilon)); | 152 | math.approxEq(f32, c.im, @as(f32, -3) / 34, epsilon)); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | test "complex.magnitude" { | 155 | test "complex.magnitude" { |
lib/std/math/complex/acos.zig+1-1| ... | @@ -8,7 +8,7 @@ const Complex = cmath.Complex; | ... | @@ -8,7 +8,7 @@ const Complex = cmath.Complex; |
| 8 | pub fn acos(z: var) Complex(@typeOf(z.re)) { | 8 | pub fn acos(z: var) Complex(@typeOf(z.re)) { |
| 9 | const T = @typeOf(z.re); | 9 | const T = @typeOf(z.re); |
| 10 | const q = cmath.asin(z); | 10 | const q = cmath.asin(z); |
| 11 | return Complex(T).new(T(math.pi) / 2 - q.re, -q.im); | 11 | return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im); |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | const epsilon = 0.0001; | 14 | const epsilon = 0.0001; |
lib/std/math/complex/ldexp.zig+2-2| ... | @@ -59,13 +59,13 @@ fn frexp_exp64(x: f64, expt: *i32) f64 { | ... | @@ -59,13 +59,13 @@ fn frexp_exp64(x: f64, expt: *i32) f64 { |
| 59 | expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k; | 59 | expt.* = @intCast(i32, hx >> 20) - (0x3ff + 1023) + k; |
| 60 | 60 | ||
| 61 | const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20); | 61 | const high_word = (hx & 0xfffff) | ((0x3ff + 1023) << 20); |
| 62 | return @bitCast(f64, (u64(high_word) << 32) | lx); | 62 | return @bitCast(f64, (@as(u64, high_word) << 32) | lx); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) { | 65 | fn ldexp_cexp64(z: Complex(f64), expt: i32) Complex(f64) { |
| 66 | var ex_expt: i32 = undefined; | 66 | var ex_expt: i32 = undefined; |
| 67 | const exp_x = frexp_exp64(z.re, &ex_expt); | 67 | const exp_x = frexp_exp64(z.re, &ex_expt); |
| 68 | const exptf = i64(expt + ex_expt); | 68 | const exptf = @as(i64, expt + ex_expt); |
| 69 | 69 | ||
| 70 | const half_expt1 = @divTrunc(exptf, 2); | 70 | const half_expt1 = @divTrunc(exptf, 2); |
| 71 | const scale1 = @bitCast(f64, (0x3ff + half_expt1) << 20); | 71 | const scale1 = @bitCast(f64, (0x3ff + half_expt1) << 20); |
lib/std/math/complex/sqrt.zig+2-2| ... | @@ -52,8 +52,8 @@ fn sqrt32(z: Complex(f32)) Complex(f32) { | ... | @@ -52,8 +52,8 @@ fn sqrt32(z: Complex(f32)) Complex(f32) { |
| 52 | // y = nan special case is handled fine below | 52 | // y = nan special case is handled fine below |
| 53 | 53 | ||
| 54 | // double-precision avoids overflow with correct rounding. | 54 | // double-precision avoids overflow with correct rounding. |
| 55 | const dx = f64(x); | 55 | const dx = @as(f64, x); |
| 56 | const dy = f64(y); | 56 | const dy = @as(f64, y); |
| 57 | 57 | ||
| 58 | if (dx >= 0) { | 58 | if (dx >= 0) { |
| 59 | const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5); | 59 | const t = math.sqrt((dx + math.hypot(f64, dx, dy)) * 0.5); |
lib/std/math/complex/tanh.zig+1-1| ... | @@ -76,7 +76,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) { | ... | @@ -76,7 +76,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) { |
| 76 | return Complex(f64).new(x, r); | 76 | return Complex(f64).new(x, r); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | const xx = @bitCast(f64, (u64(hx - 0x40000000) << 32) | lx); | 79 | const xx = @bitCast(f64, (@as(u64, hx - 0x40000000) << 32) | lx); |
| 80 | const r = if (math.isInf(y)) y else math.sin(y) * math.cos(y); | 80 | const r = if (math.isInf(y)) y else math.sin(y) * math.cos(y); |
| 81 | return Complex(f64).new(xx, math.copysign(f64, 0, r)); | 81 | return Complex(f64).new(xx, math.copysign(f64, 0, r)); |
| 82 | } | 82 | } |
lib/std/math/copysign.zig+3-3| ... | @@ -24,7 +24,7 @@ fn copysign16(x: f16, y: f16) f16 { | ... | @@ -24,7 +24,7 @@ fn copysign16(x: f16, y: f16) f16 { |
| 24 | const uy = @bitCast(u16, y); | 24 | const uy = @bitCast(u16, y); |
| 25 | 25 | ||
| 26 | const h1 = ux & (maxInt(u16) / 2); | 26 | const h1 = ux & (maxInt(u16) / 2); |
| 27 | const h2 = uy & (u16(1) << 15); | 27 | const h2 = uy & (@as(u16, 1) << 15); |
| 28 | return @bitCast(f16, h1 | h2); | 28 | return @bitCast(f16, h1 | h2); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| ... | @@ -33,7 +33,7 @@ fn copysign32(x: f32, y: f32) f32 { | ... | @@ -33,7 +33,7 @@ fn copysign32(x: f32, y: f32) f32 { |
| 33 | const uy = @bitCast(u32, y); | 33 | const uy = @bitCast(u32, y); |
| 34 | 34 | ||
| 35 | const h1 = ux & (maxInt(u32) / 2); | 35 | const h1 = ux & (maxInt(u32) / 2); |
| 36 | const h2 = uy & (u32(1) << 31); | 36 | const h2 = uy & (@as(u32, 1) << 31); |
| 37 | return @bitCast(f32, h1 | h2); | 37 | return @bitCast(f32, h1 | h2); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| ... | @@ -42,7 +42,7 @@ fn copysign64(x: f64, y: f64) f64 { | ... | @@ -42,7 +42,7 @@ fn copysign64(x: f64, y: f64) f64 { |
| 42 | const uy = @bitCast(u64, y); | 42 | const uy = @bitCast(u64, y); |
| 43 | 43 | ||
| 44 | const h1 = ux & (maxInt(u64) / 2); | 44 | const h1 = ux & (maxInt(u64) / 2); |
| 45 | const h2 = uy & (u64(1) << 63); | 45 | const h2 = uy & (@as(u64, 1) << 63); |
| 46 | return @bitCast(f64, h1 | h2); | 46 | return @bitCast(f64, h1 | h2); |
| 47 | } | 47 | } |
| 48 | 48 |
lib/std/math/cos.zig+2-2| ... | @@ -83,8 +83,8 @@ fn cos_(comptime T: type, x_: T) T { | ... | @@ -83,8 +83,8 @@ fn cos_(comptime T: type, x_: T) T { |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | test "math.cos" { | 85 | test "math.cos" { |
| 86 | expect(cos(f32(0.0)) == cos_(f32, 0.0)); | 86 | expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0)); |
| 87 | expect(cos(f64(0.0)) == cos_(f64, 0.0)); | 87 | expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0)); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | test "math.cos32" { | 90 | test "math.cos32" { |
lib/std/math/cosh.zig+2-2| ... | @@ -88,8 +88,8 @@ fn cosh64(x: f64) f64 { | ... | @@ -88,8 +88,8 @@ fn cosh64(x: f64) f64 { |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | test "math.cosh" { | 90 | test "math.cosh" { |
| 91 | expect(cosh(f32(1.5)) == cosh32(1.5)); | 91 | expect(cosh(@as(f32, 1.5)) == cosh32(1.5)); |
| 92 | expect(cosh(f64(1.5)) == cosh64(1.5)); | 92 | expect(cosh(@as(f64, 1.5)) == cosh64(1.5)); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | test "math.cosh32" { | 95 | test "math.cosh32" { |
lib/std/math/exp.zig+3-3| ... | @@ -134,7 +134,7 @@ fn exp64(x_: f64) f64 { | ... | @@ -134,7 +134,7 @@ fn exp64(x_: f64) f64 { |
| 134 | } | 134 | } |
| 135 | if (x < -708.39641853226410622) { | 135 | if (x < -708.39641853226410622) { |
| 136 | // underflow if x != -inf | 136 | // underflow if x != -inf |
| 137 | // math.forceEval(f32(-0x1.0p-149 / x)); | 137 | // math.forceEval(@as(f32, -0x1.0p-149 / x)); |
| 138 | if (x < -745.13321910194110842) { | 138 | if (x < -745.13321910194110842) { |
| 139 | return 0; | 139 | return 0; |
| 140 | } | 140 | } |
| ... | @@ -183,8 +183,8 @@ fn exp64(x_: f64) f64 { | ... | @@ -183,8 +183,8 @@ fn exp64(x_: f64) f64 { |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | test "math.exp" { | 185 | test "math.exp" { |
| 186 | assert(exp(f32(0.0)) == exp32(0.0)); | 186 | assert(exp(@as(f32, 0.0)) == exp32(0.0)); |
| 187 | assert(exp(f64(0.0)) == exp64(0.0)); | 187 | assert(exp(@as(f64, 0.0)) == exp64(0.0)); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | test "math.exp32" { | 190 | test "math.exp32" { |
lib/std/math/exp2.zig+3-3| ... | @@ -85,7 +85,7 @@ fn exp2_32(x: f32) f32 { | ... | @@ -85,7 +85,7 @@ fn exp2_32(x: f32) f32 { |
| 85 | const k = i_0 / tblsiz; | 85 | const k = i_0 / tblsiz; |
| 86 | // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the | 86 | // NOTE: musl relies on undefined overflow shift behaviour. Appears that this produces the |
| 87 | // intended result but should confirm how GCC/Clang handle this to ensure. | 87 | // intended result but should confirm how GCC/Clang handle this to ensure. |
| 88 | const uk = @bitCast(f64, u64(0x3FF + k) << 52); | 88 | const uk = @bitCast(f64, @as(u64, 0x3FF + k) << 52); |
| 89 | i_0 &= tblsiz - 1; | 89 | i_0 &= tblsiz - 1; |
| 90 | uf -= redux; | 90 | uf -= redux; |
| 91 | 91 | ||
| ... | @@ -421,8 +421,8 @@ fn exp2_64(x: f64) f64 { | ... | @@ -421,8 +421,8 @@ fn exp2_64(x: f64) f64 { |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | test "math.exp2" { | 423 | test "math.exp2" { |
| 424 | expect(exp2(f32(0.8923)) == exp2_32(0.8923)); | 424 | expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923)); |
| 425 | expect(exp2(f64(0.8923)) == exp2_64(0.8923)); | 425 | expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923)); |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 428 | test "math.exp2_32" { | 428 | test "math.exp2_32" { |
lib/std/math/expm1.zig+2-2| ... | @@ -287,8 +287,8 @@ fn expm1_64(x_: f64) f64 { | ... | @@ -287,8 +287,8 @@ fn expm1_64(x_: f64) f64 { |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | test "math.exp1m" { | 289 | test "math.exp1m" { |
| 290 | expect(expm1(f32(0.0)) == expm1_32(0.0)); | 290 | expect(expm1(@as(f32, 0.0)) == expm1_32(0.0)); |
| 291 | expect(expm1(f64(0.0)) == expm1_64(0.0)); | 291 | expect(expm1(@as(f64, 0.0)) == expm1_64(0.0)); |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | test "math.expm1_32" { | 294 | test "math.expm1_32" { |
lib/std/math/expo2.zig+1-1| ... | @@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 { | ... | @@ -30,6 +30,6 @@ fn expo2d(x: f64) f64 { |
| 30 | const kln2 = 0x1.62066151ADD8BP+10; | 30 | const kln2 = 0x1.62066151ADD8BP+10; |
| 31 | 31 | ||
| 32 | const u = (0x3FF + k / 2) << 20; | 32 | const u = (0x3FF + k / 2) << 20; |
| 33 | const scale = @bitCast(f64, u64(u) << 32); | 33 | const scale = @bitCast(f64, @as(u64, u) << 32); |
| 34 | return math.exp(x - kln2) * scale * scale; | 34 | return math.exp(x - kln2) * scale * scale; |
| 35 | } | 35 | } |
lib/std/math/fabs.zig+4-4| ... | @@ -50,10 +50,10 @@ fn fabs128(x: f128) f128 { | ... | @@ -50,10 +50,10 @@ fn fabs128(x: f128) f128 { |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | test "math.fabs" { | 52 | test "math.fabs" { |
| 53 | expect(fabs(f16(1.0)) == fabs16(1.0)); | 53 | expect(fabs(@as(f16, 1.0)) == fabs16(1.0)); |
| 54 | expect(fabs(f32(1.0)) == fabs32(1.0)); | 54 | expect(fabs(@as(f32, 1.0)) == fabs32(1.0)); |
| 55 | expect(fabs(f64(1.0)) == fabs64(1.0)); | 55 | expect(fabs(@as(f64, 1.0)) == fabs64(1.0)); |
| 56 | expect(fabs(f128(1.0)) == fabs128(1.0)); | 56 | expect(fabs(@as(f128, 1.0)) == fabs128(1.0)); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | test "math.fabs16" { | 59 | test "math.fabs16" { |
lib/std/math/floor.zig+5-5| ... | @@ -40,7 +40,7 @@ fn floor16(x: f16) f16 { | ... | @@ -40,7 +40,7 @@ fn floor16(x: f16) f16 { |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | if (e >= 0) { | 42 | if (e >= 0) { |
| 43 | m = u16(1023) >> @intCast(u4, e); | 43 | m = @as(u16, 1023) >> @intCast(u4, e); |
| 44 | if (u & m == 0) { | 44 | if (u & m == 0) { |
| 45 | return x; | 45 | return x; |
| 46 | } | 46 | } |
| ... | @@ -74,7 +74,7 @@ fn floor32(x: f32) f32 { | ... | @@ -74,7 +74,7 @@ fn floor32(x: f32) f32 { |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | if (e >= 0) { | 76 | if (e >= 0) { |
| 77 | m = u32(0x007FFFFF) >> @intCast(u5, e); | 77 | m = @as(u32, 0x007FFFFF) >> @intCast(u5, e); |
| 78 | if (u & m == 0) { | 78 | if (u & m == 0) { |
| 79 | return x; | 79 | return x; |
| 80 | } | 80 | } |
| ... | @@ -123,9 +123,9 @@ fn floor64(x: f64) f64 { | ... | @@ -123,9 +123,9 @@ fn floor64(x: f64) f64 { |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | test "math.floor" { | 125 | test "math.floor" { |
| 126 | expect(floor(f16(1.3)) == floor16(1.3)); | 126 | expect(floor(@as(f16, 1.3)) == floor16(1.3)); |
| 127 | expect(floor(f32(1.3)) == floor32(1.3)); | 127 | expect(floor(@as(f32, 1.3)) == floor32(1.3)); |
| 128 | expect(floor(f64(1.3)) == floor64(1.3)); | 128 | expect(floor(@as(f64, 1.3)) == floor64(1.3)); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | test "math.floor16" { | 131 | test "math.floor16" { |
lib/std/math/fma.zig+1-1| ... | @@ -18,7 +18,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) T { | ... | @@ -18,7 +18,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) T { |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | fn fma32(x: f32, y: f32, z: f32) f32 { | 20 | fn fma32(x: f32, y: f32, z: f32) f32 { |
| 21 | const xy = f64(x) * y; | 21 | const xy = @as(f64, x) * y; |
| 22 | const xy_z = xy + z; | 22 | const xy_z = xy + z; |
| 23 | const u = @bitCast(u64, xy_z); | 23 | const u = @bitCast(u64, xy_z); |
| 24 | const e = (u >> 52) & 0x7FF; | 24 | const e = (u >> 52) & 0x7FF; |
lib/std/math/frexp.zig+2-2| ... | @@ -108,11 +108,11 @@ fn frexp64(x: f64) frexp64_result { | ... | @@ -108,11 +108,11 @@ fn frexp64(x: f64) frexp64_result { |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | test "math.frexp" { | 110 | test "math.frexp" { |
| 111 | const a = frexp(f32(1.3)); | 111 | const a = frexp(@as(f32, 1.3)); |
| 112 | const b = frexp32(1.3); | 112 | const b = frexp32(1.3); |
| 113 | expect(a.significand == b.significand and a.exponent == b.exponent); | 113 | expect(a.significand == b.significand and a.exponent == b.exponent); |
| 114 | 114 | ||
| 115 | const c = frexp(f64(1.3)); | 115 | const c = frexp(@as(f64, 1.3)); |
| 116 | const d = frexp64(1.3); | 116 | const d = frexp64(1.3); |
| 117 | expect(c.significand == d.significand and c.exponent == d.exponent); | 117 | expect(c.significand == d.significand and c.exponent == d.exponent); |
| 118 | } | 118 | } |
lib/std/math/hypot.zig+1-1| ... | @@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 { | ... | @@ -56,7 +56,7 @@ fn hypot32(x: f32, y: f32) f32 { |
| 56 | yy *= 0x1.0p-90; | 56 | yy *= 0x1.0p-90; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | return z * math.sqrt(@floatCast(f32, f64(x) * x + f64(y) * y)); | 59 | return z * math.sqrt(@floatCast(f32, @as(f64, x) * x + @as(f64, y) * y)); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | fn sq(hi: *f64, lo: *f64, x: f64) void { | 62 | fn sq(hi: *f64, lo: *f64, x: f64) void { |
lib/std/math/ilogb.zig+3-3| ... | @@ -26,7 +26,7 @@ pub fn ilogb(x: var) i32 { | ... | @@ -26,7 +26,7 @@ pub fn ilogb(x: var) i32 { |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | // NOTE: Should these be exposed publicly? | 28 | // NOTE: Should these be exposed publicly? |
| 29 | const fp_ilogbnan = -1 - i32(maxInt(u32) >> 1); | 29 | const fp_ilogbnan = -1 - @as(i32, maxInt(u32) >> 1); |
| 30 | const fp_ilogb0 = fp_ilogbnan; | 30 | const fp_ilogb0 = fp_ilogbnan; |
| 31 | 31 | ||
| 32 | fn ilogb32(x: f32) i32 { | 32 | fn ilogb32(x: f32) i32 { |
| ... | @@ -101,8 +101,8 @@ fn ilogb64(x: f64) i32 { | ... | @@ -101,8 +101,8 @@ fn ilogb64(x: f64) i32 { |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | test "math.ilogb" { | 103 | test "math.ilogb" { |
| 104 | expect(ilogb(f32(0.2)) == ilogb32(0.2)); | 104 | expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2)); |
| 105 | expect(ilogb(f64(0.2)) == ilogb64(0.2)); | 105 | expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2)); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | test "math.ilogb32" { | 108 | test "math.ilogb32" { |
lib/std/math/isfinite.zig+6-6| ... | @@ -26,12 +26,12 @@ pub fn isFinite(x: var) bool { | ... | @@ -26,12 +26,12 @@ pub fn isFinite(x: var) bool { |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | test "math.isFinite" { | 28 | test "math.isFinite" { |
| 29 | expect(isFinite(f16(0.0))); | 29 | expect(isFinite(@as(f16, 0.0))); |
| 30 | expect(isFinite(f16(-0.0))); | 30 | expect(isFinite(@as(f16, -0.0))); |
| 31 | expect(isFinite(f32(0.0))); | 31 | expect(isFinite(@as(f32, 0.0))); |
| 32 | expect(isFinite(f32(-0.0))); | 32 | expect(isFinite(@as(f32, -0.0))); |
| 33 | expect(isFinite(f64(0.0))); | 33 | expect(isFinite(@as(f64, 0.0))); |
| 34 | expect(isFinite(f64(-0.0))); | 34 | expect(isFinite(@as(f64, -0.0))); |
| 35 | expect(!isFinite(math.inf(f16))); | 35 | expect(!isFinite(math.inf(f16))); |
| 36 | expect(!isFinite(-math.inf(f16))); | 36 | expect(!isFinite(-math.inf(f16))); |
| 37 | expect(!isFinite(math.inf(f32))); | 37 | expect(!isFinite(math.inf(f32))); |
lib/std/math/isinf.zig+24-24| ... | @@ -74,14 +74,14 @@ pub fn isNegativeInf(x: var) bool { | ... | @@ -74,14 +74,14 @@ pub fn isNegativeInf(x: var) bool { |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | test "math.isInf" { | 76 | test "math.isInf" { |
| 77 | expect(!isInf(f16(0.0))); | 77 | expect(!isInf(@as(f16, 0.0))); |
| 78 | expect(!isInf(f16(-0.0))); | 78 | expect(!isInf(@as(f16, -0.0))); |
| 79 | expect(!isInf(f32(0.0))); | 79 | expect(!isInf(@as(f32, 0.0))); |
| 80 | expect(!isInf(f32(-0.0))); | 80 | expect(!isInf(@as(f32, -0.0))); |
| 81 | expect(!isInf(f64(0.0))); | 81 | expect(!isInf(@as(f64, 0.0))); |
| 82 | expect(!isInf(f64(-0.0))); | 82 | expect(!isInf(@as(f64, -0.0))); |
| 83 | expect(!isInf(f128(0.0))); | 83 | expect(!isInf(@as(f128, 0.0))); |
| 84 | expect(!isInf(f128(-0.0))); | 84 | expect(!isInf(@as(f128, -0.0))); |
| 85 | expect(isInf(math.inf(f16))); | 85 | expect(isInf(math.inf(f16))); |
| 86 | expect(isInf(-math.inf(f16))); | 86 | expect(isInf(-math.inf(f16))); |
| 87 | expect(isInf(math.inf(f32))); | 87 | expect(isInf(math.inf(f32))); |
| ... | @@ -93,14 +93,14 @@ test "math.isInf" { | ... | @@ -93,14 +93,14 @@ test "math.isInf" { |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | test "math.isPositiveInf" { | 95 | test "math.isPositiveInf" { |
| 96 | expect(!isPositiveInf(f16(0.0))); | 96 | expect(!isPositiveInf(@as(f16, 0.0))); |
| 97 | expect(!isPositiveInf(f16(-0.0))); | 97 | expect(!isPositiveInf(@as(f16, -0.0))); |
| 98 | expect(!isPositiveInf(f32(0.0))); | 98 | expect(!isPositiveInf(@as(f32, 0.0))); |
| 99 | expect(!isPositiveInf(f32(-0.0))); | 99 | expect(!isPositiveInf(@as(f32, -0.0))); |
| 100 | expect(!isPositiveInf(f64(0.0))); | 100 | expect(!isPositiveInf(@as(f64, 0.0))); |
| 101 | expect(!isPositiveInf(f64(-0.0))); | 101 | expect(!isPositiveInf(@as(f64, -0.0))); |
| 102 | expect(!isPositiveInf(f128(0.0))); | 102 | expect(!isPositiveInf(@as(f128, 0.0))); |
| 103 | expect(!isPositiveInf(f128(-0.0))); | 103 | expect(!isPositiveInf(@as(f128, -0.0))); |
| 104 | expect(isPositiveInf(math.inf(f16))); | 104 | expect(isPositiveInf(math.inf(f16))); |
| 105 | expect(!isPositiveInf(-math.inf(f16))); | 105 | expect(!isPositiveInf(-math.inf(f16))); |
| 106 | expect(isPositiveInf(math.inf(f32))); | 106 | expect(isPositiveInf(math.inf(f32))); |
| ... | @@ -112,14 +112,14 @@ test "math.isPositiveInf" { | ... | @@ -112,14 +112,14 @@ test "math.isPositiveInf" { |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | test "math.isNegativeInf" { | 114 | test "math.isNegativeInf" { |
| 115 | expect(!isNegativeInf(f16(0.0))); | 115 | expect(!isNegativeInf(@as(f16, 0.0))); |
| 116 | expect(!isNegativeInf(f16(-0.0))); | 116 | expect(!isNegativeInf(@as(f16, -0.0))); |
| 117 | expect(!isNegativeInf(f32(0.0))); | 117 | expect(!isNegativeInf(@as(f32, 0.0))); |
| 118 | expect(!isNegativeInf(f32(-0.0))); | 118 | expect(!isNegativeInf(@as(f32, -0.0))); |
| 119 | expect(!isNegativeInf(f64(0.0))); | 119 | expect(!isNegativeInf(@as(f64, 0.0))); |
| 120 | expect(!isNegativeInf(f64(-0.0))); | 120 | expect(!isNegativeInf(@as(f64, -0.0))); |
| 121 | expect(!isNegativeInf(f128(0.0))); | 121 | expect(!isNegativeInf(@as(f128, 0.0))); |
| 122 | expect(!isNegativeInf(f128(-0.0))); | 122 | expect(!isNegativeInf(@as(f128, -0.0))); |
| 123 | expect(!isNegativeInf(math.inf(f16))); | 123 | expect(!isNegativeInf(math.inf(f16))); |
| 124 | expect(isNegativeInf(-math.inf(f16))); | 124 | expect(isNegativeInf(-math.inf(f16))); |
| 125 | expect(!isNegativeInf(math.inf(f32))); | 125 | expect(!isNegativeInf(math.inf(f32))); |
lib/std/math/isnan.zig+4-4| ... | @@ -20,8 +20,8 @@ test "math.isNan" { | ... | @@ -20,8 +20,8 @@ test "math.isNan" { |
| 20 | expect(isNan(math.nan(f32))); | 20 | expect(isNan(math.nan(f32))); |
| 21 | expect(isNan(math.nan(f64))); | 21 | expect(isNan(math.nan(f64))); |
| 22 | expect(isNan(math.nan(f128))); | 22 | expect(isNan(math.nan(f128))); |
| 23 | expect(!isNan(f16(1.0))); | 23 | expect(!isNan(@as(f16, 1.0))); |
| 24 | expect(!isNan(f32(1.0))); | 24 | expect(!isNan(@as(f32, 1.0))); |
| 25 | expect(!isNan(f64(1.0))); | 25 | expect(!isNan(@as(f64, 1.0))); |
| 26 | expect(!isNan(f128(1.0))); | 26 | expect(!isNan(@as(f128, 1.0))); |
| 27 | } | 27 | } |
lib/std/math/isnormal.zig+6-6| ... | @@ -29,10 +29,10 @@ test "math.isNormal" { | ... | @@ -29,10 +29,10 @@ test "math.isNormal" { |
| 29 | expect(!isNormal(math.nan(f16))); | 29 | expect(!isNormal(math.nan(f16))); |
| 30 | expect(!isNormal(math.nan(f32))); | 30 | expect(!isNormal(math.nan(f32))); |
| 31 | expect(!isNormal(math.nan(f64))); | 31 | expect(!isNormal(math.nan(f64))); |
| 32 | expect(!isNormal(f16(0))); | 32 | expect(!isNormal(@as(f16, 0))); |
| 33 | expect(!isNormal(f32(0))); | 33 | expect(!isNormal(@as(f32, 0))); |
| 34 | expect(!isNormal(f64(0))); | 34 | expect(!isNormal(@as(f64, 0))); |
| 35 | expect(isNormal(f16(1.0))); | 35 | expect(isNormal(@as(f16, 1.0))); |
| 36 | expect(isNormal(f32(1.0))); | 36 | expect(isNormal(@as(f32, 1.0))); |
| 37 | expect(isNormal(f64(1.0))); | 37 | expect(isNormal(@as(f64, 1.0))); |
| 38 | } | 38 | } |
lib/std/math/ln.zig+5-5| ... | @@ -31,10 +31,10 @@ pub fn ln(x: var) @typeOf(x) { | ... | @@ -31,10 +31,10 @@ pub fn ln(x: var) @typeOf(x) { |
| 31 | }; | 31 | }; |
| 32 | }, | 32 | }, |
| 33 | TypeId.ComptimeInt => { | 33 | TypeId.ComptimeInt => { |
| 34 | return @typeOf(1)(math.floor(ln_64(f64(x)))); | 34 | return @typeOf(1)(math.floor(ln_64(@as(f64, x)))); |
| 35 | }, | 35 | }, |
| 36 | TypeId.Int => { | 36 | TypeId.Int => { |
| 37 | return T(math.floor(ln_64(f64(x)))); | 37 | return @as(T, math.floor(ln_64(@as(f64, x)))); |
| 38 | }, | 38 | }, |
| 39 | else => @compileError("ln not implemented for " ++ @typeName(T)), | 39 | else => @compileError("ln not implemented for " ++ @typeName(T)), |
| 40 | } | 40 | } |
| ... | @@ -132,7 +132,7 @@ pub fn ln_64(x_: f64) f64 { | ... | @@ -132,7 +132,7 @@ pub fn ln_64(x_: f64) f64 { |
| 132 | hx += 0x3FF00000 - 0x3FE6A09E; | 132 | hx += 0x3FF00000 - 0x3FE6A09E; |
| 133 | k += @intCast(i32, hx >> 20) - 0x3FF; | 133 | k += @intCast(i32, hx >> 20) - 0x3FF; |
| 134 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; | 134 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; |
| 135 | ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF); | 135 | ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); |
| 136 | x = @bitCast(f64, ix); | 136 | x = @bitCast(f64, ix); |
| 137 | 137 | ||
| 138 | const f = x - 1.0; | 138 | const f = x - 1.0; |
| ... | @@ -149,8 +149,8 @@ pub fn ln_64(x_: f64) f64 { | ... | @@ -149,8 +149,8 @@ pub fn ln_64(x_: f64) f64 { |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | test "math.ln" { | 151 | test "math.ln" { |
| 152 | expect(ln(f32(0.2)) == ln_32(0.2)); | 152 | expect(ln(@as(f32, 0.2)) == ln_32(0.2)); |
| 153 | expect(ln(f64(0.2)) == ln_64(0.2)); | 153 | expect(ln(@as(f64, 0.2)) == ln_64(0.2)); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | test "math.ln32" { | 156 | test "math.ln32" { |
lib/std/math/log.zig+7-7| ... | @@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T { | ... | @@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T { |
| 23 | const float_base = math.lossyCast(f64, base); | 23 | const float_base = math.lossyCast(f64, base); |
| 24 | switch (@typeId(T)) { | 24 | switch (@typeId(T)) { |
| 25 | TypeId.ComptimeFloat => { | 25 | TypeId.ComptimeFloat => { |
| 26 | return @typeOf(1.0)(math.ln(f64(x)) / math.ln(float_base)); | 26 | return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base)); |
| 27 | }, | 27 | }, |
| 28 | TypeId.ComptimeInt => { | 28 | TypeId.ComptimeInt => { |
| 29 | return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(float_base))); | 29 | return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base))); |
| 30 | }, | 30 | }, |
| 31 | builtin.TypeId.Int => { | 31 | builtin.TypeId.Int => { |
| 32 | // TODO implement integer log without using float math | 32 | // TODO implement integer log without using float math |
| ... | @@ -35,7 +35,7 @@ pub fn log(comptime T: type, base: T, x: T) T { | ... | @@ -35,7 +35,7 @@ pub fn log(comptime T: type, base: T, x: T) T { |
| 35 | 35 | ||
| 36 | builtin.TypeId.Float => { | 36 | builtin.TypeId.Float => { |
| 37 | switch (T) { | 37 | switch (T) { |
| 38 | f32 => return @floatCast(f32, math.ln(f64(x)) / math.ln(float_base)), | 38 | f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)), |
| 39 | f64 => return math.ln(x) / math.ln(float_base), | 39 | f64 => return math.ln(x) / math.ln(float_base), |
| 40 | else => @compileError("log not implemented for " ++ @typeName(T)), | 40 | else => @compileError("log not implemented for " ++ @typeName(T)), |
| 41 | } | 41 | } |
| ... | @@ -64,9 +64,9 @@ test "math.log float" { | ... | @@ -64,9 +64,9 @@ test "math.log float" { |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | test "math.log float_special" { | 66 | test "math.log float_special" { |
| 67 | expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974))); | 67 | expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974))); |
| 68 | expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974))); | 68 | expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974))); |
| 69 | 69 | ||
| 70 | expect(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993))); | 70 | expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993))); |
| 71 | expect(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993))); | 71 | expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993))); |
| 72 | } | 72 | } |
lib/std/math/log10.zig+5-5| ... | @@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) { | ... | @@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) { |
| 32 | }; | 32 | }; |
| 33 | }, | 33 | }, |
| 34 | TypeId.ComptimeInt => { | 34 | TypeId.ComptimeInt => { |
| 35 | return @typeOf(1)(math.floor(log10_64(f64(x)))); | 35 | return @typeOf(1)(math.floor(log10_64(@as(f64, x)))); |
| 36 | }, | 36 | }, |
| 37 | TypeId.Int => { | 37 | TypeId.Int => { |
| 38 | return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); | 38 | return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); |
| ... | @@ -143,7 +143,7 @@ pub fn log10_64(x_: f64) f64 { | ... | @@ -143,7 +143,7 @@ pub fn log10_64(x_: f64) f64 { |
| 143 | hx += 0x3FF00000 - 0x3FE6A09E; | 143 | hx += 0x3FF00000 - 0x3FE6A09E; |
| 144 | k += @intCast(i32, hx >> 20) - 0x3FF; | 144 | k += @intCast(i32, hx >> 20) - 0x3FF; |
| 145 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; | 145 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; |
| 146 | ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF); | 146 | ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); |
| 147 | x = @bitCast(f64, ix); | 147 | x = @bitCast(f64, ix); |
| 148 | 148 | ||
| 149 | const f = x - 1.0; | 149 | const f = x - 1.0; |
| ... | @@ -158,7 +158,7 @@ pub fn log10_64(x_: f64) f64 { | ... | @@ -158,7 +158,7 @@ pub fn log10_64(x_: f64) f64 { |
| 158 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) | 158 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) |
| 159 | var hi = f - hfsq; | 159 | var hi = f - hfsq; |
| 160 | var hii = @bitCast(u64, hi); | 160 | var hii = @bitCast(u64, hi); |
| 161 | hii &= u64(maxInt(u64)) << 32; | 161 | hii &= @as(u64, maxInt(u64)) << 32; |
| 162 | hi = @bitCast(f64, hii); | 162 | hi = @bitCast(f64, hii); |
| 163 | const lo = f - hi - hfsq + s * (hfsq + R); | 163 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 164 | 164 | ||
| ... | @@ -177,8 +177,8 @@ pub fn log10_64(x_: f64) f64 { | ... | @@ -177,8 +177,8 @@ pub fn log10_64(x_: f64) f64 { |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | test "math.log10" { | 179 | test "math.log10" { |
| 180 | testing.expect(log10(f32(0.2)) == log10_32(0.2)); | 180 | testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2)); |
| 181 | testing.expect(log10(f64(0.2)) == log10_64(0.2)); | 181 | testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2)); |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | test "math.log10_32" { | 184 | test "math.log10_32" { |
lib/std/math/log1p.zig+3-3| ... | @@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 { | ... | @@ -166,7 +166,7 @@ fn log1p_64(x: f64) f64 { |
| 166 | 166 | ||
| 167 | // u into [sqrt(2)/2, sqrt(2)] | 167 | // u into [sqrt(2)/2, sqrt(2)] |
| 168 | iu = (iu & 0x000FFFFF) + 0x3FE6A09E; | 168 | iu = (iu & 0x000FFFFF) + 0x3FE6A09E; |
| 169 | const iq = (u64(iu) << 32) | (hu & 0xFFFFFFFF); | 169 | const iq = (@as(u64, iu) << 32) | (hu & 0xFFFFFFFF); |
| 170 | f = @bitCast(f64, iq) - 1; | 170 | f = @bitCast(f64, iq) - 1; |
| 171 | } | 171 | } |
| 172 | 172 | ||
| ... | @@ -183,8 +183,8 @@ fn log1p_64(x: f64) f64 { | ... | @@ -183,8 +183,8 @@ fn log1p_64(x: f64) f64 { |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | test "math.log1p" { | 185 | test "math.log1p" { |
| 186 | expect(log1p(f32(0.0)) == log1p_32(0.0)); | 186 | expect(log1p(@as(f32, 0.0)) == log1p_32(0.0)); |
| 187 | expect(log1p(f64(0.0)) == log1p_64(0.0)); | 187 | expect(log1p(@as(f64, 0.0)) == log1p_64(0.0)); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | test "math.log1p_32" { | 190 | test "math.log1p_32" { |
lib/std/math/log2.zig+4-4| ... | @@ -143,7 +143,7 @@ pub fn log2_64(x_: f64) f64 { | ... | @@ -143,7 +143,7 @@ pub fn log2_64(x_: f64) f64 { |
| 143 | hx += 0x3FF00000 - 0x3FE6A09E; | 143 | hx += 0x3FF00000 - 0x3FE6A09E; |
| 144 | k += @intCast(i32, hx >> 20) - 0x3FF; | 144 | k += @intCast(i32, hx >> 20) - 0x3FF; |
| 145 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; | 145 | hx = (hx & 0x000FFFFF) + 0x3FE6A09E; |
| 146 | ix = (u64(hx) << 32) | (ix & 0xFFFFFFFF); | 146 | ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF); |
| 147 | x = @bitCast(f64, ix); | 147 | x = @bitCast(f64, ix); |
| 148 | 148 | ||
| 149 | const f = x - 1.0; | 149 | const f = x - 1.0; |
| ... | @@ -158,7 +158,7 @@ pub fn log2_64(x_: f64) f64 { | ... | @@ -158,7 +158,7 @@ pub fn log2_64(x_: f64) f64 { |
| 158 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) | 158 | // hi + lo = f - hfsq + s * (hfsq + R) ~ log(1 + f) |
| 159 | var hi = f - hfsq; | 159 | var hi = f - hfsq; |
| 160 | var hii = @bitCast(u64, hi); | 160 | var hii = @bitCast(u64, hi); |
| 161 | hii &= u64(maxInt(u64)) << 32; | 161 | hii &= @as(u64, maxInt(u64)) << 32; |
| 162 | hi = @bitCast(f64, hii); | 162 | hi = @bitCast(f64, hii); |
| 163 | const lo = f - hi - hfsq + s * (hfsq + R); | 163 | const lo = f - hi - hfsq + s * (hfsq + R); |
| 164 | 164 | ||
| ... | @@ -175,8 +175,8 @@ pub fn log2_64(x_: f64) f64 { | ... | @@ -175,8 +175,8 @@ pub fn log2_64(x_: f64) f64 { |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | test "math.log2" { | 177 | test "math.log2" { |
| 178 | expect(log2(f32(0.2)) == log2_32(0.2)); | 178 | expect(log2(@as(f32, 0.2)) == log2_32(0.2)); |
| 179 | expect(log2(f64(0.2)) == log2_64(0.2)); | 179 | expect(log2(@as(f64, 0.2)) == log2_64(0.2)); |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | test "math.log2_32" { | 182 | test "math.log2_32" { |
lib/std/math/modf.zig+4-4| ... | @@ -65,7 +65,7 @@ fn modf32(x: f32) modf32_result { | ... | @@ -65,7 +65,7 @@ fn modf32(x: f32) modf32_result { |
| 65 | return result; | 65 | return result; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | const mask = u32(0x007FFFFF) >> @intCast(u5, e); | 68 | const mask = @as(u32, 0x007FFFFF) >> @intCast(u5, e); |
| 69 | if (u & mask == 0) { | 69 | if (u & mask == 0) { |
| 70 | result.ipart = x; | 70 | result.ipart = x; |
| 71 | result.fpart = @bitCast(f32, us); | 71 | result.fpart = @bitCast(f32, us); |
| ... | @@ -109,7 +109,7 @@ fn modf64(x: f64) modf64_result { | ... | @@ -109,7 +109,7 @@ fn modf64(x: f64) modf64_result { |
| 109 | return result; | 109 | return result; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | const mask = u64(maxInt(u64) >> 12) >> @intCast(u6, e); | 112 | const mask = @as(u64, maxInt(u64) >> 12) >> @intCast(u6, e); |
| 113 | if (u & mask == 0) { | 113 | if (u & mask == 0) { |
| 114 | result.ipart = x; | 114 | result.ipart = x; |
| 115 | result.fpart = @bitCast(f64, us); | 115 | result.fpart = @bitCast(f64, us); |
| ... | @@ -123,12 +123,12 @@ fn modf64(x: f64) modf64_result { | ... | @@ -123,12 +123,12 @@ fn modf64(x: f64) modf64_result { |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | test "math.modf" { | 125 | test "math.modf" { |
| 126 | const a = modf(f32(1.0)); | 126 | const a = modf(@as(f32, 1.0)); |
| 127 | const b = modf32(1.0); | 127 | const b = modf32(1.0); |
| 128 | // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still. | 128 | // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still. |
| 129 | expect(a.ipart == b.ipart and a.fpart == b.fpart); | 129 | expect(a.ipart == b.ipart and a.fpart == b.fpart); |
| 130 | 130 | ||
| 131 | const c = modf(f64(1.0)); | 131 | const c = modf(@as(f64, 1.0)); |
| 132 | const d = modf64(1.0); | 132 | const d = modf64(1.0); |
| 133 | expect(a.ipart == b.ipart and a.fpart == b.fpart); | 133 | expect(a.ipart == b.ipart and a.fpart == b.fpart); |
| 134 | } | 134 | } |
lib/std/math/round.zig+2-2| ... | @@ -91,8 +91,8 @@ fn round64(x_: f64) f64 { | ... | @@ -91,8 +91,8 @@ fn round64(x_: f64) f64 { |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | test "math.round" { | 93 | test "math.round" { |
| 94 | expect(round(f32(1.3)) == round32(1.3)); | 94 | expect(round(@as(f32, 1.3)) == round32(1.3)); |
| 95 | expect(round(f64(1.3)) == round64(1.3)); | 95 | expect(round(@as(f64, 1.3)) == round64(1.3)); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | test "math.round32" { | 98 | test "math.round32" { |
lib/std/math/scalbn.zig+2-2| ... | @@ -79,8 +79,8 @@ fn scalbn64(x: f64, n_: i32) f64 { | ... | @@ -79,8 +79,8 @@ fn scalbn64(x: f64, n_: i32) f64 { |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | test "math.scalbn" { | 81 | test "math.scalbn" { |
| 82 | expect(scalbn(f32(1.5), 4) == scalbn32(1.5, 4)); | 82 | expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4)); |
| 83 | expect(scalbn(f64(1.5), 4) == scalbn64(1.5, 4)); | 83 | expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4)); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | test "math.scalbn32" { | 86 | test "math.scalbn32" { |
lib/std/math/signbit.zig+3-3| ... | @@ -29,9 +29,9 @@ fn signbit64(x: f64) bool { | ... | @@ -29,9 +29,9 @@ fn signbit64(x: f64) bool { |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | test "math.signbit" { | 31 | test "math.signbit" { |
| 32 | expect(signbit(f16(4.0)) == signbit16(4.0)); | 32 | expect(signbit(@as(f16, 4.0)) == signbit16(4.0)); |
| 33 | expect(signbit(f32(4.0)) == signbit32(4.0)); | 33 | expect(signbit(@as(f32, 4.0)) == signbit32(4.0)); |
| 34 | expect(signbit(f64(4.0)) == signbit64(4.0)); | 34 | expect(signbit(@as(f64, 4.0)) == signbit64(4.0)); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | test "math.signbit16" { | 37 | test "math.signbit16" { |
lib/std/math/sin.zig+3-3| ... | @@ -88,9 +88,9 @@ test "math.sin" { | ... | @@ -88,9 +88,9 @@ test "math.sin" { |
| 88 | // TODO https://github.com/ziglang/zig/issues/3289 | 88 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 89 | return error.SkipZigTest; | 89 | return error.SkipZigTest; |
| 90 | } | 90 | } |
| 91 | expect(sin(f32(0.0)) == sin_(f32, 0.0)); | 91 | expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0)); |
| 92 | expect(sin(f64(0.0)) == sin_(f64, 0.0)); | 92 | expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0)); |
| 93 | expect(comptime (math.sin(f64(2))) == math.sin(f64(2))); | 93 | expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2))); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | test "math.sin32" { | 96 | test "math.sin32" { |
lib/std/math/sinh.zig+2-2| ... | @@ -93,8 +93,8 @@ fn sinh64(x: f64) f64 { | ... | @@ -93,8 +93,8 @@ fn sinh64(x: f64) f64 { |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | test "math.sinh" { | 95 | test "math.sinh" { |
| 96 | expect(sinh(f32(1.5)) == sinh32(1.5)); | 96 | expect(sinh(@as(f32, 1.5)) == sinh32(1.5)); |
| 97 | expect(sinh(f64(1.5)) == sinh64(1.5)); | 97 | expect(sinh(@as(f64, 1.5)) == sinh64(1.5)); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | test "math.sinh32" { | 100 | test "math.sinh32" { |
lib/std/math/sqrt.zig+5-5| ... | @@ -15,7 +15,7 @@ const maxInt = std.math.maxInt; | ... | @@ -15,7 +15,7 @@ const maxInt = std.math.maxInt; |
| 15 | pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) { | 15 | pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) { |
| 16 | const T = @typeOf(x); | 16 | const T = @typeOf(x); |
| 17 | switch (@typeId(T)) { | 17 | switch (@typeId(T)) { |
| 18 | TypeId.ComptimeFloat => return T(@sqrt(f64, x)), // TODO upgrade to f128 | 18 | TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128 |
| 19 | TypeId.Float => return @sqrt(T, x), | 19 | TypeId.Float => return @sqrt(T, x), |
| 20 | TypeId.ComptimeInt => comptime { | 20 | TypeId.ComptimeInt => comptime { |
| 21 | if (x > maxInt(u128)) { | 21 | if (x > maxInt(u128)) { |
| ... | @@ -24,7 +24,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ | ... | @@ -24,7 +24,7 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ |
| 24 | if (x < 0) { | 24 | if (x < 0) { |
| 25 | @compileError("sqrt on negative number"); | 25 | @compileError("sqrt on negative number"); |
| 26 | } | 26 | } |
| 27 | return T(sqrt_int(u128, x)); | 27 | return @as(T, sqrt_int(u128, x)); |
| 28 | }, | 28 | }, |
| 29 | TypeId.Int => return sqrt_int(T, x), | 29 | TypeId.Int => return sqrt_int(T, x), |
| 30 | else => @compileError("sqrt not implemented for " ++ @typeName(T)), | 30 | else => @compileError("sqrt not implemented for " ++ @typeName(T)), |
| ... | @@ -32,9 +32,9 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ | ... | @@ -32,9 +32,9 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | test "math.sqrt" { | 34 | test "math.sqrt" { |
| 35 | expect(sqrt(f16(0.0)) == @sqrt(f16, 0.0)); | 35 | expect(sqrt(@as(f16, 0.0)) == @sqrt(f16, 0.0)); |
| 36 | expect(sqrt(f32(0.0)) == @sqrt(f32, 0.0)); | 36 | expect(sqrt(@as(f32, 0.0)) == @sqrt(f32, 0.0)); |
| 37 | expect(sqrt(f64(0.0)) == @sqrt(f64, 0.0)); | 37 | expect(sqrt(@as(f64, 0.0)) == @sqrt(f64, 0.0)); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | test "math.sqrt16" { | 40 | test "math.sqrt16" { |
lib/std/math/tan.zig+2-2| ... | @@ -75,8 +75,8 @@ fn tan_(comptime T: type, x_: T) T { | ... | @@ -75,8 +75,8 @@ fn tan_(comptime T: type, x_: T) T { |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | test "math.tan" { | 77 | test "math.tan" { |
| 78 | expect(tan(f32(0.0)) == tan_(f32, 0.0)); | 78 | expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0)); |
| 79 | expect(tan(f64(0.0)) == tan_(f64, 0.0)); | 79 | expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0)); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | test "math.tan32" { | 82 | test "math.tan32" { |
lib/std/math/tanh.zig+2-2| ... | @@ -119,8 +119,8 @@ fn tanh64(x: f64) f64 { | ... | @@ -119,8 +119,8 @@ fn tanh64(x: f64) f64 { |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | test "math.tanh" { | 121 | test "math.tanh" { |
| 122 | expect(tanh(f32(1.5)) == tanh32(1.5)); | 122 | expect(tanh(@as(f32, 1.5)) == tanh32(1.5)); |
| 123 | expect(tanh(f64(1.5)) == tanh64(1.5)); | 123 | expect(tanh(@as(f64, 1.5)) == tanh64(1.5)); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | test "math.tanh32" { | 126 | test "math.tanh32" { |
lib/std/math/trunc.zig+4-4| ... | @@ -36,7 +36,7 @@ fn trunc32(x: f32) f32 { | ... | @@ -36,7 +36,7 @@ fn trunc32(x: f32) f32 { |
| 36 | e = 1; | 36 | e = 1; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | m = u32(maxInt(u32)) >> @intCast(u5, e); | 39 | m = @as(u32, maxInt(u32)) >> @intCast(u5, e); |
| 40 | if (u & m == 0) { | 40 | if (u & m == 0) { |
| 41 | return x; | 41 | return x; |
| 42 | } else { | 42 | } else { |
| ... | @@ -57,7 +57,7 @@ fn trunc64(x: f64) f64 { | ... | @@ -57,7 +57,7 @@ fn trunc64(x: f64) f64 { |
| 57 | e = 1; | 57 | e = 1; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | m = u64(maxInt(u64)) >> @intCast(u6, e); | 60 | m = @as(u64, maxInt(u64)) >> @intCast(u6, e); |
| 61 | if (u & m == 0) { | 61 | if (u & m == 0) { |
| 62 | return x; | 62 | return x; |
| 63 | } else { | 63 | } else { |
| ... | @@ -67,8 +67,8 @@ fn trunc64(x: f64) f64 { | ... | @@ -67,8 +67,8 @@ fn trunc64(x: f64) f64 { |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | test "math.trunc" { | 69 | test "math.trunc" { |
| 70 | expect(trunc(f32(1.3)) == trunc32(1.3)); | 70 | expect(trunc(@as(f32, 1.3)) == trunc32(1.3)); |
| 71 | expect(trunc(f64(1.3)) == trunc64(1.3)); | 71 | expect(trunc(@as(f64, 1.3)) == trunc64(1.3)); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | test "math.trunc32" { | 74 | test "math.trunc32" { |
lib/std/mem.zig+10-10| ... | @@ -118,7 +118,7 @@ pub const Allocator = struct { | ... | @@ -118,7 +118,7 @@ pub const Allocator = struct { |
| 118 | } else @alignOf(T); | 118 | } else @alignOf(T); |
| 119 | 119 | ||
| 120 | if (n == 0) { | 120 | if (n == 0) { |
| 121 | return ([*]align(a) T)(undefined)[0..0]; | 121 | return @as([*]align(a) T, undefined)[0..0]; |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory; | 124 | const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory; |
| ... | @@ -170,7 +170,7 @@ pub const Allocator = struct { | ... | @@ -170,7 +170,7 @@ pub const Allocator = struct { |
| 170 | } | 170 | } |
| 171 | if (new_n == 0) { | 171 | if (new_n == 0) { |
| 172 | self.free(old_mem); | 172 | self.free(old_mem); |
| 173 | return ([*]align(new_alignment) T)(undefined)[0..0]; | 173 | return @as([*]align(new_alignment) T, undefined)[0..0]; |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | const old_byte_slice = @sliceToBytes(old_mem); | 176 | const old_byte_slice = @sliceToBytes(old_mem); |
| ... | @@ -523,7 +523,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin. | ... | @@ -523,7 +523,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin. |
| 523 | builtin.Endian.Little => { | 523 | builtin.Endian.Little => { |
| 524 | const ShiftType = math.Log2Int(ReturnType); | 524 | const ShiftType = math.Log2Int(ReturnType); |
| 525 | for (bytes) |b, index| { | 525 | for (bytes) |b, index| { |
| 526 | result = result | (ReturnType(b) << @intCast(ShiftType, index * 8)); | 526 | result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8)); |
| 527 | } | 527 | } |
| 528 | }, | 528 | }, |
| 529 | } | 529 | } |
| ... | @@ -1332,7 +1332,7 @@ fn AsBytesReturnType(comptime P: type) type { | ... | @@ -1332,7 +1332,7 @@ fn AsBytesReturnType(comptime P: type) type { |
| 1332 | if (comptime !trait.isSingleItemPtr(P)) | 1332 | if (comptime !trait.isSingleItemPtr(P)) |
| 1333 | @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P)); | 1333 | @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P)); |
| 1334 | 1334 | ||
| 1335 | const size = usize(@sizeOf(meta.Child(P))); | 1335 | const size = @as(usize, @sizeOf(meta.Child(P))); |
| 1336 | const alignment = comptime meta.alignment(P); | 1336 | const alignment = comptime meta.alignment(P); |
| 1337 | 1337 | ||
| 1338 | if (alignment == 0) { | 1338 | if (alignment == 0) { |
| ... | @@ -1353,7 +1353,7 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) { | ... | @@ -1353,7 +1353,7 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) { |
| 1353 | } | 1353 | } |
| 1354 | 1354 | ||
| 1355 | test "asBytes" { | 1355 | test "asBytes" { |
| 1356 | const deadbeef = u32(0xDEADBEEF); | 1356 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 1357 | const deadbeef_bytes = switch (builtin.endian) { | 1357 | const deadbeef_bytes = switch (builtin.endian) { |
| 1358 | builtin.Endian.Big => "\xDE\xAD\xBE\xEF", | 1358 | builtin.Endian.Big => "\xDE\xAD\xBE\xEF", |
| 1359 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", | 1359 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", |
| ... | @@ -1361,7 +1361,7 @@ test "asBytes" { | ... | @@ -1361,7 +1361,7 @@ test "asBytes" { |
| 1361 | 1361 | ||
| 1362 | testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); | 1362 | testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); |
| 1363 | 1363 | ||
| 1364 | var codeface = u32(0xC0DEFACE); | 1364 | var codeface = @as(u32, 0xC0DEFACE); |
| 1365 | for (asBytes(&codeface).*) |*b| | 1365 | for (asBytes(&codeface).*) |*b| |
| 1366 | b.* = 0; | 1366 | b.* = 0; |
| 1367 | testing.expect(codeface == 0); | 1367 | testing.expect(codeface == 0); |
| ... | @@ -1392,7 +1392,7 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 { | ... | @@ -1392,7 +1392,7 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 { |
| 1392 | } | 1392 | } |
| 1393 | 1393 | ||
| 1394 | test "toBytes" { | 1394 | test "toBytes" { |
| 1395 | var my_bytes = toBytes(u32(0x12345678)); | 1395 | var my_bytes = toBytes(@as(u32, 0x12345678)); |
| 1396 | switch (builtin.endian) { | 1396 | switch (builtin.endian) { |
| 1397 | builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")), | 1397 | builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")), |
| 1398 | builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")), | 1398 | builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")), |
| ... | @@ -1406,7 +1406,7 @@ test "toBytes" { | ... | @@ -1406,7 +1406,7 @@ test "toBytes" { |
| 1406 | } | 1406 | } |
| 1407 | 1407 | ||
| 1408 | fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { | 1408 | fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { |
| 1409 | const size = usize(@sizeOf(T)); | 1409 | const size = @as(usize, @sizeOf(T)); |
| 1410 | 1410 | ||
| 1411 | if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) { | 1411 | if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) { |
| 1412 | @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B)); | 1412 | @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B)); |
| ... | @@ -1424,7 +1424,7 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typ | ... | @@ -1424,7 +1424,7 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typ |
| 1424 | } | 1424 | } |
| 1425 | 1425 | ||
| 1426 | test "bytesAsValue" { | 1426 | test "bytesAsValue" { |
| 1427 | const deadbeef = u32(0xDEADBEEF); | 1427 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 1428 | const deadbeef_bytes = switch (builtin.endian) { | 1428 | const deadbeef_bytes = switch (builtin.endian) { |
| 1429 | builtin.Endian.Big => "\xDE\xAD\xBE\xEF", | 1429 | builtin.Endian.Big => "\xDE\xAD\xBE\xEF", |
| 1430 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", | 1430 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", |
| ... | @@ -1472,7 +1472,7 @@ test "bytesToValue" { | ... | @@ -1472,7 +1472,7 @@ test "bytesToValue" { |
| 1472 | }; | 1472 | }; |
| 1473 | 1473 | ||
| 1474 | const deadbeef = bytesToValue(u32, deadbeef_bytes); | 1474 | const deadbeef = bytesToValue(u32, deadbeef_bytes); |
| 1475 | testing.expect(deadbeef == u32(0xDEADBEEF)); | 1475 | testing.expect(deadbeef == @as(u32, 0xDEADBEEF)); |
| 1476 | } | 1476 | } |
| 1477 | 1477 | ||
| 1478 | fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type { | 1478 | fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type { |
lib/std/meta.zig+2-2| ... | @@ -341,7 +341,7 @@ test "std.meta.TagType" { | ... | @@ -341,7 +341,7 @@ test "std.meta.TagType" { |
| 341 | ///Returns the active tag of a tagged union | 341 | ///Returns the active tag of a tagged union |
| 342 | pub fn activeTag(u: var) @TagType(@typeOf(u)) { | 342 | pub fn activeTag(u: var) @TagType(@typeOf(u)) { |
| 343 | const T = @typeOf(u); | 343 | const T = @typeOf(u); |
| 344 | return @TagType(T)(u); | 344 | return @as(@TagType(T), u); |
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | test "std.meta.activeTag" { | 347 | test "std.meta.activeTag" { |
| ... | @@ -505,7 +505,7 @@ test "std.meta.eql" { | ... | @@ -505,7 +505,7 @@ test "std.meta.eql" { |
| 505 | const EU = struct { | 505 | const EU = struct { |
| 506 | fn tst(err: bool) !u8 { | 506 | fn tst(err: bool) !u8 { |
| 507 | if (err) return error.Error; | 507 | if (err) return error.Error; |
| 508 | return u8(5); | 508 | return @as(u8, 5); |
| 509 | } | 509 | } |
| 510 | }; | 510 | }; |
| 511 | 511 |
lib/std/meta/trait.zig+2-2| ... | @@ -327,8 +327,8 @@ pub fn isConstPtr(comptime T: type) bool { | ... | @@ -327,8 +327,8 @@ pub fn isConstPtr(comptime T: type) bool { |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | test "std.meta.trait.isConstPtr" { | 329 | test "std.meta.trait.isConstPtr" { |
| 330 | var t = u8(0); | 330 | var t = @as(u8, 0); |
| 331 | const c = u8(0); | 331 | const c = @as(u8, 0); |
| 332 | testing.expect(isConstPtr(*const @typeOf(t))); | 332 | testing.expect(isConstPtr(*const @typeOf(t))); |
| 333 | testing.expect(isConstPtr(@typeOf(&c))); | 333 | testing.expect(isConstPtr(@typeOf(&c))); |
| 334 | testing.expect(!isConstPtr(*@typeOf(t))); | 334 | testing.expect(!isConstPtr(*@typeOf(t))); |
lib/std/net.zig+11-11| ... | @@ -117,7 +117,7 @@ pub const IpAddress = extern union { | ... | @@ -117,7 +117,7 @@ pub const IpAddress = extern union { |
| 117 | ip_slice[10] = 0xff; | 117 | ip_slice[10] = 0xff; |
| 118 | ip_slice[11] = 0xff; | 118 | ip_slice[11] = 0xff; |
| 119 | 119 | ||
| 120 | const ptr = @sliceToBytes((*const [1]u32)(&addr)[0..]); | 120 | const ptr = @sliceToBytes(@as(*const [1]u32, &addr)[0..]); |
| 121 | 121 | ||
| 122 | ip_slice[12] = ptr[0]; | 122 | ip_slice[12] = ptr[0]; |
| 123 | ip_slice[13] = ptr[1]; | 123 | ip_slice[13] = ptr[1]; |
| ... | @@ -161,7 +161,7 @@ pub const IpAddress = extern union { | ... | @@ -161,7 +161,7 @@ pub const IpAddress = extern union { |
| 161 | .addr = undefined, | 161 | .addr = undefined, |
| 162 | }, | 162 | }, |
| 163 | }; | 163 | }; |
| 164 | const out_ptr = @sliceToBytes((*[1]u32)(&result.in.addr)[0..]); | 164 | const out_ptr = @sliceToBytes(@as(*[1]u32, &result.in.addr)[0..]); |
| 165 | 165 | ||
| 166 | var x: u8 = 0; | 166 | var x: u8 = 0; |
| 167 | var index: u8 = 0; | 167 | var index: u8 = 0; |
| ... | @@ -271,7 +271,7 @@ pub const IpAddress = extern union { | ... | @@ -271,7 +271,7 @@ pub const IpAddress = extern union { |
| 271 | }, | 271 | }, |
| 272 | os.AF_INET6 => { | 272 | os.AF_INET6 => { |
| 273 | const port = mem.bigToNative(u16, self.in6.port); | 273 | const port = mem.bigToNative(u16, self.in6.port); |
| 274 | if (mem.eql(u8, self.in6.addr[0..12], [_]u8{0,0,0,0,0,0,0,0,0,0,0xff,0xff})) { | 274 | if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) { |
| 275 | try std.fmt.format( | 275 | try std.fmt.format( |
| 276 | context, | 276 | context, |
| 277 | Errors, | 277 | Errors, |
| ... | @@ -611,7 +611,7 @@ fn linuxLookupName( | ... | @@ -611,7 +611,7 @@ fn linuxLookupName( |
| 611 | // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary. | 611 | // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary. |
| 612 | mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr); | 612 | mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr); |
| 613 | } | 613 | } |
| 614 | if (dscope == i32(scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE; | 614 | if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE; |
| 615 | if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL; | 615 | if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL; |
| 616 | prefixlen = prefixMatch(sa6.addr, da6.addr); | 616 | prefixlen = prefixMatch(sa6.addr, da6.addr); |
| 617 | } else |_| {} | 617 | } else |_| {} |
| ... | @@ -710,7 +710,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 { | ... | @@ -710,7 +710,7 @@ fn prefixMatch(s: [16]u8, d: [16]u8) u8 { |
| 710 | // address. However the definition of the source prefix length is | 710 | // address. However the definition of the source prefix length is |
| 711 | // not clear and thus this limiting is not yet implemented. | 711 | // not clear and thus this limiting is not yet implemented. |
| 712 | var i: u8 = 0; | 712 | var i: u8 = 0; |
| 713 | while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (u8(128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {} | 713 | while (i < 128 and ((s[i / 8] ^ d[i / 8]) & (@as(u8, 128) >> @intCast(u3, i % 8))) == 0) : (i += 1) {} |
| 714 | return i; | 714 | return i; |
| 715 | } | 715 | } |
| 716 | 716 | ||
| ... | @@ -1133,7 +1133,7 @@ fn resMSendRc( | ... | @@ -1133,7 +1133,7 @@ fn resMSendRc( |
| 1133 | } | 1133 | } |
| 1134 | 1134 | ||
| 1135 | // Wait for a response, or until time to retry | 1135 | // Wait for a response, or until time to retry |
| 1136 | const clamped_timeout = std.math.min(u31(std.math.maxInt(u31)), t1 + retry_interval - t2); | 1136 | const clamped_timeout = std.math.min(@as(u31, std.math.maxInt(u31)), t1 + retry_interval - t2); |
| 1137 | const nevents = os.poll(&pfd, clamped_timeout) catch 0; | 1137 | const nevents = os.poll(&pfd, clamped_timeout) catch 0; |
| 1138 | if (nevents == 0) continue; | 1138 | if (nevents == 0) continue; |
| 1139 | 1139 | ||
| ... | @@ -1194,23 +1194,23 @@ fn dnsParse( | ... | @@ -1194,23 +1194,23 @@ fn dnsParse( |
| 1194 | if (r.len < 12) return error.InvalidDnsPacket; | 1194 | if (r.len < 12) return error.InvalidDnsPacket; |
| 1195 | if ((r[3] & 15) != 0) return; | 1195 | if ((r[3] & 15) != 0) return; |
| 1196 | var p = r.ptr + 12; | 1196 | var p = r.ptr + 12; |
| 1197 | var qdcount = r[4] * usize(256) + r[5]; | 1197 | var qdcount = r[4] * @as(usize, 256) + r[5]; |
| 1198 | var ancount = r[6] * usize(256) + r[7]; | 1198 | var ancount = r[6] * @as(usize, 256) + r[7]; |
| 1199 | if (qdcount + ancount > 64) return error.InvalidDnsPacket; | 1199 | if (qdcount + ancount > 64) return error.InvalidDnsPacket; |
| 1200 | while (qdcount != 0) { | 1200 | while (qdcount != 0) { |
| 1201 | qdcount -= 1; | 1201 | qdcount -= 1; |
| 1202 | while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1; | 1202 | while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1; |
| 1203 | if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6) | 1203 | if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6) |
| 1204 | return error.InvalidDnsPacket; | 1204 | return error.InvalidDnsPacket; |
| 1205 | p += usize(5) + @boolToInt(p[0] != 0); | 1205 | p += @as(usize, 5) + @boolToInt(p[0] != 0); |
| 1206 | } | 1206 | } |
| 1207 | while (ancount != 0) { | 1207 | while (ancount != 0) { |
| 1208 | ancount -= 1; | 1208 | ancount -= 1; |
| 1209 | while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1; | 1209 | while (@ptrToInt(p) - @ptrToInt(r.ptr) < r.len and p[0] -% 1 < 127) p += 1; |
| 1210 | if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6) | 1210 | if (p[0] > 193 or (p[0] == 193 and p[1] > 254) or @ptrToInt(p) > @ptrToInt(r.ptr) + r.len - 6) |
| 1211 | return error.InvalidDnsPacket; | 1211 | return error.InvalidDnsPacket; |
| 1212 | p += usize(1) + @boolToInt(p[0] != 0); | 1212 | p += @as(usize, 1) + @boolToInt(p[0] != 0); |
| 1213 | const len = p[8] * usize(256) + p[9]; | 1213 | const len = p[8] * @as(usize, 256) + p[9]; |
| 1214 | if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket; | 1214 | if (@ptrToInt(p) + len > @ptrToInt(r.ptr) + r.len) return error.InvalidDnsPacket; |
| 1215 | try callback(ctx, p[1], p[10 .. 10 + len], r); | 1215 | try callback(ctx, p[1], p[10 .. 10 + len], r); |
| 1216 | p += 10 + len; | 1216 | p += 10 + len; |
lib/std/os.zig+7-7| ... | @@ -472,7 +472,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void { | ... | @@ -472,7 +472,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void { |
| 472 | 472 | ||
| 473 | var index: usize = 0; | 473 | var index: usize = 0; |
| 474 | while (index < bytes.len) { | 474 | while (index < bytes.len) { |
| 475 | const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len)); | 475 | const amt_to_write = math.min(bytes.len - index, @as(usize, max_bytes_len)); |
| 476 | const rc = system.write(fd, bytes.ptr + index, amt_to_write); | 476 | const rc = system.write(fd, bytes.ptr + index, amt_to_write); |
| 477 | switch (errno(rc)) { | 477 | switch (errno(rc)) { |
| 478 | 0 => { | 478 | 0 => { |
| ... | @@ -1126,9 +1126,9 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*]const u16, flags: u32) UnlinkatErro | ... | @@ -1126,9 +1126,9 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*]const u16, flags: u32) UnlinkatErro |
| 1126 | 1126 | ||
| 1127 | const want_rmdir_behavior = (flags & AT_REMOVEDIR) != 0; | 1127 | const want_rmdir_behavior = (flags & AT_REMOVEDIR) != 0; |
| 1128 | const create_options_flags = if (want_rmdir_behavior) | 1128 | const create_options_flags = if (want_rmdir_behavior) |
| 1129 | w.ULONG(w.FILE_DELETE_ON_CLOSE) | 1129 | @as(w.ULONG, w.FILE_DELETE_ON_CLOSE) |
| 1130 | else | 1130 | else |
| 1131 | w.ULONG(w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE); | 1131 | @as(w.ULONG, w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE); |
| 1132 | 1132 | ||
| 1133 | const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2); | 1133 | const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2); |
| 1134 | var nt_name = w.UNICODE_STRING{ | 1134 | var nt_name = w.UNICODE_STRING{ |
| ... | @@ -1526,7 +1526,7 @@ pub fn isatty(handle: fd_t) bool { | ... | @@ -1526,7 +1526,7 @@ pub fn isatty(handle: fd_t) bool { |
| 1526 | } | 1526 | } |
| 1527 | if (builtin.os == .linux) { | 1527 | if (builtin.os == .linux) { |
| 1528 | var wsz: linux.winsize = undefined; | 1528 | var wsz: linux.winsize = undefined; |
| 1529 | return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | 1529 | return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; |
| 1530 | } | 1530 | } |
| 1531 | unreachable; | 1531 | unreachable; |
| 1532 | } | 1532 | } |
| ... | @@ -1547,7 +1547,7 @@ pub fn isCygwinPty(handle: fd_t) bool { | ... | @@ -1547,7 +1547,7 @@ pub fn isCygwinPty(handle: fd_t) bool { |
| 1547 | } | 1547 | } |
| 1548 | 1548 | ||
| 1549 | const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]); | 1549 | const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]); |
| 1550 | const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)]; | 1550 | const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)]; |
| 1551 | const name_wide = @bytesToSlice(u16, name_bytes); | 1551 | const name_wide = @bytesToSlice(u16, name_bytes); |
| 1552 | return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or | 1552 | return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or |
| 1553 | mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null; | 1553 | mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null; |
| ... | @@ -2897,7 +2897,7 @@ pub fn res_mkquery( | ... | @@ -2897,7 +2897,7 @@ pub fn res_mkquery( |
| 2897 | // Construct query template - ID will be filled later | 2897 | // Construct query template - ID will be filled later |
| 2898 | var q: [280]u8 = undefined; | 2898 | var q: [280]u8 = undefined; |
| 2899 | @memset(&q, 0, n); | 2899 | @memset(&q, 0, n); |
| 2900 | q[2] = u8(op) * 8 + 1; | 2900 | q[2] = @as(u8, op) * 8 + 1; |
| 2901 | q[5] = 1; | 2901 | q[5] = 1; |
| 2902 | mem.copy(u8, q[13..], name); | 2902 | mem.copy(u8, q[13..], name); |
| 2903 | var i: usize = 13; | 2903 | var i: usize = 13; |
| ... | @@ -3143,7 +3143,7 @@ pub fn dn_expand( | ... | @@ -3143,7 +3143,7 @@ pub fn dn_expand( |
| 3143 | // loop invariants: p<end, dest<dend | 3143 | // loop invariants: p<end, dest<dend |
| 3144 | if ((p[0] & 0xc0) != 0) { | 3144 | if ((p[0] & 0xc0) != 0) { |
| 3145 | if (p + 1 == end) return error.InvalidDnsPacket; | 3145 | if (p + 1 == end) return error.InvalidDnsPacket; |
| 3146 | var j = ((p[0] & usize(0x3f)) << 8) | p[1]; | 3146 | var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1]; |
| 3147 | if (len == std.math.maxInt(usize)) len = @ptrToInt(p) + 2 - @ptrToInt(comp_dn.ptr); | 3147 | if (len == std.math.maxInt(usize)) len = @ptrToInt(p) + 2 - @ptrToInt(comp_dn.ptr); |
| 3148 | if (j >= msg.len) return error.InvalidDnsPacket; | 3148 | if (j >= msg.len) return error.InvalidDnsPacket; |
| 3149 | p = msg.ptr + j; | 3149 | p = msg.ptr + j; |
lib/std/os/bits/dragonfly.zig+1-1| ... | @@ -315,7 +315,7 @@ pub const dirent = extern struct { | ... | @@ -315,7 +315,7 @@ pub const dirent = extern struct { |
| 315 | d_name: [256]u8, | 315 | d_name: [256]u8, |
| 316 | 316 | ||
| 317 | pub fn reclen(self: dirent) u16 { | 317 | pub fn reclen(self: dirent) u16 { |
| 318 | return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~u16(7); | 318 | return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7); |
| 319 | } | 319 | } |
| 320 | }; | 320 | }; |
| 321 | 321 |
lib/std/os/bits/linux.zig+5-5| ... | @@ -559,10 +559,10 @@ pub const EPOLLMSG = 0x400; | ... | @@ -559,10 +559,10 @@ pub const EPOLLMSG = 0x400; |
| 559 | pub const EPOLLERR = 0x008; | 559 | pub const EPOLLERR = 0x008; |
| 560 | pub const EPOLLHUP = 0x010; | 560 | pub const EPOLLHUP = 0x010; |
| 561 | pub const EPOLLRDHUP = 0x2000; | 561 | pub const EPOLLRDHUP = 0x2000; |
| 562 | pub const EPOLLEXCLUSIVE = (u32(1) << 28); | 562 | pub const EPOLLEXCLUSIVE = (@as(u32, 1) << 28); |
| 563 | pub const EPOLLWAKEUP = (u32(1) << 29); | 563 | pub const EPOLLWAKEUP = (@as(u32, 1) << 29); |
| 564 | pub const EPOLLONESHOT = (u32(1) << 30); | 564 | pub const EPOLLONESHOT = (@as(u32, 1) << 30); |
| 565 | pub const EPOLLET = (u32(1) << 31); | 565 | pub const EPOLLET = (@as(u32, 1) << 31); |
| 566 | 566 | ||
| 567 | pub const CLOCK_REALTIME = 0; | 567 | pub const CLOCK_REALTIME = 0; |
| 568 | pub const CLOCK_MONOTONIC = 1; | 568 | pub const CLOCK_MONOTONIC = 1; |
| ... | @@ -950,7 +950,7 @@ pub fn cap_valid(u8: x) bool { | ... | @@ -950,7 +950,7 @@ pub fn cap_valid(u8: x) bool { |
| 950 | } | 950 | } |
| 951 | 951 | ||
| 952 | pub fn CAP_TO_MASK(cap: u8) u32 { | 952 | pub fn CAP_TO_MASK(cap: u8) u32 { |
| 953 | return u32(1) << u5(cap & 31); | 953 | return @as(u32, 1) << u5(cap & 31); |
| 954 | } | 954 | } |
| 955 | 955 | ||
| 956 | pub fn CAP_TO_INDEX(cap: u8) u8 { | 956 | pub fn CAP_TO_INDEX(cap: u8) u8 { |
lib/std/os/linux.zig+94-94| ... | @@ -46,22 +46,22 @@ pub fn getErrno(r: usize) u12 { | ... | @@ -46,22 +46,22 @@ pub fn getErrno(r: usize) u12 { |
| 46 | 46 | ||
| 47 | pub fn dup2(old: i32, new: i32) usize { | 47 | pub fn dup2(old: i32, new: i32) usize { |
| 48 | if (@hasDecl(@This(), "SYS_dup2")) { | 48 | if (@hasDecl(@This(), "SYS_dup2")) { |
| 49 | return syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new))); | 49 | return syscall2(SYS_dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new))); |
| 50 | } else { | 50 | } else { |
| 51 | if (old == new) { | 51 | if (old == new) { |
| 52 | if (std.debug.runtime_safety) { | 52 | if (std.debug.runtime_safety) { |
| 53 | const rc = syscall2(SYS_fcntl, @bitCast(usize, isize(old)), F_GETFD); | 53 | const rc = syscall2(SYS_fcntl, @bitCast(usize, @as(isize, old)), F_GETFD); |
| 54 | if (@bitCast(isize, rc) < 0) return rc; | 54 | if (@bitCast(isize, rc) < 0) return rc; |
| 55 | } | 55 | } |
| 56 | return @intCast(usize, old); | 56 | return @intCast(usize, old); |
| 57 | } else { | 57 | } else { |
| 58 | return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), 0); | 58 | return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0); |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | pub fn dup3(old: i32, new: i32, flags: u32) usize { | 63 | pub fn dup3(old: i32, new: i32, flags: u32) usize { |
| 64 | return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), flags); | 64 | return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | // TODO https://github.com/ziglang/zig/issues/265 | 67 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -102,7 +102,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize { | ... | @@ -102,7 +102,7 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize { |
| 102 | 102 | ||
| 103 | // TODO https://github.com/ziglang/zig/issues/265 | 103 | // TODO https://github.com/ziglang/zig/issues/265 |
| 104 | pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize { | 104 | pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize { |
| 105 | return syscall4(SYS_utimensat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(times), flags); | 105 | return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize { | 108 | pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize { |
| ... | @@ -120,7 +120,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { | ... | @@ -120,7 +120,7 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { |
| 120 | pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { | 120 | pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { |
| 121 | return syscall3( | 121 | return syscall3( |
| 122 | SYS_getdents, | 122 | SYS_getdents, |
| 123 | @bitCast(usize, isize(fd)), | 123 | @bitCast(usize, @as(isize, fd)), |
| 124 | @ptrToInt(dirp), | 124 | @ptrToInt(dirp), |
| 125 | std.math.min(len, maxInt(c_int)), | 125 | std.math.min(len, maxInt(c_int)), |
| 126 | ); | 126 | ); |
| ... | @@ -129,7 +129,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { | ... | @@ -129,7 +129,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { |
| 129 | pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize { | 129 | pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize { |
| 130 | return syscall3( | 130 | return syscall3( |
| 131 | SYS_getdents64, | 131 | SYS_getdents64, |
| 132 | @bitCast(usize, isize(fd)), | 132 | @bitCast(usize, @as(isize, fd)), |
| 133 | @ptrToInt(dirp), | 133 | @ptrToInt(dirp), |
| 134 | std.math.min(len, maxInt(c_int)), | 134 | std.math.min(len, maxInt(c_int)), |
| 135 | ); | 135 | ); |
| ... | @@ -140,11 +140,11 @@ pub fn inotify_init1(flags: u32) usize { | ... | @@ -140,11 +140,11 @@ pub fn inotify_init1(flags: u32) usize { |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize { | 142 | pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize { |
| 143 | return syscall3(SYS_inotify_add_watch, @bitCast(usize, isize(fd)), @ptrToInt(pathname), mask); | 143 | return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask); |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | pub fn inotify_rm_watch(fd: i32, wd: i32) usize { | 146 | pub fn inotify_rm_watch(fd: i32, wd: i32) usize { |
| 147 | return syscall2(SYS_inotify_rm_watch, @bitCast(usize, isize(fd)), @bitCast(usize, isize(wd))); | 147 | return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd))); |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | // TODO https://github.com/ziglang/zig/issues/265 | 150 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -152,13 +152,13 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz | ... | @@ -152,13 +152,13 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz |
| 152 | if (@hasDecl(@This(), "SYS_readlink")) { | 152 | if (@hasDecl(@This(), "SYS_readlink")) { |
| 153 | return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | 153 | return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); |
| 154 | } else { | 154 | } else { |
| 155 | return syscall4(SYS_readlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | 155 | return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); |
| 156 | } | 156 | } |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | // TODO https://github.com/ziglang/zig/issues/265 | 159 | // TODO https://github.com/ziglang/zig/issues/265 |
| 160 | pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { | 160 | pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { |
| 161 | return syscall4(SYS_readlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | 161 | return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | // TODO https://github.com/ziglang/zig/issues/265 | 164 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -166,13 +166,13 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize { | ... | @@ -166,13 +166,13 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize { |
| 166 | if (@hasDecl(@This(), "SYS_mkdir")) { | 166 | if (@hasDecl(@This(), "SYS_mkdir")) { |
| 167 | return syscall2(SYS_mkdir, @ptrToInt(path), mode); | 167 | return syscall2(SYS_mkdir, @ptrToInt(path), mode); |
| 168 | } else { | 168 | } else { |
| 169 | return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode); | 169 | return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode); |
| 170 | } | 170 | } |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | // TODO https://github.com/ziglang/zig/issues/265 | 173 | // TODO https://github.com/ziglang/zig/issues/265 |
| 174 | pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize { | 174 | pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize { |
| 175 | return syscall3(SYS_mkdirat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode); | 175 | return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode); |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | // TODO https://github.com/ziglang/zig/issues/265 | 178 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -194,7 +194,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of | ... | @@ -194,7 +194,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 194 | if (@hasDecl(@This(), "SYS_mmap2")) { | 194 | if (@hasDecl(@This(), "SYS_mmap2")) { |
| 195 | // Make sure the offset is also specified in multiples of page size | 195 | // Make sure the offset is also specified in multiples of page size |
| 196 | if ((offset & (MMAP2_UNIT - 1)) != 0) | 196 | if ((offset & (MMAP2_UNIT - 1)) != 0) |
| 197 | return @bitCast(usize, isize(-EINVAL)); | 197 | return @bitCast(usize, @as(isize, -EINVAL)); |
| 198 | 198 | ||
| 199 | return syscall6( | 199 | return syscall6( |
| 200 | SYS_mmap2, | 200 | SYS_mmap2, |
| ... | @@ -202,7 +202,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of | ... | @@ -202,7 +202,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 202 | length, | 202 | length, |
| 203 | prot, | 203 | prot, |
| 204 | flags, | 204 | flags, |
| 205 | @bitCast(usize, isize(fd)), | 205 | @bitCast(usize, @as(isize, fd)), |
| 206 | @truncate(usize, offset / MMAP2_UNIT), | 206 | @truncate(usize, offset / MMAP2_UNIT), |
| 207 | ); | 207 | ); |
| 208 | } else { | 208 | } else { |
| ... | @@ -212,7 +212,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of | ... | @@ -212,7 +212,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 212 | length, | 212 | length, |
| 213 | prot, | 213 | prot, |
| 214 | flags, | 214 | flags, |
| 215 | @bitCast(usize, isize(fd)), | 215 | @bitCast(usize, @as(isize, fd)), |
| 216 | offset, | 216 | offset, |
| 217 | ); | 217 | ); |
| 218 | } | 218 | } |
| ... | @@ -249,13 +249,13 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize { | ... | @@ -249,13 +249,13 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize { |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | pub fn read(fd: i32, buf: [*]u8, count: usize) usize { | 251 | pub fn read(fd: i32, buf: [*]u8, count: usize) usize { |
| 252 | return syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); | 252 | return syscall3(SYS_read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { | 255 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { |
| 256 | return syscall5( | 256 | return syscall5( |
| 257 | SYS_preadv, | 257 | SYS_preadv, |
| 258 | @bitCast(usize, isize(fd)), | 258 | @bitCast(usize, @as(isize, fd)), |
| 259 | @ptrToInt(iov), | 259 | @ptrToInt(iov), |
| 260 | count, | 260 | count, |
| 261 | @truncate(usize, offset), | 261 | @truncate(usize, offset), |
| ... | @@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { | ... | @@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { |
| 266 | pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize { | 266 | pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize { |
| 267 | return syscall6( | 267 | return syscall6( |
| 268 | SYS_preadv2, | 268 | SYS_preadv2, |
| 269 | @bitCast(usize, isize(fd)), | 269 | @bitCast(usize, @as(isize, fd)), |
| 270 | @ptrToInt(iov), | 270 | @ptrToInt(iov), |
| 271 | count, | 271 | count, |
| 272 | @truncate(usize, offset), | 272 | @truncate(usize, offset), |
| ... | @@ -276,17 +276,17 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k | ... | @@ -276,17 +276,17 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k |
| 276 | } | 276 | } |
| 277 | 277 | ||
| 278 | pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize { | 278 | pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize { |
| 279 | return syscall3(SYS_readv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count); | 279 | return syscall3(SYS_readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); |
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { | 282 | pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { |
| 283 | return syscall3(SYS_writev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count); | 283 | return syscall3(SYS_writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { | 286 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { |
| 287 | return syscall5( | 287 | return syscall5( |
| 288 | SYS_pwritev, | 288 | SYS_pwritev, |
| 289 | @bitCast(usize, isize(fd)), | 289 | @bitCast(usize, @as(isize, fd)), |
| 290 | @ptrToInt(iov), | 290 | @ptrToInt(iov), |
| 291 | count, | 291 | count, |
| 292 | @truncate(usize, offset), | 292 | @truncate(usize, offset), |
| ... | @@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us | ... | @@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us |
| 297 | pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize { | 297 | pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize { |
| 298 | return syscall6( | 298 | return syscall6( |
| 299 | SYS_pwritev2, | 299 | SYS_pwritev2, |
| 300 | @bitCast(usize, isize(fd)), | 300 | @bitCast(usize, @as(isize, fd)), |
| 301 | @ptrToInt(iov), | 301 | @ptrToInt(iov), |
| 302 | count, | 302 | count, |
| 303 | @truncate(usize, offset), | 303 | @truncate(usize, offset), |
| ... | @@ -311,7 +311,7 @@ pub fn rmdir(path: [*]const u8) usize { | ... | @@ -311,7 +311,7 @@ pub fn rmdir(path: [*]const u8) usize { |
| 311 | if (@hasDecl(@This(), "SYS_rmdir")) { | 311 | if (@hasDecl(@This(), "SYS_rmdir")) { |
| 312 | return syscall1(SYS_rmdir, @ptrToInt(path)); | 312 | return syscall1(SYS_rmdir, @ptrToInt(path)); |
| 313 | } else { | 313 | } else { |
| 314 | return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); | 314 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); |
| 315 | } | 315 | } |
| 316 | } | 316 | } |
| 317 | 317 | ||
| ... | @@ -320,18 +320,18 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { | ... | @@ -320,18 +320,18 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { |
| 320 | if (@hasDecl(@This(), "SYS_symlink")) { | 320 | if (@hasDecl(@This(), "SYS_symlink")) { |
| 321 | return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); | 321 | return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); |
| 322 | } else { | 322 | } else { |
| 323 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); | 323 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); |
| 324 | } | 324 | } |
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | // TODO https://github.com/ziglang/zig/issues/265 | 327 | // TODO https://github.com/ziglang/zig/issues/265 |
| 328 | pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize { | 328 | pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize { |
| 329 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(newfd)), @ptrToInt(newpath)); | 329 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath)); |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | // TODO https://github.com/ziglang/zig/issues/265 | 332 | // TODO https://github.com/ziglang/zig/issues/265 |
| 333 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { | 333 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { |
| 334 | return syscall4(SYS_pread, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); | 334 | return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset); |
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | // TODO https://github.com/ziglang/zig/issues/265 | 337 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -339,13 +339,13 @@ pub fn access(path: [*]const u8, mode: u32) usize { | ... | @@ -339,13 +339,13 @@ pub fn access(path: [*]const u8, mode: u32) usize { |
| 339 | if (@hasDecl(@This(), "SYS_access")) { | 339 | if (@hasDecl(@This(), "SYS_access")) { |
| 340 | return syscall2(SYS_access, @ptrToInt(path), mode); | 340 | return syscall2(SYS_access, @ptrToInt(path), mode); |
| 341 | } else { | 341 | } else { |
| 342 | return syscall4(SYS_faccessat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode, 0); | 342 | return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0); |
| 343 | } | 343 | } |
| 344 | } | 344 | } |
| 345 | 345 | ||
| 346 | // TODO https://github.com/ziglang/zig/issues/265 | 346 | // TODO https://github.com/ziglang/zig/issues/265 |
| 347 | pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize { | 347 | pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize { |
| 348 | return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags); | 348 | return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags); |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | pub fn pipe(fd: *[2]i32) usize { | 351 | pub fn pipe(fd: *[2]i32) usize { |
| ... | @@ -363,11 +363,11 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize { | ... | @@ -363,11 +363,11 @@ pub fn pipe2(fd: *[2]i32, flags: u32) usize { |
| 363 | } | 363 | } |
| 364 | 364 | ||
| 365 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { | 365 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { |
| 366 | return syscall3(SYS_write, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); | 366 | return syscall3(SYS_write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { | 369 | pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { |
| 370 | return syscall4(SYS_pwrite, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); | 370 | return syscall4(SYS_pwrite, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset); |
| 371 | } | 371 | } |
| 372 | 372 | ||
| 373 | // TODO https://github.com/ziglang/zig/issues/265 | 373 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -375,9 +375,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize { | ... | @@ -375,9 +375,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize { |
| 375 | if (@hasDecl(@This(), "SYS_rename")) { | 375 | if (@hasDecl(@This(), "SYS_rename")) { |
| 376 | return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); | 376 | return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); |
| 377 | } else if (@hasDecl(@This(), "SYS_renameat")) { | 377 | } else if (@hasDecl(@This(), "SYS_renameat")) { |
| 378 | return syscall4(SYS_renameat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); | 378 | return syscall4(SYS_renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); |
| 379 | } else { | 379 | } else { |
| 380 | return syscall5(SYS_renameat2, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new), 0); | 380 | return syscall5(SYS_renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0); |
| 381 | } | 381 | } |
| 382 | } | 382 | } |
| 383 | 383 | ||
| ... | @@ -385,17 +385,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const | ... | @@ -385,17 +385,17 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const |
| 385 | if (@hasDecl(@This(), "SYS_renameat")) { | 385 | if (@hasDecl(@This(), "SYS_renameat")) { |
| 386 | return syscall4( | 386 | return syscall4( |
| 387 | SYS_renameat, | 387 | SYS_renameat, |
| 388 | @bitCast(usize, isize(oldfd)), | 388 | @bitCast(usize, @as(isize, oldfd)), |
| 389 | @ptrToInt(old), | 389 | @ptrToInt(old), |
| 390 | @bitCast(usize, isize(newfd)), | 390 | @bitCast(usize, @as(isize, newfd)), |
| 391 | @ptrToInt(new), | 391 | @ptrToInt(new), |
| 392 | ); | 392 | ); |
| 393 | } else { | 393 | } else { |
| 394 | return syscall5( | 394 | return syscall5( |
| 395 | SYS_renameat2, | 395 | SYS_renameat2, |
| 396 | @bitCast(usize, isize(oldfd)), | 396 | @bitCast(usize, @as(isize, oldfd)), |
| 397 | @ptrToInt(old), | 397 | @ptrToInt(old), |
| 398 | @bitCast(usize, isize(newfd)), | 398 | @bitCast(usize, @as(isize, newfd)), |
| 399 | @ptrToInt(new), | 399 | @ptrToInt(new), |
| 400 | 0, | 400 | 0, |
| 401 | ); | 401 | ); |
| ... | @@ -406,9 +406,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const | ... | @@ -406,9 +406,9 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const |
| 406 | pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize { | 406 | pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize { |
| 407 | return syscall5( | 407 | return syscall5( |
| 408 | SYS_renameat2, | 408 | SYS_renameat2, |
| 409 | @bitCast(usize, isize(oldfd)), | 409 | @bitCast(usize, @as(isize, oldfd)), |
| 410 | @ptrToInt(oldpath), | 410 | @ptrToInt(oldpath), |
| 411 | @bitCast(usize, isize(newfd)), | 411 | @bitCast(usize, @as(isize, newfd)), |
| 412 | @ptrToInt(newpath), | 412 | @ptrToInt(newpath), |
| 413 | flags, | 413 | flags, |
| 414 | ); | 414 | ); |
| ... | @@ -421,7 +421,7 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { | ... | @@ -421,7 +421,7 @@ pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { |
| 421 | } else { | 421 | } else { |
| 422 | return syscall4( | 422 | return syscall4( |
| 423 | SYS_openat, | 423 | SYS_openat, |
| 424 | @bitCast(usize, isize(AT_FDCWD)), | 424 | @bitCast(usize, @as(isize, AT_FDCWD)), |
| 425 | @ptrToInt(path), | 425 | @ptrToInt(path), |
| 426 | flags, | 426 | flags, |
| 427 | perm, | 427 | perm, |
| ... | @@ -437,7 +437,7 @@ pub fn create(path: [*]const u8, perm: usize) usize { | ... | @@ -437,7 +437,7 @@ pub fn create(path: [*]const u8, perm: usize) usize { |
| 437 | // TODO https://github.com/ziglang/zig/issues/265 | 437 | // TODO https://github.com/ziglang/zig/issues/265 |
| 438 | pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize { | 438 | pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize { |
| 439 | // dirfd could be negative, for example AT_FDCWD is -100 | 439 | // dirfd could be negative, for example AT_FDCWD is -100 |
| 440 | return syscall4(SYS_openat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode); | 440 | return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode); |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | /// See also `clone` (from the arch-specific include) | 443 | /// See also `clone` (from the arch-specific include) |
| ... | @@ -451,14 +451,14 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize { | ... | @@ -451,14 +451,14 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize { |
| 451 | } | 451 | } |
| 452 | 452 | ||
| 453 | pub fn close(fd: i32) usize { | 453 | pub fn close(fd: i32) usize { |
| 454 | return syscall1(SYS_close, @bitCast(usize, isize(fd))); | 454 | return syscall1(SYS_close, @bitCast(usize, @as(isize, fd))); |
| 455 | } | 455 | } |
| 456 | 456 | ||
| 457 | /// Can only be called on 32 bit systems. For 64 bit see `lseek`. | 457 | /// Can only be called on 32 bit systems. For 64 bit see `lseek`. |
| 458 | pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { | 458 | pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { |
| 459 | return syscall5( | 459 | return syscall5( |
| 460 | SYS__llseek, | 460 | SYS__llseek, |
| 461 | @bitCast(usize, isize(fd)), | 461 | @bitCast(usize, @as(isize, fd)), |
| 462 | @truncate(usize, offset >> 32), | 462 | @truncate(usize, offset >> 32), |
| 463 | @truncate(usize, offset), | 463 | @truncate(usize, offset), |
| 464 | @ptrToInt(result), | 464 | @ptrToInt(result), |
| ... | @@ -468,16 +468,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { | ... | @@ -468,16 +468,16 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { |
| 468 | 468 | ||
| 469 | /// Can only be called on 64 bit systems. For 32 bit see `llseek`. | 469 | /// Can only be called on 64 bit systems. For 32 bit see `llseek`. |
| 470 | pub fn lseek(fd: i32, offset: i64, whence: usize) usize { | 470 | pub fn lseek(fd: i32, offset: i64, whence: usize) usize { |
| 471 | return syscall3(SYS_lseek, @bitCast(usize, isize(fd)), @bitCast(usize, offset), whence); | 471 | return syscall3(SYS_lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence); |
| 472 | } | 472 | } |
| 473 | 473 | ||
| 474 | pub fn exit(status: i32) noreturn { | 474 | pub fn exit(status: i32) noreturn { |
| 475 | _ = syscall1(SYS_exit, @bitCast(usize, isize(status))); | 475 | _ = syscall1(SYS_exit, @bitCast(usize, @as(isize, status))); |
| 476 | unreachable; | 476 | unreachable; |
| 477 | } | 477 | } |
| 478 | 478 | ||
| 479 | pub fn exit_group(status: i32) noreturn { | 479 | pub fn exit_group(status: i32) noreturn { |
| 480 | _ = syscall1(SYS_exit_group, @bitCast(usize, isize(status))); | 480 | _ = syscall1(SYS_exit_group, @bitCast(usize, @as(isize, status))); |
| 481 | unreachable; | 481 | unreachable; |
| 482 | } | 482 | } |
| 483 | 483 | ||
| ... | @@ -486,7 +486,7 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { | ... | @@ -486,7 +486,7 @@ pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { |
| 486 | } | 486 | } |
| 487 | 487 | ||
| 488 | pub fn kill(pid: i32, sig: i32) usize { | 488 | pub fn kill(pid: i32, sig: i32) usize { |
| 489 | return syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig))); | 489 | return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig))); |
| 490 | } | 490 | } |
| 491 | 491 | ||
| 492 | // TODO https://github.com/ziglang/zig/issues/265 | 492 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -494,17 +494,17 @@ pub fn unlink(path: [*]const u8) usize { | ... | @@ -494,17 +494,17 @@ pub fn unlink(path: [*]const u8) usize { |
| 494 | if (@hasDecl(@This(), "SYS_unlink")) { | 494 | if (@hasDecl(@This(), "SYS_unlink")) { |
| 495 | return syscall1(SYS_unlink, @ptrToInt(path)); | 495 | return syscall1(SYS_unlink, @ptrToInt(path)); |
| 496 | } else { | 496 | } else { |
| 497 | return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0); | 497 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0); |
| 498 | } | 498 | } |
| 499 | } | 499 | } |
| 500 | 500 | ||
| 501 | // TODO https://github.com/ziglang/zig/issues/265 | 501 | // TODO https://github.com/ziglang/zig/issues/265 |
| 502 | pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize { | 502 | pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize { |
| 503 | return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags); | 503 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags); |
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | pub fn waitpid(pid: i32, status: *u32, flags: u32) usize { | 506 | pub fn waitpid(pid: i32, status: *u32, flags: u32) usize { |
| 507 | return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), flags, 0); | 507 | return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0); |
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime); | 510 | var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime); |
| ... | @@ -519,12 +519,12 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { | ... | @@ -519,12 +519,12 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { |
| 519 | const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); | 519 | const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); |
| 520 | const rc = f(clk_id, tp); | 520 | const rc = f(clk_id, tp); |
| 521 | switch (rc) { | 521 | switch (rc) { |
| 522 | 0, @bitCast(usize, isize(-EINVAL)) => return rc, | 522 | 0, @bitCast(usize, @as(isize, -EINVAL)) => return rc, |
| 523 | else => {}, | 523 | else => {}, |
| 524 | } | 524 | } |
| 525 | } | 525 | } |
| 526 | } | 526 | } |
| 527 | return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); | 527 | return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); |
| 528 | } | 528 | } |
| 529 | 529 | ||
| 530 | extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { | 530 | extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { |
| ... | @@ -537,15 +537,15 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { | ... | @@ -537,15 +537,15 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { |
| 537 | const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); | 537 | const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); |
| 538 | return f(clk, ts); | 538 | return f(clk, ts); |
| 539 | } | 539 | } |
| 540 | return @bitCast(usize, isize(-ENOSYS)); | 540 | return @bitCast(usize, @as(isize, -ENOSYS)); |
| 541 | } | 541 | } |
| 542 | 542 | ||
| 543 | pub fn clock_getres(clk_id: i32, tp: *timespec) usize { | 543 | pub fn clock_getres(clk_id: i32, tp: *timespec) usize { |
| 544 | return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); | 544 | return syscall2(SYS_clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); |
| 545 | } | 545 | } |
| 546 | 546 | ||
| 547 | pub fn clock_settime(clk_id: i32, tp: *const timespec) usize { | 547 | pub fn clock_settime(clk_id: i32, tp: *const timespec) usize { |
| 548 | return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); | 548 | return syscall2(SYS_clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); |
| 549 | } | 549 | } |
| 550 | 550 | ||
| 551 | pub fn gettimeofday(tv: *timeval, tz: *timezone) usize { | 551 | pub fn gettimeofday(tv: *timeval, tz: *timezone) usize { |
| ... | @@ -594,33 +594,33 @@ pub fn setregid(rgid: u32, egid: u32) usize { | ... | @@ -594,33 +594,33 @@ pub fn setregid(rgid: u32, egid: u32) usize { |
| 594 | 594 | ||
| 595 | pub fn getuid() u32 { | 595 | pub fn getuid() u32 { |
| 596 | if (@hasDecl(@This(), "SYS_getuid32")) { | 596 | if (@hasDecl(@This(), "SYS_getuid32")) { |
| 597 | return u32(syscall0(SYS_getuid32)); | 597 | return @as(u32, syscall0(SYS_getuid32)); |
| 598 | } else { | 598 | } else { |
| 599 | return u32(syscall0(SYS_getuid)); | 599 | return @as(u32, syscall0(SYS_getuid)); |
| 600 | } | 600 | } |
| 601 | } | 601 | } |
| 602 | 602 | ||
| 603 | pub fn getgid() u32 { | 603 | pub fn getgid() u32 { |
| 604 | if (@hasDecl(@This(), "SYS_getgid32")) { | 604 | if (@hasDecl(@This(), "SYS_getgid32")) { |
| 605 | return u32(syscall0(SYS_getgid32)); | 605 | return @as(u32, syscall0(SYS_getgid32)); |
| 606 | } else { | 606 | } else { |
| 607 | return u32(syscall0(SYS_getgid)); | 607 | return @as(u32, syscall0(SYS_getgid)); |
| 608 | } | 608 | } |
| 609 | } | 609 | } |
| 610 | 610 | ||
| 611 | pub fn geteuid() u32 { | 611 | pub fn geteuid() u32 { |
| 612 | if (@hasDecl(@This(), "SYS_geteuid32")) { | 612 | if (@hasDecl(@This(), "SYS_geteuid32")) { |
| 613 | return u32(syscall0(SYS_geteuid32)); | 613 | return @as(u32, syscall0(SYS_geteuid32)); |
| 614 | } else { | 614 | } else { |
| 615 | return u32(syscall0(SYS_geteuid)); | 615 | return @as(u32, syscall0(SYS_geteuid)); |
| 616 | } | 616 | } |
| 617 | } | 617 | } |
| 618 | 618 | ||
| 619 | pub fn getegid() u32 { | 619 | pub fn getegid() u32 { |
| 620 | if (@hasDecl(@This(), "SYS_getegid32")) { | 620 | if (@hasDecl(@This(), "SYS_getegid32")) { |
| 621 | return u32(syscall0(SYS_getegid32)); | 621 | return @as(u32, syscall0(SYS_getegid32)); |
| 622 | } else { | 622 | } else { |
| 623 | return u32(syscall0(SYS_getegid)); | 623 | return @as(u32, syscall0(SYS_getegid)); |
| 624 | } | 624 | } |
| 625 | } | 625 | } |
| 626 | 626 | ||
| ... | @@ -743,11 +743,11 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool { | ... | @@ -743,11 +743,11 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool { |
| 743 | } | 743 | } |
| 744 | 744 | ||
| 745 | pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { | 745 | pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { |
| 746 | return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); | 746 | return syscall3(SYS_getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); |
| 747 | } | 747 | } |
| 748 | 748 | ||
| 749 | pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { | 749 | pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { |
| 750 | return syscall3(SYS_getpeername, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); | 750 | return syscall3(SYS_getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); |
| 751 | } | 751 | } |
| 752 | 752 | ||
| 753 | pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { | 753 | pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { |
| ... | @@ -755,15 +755,15 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { | ... | @@ -755,15 +755,15 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { |
| 755 | } | 755 | } |
| 756 | 756 | ||
| 757 | pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize { | 757 | pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize { |
| 758 | return syscall5(SYS_setsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); | 758 | return syscall5(SYS_setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); |
| 759 | } | 759 | } |
| 760 | 760 | ||
| 761 | pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize { | 761 | pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize { |
| 762 | return syscall5(SYS_getsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); | 762 | return syscall5(SYS_getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); |
| 763 | } | 763 | } |
| 764 | 764 | ||
| 765 | pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize { | 765 | pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize { |
| 766 | return syscall3(SYS_sendmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags); | 766 | return syscall3(SYS_sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); |
| 767 | } | 767 | } |
| 768 | 768 | ||
| 769 | pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize { | 769 | pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize { |
| ... | @@ -781,7 +781,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize | ... | @@ -781,7 +781,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize |
| 781 | // batch-send all messages up to the current message | 781 | // batch-send all messages up to the current message |
| 782 | if (next_unsent < i) { | 782 | if (next_unsent < i) { |
| 783 | const batch_size = i - next_unsent; | 783 | const batch_size = i - next_unsent; |
| 784 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | 784 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); |
| 785 | if (getErrno(r) != 0) return next_unsent; | 785 | if (getErrno(r) != 0) return next_unsent; |
| 786 | if (r < batch_size) return next_unsent + r; | 786 | if (r < batch_size) return next_unsent + r; |
| 787 | } | 787 | } |
| ... | @@ -797,41 +797,41 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize | ... | @@ -797,41 +797,41 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize |
| 797 | } | 797 | } |
| 798 | if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR) | 798 | if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR) |
| 799 | const batch_size = kvlen - next_unsent; | 799 | const batch_size = kvlen - next_unsent; |
| 800 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | 800 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); |
| 801 | if (getErrno(r) != 0) return r; | 801 | if (getErrno(r) != 0) return r; |
| 802 | return next_unsent + r; | 802 | return next_unsent + r; |
| 803 | } | 803 | } |
| 804 | return kvlen; | 804 | return kvlen; |
| 805 | } | 805 | } |
| 806 | return syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(msgvec), vlen, flags); | 806 | return syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags); |
| 807 | } | 807 | } |
| 808 | 808 | ||
| 809 | pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { | 809 | pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { |
| 810 | return syscall3(SYS_connect, @bitCast(usize, isize(fd)), @ptrToInt(addr), len); | 810 | return syscall3(SYS_connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len); |
| 811 | } | 811 | } |
| 812 | 812 | ||
| 813 | pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize { | 813 | pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize { |
| 814 | return syscall3(SYS_recvmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags); | 814 | return syscall3(SYS_recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); |
| 815 | } | 815 | } |
| 816 | 816 | ||
| 817 | pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize { | 817 | pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize { |
| 818 | return syscall6(SYS_recvfrom, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); | 818 | return syscall6(SYS_recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); |
| 819 | } | 819 | } |
| 820 | 820 | ||
| 821 | pub fn shutdown(fd: i32, how: i32) usize { | 821 | pub fn shutdown(fd: i32, how: i32) usize { |
| 822 | return syscall2(SYS_shutdown, @bitCast(usize, isize(fd)), @bitCast(usize, isize(how))); | 822 | return syscall2(SYS_shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how))); |
| 823 | } | 823 | } |
| 824 | 824 | ||
| 825 | pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { | 825 | pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { |
| 826 | return syscall3(SYS_bind, @bitCast(usize, isize(fd)), @ptrToInt(addr), @intCast(usize, len)); | 826 | return syscall3(SYS_bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len)); |
| 827 | } | 827 | } |
| 828 | 828 | ||
| 829 | pub fn listen(fd: i32, backlog: u32) usize { | 829 | pub fn listen(fd: i32, backlog: u32) usize { |
| 830 | return syscall2(SYS_listen, @bitCast(usize, isize(fd)), backlog); | 830 | return syscall2(SYS_listen, @bitCast(usize, @as(isize, fd)), backlog); |
| 831 | } | 831 | } |
| 832 | 832 | ||
| 833 | pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize { | 833 | pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize { |
| 834 | return syscall6(SYS_sendto, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); | 834 | return syscall6(SYS_sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); |
| 835 | } | 835 | } |
| 836 | 836 | ||
| 837 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { | 837 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { |
| ... | @@ -843,14 +843,14 @@ pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { | ... | @@ -843,14 +843,14 @@ pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { |
| 843 | } | 843 | } |
| 844 | 844 | ||
| 845 | pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize { | 845 | pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize { |
| 846 | return syscall4(SYS_accept4, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len), flags); | 846 | return syscall4(SYS_accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags); |
| 847 | } | 847 | } |
| 848 | 848 | ||
| 849 | pub fn fstat(fd: i32, stat_buf: *Stat) usize { | 849 | pub fn fstat(fd: i32, stat_buf: *Stat) usize { |
| 850 | if (@hasDecl(@This(), "SYS_fstat64")) { | 850 | if (@hasDecl(@This(), "SYS_fstat64")) { |
| 851 | return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); | 851 | return syscall2(SYS_fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); |
| 852 | } else { | 852 | } else { |
| 853 | return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); | 853 | return syscall2(SYS_fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); |
| 854 | } | 854 | } |
| 855 | } | 855 | } |
| 856 | 856 | ||
| ... | @@ -875,9 +875,9 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { | ... | @@ -875,9 +875,9 @@ pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { |
| 875 | // TODO https://github.com/ziglang/zig/issues/265 | 875 | // TODO https://github.com/ziglang/zig/issues/265 |
| 876 | pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize { | 876 | pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize { |
| 877 | if (@hasDecl(@This(), "SYS_fstatat64")) { | 877 | if (@hasDecl(@This(), "SYS_fstatat64")) { |
| 878 | return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | 878 | return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); |
| 879 | } else { | 879 | } else { |
| 880 | return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | 880 | return syscall4(SYS_fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); |
| 881 | } | 881 | } |
| 882 | } | 882 | } |
| 883 | 883 | ||
| ... | @@ -885,14 +885,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S | ... | @@ -885,14 +885,14 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S |
| 885 | if (@hasDecl(@This(), "SYS_statx")) { | 885 | if (@hasDecl(@This(), "SYS_statx")) { |
| 886 | return syscall5( | 886 | return syscall5( |
| 887 | SYS_statx, | 887 | SYS_statx, |
| 888 | @bitCast(usize, isize(dirfd)), | 888 | @bitCast(usize, @as(isize, dirfd)), |
| 889 | @ptrToInt(path), | 889 | @ptrToInt(path), |
| 890 | flags, | 890 | flags, |
| 891 | mask, | 891 | mask, |
| 892 | @ptrToInt(statx_buf), | 892 | @ptrToInt(statx_buf), |
| 893 | ); | 893 | ); |
| 894 | } | 894 | } |
| 895 | return @bitCast(usize, isize(-ENOSYS)); | 895 | return @bitCast(usize, @as(isize, -ENOSYS)); |
| 896 | } | 896 | } |
| 897 | 897 | ||
| 898 | // TODO https://github.com/ziglang/zig/issues/265 | 898 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -959,7 +959,7 @@ pub fn sched_yield() usize { | ... | @@ -959,7 +959,7 @@ pub fn sched_yield() usize { |
| 959 | } | 959 | } |
| 960 | 960 | ||
| 961 | pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize { | 961 | pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize { |
| 962 | const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), size, @ptrToInt(set)); | 962 | const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set)); |
| 963 | if (@bitCast(isize, rc) < 0) return rc; | 963 | if (@bitCast(isize, rc) < 0) return rc; |
| 964 | if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc); | 964 | if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc); |
| 965 | return 0; | 965 | return 0; |
| ... | @@ -974,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize { | ... | @@ -974,7 +974,7 @@ pub fn epoll_create1(flags: usize) usize { |
| 974 | } | 974 | } |
| 975 | 975 | ||
| 976 | pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize { | 976 | pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize { |
| 977 | return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev)); | 977 | return syscall4(SYS_epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev)); |
| 978 | } | 978 | } |
| 979 | 979 | ||
| 980 | pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { | 980 | pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { |
| ... | @@ -984,10 +984,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout | ... | @@ -984,10 +984,10 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout |
| 984 | pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { | 984 | pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { |
| 985 | return syscall6( | 985 | return syscall6( |
| 986 | SYS_epoll_pwait, | 986 | SYS_epoll_pwait, |
| 987 | @bitCast(usize, isize(epoll_fd)), | 987 | @bitCast(usize, @as(isize, epoll_fd)), |
| 988 | @ptrToInt(events), | 988 | @ptrToInt(events), |
| 989 | @intCast(usize, maxevents), | 989 | @intCast(usize, maxevents), |
| 990 | @bitCast(usize, isize(timeout)), | 990 | @bitCast(usize, @as(isize, timeout)), |
| 991 | @ptrToInt(sigmask), | 991 | @ptrToInt(sigmask), |
| 992 | @sizeOf(sigset_t), | 992 | @sizeOf(sigset_t), |
| 993 | ); | 993 | ); |
| ... | @@ -998,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize { | ... | @@ -998,7 +998,7 @@ pub fn eventfd(count: u32, flags: u32) usize { |
| 998 | } | 998 | } |
| 999 | 999 | ||
| 1000 | pub fn timerfd_create(clockid: i32, flags: u32) usize { | 1000 | pub fn timerfd_create(clockid: i32, flags: u32) usize { |
| 1001 | return syscall2(SYS_timerfd_create, @bitCast(usize, isize(clockid)), flags); | 1001 | return syscall2(SYS_timerfd_create, @bitCast(usize, @as(isize, clockid)), flags); |
| 1002 | } | 1002 | } |
| 1003 | 1003 | ||
| 1004 | pub const itimerspec = extern struct { | 1004 | pub const itimerspec = extern struct { |
| ... | @@ -1007,11 +1007,11 @@ pub const itimerspec = extern struct { | ... | @@ -1007,11 +1007,11 @@ pub const itimerspec = extern struct { |
| 1007 | }; | 1007 | }; |
| 1008 | 1008 | ||
| 1009 | pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize { | 1009 | pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize { |
| 1010 | return syscall2(SYS_timerfd_gettime, @bitCast(usize, isize(fd)), @ptrToInt(curr_value)); | 1010 | return syscall2(SYS_timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value)); |
| 1011 | } | 1011 | } |
| 1012 | 1012 | ||
| 1013 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { | 1013 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { |
| 1014 | return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); | 1014 | return syscall4(SYS_timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); |
| 1015 | } | 1015 | } |
| 1016 | 1016 | ||
| 1017 | pub fn unshare(flags: usize) usize { | 1017 | pub fn unshare(flags: usize) usize { |
| ... | @@ -1096,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize { | ... | @@ -1096,11 +1096,11 @@ pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize { |
| 1096 | } | 1096 | } |
| 1097 | 1097 | ||
| 1098 | pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize { | 1098 | pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize { |
| 1099 | return syscall6(SYS_io_uring_enter, @bitCast(usize, isize(fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8); | 1099 | return syscall6(SYS_io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8); |
| 1100 | } | 1100 | } |
| 1101 | 1101 | ||
| 1102 | pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize { | 1102 | pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize { |
| 1103 | return syscall4(SYS_io_uring_register, @bitCast(usize, isize(fd)), opcode, @ptrToInt(arg), nr_args); | 1103 | return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args); |
| 1104 | } | 1104 | } |
| 1105 | 1105 | ||
| 1106 | test "" { | 1106 | test "" { |
lib/std/os/linux/arm-eabi.zig+2-2| ... | @@ -100,7 +100,7 @@ pub extern fn getThreadPointer() usize { | ... | @@ -100,7 +100,7 @@ pub extern fn getThreadPointer() usize { |
| 100 | pub nakedcc fn restore() void { | 100 | pub nakedcc fn restore() void { |
| 101 | return asm volatile ("svc #0" | 101 | return asm volatile ("svc #0" |
| 102 | : | 102 | : |
| 103 | : [number] "{r7}" (usize(SYS_sigreturn)) | 103 | : [number] "{r7}" (@as(usize, SYS_sigreturn)) |
| 104 | : "memory" | 104 | : "memory" |
| 105 | ); | 105 | ); |
| 106 | } | 106 | } |
| ... | @@ -108,7 +108,7 @@ pub nakedcc fn restore() void { | ... | @@ -108,7 +108,7 @@ pub nakedcc fn restore() void { |
| 108 | pub nakedcc fn restore_rt() void { | 108 | pub nakedcc fn restore_rt() void { |
| 109 | return asm volatile ("svc #0" | 109 | return asm volatile ("svc #0" |
| 110 | : | 110 | : |
| 111 | : [number] "{r7}" (usize(SYS_rt_sigreturn)) | 111 | : [number] "{r7}" (@as(usize, SYS_rt_sigreturn)) |
| 112 | : "memory" | 112 | : "memory" |
| 113 | ); | 113 | ); |
| 114 | } | 114 | } |
lib/std/os/linux/arm64.zig+1-1| ... | @@ -93,7 +93,7 @@ pub const restore = restore_rt; | ... | @@ -93,7 +93,7 @@ pub const restore = restore_rt; |
| 93 | pub nakedcc fn restore_rt() void { | 93 | pub nakedcc fn restore_rt() void { |
| 94 | return asm volatile ("svc #0" | 94 | return asm volatile ("svc #0" |
| 95 | : | 95 | : |
| 96 | : [number] "{x8}" (usize(SYS_rt_sigreturn)) | 96 | : [number] "{x8}" (@as(usize, SYS_rt_sigreturn)) |
| 97 | : "memory", "cc" | 97 | : "memory", "cc" |
| 98 | ); | 98 | ); |
| 99 | } | 99 | } |
lib/std/os/linux/mipsel.zig+3-3| ... | @@ -26,7 +26,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize { | ... | @@ -26,7 +26,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize { |
| 26 | \\ sw $3, 4($4) | 26 | \\ sw $3, 4($4) |
| 27 | \\ 2: | 27 | \\ 2: |
| 28 | : [ret] "={$2}" (-> usize) | 28 | : [ret] "={$2}" (-> usize) |
| 29 | : [number] "{$2}" (usize(SYS_pipe)) | 29 | : [number] "{$2}" (@as(usize, SYS_pipe)) |
| 30 | : "memory", "cc", "$7" | 30 | : "memory", "cc", "$7" |
| 31 | ); | 31 | ); |
| 32 | } | 32 | } |
| ... | @@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a | ... | @@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a |
| 147 | pub nakedcc fn restore() void { | 147 | pub nakedcc fn restore() void { |
| 148 | return asm volatile ("syscall" | 148 | return asm volatile ("syscall" |
| 149 | : | 149 | : |
| 150 | : [number] "{$2}" (usize(SYS_sigreturn)) | 150 | : [number] "{$2}" (@as(usize, SYS_sigreturn)) |
| 151 | : "memory", "cc", "$7" | 151 | : "memory", "cc", "$7" |
| 152 | ); | 152 | ); |
| 153 | } | 153 | } |
| ... | @@ -155,7 +155,7 @@ pub nakedcc fn restore() void { | ... | @@ -155,7 +155,7 @@ pub nakedcc fn restore() void { |
| 155 | pub nakedcc fn restore_rt() void { | 155 | pub nakedcc fn restore_rt() void { |
| 156 | return asm volatile ("syscall" | 156 | return asm volatile ("syscall" |
| 157 | : | 157 | : |
| 158 | : [number] "{$2}" (usize(SYS_rt_sigreturn)) | 158 | : [number] "{$2}" (@as(usize, SYS_rt_sigreturn)) |
| 159 | : "memory", "cc", "$7" | 159 | : "memory", "cc", "$7" |
| 160 | ); | 160 | ); |
| 161 | } | 161 | } |
lib/std/os/linux/riscv64.zig+1-1| ... | @@ -92,7 +92,7 @@ pub const restore = restore_rt; | ... | @@ -92,7 +92,7 @@ pub const restore = restore_rt; |
| 92 | pub nakedcc fn restore_rt() void { | 92 | pub nakedcc fn restore_rt() void { |
| 93 | return asm volatile ("ecall" | 93 | return asm volatile ("ecall" |
| 94 | : | 94 | : |
| 95 | : [number] "{x17}" (usize(SYS_rt_sigreturn)) | 95 | : [number] "{x17}" (@as(usize, SYS_rt_sigreturn)) |
| 96 | : "memory" | 96 | : "memory" |
| 97 | ); | 97 | ); |
| 98 | } | 98 | } |
lib/std/os/linux/test.zig+3-3| ... | @@ -72,7 +72,7 @@ test "statx" { | ... | @@ -72,7 +72,7 @@ test "statx" { |
| 72 | expect(stat_buf.mode == statx_buf.mode); | 72 | expect(stat_buf.mode == statx_buf.mode); |
| 73 | expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid); | 73 | expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid); |
| 74 | expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid); | 74 | expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid); |
| 75 | expect(@bitCast(u64, i64(stat_buf.size)) == statx_buf.size); | 75 | expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size); |
| 76 | expect(@bitCast(u64, i64(stat_buf.blksize)) == statx_buf.blksize); | 76 | expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize); |
| 77 | expect(@bitCast(u64, i64(stat_buf.blocks)) == statx_buf.blocks); | 77 | expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks); |
| 78 | } | 78 | } |
lib/std/os/linux/vdso.zig+2-2| ... | @@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { | ... | @@ -62,8 +62,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 62 | 62 | ||
| 63 | var i: usize = 0; | 63 | var i: usize = 0; |
| 64 | while (i < hashtab[1]) : (i += 1) { | 64 | while (i < hashtab[1]) : (i += 1) { |
| 65 | if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue; | 65 | if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue; |
| 66 | if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; | 66 | if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; |
| 67 | if (0 == syms[i].st_shndx) continue; | 67 | if (0 == syms[i].st_shndx) continue; |
| 68 | if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue; | 68 | if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue; |
| 69 | if (maybe_versym) |versym| { | 69 | if (maybe_versym) |versym| { |
lib/std/os/linux/x86_64.zig+1-1| ... | @@ -93,7 +93,7 @@ pub const restore = restore_rt; | ... | @@ -93,7 +93,7 @@ pub const restore = restore_rt; |
| 93 | pub nakedcc fn restore_rt() void { | 93 | pub nakedcc fn restore_rt() void { |
| 94 | return asm volatile ("syscall" | 94 | return asm volatile ("syscall" |
| 95 | : | 95 | : |
| 96 | : [number] "{rax}" (usize(SYS_rt_sigreturn)) | 96 | : [number] "{rax}" (@as(usize, SYS_rt_sigreturn)) |
| 97 | : "rcx", "r11", "memory" | 97 | : "rcx", "r11", "memory" |
| 98 | ); | 98 | ); |
| 99 | } | 99 | } |
lib/std/os/test.zig+1-1| ... | @@ -172,7 +172,7 @@ export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 { | ... | @@ -172,7 +172,7 @@ export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 { |
| 172 | 172 | ||
| 173 | var counter = data.?; | 173 | var counter = data.?; |
| 174 | // Count how many libraries are loaded | 174 | // Count how many libraries are loaded |
| 175 | counter.* += usize(1); | 175 | counter.* += @as(usize, 1); |
| 176 | 176 | ||
| 177 | // The image should contain at least a PT_LOAD segment | 177 | // The image should contain at least a PT_LOAD segment |
| 178 | if (info.dlpi_phnum < 1) return -1; | 178 | if (info.dlpi_phnum < 1) return -1; |
lib/std/os/windows.zig+2-2| ... | @@ -262,7 +262,7 @@ pub const ReadFileError = error{Unexpected}; | ... | @@ -262,7 +262,7 @@ pub const ReadFileError = error{Unexpected}; |
| 262 | pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize { | 262 | pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize { |
| 263 | var index: usize = 0; | 263 | var index: usize = 0; |
| 264 | while (index < buffer.len) { | 264 | while (index < buffer.len) { |
| 265 | const want_read_count = @intCast(DWORD, math.min(DWORD(maxInt(DWORD)), buffer.len - index)); | 265 | const want_read_count = @intCast(DWORD, math.min(@as(DWORD, maxInt(DWORD)), buffer.len - index)); |
| 266 | var amt_read: DWORD = undefined; | 266 | var amt_read: DWORD = undefined; |
| 267 | if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, null) == 0) { | 267 | if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, null) == 0) { |
| 268 | switch (kernel32.GetLastError()) { | 268 | switch (kernel32.GetLastError()) { |
| ... | @@ -801,7 +801,7 @@ pub fn toSysTime(ns: i64) i64 { | ... | @@ -801,7 +801,7 @@ pub fn toSysTime(ns: i64) i64 { |
| 801 | } | 801 | } |
| 802 | 802 | ||
| 803 | pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 { | 803 | pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 { |
| 804 | const hns = @bitCast(i64, (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime); | 804 | const hns = @bitCast(i64, (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime); |
| 805 | return fromSysTime(hns); | 805 | return fromSysTime(hns); |
| 806 | } | 806 | } |
| 807 | 807 |
lib/std/os/windows/bits.zig+12-12| ... | @@ -69,7 +69,7 @@ pub const FALSE = 0; | ... | @@ -69,7 +69,7 @@ pub const FALSE = 0; |
| 69 | 69 | ||
| 70 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); | 70 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); |
| 71 | 71 | ||
| 72 | pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD)); | 72 | pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD)); |
| 73 | 73 | ||
| 74 | pub const FILE_ALL_INFORMATION = extern struct { | 74 | pub const FILE_ALL_INFORMATION = extern struct { |
| 75 | BasicInformation: FILE_BASIC_INFORMATION, | 75 | BasicInformation: FILE_BASIC_INFORMATION, |
| ... | @@ -571,16 +571,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256; | ... | @@ -571,16 +571,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256; |
| 571 | pub const KF_FLAG_ALIAS_ONLY = -2147483648; | 571 | pub const KF_FLAG_ALIAS_ONLY = -2147483648; |
| 572 | 572 | ||
| 573 | pub const S_OK = 0; | 573 | pub const S_OK = 0; |
| 574 | pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001)); | 574 | pub const E_NOTIMPL = @bitCast(c_long, @as(c_ulong, 0x80004001)); |
| 575 | pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002)); | 575 | pub const E_NOINTERFACE = @bitCast(c_long, @as(c_ulong, 0x80004002)); |
| 576 | pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003)); | 576 | pub const E_POINTER = @bitCast(c_long, @as(c_ulong, 0x80004003)); |
| 577 | pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004)); | 577 | pub const E_ABORT = @bitCast(c_long, @as(c_ulong, 0x80004004)); |
| 578 | pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005)); | 578 | pub const E_FAIL = @bitCast(c_long, @as(c_ulong, 0x80004005)); |
| 579 | pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF)); | 579 | pub const E_UNEXPECTED = @bitCast(c_long, @as(c_ulong, 0x8000FFFF)); |
| 580 | pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005)); | 580 | pub const E_ACCESSDENIED = @bitCast(c_long, @as(c_ulong, 0x80070005)); |
| 581 | pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006)); | 581 | pub const E_HANDLE = @bitCast(c_long, @as(c_ulong, 0x80070006)); |
| 582 | pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E)); | 582 | pub const E_OUTOFMEMORY = @bitCast(c_long, @as(c_ulong, 0x8007000E)); |
| 583 | pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057)); | 583 | pub const E_INVALIDARG = @bitCast(c_long, @as(c_ulong, 0x80070057)); |
| 584 | 584 | ||
| 585 | pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; | 585 | pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; |
| 586 | pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000; | 586 | pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000; |
| ... | @@ -873,4 +873,4 @@ pub const CURDIR = extern struct { | ... | @@ -873,4 +873,4 @@ pub const CURDIR = extern struct { |
| 873 | Handle: HANDLE, | 873 | Handle: HANDLE, |
| 874 | }; | 874 | }; |
| 875 | 875 | ||
| 876 | pub const DUPLICATE_SAME_ACCESS = 2; | ||
| \ No newline at end of file | |||
| 876 | pub const DUPLICATE_SAME_ACCESS = 2; | ||
lib/std/os/zen.zig+2-2| ... | @@ -138,7 +138,7 @@ pub const Syscall = enum(usize) { | ... | @@ -138,7 +138,7 @@ pub const Syscall = enum(usize) { |
| 138 | //////////////////// | 138 | //////////////////// |
| 139 | 139 | ||
| 140 | pub fn exit(status: i32) noreturn { | 140 | pub fn exit(status: i32) noreturn { |
| 141 | _ = syscall1(Syscall.exit, @bitCast(usize, isize(status))); | 141 | _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status))); |
| 142 | unreachable; | 142 | unreachable; |
| 143 | } | 143 | } |
| 144 | 144 | ||
| ... | @@ -167,7 +167,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { | ... | @@ -167,7 +167,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | pub fn createThread(function: fn () void) u16 { | 169 | pub fn createThread(function: fn () void) u16 { |
| 170 | return u16(syscall1(Syscall.createThread, @ptrToInt(function))); | 170 | return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function))); |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | ///////////////////////// | 173 | ///////////////////////// |
lib/std/packed_int_array.zig+18-18| ... | @@ -193,7 +193,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian, | ... | @@ -193,7 +193,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian, |
| 193 | ///Initialize a packed array using an unpacked array | 193 | ///Initialize a packed array using an unpacked array |
| 194 | /// or, more likely, an array literal. | 194 | /// or, more likely, an array literal. |
| 195 | pub fn init(ints: [int_count]Int) Self { | 195 | pub fn init(ints: [int_count]Int) Self { |
| 196 | var self = Self(undefined); | 196 | var self = @as(Self, undefined); |
| 197 | for (ints) |int, i| self.set(i, int); | 197 | for (ints) |int, i| self.set(i, int); |
| 198 | return self; | 198 | return self; |
| 199 | } | 199 | } |
| ... | @@ -328,11 +328,11 @@ test "PackedIntArray" { | ... | @@ -328,11 +328,11 @@ test "PackedIntArray" { |
| 328 | const expected_bytes = ((bits * int_count) + 7) / 8; | 328 | const expected_bytes = ((bits * int_count) + 7) / 8; |
| 329 | testing.expect(@sizeOf(PackedArray) == expected_bytes); | 329 | testing.expect(@sizeOf(PackedArray) == expected_bytes); |
| 330 | 330 | ||
| 331 | var data = PackedArray(undefined); | 331 | var data = @as(PackedArray, undefined); |
| 332 | 332 | ||
| 333 | //write values, counting up | 333 | //write values, counting up |
| 334 | var i = usize(0); | 334 | var i = @as(usize, 0); |
| 335 | var count = I(0); | 335 | var count = @as(I, 0); |
| 336 | while (i < data.len()) : (i += 1) { | 336 | while (i < data.len()) : (i += 1) { |
| 337 | data.set(i, count); | 337 | data.set(i, count); |
| 338 | if (bits > 0) count +%= 1; | 338 | if (bits > 0) count +%= 1; |
| ... | @@ -352,7 +352,7 @@ test "PackedIntArray" { | ... | @@ -352,7 +352,7 @@ test "PackedIntArray" { |
| 352 | test "PackedIntArray init" { | 352 | test "PackedIntArray init" { |
| 353 | const PackedArray = PackedIntArray(u3, 8); | 353 | const PackedArray = PackedIntArray(u3, 8); |
| 354 | var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 }); | 354 | var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 }); |
| 355 | var i = usize(0); | 355 | var i = @as(usize, 0); |
| 356 | while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i); | 356 | while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i); |
| 357 | } | 357 | } |
| 358 | 358 | ||
| ... | @@ -375,8 +375,8 @@ test "PackedIntSlice" { | ... | @@ -375,8 +375,8 @@ test "PackedIntSlice" { |
| 375 | var data = P.init(&buffer, int_count); | 375 | var data = P.init(&buffer, int_count); |
| 376 | 376 | ||
| 377 | //write values, counting up | 377 | //write values, counting up |
| 378 | var i = usize(0); | 378 | var i = @as(usize, 0); |
| 379 | var count = I(0); | 379 | var count = @as(I, 0); |
| 380 | while (i < data.len()) : (i += 1) { | 380 | while (i < data.len()) : (i += 1) { |
| 381 | data.set(i, count); | 381 | data.set(i, count); |
| 382 | if (bits > 0) count +%= 1; | 382 | if (bits > 0) count +%= 1; |
| ... | @@ -402,11 +402,11 @@ test "PackedIntSlice of PackedInt(Array/Slice)" { | ... | @@ -402,11 +402,11 @@ test "PackedIntSlice of PackedInt(Array/Slice)" { |
| 402 | const Int = @IntType(false, bits); | 402 | const Int = @IntType(false, bits); |
| 403 | 403 | ||
| 404 | const PackedArray = PackedIntArray(Int, int_count); | 404 | const PackedArray = PackedIntArray(Int, int_count); |
| 405 | var packed_array = PackedArray(undefined); | 405 | var packed_array = @as(PackedArray, undefined); |
| 406 | 406 | ||
| 407 | const limit = (1 << bits); | 407 | const limit = (1 << bits); |
| 408 | 408 | ||
| 409 | var i = usize(0); | 409 | var i = @as(usize, 0); |
| 410 | while (i < packed_array.len()) : (i += 1) { | 410 | while (i < packed_array.len()) : (i += 1) { |
| 411 | packed_array.set(i, @intCast(Int, i % limit)); | 411 | packed_array.set(i, @intCast(Int, i % limit)); |
| 412 | } | 412 | } |
| ... | @@ -463,20 +463,20 @@ test "PackedIntSlice accumulating bit offsets" { | ... | @@ -463,20 +463,20 @@ test "PackedIntSlice accumulating bit offsets" { |
| 463 | // anything | 463 | // anything |
| 464 | { | 464 | { |
| 465 | const PackedArray = PackedIntArray(u3, 16); | 465 | const PackedArray = PackedIntArray(u3, 16); |
| 466 | var packed_array = PackedArray(undefined); | 466 | var packed_array = @as(PackedArray, undefined); |
| 467 | 467 | ||
| 468 | var packed_slice = packed_array.slice(0, packed_array.len()); | 468 | var packed_slice = packed_array.slice(0, packed_array.len()); |
| 469 | var i = usize(0); | 469 | var i = @as(usize, 0); |
| 470 | while (i < packed_array.len() - 1) : (i += 1) { | 470 | while (i < packed_array.len() - 1) : (i += 1) { |
| 471 | packed_slice = packed_slice.slice(1, packed_slice.len()); | 471 | packed_slice = packed_slice.slice(1, packed_slice.len()); |
| 472 | } | 472 | } |
| 473 | } | 473 | } |
| 474 | { | 474 | { |
| 475 | const PackedArray = PackedIntArray(u11, 88); | 475 | const PackedArray = PackedIntArray(u11, 88); |
| 476 | var packed_array = PackedArray(undefined); | 476 | var packed_array = @as(PackedArray, undefined); |
| 477 | 477 | ||
| 478 | var packed_slice = packed_array.slice(0, packed_array.len()); | 478 | var packed_slice = packed_array.slice(0, packed_array.len()); |
| 479 | var i = usize(0); | 479 | var i = @as(usize, 0); |
| 480 | while (i < packed_array.len() - 1) : (i += 1) { | 480 | while (i < packed_array.len() - 1) : (i += 1) { |
| 481 | packed_slice = packed_slice.slice(1, packed_slice.len()); | 481 | packed_slice = packed_slice.slice(1, packed_slice.len()); |
| 482 | } | 482 | } |
| ... | @@ -493,7 +493,7 @@ test "PackedInt(Array/Slice) sliceCast" { | ... | @@ -493,7 +493,7 @@ test "PackedInt(Array/Slice) sliceCast" { |
| 493 | var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9); | 493 | var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9); |
| 494 | const packed_slice_cast_3 = packed_slice_cast_9.sliceCast(u3); | 494 | const packed_slice_cast_3 = packed_slice_cast_9.sliceCast(u3); |
| 495 | 495 | ||
| 496 | var i = usize(0); | 496 | var i = @as(usize, 0); |
| 497 | while (i < packed_slice_cast_2.len()) : (i += 1) { | 497 | while (i < packed_slice_cast_2.len()) : (i += 1) { |
| 498 | const val = switch (builtin.endian) { | 498 | const val = switch (builtin.endian) { |
| 499 | .Big => 0b01, | 499 | .Big => 0b01, |
| ... | @@ -518,8 +518,8 @@ test "PackedInt(Array/Slice) sliceCast" { | ... | @@ -518,8 +518,8 @@ test "PackedInt(Array/Slice) sliceCast" { |
| 518 | i = 0; | 518 | i = 0; |
| 519 | while (i < packed_slice_cast_3.len()) : (i += 1) { | 519 | while (i < packed_slice_cast_3.len()) : (i += 1) { |
| 520 | const val = switch (builtin.endian) { | 520 | const val = switch (builtin.endian) { |
| 521 | .Big => if (i % 2 == 0) u3(0b111) else u3(0b000), | 521 | .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), |
| 522 | .Little => if (i % 2 == 0) u3(0b111) else u3(0b000), | 522 | .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), |
| 523 | }; | 523 | }; |
| 524 | testing.expect(packed_slice_cast_3.get(i) == val); | 524 | testing.expect(packed_slice_cast_3.get(i) == val); |
| 525 | } | 525 | } |
| ... | @@ -541,7 +541,7 @@ test "PackedInt(Array/Slice)Endian" { | ... | @@ -541,7 +541,7 @@ test "PackedInt(Array/Slice)Endian" { |
| 541 | testing.expect(packed_array_be.bytes[0] == 0b00000001); | 541 | testing.expect(packed_array_be.bytes[0] == 0b00000001); |
| 542 | testing.expect(packed_array_be.bytes[1] == 0b00100011); | 542 | testing.expect(packed_array_be.bytes[1] == 0b00100011); |
| 543 | 543 | ||
| 544 | var i = usize(0); | 544 | var i = @as(usize, 0); |
| 545 | while (i < packed_array_be.len()) : (i += 1) { | 545 | while (i < packed_array_be.len()) : (i += 1) { |
| 546 | testing.expect(packed_array_be.get(i) == i); | 546 | testing.expect(packed_array_be.get(i) == i); |
| 547 | } | 547 | } |
| ... | @@ -579,7 +579,7 @@ test "PackedInt(Array/Slice)Endian" { | ... | @@ -579,7 +579,7 @@ test "PackedInt(Array/Slice)Endian" { |
| 579 | testing.expect(packed_array_be.bytes[3] == 0b00000001); | 579 | testing.expect(packed_array_be.bytes[3] == 0b00000001); |
| 580 | testing.expect(packed_array_be.bytes[4] == 0b00000000); | 580 | testing.expect(packed_array_be.bytes[4] == 0b00000000); |
| 581 | 581 | ||
| 582 | var i = usize(0); | 582 | var i = @as(usize, 0); |
| 583 | while (i < packed_array_be.len()) : (i += 1) { | 583 | while (i < packed_array_be.len()) : (i += 1) { |
| 584 | testing.expect(packed_array_be.get(i) == i); | 584 | testing.expect(packed_array_be.get(i) == i); |
| 585 | } | 585 | } |
lib/std/pdb.zig+1-1| ... | @@ -532,7 +532,7 @@ const Msf = struct { | ... | @@ -532,7 +532,7 @@ const Msf = struct { |
| 532 | const stream_sizes = try allocator.alloc(u32, stream_count); | 532 | const stream_sizes = try allocator.alloc(u32, stream_count); |
| 533 | defer allocator.free(stream_sizes); | 533 | defer allocator.free(stream_sizes); |
| 534 | 534 | ||
| 535 | // Microsoft's implementation uses u32(-1) for inexistant streams. | 535 | // Microsoft's implementation uses @as(u32, -1) for inexistant streams. |
| 536 | // These streams are not used, but still participate in the file | 536 | // These streams are not used, but still participate in the file |
| 537 | // and must be taken into account when resolving stream indices. | 537 | // and must be taken into account when resolving stream indices. |
| 538 | const Nil = 0xFFFFFFFF; | 538 | const Nil = 0xFFFFFFFF; |
lib/std/priority_queue.zig+30-30| ... | @@ -236,12 +236,12 @@ test "std.PriorityQueue: add and remove min heap" { | ... | @@ -236,12 +236,12 @@ test "std.PriorityQueue: add and remove min heap" { |
| 236 | try queue.add(23); | 236 | try queue.add(23); |
| 237 | try queue.add(25); | 237 | try queue.add(25); |
| 238 | try queue.add(13); | 238 | try queue.add(13); |
| 239 | expectEqual(u32(7), queue.remove()); | 239 | expectEqual(@as(u32, 7), queue.remove()); |
| 240 | expectEqual(u32(12), queue.remove()); | 240 | expectEqual(@as(u32, 12), queue.remove()); |
| 241 | expectEqual(u32(13), queue.remove()); | 241 | expectEqual(@as(u32, 13), queue.remove()); |
| 242 | expectEqual(u32(23), queue.remove()); | 242 | expectEqual(@as(u32, 23), queue.remove()); |
| 243 | expectEqual(u32(25), queue.remove()); | 243 | expectEqual(@as(u32, 25), queue.remove()); |
| 244 | expectEqual(u32(54), queue.remove()); | 244 | expectEqual(@as(u32, 54), queue.remove()); |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | test "std.PriorityQueue: add and remove same min heap" { | 247 | test "std.PriorityQueue: add and remove same min heap" { |
| ... | @@ -254,12 +254,12 @@ test "std.PriorityQueue: add and remove same min heap" { | ... | @@ -254,12 +254,12 @@ test "std.PriorityQueue: add and remove same min heap" { |
| 254 | try queue.add(2); | 254 | try queue.add(2); |
| 255 | try queue.add(1); | 255 | try queue.add(1); |
| 256 | try queue.add(1); | 256 | try queue.add(1); |
| 257 | expectEqual(u32(1), queue.remove()); | 257 | expectEqual(@as(u32, 1), queue.remove()); |
| 258 | expectEqual(u32(1), queue.remove()); | 258 | expectEqual(@as(u32, 1), queue.remove()); |
| 259 | expectEqual(u32(1), queue.remove()); | 259 | expectEqual(@as(u32, 1), queue.remove()); |
| 260 | expectEqual(u32(1), queue.remove()); | 260 | expectEqual(@as(u32, 1), queue.remove()); |
| 261 | expectEqual(u32(2), queue.remove()); | 261 | expectEqual(@as(u32, 2), queue.remove()); |
| 262 | expectEqual(u32(2), queue.remove()); | 262 | expectEqual(@as(u32, 2), queue.remove()); |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | test "std.PriorityQueue: removeOrNull on empty" { | 265 | test "std.PriorityQueue: removeOrNull on empty" { |
| ... | @@ -276,9 +276,9 @@ test "std.PriorityQueue: edge case 3 elements" { | ... | @@ -276,9 +276,9 @@ test "std.PriorityQueue: edge case 3 elements" { |
| 276 | try queue.add(9); | 276 | try queue.add(9); |
| 277 | try queue.add(3); | 277 | try queue.add(3); |
| 278 | try queue.add(2); | 278 | try queue.add(2); |
| 279 | expectEqual(u32(2), queue.remove()); | 279 | expectEqual(@as(u32, 2), queue.remove()); |
| 280 | expectEqual(u32(3), queue.remove()); | 280 | expectEqual(@as(u32, 3), queue.remove()); |
| 281 | expectEqual(u32(9), queue.remove()); | 281 | expectEqual(@as(u32, 9), queue.remove()); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | test "std.PriorityQueue: peek" { | 284 | test "std.PriorityQueue: peek" { |
| ... | @@ -289,8 +289,8 @@ test "std.PriorityQueue: peek" { | ... | @@ -289,8 +289,8 @@ test "std.PriorityQueue: peek" { |
| 289 | try queue.add(9); | 289 | try queue.add(9); |
| 290 | try queue.add(3); | 290 | try queue.add(3); |
| 291 | try queue.add(2); | 291 | try queue.add(2); |
| 292 | expectEqual(u32(2), queue.peek().?); | 292 | expectEqual(@as(u32, 2), queue.peek().?); |
| 293 | expectEqual(u32(2), queue.peek().?); | 293 | expectEqual(@as(u32, 2), queue.peek().?); |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | test "std.PriorityQueue: sift up with odd indices" { | 296 | test "std.PriorityQueue: sift up with odd indices" { |
| ... | @@ -341,12 +341,12 @@ test "std.PriorityQueue: add and remove max heap" { | ... | @@ -341,12 +341,12 @@ test "std.PriorityQueue: add and remove max heap" { |
| 341 | try queue.add(23); | 341 | try queue.add(23); |
| 342 | try queue.add(25); | 342 | try queue.add(25); |
| 343 | try queue.add(13); | 343 | try queue.add(13); |
| 344 | expectEqual(u32(54), queue.remove()); | 344 | expectEqual(@as(u32, 54), queue.remove()); |
| 345 | expectEqual(u32(25), queue.remove()); | 345 | expectEqual(@as(u32, 25), queue.remove()); |
| 346 | expectEqual(u32(23), queue.remove()); | 346 | expectEqual(@as(u32, 23), queue.remove()); |
| 347 | expectEqual(u32(13), queue.remove()); | 347 | expectEqual(@as(u32, 13), queue.remove()); |
| 348 | expectEqual(u32(12), queue.remove()); | 348 | expectEqual(@as(u32, 12), queue.remove()); |
| 349 | expectEqual(u32(7), queue.remove()); | 349 | expectEqual(@as(u32, 7), queue.remove()); |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | test "std.PriorityQueue: add and remove same max heap" { | 352 | test "std.PriorityQueue: add and remove same max heap" { |
| ... | @@ -359,12 +359,12 @@ test "std.PriorityQueue: add and remove same max heap" { | ... | @@ -359,12 +359,12 @@ test "std.PriorityQueue: add and remove same max heap" { |
| 359 | try queue.add(2); | 359 | try queue.add(2); |
| 360 | try queue.add(1); | 360 | try queue.add(1); |
| 361 | try queue.add(1); | 361 | try queue.add(1); |
| 362 | expectEqual(u32(2), queue.remove()); | 362 | expectEqual(@as(u32, 2), queue.remove()); |
| 363 | expectEqual(u32(2), queue.remove()); | 363 | expectEqual(@as(u32, 2), queue.remove()); |
| 364 | expectEqual(u32(1), queue.remove()); | 364 | expectEqual(@as(u32, 1), queue.remove()); |
| 365 | expectEqual(u32(1), queue.remove()); | 365 | expectEqual(@as(u32, 1), queue.remove()); |
| 366 | expectEqual(u32(1), queue.remove()); | 366 | expectEqual(@as(u32, 1), queue.remove()); |
| 367 | expectEqual(u32(1), queue.remove()); | 367 | expectEqual(@as(u32, 1), queue.remove()); |
| 368 | } | 368 | } |
| 369 | 369 | ||
| 370 | test "std.PriorityQueue: iterator" { | 370 | test "std.PriorityQueue: iterator" { |
| ... | @@ -386,5 +386,5 @@ test "std.PriorityQueue: iterator" { | ... | @@ -386,5 +386,5 @@ test "std.PriorityQueue: iterator" { |
| 386 | _ = map.remove(e); | 386 | _ = map.remove(e); |
| 387 | } | 387 | } |
| 388 | 388 | ||
| 389 | expectEqual(usize(0), map.count()); | 389 | expectEqual(@as(usize, 0), map.count()); |
| 390 | } | 390 | } |
lib/std/rand.zig+8-8| ... | @@ -93,13 +93,13 @@ pub const Random = struct { | ... | @@ -93,13 +93,13 @@ pub const Random = struct { |
| 93 | // http://www.pcg-random.org/posts/bounded-rands.html | 93 | // http://www.pcg-random.org/posts/bounded-rands.html |
| 94 | // "Lemire's (with an extra tweak from me)" | 94 | // "Lemire's (with an extra tweak from me)" |
| 95 | var x: Small = r.int(Small); | 95 | var x: Small = r.int(Small); |
| 96 | var m: Large = Large(x) * Large(less_than); | 96 | var m: Large = @as(Large, x) * @as(Large, less_than); |
| 97 | var l: Small = @truncate(Small, m); | 97 | var l: Small = @truncate(Small, m); |
| 98 | if (l < less_than) { | 98 | if (l < less_than) { |
| 99 | // TODO: workaround for https://github.com/ziglang/zig/issues/1770 | 99 | // TODO: workaround for https://github.com/ziglang/zig/issues/1770 |
| 100 | // should be: | 100 | // should be: |
| 101 | // var t: Small = -%less_than; | 101 | // var t: Small = -%less_than; |
| 102 | var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), Small(less_than))); | 102 | var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), @as(Small, less_than))); |
| 103 | 103 | ||
| 104 | if (t >= less_than) { | 104 | if (t >= less_than) { |
| 105 | t -= less_than; | 105 | t -= less_than; |
| ... | @@ -109,7 +109,7 @@ pub const Random = struct { | ... | @@ -109,7 +109,7 @@ pub const Random = struct { |
| 109 | } | 109 | } |
| 110 | while (l < t) { | 110 | while (l < t) { |
| 111 | x = r.int(Small); | 111 | x = r.int(Small); |
| 112 | m = Large(x) * Large(less_than); | 112 | m = @as(Large, x) * @as(Large, less_than); |
| 113 | l = @truncate(Small, m); | 113 | l = @truncate(Small, m); |
| 114 | } | 114 | } |
| 115 | } | 115 | } |
| ... | @@ -286,7 +286,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T { | ... | @@ -286,7 +286,7 @@ pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T { |
| 286 | // adapted from: | 286 | // adapted from: |
| 287 | // http://www.pcg-random.org/posts/bounded-rands.html | 287 | // http://www.pcg-random.org/posts/bounded-rands.html |
| 288 | // "Integer Multiplication (Biased)" | 288 | // "Integer Multiplication (Biased)" |
| 289 | var m: T2 = T2(random_int) * T2(less_than); | 289 | var m: T2 = @as(T2, random_int) * @as(T2, less_than); |
| 290 | return @intCast(T, m >> T.bit_count); | 290 | return @intCast(T, m >> T.bit_count); |
| 291 | } | 291 | } |
| 292 | 292 | ||
| ... | @@ -633,8 +633,8 @@ pub const Xoroshiro128 = struct { | ... | @@ -633,8 +633,8 @@ pub const Xoroshiro128 = struct { |
| 633 | const r = s0 +% s1; | 633 | const r = s0 +% s1; |
| 634 | 634 | ||
| 635 | s1 ^= s0; | 635 | s1 ^= s0; |
| 636 | self.s[0] = math.rotl(u64, s0, u8(55)) ^ s1 ^ (s1 << 14); | 636 | self.s[0] = math.rotl(u64, s0, @as(u8, 55)) ^ s1 ^ (s1 << 14); |
| 637 | self.s[1] = math.rotl(u64, s1, u8(36)); | 637 | self.s[1] = math.rotl(u64, s1, @as(u8, 36)); |
| 638 | 638 | ||
| 639 | return r; | 639 | return r; |
| 640 | } | 640 | } |
| ... | @@ -652,7 +652,7 @@ pub const Xoroshiro128 = struct { | ... | @@ -652,7 +652,7 @@ pub const Xoroshiro128 = struct { |
| 652 | inline for (table) |entry| { | 652 | inline for (table) |entry| { |
| 653 | var b: usize = 0; | 653 | var b: usize = 0; |
| 654 | while (b < 64) : (b += 1) { | 654 | while (b < 64) : (b += 1) { |
| 655 | if ((entry & (u64(1) << @intCast(u6, b))) != 0) { | 655 | if ((entry & (@as(u64, 1) << @intCast(u6, b))) != 0) { |
| 656 | s0 ^= self.s[0]; | 656 | s0 ^= self.s[0]; |
| 657 | s1 ^= self.s[1]; | 657 | s1 ^= self.s[1]; |
| 658 | } | 658 | } |
| ... | @@ -1090,7 +1090,7 @@ fn testRange(r: *Random, start: i8, end: i8) void { | ... | @@ -1090,7 +1090,7 @@ fn testRange(r: *Random, start: i8, end: i8) void { |
| 1090 | testRangeBias(r, start, end, false); | 1090 | testRangeBias(r, start, end, false); |
| 1091 | } | 1091 | } |
| 1092 | fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void { | 1092 | fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void { |
| 1093 | const count = @intCast(usize, i32(end) - i32(start)); | 1093 | const count = @intCast(usize, @as(i32, end) - @as(i32, start)); |
| 1094 | var values_buffer = [_]bool{false} ** 0x100; | 1094 | var values_buffer = [_]bool{false} ** 0x100; |
| 1095 | const values = values_buffer[0..count]; | 1095 | const values = values_buffer[0..count]; |
| 1096 | var i: usize = 0; | 1096 | var i: usize = 0; |
lib/std/rand/ziggurat.zig+1-1| ... | @@ -17,7 +17,7 @@ pub fn next_f64(random: *Random, comptime tables: ZigTable) f64 { | ... | @@ -17,7 +17,7 @@ pub fn next_f64(random: *Random, comptime tables: ZigTable) f64 { |
| 17 | // We manually construct a float from parts as we can avoid an extra random lookup here by | 17 | // We manually construct a float from parts as we can avoid an extra random lookup here by |
| 18 | // using the unused exponent for the lookup table entry. | 18 | // using the unused exponent for the lookup table entry. |
| 19 | const bits = random.scalar(u64); | 19 | const bits = random.scalar(u64); |
| 20 | const i = usize(bits & 0xff); | 20 | const i = @as(usize, bits & 0xff); |
| 21 | 21 | ||
| 22 | const u = blk: { | 22 | const u = blk: { |
| 23 | if (tables.is_symmetric) { | 23 | if (tables.is_symmetric) { |
lib/std/segmented_list.zig+5-5| ... | @@ -162,7 +162,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type | ... | @@ -162,7 +162,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 162 | /// Grows or shrinks capacity to match usage. | 162 | /// Grows or shrinks capacity to match usage. |
| 163 | pub fn setCapacity(self: *Self, new_capacity: usize) !void { | 163 | pub fn setCapacity(self: *Self, new_capacity: usize) !void { |
| 164 | if (prealloc_item_count != 0) { | 164 | if (prealloc_item_count != 0) { |
| 165 | if (new_capacity <= usize(1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) { | 165 | if (new_capacity <= @as(usize, 1) << (prealloc_exp + @intCast(ShelfIndex, self.dynamic_segments.len))) { |
| 166 | return self.shrinkCapacity(new_capacity); | 166 | return self.shrinkCapacity(new_capacity); |
| 167 | } | 167 | } |
| 168 | } | 168 | } |
| ... | @@ -231,9 +231,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type | ... | @@ -231,9 +231,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 231 | 231 | ||
| 232 | fn shelfSize(shelf_index: ShelfIndex) usize { | 232 | fn shelfSize(shelf_index: ShelfIndex) usize { |
| 233 | if (prealloc_item_count == 0) { | 233 | if (prealloc_item_count == 0) { |
| 234 | return usize(1) << shelf_index; | 234 | return @as(usize, 1) << shelf_index; |
| 235 | } | 235 | } |
| 236 | return usize(1) << (shelf_index + (prealloc_exp + 1)); | 236 | return @as(usize, 1) << (shelf_index + (prealloc_exp + 1)); |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | fn shelfIndex(list_index: usize) ShelfIndex { | 239 | fn shelfIndex(list_index: usize) ShelfIndex { |
| ... | @@ -245,9 +245,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type | ... | @@ -245,9 +245,9 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 245 | 245 | ||
| 246 | fn boxIndex(list_index: usize, shelf_index: ShelfIndex) usize { | 246 | fn boxIndex(list_index: usize, shelf_index: ShelfIndex) usize { |
| 247 | if (prealloc_item_count == 0) { | 247 | if (prealloc_item_count == 0) { |
| 248 | return (list_index + 1) - (usize(1) << shelf_index); | 248 | return (list_index + 1) - (@as(usize, 1) << shelf_index); |
| 249 | } | 249 | } |
| 250 | return list_index + prealloc_item_count - (usize(1) << ((prealloc_exp + 1) + shelf_index)); | 250 | return list_index + prealloc_item_count - (@as(usize, 1) << ((prealloc_exp + 1) + shelf_index)); |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | fn freeShelves(self: *Self, from_count: ShelfIndex, to_count: ShelfIndex) void { | 253 | fn freeShelves(self: *Self, from_count: ShelfIndex, to_count: ShelfIndex) void { |
lib/std/sort.zig+4-4| ... | @@ -813,7 +813,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s | ... | @@ -813,7 +813,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s |
| 813 | // where have some idea as to how many unique values there are and where the next value might be | 813 | // where have some idea as to how many unique values there are and where the next value might be |
| 814 | fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { | 814 | fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { |
| 815 | if (range.length() == 0) return range.start; | 815 | if (range.length() == 0) return range.start; |
| 816 | const skip = math.max(range.length() / unique, usize(1)); | 816 | const skip = math.max(range.length() / unique, @as(usize, 1)); |
| 817 | 817 | ||
| 818 | var index = range.start + skip; | 818 | var index = range.start + skip; |
| 819 | while (lessThan(items[index - 1], value)) : (index += skip) { | 819 | while (lessThan(items[index - 1], value)) : (index += skip) { |
| ... | @@ -827,7 +827,7 @@ fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessTh | ... | @@ -827,7 +827,7 @@ fn findFirstForward(comptime T: type, items: []T, value: T, range: Range, lessTh |
| 827 | 827 | ||
| 828 | fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { | 828 | fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { |
| 829 | if (range.length() == 0) return range.start; | 829 | if (range.length() == 0) return range.start; |
| 830 | const skip = math.max(range.length() / unique, usize(1)); | 830 | const skip = math.max(range.length() / unique, @as(usize, 1)); |
| 831 | 831 | ||
| 832 | var index = range.end - skip; | 832 | var index = range.end - skip; |
| 833 | while (index > range.start and !lessThan(items[index - 1], value)) : (index -= skip) { | 833 | while (index > range.start and !lessThan(items[index - 1], value)) : (index -= skip) { |
| ... | @@ -841,7 +841,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessT | ... | @@ -841,7 +841,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: T, range: Range, lessT |
| 841 | 841 | ||
| 842 | fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { | 842 | fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { |
| 843 | if (range.length() == 0) return range.start; | 843 | if (range.length() == 0) return range.start; |
| 844 | const skip = math.max(range.length() / unique, usize(1)); | 844 | const skip = math.max(range.length() / unique, @as(usize, 1)); |
| 845 | 845 | ||
| 846 | var index = range.start + skip; | 846 | var index = range.start + skip; |
| 847 | while (!lessThan(value, items[index - 1])) : (index += skip) { | 847 | while (!lessThan(value, items[index - 1])) : (index += skip) { |
| ... | @@ -855,7 +855,7 @@ fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessTha | ... | @@ -855,7 +855,7 @@ fn findLastForward(comptime T: type, items: []T, value: T, range: Range, lessTha |
| 855 | 855 | ||
| 856 | fn findLastBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { | 856 | fn findLastBackward(comptime T: type, items: []T, value: T, range: Range, lessThan: fn (T, T) bool, unique: usize) usize { |
| 857 | if (range.length() == 0) return range.start; | 857 | if (range.length() == 0) return range.start; |
| 858 | const skip = math.max(range.length() / unique, usize(1)); | 858 | const skip = math.max(range.length() / unique, @as(usize, 1)); |
| 859 | 859 | ||
| 860 | var index = range.end - skip; | 860 | var index = range.end - skip; |
| 861 | while (index > range.start and lessThan(value, items[index - 1])) : (index -= skip) { | 861 | while (index > range.start and lessThan(value, items[index - 1])) : (index -= skip) { |
lib/std/special/c.zig+3-3| ... | @@ -62,7 +62,7 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int { | ... | @@ -62,7 +62,7 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int { |
| 62 | r += 1; | 62 | r += 1; |
| 63 | n -= 1; | 63 | n -= 1; |
| 64 | } | 64 | } |
| 65 | return c_int(l[0]) - c_int(r[0]); | 65 | return @as(c_int, l[0]) - @as(c_int, r[0]); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | extern fn strerror(errnum: c_int) [*]const u8 { | 68 | extern fn strerror(errnum: c_int) [*]const u8 { |
| ... | @@ -540,7 +540,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T { | ... | @@ -540,7 +540,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 540 | // scale result up | 540 | // scale result up |
| 541 | if (ex > 0) { | 541 | if (ex > 0) { |
| 542 | ux -%= 1 << digits; | 542 | ux -%= 1 << digits; |
| 543 | ux |= uint(@bitCast(u32, ex)) << digits; | 543 | ux |= @as(uint, @bitCast(u32, ex)) << digits; |
| 544 | } else { | 544 | } else { |
| 545 | ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1)); | 545 | ux >>= @intCast(log2uint, @bitCast(u32, -ex + 1)); |
| 546 | } | 546 | } |
| ... | @@ -687,7 +687,7 @@ export fn sqrt(x: f64) f64 { | ... | @@ -687,7 +687,7 @@ export fn sqrt(x: f64) f64 { |
| 687 | 687 | ||
| 688 | export fn sqrtf(x: f32) f32 { | 688 | export fn sqrtf(x: f32) f32 { |
| 689 | const tiny: f32 = 1.0e-30; | 689 | const tiny: f32 = 1.0e-30; |
| 690 | const sign: i32 = @bitCast(i32, u32(0x80000000)); | 690 | const sign: i32 = @bitCast(i32, @as(u32, 0x80000000)); |
| 691 | var ix: i32 = @bitCast(i32, x); | 691 | var ix: i32 = @bitCast(i32, x); |
| 692 | 692 | ||
| 693 | if ((ix & 0x7F800000) == 0x7F800000) { | 693 | if ((ix & 0x7F800000) == 0x7F800000) { |
lib/std/special/compiler_rt.zig+17-17| ... | @@ -672,7 +672,7 @@ extern fn __udivsi3(n: u32, d: u32) u32 { | ... | @@ -672,7 +672,7 @@ extern fn __udivsi3(n: u32, d: u32) u32 { |
| 672 | // special cases | 672 | // special cases |
| 673 | if (d == 0) return 0; // ?! | 673 | if (d == 0) return 0; // ?! |
| 674 | if (n == 0) return 0; | 674 | if (n == 0) return 0; |
| 675 | var sr = @bitCast(c_uint, c_int(@clz(u32, d)) - c_int(@clz(u32, n))); | 675 | var sr = @bitCast(c_uint, @as(c_int, @clz(u32, d)) - @as(c_int, @clz(u32, n))); |
| 676 | // 0 <= sr <= n_uword_bits - 1 or sr large | 676 | // 0 <= sr <= n_uword_bits - 1 or sr large |
| 677 | if (sr > n_uword_bits - 1) { | 677 | if (sr > n_uword_bits - 1) { |
| 678 | // d > r | 678 | // d > r |
| ... | @@ -1414,10 +1414,10 @@ test "test_divsi3" { | ... | @@ -1414,10 +1414,10 @@ test "test_divsi3" { |
| 1414 | [_]i32{ -2, 1, -2 }, | 1414 | [_]i32{ -2, 1, -2 }, |
| 1415 | [_]i32{ -2, -1, 2 }, | 1415 | [_]i32{ -2, -1, 2 }, |
| 1416 | 1416 | ||
| 1417 | [_]i32{ @bitCast(i32, u32(0x80000000)), 1, @bitCast(i32, u32(0x80000000)) }, | 1417 | [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 1, @bitCast(i32, @as(u32, 0x80000000)) }, |
| 1418 | [_]i32{ @bitCast(i32, u32(0x80000000)), -1, @bitCast(i32, u32(0x80000000)) }, | 1418 | [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -1, @bitCast(i32, @as(u32, 0x80000000)) }, |
| 1419 | [_]i32{ @bitCast(i32, u32(0x80000000)), -2, 0x40000000 }, | 1419 | [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), -2, 0x40000000 }, |
| 1420 | [_]i32{ @bitCast(i32, u32(0x80000000)), 2, @bitCast(i32, u32(0xC0000000)) }, | 1420 | [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 2, @bitCast(i32, @as(u32, 0xC0000000)) }, |
| 1421 | }; | 1421 | }; |
| 1422 | 1422 | ||
| 1423 | for (cases) |case| { | 1423 | for (cases) |case| { |
| ... | @@ -1443,8 +1443,8 @@ test "test_divmodsi4" { | ... | @@ -1443,8 +1443,8 @@ test "test_divmodsi4" { |
| 1443 | [_]i32{ 19, 5, 3, 4 }, | 1443 | [_]i32{ 19, 5, 3, 4 }, |
| 1444 | [_]i32{ 19, -5, -3, 4 }, | 1444 | [_]i32{ 19, -5, -3, 4 }, |
| 1445 | 1445 | ||
| 1446 | [_]i32{ @bitCast(i32, u32(0x80000000)), 8, @bitCast(i32, u32(0xf0000000)), 0 }, | 1446 | [_]i32{ @bitCast(i32, @as(u32, 0x80000000)), 8, @bitCast(i32, @as(u32, 0xf0000000)), 0 }, |
| 1447 | [_]i32{ @bitCast(i32, u32(0x80000007)), 8, @bitCast(i32, u32(0xf0000001)), -1 }, | 1447 | [_]i32{ @bitCast(i32, @as(u32, 0x80000007)), 8, @bitCast(i32, @as(u32, 0xf0000001)), -1 }, |
| 1448 | }; | 1448 | }; |
| 1449 | 1449 | ||
| 1450 | for (cases) |case| { | 1450 | for (cases) |case| { |
| ... | @@ -1467,10 +1467,10 @@ test "test_divdi3" { | ... | @@ -1467,10 +1467,10 @@ test "test_divdi3" { |
| 1467 | [_]i64{ -2, 1, -2 }, | 1467 | [_]i64{ -2, 1, -2 }, |
| 1468 | [_]i64{ -2, -1, 2 }, | 1468 | [_]i64{ -2, -1, 2 }, |
| 1469 | 1469 | ||
| 1470 | [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)) }, | 1470 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)) }, |
| 1471 | [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)) }, | 1471 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)) }, |
| 1472 | [_]i64{ @bitCast(i64, u64(0x8000000000000000)), -2, 0x4000000000000000 }, | 1472 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0x4000000000000000 }, |
| 1473 | [_]i64{ @bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0xC000000000000000)) }, | 1473 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0xC000000000000000)) }, |
| 1474 | }; | 1474 | }; |
| 1475 | 1475 | ||
| 1476 | for (cases) |case| { | 1476 | for (cases) |case| { |
| ... | @@ -1492,12 +1492,12 @@ test "test_moddi3" { | ... | @@ -1492,12 +1492,12 @@ test "test_moddi3" { |
| 1492 | [_]i64{ -5, 3, -2 }, | 1492 | [_]i64{ -5, 3, -2 }, |
| 1493 | [_]i64{ -5, -3, -2 }, | 1493 | [_]i64{ -5, -3, -2 }, |
| 1494 | 1494 | ||
| 1495 | [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 1, 0 }, | 1495 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 1, 0 }, |
| 1496 | [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -1, 0 }, | 1496 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -1, 0 }, |
| 1497 | [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 2, 0 }, | 1497 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 2, 0 }, |
| 1498 | [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -2, 0 }, | 1498 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -2, 0 }, |
| 1499 | [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), 3, -2 }, | 1499 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 3, -2 }, |
| 1500 | [_]i64{ @bitCast(i64, @intCast(u64, 0x8000000000000000)), -3, -2 }, | 1500 | [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), -3, -2 }, |
| 1501 | }; | 1501 | }; |
| 1502 | 1502 | ||
| 1503 | for (cases) |case| { | 1503 | for (cases) |case| { |
lib/std/special/compiler_rt/addXf3.zig+13-13| ... | @@ -19,26 +19,26 @@ pub extern fn __addtf3(a: f128, b: f128) f128 { | ... | @@ -19,26 +19,26 @@ pub extern fn __addtf3(a: f128, b: f128) f128 { |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | pub extern fn __subsf3(a: f32, b: f32) f32 { | 21 | pub extern fn __subsf3(a: f32, b: f32) f32 { |
| 22 | const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (u32(1) << 31)); | 22 | const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31)); |
| 23 | return addXf3(f32, a, neg_b); | 23 | return addXf3(f32, a, neg_b); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | pub extern fn __subdf3(a: f64, b: f64) f64 { | 26 | pub extern fn __subdf3(a: f64, b: f64) f64 { |
| 27 | const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (u64(1) << 63)); | 27 | const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (@as(u64, 1) << 63)); |
| 28 | return addXf3(f64, a, neg_b); | 28 | return addXf3(f64, a, neg_b); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | pub extern fn __subtf3(a: f128, b: f128) f128 { | 31 | pub extern fn __subtf3(a: f128, b: f128) f128 { |
| 32 | const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (u128(1) << 127)); | 32 | const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (@as(u128, 1) << 127)); |
| 33 | return addXf3(f128, a, neg_b); | 33 | return addXf3(f128, a, neg_b); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | // TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154 | 36 | // TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154 |
| 37 | fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { | 37 | fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 38 | const Z = @IntType(false, T.bit_count); | 38 | const Z = @IntType(false, T.bit_count); |
| 39 | const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1)); | 39 | const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1)); |
| 40 | const significandBits = std.math.floatMantissaBits(T); | 40 | const significandBits = std.math.floatMantissaBits(T); |
| 41 | const implicitBit = Z(1) << significandBits; | 41 | const implicitBit = @as(Z, 1) << significandBits; |
| 42 | 42 | ||
| 43 | const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit); | 43 | const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit); |
| 44 | significand.* <<= @intCast(S, shift); | 44 | significand.* <<= @intCast(S, shift); |
| ... | @@ -48,17 +48,17 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { | ... | @@ -48,17 +48,17 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 48 | // TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154 | 48 | // TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154 |
| 49 | fn addXf3(comptime T: type, a: T, b: T) T { | 49 | fn addXf3(comptime T: type, a: T, b: T) T { |
| 50 | const Z = @IntType(false, T.bit_count); | 50 | const Z = @IntType(false, T.bit_count); |
| 51 | const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1)); | 51 | const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1)); |
| 52 | 52 | ||
| 53 | const typeWidth = T.bit_count; | 53 | const typeWidth = T.bit_count; |
| 54 | const significandBits = std.math.floatMantissaBits(T); | 54 | const significandBits = std.math.floatMantissaBits(T); |
| 55 | const exponentBits = std.math.floatExponentBits(T); | 55 | const exponentBits = std.math.floatExponentBits(T); |
| 56 | 56 | ||
| 57 | const signBit = (Z(1) << (significandBits + exponentBits)); | 57 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); |
| 58 | const maxExponent = ((1 << exponentBits) - 1); | 58 | const maxExponent = ((1 << exponentBits) - 1); |
| 59 | const exponentBias = (maxExponent >> 1); | 59 | const exponentBias = (maxExponent >> 1); |
| 60 | 60 | ||
| 61 | const implicitBit = (Z(1) << significandBits); | 61 | const implicitBit = (@as(Z, 1) << significandBits); |
| 62 | const quietBit = implicitBit >> 1; | 62 | const quietBit = implicitBit >> 1; |
| 63 | const significandMask = implicitBit - 1; | 63 | const significandMask = implicitBit - 1; |
| 64 | 64 | ||
| ... | @@ -78,8 +78,8 @@ fn addXf3(comptime T: type, a: T, b: T) T { | ... | @@ -78,8 +78,8 @@ fn addXf3(comptime T: type, a: T, b: T) T { |
| 78 | const infRep = @bitCast(Z, std.math.inf(T)); | 78 | const infRep = @bitCast(Z, std.math.inf(T)); |
| 79 | 79 | ||
| 80 | // Detect if a or b is zero, infinity, or NaN. | 80 | // Detect if a or b is zero, infinity, or NaN. |
| 81 | if (aAbs -% Z(1) >= infRep - Z(1) or | 81 | if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or |
| 82 | bAbs -% Z(1) >= infRep - Z(1)) | 82 | bAbs -% @as(Z, 1) >= infRep - @as(Z, 1)) |
| 83 | { | 83 | { |
| 84 | // NaN + anything = qNaN | 84 | // NaN + anything = qNaN |
| 85 | if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit); | 85 | if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit); |
| ... | @@ -148,7 +148,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { | ... | @@ -148,7 +148,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { |
| 148 | const @"align" = @intCast(Z, aExponent - bExponent); | 148 | const @"align" = @intCast(Z, aExponent - bExponent); |
| 149 | if (@"align" != 0) { | 149 | if (@"align" != 0) { |
| 150 | if (@"align" < typeWidth) { | 150 | if (@"align" < typeWidth) { |
| 151 | const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) Z(1) else 0; | 151 | const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) @as(Z, 1) else 0; |
| 152 | bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky; | 152 | bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky; |
| 153 | } else { | 153 | } else { |
| 154 | bSignificand = 1; // sticky; b is known to be non-zero. | 154 | bSignificand = 1; // sticky; b is known to be non-zero. |
| ... | @@ -157,7 +157,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { | ... | @@ -157,7 +157,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { |
| 157 | if (subtraction) { | 157 | if (subtraction) { |
| 158 | aSignificand -= bSignificand; | 158 | aSignificand -= bSignificand; |
| 159 | // If a == -b, return +zero. | 159 | // If a == -b, return +zero. |
| 160 | if (aSignificand == 0) return @bitCast(T, Z(0)); | 160 | if (aSignificand == 0) return @bitCast(T, @as(Z, 0)); |
| 161 | 161 | ||
| 162 | // If partial cancellation occured, we need to left-shift the result | 162 | // If partial cancellation occured, we need to left-shift the result |
| 163 | // and adjust the exponent: | 163 | // and adjust the exponent: |
| ... | @@ -185,7 +185,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { | ... | @@ -185,7 +185,7 @@ fn addXf3(comptime T: type, a: T, b: T) T { |
| 185 | // Result is denormal before rounding; the exponent is zero and we | 185 | // Result is denormal before rounding; the exponent is zero and we |
| 186 | // need to shift the significand. | 186 | // need to shift the significand. |
| 187 | const shift = @intCast(Z, 1 - aExponent); | 187 | const shift = @intCast(Z, 1 - aExponent); |
| 188 | const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) Z(1) else 0; | 188 | const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) @as(Z, 1) else 0; |
| 189 | aSignificand = aSignificand >> @intCast(S, shift | sticky); | 189 | aSignificand = aSignificand >> @intCast(S, shift | sticky); |
| 190 | aExponent = 0; | 190 | aExponent = 0; |
| 191 | } | 191 | } |
lib/std/special/compiler_rt/addXf3_test.zig+4-4| ... | @@ -3,8 +3,8 @@ | ... | @@ -3,8 +3,8 @@ |
| 3 | // https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c | 3 | // https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c |
| 4 | // https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/subtf3_test.c | 4 | // https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/subtf3_test.c |
| 5 | 5 | ||
| 6 | const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64); | 6 | const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64); |
| 7 | const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64); | 7 | const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64); |
| 8 | 8 | ||
| 9 | const __addtf3 = @import("addXf3.zig").__addtf3; | 9 | const __addtf3 = @import("addXf3.zig").__addtf3; |
| 10 | 10 | ||
| ... | @@ -34,7 +34,7 @@ test "addtf3" { | ... | @@ -34,7 +34,7 @@ test "addtf3" { |
| 34 | test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | 34 | test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); |
| 35 | 35 | ||
| 36 | // NaN + any = NaN | 36 | // NaN + any = NaN |
| 37 | test__addtf3(@bitCast(f128, (u128(0x7fff000000000000) << 64) | u128(0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | 37 | test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); |
| 38 | 38 | ||
| 39 | // inf + inf = inf | 39 | // inf + inf = inf |
| 40 | test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0); | 40 | test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0); |
| ... | @@ -75,7 +75,7 @@ test "subtf3" { | ... | @@ -75,7 +75,7 @@ test "subtf3" { |
| 75 | test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | 75 | test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); |
| 76 | 76 | ||
| 77 | // NaN + any = NaN | 77 | // NaN + any = NaN |
| 78 | test__subtf3(@bitCast(f128, (u128(0x7fff000000000000) << 64) | u128(0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | 78 | test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); |
| 79 | 79 | ||
| 80 | // inf - any = inf | 80 | // inf - any = inf |
| 81 | test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0); | 81 | test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0); |
lib/std/special/compiler_rt/comparedf2.zig+10-10| ... | @@ -13,19 +13,19 @@ const srep_t = i64; | ... | @@ -13,19 +13,19 @@ const srep_t = i64; |
| 13 | const typeWidth = rep_t.bit_count; | 13 | const typeWidth = rep_t.bit_count; |
| 14 | const significandBits = std.math.floatMantissaBits(fp_t); | 14 | const significandBits = std.math.floatMantissaBits(fp_t); |
| 15 | const exponentBits = std.math.floatExponentBits(fp_t); | 15 | const exponentBits = std.math.floatExponentBits(fp_t); |
| 16 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | 16 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); |
| 17 | const absMask = signBit - 1; | 17 | const absMask = signBit - 1; |
| 18 | const implicitBit = rep_t(1) << significandBits; | 18 | const implicitBit = @as(rep_t, 1) << significandBits; |
| 19 | const significandMask = implicitBit - 1; | 19 | const significandMask = implicitBit - 1; |
| 20 | const exponentMask = absMask ^ significandMask; | 20 | const exponentMask = absMask ^ significandMask; |
| 21 | const infRep = @bitCast(rep_t, std.math.inf(fp_t)); | 21 | const infRep = @bitCast(rep_t, std.math.inf(fp_t)); |
| 22 | 22 | ||
| 23 | // TODO https://github.com/ziglang/zig/issues/641 | 23 | // TODO https://github.com/ziglang/zig/issues/641 |
| 24 | // and then make the return types of some of these functions the enum instead of c_int | 24 | // and then make the return types of some of these functions the enum instead of c_int |
| 25 | const LE_LESS = c_int(-1); | 25 | const LE_LESS = @as(c_int, -1); |
| 26 | const LE_EQUAL = c_int(0); | 26 | const LE_EQUAL = @as(c_int, 0); |
| 27 | const LE_GREATER = c_int(1); | 27 | const LE_GREATER = @as(c_int, 1); |
| 28 | const LE_UNORDERED = c_int(1); | 28 | const LE_UNORDERED = @as(c_int, 1); |
| 29 | 29 | ||
| 30 | pub extern fn __ledf2(a: fp_t, b: fp_t) c_int { | 30 | pub extern fn __ledf2(a: fp_t, b: fp_t) c_int { |
| 31 | @setRuntimeSafety(is_test); | 31 | @setRuntimeSafety(is_test); |
| ... | @@ -65,10 +65,10 @@ pub extern fn __ledf2(a: fp_t, b: fp_t) c_int { | ... | @@ -65,10 +65,10 @@ pub extern fn __ledf2(a: fp_t, b: fp_t) c_int { |
| 65 | 65 | ||
| 66 | // TODO https://github.com/ziglang/zig/issues/641 | 66 | // TODO https://github.com/ziglang/zig/issues/641 |
| 67 | // and then make the return types of some of these functions the enum instead of c_int | 67 | // and then make the return types of some of these functions the enum instead of c_int |
| 68 | const GE_LESS = c_int(-1); | 68 | const GE_LESS = @as(c_int, -1); |
| 69 | const GE_EQUAL = c_int(0); | 69 | const GE_EQUAL = @as(c_int, 0); |
| 70 | const GE_GREATER = c_int(1); | 70 | const GE_GREATER = @as(c_int, 1); |
| 71 | const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED | 71 | const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED |
| 72 | 72 | ||
| 73 | pub extern fn __gedf2(a: fp_t, b: fp_t) c_int { | 73 | pub extern fn __gedf2(a: fp_t, b: fp_t) c_int { |
| 74 | @setRuntimeSafety(is_test); | 74 | @setRuntimeSafety(is_test); |
lib/std/special/compiler_rt/comparesf2.zig+10-10| ... | @@ -13,19 +13,19 @@ const srep_t = i32; | ... | @@ -13,19 +13,19 @@ const srep_t = i32; |
| 13 | const typeWidth = rep_t.bit_count; | 13 | const typeWidth = rep_t.bit_count; |
| 14 | const significandBits = std.math.floatMantissaBits(fp_t); | 14 | const significandBits = std.math.floatMantissaBits(fp_t); |
| 15 | const exponentBits = std.math.floatExponentBits(fp_t); | 15 | const exponentBits = std.math.floatExponentBits(fp_t); |
| 16 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | 16 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); |
| 17 | const absMask = signBit - 1; | 17 | const absMask = signBit - 1; |
| 18 | const implicitBit = rep_t(1) << significandBits; | 18 | const implicitBit = @as(rep_t, 1) << significandBits; |
| 19 | const significandMask = implicitBit - 1; | 19 | const significandMask = implicitBit - 1; |
| 20 | const exponentMask = absMask ^ significandMask; | 20 | const exponentMask = absMask ^ significandMask; |
| 21 | const infRep = @bitCast(rep_t, std.math.inf(fp_t)); | 21 | const infRep = @bitCast(rep_t, std.math.inf(fp_t)); |
| 22 | 22 | ||
| 23 | // TODO https://github.com/ziglang/zig/issues/641 | 23 | // TODO https://github.com/ziglang/zig/issues/641 |
| 24 | // and then make the return types of some of these functions the enum instead of c_int | 24 | // and then make the return types of some of these functions the enum instead of c_int |
| 25 | const LE_LESS = c_int(-1); | 25 | const LE_LESS = @as(c_int, -1); |
| 26 | const LE_EQUAL = c_int(0); | 26 | const LE_EQUAL = @as(c_int, 0); |
| 27 | const LE_GREATER = c_int(1); | 27 | const LE_GREATER = @as(c_int, 1); |
| 28 | const LE_UNORDERED = c_int(1); | 28 | const LE_UNORDERED = @as(c_int, 1); |
| 29 | 29 | ||
| 30 | pub extern fn __lesf2(a: fp_t, b: fp_t) c_int { | 30 | pub extern fn __lesf2(a: fp_t, b: fp_t) c_int { |
| 31 | @setRuntimeSafety(is_test); | 31 | @setRuntimeSafety(is_test); |
| ... | @@ -65,10 +65,10 @@ pub extern fn __lesf2(a: fp_t, b: fp_t) c_int { | ... | @@ -65,10 +65,10 @@ pub extern fn __lesf2(a: fp_t, b: fp_t) c_int { |
| 65 | 65 | ||
| 66 | // TODO https://github.com/ziglang/zig/issues/641 | 66 | // TODO https://github.com/ziglang/zig/issues/641 |
| 67 | // and then make the return types of some of these functions the enum instead of c_int | 67 | // and then make the return types of some of these functions the enum instead of c_int |
| 68 | const GE_LESS = c_int(-1); | 68 | const GE_LESS = @as(c_int, -1); |
| 69 | const GE_EQUAL = c_int(0); | 69 | const GE_EQUAL = @as(c_int, 0); |
| 70 | const GE_GREATER = c_int(1); | 70 | const GE_GREATER = @as(c_int, 1); |
| 71 | const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED | 71 | const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED |
| 72 | 72 | ||
| 73 | pub extern fn __gesf2(a: fp_t, b: fp_t) c_int { | 73 | pub extern fn __gesf2(a: fp_t, b: fp_t) c_int { |
| 74 | @setRuntimeSafety(is_test); | 74 | @setRuntimeSafety(is_test); |
lib/std/special/compiler_rt/comparetf2.zig+10-10| ... | @@ -1,9 +1,9 @@ | ... | @@ -1,9 +1,9 @@ |
| 1 | // TODO https://github.com/ziglang/zig/issues/641 | 1 | // TODO https://github.com/ziglang/zig/issues/641 |
| 2 | // and then make the return types of some of these functions the enum instead of c_int | 2 | // and then make the return types of some of these functions the enum instead of c_int |
| 3 | const LE_LESS = c_int(-1); | 3 | const LE_LESS = @as(c_int, -1); |
| 4 | const LE_EQUAL = c_int(0); | 4 | const LE_EQUAL = @as(c_int, 0); |
| 5 | const LE_GREATER = c_int(1); | 5 | const LE_GREATER = @as(c_int, 1); |
| 6 | const LE_UNORDERED = c_int(1); | 6 | const LE_UNORDERED = @as(c_int, 1); |
| 7 | 7 | ||
| 8 | const rep_t = u128; | 8 | const rep_t = u128; |
| 9 | const srep_t = i128; | 9 | const srep_t = i128; |
| ... | @@ -11,9 +11,9 @@ const srep_t = i128; | ... | @@ -11,9 +11,9 @@ const srep_t = i128; |
| 11 | const typeWidth = rep_t.bit_count; | 11 | const typeWidth = rep_t.bit_count; |
| 12 | const significandBits = 112; | 12 | const significandBits = 112; |
| 13 | const exponentBits = (typeWidth - significandBits - 1); | 13 | const exponentBits = (typeWidth - significandBits - 1); |
| 14 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | 14 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); |
| 15 | const absMask = signBit - 1; | 15 | const absMask = signBit - 1; |
| 16 | const implicitBit = rep_t(1) << significandBits; | 16 | const implicitBit = @as(rep_t, 1) << significandBits; |
| 17 | const significandMask = implicitBit - 1; | 17 | const significandMask = implicitBit - 1; |
| 18 | const exponentMask = absMask ^ significandMask; | 18 | const exponentMask = absMask ^ significandMask; |
| 19 | const infRep = exponentMask; | 19 | const infRep = exponentMask; |
| ... | @@ -60,10 +60,10 @@ pub extern fn __letf2(a: f128, b: f128) c_int { | ... | @@ -60,10 +60,10 @@ pub extern fn __letf2(a: f128, b: f128) c_int { |
| 60 | 60 | ||
| 61 | // TODO https://github.com/ziglang/zig/issues/641 | 61 | // TODO https://github.com/ziglang/zig/issues/641 |
| 62 | // and then make the return types of some of these functions the enum instead of c_int | 62 | // and then make the return types of some of these functions the enum instead of c_int |
| 63 | const GE_LESS = c_int(-1); | 63 | const GE_LESS = @as(c_int, -1); |
| 64 | const GE_EQUAL = c_int(0); | 64 | const GE_EQUAL = @as(c_int, 0); |
| 65 | const GE_GREATER = c_int(1); | 65 | const GE_GREATER = @as(c_int, 1); |
| 66 | const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED | 66 | const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED |
| 67 | 67 | ||
| 68 | pub extern fn __getf2(a: f128, b: f128) c_int { | 68 | pub extern fn __getf2(a: f128, b: f128) c_int { |
| 69 | @setRuntimeSafety(is_test); | 69 | @setRuntimeSafety(is_test); |
lib/std/special/compiler_rt/divdf3.zig+33-33| ... | @@ -14,11 +14,11 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { | ... | @@ -14,11 +14,11 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 14 | const significandBits = std.math.floatMantissaBits(f64); | 14 | const significandBits = std.math.floatMantissaBits(f64); |
| 15 | const exponentBits = std.math.floatExponentBits(f64); | 15 | const exponentBits = std.math.floatExponentBits(f64); |
| 16 | 16 | ||
| 17 | const signBit = (Z(1) << (significandBits + exponentBits)); | 17 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); |
| 18 | const maxExponent = ((1 << exponentBits) - 1); | 18 | const maxExponent = ((1 << exponentBits) - 1); |
| 19 | const exponentBias = (maxExponent >> 1); | 19 | const exponentBias = (maxExponent >> 1); |
| 20 | 20 | ||
| 21 | const implicitBit = (Z(1) << significandBits); | 21 | const implicitBit = (@as(Z, 1) << significandBits); |
| 22 | const quietBit = implicitBit >> 1; | 22 | const quietBit = implicitBit >> 1; |
| 23 | const significandMask = implicitBit - 1; | 23 | const significandMask = implicitBit - 1; |
| 24 | 24 | ||
| ... | @@ -91,7 +91,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { | ... | @@ -91,7 +91,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 91 | // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This | 91 | // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This |
| 92 | // is accurate to about 3.5 binary digits. | 92 | // is accurate to about 3.5 binary digits. |
| 93 | const q31b: u32 = @truncate(u32, bSignificand >> 21); | 93 | const q31b: u32 = @truncate(u32, bSignificand >> 21); |
| 94 | var recip32 = u32(0x7504f333) -% q31b; | 94 | var recip32 = @as(u32, 0x7504f333) -% q31b; |
| 95 | 95 | ||
| 96 | // Now refine the reciprocal estimate using a Newton-Raphson iteration: | 96 | // Now refine the reciprocal estimate using a Newton-Raphson iteration: |
| 97 | // | 97 | // |
| ... | @@ -101,12 +101,12 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { | ... | @@ -101,12 +101,12 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 101 | // with each iteration, so after three iterations, we have about 28 binary | 101 | // with each iteration, so after three iterations, we have about 28 binary |
| 102 | // digits of accuracy. | 102 | // digits of accuracy. |
| 103 | var correction32: u32 = undefined; | 103 | var correction32: u32 = undefined; |
| 104 | correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1); | 104 | correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1); |
| 105 | recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31); | 105 | recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31); |
| 106 | correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1); | 106 | correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1); |
| 107 | recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31); | 107 | recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31); |
| 108 | correction32 = @truncate(u32, ~(u64(recip32) *% q31b >> 32) +% 1); | 108 | correction32 = @truncate(u32, ~(@as(u64, recip32) *% q31b >> 32) +% 1); |
| 109 | recip32 = @truncate(u32, u64(recip32) *% correction32 >> 31); | 109 | recip32 = @truncate(u32, @as(u64, recip32) *% correction32 >> 31); |
| 110 | 110 | ||
| 111 | // recip32 might have overflowed to exactly zero in the preceding | 111 | // recip32 might have overflowed to exactly zero in the preceding |
| 112 | // computation if the high word of b is exactly 1.0. This would sabotage | 112 | // computation if the high word of b is exactly 1.0. This would sabotage |
| ... | @@ -119,10 +119,10 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { | ... | @@ -119,10 +119,10 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 119 | const q63blo: u32 = @truncate(u32, bSignificand << 11); | 119 | const q63blo: u32 = @truncate(u32, bSignificand << 11); |
| 120 | var correction: u64 = undefined; | 120 | var correction: u64 = undefined; |
| 121 | var reciprocal: u64 = undefined; | 121 | var reciprocal: u64 = undefined; |
| 122 | correction = ~(u64(recip32) *% q31b +% (u64(recip32) *% q63blo >> 32)) +% 1; | 122 | correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1; |
| 123 | const cHi = @truncate(u32, correction >> 32); | 123 | const cHi = @truncate(u32, correction >> 32); |
| 124 | const cLo = @truncate(u32, correction); | 124 | const cLo = @truncate(u32, correction); |
| 125 | reciprocal = u64(recip32) *% cHi +% (u64(recip32) *% cLo >> 32); | 125 | reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32); |
| 126 | 126 | ||
| 127 | // We already adjusted the 32-bit estimate, now we need to adjust the final | 127 | // We already adjusted the 32-bit estimate, now we need to adjust the final |
| 128 | // 64-bit reciprocal estimate downward to ensure that it is strictly smaller | 128 | // 64-bit reciprocal estimate downward to ensure that it is strictly smaller |
| ... | @@ -195,7 +195,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { | ... | @@ -195,7 +195,7 @@ pub extern fn __divdf3(a: f64, b: f64) f64 { |
| 195 | // Clear the implicit bit | 195 | // Clear the implicit bit |
| 196 | var absResult = quotient & significandMask; | 196 | var absResult = quotient & significandMask; |
| 197 | // Insert the exponent | 197 | // Insert the exponent |
| 198 | absResult |= @bitCast(Z, SignedZ(writtenExponent)) << significandBits; | 198 | absResult |= @bitCast(Z, @as(SignedZ, writtenExponent)) << significandBits; |
| 199 | // Round | 199 | // Round |
| 200 | absResult +%= round; | 200 | absResult +%= round; |
| 201 | // Insert the sign and return | 201 | // Insert the sign and return |
| ... | @@ -208,7 +208,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { | ... | @@ -208,7 +208,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 208 | switch (Z) { | 208 | switch (Z) { |
| 209 | u32 => { | 209 | u32 => { |
| 210 | // 32x32 --> 64 bit multiply | 210 | // 32x32 --> 64 bit multiply |
| 211 | const product = u64(a) * u64(b); | 211 | const product = @as(u64, a) * @as(u64, b); |
| 212 | hi.* = @truncate(u32, product >> 32); | 212 | hi.* = @truncate(u32, product >> 32); |
| 213 | lo.* = @truncate(u32, product); | 213 | lo.* = @truncate(u32, product); |
| 214 | }, | 214 | }, |
| ... | @@ -237,9 +237,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { | ... | @@ -237,9 +237,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 237 | hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; | 237 | hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; |
| 238 | }, | 238 | }, |
| 239 | u128 => { | 239 | u128 => { |
| 240 | const Word_LoMask = u64(0x00000000ffffffff); | 240 | const Word_LoMask = @as(u64, 0x00000000ffffffff); |
| 241 | const Word_HiMask = u64(0xffffffff00000000); | 241 | const Word_HiMask = @as(u64, 0xffffffff00000000); |
| 242 | const Word_FullMask = u64(0xffffffffffffffff); | 242 | const Word_FullMask = @as(u64, 0xffffffffffffffff); |
| 243 | const S = struct { | 243 | const S = struct { |
| 244 | fn Word_1(x: u128) u64 { | 244 | fn Word_1(x: u128) u64 { |
| 245 | return @truncate(u32, x >> 96); | 245 | return @truncate(u32, x >> 96); |
| ... | @@ -275,22 +275,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { | ... | @@ -275,22 +275,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 275 | const product43: u64 = S.Word_4(a) * S.Word_3(b); | 275 | const product43: u64 = S.Word_4(a) * S.Word_3(b); |
| 276 | const product44: u64 = S.Word_4(a) * S.Word_4(b); | 276 | const product44: u64 = S.Word_4(a) * S.Word_4(b); |
| 277 | 277 | ||
| 278 | const sum0: u128 = u128(product44); | 278 | const sum0: u128 = @as(u128, product44); |
| 279 | const sum1: u128 = u128(product34) +% | 279 | const sum1: u128 = @as(u128, product34) +% |
| 280 | u128(product43); | 280 | @as(u128, product43); |
| 281 | const sum2: u128 = u128(product24) +% | 281 | const sum2: u128 = @as(u128, product24) +% |
| 282 | u128(product33) +% | 282 | @as(u128, product33) +% |
| 283 | u128(product42); | 283 | @as(u128, product42); |
| 284 | const sum3: u128 = u128(product14) +% | 284 | const sum3: u128 = @as(u128, product14) +% |
| 285 | u128(product23) +% | 285 | @as(u128, product23) +% |
| 286 | u128(product32) +% | 286 | @as(u128, product32) +% |
| 287 | u128(product41); | 287 | @as(u128, product41); |
| 288 | const sum4: u128 = u128(product13) +% | 288 | const sum4: u128 = @as(u128, product13) +% |
| 289 | u128(product22) +% | 289 | @as(u128, product22) +% |
| 290 | u128(product31); | 290 | @as(u128, product31); |
| 291 | const sum5: u128 = u128(product12) +% | 291 | const sum5: u128 = @as(u128, product12) +% |
| 292 | u128(product21); | 292 | @as(u128, product21); |
| 293 | const sum6: u128 = u128(product11); | 293 | const sum6: u128 = @as(u128, product11); |
| 294 | 294 | ||
| 295 | const r0: u128 = (sum0 & Word_FullMask) +% | 295 | const r0: u128 = (sum0 & Word_FullMask) +% |
| 296 | ((sum1 & Word_LoMask) << 32); | 296 | ((sum1 & Word_LoMask) << 32); |
| ... | @@ -316,7 +316,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { | ... | @@ -316,7 +316,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 316 | @setRuntimeSafety(builtin.is_test); | 316 | @setRuntimeSafety(builtin.is_test); |
| 317 | const Z = @IntType(false, T.bit_count); | 317 | const Z = @IntType(false, T.bit_count); |
| 318 | const significandBits = std.math.floatMantissaBits(T); | 318 | const significandBits = std.math.floatMantissaBits(T); |
| 319 | const implicitBit = Z(1) << significandBits; | 319 | const implicitBit = @as(Z, 1) << significandBits; |
| 320 | 320 | ||
| 321 | const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); | 321 | const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); |
| 322 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); | 322 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); |
lib/std/special/compiler_rt/divsf3.zig+11-11| ... | @@ -13,11 +13,11 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { | ... | @@ -13,11 +13,11 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { |
| 13 | const significandBits = std.math.floatMantissaBits(f32); | 13 | const significandBits = std.math.floatMantissaBits(f32); |
| 14 | const exponentBits = std.math.floatExponentBits(f32); | 14 | const exponentBits = std.math.floatExponentBits(f32); |
| 15 | 15 | ||
| 16 | const signBit = (Z(1) << (significandBits + exponentBits)); | 16 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); |
| 17 | const maxExponent = ((1 << exponentBits) - 1); | 17 | const maxExponent = ((1 << exponentBits) - 1); |
| 18 | const exponentBias = (maxExponent >> 1); | 18 | const exponentBias = (maxExponent >> 1); |
| 19 | 19 | ||
| 20 | const implicitBit = (Z(1) << significandBits); | 20 | const implicitBit = (@as(Z, 1) << significandBits); |
| 21 | const quietBit = implicitBit >> 1; | 21 | const quietBit = implicitBit >> 1; |
| 22 | const significandMask = implicitBit - 1; | 22 | const significandMask = implicitBit - 1; |
| 23 | 23 | ||
| ... | @@ -90,7 +90,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { | ... | @@ -90,7 +90,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { |
| 90 | // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This | 90 | // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This |
| 91 | // is accurate to about 3.5 binary digits. | 91 | // is accurate to about 3.5 binary digits. |
| 92 | const q31b = bSignificand << 8; | 92 | const q31b = bSignificand << 8; |
| 93 | var reciprocal = u32(0x7504f333) -% q31b; | 93 | var reciprocal = @as(u32, 0x7504f333) -% q31b; |
| 94 | 94 | ||
| 95 | // Now refine the reciprocal estimate using a Newton-Raphson iteration: | 95 | // Now refine the reciprocal estimate using a Newton-Raphson iteration: |
| 96 | // | 96 | // |
| ... | @@ -100,12 +100,12 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { | ... | @@ -100,12 +100,12 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { |
| 100 | // with each iteration, so after three iterations, we have about 28 binary | 100 | // with each iteration, so after three iterations, we have about 28 binary |
| 101 | // digits of accuracy. | 101 | // digits of accuracy. |
| 102 | var correction: u32 = undefined; | 102 | var correction: u32 = undefined; |
| 103 | correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1); | 103 | correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1); |
| 104 | reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31); | 104 | reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31); |
| 105 | correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1); | 105 | correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1); |
| 106 | reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31); | 106 | reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31); |
| 107 | correction = @truncate(u32, ~(u64(reciprocal) *% q31b >> 32) +% 1); | 107 | correction = @truncate(u32, ~(@as(u64, reciprocal) *% q31b >> 32) +% 1); |
| 108 | reciprocal = @truncate(u32, u64(reciprocal) *% correction >> 31); | 108 | reciprocal = @truncate(u32, @as(u64, reciprocal) *% correction >> 31); |
| 109 | 109 | ||
| 110 | // Exhaustive testing shows that the error in reciprocal after three steps | 110 | // Exhaustive testing shows that the error in reciprocal after three steps |
| 111 | // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our | 111 | // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our |
| ... | @@ -127,7 +127,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { | ... | @@ -127,7 +127,7 @@ pub extern fn __divsf3(a: f32, b: f32) f32 { |
| 127 | // is the error in the reciprocal of b scaled by the maximum | 127 | // is the error in the reciprocal of b scaled by the maximum |
| 128 | // possible value of a. As a consequence of this error bound, | 128 | // possible value of a. As a consequence of this error bound, |
| 129 | // either q or nextafter(q) is the correctly rounded | 129 | // either q or nextafter(q) is the correctly rounded |
| 130 | var quotient: Z = @truncate(u32, u64(reciprocal) *% (aSignificand << 1) >> 32); | 130 | var quotient: Z = @truncate(u32, @as(u64, reciprocal) *% (aSignificand << 1) >> 32); |
| 131 | 131 | ||
| 132 | // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0). | 132 | // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0). |
| 133 | // In either case, we are going to compute a residual of the form | 133 | // In either case, we are going to compute a residual of the form |
| ... | @@ -189,7 +189,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { | ... | @@ -189,7 +189,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 189 | @setRuntimeSafety(builtin.is_test); | 189 | @setRuntimeSafety(builtin.is_test); |
| 190 | const Z = @IntType(false, T.bit_count); | 190 | const Z = @IntType(false, T.bit_count); |
| 191 | const significandBits = std.math.floatMantissaBits(T); | 191 | const significandBits = std.math.floatMantissaBits(T); |
| 192 | const implicitBit = Z(1) << significandBits; | 192 | const implicitBit = @as(Z, 1) << significandBits; |
| 193 | 193 | ||
| 194 | const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); | 194 | const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); |
| 195 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); | 195 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); |
lib/std/special/compiler_rt/divti3_test.zig+4-4| ... | @@ -14,8 +14,8 @@ test "divti3" { | ... | @@ -14,8 +14,8 @@ test "divti3" { |
| 14 | test__divti3(-2, 1, -2); | 14 | test__divti3(-2, 1, -2); |
| 15 | test__divti3(-2, -1, 2); | 15 | test__divti3(-2, -1, 2); |
| 16 | 16 | ||
| 17 | test__divti3(@bitCast(i128, u128(0x8 << 124)), 1, @bitCast(i128, u128(0x8 << 124))); | 17 | test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124))); |
| 18 | test__divti3(@bitCast(i128, u128(0x8 << 124)), -1, @bitCast(i128, u128(0x8 << 124))); | 18 | test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124))); |
| 19 | test__divti3(@bitCast(i128, u128(0x8 << 124)), -2, @bitCast(i128, u128(0x4 << 124))); | 19 | test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124))); |
| 20 | test__divti3(@bitCast(i128, u128(0x8 << 124)), 2, @bitCast(i128, u128(0xc << 124))); | 20 | test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124))); |
| 21 | } | 21 | } |
lib/std/special/compiler_rt/extendXfYf2.zig+7-7| ... | @@ -49,7 +49,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t | ... | @@ -49,7 +49,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t |
| 49 | const dstInfExp = (1 << dstExpBits) - 1; | 49 | const dstInfExp = (1 << dstExpBits) - 1; |
| 50 | const dstExpBias = dstInfExp >> 1; | 50 | const dstExpBias = dstInfExp >> 1; |
| 51 | 51 | ||
| 52 | const dstMinNormal: dst_rep_t = dst_rep_t(1) << dstSigBits; | 52 | const dstMinNormal: dst_rep_t = @as(dst_rep_t, 1) << dstSigBits; |
| 53 | 53 | ||
| 54 | // Break a into a sign and representation of the absolute value | 54 | // Break a into a sign and representation of the absolute value |
| 55 | const aRep: src_rep_t = @bitCast(src_rep_t, a); | 55 | const aRep: src_rep_t = @bitCast(src_rep_t, a); |
| ... | @@ -61,7 +61,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t | ... | @@ -61,7 +61,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t |
| 61 | // a is a normal number. | 61 | // a is a normal number. |
| 62 | // Extend to the destination type by shifting the significand and | 62 | // Extend to the destination type by shifting the significand and |
| 63 | // exponent into the proper position and rebiasing the exponent. | 63 | // exponent into the proper position and rebiasing the exponent. |
| 64 | absResult = dst_rep_t(aAbs) << (dstSigBits - srcSigBits); | 64 | absResult = @as(dst_rep_t, aAbs) << (dstSigBits - srcSigBits); |
| 65 | absResult += (dstExpBias - srcExpBias) << dstSigBits; | 65 | absResult += (dstExpBias - srcExpBias) << dstSigBits; |
| 66 | } else if (aAbs >= srcInfinity) { | 66 | } else if (aAbs >= srcInfinity) { |
| 67 | // a is NaN or infinity. | 67 | // a is NaN or infinity. |
| ... | @@ -69,15 +69,15 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t | ... | @@ -69,15 +69,15 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t |
| 69 | // bit (if needed) and right-aligning the rest of the trailing NaN | 69 | // bit (if needed) and right-aligning the rest of the trailing NaN |
| 70 | // payload field. | 70 | // payload field. |
| 71 | absResult = dstInfExp << dstSigBits; | 71 | absResult = dstInfExp << dstSigBits; |
| 72 | absResult |= dst_rep_t(aAbs & srcQNaN) << (dstSigBits - srcSigBits); | 72 | absResult |= @as(dst_rep_t, aAbs & srcQNaN) << (dstSigBits - srcSigBits); |
| 73 | absResult |= dst_rep_t(aAbs & srcNaNCode) << (dstSigBits - srcSigBits); | 73 | absResult |= @as(dst_rep_t, aAbs & srcNaNCode) << (dstSigBits - srcSigBits); |
| 74 | } else if (aAbs != 0) { | 74 | } else if (aAbs != 0) { |
| 75 | // a is denormal. | 75 | // a is denormal. |
| 76 | // renormalize the significand and clear the leading bit, then insert | 76 | // renormalize the significand and clear the leading bit, then insert |
| 77 | // the correct adjusted exponent in the destination type. | 77 | // the correct adjusted exponent in the destination type. |
| 78 | const scale: u32 = @clz(src_rep_t, aAbs) - | 78 | const scale: u32 = @clz(src_rep_t, aAbs) - |
| 79 | @clz(src_rep_t, src_rep_t(srcMinNormal)); | 79 | @clz(src_rep_t, @as(src_rep_t, srcMinNormal)); |
| 80 | absResult = dst_rep_t(aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale); | 80 | absResult = @as(dst_rep_t, aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale); |
| 81 | absResult ^= dstMinNormal; | 81 | absResult ^= dstMinNormal; |
| 82 | const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1; | 82 | const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1; |
| 83 | absResult |= @intCast(dst_rep_t, resultExponent) << dstSigBits; | 83 | absResult |= @intCast(dst_rep_t, resultExponent) << dstSigBits; |
| ... | @@ -87,7 +87,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t | ... | @@ -87,7 +87,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | // Apply the signbit to (dst_t)abs(a). | 89 | // Apply the signbit to (dst_t)abs(a). |
| 90 | const result: dst_rep_t align(@alignOf(dst_t)) = absResult | dst_rep_t(sign) << (dstBits - srcBits); | 90 | const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits); |
| 91 | return @bitCast(dst_t, result); | 91 | return @bitCast(dst_t, result); |
| 92 | } | 92 | } |
| 93 | 93 |
lib/std/special/compiler_rt/extendXfYf2_test.zig+4-4| ... | @@ -134,11 +134,11 @@ test "extendsftf2" { | ... | @@ -134,11 +134,11 @@ test "extendsftf2" { |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | fn makeQNaN64() f64 { | 136 | fn makeQNaN64() f64 { |
| 137 | return @bitCast(f64, u64(0x7ff8000000000000)); | 137 | return @bitCast(f64, @as(u64, 0x7ff8000000000000)); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | fn makeInf64() f64 { | 140 | fn makeInf64() f64 { |
| 141 | return @bitCast(f64, u64(0x7ff0000000000000)); | 141 | return @bitCast(f64, @as(u64, 0x7ff0000000000000)); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | fn makeNaN64(rand: u64) f64 { | 144 | fn makeNaN64(rand: u64) f64 { |
| ... | @@ -146,7 +146,7 @@ fn makeNaN64(rand: u64) f64 { | ... | @@ -146,7 +146,7 @@ fn makeNaN64(rand: u64) f64 { |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | fn makeQNaN32() f32 { | 148 | fn makeQNaN32() f32 { |
| 149 | return @bitCast(f32, u32(0x7fc00000)); | 149 | return @bitCast(f32, @as(u32, 0x7fc00000)); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | fn makeNaN32(rand: u32) f32 { | 152 | fn makeNaN32(rand: u32) f32 { |
| ... | @@ -154,5 +154,5 @@ fn makeNaN32(rand: u32) f32 { | ... | @@ -154,5 +154,5 @@ fn makeNaN32(rand: u32) f32 { |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | fn makeInf32() f32 { | 156 | fn makeInf32() f32 { |
| 157 | return @bitCast(f32, u32(0x7f800000)); | 157 | return @bitCast(f32, @as(u32, 0x7f800000)); |
| 158 | } | 158 | } |
lib/std/special/compiler_rt/fixdfdi_test.zig+1-1| ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | fn test__fixdfdi(a: f64, expected: i64) void { | 7 | fn test__fixdfdi(a: f64, expected: i64) void { |
| 8 | const x = __fixdfdi(a); | 8 | const x = __fixdfdi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)); | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)); |
| 10 | testing.expect(x == expected); | 10 | testing.expect(x == expected); |
| 11 | } | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixdfsi_test.zig+1-1| ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | fn test__fixdfsi(a: f64, expected: i32) void { | 7 | fn test__fixdfsi(a: f64, expected: i32) void { |
| 8 | const x = __fixdfsi(a); | 8 | const x = __fixdfsi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)); | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)); |
| 10 | testing.expect(x == expected); | 10 | testing.expect(x == expected); |
| 11 | } | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixdfti_test.zig+1-1| ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | fn test__fixdfti(a: f64, expected: i128) void { | 7 | fn test__fixdfti(a: f64, expected: i128) void { |
| 8 | const x = __fixdfti(a); | 8 | const x = __fixdfti(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)); | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)); |
| 10 | testing.expect(x == expected); | 10 | testing.expect(x == expected); |
| 11 | } | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixint.zig+3-3| ... | @@ -25,11 +25,11 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t { | ... | @@ -25,11 +25,11 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t { |
| 25 | 25 | ||
| 26 | const typeWidth = rep_t.bit_count; | 26 | const typeWidth = rep_t.bit_count; |
| 27 | const exponentBits = (typeWidth - significandBits - 1); | 27 | const exponentBits = (typeWidth - significandBits - 1); |
| 28 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | 28 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); |
| 29 | const maxExponent = ((1 << exponentBits) - 1); | 29 | const maxExponent = ((1 << exponentBits) - 1); |
| 30 | const exponentBias = (maxExponent >> 1); | 30 | const exponentBias = (maxExponent >> 1); |
| 31 | 31 | ||
| 32 | const implicitBit = (rep_t(1) << significandBits); | 32 | const implicitBit = (@as(rep_t, 1) << significandBits); |
| 33 | const significandMask = (implicitBit - 1); | 33 | const significandMask = (implicitBit - 1); |
| 34 | 34 | ||
| 35 | // Break a into sign, exponent, significand | 35 | // Break a into sign, exponent, significand |
| ... | @@ -51,7 +51,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t { | ... | @@ -51,7 +51,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t { |
| 51 | 51 | ||
| 52 | // If the value is too large for the integer type, saturate. | 52 | // If the value is too large for the integer type, saturate. |
| 53 | if (@intCast(usize, exponent) >= fixint_t.bit_count) { | 53 | if (@intCast(usize, exponent) >= fixint_t.bit_count) { |
| 54 | return if (negative) fixint_t(minInt(fixint_t)) else fixint_t(maxInt(fixint_t)); | 54 | return if (negative) @as(fixint_t, minInt(fixint_t)) else @as(fixint_t, maxInt(fixint_t)); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | // If 0 <= exponent < significandBits, right shift else left shift | 57 | // If 0 <= exponent < significandBits, right shift else left shift |
lib/std/special/compiler_rt/fixint_test.zig+13-13| ... | @@ -81,8 +81,8 @@ test "fixint.i3" { | ... | @@ -81,8 +81,8 @@ test "fixint.i3" { |
| 81 | test "fixint.i32" { | 81 | test "fixint.i32" { |
| 82 | test__fixint(f64, i32, -math.inf_f64, math.minInt(i32)); | 82 | test__fixint(f64, i32, -math.inf_f64, math.minInt(i32)); |
| 83 | test__fixint(f64, i32, -math.f64_max, math.minInt(i32)); | 83 | test__fixint(f64, i32, -math.f64_max, math.minInt(i32)); |
| 84 | test__fixint(f64, i32, f64(math.minInt(i32)), math.minInt(i32)); | 84 | test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32)); |
| 85 | test__fixint(f64, i32, f64(math.minInt(i32)) + 1, math.minInt(i32) + 1); | 85 | test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1); |
| 86 | test__fixint(f64, i32, -2.0, -2); | 86 | test__fixint(f64, i32, -2.0, -2); |
| 87 | test__fixint(f64, i32, -1.9, -1); | 87 | test__fixint(f64, i32, -1.9, -1); |
| 88 | test__fixint(f64, i32, -1.1, -1); | 88 | test__fixint(f64, i32, -1.1, -1); |
| ... | @@ -96,8 +96,8 @@ test "fixint.i32" { | ... | @@ -96,8 +96,8 @@ test "fixint.i32" { |
| 96 | test__fixint(f64, i32, 0.1, 0); | 96 | test__fixint(f64, i32, 0.1, 0); |
| 97 | test__fixint(f64, i32, 0.9, 0); | 97 | test__fixint(f64, i32, 0.9, 0); |
| 98 | test__fixint(f64, i32, 1.0, 1); | 98 | test__fixint(f64, i32, 1.0, 1); |
| 99 | test__fixint(f64, i32, f64(math.maxInt(i32)) - 1, math.maxInt(i32) - 1); | 99 | test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1); |
| 100 | test__fixint(f64, i32, f64(math.maxInt(i32)), math.maxInt(i32)); | 100 | test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32)); |
| 101 | test__fixint(f64, i32, math.f64_max, math.maxInt(i32)); | 101 | test__fixint(f64, i32, math.f64_max, math.maxInt(i32)); |
| 102 | test__fixint(f64, i32, math.inf_f64, math.maxInt(i32)); | 102 | test__fixint(f64, i32, math.inf_f64, math.maxInt(i32)); |
| 103 | } | 103 | } |
| ... | @@ -105,9 +105,9 @@ test "fixint.i32" { | ... | @@ -105,9 +105,9 @@ test "fixint.i32" { |
| 105 | test "fixint.i64" { | 105 | test "fixint.i64" { |
| 106 | test__fixint(f64, i64, -math.inf_f64, math.minInt(i64)); | 106 | test__fixint(f64, i64, -math.inf_f64, math.minInt(i64)); |
| 107 | test__fixint(f64, i64, -math.f64_max, math.minInt(i64)); | 107 | test__fixint(f64, i64, -math.f64_max, math.minInt(i64)); |
| 108 | test__fixint(f64, i64, f64(math.minInt(i64)), math.minInt(i64)); | 108 | test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64)); |
| 109 | test__fixint(f64, i64, f64(math.minInt(i64)) + 1, math.minInt(i64)); | 109 | test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64)); |
| 110 | test__fixint(f64, i64, f64(math.minInt(i64) / 2), math.minInt(i64) / 2); | 110 | test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2); |
| 111 | test__fixint(f64, i64, -2.0, -2); | 111 | test__fixint(f64, i64, -2.0, -2); |
| 112 | test__fixint(f64, i64, -1.9, -1); | 112 | test__fixint(f64, i64, -1.9, -1); |
| 113 | test__fixint(f64, i64, -1.1, -1); | 113 | test__fixint(f64, i64, -1.1, -1); |
| ... | @@ -121,8 +121,8 @@ test "fixint.i64" { | ... | @@ -121,8 +121,8 @@ test "fixint.i64" { |
| 121 | test__fixint(f64, i64, 0.1, 0); | 121 | test__fixint(f64, i64, 0.1, 0); |
| 122 | test__fixint(f64, i64, 0.9, 0); | 122 | test__fixint(f64, i64, 0.9, 0); |
| 123 | test__fixint(f64, i64, 1.0, 1); | 123 | test__fixint(f64, i64, 1.0, 1); |
| 124 | test__fixint(f64, i64, f64(math.maxInt(i64)) - 1, math.maxInt(i64)); | 124 | test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64)); |
| 125 | test__fixint(f64, i64, f64(math.maxInt(i64)), math.maxInt(i64)); | 125 | test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64)); |
| 126 | test__fixint(f64, i64, math.f64_max, math.maxInt(i64)); | 126 | test__fixint(f64, i64, math.f64_max, math.maxInt(i64)); |
| 127 | test__fixint(f64, i64, math.inf_f64, math.maxInt(i64)); | 127 | test__fixint(f64, i64, math.inf_f64, math.maxInt(i64)); |
| 128 | } | 128 | } |
| ... | @@ -130,8 +130,8 @@ test "fixint.i64" { | ... | @@ -130,8 +130,8 @@ test "fixint.i64" { |
| 130 | test "fixint.i128" { | 130 | test "fixint.i128" { |
| 131 | test__fixint(f64, i128, -math.inf_f64, math.minInt(i128)); | 131 | test__fixint(f64, i128, -math.inf_f64, math.minInt(i128)); |
| 132 | test__fixint(f64, i128, -math.f64_max, math.minInt(i128)); | 132 | test__fixint(f64, i128, -math.f64_max, math.minInt(i128)); |
| 133 | test__fixint(f64, i128, f64(math.minInt(i128)), math.minInt(i128)); | 133 | test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128)); |
| 134 | test__fixint(f64, i128, f64(math.minInt(i128)) + 1, math.minInt(i128)); | 134 | test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128)); |
| 135 | test__fixint(f64, i128, -2.0, -2); | 135 | test__fixint(f64, i128, -2.0, -2); |
| 136 | test__fixint(f64, i128, -1.9, -1); | 136 | test__fixint(f64, i128, -1.9, -1); |
| 137 | test__fixint(f64, i128, -1.1, -1); | 137 | test__fixint(f64, i128, -1.1, -1); |
| ... | @@ -145,8 +145,8 @@ test "fixint.i128" { | ... | @@ -145,8 +145,8 @@ test "fixint.i128" { |
| 145 | test__fixint(f64, i128, 0.1, 0); | 145 | test__fixint(f64, i128, 0.1, 0); |
| 146 | test__fixint(f64, i128, 0.9, 0); | 146 | test__fixint(f64, i128, 0.9, 0); |
| 147 | test__fixint(f64, i128, 1.0, 1); | 147 | test__fixint(f64, i128, 1.0, 1); |
| 148 | test__fixint(f64, i128, f64(math.maxInt(i128)) - 1, math.maxInt(i128)); | 148 | test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128)); |
| 149 | test__fixint(f64, i128, f64(math.maxInt(i128)), math.maxInt(i128)); | 149 | test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128)); |
| 150 | test__fixint(f64, i128, math.f64_max, math.maxInt(i128)); | 150 | test__fixint(f64, i128, math.f64_max, math.maxInt(i128)); |
| 151 | test__fixint(f64, i128, math.inf_f64, math.maxInt(i128)); | 151 | test__fixint(f64, i128, math.inf_f64, math.maxInt(i128)); |
| 152 | } | 152 | } |
lib/std/special/compiler_rt/fixsfdi_test.zig+1-1| ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | fn test__fixsfdi(a: f32, expected: i64) void { | 7 | fn test__fixsfdi(a: f32, expected: i64) void { |
| 8 | const x = __fixsfdi(a); | 8 | const x = __fixsfdi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)); | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)); |
| 10 | testing.expect(x == expected); | 10 | testing.expect(x == expected); |
| 11 | } | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixsfsi_test.zig+1-1| ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | fn test__fixsfsi(a: f32, expected: i32) void { | 7 | fn test__fixsfsi(a: f32, expected: i32) void { |
| 8 | const x = __fixsfsi(a); | 8 | const x = __fixsfsi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)); | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)); |
| 10 | testing.expect(x == expected); | 10 | testing.expect(x == expected); |
| 11 | } | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixsfti_test.zig+1-1| ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | fn test__fixsfti(a: f32, expected: i128) void { | 7 | fn test__fixsfti(a: f32, expected: i128) void { |
| 8 | const x = __fixsfti(a); | 8 | const x = __fixsfti(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)); | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)); |
| 10 | testing.expect(x == expected); | 10 | testing.expect(x == expected); |
| 11 | } | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixtfdi_test.zig+1-1| ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | fn test__fixtfdi(a: f128, expected: i64) void { | 7 | fn test__fixtfdi(a: f128, expected: i64) void { |
| 8 | const x = __fixtfdi(a); | 8 | const x = __fixtfdi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)); | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)); |
| 10 | testing.expect(x == expected); | 10 | testing.expect(x == expected); |
| 11 | } | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixtfsi_test.zig+1-1| ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | fn test__fixtfsi(a: f128, expected: i32) void { | 7 | fn test__fixtfsi(a: f128, expected: i32) void { |
| 8 | const x = __fixtfsi(a); | 8 | const x = __fixtfsi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)); | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)); |
| 10 | testing.expect(x == expected); | 10 | testing.expect(x == expected); |
| 11 | } | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixtfti_test.zig+1-1| ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; | ... | @@ -6,7 +6,7 @@ const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | fn test__fixtfti(a: f128, expected: i128) void { | 7 | fn test__fixtfti(a: f128, expected: i128) void { |
| 8 | const x = __fixtfti(a); | 8 | const x = __fixtfti(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)); | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)); |
| 10 | testing.expect(x == expected); | 10 | testing.expect(x == expected); |
| 11 | } | 11 | } |
| 12 | 12 |
lib/std/special/compiler_rt/fixuint.zig+4-4| ... | @@ -19,11 +19,11 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t | ... | @@ -19,11 +19,11 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t |
| 19 | }; | 19 | }; |
| 20 | const typeWidth = rep_t.bit_count; | 20 | const typeWidth = rep_t.bit_count; |
| 21 | const exponentBits = (typeWidth - significandBits - 1); | 21 | const exponentBits = (typeWidth - significandBits - 1); |
| 22 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | 22 | const signBit = (@as(rep_t, 1) << (significandBits + exponentBits)); |
| 23 | const maxExponent = ((1 << exponentBits) - 1); | 23 | const maxExponent = ((1 << exponentBits) - 1); |
| 24 | const exponentBias = (maxExponent >> 1); | 24 | const exponentBias = (maxExponent >> 1); |
| 25 | 25 | ||
| 26 | const implicitBit = (rep_t(1) << significandBits); | 26 | const implicitBit = (@as(rep_t, 1) << significandBits); |
| 27 | const significandMask = (implicitBit - 1); | 27 | const significandMask = (implicitBit - 1); |
| 28 | 28 | ||
| 29 | // Break a into sign, exponent, significand | 29 | // Break a into sign, exponent, significand |
| ... | @@ -31,7 +31,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t | ... | @@ -31,7 +31,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t |
| 31 | const absMask = signBit - 1; | 31 | const absMask = signBit - 1; |
| 32 | const aAbs: rep_t = aRep & absMask; | 32 | const aAbs: rep_t = aRep & absMask; |
| 33 | 33 | ||
| 34 | const sign = if ((aRep & signBit) != 0) i32(-1) else i32(1); | 34 | const sign = if ((aRep & signBit) != 0) @as(i32, -1) else @as(i32, 1); |
| 35 | const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias; | 35 | const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias; |
| 36 | const significand: rep_t = (aAbs & significandMask) | implicitBit; | 36 | const significand: rep_t = (aAbs & significandMask) | implicitBit; |
| 37 | 37 | ||
| ... | @@ -39,7 +39,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t | ... | @@ -39,7 +39,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t |
| 39 | if (sign == -1 or exponent < 0) return 0; | 39 | if (sign == -1 or exponent < 0) return 0; |
| 40 | 40 | ||
| 41 | // If the value is too large for the integer type, saturate. | 41 | // If the value is too large for the integer type, saturate. |
| 42 | if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~fixuint_t(0); | 42 | if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~@as(fixuint_t, 0); |
| 43 | 43 | ||
| 44 | // If 0 <= exponent < significandBits, right shift to get the result. | 44 | // If 0 <= exponent < significandBits, right shift to get the result. |
| 45 | // Otherwise, shift left. | 45 | // Otherwise, shift left. |
lib/std/special/compiler_rt/fixunstfsi_test.zig+1-1| ... | @@ -6,7 +6,7 @@ fn test__fixunstfsi(a: f128, expected: u32) void { | ... | @@ -6,7 +6,7 @@ fn test__fixunstfsi(a: f128, expected: u32) void { |
| 6 | testing.expect(x == expected); | 6 | testing.expect(x == expected); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000)); | 9 | const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)); |
| 10 | 10 | ||
| 11 | test "fixunstfsi" { | 11 | test "fixunstfsi" { |
| 12 | test__fixunstfsi(inf128, 0xffffffff); | 12 | test__fixunstfsi(inf128, 0xffffffff); |
lib/std/special/compiler_rt/fixunstfti_test.zig+1-1| ... | @@ -6,7 +6,7 @@ fn test__fixunstfti(a: f128, expected: u128) void { | ... | @@ -6,7 +6,7 @@ fn test__fixunstfti(a: f128, expected: u128) void { |
| 6 | testing.expect(x == expected); | 6 | testing.expect(x == expected); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000)); | 9 | const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)); |
| 10 | 10 | ||
| 11 | test "fixunstfti" { | 11 | test "fixunstfti" { |
| 12 | test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff); | 12 | test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff); |
lib/std/special/compiler_rt/floatsiXf.zig+5-5| ... | @@ -6,24 +6,24 @@ fn floatsiXf(comptime T: type, a: i32) T { | ... | @@ -6,24 +6,24 @@ fn floatsiXf(comptime T: type, a: i32) T { |
| 6 | @setRuntimeSafety(builtin.is_test); | 6 | @setRuntimeSafety(builtin.is_test); |
| 7 | 7 | ||
| 8 | const Z = @IntType(false, T.bit_count); | 8 | const Z = @IntType(false, T.bit_count); |
| 9 | const S = @IntType(false, T.bit_count - @clz(Z, Z(T.bit_count) - 1)); | 9 | const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1)); |
| 10 | 10 | ||
| 11 | if (a == 0) { | 11 | if (a == 0) { |
| 12 | return T(0.0); | 12 | return @as(T, 0.0); |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | const significandBits = std.math.floatMantissaBits(T); | 15 | const significandBits = std.math.floatMantissaBits(T); |
| 16 | const exponentBits = std.math.floatExponentBits(T); | 16 | const exponentBits = std.math.floatExponentBits(T); |
| 17 | const exponentBias = ((1 << exponentBits - 1) - 1); | 17 | const exponentBias = ((1 << exponentBits - 1) - 1); |
| 18 | 18 | ||
| 19 | const implicitBit = Z(1) << significandBits; | 19 | const implicitBit = @as(Z, 1) << significandBits; |
| 20 | const signBit = Z(1 << Z.bit_count - 1); | 20 | const signBit = @as(Z, 1 << Z.bit_count - 1); |
| 21 | 21 | ||
| 22 | const sign = a >> 31; | 22 | const sign = a >> 31; |
| 23 | // Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31). | 23 | // Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31). |
| 24 | const abs_a = (a ^ sign) -% sign; | 24 | const abs_a = (a ^ sign) -% sign; |
| 25 | // The exponent is the width of abs(a) | 25 | // The exponent is the width of abs(a) |
| 26 | const exp = Z(31 - @clz(i32, abs_a)); | 26 | const exp = @as(Z, 31 - @clz(i32, abs_a)); |
| 27 | 27 | ||
| 28 | const sign_bit = if (sign < 0) signBit else 0; | 28 | const sign_bit = if (sign < 0) signBit else 0; |
| 29 | 29 |
lib/std/special/compiler_rt/floattidf.zig+1-1| ... | @@ -47,7 +47,7 @@ pub extern fn __floattidf(arg: i128) f64 { | ... | @@ -47,7 +47,7 @@ pub extern fn __floattidf(arg: i128) f64 { |
| 47 | a += 1; // round - this step may add a significant bit | 47 | a += 1; // round - this step may add a significant bit |
| 48 | a >>= 2; // dump Q and R | 48 | a >>= 2; // dump Q and R |
| 49 | // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits | 49 | // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits |
| 50 | if ((a & (u128(1) << DBL_MANT_DIG)) != 0) { | 50 | if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) { |
| 51 | a >>= 1; | 51 | a >>= 1; |
| 52 | e += 1; | 52 | e += 1; |
| 53 | } | 53 | } |
lib/std/special/compiler_rt/floattisf.zig+1-1| ... | @@ -48,7 +48,7 @@ pub extern fn __floattisf(arg: i128) f32 { | ... | @@ -48,7 +48,7 @@ pub extern fn __floattisf(arg: i128) f32 { |
| 48 | a += 1; // round - this step may add a significant bit | 48 | a += 1; // round - this step may add a significant bit |
| 49 | a >>= 2; // dump Q and R | 49 | a >>= 2; // dump Q and R |
| 50 | // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits | 50 | // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits |
| 51 | if ((a & (u128(1) << FLT_MANT_DIG)) != 0) { | 51 | if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) { |
| 52 | a >>= 1; | 52 | a >>= 1; |
| 53 | e += 1; | 53 | e += 1; |
| 54 | } | 54 | } |
lib/std/special/compiler_rt/floattitf.zig+1-1| ... | @@ -47,7 +47,7 @@ pub extern fn __floattitf(arg: i128) f128 { | ... | @@ -47,7 +47,7 @@ pub extern fn __floattitf(arg: i128) f128 { |
| 47 | a += 1; // round - this step may add a significant bit | 47 | a += 1; // round - this step may add a significant bit |
| 48 | a >>= 2; // dump Q and R | 48 | a >>= 2; // dump Q and R |
| 49 | // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits | 49 | // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits |
| 50 | if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) { | 50 | if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) { |
| 51 | a >>= 1; | 51 | a >>= 1; |
| 52 | e += 1; | 52 | e += 1; |
| 53 | } | 53 | } |
lib/std/special/compiler_rt/floatunsidf.zig+3-3| ... | @@ -2,7 +2,7 @@ const builtin = @import("builtin"); | ... | @@ -2,7 +2,7 @@ const builtin = @import("builtin"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | const maxInt = std.math.maxInt; | 3 | const maxInt = std.math.maxInt; |
| 4 | 4 | ||
| 5 | const implicitBit = u64(1) << 52; | 5 | const implicitBit = @as(u64, 1) << 52; |
| 6 | 6 | ||
| 7 | pub extern fn __floatunsidf(arg: u32) f64 { | 7 | pub extern fn __floatunsidf(arg: u32) f64 { |
| 8 | @setRuntimeSafety(builtin.is_test); | 8 | @setRuntimeSafety(builtin.is_test); |
| ... | @@ -10,10 +10,10 @@ pub extern fn __floatunsidf(arg: u32) f64 { | ... | @@ -10,10 +10,10 @@ pub extern fn __floatunsidf(arg: u32) f64 { |
| 10 | if (arg == 0) return 0.0; | 10 | if (arg == 0) return 0.0; |
| 11 | 11 | ||
| 12 | // The exponent is the width of abs(a) | 12 | // The exponent is the width of abs(a) |
| 13 | const exp = u64(31) - @clz(u32, arg); | 13 | const exp = @as(u64, 31) - @clz(u32, arg); |
| 14 | // Shift a into the significand field and clear the implicit bit | 14 | // Shift a into the significand field and clear the implicit bit |
| 15 | const shift = @intCast(u6, 52 - exp); | 15 | const shift = @intCast(u6, 52 - exp); |
| 16 | const mant = u64(arg) << shift ^ implicitBit; | 16 | const mant = @as(u64, arg) << shift ^ implicitBit; |
| 17 | 17 | ||
| 18 | return @bitCast(f64, mant | (exp + 1023) << 52); | 18 | return @bitCast(f64, mant | (exp + 1023) << 52); |
| 19 | } | 19 | } |
lib/std/special/compiler_rt/floatuntidf.zig+2-2| ... | @@ -32,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { | ... | @@ -32,7 +32,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { |
| 32 | const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd; | 32 | const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd; |
| 33 | const shift_amt_u7 = @intCast(u7, shift_amt); | 33 | const shift_amt_u7 = @intCast(u7, shift_amt); |
| 34 | a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) | | 34 | a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) | |
| 35 | @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); | 35 | @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); |
| 36 | }, | 36 | }, |
| 37 | } | 37 | } |
| 38 | // finish | 38 | // finish |
| ... | @@ -40,7 +40,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { | ... | @@ -40,7 +40,7 @@ pub extern fn __floatuntidf(arg: u128) f64 { |
| 40 | a += 1; // round - this step may add a significant bit | 40 | a += 1; // round - this step may add a significant bit |
| 41 | a >>= 2; // dump Q and R | 41 | a >>= 2; // dump Q and R |
| 42 | // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits | 42 | // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits |
| 43 | if ((a & (u128(1) << DBL_MANT_DIG)) != 0) { | 43 | if ((a & (@as(u128, 1) << DBL_MANT_DIG)) != 0) { |
| 44 | a >>= 1; | 44 | a >>= 1; |
| 45 | e += 1; | 45 | e += 1; |
| 46 | } | 46 | } |
lib/std/special/compiler_rt/floatuntisf.zig+2-2| ... | @@ -32,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { | ... | @@ -32,7 +32,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { |
| 32 | const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd; | 32 | const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd; |
| 33 | const shift_amt_u7 = @intCast(u7, shift_amt); | 33 | const shift_amt_u7 = @intCast(u7, shift_amt); |
| 34 | a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) | | 34 | a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) | |
| 35 | @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); | 35 | @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); |
| 36 | }, | 36 | }, |
| 37 | } | 37 | } |
| 38 | // finish | 38 | // finish |
| ... | @@ -40,7 +40,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { | ... | @@ -40,7 +40,7 @@ pub extern fn __floatuntisf(arg: u128) f32 { |
| 40 | a += 1; // round - this step may add a significant bit | 40 | a += 1; // round - this step may add a significant bit |
| 41 | a >>= 2; // dump Q and R | 41 | a >>= 2; // dump Q and R |
| 42 | // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits | 42 | // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits |
| 43 | if ((a & (u128(1) << FLT_MANT_DIG)) != 0) { | 43 | if ((a & (@as(u128, 1) << FLT_MANT_DIG)) != 0) { |
| 44 | a >>= 1; | 44 | a >>= 1; |
| 45 | e += 1; | 45 | e += 1; |
| 46 | } | 46 | } |
lib/std/special/compiler_rt/floatuntitf.zig+2-2| ... | @@ -32,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { | ... | @@ -32,7 +32,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { |
| 32 | const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd; | 32 | const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd; |
| 33 | const shift_amt_u7 = @intCast(u7, shift_amt); | 33 | const shift_amt_u7 = @intCast(u7, shift_amt); |
| 34 | a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) | | 34 | a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) | |
| 35 | @boolToInt((a & (u128(maxInt(u128)) >> shift_amt_u7)) != 0); | 35 | @boolToInt((a & (@as(u128, maxInt(u128)) >> shift_amt_u7)) != 0); |
| 36 | }, | 36 | }, |
| 37 | } | 37 | } |
| 38 | // finish | 38 | // finish |
| ... | @@ -40,7 +40,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { | ... | @@ -40,7 +40,7 @@ pub extern fn __floatuntitf(arg: u128) f128 { |
| 40 | a += 1; // round - this step may add a significant bit | 40 | a += 1; // round - this step may add a significant bit |
| 41 | a >>= 2; // dump Q and R | 41 | a >>= 2; // dump Q and R |
| 42 | // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits | 42 | // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits |
| 43 | if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) { | 43 | if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) { |
| 44 | a >>= 1; | 44 | a >>= 1; |
| 45 | e += 1; | 45 | e += 1; |
| 46 | } | 46 | } |
lib/std/special/compiler_rt/mulXf3.zig+25-25| ... | @@ -24,11 +24,11 @@ fn mulXf3(comptime T: type, a: T, b: T) T { | ... | @@ -24,11 +24,11 @@ fn mulXf3(comptime T: type, a: T, b: T) T { |
| 24 | const significandBits = std.math.floatMantissaBits(T); | 24 | const significandBits = std.math.floatMantissaBits(T); |
| 25 | const exponentBits = std.math.floatExponentBits(T); | 25 | const exponentBits = std.math.floatExponentBits(T); |
| 26 | 26 | ||
| 27 | const signBit = (Z(1) << (significandBits + exponentBits)); | 27 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); |
| 28 | const maxExponent = ((1 << exponentBits) - 1); | 28 | const maxExponent = ((1 << exponentBits) - 1); |
| 29 | const exponentBias = (maxExponent >> 1); | 29 | const exponentBias = (maxExponent >> 1); |
| 30 | 30 | ||
| 31 | const implicitBit = (Z(1) << significandBits); | 31 | const implicitBit = (@as(Z, 1) << significandBits); |
| 32 | const quietBit = implicitBit >> 1; | 32 | const quietBit = implicitBit >> 1; |
| 33 | const significandMask = implicitBit - 1; | 33 | const significandMask = implicitBit - 1; |
| 34 | 34 | ||
| ... | @@ -122,7 +122,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T { | ... | @@ -122,7 +122,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T { |
| 122 | // a zero of the appropriate sign. Mathematically there is no need to | 122 | // a zero of the appropriate sign. Mathematically there is no need to |
| 123 | // handle this case separately, but we make it a special case to | 123 | // handle this case separately, but we make it a special case to |
| 124 | // simplify the shift logic. | 124 | // simplify the shift logic. |
| 125 | const shift: u32 = @truncate(u32, Z(1) -% @bitCast(u32, productExponent)); | 125 | const shift: u32 = @truncate(u32, @as(Z, 1) -% @bitCast(u32, productExponent)); |
| 126 | if (shift >= typeWidth) return @bitCast(T, productSign); | 126 | if (shift >= typeWidth) return @bitCast(T, productSign); |
| 127 | 127 | ||
| 128 | // Otherwise, shift the significand of the result so that the round | 128 | // Otherwise, shift the significand of the result so that the round |
| ... | @@ -131,7 +131,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T { | ... | @@ -131,7 +131,7 @@ fn mulXf3(comptime T: type, a: T, b: T) T { |
| 131 | } else { | 131 | } else { |
| 132 | // Result is normal before rounding; insert the exponent. | 132 | // Result is normal before rounding; insert the exponent. |
| 133 | productHi &= significandMask; | 133 | productHi &= significandMask; |
| 134 | productHi |= Z(@bitCast(u32, productExponent)) << significandBits; | 134 | productHi |= @as(Z, @bitCast(u32, productExponent)) << significandBits; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | // Insert the sign of the result: | 137 | // Insert the sign of the result: |
| ... | @@ -150,7 +150,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { | ... | @@ -150,7 +150,7 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 150 | switch (Z) { | 150 | switch (Z) { |
| 151 | u32 => { | 151 | u32 => { |
| 152 | // 32x32 --> 64 bit multiply | 152 | // 32x32 --> 64 bit multiply |
| 153 | const product = u64(a) * u64(b); | 153 | const product = @as(u64, a) * @as(u64, b); |
| 154 | hi.* = @truncate(u32, product >> 32); | 154 | hi.* = @truncate(u32, product >> 32); |
| 155 | lo.* = @truncate(u32, product); | 155 | lo.* = @truncate(u32, product); |
| 156 | }, | 156 | }, |
| ... | @@ -179,9 +179,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { | ... | @@ -179,9 +179,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 179 | hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; | 179 | hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; |
| 180 | }, | 180 | }, |
| 181 | u128 => { | 181 | u128 => { |
| 182 | const Word_LoMask = u64(0x00000000ffffffff); | 182 | const Word_LoMask = @as(u64, 0x00000000ffffffff); |
| 183 | const Word_HiMask = u64(0xffffffff00000000); | 183 | const Word_HiMask = @as(u64, 0xffffffff00000000); |
| 184 | const Word_FullMask = u64(0xffffffffffffffff); | 184 | const Word_FullMask = @as(u64, 0xffffffffffffffff); |
| 185 | const S = struct { | 185 | const S = struct { |
| 186 | fn Word_1(x: u128) u64 { | 186 | fn Word_1(x: u128) u64 { |
| 187 | return @truncate(u32, x >> 96); | 187 | return @truncate(u32, x >> 96); |
| ... | @@ -217,22 +217,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { | ... | @@ -217,22 +217,22 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { |
| 217 | const product43: u64 = S.Word_4(a) * S.Word_3(b); | 217 | const product43: u64 = S.Word_4(a) * S.Word_3(b); |
| 218 | const product44: u64 = S.Word_4(a) * S.Word_4(b); | 218 | const product44: u64 = S.Word_4(a) * S.Word_4(b); |
| 219 | 219 | ||
| 220 | const sum0: u128 = u128(product44); | 220 | const sum0: u128 = @as(u128, product44); |
| 221 | const sum1: u128 = u128(product34) +% | 221 | const sum1: u128 = @as(u128, product34) +% |
| 222 | u128(product43); | 222 | @as(u128, product43); |
| 223 | const sum2: u128 = u128(product24) +% | 223 | const sum2: u128 = @as(u128, product24) +% |
| 224 | u128(product33) +% | 224 | @as(u128, product33) +% |
| 225 | u128(product42); | 225 | @as(u128, product42); |
| 226 | const sum3: u128 = u128(product14) +% | 226 | const sum3: u128 = @as(u128, product14) +% |
| 227 | u128(product23) +% | 227 | @as(u128, product23) +% |
| 228 | u128(product32) +% | 228 | @as(u128, product32) +% |
| 229 | u128(product41); | 229 | @as(u128, product41); |
| 230 | const sum4: u128 = u128(product13) +% | 230 | const sum4: u128 = @as(u128, product13) +% |
| 231 | u128(product22) +% | 231 | @as(u128, product22) +% |
| 232 | u128(product31); | 232 | @as(u128, product31); |
| 233 | const sum5: u128 = u128(product12) +% | 233 | const sum5: u128 = @as(u128, product12) +% |
| 234 | u128(product21); | 234 | @as(u128, product21); |
| 235 | const sum6: u128 = u128(product11); | 235 | const sum6: u128 = @as(u128, product11); |
| 236 | 236 | ||
| 237 | const r0: u128 = (sum0 & Word_FullMask) +% | 237 | const r0: u128 = (sum0 & Word_FullMask) +% |
| 238 | ((sum1 & Word_LoMask) << 32); | 238 | ((sum1 & Word_LoMask) << 32); |
| ... | @@ -258,7 +258,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { | ... | @@ -258,7 +258,7 @@ fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 { |
| 258 | @setRuntimeSafety(builtin.is_test); | 258 | @setRuntimeSafety(builtin.is_test); |
| 259 | const Z = @IntType(false, T.bit_count); | 259 | const Z = @IntType(false, T.bit_count); |
| 260 | const significandBits = std.math.floatMantissaBits(T); | 260 | const significandBits = std.math.floatMantissaBits(T); |
| 261 | const implicitBit = Z(1) << significandBits; | 261 | const implicitBit = @as(Z, 1) << significandBits; |
| 262 | 262 | ||
| 263 | const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); | 263 | const shift = @clz(Z, significand.*) - @clz(Z, implicitBit); |
| 264 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); | 264 | significand.* <<= @intCast(std.math.Log2Int(Z), shift); |
lib/std/special/compiler_rt/mulXf3_test.zig+9-9| ... | @@ -2,8 +2,8 @@ | ... | @@ -2,8 +2,8 @@ |
| 2 | // | 2 | // |
| 3 | // https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/test/builtins/Unit/multf3_test.c | 3 | // https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/test/builtins/Unit/multf3_test.c |
| 4 | 4 | ||
| 5 | const qnan128 = @bitCast(f128, u128(0x7fff800000000000) << 64); | 5 | const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64); |
| 6 | const inf128 = @bitCast(f128, u128(0x7fff000000000000) << 64); | 6 | const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64); |
| 7 | 7 | ||
| 8 | const __multf3 = @import("mulXf3.zig").__multf3; | 8 | const __multf3 = @import("mulXf3.zig").__multf3; |
| 9 | 9 | ||
| ... | @@ -39,7 +39,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void { | ... | @@ -39,7 +39,7 @@ fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void { |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | fn makeNaN128(rand: u64) f128 { | 41 | fn makeNaN128(rand: u64) f128 { |
| 42 | const int_result = u128(0x7fff000000000000 | (rand & 0xffffffffffff)) << 64; | 42 | const int_result = @as(u128, 0x7fff000000000000 | (rand & 0xffffffffffff)) << 64; |
| 43 | const float_result = @bitCast(f128, int_result); | 43 | const float_result = @bitCast(f128, int_result); |
| 44 | return float_result; | 44 | return float_result; |
| 45 | } | 45 | } |
| ... | @@ -55,15 +55,15 @@ test "multf3" { | ... | @@ -55,15 +55,15 @@ test "multf3" { |
| 55 | 55 | ||
| 56 | // any * any | 56 | // any * any |
| 57 | test__multf3( | 57 | test__multf3( |
| 58 | @bitCast(f128, u128(0x40042eab345678439abcdefea5678234)), | 58 | @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)), |
| 59 | @bitCast(f128, u128(0x3ffeedcb34a235253948765432134675)), | 59 | @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)), |
| 60 | 0x400423e7f9e3c9fc, | 60 | 0x400423e7f9e3c9fc, |
| 61 | 0xd906c2c2a85777c4, | 61 | 0xd906c2c2a85777c4, |
| 62 | ); | 62 | ); |
| 63 | 63 | ||
| 64 | test__multf3( | 64 | test__multf3( |
| 65 | @bitCast(f128, u128(0x3fcd353e45674d89abacc3a2ebf3ff50)), | 65 | @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)), |
| 66 | @bitCast(f128, u128(0x3ff6ed8764648369535adf4be3214568)), | 66 | @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)), |
| 67 | 0x3fc52a163c6223fc, | 67 | 0x3fc52a163c6223fc, |
| 68 | 0xc94c4bf0430768b4, | 68 | 0xc94c4bf0430768b4, |
| 69 | ); | 69 | ); |
| ... | @@ -76,8 +76,8 @@ test "multf3" { | ... | @@ -76,8 +76,8 @@ test "multf3" { |
| 76 | ); | 76 | ); |
| 77 | 77 | ||
| 78 | test__multf3( | 78 | test__multf3( |
| 79 | @bitCast(f128, u128(0x3f154356473c82a9fabf2d22ace345df)), | 79 | @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)), |
| 80 | @bitCast(f128, u128(0x3e38eda98765476743ab21da23d45679)), | 80 | @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)), |
| 81 | 0x3d4f37c1a3137cae, | 81 | 0x3d4f37c1a3137cae, |
| 82 | 0xfc6807048bc2836a, | 82 | 0xfc6807048bc2836a, |
| 83 | ); | 83 | ); |
lib/std/special/compiler_rt/muldi3.zig+1-1| ... | @@ -21,7 +21,7 @@ fn __muldsi3(a: u32, b: u32) i64 { | ... | @@ -21,7 +21,7 @@ fn __muldsi3(a: u32, b: u32) i64 { |
| 21 | @setRuntimeSafety(builtin.is_test); | 21 | @setRuntimeSafety(builtin.is_test); |
| 22 | 22 | ||
| 23 | const bits_in_word_2 = @sizeOf(i32) * 8 / 2; | 23 | const bits_in_word_2 = @sizeOf(i32) * 8 / 2; |
| 24 | const lower_mask = (~u32(0)) >> bits_in_word_2; | 24 | const lower_mask = (~@as(u32, 0)) >> bits_in_word_2; |
| 25 | 25 | ||
| 26 | var r: dwords = undefined; | 26 | var r: dwords = undefined; |
| 27 | r.s.low = (a & lower_mask) *% (b & lower_mask); | 27 | r.s.low = (a & lower_mask) *% (b & lower_mask); |
lib/std/special/compiler_rt/mulodi4.zig+1-1| ... | @@ -6,7 +6,7 @@ const minInt = std.math.minInt; | ... | @@ -6,7 +6,7 @@ const minInt = std.math.minInt; |
| 6 | pub extern fn __mulodi4(a: i64, b: i64, overflow: *c_int) i64 { | 6 | pub extern fn __mulodi4(a: i64, b: i64, overflow: *c_int) i64 { |
| 7 | @setRuntimeSafety(builtin.is_test); | 7 | @setRuntimeSafety(builtin.is_test); |
| 8 | 8 | ||
| 9 | const min = @bitCast(i64, u64(1 << (i64.bit_count - 1))); | 9 | const min = @bitCast(i64, @as(u64, 1 << (i64.bit_count - 1))); |
| 10 | const max = ~min; | 10 | const max = ~min; |
| 11 | 11 | ||
| 12 | overflow.* = 0; | 12 | overflow.* = 0; |
lib/std/special/compiler_rt/mulodi4_test.zig+24-24| ... | @@ -52,34 +52,34 @@ test "mulodi4" { | ... | @@ -52,34 +52,34 @@ test "mulodi4" { |
| 52 | 52 | ||
| 53 | test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1); | 53 | test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1); |
| 54 | test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1); | 54 | test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1); |
| 55 | test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, u64(0x8000000000000001)), 0); | 55 | test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); |
| 56 | test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 0); | 56 | test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); |
| 57 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0); | 57 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0); |
| 58 | test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0); | 58 | test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0); |
| 59 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0); | 59 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0); |
| 60 | test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0); | 60 | test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0); |
| 61 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, u64(0x8000000000000001)), 1); | 61 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); |
| 62 | test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 1); | 62 | test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); |
| 63 | 63 | ||
| 64 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -2, @bitCast(i64, u64(0x8000000000000000)), 1); | 64 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); |
| 65 | test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1); | 65 | test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); |
| 66 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)), 1); | 66 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); |
| 67 | test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1); | 67 | test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); |
| 68 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 0, 0, 0); | 68 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0); |
| 69 | test__mulodi4(0, @bitCast(i64, u64(0x8000000000000000)), 0, 0); | 69 | test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0); |
| 70 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)), 0); | 70 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0); |
| 71 | test__mulodi4(1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 0); | 71 | test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0); |
| 72 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0x8000000000000000)), 1); | 72 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); |
| 73 | test__mulodi4(2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1); | 73 | test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); |
| 74 | 74 | ||
| 75 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -2, @bitCast(i64, u64(0x8000000000000001)), 1); | 75 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); |
| 76 | test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 1); | 76 | test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1); |
| 77 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0); | 77 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0); |
| 78 | test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0); | 78 | test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0); |
| 79 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 0, 0, 0); | 79 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0); |
| 80 | test__mulodi4(0, @bitCast(i64, u64(0x8000000000000001)), 0, 0); | 80 | test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0); |
| 81 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 1, @bitCast(i64, u64(0x8000000000000001)), 0); | 81 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); |
| 82 | test__mulodi4(1, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 0); | 82 | test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0); |
| 83 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 2, @bitCast(i64, u64(0x8000000000000000)), 1); | 83 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); |
| 84 | test__mulodi4(2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000000)), 1); | 84 | test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); |
| 85 | } | 85 | } |
lib/std/special/compiler_rt/muloti4.zig+1-1| ... | @@ -4,7 +4,7 @@ const compiler_rt = @import("../compiler_rt.zig"); | ... | @@ -4,7 +4,7 @@ const compiler_rt = @import("../compiler_rt.zig"); |
| 4 | pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 { | 4 | pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | 6 | ||
| 7 | const min = @bitCast(i128, u128(1 << (i128.bit_count - 1))); | 7 | const min = @bitCast(i128, @as(u128, 1 << (i128.bit_count - 1))); |
| 8 | const max = ~min; | 8 | const max = ~min; |
| 9 | overflow.* = 0; | 9 | overflow.* = 0; |
| 10 | 10 |
lib/std/special/compiler_rt/muloti4_test.zig+31-31| ... | @@ -39,38 +39,38 @@ test "muloti4" { | ... | @@ -39,38 +39,38 @@ test "muloti4" { |
| 39 | test__muloti4(2097152, -4398046511103, -9223372036852678656, 0); | 39 | test__muloti4(2097152, -4398046511103, -9223372036852678656, 0); |
| 40 | test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0); | 40 | test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0); |
| 41 | 41 | ||
| 42 | test__muloti4(@bitCast(i128, u128(0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, u128(0x000000000000000000B504F333F9DE5B)), @bitCast(i128, u128(0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0); | 42 | test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0); |
| 43 | test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); | 43 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); |
| 44 | test__muloti4(-2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); | 44 | test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); |
| 45 | 45 | ||
| 46 | test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); | 46 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); |
| 47 | test__muloti4(-1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); | 47 | test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); |
| 48 | test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0); | 48 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0); |
| 49 | test__muloti4(0, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0); | 49 | test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0); |
| 50 | test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | 50 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); |
| 51 | test__muloti4(1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | 51 | test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); |
| 52 | test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); | 52 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); |
| 53 | test__muloti4(2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); | 53 | test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); |
| 54 | 54 | ||
| 55 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); | 55 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); |
| 56 | test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); | 56 | test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); |
| 57 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); | 57 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); |
| 58 | test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); | 58 | test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); |
| 59 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0, 0); | 59 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0); |
| 60 | test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0); | 60 | test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0); |
| 61 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0); | 61 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0); |
| 62 | test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 0); | 62 | test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0); |
| 63 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); | 63 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); |
| 64 | test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); | 64 | test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); |
| 65 | 65 | ||
| 66 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); | 66 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); |
| 67 | test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); | 67 | test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); |
| 68 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | 68 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); |
| 69 | test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | 69 | test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); |
| 70 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0, 0); | 70 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0); |
| 71 | test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0); | 71 | test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0); |
| 72 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); | 72 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); |
| 73 | test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); | 73 | test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); |
| 74 | test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); | 74 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); |
| 75 | test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); | 75 | test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); |
| 76 | } | 76 | } |
lib/std/special/compiler_rt/multi3.zig+1-1| ... | @@ -21,7 +21,7 @@ pub extern fn __multi3_windows_x86_64(a: v128, b: v128) v128 { | ... | @@ -21,7 +21,7 @@ pub extern fn __multi3_windows_x86_64(a: v128, b: v128) v128 { |
| 21 | 21 | ||
| 22 | fn __mulddi3(a: u64, b: u64) i128 { | 22 | fn __mulddi3(a: u64, b: u64) i128 { |
| 23 | const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2; | 23 | const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2; |
| 24 | const lower_mask = ~u64(0) >> bits_in_dword_2; | 24 | const lower_mask = ~@as(u64, 0) >> bits_in_dword_2; |
| 25 | var r: twords = undefined; | 25 | var r: twords = undefined; |
| 26 | r.s.low = (a & lower_mask) *% (b & lower_mask); | 26 | r.s.low = (a & lower_mask) *% (b & lower_mask); |
| 27 | var t: u64 = r.s.low >> bits_in_dword_2; | 27 | var t: u64 = r.s.low >> bits_in_dword_2; |
lib/std/special/compiler_rt/negXf2.zig+1-1| ... | @@ -15,7 +15,7 @@ fn negXf2(comptime T: type, a: T) T { | ... | @@ -15,7 +15,7 @@ fn negXf2(comptime T: type, a: T) T { |
| 15 | const significandBits = std.math.floatMantissaBits(T); | 15 | const significandBits = std.math.floatMantissaBits(T); |
| 16 | const exponentBits = std.math.floatExponentBits(T); | 16 | const exponentBits = std.math.floatExponentBits(T); |
| 17 | 17 | ||
| 18 | const signBit = (Z(1) << (significandBits + exponentBits)); | 18 | const signBit = (@as(Z, 1) << (significandBits + exponentBits)); |
| 19 | 19 | ||
| 20 | return @bitCast(T, @bitCast(Z, a) ^ signBit); | 20 | return @bitCast(T, @bitCast(Z, a) ^ signBit); |
| 21 | } | 21 | } |
lib/std/special/compiler_rt/popcountdi2_test.zig+3-3| ... | @@ -20,8 +20,8 @@ test "popcountdi2" { | ... | @@ -20,8 +20,8 @@ test "popcountdi2" { |
| 20 | test__popcountdi2(0); | 20 | test__popcountdi2(0); |
| 21 | test__popcountdi2(1); | 21 | test__popcountdi2(1); |
| 22 | test__popcountdi2(2); | 22 | test__popcountdi2(2); |
| 23 | test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFD))); | 23 | test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD))); |
| 24 | test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFE))); | 24 | test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE))); |
| 25 | test__popcountdi2(@bitCast(i64, u64(0xFFFFFFFFFFFFFFFF))); | 25 | test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF))); |
| 26 | // TODO some fuzz testing | 26 | // TODO some fuzz testing |
| 27 | } | 27 | } |
lib/std/special/compiler_rt/truncXfYf2.zig+1-1| ... | @@ -69,7 +69,7 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t | ... | @@ -69,7 +69,7 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 69 | // destination format. We can convert by simply right-shifting with | 69 | // destination format. We can convert by simply right-shifting with |
| 70 | // rounding and adjusting the exponent. | 70 | // rounding and adjusting the exponent. |
| 71 | absResult = @truncate(dst_rep_t, aAbs >> (srcSigBits - dstSigBits)); | 71 | absResult = @truncate(dst_rep_t, aAbs >> (srcSigBits - dstSigBits)); |
| 72 | absResult -%= dst_rep_t(srcExpBias - dstExpBias) << dstSigBits; | 72 | absResult -%= @as(dst_rep_t, srcExpBias - dstExpBias) << dstSigBits; |
| 73 | 73 | ||
| 74 | const roundBits: src_rep_t = aAbs & roundMask; | 74 | const roundBits: src_rep_t = aAbs & roundMask; |
| 75 | if (roundBits > halfway) { | 75 | if (roundBits > halfway) { |
lib/std/special/compiler_rt/truncXfYf2_test.zig+10-10| ... | @@ -152,11 +152,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void { | ... | @@ -152,11 +152,11 @@ fn test__trunctfsf2(a: f128, expected: u32) void { |
| 152 | 152 | ||
| 153 | test "trunctfsf2" { | 153 | test "trunctfsf2" { |
| 154 | // qnan | 154 | // qnan |
| 155 | test__trunctfsf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7fc00000); | 155 | test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000); |
| 156 | // nan | 156 | // nan |
| 157 | test__trunctfsf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000); | 157 | test__trunctfsf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000); |
| 158 | // inf | 158 | // inf |
| 159 | test__trunctfsf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7f800000); | 159 | test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7f800000); |
| 160 | // zero | 160 | // zero |
| 161 | test__trunctfsf2(0.0, 0x0); | 161 | test__trunctfsf2(0.0, 0x0); |
| 162 | 162 | ||
| ... | @@ -187,11 +187,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void { | ... | @@ -187,11 +187,11 @@ fn test__trunctfdf2(a: f128, expected: u64) void { |
| 187 | 187 | ||
| 188 | test "trunctfdf2" { | 188 | test "trunctfdf2" { |
| 189 | // qnan | 189 | // qnan |
| 190 | test__trunctfdf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7ff8000000000000); | 190 | test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000); |
| 191 | // nan | 191 | // nan |
| 192 | test__trunctfdf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000); | 192 | test__trunctfdf2(@bitCast(f128, @as(u128, (0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000); |
| 193 | // inf | 193 | // inf |
| 194 | test__trunctfdf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7ff0000000000000); | 194 | test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff000000000000 << 64)), 0x7ff0000000000000); |
| 195 | // zero | 195 | // zero |
| 196 | test__trunctfdf2(0.0, 0x0); | 196 | test__trunctfdf2(0.0, 0x0); |
| 197 | 197 | ||
| ... | @@ -224,11 +224,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void { | ... | @@ -224,11 +224,11 @@ fn test__truncdfsf2(a: f64, expected: u32) void { |
| 224 | 224 | ||
| 225 | test "truncdfsf2" { | 225 | test "truncdfsf2" { |
| 226 | // nan & qnan | 226 | // nan & qnan |
| 227 | test__truncdfsf2(@bitCast(f64, u64(0x7ff8000000000000)), 0x7fc00000); | 227 | test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff8000000000000)), 0x7fc00000); |
| 228 | test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000001)), 0x7fc00000); | 228 | test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000001)), 0x7fc00000); |
| 229 | // inf | 229 | // inf |
| 230 | test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000000)), 0x7f800000); | 230 | test__truncdfsf2(@bitCast(f64, @as(u64, 0x7ff0000000000000)), 0x7f800000); |
| 231 | test__truncdfsf2(@bitCast(f64, u64(0xfff0000000000000)), 0xff800000); | 231 | test__truncdfsf2(@bitCast(f64, @as(u64, 0xfff0000000000000)), 0xff800000); |
| 232 | 232 | ||
| 233 | test__truncdfsf2(0.0, 0x0); | 233 | test__truncdfsf2(0.0, 0x0); |
| 234 | test__truncdfsf2(1.0, 0x3f800000); | 234 | test__truncdfsf2(1.0, 0x3f800000); |
lib/std/special/compiler_rt/udivmod.zig+3-3| ... | @@ -76,7 +76,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: | ... | @@ -76,7 +76,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 76 | // K K | 76 | // K K |
| 77 | // --- | 77 | // --- |
| 78 | // K 0 | 78 | // K 0 |
| 79 | sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high]))); | 79 | sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high]))); |
| 80 | // 0 <= sr <= SingleInt.bit_count - 2 or sr large | 80 | // 0 <= sr <= SingleInt.bit_count - 2 or sr large |
| 81 | if (sr > SingleInt.bit_count - 2) { | 81 | if (sr > SingleInt.bit_count - 2) { |
| 82 | if (maybe_rem) |rem| { | 82 | if (maybe_rem) |rem| { |
| ... | @@ -114,7 +114,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: | ... | @@ -114,7 +114,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 114 | // K X | 114 | // K X |
| 115 | // --- | 115 | // --- |
| 116 | // 0 K | 116 | // 0 K |
| 117 | sr = 1 + SingleInt.bit_count + c_uint(@clz(SingleInt, d[low])) - c_uint(@clz(SingleInt, n[high])); | 117 | sr = 1 + SingleInt.bit_count + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high])); |
| 118 | // 2 <= sr <= DoubleInt.bit_count - 1 | 118 | // 2 <= sr <= DoubleInt.bit_count - 1 |
| 119 | // q.all = a << (DoubleInt.bit_count - sr); | 119 | // q.all = a << (DoubleInt.bit_count - sr); |
| 120 | // r.all = a >> sr; | 120 | // r.all = a >> sr; |
| ... | @@ -140,7 +140,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: | ... | @@ -140,7 +140,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 140 | // K X | 140 | // K X |
| 141 | // --- | 141 | // --- |
| 142 | // K K | 142 | // K K |
| 143 | sr = @bitCast(c_uint, c_int(@clz(SingleInt, d[high])) - c_int(@clz(SingleInt, n[high]))); | 143 | sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high]))); |
| 144 | // 0 <= sr <= SingleInt.bit_count - 1 or sr large | 144 | // 0 <= sr <= SingleInt.bit_count - 1 or sr large |
| 145 | if (sr > SingleInt.bit_count - 1) { | 145 | if (sr > SingleInt.bit_count - 1) { |
| 146 | if (maybe_rem) |rem| { | 146 | if (maybe_rem) |rem| { |
lib/std/target.zig+1-1| ... | @@ -581,7 +581,7 @@ pub const Target = union(enum) { | ... | @@ -581,7 +581,7 @@ pub const Target = union(enum) { |
| 581 | }; | 581 | }; |
| 582 | 582 | ||
| 583 | pub fn getExternalExecutor(self: Target) Executor { | 583 | pub fn getExternalExecutor(self: Target) Executor { |
| 584 | if (@TagType(Target)(self) == .Native) return .native; | 584 | if (@as(@TagType(Target),self) == .Native) return .native; |
| 585 | 585 | ||
| 586 | // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture. | 586 | // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture. |
| 587 | if (self.getOs() == builtin.os) { | 587 | if (self.getOs() == builtin.os) { |
lib/std/thread.zig+1-1| ... | @@ -344,7 +344,7 @@ pub const Thread = struct { | ... | @@ -344,7 +344,7 @@ pub const Thread = struct { |
| 344 | pub fn cpuCount() CpuCountError!usize { | 344 | pub fn cpuCount() CpuCountError!usize { |
| 345 | if (builtin.os == .linux) { | 345 | if (builtin.os == .linux) { |
| 346 | const cpu_set = try os.sched_getaffinity(0); | 346 | const cpu_set = try os.sched_getaffinity(0); |
| 347 | return usize(os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast | 347 | return @as(usize, os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast |
| 348 | } | 348 | } |
| 349 | if (builtin.os == .windows) { | 349 | if (builtin.os == .windows) { |
| 350 | var system_info: windows.SYSTEM_INFO = undefined; | 350 | var system_info: windows.SYSTEM_INFO = undefined; |
lib/std/time.zig+4-4| ... | @@ -38,7 +38,7 @@ pub fn milliTimestamp() u64 { | ... | @@ -38,7 +38,7 @@ pub fn milliTimestamp() u64 { |
| 38 | const hns_per_ms = (ns_per_s / 100) / ms_per_s; | 38 | const hns_per_ms = (ns_per_s / 100) / ms_per_s; |
| 39 | const epoch_adj = epoch.windows * ms_per_s; | 39 | const epoch_adj = epoch.windows * ms_per_s; |
| 40 | 40 | ||
| 41 | const ft64 = (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime; | 41 | const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime; |
| 42 | return @divFloor(ft64, hns_per_ms) - -epoch_adj; | 42 | return @divFloor(ft64, hns_per_ms) - -epoch_adj; |
| 43 | } | 43 | } |
| 44 | if (builtin.os == .wasi and !builtin.link_libc) { | 44 | if (builtin.os == .wasi and !builtin.link_libc) { |
| ... | @@ -142,10 +142,10 @@ pub const Timer = struct { | ... | @@ -142,10 +142,10 @@ pub const Timer = struct { |
| 142 | // seccomp is going to block us it will at least do so consistently | 142 | // seccomp is going to block us it will at least do so consistently |
| 143 | var ts: os.timespec = undefined; | 143 | var ts: os.timespec = undefined; |
| 144 | os.clock_getres(monotonic_clock_id, &ts) catch return error.TimerUnsupported; | 144 | os.clock_getres(monotonic_clock_id, &ts) catch return error.TimerUnsupported; |
| 145 | self.resolution = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec); | 145 | self.resolution = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec); |
| 146 | 146 | ||
| 147 | os.clock_gettime(monotonic_clock_id, &ts) catch return error.TimerUnsupported; | 147 | os.clock_gettime(monotonic_clock_id, &ts) catch return error.TimerUnsupported; |
| 148 | self.start_time = @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec); | 148 | self.start_time = @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec); |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | return self; | 151 | return self; |
| ... | @@ -185,7 +185,7 @@ pub const Timer = struct { | ... | @@ -185,7 +185,7 @@ pub const Timer = struct { |
| 185 | } | 185 | } |
| 186 | var ts: os.timespec = undefined; | 186 | var ts: os.timespec = undefined; |
| 187 | os.clock_gettime(monotonic_clock_id, &ts) catch unreachable; | 187 | os.clock_gettime(monotonic_clock_id, &ts) catch unreachable; |
| 188 | return @intCast(u64, ts.tv_sec) * u64(ns_per_s) + @intCast(u64, ts.tv_nsec); | 188 | return @intCast(u64, ts.tv_sec) * @as(u64, ns_per_s) + @intCast(u64, ts.tv_nsec); |
| 189 | } | 189 | } |
| 190 | }; | 190 | }; |
| 191 | 191 |
lib/std/unicode.zig+13-13| ... | @@ -7,10 +7,10 @@ const mem = std.mem; | ... | @@ -7,10 +7,10 @@ const mem = std.mem; |
| 7 | /// Returns how many bytes the UTF-8 representation would require | 7 | /// Returns how many bytes the UTF-8 representation would require |
| 8 | /// for the given codepoint. | 8 | /// for the given codepoint. |
| 9 | pub fn utf8CodepointSequenceLength(c: u32) !u3 { | 9 | pub fn utf8CodepointSequenceLength(c: u32) !u3 { |
| 10 | if (c < 0x80) return u3(1); | 10 | if (c < 0x80) return @as(u3, 1); |
| 11 | if (c < 0x800) return u3(2); | 11 | if (c < 0x800) return @as(u3, 2); |
| 12 | if (c < 0x10000) return u3(3); | 12 | if (c < 0x10000) return @as(u3, 3); |
| 13 | if (c < 0x110000) return u3(4); | 13 | if (c < 0x110000) return @as(u3, 4); |
| 14 | return error.CodepointTooLarge; | 14 | return error.CodepointTooLarge; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| ... | @@ -18,10 +18,10 @@ pub fn utf8CodepointSequenceLength(c: u32) !u3 { | ... | @@ -18,10 +18,10 @@ pub fn utf8CodepointSequenceLength(c: u32) !u3 { |
| 18 | /// returns a number 1-4 indicating the total length of the codepoint in bytes. | 18 | /// returns a number 1-4 indicating the total length of the codepoint in bytes. |
| 19 | /// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte. | 19 | /// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte. |
| 20 | pub fn utf8ByteSequenceLength(first_byte: u8) !u3 { | 20 | pub fn utf8ByteSequenceLength(first_byte: u8) !u3 { |
| 21 | if (first_byte < 0b10000000) return u3(1); | 21 | if (first_byte < 0b10000000) return @as(u3, 1); |
| 22 | if (first_byte & 0b11100000 == 0b11000000) return u3(2); | 22 | if (first_byte & 0b11100000 == 0b11000000) return @as(u3, 2); |
| 23 | if (first_byte & 0b11110000 == 0b11100000) return u3(3); | 23 | if (first_byte & 0b11110000 == 0b11100000) return @as(u3, 3); |
| 24 | if (first_byte & 0b11111000 == 0b11110000) return u3(4); | 24 | if (first_byte & 0b11111000 == 0b11110000) return @as(u3, 4); |
| 25 | return error.Utf8InvalidStartByte; | 25 | return error.Utf8InvalidStartByte; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| ... | @@ -68,7 +68,7 @@ const Utf8DecodeError = Utf8Decode2Error || Utf8Decode3Error || Utf8Decode4Error | ... | @@ -68,7 +68,7 @@ const Utf8DecodeError = Utf8Decode2Error || Utf8Decode3Error || Utf8Decode4Error |
| 68 | /// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function. | 68 | /// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function. |
| 69 | pub fn utf8Decode(bytes: []const u8) Utf8DecodeError!u32 { | 69 | pub fn utf8Decode(bytes: []const u8) Utf8DecodeError!u32 { |
| 70 | return switch (bytes.len) { | 70 | return switch (bytes.len) { |
| 71 | 1 => u32(bytes[0]), | 71 | 1 => @as(u32, bytes[0]), |
| 72 | 2 => utf8Decode2(bytes), | 72 | 2 => utf8Decode2(bytes), |
| 73 | 3 => utf8Decode3(bytes), | 73 | 3 => utf8Decode3(bytes), |
| 74 | 4 => utf8Decode4(bytes), | 74 | 4 => utf8Decode4(bytes), |
| ... | @@ -226,7 +226,7 @@ pub const Utf8Iterator = struct { | ... | @@ -226,7 +226,7 @@ pub const Utf8Iterator = struct { |
| 226 | const slice = it.nextCodepointSlice() orelse return null; | 226 | const slice = it.nextCodepointSlice() orelse return null; |
| 227 | 227 | ||
| 228 | switch (slice.len) { | 228 | switch (slice.len) { |
| 229 | 1 => return u32(slice[0]), | 229 | 1 => return @as(u32, slice[0]), |
| 230 | 2 => return utf8Decode2(slice) catch unreachable, | 230 | 2 => return utf8Decode2(slice) catch unreachable, |
| 231 | 3 => return utf8Decode3(slice) catch unreachable, | 231 | 3 => return utf8Decode3(slice) catch unreachable, |
| 232 | 4 => return utf8Decode4(slice) catch unreachable, | 232 | 4 => return utf8Decode4(slice) catch unreachable, |
| ... | @@ -250,15 +250,15 @@ pub const Utf16LeIterator = struct { | ... | @@ -250,15 +250,15 @@ pub const Utf16LeIterator = struct { |
| 250 | assert(it.i <= it.bytes.len); | 250 | assert(it.i <= it.bytes.len); |
| 251 | if (it.i == it.bytes.len) return null; | 251 | if (it.i == it.bytes.len) return null; |
| 252 | const c0: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); | 252 | const c0: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); |
| 253 | if (c0 & ~u32(0x03ff) == 0xd800) { | 253 | if (c0 & ~@as(u32, 0x03ff) == 0xd800) { |
| 254 | // surrogate pair | 254 | // surrogate pair |
| 255 | it.i += 2; | 255 | it.i += 2; |
| 256 | if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf; | 256 | if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf; |
| 257 | const c1: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); | 257 | const c1: u32 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); |
| 258 | if (c1 & ~u32(0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf; | 258 | if (c1 & ~@as(u32, 0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf; |
| 259 | it.i += 2; | 259 | it.i += 2; |
| 260 | return 0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff)); | 260 | return 0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff)); |
| 261 | } else if (c0 & ~u32(0x03ff) == 0xdc00) { | 261 | } else if (c0 & ~@as(u32, 0x03ff) == 0xdc00) { |
| 262 | return error.UnexpectedSecondSurrogateHalf; | 262 | return error.UnexpectedSecondSurrogateHalf; |
| 263 | } else { | 263 | } else { |
| 264 | it.i += 2; | 264 | it.i += 2; |
lib/std/valgrind.zig+1-1| ... | @@ -76,7 +76,7 @@ pub const ClientRequest = extern enum { | ... | @@ -76,7 +76,7 @@ pub const ClientRequest = extern enum { |
| 76 | InnerThreads = 6402, | 76 | InnerThreads = 6402, |
| 77 | }; | 77 | }; |
| 78 | pub fn ToolBase(base: [2]u8) u32 { | 78 | pub fn ToolBase(base: [2]u8) u32 { |
| 79 | return (u32(base[0] & 0xff) << 24) | (u32(base[1] & 0xff) << 16); | 79 | return (@as(u32, base[0] & 0xff) << 24) | (@as(u32, base[1] & 0xff) << 16); |
| 80 | } | 80 | } |
| 81 | pub fn IsTool(base: [2]u8, code: usize) bool { | 81 | pub fn IsTool(base: [2]u8, code: usize) bool { |
| 82 | return ToolBase(base) == (code & 0xffff0000); | 82 | return ToolBase(base) == (code & 0xffff0000); |
lib/std/zig/parse_string_literal.zig+1-1| ... | @@ -19,7 +19,7 @@ pub fn parseStringLiteral( | ... | @@ -19,7 +19,7 @@ pub fn parseStringLiteral( |
| 19 | bytes: []const u8, | 19 | bytes: []const u8, |
| 20 | bad_index: *usize, // populated if error.InvalidCharacter is returned | 20 | bad_index: *usize, // populated if error.InvalidCharacter is returned |
| 21 | ) ParseStringLiteralError![]u8 { | 21 | ) ParseStringLiteralError![]u8 { |
| 22 | const first_index = if (bytes[0] == 'c') usize(2) else usize(1); | 22 | const first_index = if (bytes[0] == 'c') @as(usize, 2) else @as(usize, 1); |
| 23 | assert(bytes[bytes.len - 1] == '"'); | 23 | assert(bytes[bytes.len - 1] == '"'); |
| 24 | 24 | ||
| 25 | var list = std.ArrayList(u8).init(allocator); | 25 | var list = std.ArrayList(u8).init(allocator); |
lib/std/zig/parser_test.zig+1-1| ... | @@ -37,7 +37,7 @@ test "zig fmt: while else err prong with no block" { | ... | @@ -37,7 +37,7 @@ test "zig fmt: while else err prong with no block" { |
| 37 | \\test "" { | 37 | \\test "" { |
| 38 | \\ const result = while (returnError()) |value| { | 38 | \\ const result = while (returnError()) |value| { |
| 39 | \\ break value; | 39 | \\ break value; |
| 40 | \\ } else |err| i32(2); | 40 | \\ } else |err| @as(i32, 2); |
| 41 | \\ expect(result == 2); | 41 | \\ expect(result == 2); |
| 42 | \\} | 42 | \\} |
| 43 | \\ | 43 | \\ |
lib/std/zig/render.zig+3-3| ... | @@ -410,8 +410,8 @@ fn renderExpression( | ... | @@ -410,8 +410,8 @@ fn renderExpression( |
| 410 | switch (prefix_op_node.op) { | 410 | switch (prefix_op_node.op) { |
| 411 | ast.Node.PrefixOp.Op.PtrType => |ptr_info| { | 411 | ast.Node.PrefixOp.Op.PtrType => |ptr_info| { |
| 412 | const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) { | 412 | const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) { |
| 413 | Token.Id.AsteriskAsterisk => usize(1), | 413 | Token.Id.AsteriskAsterisk => @as(usize, 1), |
| 414 | else => usize(0), | 414 | else => @as(usize, 0), |
| 415 | }; | 415 | }; |
| 416 | try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // * | 416 | try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // * |
| 417 | if (ptr_info.allowzero_token) |allowzero_token| { | 417 | if (ptr_info.allowzero_token) |allowzero_token| { |
| ... | @@ -2097,7 +2097,7 @@ fn renderTokenOffset( | ... | @@ -2097,7 +2097,7 @@ fn renderTokenOffset( |
| 2097 | 2097 | ||
| 2098 | while (true) { | 2098 | while (true) { |
| 2099 | assert(loc.line != 0); | 2099 | assert(loc.line != 0); |
| 2100 | const newline_count = if (loc.line == 1) u8(1) else u8(2); | 2100 | const newline_count = if (loc.line == 1) @as(u8, 1) else @as(u8, 2); |
| 2101 | try stream.writeByteNTimes('\n', newline_count); | 2101 | try stream.writeByteNTimes('\n', newline_count); |
| 2102 | try stream.writeByteNTimes(' ', indent); | 2102 | try stream.writeByteNTimes(' ', indent); |
| 2103 | try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")); | 2103 | try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")); |
lib/std/zig/tokenizer.zig+1-1| ... | @@ -350,7 +350,7 @@ pub const Tokenizer = struct { | ... | @@ -350,7 +350,7 @@ pub const Tokenizer = struct { |
| 350 | }; | 350 | }; |
| 351 | } else { | 351 | } else { |
| 352 | // Skip the UTF-8 BOM if present | 352 | // Skip the UTF-8 BOM if present |
| 353 | const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else usize(0); | 353 | const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else @as(usize, 0); |
| 354 | return Tokenizer{ | 354 | return Tokenizer{ |
| 355 | .buffer = buffer, | 355 | .buffer = buffer, |
| 356 | .index = src_start, | 356 | .index = src_start, |
src-self-hosted/stage1.zig+1-1| ... | @@ -224,7 +224,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void { | ... | @@ -224,7 +224,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void { |
| 224 | } | 224 | } |
| 225 | if (flags.present("check")) { | 225 | if (flags.present("check")) { |
| 226 | const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree); | 226 | const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree); |
| 227 | const code = if (anything_changed) u8(1) else u8(0); | 227 | const code = if (anything_changed) @as(u8, 1) else @as(u8, 0); |
| 228 | process.exit(code); | 228 | process.exit(code); |
| 229 | } | 229 | } |
| 230 | 230 |
src-self-hosted/translate_c.zig+11-7| ... | @@ -123,7 +123,7 @@ const Context = struct { | ... | @@ -123,7 +123,7 @@ const Context = struct { |
| 123 | fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 { | 123 | fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 { |
| 124 | const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc); | 124 | const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc); |
| 125 | const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc); | 125 | const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc); |
| 126 | const filename = if (filename_c) |s| try c.str(s) else ([]const u8)("(no file)"); | 126 | const filename = if (filename_c) |s| try c.str(s) else @as([]const u8, "(no file)"); |
| 127 | 127 | ||
| 128 | const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc); | 128 | const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc); |
| 129 | const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc); | 129 | const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc); |
| ... | @@ -774,12 +774,14 @@ fn transCCast( | ... | @@ -774,12 +774,14 @@ fn transCCast( |
| 774 | if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type)) | 774 | if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type)) |
| 775 | return transCPtrCast(rp, loc, dst_type, src_type, expr); | 775 | return transCPtrCast(rp, loc, dst_type, src_type, expr); |
| 776 | if (cIsUnsignedInteger(dst_type) and qualTypeIsPtr(src_type)) { | 776 | if (cIsUnsignedInteger(dst_type) and qualTypeIsPtr(src_type)) { |
| 777 | const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc)); | 777 | const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as"); |
| 778 | try cast_node.params.push(try transQualType(rp, dst_type, loc)); | ||
| 779 | _ = try appendToken(rp.c, .Comma, ","); | ||
| 778 | const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt"); | 780 | const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt"); |
| 779 | try builtin_node.params.push(expr); | 781 | try builtin_node.params.push(expr); |
| 780 | builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | 782 | builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")"); |
| 781 | try cast_node.op.Call.params.push(&builtin_node.base); | 783 | try cast_node.params.push(&builtin_node.base); |
| 782 | cast_node.rtoken = try appendToken(rp.c, .RParen, ")"); | 784 | cast_node.rparen_token = try appendToken(rp.c, .RParen, ")"); |
| 783 | return &cast_node.base; | 785 | return &cast_node.base; |
| 784 | } | 786 | } |
| 785 | if (cIsUnsignedInteger(src_type) and qualTypeIsPtr(dst_type)) { | 787 | if (cIsUnsignedInteger(src_type) and qualTypeIsPtr(dst_type)) { |
| ... | @@ -793,9 +795,11 @@ fn transCCast( | ... | @@ -793,9 +795,11 @@ fn transCCast( |
| 793 | // TODO: maybe widen to increase size | 795 | // TODO: maybe widen to increase size |
| 794 | // TODO: maybe bitcast to change sign | 796 | // TODO: maybe bitcast to change sign |
| 795 | // TODO: maybe truncate to reduce size | 797 | // TODO: maybe truncate to reduce size |
| 796 | const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc)); | 798 | const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as"); |
| 797 | try cast_node.op.Call.params.push(expr); | 799 | try cast_node.params.push(try transQualType(rp, dst_type, loc)); |
| 798 | cast_node.rtoken = try appendToken(rp.c, .RParen, ")"); | 800 | _ = try appendToken(rp.c, .Comma, ","); |
| 801 | try cast_node.params.push(expr); | ||
| 802 | cast_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | ||
| 799 | return &cast_node.base; | 803 | return &cast_node.base; |
| 800 | } | 804 | } |
| 801 | 805 |
src/all_types.hpp+17-8| ... | @@ -48,6 +48,7 @@ struct ResultLoc; | ... | @@ -48,6 +48,7 @@ struct ResultLoc; |
| 48 | struct ResultLocPeer; | 48 | struct ResultLocPeer; |
| 49 | struct ResultLocPeerParent; | 49 | struct ResultLocPeerParent; |
| 50 | struct ResultLocBitCast; | 50 | struct ResultLocBitCast; |
| 51 | struct ResultLocCast; | ||
| 51 | struct ResultLocReturn; | 52 | struct ResultLocReturn; |
| 52 | 53 | ||
| 53 | enum PtrLen { | 54 | enum PtrLen { |
| ... | @@ -1691,6 +1692,7 @@ enum BuiltinFnId { | ... | @@ -1691,6 +1692,7 @@ enum BuiltinFnId { |
| 1691 | BuiltinFnIdFrameType, | 1692 | BuiltinFnIdFrameType, |
| 1692 | BuiltinFnIdFrameHandle, | 1693 | BuiltinFnIdFrameHandle, |
| 1693 | BuiltinFnIdFrameSize, | 1694 | BuiltinFnIdFrameSize, |
| 1695 | BuiltinFnIdAs, | ||
| 1694 | }; | 1696 | }; |
| 1695 | 1697 | ||
| 1696 | struct BuiltinFnEntry { | 1698 | struct BuiltinFnEntry { |
| ... | @@ -3458,6 +3460,13 @@ struct IrInstructionPtrCastGen { | ... | @@ -3458,6 +3460,13 @@ struct IrInstructionPtrCastGen { |
| 3458 | bool safety_check_on; | 3460 | bool safety_check_on; |
| 3459 | }; | 3461 | }; |
| 3460 | 3462 | ||
| 3463 | struct IrInstructionImplicitCast { | ||
| 3464 | IrInstruction base; | ||
| 3465 | |||
| 3466 | IrInstruction *operand; | ||
| 3467 | ResultLocCast *result_loc_cast; | ||
| 3468 | }; | ||
| 3469 | |||
| 3461 | struct IrInstructionBitCastSrc { | 3470 | struct IrInstructionBitCastSrc { |
| 3462 | IrInstruction base; | 3471 | IrInstruction base; |
| 3463 | 3472 | ||
| ... | @@ -3823,14 +3832,6 @@ struct IrInstructionEndExpr { | ... | @@ -3823,14 +3832,6 @@ struct IrInstructionEndExpr { |
| 3823 | ResultLoc *result_loc; | 3832 | ResultLoc *result_loc; |
| 3824 | }; | 3833 | }; |
| 3825 | 3834 | ||
| 3826 | struct IrInstructionImplicitCast { | ||
| 3827 | IrInstruction base; | ||
| 3828 | |||
| 3829 | IrInstruction *dest_type; | ||
| 3830 | IrInstruction *target; | ||
| 3831 | ResultLoc *result_loc; | ||
| 3832 | }; | ||
| 3833 | |||
| 3834 | // This one is for writing through the result pointer. | 3835 | // This one is for writing through the result pointer. |
| 3835 | struct IrInstructionResolveResult { | 3836 | struct IrInstructionResolveResult { |
| 3836 | IrInstruction base; | 3837 | IrInstruction base; |
| ... | @@ -3928,6 +3929,7 @@ enum ResultLocId { | ... | @@ -3928,6 +3929,7 @@ enum ResultLocId { |
| 3928 | ResultLocIdPeerParent, | 3929 | ResultLocIdPeerParent, |
| 3929 | ResultLocIdInstruction, | 3930 | ResultLocIdInstruction, |
| 3930 | ResultLocIdBitCast, | 3931 | ResultLocIdBitCast, |
| 3932 | ResultLocIdCast, | ||
| 3931 | }; | 3933 | }; |
| 3932 | 3934 | ||
| 3933 | // Additions to this struct may need to be handled in | 3935 | // Additions to this struct may need to be handled in |
| ... | @@ -3995,6 +3997,13 @@ struct ResultLocBitCast { | ... | @@ -3995,6 +3997,13 @@ struct ResultLocBitCast { |
| 3995 | ResultLoc *parent; | 3997 | ResultLoc *parent; |
| 3996 | }; | 3998 | }; |
| 3997 | 3999 | ||
| 4000 | // The source_instruction is the destination type | ||
| 4001 | struct ResultLocCast { | ||
| 4002 | ResultLoc base; | ||
| 4003 | |||
| 4004 | ResultLoc *parent; | ||
| 4005 | }; | ||
| 4006 | |||
| 3998 | static const size_t slice_ptr_index = 0; | 4007 | static const size_t slice_ptr_index = 0; |
| 3999 | static const size_t slice_len_index = 1; | 4008 | static const size_t slice_len_index = 1; |
| 4000 | 4009 |
src/codegen.cpp+1| ... | @@ -8070,6 +8070,7 @@ static void define_builtin_fns(CodeGen *g) { | ... | @@ -8070,6 +8070,7 @@ static void define_builtin_fns(CodeGen *g) { |
| 8070 | create_builtin_fn(g, BuiltinFnIdFrameType, "Frame", 1); | 8070 | create_builtin_fn(g, BuiltinFnIdFrameType, "Frame", 1); |
| 8071 | create_builtin_fn(g, BuiltinFnIdFrameAddress, "frameAddress", 0); | 8071 | create_builtin_fn(g, BuiltinFnIdFrameAddress, "frameAddress", 0); |
| 8072 | create_builtin_fn(g, BuiltinFnIdFrameSize, "frameSize", 1); | 8072 | create_builtin_fn(g, BuiltinFnIdFrameSize, "frameSize", 1); |
| 8073 | create_builtin_fn(g, BuiltinFnIdAs, "as", 2); | ||
| 8073 | } | 8074 | } |
| 8074 | 8075 | ||
| 8075 | static const char *bool_to_str(bool b) { | 8076 | static const char *bool_to_str(bool b) { |
src/ir.cpp+180-66| ... | @@ -200,6 +200,8 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -200,6 +200,8 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo |
| 200 | static void ir_reset_result(ResultLoc *result_loc); | 200 | static void ir_reset_result(ResultLoc *result_loc); |
| 201 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, | 201 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, |
| 202 | Scope *scope, AstNode *source_node, Buf *out_bare_name); | 202 | Scope *scope, AstNode *source_node, Buf *out_bare_name); |
| 203 | static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type, | ||
| 204 | ResultLoc *parent_result_loc); | ||
| 203 | 205 | ||
| 204 | static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { | 206 | static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { |
| 205 | assert(get_src_ptr_type(const_val->type) != nullptr); | 207 | assert(get_src_ptr_type(const_val->type) != nullptr); |
| ... | @@ -2766,6 +2768,18 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -2766,6 +2768,18 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2766 | return &instruction->base; | 2768 | return &instruction->base; |
| 2767 | } | 2769 | } |
| 2768 | 2770 | ||
| 2771 | static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, | ||
| 2772 | IrInstruction *operand, ResultLocCast *result_loc_cast) | ||
| 2773 | { | ||
| 2774 | IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node); | ||
| 2775 | instruction->operand = operand; | ||
| 2776 | instruction->result_loc_cast = result_loc_cast; | ||
| 2777 | |||
| 2778 | ir_ref_instruction(operand, irb->current_basic_block); | ||
| 2779 | |||
| 2780 | return &instruction->base; | ||
| 2781 | } | ||
| 2782 | |||
| 2769 | static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node, | 2783 | static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2770 | IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast) | 2784 | IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast) |
| 2771 | { | 2785 | { |
| ... | @@ -3063,20 +3077,6 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -3063,20 +3077,6 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode |
| 3063 | return &instruction->base; | 3077 | return &instruction->base; |
| 3064 | } | 3078 | } |
| 3065 | 3079 | ||
| 3066 | static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, | ||
| 3067 | IrInstruction *dest_type, IrInstruction *target, ResultLoc *result_loc) | ||
| 3068 | { | ||
| 3069 | IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node); | ||
| 3070 | instruction->dest_type = dest_type; | ||
| 3071 | instruction->target = target; | ||
| 3072 | instruction->result_loc = result_loc; | ||
| 3073 | |||
| 3074 | ir_ref_instruction(dest_type, irb->current_basic_block); | ||
| 3075 | ir_ref_instruction(target, irb->current_basic_block); | ||
| 3076 | |||
| 3077 | return &instruction->base; | ||
| 3078 | } | ||
| 3079 | |||
| 3080 | static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node, | 3080 | static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3081 | ResultLoc *result_loc, IrInstruction *ty) | 3081 | ResultLoc *result_loc, IrInstruction *ty) |
| 3082 | { | 3082 | { |
| ... | @@ -5374,6 +5374,24 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5374,6 +5374,24 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5374 | IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast); | 5374 | IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast); |
| 5375 | return ir_lval_wrap(irb, scope, bitcast, lval, result_loc); | 5375 | return ir_lval_wrap(irb, scope, bitcast, lval, result_loc); |
| 5376 | } | 5376 | } |
| 5377 | case BuiltinFnIdAs: | ||
| 5378 | { | ||
| 5379 | AstNode *dest_type_node = node->data.fn_call_expr.params.at(0); | ||
| 5380 | IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope); | ||
| 5381 | if (dest_type == irb->codegen->invalid_instruction) | ||
| 5382 | return dest_type; | ||
| 5383 | |||
| 5384 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc); | ||
| 5385 | |||
| 5386 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | ||
| 5387 | IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, | ||
| 5388 | &result_loc_cast->base); | ||
| 5389 | if (arg1_value == irb->codegen->invalid_instruction) | ||
| 5390 | return arg1_value; | ||
| 5391 | |||
| 5392 | IrInstruction *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast); | ||
| 5393 | return ir_lval_wrap(irb, scope, result, lval, result_loc); | ||
| 5394 | } | ||
| 5377 | case BuiltinFnIdIntToPtr: | 5395 | case BuiltinFnIdIntToPtr: |
| 5378 | { | 5396 | { |
| 5379 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 5397 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| ... | @@ -6214,6 +6232,20 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *allo | ... | @@ -6214,6 +6232,20 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *allo |
| 6214 | return result_loc_var; | 6232 | return result_loc_var; |
| 6215 | } | 6233 | } |
| 6216 | 6234 | ||
| 6235 | static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type, | ||
| 6236 | ResultLoc *parent_result_loc) | ||
| 6237 | { | ||
| 6238 | ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1); | ||
| 6239 | result_loc_cast->base.id = ResultLocIdCast; | ||
| 6240 | result_loc_cast->base.source_instruction = dest_type; | ||
| 6241 | ir_ref_instruction(dest_type, irb->current_basic_block); | ||
| 6242 | result_loc_cast->parent = parent_result_loc; | ||
| 6243 | |||
| 6244 | ir_build_reset_result(irb, dest_type->scope, dest_type->source_node, &result_loc_cast->base); | ||
| 6245 | |||
| 6246 | return result_loc_cast; | ||
| 6247 | } | ||
| 6248 | |||
| 6217 | static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var, | 6249 | static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| 6218 | IrInstruction *init, const char *name_hint, IrInstruction *is_comptime) | 6250 | IrInstruction *init, const char *name_hint, IrInstruction *is_comptime) |
| 6219 | { | 6251 | { |
| ... | @@ -6282,7 +6314,15 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -6282,7 +6314,15 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 6282 | 6314 | ||
| 6283 | // Create a result location for the initialization expression. | 6315 | // Create a result location for the initialization expression. |
| 6284 | ResultLocVar *result_loc_var = ir_build_var_result_loc(irb, alloca, var); | 6316 | ResultLocVar *result_loc_var = ir_build_var_result_loc(irb, alloca, var); |
| 6285 | ResultLoc *init_result_loc = (type_instruction == nullptr) ? &result_loc_var->base : nullptr; | 6317 | ResultLoc *init_result_loc; |
| 6318 | ResultLocCast *result_loc_cast; | ||
| 6319 | if (type_instruction != nullptr) { | ||
| 6320 | result_loc_cast = ir_build_cast_result_loc(irb, type_instruction, &result_loc_var->base); | ||
| 6321 | init_result_loc = &result_loc_cast->base; | ||
| 6322 | } else { | ||
| 6323 | result_loc_cast = nullptr; | ||
| 6324 | init_result_loc = &result_loc_var->base; | ||
| 6325 | } | ||
| 6286 | 6326 | ||
| 6287 | Scope *init_scope = is_comptime_scalar ? | 6327 | Scope *init_scope = is_comptime_scalar ? |
| 6288 | create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope; | 6328 | create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope; |
| ... | @@ -6298,9 +6338,9 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -6298,9 +6338,9 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 6298 | if (init_value == irb->codegen->invalid_instruction) | 6338 | if (init_value == irb->codegen->invalid_instruction) |
| 6299 | return irb->codegen->invalid_instruction; | 6339 | return irb->codegen->invalid_instruction; |
| 6300 | 6340 | ||
| 6301 | if (type_instruction != nullptr) { | 6341 | if (result_loc_cast != nullptr) { |
| 6302 | IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, node, type_instruction, init_value, | 6342 | IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node, |
| 6303 | &result_loc_var->base); | 6343 | init_value, result_loc_cast); |
| 6304 | ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base); | 6344 | ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base); |
| 6305 | } | 6345 | } |
| 6306 | 6346 | ||
| ... | @@ -9571,7 +9611,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -9571,7 +9611,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 9571 | } | 9611 | } |
| 9572 | 9612 | ||
| 9573 | ir_add_error(ira, instruction, | 9613 | ir_add_error(ira, instruction, |
| 9574 | buf_sprintf("%s value %s cannot be implicitly casted to type '%s'", | 9614 | buf_sprintf("%s value %s cannot be coerced to type '%s'", |
| 9575 | num_lit_str, | 9615 | num_lit_str, |
| 9576 | buf_ptr(val_buf), | 9616 | buf_ptr(val_buf), |
| 9577 | buf_ptr(&other_type->name))); | 9617 | buf_ptr(&other_type->name))); |
| ... | @@ -13026,8 +13066,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -13026,8 +13066,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13026 | return ira->codegen->invalid_instruction; | 13066 | return ira->codegen->invalid_instruction; |
| 13027 | } | 13067 | } |
| 13028 | 13068 | ||
| 13029 | static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type, | 13069 | static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *source_instr, |
| 13030 | ResultLoc *result_loc) | 13070 | IrInstruction *value, ZigType *expected_type, ResultLoc *result_loc) |
| 13031 | { | 13071 | { |
| 13032 | assert(value); | 13072 | assert(value); |
| 13033 | assert(value != ira->codegen->invalid_instruction); | 13073 | assert(value != ira->codegen->invalid_instruction); |
| ... | @@ -13041,11 +13081,11 @@ static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction | ... | @@ -13041,11 +13081,11 @@ static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction |
| 13041 | if (value->value.type->id == ZigTypeIdUnreachable) | 13081 | if (value->value.type->id == ZigTypeIdUnreachable) |
| 13042 | return value; | 13082 | return value; |
| 13043 | 13083 | ||
| 13044 | return ir_analyze_cast(ira, value, expected_type, value, result_loc); | 13084 | return ir_analyze_cast(ira, source_instr, expected_type, value, result_loc); |
| 13045 | } | 13085 | } |
| 13046 | 13086 | ||
| 13047 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) { | 13087 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) { |
| 13048 | return ir_implicit_cast_with_result(ira, value, expected_type, nullptr); | 13088 | return ir_implicit_cast_with_result(ira, value, value, expected_type, nullptr); |
| 13049 | } | 13089 | } |
| 13050 | 13090 | ||
| 13051 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr, | 13091 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr, |
| ... | @@ -15435,6 +15475,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -15435,6 +15475,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe |
| 15435 | case ResultLocIdNone: | 15475 | case ResultLocIdNone: |
| 15436 | case ResultLocIdVar: | 15476 | case ResultLocIdVar: |
| 15437 | case ResultLocIdBitCast: | 15477 | case ResultLocIdBitCast: |
| 15478 | case ResultLocIdCast: | ||
| 15438 | return nullptr; | 15479 | return nullptr; |
| 15439 | case ResultLocIdInstruction: | 15480 | case ResultLocIdInstruction: |
| 15440 | return result_loc->source_instruction->child->value.type; | 15481 | return result_loc->source_instruction->child->value.type; |
| ... | @@ -15489,6 +15530,7 @@ static bool ir_result_has_type(ResultLoc *result_loc) { | ... | @@ -15489,6 +15530,7 @@ static bool ir_result_has_type(ResultLoc *result_loc) { |
| 15489 | case ResultLocIdReturn: | 15530 | case ResultLocIdReturn: |
| 15490 | case ResultLocIdInstruction: | 15531 | case ResultLocIdInstruction: |
| 15491 | case ResultLocIdBitCast: | 15532 | case ResultLocIdBitCast: |
| 15533 | case ResultLocIdCast: | ||
| 15492 | return true; | 15534 | return true; |
| 15493 | case ResultLocIdVar: | 15535 | case ResultLocIdVar: |
| 15494 | return reinterpret_cast<ResultLocVar *>(result_loc)->var->decl_node->data.variable_declaration.type != nullptr; | 15536 | return reinterpret_cast<ResultLocVar *>(result_loc)->var->decl_node->data.variable_declaration.type != nullptr; |
| ... | @@ -15496,6 +15538,26 @@ static bool ir_result_has_type(ResultLoc *result_loc) { | ... | @@ -15496,6 +15538,26 @@ static bool ir_result_has_type(ResultLoc *result_loc) { |
| 15496 | zig_unreachable(); | 15538 | zig_unreachable(); |
| 15497 | } | 15539 | } |
| 15498 | 15540 | ||
| 15541 | static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr, | ||
| 15542 | ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime) | ||
| 15543 | { | ||
| 15544 | Error err; | ||
| 15545 | |||
| 15546 | IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); | ||
| 15547 | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown))) | ||
| 15548 | return ira->codegen->invalid_instruction; | ||
| 15549 | alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, | ||
| 15550 | PtrLenSingle, 0, 0, 0, false); | ||
| 15551 | set_up_result_loc_for_inferred_comptime(&alloca_gen->base); | ||
| 15552 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); | ||
| 15553 | if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) { | ||
| 15554 | fn_entry->alloca_gen_list.append(alloca_gen); | ||
| 15555 | } | ||
| 15556 | result_loc->written = true; | ||
| 15557 | result_loc->resolved_loc = &alloca_gen->base; | ||
| 15558 | return result_loc->resolved_loc; | ||
| 15559 | } | ||
| 15560 | |||
| 15499 | // when calling this function, at the callsite must check for result type noreturn and propagate it up | 15561 | // when calling this function, at the callsite must check for result type noreturn and propagate it up |
| 15500 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, | 15562 | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 15501 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime) | 15563 | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime) |
| ... | @@ -15518,19 +15580,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -15518,19 +15580,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 15518 | return nullptr; | 15580 | return nullptr; |
| 15519 | } | 15581 | } |
| 15520 | // need to return a result location and don't have one. use a stack allocation | 15582 | // need to return a result location and don't have one. use a stack allocation |
| 15521 | IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); | 15583 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, |
| 15522 | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown))) | 15584 | force_runtime, non_null_comptime); |
| 15523 | return ira->codegen->invalid_instruction; | ||
| 15524 | alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, | ||
| 15525 | PtrLenSingle, 0, 0, 0, false); | ||
| 15526 | set_up_result_loc_for_inferred_comptime(&alloca_gen->base); | ||
| 15527 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); | ||
| 15528 | if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) { | ||
| 15529 | fn_entry->alloca_gen_list.append(alloca_gen); | ||
| 15530 | } | ||
| 15531 | result_loc->written = true; | ||
| 15532 | result_loc->resolved_loc = &alloca_gen->base; | ||
| 15533 | return result_loc->resolved_loc; | ||
| 15534 | } | 15585 | } |
| 15535 | case ResultLocIdVar: { | 15586 | case ResultLocIdVar: { |
| 15536 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); | 15587 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); |
| ... | @@ -15668,6 +15719,67 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe | ... | @@ -15668,6 +15719,67 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 15668 | result_loc->resolved_loc = parent_result_loc; | 15719 | result_loc->resolved_loc = parent_result_loc; |
| 15669 | return result_loc->resolved_loc; | 15720 | return result_loc->resolved_loc; |
| 15670 | } | 15721 | } |
| 15722 | case ResultLocIdCast: { | ||
| 15723 | if (value != nullptr && value->value.special != ConstValSpecialRuntime) | ||
| 15724 | return nullptr; | ||
| 15725 | ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); | ||
| 15726 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); | ||
| 15727 | if (type_is_invalid(dest_type)) | ||
| 15728 | return ira->codegen->invalid_instruction; | ||
| 15729 | |||
| 15730 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, dest_type, value_type, | ||
| 15731 | result_cast->base.source_instruction->source_node, false); | ||
| 15732 | if (const_cast_result.id == ConstCastResultIdInvalid) | ||
| 15733 | return ira->codegen->invalid_instruction; | ||
| 15734 | if (const_cast_result.id != ConstCastResultIdOk) { | ||
| 15735 | // We will not be able to provide a result location for this value. Create | ||
| 15736 | // a new result location. | ||
| 15737 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, | ||
| 15738 | force_runtime, non_null_comptime); | ||
| 15739 | } | ||
| 15740 | |||
| 15741 | // In this case we can pointer cast the result location. | ||
| 15742 | IrInstruction *casted_value; | ||
| 15743 | if (value != nullptr) { | ||
| 15744 | casted_value = ir_implicit_cast(ira, value, dest_type); | ||
| 15745 | } else { | ||
| 15746 | casted_value = nullptr; | ||
| 15747 | } | ||
| 15748 | |||
| 15749 | if (casted_value != nullptr && type_is_invalid(casted_value->value.type)) { | ||
| 15750 | return casted_value; | ||
| 15751 | } | ||
| 15752 | |||
| 15753 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, | ||
| 15754 | dest_type, casted_value, force_runtime, non_null_comptime, true); | ||
| 15755 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || | ||
| 15756 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) | ||
| 15757 | { | ||
| 15758 | return parent_result_loc; | ||
| 15759 | } | ||
| 15760 | ZigType *parent_ptr_type = parent_result_loc->value.type; | ||
| 15761 | assert(parent_ptr_type->id == ZigTypeIdPointer); | ||
| 15762 | if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type, | ||
| 15763 | ResolveStatusAlignmentKnown))) | ||
| 15764 | { | ||
| 15765 | return ira->codegen->invalid_instruction; | ||
| 15766 | } | ||
| 15767 | uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type); | ||
| 15768 | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) { | ||
| 15769 | return ira->codegen->invalid_instruction; | ||
| 15770 | } | ||
| 15771 | if (!type_has_bits(value_type)) { | ||
| 15772 | parent_ptr_align = 0; | ||
| 15773 | } | ||
| 15774 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type, | ||
| 15775 | parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle, | ||
| 15776 | parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero); | ||
| 15777 | |||
| 15778 | result_loc->written = true; | ||
| 15779 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, | ||
| 15780 | ptr_type, result_cast->base.source_instruction, false); | ||
| 15781 | return result_loc->resolved_loc; | ||
| 15782 | } | ||
| 15671 | case ResultLocIdBitCast: { | 15783 | case ResultLocIdBitCast: { |
| 15672 | ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc); | 15784 | ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc); |
| 15673 | ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child); | 15785 | ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child); |
| ... | @@ -15790,18 +15902,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -15790,18 +15902,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 15790 | return result_loc; | 15902 | return result_loc; |
| 15791 | } | 15903 | } |
| 15792 | 15904 | ||
| 15793 | static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) { | ||
| 15794 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); | ||
| 15795 | if (type_is_invalid(dest_type)) | ||
| 15796 | return ira->codegen->invalid_instruction; | ||
| 15797 | |||
| 15798 | IrInstruction *target = instruction->target->child; | ||
| 15799 | if (type_is_invalid(target->value.type)) | ||
| 15800 | return ira->codegen->invalid_instruction; | ||
| 15801 | |||
| 15802 | return ir_implicit_cast_with_result(ira, target, dest_type, instruction->result_loc); | ||
| 15803 | } | ||
| 15804 | |||
| 15805 | static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstructionResolveResult *instruction) { | 15905 | static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstructionResolveResult *instruction) { |
| 15806 | ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child); | 15906 | ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child); |
| 15807 | if (type_is_invalid(implicit_elem_type)) | 15907 | if (type_is_invalid(implicit_elem_type)) |
| ... | @@ -15864,6 +15964,7 @@ static void ir_reset_result(ResultLoc *result_loc) { | ... | @@ -15864,6 +15964,7 @@ static void ir_reset_result(ResultLoc *result_loc) { |
| 15864 | case ResultLocIdNone: | 15964 | case ResultLocIdNone: |
| 15865 | case ResultLocIdInstruction: | 15965 | case ResultLocIdInstruction: |
| 15866 | case ResultLocIdBitCast: | 15966 | case ResultLocIdBitCast: |
| 15967 | case ResultLocIdCast: | ||
| 15867 | break; | 15968 | break; |
| 15868 | } | 15969 | } |
| 15869 | } | 15970 | } |
| ... | @@ -16903,25 +17004,14 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC | ... | @@ -16903,25 +17004,14 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC |
| 16903 | 17004 | ||
| 16904 | if (is_comptime || instr_is_comptime(fn_ref)) { | 17005 | if (is_comptime || instr_is_comptime(fn_ref)) { |
| 16905 | if (fn_ref->value.type->id == ZigTypeIdMetaType) { | 17006 | if (fn_ref->value.type->id == ZigTypeIdMetaType) { |
| 16906 | ZigType *dest_type = ir_resolve_type(ira, fn_ref); | 17007 | ZigType *ty = ir_resolve_type(ira, fn_ref); |
| 16907 | if (type_is_invalid(dest_type)) | 17008 | if (ty == nullptr) |
| 16908 | return ira->codegen->invalid_instruction; | ||
| 16909 | |||
| 16910 | size_t actual_param_count = call_instruction->arg_count; | ||
| 16911 | |||
| 16912 | if (actual_param_count != 1) { | ||
| 16913 | ir_add_error_node(ira, call_instruction->base.source_node, | ||
| 16914 | buf_sprintf("cast expression expects exactly one parameter")); | ||
| 16915 | return ira->codegen->invalid_instruction; | ||
| 16916 | } | ||
| 16917 | |||
| 16918 | IrInstruction *arg = call_instruction->args[0]->child; | ||
| 16919 | |||
| 16920 | IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg, | ||
| 16921 | call_instruction->result_loc); | ||
| 16922 | if (type_is_invalid(cast_instruction->value.type)) | ||
| 16923 | return ira->codegen->invalid_instruction; | 17009 | return ira->codegen->invalid_instruction; |
| 16924 | return ir_finish_anal(ira, cast_instruction); | 17010 | ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node, |
| 17011 | buf_sprintf("type '%s' not a function", buf_ptr(&ty->name))); | ||
| 17012 | add_error_note(ira->codegen, msg, call_instruction->base.source_node, | ||
| 17013 | buf_sprintf("use @as builtin for type coercion")); | ||
| 17014 | return ira->codegen->invalid_instruction; | ||
| 16925 | } else if (fn_ref->value.type->id == ZigTypeIdFn) { | 17015 | } else if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 16926 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); | 17016 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 16927 | ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type; | 17017 | ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type; |
| ... | @@ -17453,6 +17543,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh | ... | @@ -17453,6 +17543,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 17453 | if (peer_parent != nullptr && ir_result_has_type(peer_parent->parent)) { | 17543 | if (peer_parent != nullptr && ir_result_has_type(peer_parent->parent)) { |
| 17454 | if (peer_parent->parent->id == ResultLocIdReturn) { | 17544 | if (peer_parent->parent->id == ResultLocIdReturn) { |
| 17455 | resolved_type = ira->explicit_return_type; | 17545 | resolved_type = ira->explicit_return_type; |
| 17546 | } else if (peer_parent->parent->id == ResultLocIdCast) { | ||
| 17547 | resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child); | ||
| 17548 | if (type_is_invalid(resolved_type)) | ||
| 17549 | return ira->codegen->invalid_instruction; | ||
| 17456 | } else { | 17550 | } else { |
| 17457 | ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type; | 17551 | ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type; |
| 17458 | ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base); | 17552 | ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base); |
| ... | @@ -25958,6 +26052,26 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct | ... | @@ -25958,6 +26052,26 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 25958 | return ir_const_void(ira, &instruction->base); | 26052 | return ir_const_void(ira, &instruction->base); |
| 25959 | } | 26053 | } |
| 25960 | 26054 | ||
| 26055 | static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) { | ||
| 26056 | IrInstruction *operand = instruction->operand->child; | ||
| 26057 | if (type_is_invalid(operand->value.type)) | ||
| 26058 | return operand; | ||
| 26059 | |||
| 26060 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, | ||
| 26061 | &instruction->result_loc_cast->base, operand->value.type, operand, false, false, true); | ||
| 26062 | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) | ||
| 26063 | return result_loc; | ||
| 26064 | |||
| 26065 | if (instruction->result_loc_cast->parent->gen_instruction != nullptr) { | ||
| 26066 | return instruction->result_loc_cast->parent->gen_instruction; | ||
| 26067 | } | ||
| 26068 | |||
| 26069 | ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child); | ||
| 26070 | if (type_is_invalid(dest_type)) | ||
| 26071 | return ira->codegen->invalid_instruction; | ||
| 26072 | return ir_implicit_cast_with_result(ira, &instruction->base, operand, dest_type, nullptr); | ||
| 26073 | } | ||
| 26074 | |||
| 25961 | static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) { | 26075 | static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) { |
| 25962 | IrInstruction *operand = instruction->operand->child; | 26076 | IrInstruction *operand = instruction->operand->child; |
| 25963 | if (type_is_invalid(operand->value.type)) | 26077 | if (type_is_invalid(operand->value.type)) |
src/ir_print.cpp+15-8| ... | @@ -601,6 +601,12 @@ static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_ | ... | @@ -601,6 +601,12 @@ static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_ |
| 601 | fprintf(irp->f, ")"); | 601 | fprintf(irp->f, ")"); |
| 602 | } | 602 | } |
| 603 | 603 | ||
| 604 | static void ir_print_result_loc_cast(IrPrint *irp, ResultLocCast *result_loc_cast) { | ||
| 605 | fprintf(irp->f, "cast(ty="); | ||
| 606 | ir_print_other_instruction(irp, result_loc_cast->base.source_instruction); | ||
| 607 | fprintf(irp->f, ")"); | ||
| 608 | } | ||
| 609 | |||
| 604 | static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) { | 610 | static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) { |
| 605 | switch (result_loc->id) { | 611 | switch (result_loc->id) { |
| 606 | case ResultLocIdInvalid: | 612 | case ResultLocIdInvalid: |
| ... | @@ -619,6 +625,8 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) { | ... | @@ -619,6 +625,8 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) { |
| 619 | return ir_print_result_loc_peer(irp, (ResultLocPeer *)result_loc); | 625 | return ir_print_result_loc_peer(irp, (ResultLocPeer *)result_loc); |
| 620 | case ResultLocIdBitCast: | 626 | case ResultLocIdBitCast: |
| 621 | return ir_print_result_loc_bit_cast(irp, (ResultLocBitCast *)result_loc); | 627 | return ir_print_result_loc_bit_cast(irp, (ResultLocBitCast *)result_loc); |
| 628 | case ResultLocIdCast: | ||
| 629 | return ir_print_result_loc_cast(irp, (ResultLocCast *)result_loc); | ||
| 622 | case ResultLocIdPeerParent: | 630 | case ResultLocIdPeerParent: |
| 623 | fprintf(irp->f, "peer_parent"); | 631 | fprintf(irp->f, "peer_parent"); |
| 624 | return; | 632 | return; |
| ... | @@ -1484,6 +1492,13 @@ static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruc | ... | @@ -1484,6 +1492,13 @@ static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruc |
| 1484 | fprintf(irp->f, ")"); | 1492 | fprintf(irp->f, ")"); |
| 1485 | } | 1493 | } |
| 1486 | 1494 | ||
| 1495 | static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) { | ||
| 1496 | fprintf(irp->f, "@implicitCast("); | ||
| 1497 | ir_print_other_instruction(irp, instruction->operand); | ||
| 1498 | fprintf(irp->f, ")result="); | ||
| 1499 | ir_print_result_loc(irp, &instruction->result_loc_cast->base); | ||
| 1500 | } | ||
| 1501 | |||
| 1487 | static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) { | 1502 | static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) { |
| 1488 | fprintf(irp->f, "@bitCast("); | 1503 | fprintf(irp->f, "@bitCast("); |
| 1489 | ir_print_other_instruction(irp, instruction->operand); | 1504 | ir_print_other_instruction(irp, instruction->operand); |
| ... | @@ -1739,14 +1754,6 @@ static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instructio | ... | @@ -1739,14 +1754,6 @@ static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instructio |
| 1739 | fprintf(irp->f, ")"); | 1754 | fprintf(irp->f, ")"); |
| 1740 | } | 1755 | } |
| 1741 | 1756 | ||
| 1742 | static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) { | ||
| 1743 | fprintf(irp->f, "@implicitCast("); | ||
| 1744 | ir_print_other_instruction(irp, instruction->dest_type); | ||
| 1745 | fprintf(irp->f, ","); | ||
| 1746 | ir_print_other_instruction(irp, instruction->target); | ||
| 1747 | fprintf(irp->f, ")"); | ||
| 1748 | } | ||
| 1749 | |||
| 1750 | static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) { | 1757 | static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) { |
| 1751 | fprintf(irp->f, "ResolveResult("); | 1758 | fprintf(irp->f, "ResolveResult("); |
| 1752 | ir_print_result_loc(irp, instruction->result_loc); | 1759 | ir_print_result_loc(irp, instruction->result_loc); |
src/translate_c.cpp+15-14| ... | @@ -221,6 +221,15 @@ static AstNode *trans_create_node_opaque(Context *c) { | ... | @@ -221,6 +221,15 @@ static AstNode *trans_create_node_opaque(Context *c) { |
| 221 | return trans_create_node_builtin_fn_call_str(c, "OpaqueType"); | 221 | return trans_create_node_builtin_fn_call_str(c, "OpaqueType"); |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | static AstNode *trans_create_node_cast(Context *c, AstNode *dest_type, AstNode *operand) { | ||
| 225 | AstNode *node = trans_create_node(c, NodeTypeFnCallExpr); | ||
| 226 | node->data.fn_call_expr.fn_ref_expr = trans_create_node_symbol(c, buf_create_from_str("as")); | ||
| 227 | node->data.fn_call_expr.modifier = CallModifierBuiltin; | ||
| 228 | node->data.fn_call_expr.params.append(dest_type); | ||
| 229 | node->data.fn_call_expr.params.append(operand); | ||
| 230 | return node; | ||
| 231 | } | ||
| 232 | |||
| 224 | static AstNode *trans_create_node_fn_call_1(Context *c, AstNode *fn_ref_expr, AstNode *arg1) { | 233 | static AstNode *trans_create_node_fn_call_1(Context *c, AstNode *fn_ref_expr, AstNode *arg1) { |
| 225 | AstNode *node = trans_create_node(c, NodeTypeFnCallExpr); | 234 | AstNode *node = trans_create_node(c, NodeTypeFnCallExpr); |
| 226 | node->data.fn_call_expr.fn_ref_expr = fn_ref_expr; | 235 | node->data.fn_call_expr.fn_ref_expr = fn_ref_expr; |
| ... | @@ -337,14 +346,6 @@ static AstNode *trans_create_node_unsigned(Context *c, uint64_t x) { | ... | @@ -337,14 +346,6 @@ static AstNode *trans_create_node_unsigned(Context *c, uint64_t x) { |
| 337 | return trans_create_node_unsigned_negative(c, x, false); | 346 | return trans_create_node_unsigned_negative(c, x, false); |
| 338 | } | 347 | } |
| 339 | 348 | ||
| 340 | static AstNode *trans_create_node_cast(Context *c, AstNode *dest, AstNode *src) { | ||
| 341 | AstNode *node = trans_create_node(c, NodeTypeFnCallExpr); | ||
| 342 | node->data.fn_call_expr.fn_ref_expr = dest; | ||
| 343 | node->data.fn_call_expr.params.resize(1); | ||
| 344 | node->data.fn_call_expr.params.items[0] = src; | ||
| 345 | return node; | ||
| 346 | } | ||
| 347 | |||
| 348 | static AstNode *trans_create_node_unsigned_negative_type(Context *c, uint64_t x, bool is_negative, | 349 | static AstNode *trans_create_node_unsigned_negative_type(Context *c, uint64_t x, bool is_negative, |
| 349 | const char *type_name) | 350 | const char *type_name) |
| 350 | { | 351 | { |
| ... | @@ -701,7 +702,7 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location, | ... | @@ -701,7 +702,7 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location, |
| 701 | if (c_is_unsigned_integer(c, dest_type) && qual_type_is_ptr(src_type)) { | 702 | if (c_is_unsigned_integer(c, dest_type) && qual_type_is_ptr(src_type)) { |
| 702 | AstNode *addr_node = trans_create_node_builtin_fn_call_str(c, "ptrToInt"); | 703 | AstNode *addr_node = trans_create_node_builtin_fn_call_str(c, "ptrToInt"); |
| 703 | addr_node->data.fn_call_expr.params.append(expr); | 704 | addr_node->data.fn_call_expr.params.append(expr); |
| 704 | return trans_create_node_fn_call_1(c, trans_qual_type(c, dest_type, source_location), addr_node); | 705 | return trans_create_node_cast(c, trans_qual_type(c, dest_type, source_location), addr_node); |
| 705 | } | 706 | } |
| 706 | if (c_is_unsigned_integer(c, src_type) && qual_type_is_ptr(dest_type)) { | 707 | if (c_is_unsigned_integer(c, src_type) && qual_type_is_ptr(dest_type)) { |
| 707 | AstNode *ptr_node = trans_create_node_builtin_fn_call_str(c, "intToPtr"); | 708 | AstNode *ptr_node = trans_create_node_builtin_fn_call_str(c, "intToPtr"); |
| ... | @@ -712,7 +713,7 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location, | ... | @@ -712,7 +713,7 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location, |
| 712 | // TODO: maybe widen to increase size | 713 | // TODO: maybe widen to increase size |
| 713 | // TODO: maybe bitcast to change sign | 714 | // TODO: maybe bitcast to change sign |
| 714 | // TODO: maybe truncate to reduce size | 715 | // TODO: maybe truncate to reduce size |
| 715 | return trans_create_node_fn_call_1(c, trans_qual_type(c, dest_type, source_location), expr); | 716 | return trans_create_node_cast(c, trans_qual_type(c, dest_type, source_location), expr); |
| 716 | } | 717 | } |
| 717 | 718 | ||
| 718 | static bool c_is_signed_integer(Context *c, ZigClangQualType qt) { | 719 | static bool c_is_signed_integer(Context *c, ZigClangQualType qt) { |
| ... | @@ -1527,7 +1528,7 @@ static AstNode *trans_create_shift_op(Context *c, TransScope *scope, ZigClangQua | ... | @@ -1527,7 +1528,7 @@ static AstNode *trans_create_shift_op(Context *c, TransScope *scope, ZigClangQua |
| 1527 | 1528 | ||
| 1528 | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, rhs_expr, TransRValue); | 1529 | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, rhs_expr, TransRValue); |
| 1529 | if (rhs == nullptr) return nullptr; | 1530 | if (rhs == nullptr) return nullptr; |
| 1530 | AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs); | 1531 | AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs); |
| 1531 | 1532 | ||
| 1532 | return trans_create_node_bin_op(c, lhs, bin_op, coerced_rhs); | 1533 | return trans_create_node_bin_op(c, lhs, bin_op, coerced_rhs); |
| 1533 | } | 1534 | } |
| ... | @@ -1702,7 +1703,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result | ... | @@ -1702,7 +1703,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result |
| 1702 | 1703 | ||
| 1703 | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue); | 1704 | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue); |
| 1704 | if (rhs == nullptr) return nullptr; | 1705 | if (rhs == nullptr) return nullptr; |
| 1705 | AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs); | 1706 | AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs); |
| 1706 | 1707 | ||
| 1707 | return trans_create_node_bin_op(c, lhs, assign_op, coerced_rhs); | 1708 | return trans_create_node_bin_op(c, lhs, assign_op, coerced_rhs); |
| 1708 | } else { | 1709 | } else { |
| ... | @@ -1733,7 +1734,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result | ... | @@ -1733,7 +1734,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result |
| 1733 | 1734 | ||
| 1734 | AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue); | 1735 | AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue); |
| 1735 | if (rhs == nullptr) return nullptr; | 1736 | if (rhs == nullptr) return nullptr; |
| 1736 | AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs); | 1737 | AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs); |
| 1737 | 1738 | ||
| 1738 | // operation_type(*_ref) | 1739 | // operation_type(*_ref) |
| 1739 | AstNode *operation_type_cast = trans_c_cast(c, rhs_location, | 1740 | AstNode *operation_type_cast = trans_c_cast(c, rhs_location, |
| ... | @@ -2684,7 +2685,7 @@ static AstNode *to_enum_zero_cmp(Context *c, AstNode *expr, AstNode *enum_type) | ... | @@ -2684,7 +2685,7 @@ static AstNode *to_enum_zero_cmp(Context *c, AstNode *expr, AstNode *enum_type) |
| 2684 | 2685 | ||
| 2685 | // @TagType(Enum)(0) | 2686 | // @TagType(Enum)(0) |
| 2686 | AstNode *zero = trans_create_node_unsigned_negative(c, 0, false); | 2687 | AstNode *zero = trans_create_node_unsigned_negative(c, 0, false); |
| 2687 | AstNode *casted_zero = trans_create_node_fn_call_1(c, tag_type, zero); | 2688 | AstNode *casted_zero = trans_create_node_cast(c, tag_type, zero); |
| 2688 | 2689 | ||
| 2689 | // @bitCast(Enum, @TagType(Enum)(0)) | 2690 | // @bitCast(Enum, @TagType(Enum)(0)) |
| 2690 | AstNode *bitcast = trans_create_node_builtin_fn_call_str(c, "bitCast"); | 2691 | AstNode *bitcast = trans_create_node_builtin_fn_call_str(c, "bitCast"); |
test/compare_output.zig+34-34| ... | @@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 122 | \\ | 122 | \\ |
| 123 | \\pub fn main() void { | 123 | \\pub fn main() void { |
| 124 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | 124 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 125 | \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable; | 125 | \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", @as(u32, 12), @as(u16, 0x12), @as(u8, 'a')) catch unreachable; |
| 126 | \\} | 126 | \\} |
| 127 | , "Hello, world!\n 12 12 a\n"); | 127 | , "Hello, world!\n 12 12 a\n"); |
| 128 | 128 | ||
| ... | @@ -145,75 +145,75 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -145,75 +145,75 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 145 | \\ _ = c._setmode(1, c._O_BINARY); | 145 | \\ _ = c._setmode(1, c._O_BINARY); |
| 146 | \\ } | 146 | \\ } |
| 147 | \\ _ = c.printf(c"0: %llu\n", | 147 | \\ _ = c.printf(c"0: %llu\n", |
| 148 | \\ u64(0)); | 148 | \\ @as(u64, 0)); |
| 149 | \\ _ = c.printf(c"320402575052271: %llu\n", | 149 | \\ _ = c.printf(c"320402575052271: %llu\n", |
| 150 | \\ u64(320402575052271)); | 150 | \\ @as(u64, 320402575052271)); |
| 151 | \\ _ = c.printf(c"0x01236789abcdef: %llu\n", | 151 | \\ _ = c.printf(c"0x01236789abcdef: %llu\n", |
| 152 | \\ u64(0x01236789abcdef)); | 152 | \\ @as(u64, 0x01236789abcdef)); |
| 153 | \\ _ = c.printf(c"0xffffffffffffffff: %llu\n", | 153 | \\ _ = c.printf(c"0xffffffffffffffff: %llu\n", |
| 154 | \\ u64(0xffffffffffffffff)); | 154 | \\ @as(u64, 0xffffffffffffffff)); |
| 155 | \\ _ = c.printf(c"0x000000ffffffffffffffff: %llu\n", | 155 | \\ _ = c.printf(c"0x000000ffffffffffffffff: %llu\n", |
| 156 | \\ u64(0x000000ffffffffffffffff)); | 156 | \\ @as(u64, 0x000000ffffffffffffffff)); |
| 157 | \\ _ = c.printf(c"0o1777777777777777777777: %llu\n", | 157 | \\ _ = c.printf(c"0o1777777777777777777777: %llu\n", |
| 158 | \\ u64(0o1777777777777777777777)); | 158 | \\ @as(u64, 0o1777777777777777777777)); |
| 159 | \\ _ = c.printf(c"0o0000001777777777777777777777: %llu\n", | 159 | \\ _ = c.printf(c"0o0000001777777777777777777777: %llu\n", |
| 160 | \\ u64(0o0000001777777777777777777777)); | 160 | \\ @as(u64, 0o0000001777777777777777777777)); |
| 161 | \\ _ = c.printf(c"0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n", | 161 | \\ _ = c.printf(c"0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n", |
| 162 | \\ u64(0b1111111111111111111111111111111111111111111111111111111111111111)); | 162 | \\ @as(u64, 0b1111111111111111111111111111111111111111111111111111111111111111)); |
| 163 | \\ _ = c.printf(c"0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n", | 163 | \\ _ = c.printf(c"0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n", |
| 164 | \\ u64(0b0000001111111111111111111111111111111111111111111111111111111111111111)); | 164 | \\ @as(u64, 0b0000001111111111111111111111111111111111111111111111111111111111111111)); |
| 165 | \\ | 165 | \\ |
| 166 | \\ _ = c.printf(c"\n"); | 166 | \\ _ = c.printf(c"\n"); |
| 167 | \\ | 167 | \\ |
| 168 | \\ _ = c.printf(c"0.0: %.013a\n", | 168 | \\ _ = c.printf(c"0.0: %.013a\n", |
| 169 | \\ f64(0.0)); | 169 | \\ @as(f64, 0.0)); |
| 170 | \\ _ = c.printf(c"0e0: %.013a\n", | 170 | \\ _ = c.printf(c"0e0: %.013a\n", |
| 171 | \\ f64(0e0)); | 171 | \\ @as(f64, 0e0)); |
| 172 | \\ _ = c.printf(c"0.0e0: %.013a\n", | 172 | \\ _ = c.printf(c"0.0e0: %.013a\n", |
| 173 | \\ f64(0.0e0)); | 173 | \\ @as(f64, 0.0e0)); |
| 174 | \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n", | 174 | \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n", |
| 175 | \\ f64(000000000000000000000000000000000000000000000000000000000.0e0)); | 175 | \\ @as(f64, 000000000000000000000000000000000000000000000000000000000.0e0)); |
| 176 | \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n", | 176 | \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n", |
| 177 | \\ f64(0.000000000000000000000000000000000000000000000000000000000e0)); | 177 | \\ @as(f64, 0.000000000000000000000000000000000000000000000000000000000e0)); |
| 178 | \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n", | 178 | \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n", |
| 179 | \\ f64(0.0e000000000000000000000000000000000000000000000000000000000)); | 179 | \\ @as(f64, 0.0e000000000000000000000000000000000000000000000000000000000)); |
| 180 | \\ _ = c.printf(c"1.0: %.013a\n", | 180 | \\ _ = c.printf(c"1.0: %.013a\n", |
| 181 | \\ f64(1.0)); | 181 | \\ @as(f64, 1.0)); |
| 182 | \\ _ = c.printf(c"10.0: %.013a\n", | 182 | \\ _ = c.printf(c"10.0: %.013a\n", |
| 183 | \\ f64(10.0)); | 183 | \\ @as(f64, 10.0)); |
| 184 | \\ _ = c.printf(c"10.5: %.013a\n", | 184 | \\ _ = c.printf(c"10.5: %.013a\n", |
| 185 | \\ f64(10.5)); | 185 | \\ @as(f64, 10.5)); |
| 186 | \\ _ = c.printf(c"10.5e5: %.013a\n", | 186 | \\ _ = c.printf(c"10.5e5: %.013a\n", |
| 187 | \\ f64(10.5e5)); | 187 | \\ @as(f64, 10.5e5)); |
| 188 | \\ _ = c.printf(c"10.5e+5: %.013a\n", | 188 | \\ _ = c.printf(c"10.5e+5: %.013a\n", |
| 189 | \\ f64(10.5e+5)); | 189 | \\ @as(f64, 10.5e+5)); |
| 190 | \\ _ = c.printf(c"50.0e-2: %.013a\n", | 190 | \\ _ = c.printf(c"50.0e-2: %.013a\n", |
| 191 | \\ f64(50.0e-2)); | 191 | \\ @as(f64, 50.0e-2)); |
| 192 | \\ _ = c.printf(c"50e-2: %.013a\n", | 192 | \\ _ = c.printf(c"50e-2: %.013a\n", |
| 193 | \\ f64(50e-2)); | 193 | \\ @as(f64, 50e-2)); |
| 194 | \\ | 194 | \\ |
| 195 | \\ _ = c.printf(c"\n"); | 195 | \\ _ = c.printf(c"\n"); |
| 196 | \\ | 196 | \\ |
| 197 | \\ _ = c.printf(c"0x1.0: %.013a\n", | 197 | \\ _ = c.printf(c"0x1.0: %.013a\n", |
| 198 | \\ f64(0x1.0)); | 198 | \\ @as(f64, 0x1.0)); |
| 199 | \\ _ = c.printf(c"0x10.0: %.013a\n", | 199 | \\ _ = c.printf(c"0x10.0: %.013a\n", |
| 200 | \\ f64(0x10.0)); | 200 | \\ @as(f64, 0x10.0)); |
| 201 | \\ _ = c.printf(c"0x100.0: %.013a\n", | 201 | \\ _ = c.printf(c"0x100.0: %.013a\n", |
| 202 | \\ f64(0x100.0)); | 202 | \\ @as(f64, 0x100.0)); |
| 203 | \\ _ = c.printf(c"0x103.0: %.013a\n", | 203 | \\ _ = c.printf(c"0x103.0: %.013a\n", |
| 204 | \\ f64(0x103.0)); | 204 | \\ @as(f64, 0x103.0)); |
| 205 | \\ _ = c.printf(c"0x103.7: %.013a\n", | 205 | \\ _ = c.printf(c"0x103.7: %.013a\n", |
| 206 | \\ f64(0x103.7)); | 206 | \\ @as(f64, 0x103.7)); |
| 207 | \\ _ = c.printf(c"0x103.70: %.013a\n", | 207 | \\ _ = c.printf(c"0x103.70: %.013a\n", |
| 208 | \\ f64(0x103.70)); | 208 | \\ @as(f64, 0x103.70)); |
| 209 | \\ _ = c.printf(c"0x103.70p4: %.013a\n", | 209 | \\ _ = c.printf(c"0x103.70p4: %.013a\n", |
| 210 | \\ f64(0x103.70p4)); | 210 | \\ @as(f64, 0x103.70p4)); |
| 211 | \\ _ = c.printf(c"0x103.70p5: %.013a\n", | 211 | \\ _ = c.printf(c"0x103.70p5: %.013a\n", |
| 212 | \\ f64(0x103.70p5)); | 212 | \\ @as(f64, 0x103.70p5)); |
| 213 | \\ _ = c.printf(c"0x103.70p+5: %.013a\n", | 213 | \\ _ = c.printf(c"0x103.70p+5: %.013a\n", |
| 214 | \\ f64(0x103.70p+5)); | 214 | \\ @as(f64, 0x103.70p+5)); |
| 215 | \\ _ = c.printf(c"0x103.70p-5: %.013a\n", | 215 | \\ _ = c.printf(c"0x103.70p-5: %.013a\n", |
| 216 | \\ f64(0x103.70p-5)); | 216 | \\ @as(f64, 0x103.70p-5)); |
| 217 | \\ | 217 | \\ |
| 218 | \\ return 0; | 218 | \\ return 0; |
| 219 | \\} | 219 | \\} |
| ... | @@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 323 | \\ const x: f64 = small; | 323 | \\ const x: f64 = small; |
| 324 | \\ const y = @floatToInt(i32, x); | 324 | \\ const y = @floatToInt(i32, x); |
| 325 | \\ const z = @intToFloat(f64, y); | 325 | \\ const z = @intToFloat(f64, y); |
| 326 | \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, f64(-0.4)); | 326 | \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4)); |
| 327 | \\ return 0; | 327 | \\ return 0; |
| 328 | \\} | 328 | \\} |
| 329 | , "3.25\n3\n3.00\n-0.40\n"); | 329 | , "3.25\n3\n3.00\n-0.40\n"); |
test/compile_errors.zig+66-68| ... | @@ -186,21 +186,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -186,21 +186,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 186 | cases.add( | 186 | cases.add( |
| 187 | "shift amount has to be an integer type", | 187 | "shift amount has to be an integer type", |
| 188 | \\export fn entry() void { | 188 | \\export fn entry() void { |
| 189 | \\ const x = 1 << &u8(10); | 189 | \\ const x = 1 << &@as(u8, 10); |
| 190 | \\} | 190 | \\} |
| 191 | , | 191 | , |
| 192 | "tmp.zig:2:23: error: shift amount has to be an integer type, but found '*u8'", | 192 | "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'", |
| 193 | "tmp.zig:2:17: note: referenced here", | 193 | "tmp.zig:2:17: note: referenced here", |
| 194 | ); | 194 | ); |
| 195 | 195 | ||
| 196 | cases.add( | 196 | cases.add( |
| 197 | "bit shifting only works on integer types", | 197 | "bit shifting only works on integer types", |
| 198 | \\export fn entry() void { | 198 | \\export fn entry() void { |
| 199 | \\ const x = &u8(1) << 10; | 199 | \\ const x = &@as(u8, 1) << 10; |
| 200 | \\} | 200 | \\} |
| 201 | , | 201 | , |
| 202 | "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'", | 202 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'", |
| 203 | "tmp.zig:2:22: note: referenced here", | 203 | "tmp.zig:2:27: note: referenced here", |
| 204 | ); | 204 | ); |
| 205 | 205 | ||
| 206 | cases.add( | 206 | cases.add( |
| ... | @@ -241,11 +241,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -241,11 +241,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 241 | \\ var x: []align(true) i32 = undefined; | 241 | \\ var x: []align(true) i32 = undefined; |
| 242 | \\} | 242 | \\} |
| 243 | \\export fn entry2() void { | 243 | \\export fn entry2() void { |
| 244 | \\ var x: *align(f64(12.34)) i32 = undefined; | 244 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; |
| 245 | \\} | 245 | \\} |
| 246 | , | 246 | , |
| 247 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", | 247 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", |
| 248 | "tmp.zig:5:22: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", | 248 | "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", |
| 249 | ); | 249 | ); |
| 250 | 250 | ||
| 251 | cases.addCase(x: { | 251 | cases.addCase(x: { |
| ... | @@ -1243,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1243,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1243 | \\ var ptr: [*c]u8 = x; | 1243 | \\ var ptr: [*c]u8 = x; |
| 1244 | \\} | 1244 | \\} |
| 1245 | , | 1245 | , |
| 1246 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be implicitly casted to type 'usize'", | 1246 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", |
| 1247 | "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", | 1247 | "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", |
| 1248 | ); | 1248 | ); |
| 1249 | 1249 | ||
| ... | @@ -1297,17 +1297,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1297,17 +1297,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1297 | cases.add( | 1297 | cases.add( |
| 1298 | "@truncate undefined value", | 1298 | "@truncate undefined value", |
| 1299 | \\export fn entry() void { | 1299 | \\export fn entry() void { |
| 1300 | \\ var z = @truncate(u8, u16(undefined)); | 1300 | \\ var z = @truncate(u8, @as(u16, undefined)); |
| 1301 | \\} | 1301 | \\} |
| 1302 | , | 1302 | , |
| 1303 | "tmp.zig:2:30: error: use of undefined value here causes undefined behavior", | 1303 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", |
| 1304 | ); | 1304 | ); |
| 1305 | 1305 | ||
| 1306 | cases.addTest( | 1306 | cases.addTest( |
| 1307 | "return invalid type from test", | 1307 | "return invalid type from test", |
| 1308 | \\test "example" { return 1; } | 1308 | \\test "example" { return 1; } |
| 1309 | , | 1309 | , |
| 1310 | "tmp.zig:1:25: error: integer value 1 cannot be implicitly casted to type 'void'", | 1310 | "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'", |
| 1311 | ); | 1311 | ); |
| 1312 | 1312 | ||
| 1313 | cases.add( | 1313 | cases.add( |
| ... | @@ -1332,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1332,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1332 | cases.add( | 1332 | cases.add( |
| 1333 | "@bitCast with different sizes inside an expression", | 1333 | "@bitCast with different sizes inside an expression", |
| 1334 | \\export fn entry() void { | 1334 | \\export fn entry() void { |
| 1335 | \\ var foo = (@bitCast(u8, f32(1.0)) == 0xf); | 1335 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); |
| 1336 | \\} | 1336 | \\} |
| 1337 | , | 1337 | , |
| 1338 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", | 1338 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", |
| ... | @@ -1464,8 +1464,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1464,8 +1464,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1464 | \\ var byte: u8 = spartan_count; | 1464 | \\ var byte: u8 = spartan_count; |
| 1465 | \\} | 1465 | \\} |
| 1466 | , | 1466 | , |
| 1467 | "tmp.zig:3:31: error: integer value 300 cannot be implicitly casted to type 'u8'", | 1467 | "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'", |
| 1468 | "tmp.zig:7:22: error: integer value 300 cannot be implicitly casted to type 'u8'", | 1468 | "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'", |
| 1469 | "tmp.zig:11:20: error: expected type 'u8', found 'u16'", | 1469 | "tmp.zig:11:20: error: expected type 'u8', found 'u16'", |
| 1470 | ); | 1470 | ); |
| 1471 | 1471 | ||
| ... | @@ -1498,7 +1498,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1498,7 +1498,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1498 | \\ var x: i65536 = 1; | 1498 | \\ var x: i65536 = 1; |
| 1499 | \\} | 1499 | \\} |
| 1500 | , | 1500 | , |
| 1501 | "tmp.zig:2:31: error: integer value 65536 cannot be implicitly casted to type 'u16'", | 1501 | "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'", |
| 1502 | "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", | 1502 | "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", |
| 1503 | ); | 1503 | ); |
| 1504 | 1504 | ||
| ... | @@ -1686,10 +1686,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1686,10 +1686,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1686 | cases.add( | 1686 | cases.add( |
| 1687 | "non float passed to @floatToInt", | 1687 | "non float passed to @floatToInt", |
| 1688 | \\export fn entry() void { | 1688 | \\export fn entry() void { |
| 1689 | \\ const x = @floatToInt(i32, i32(54)); | 1689 | \\ const x = @floatToInt(i32, @as(i32, 54)); |
| 1690 | \\} | 1690 | \\} |
| 1691 | , | 1691 | , |
| 1692 | "tmp.zig:2:35: error: expected float type, found 'i32'", | 1692 | "tmp.zig:2:32: error: expected float type, found 'i32'", |
| 1693 | ); | 1693 | ); |
| 1694 | 1694 | ||
| 1695 | cases.add( | 1695 | cases.add( |
| ... | @@ -1698,7 +1698,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1698,7 +1698,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1698 | \\ const x = @floatToInt(i8, 200); | 1698 | \\ const x = @floatToInt(i8, 200); |
| 1699 | \\} | 1699 | \\} |
| 1700 | , | 1700 | , |
| 1701 | "tmp.zig:2:31: error: integer value 200 cannot be implicitly casted to type 'i8'", | 1701 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", |
| 1702 | ); | 1702 | ); |
| 1703 | 1703 | ||
| 1704 | cases.add( | 1704 | cases.add( |
| ... | @@ -2120,13 +2120,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2120,13 +2120,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2120 | cases.add( | 2120 | cases.add( |
| 2121 | "@floatToInt comptime safety", | 2121 | "@floatToInt comptime safety", |
| 2122 | \\comptime { | 2122 | \\comptime { |
| 2123 | \\ _ = @floatToInt(i8, f32(-129.1)); | 2123 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); |
| 2124 | \\} | 2124 | \\} |
| 2125 | \\comptime { | 2125 | \\comptime { |
| 2126 | \\ _ = @floatToInt(u8, f32(-1.1)); | 2126 | \\ _ = @floatToInt(u8, @as(f32, -1.1)); |
| 2127 | \\} | 2127 | \\} |
| 2128 | \\comptime { | 2128 | \\comptime { |
| 2129 | \\ _ = @floatToInt(u8, f32(256.1)); | 2129 | \\ _ = @floatToInt(u8, @as(f32, 256.1)); |
| 2130 | \\} | 2130 | \\} |
| 2131 | , | 2131 | , |
| 2132 | "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'", | 2132 | "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'", |
| ... | @@ -2197,7 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2197,7 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2197 | cases.add( | 2197 | cases.add( |
| 2198 | "error when evaluating return type", | 2198 | "error when evaluating return type", |
| 2199 | \\const Foo = struct { | 2199 | \\const Foo = struct { |
| 2200 | \\ map: i32(i32), | 2200 | \\ map: @as(i32, i32), |
| 2201 | \\ | 2201 | \\ |
| 2202 | \\ fn init() Foo { | 2202 | \\ fn init() Foo { |
| 2203 | \\ return undefined; | 2203 | \\ return undefined; |
| ... | @@ -2207,7 +2207,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2207,7 +2207,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2207 | \\ var rule_set = try Foo.init(); | 2207 | \\ var rule_set = try Foo.init(); |
| 2208 | \\} | 2208 | \\} |
| 2209 | , | 2209 | , |
| 2210 | "tmp.zig:2:13: error: expected type 'i32', found 'type'", | 2210 | "tmp.zig:2:10: error: expected type 'i32', found 'type'", |
| 2211 | ); | 2211 | ); |
| 2212 | 2212 | ||
| 2213 | cases.add( | 2213 | cases.add( |
| ... | @@ -2338,7 +2338,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2338,7 +2338,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2338 | cases.add( | 2338 | cases.add( |
| 2339 | "var not allowed in structs", | 2339 | "var not allowed in structs", |
| 2340 | \\export fn entry() void { | 2340 | \\export fn entry() void { |
| 2341 | \\ var s = (struct{v: var}){.v=i32(10)}; | 2341 | \\ var s = (struct{v: var}){.v=@as(i32, 10)}; |
| 2342 | \\} | 2342 | \\} |
| 2343 | , | 2343 | , |
| 2344 | "tmp.zig:2:23: error: invalid token: 'var'", | 2344 | "tmp.zig:2:23: error: invalid token: 'var'", |
| ... | @@ -2357,10 +2357,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2357,10 +2357,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2357 | cases.add( | 2357 | cases.add( |
| 2358 | "comptime slice of undefined pointer non-zero len", | 2358 | "comptime slice of undefined pointer non-zero len", |
| 2359 | \\export fn entry() void { | 2359 | \\export fn entry() void { |
| 2360 | \\ const slice = ([*]i32)(undefined)[0..1]; | 2360 | \\ const slice = @as([*]i32, undefined)[0..1]; |
| 2361 | \\} | 2361 | \\} |
| 2362 | , | 2362 | , |
| 2363 | "tmp.zig:2:38: error: non-zero length slice of undefined pointer", | 2363 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", |
| 2364 | ); | 2364 | ); |
| 2365 | 2365 | ||
| 2366 | cases.add( | 2366 | cases.add( |
| ... | @@ -2657,10 +2657,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2657,10 +2657,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2657 | cases.add( | 2657 | cases.add( |
| 2658 | "cast negative integer literal to usize", | 2658 | "cast negative integer literal to usize", |
| 2659 | \\export fn entry() void { | 2659 | \\export fn entry() void { |
| 2660 | \\ const x = usize(-10); | 2660 | \\ const x = @as(usize, -10); |
| 2661 | \\} | 2661 | \\} |
| 2662 | , | 2662 | , |
| 2663 | "tmp.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'", | 2663 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", |
| 2664 | ); | 2664 | ); |
| 2665 | 2665 | ||
| 2666 | cases.add( | 2666 | cases.add( |
| ... | @@ -3384,11 +3384,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3384,11 +3384,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3384 | \\ const x : i32 = if (b) h: { break :h 1; }; | 3384 | \\ const x : i32 = if (b) h: { break :h 1; }; |
| 3385 | \\} | 3385 | \\} |
| 3386 | \\fn g(b: bool) void { | 3386 | \\fn g(b: bool) void { |
| 3387 | \\ const y = if (b) h: { break :h i32(1); }; | 3387 | \\ const y = if (b) h: { break :h @as(i32, 1); }; |
| 3388 | \\} | 3388 | \\} |
| 3389 | \\export fn entry() void { f(true); g(true); } | 3389 | \\export fn entry() void { f(true); g(true); } |
| 3390 | , | 3390 | , |
| 3391 | "tmp.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'", | 3391 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", |
| 3392 | "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", | 3392 | "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", |
| 3393 | ); | 3393 | ); |
| 3394 | 3394 | ||
| ... | @@ -3520,11 +3520,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3520,11 +3520,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3520 | cases.add( | 3520 | cases.add( |
| 3521 | "cast unreachable", | 3521 | "cast unreachable", |
| 3522 | \\fn f() i32 { | 3522 | \\fn f() i32 { |
| 3523 | \\ return i32(return 1); | 3523 | \\ return @as(i32, return 1); |
| 3524 | \\} | 3524 | \\} |
| 3525 | \\export fn entry() void { _ = f(); } | 3525 | \\export fn entry() void { _ = f(); } |
| 3526 | , | 3526 | , |
| 3527 | "tmp.zig:2:15: error: unreachable code", | 3527 | "tmp.zig:2:12: error: unreachable code", |
| 3528 | ); | 3528 | ); |
| 3529 | 3529 | ||
| 3530 | cases.add( | 3530 | cases.add( |
| ... | @@ -3595,7 +3595,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3595,7 +3595,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3595 | \\ switch (n) { | 3595 | \\ switch (n) { |
| 3596 | \\ Number.One => 1, | 3596 | \\ Number.One => 1, |
| 3597 | \\ Number.Two => 2, | 3597 | \\ Number.Two => 2, |
| 3598 | \\ Number.Three => i32(3), | 3598 | \\ Number.Three => @as(i32, 3), |
| 3599 | \\ } | 3599 | \\ } |
| 3600 | \\} | 3600 | \\} |
| 3601 | \\ | 3601 | \\ |
| ... | @@ -3616,7 +3616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3616,7 +3616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3616 | \\ switch (n) { | 3616 | \\ switch (n) { |
| 3617 | \\ Number.One => 1, | 3617 | \\ Number.One => 1, |
| 3618 | \\ Number.Two => 2, | 3618 | \\ Number.Two => 2, |
| 3619 | \\ Number.Three => i32(3), | 3619 | \\ Number.Three => @as(i32, 3), |
| 3620 | \\ Number.Four => 4, | 3620 | \\ Number.Four => 4, |
| 3621 | \\ Number.Two => 2, | 3621 | \\ Number.Two => 2, |
| 3622 | \\ } | 3622 | \\ } |
| ... | @@ -3640,7 +3640,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3640,7 +3640,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3640 | \\ switch (n) { | 3640 | \\ switch (n) { |
| 3641 | \\ Number.One => 1, | 3641 | \\ Number.One => 1, |
| 3642 | \\ Number.Two => 2, | 3642 | \\ Number.Two => 2, |
| 3643 | \\ Number.Three => i32(3), | 3643 | \\ Number.Three => @as(i32, 3), |
| 3644 | \\ Number.Four => 4, | 3644 | \\ Number.Four => 4, |
| 3645 | \\ Number.Two => 2, | 3645 | \\ Number.Two => 2, |
| 3646 | \\ else => 10, | 3646 | \\ else => 10, |
| ... | @@ -3685,7 +3685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3685,7 +3685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3685 | "switch expression - duplicate or overlapping integer value", | 3685 | "switch expression - duplicate or overlapping integer value", |
| 3686 | \\fn foo(x: u8) u8 { | 3686 | \\fn foo(x: u8) u8 { |
| 3687 | \\ return switch (x) { | 3687 | \\ return switch (x) { |
| 3688 | \\ 0 ... 100 => u8(0), | 3688 | \\ 0 ... 100 => @as(u8, 0), |
| 3689 | \\ 101 ... 200 => 1, | 3689 | \\ 101 ... 200 => 1, |
| 3690 | \\ 201, 203 ... 207 => 2, | 3690 | \\ 201, 203 ... 207 => 2, |
| 3691 | \\ 206 ... 255 => 3, | 3691 | \\ 206 ... 255 => 3, |
| ... | @@ -3722,7 +3722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3722,7 +3722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3722 | cases.add( | 3722 | cases.add( |
| 3723 | "array concatenation with wrong type", | 3723 | "array concatenation with wrong type", |
| 3724 | \\const src = "aoeu"; | 3724 | \\const src = "aoeu"; |
| 3725 | \\const derp = usize(1234); | 3725 | \\const derp = @as(usize, 1234); |
| 3726 | \\const a = derp ++ "foo"; | 3726 | \\const a = derp ++ "foo"; |
| 3727 | \\ | 3727 | \\ |
| 3728 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } | 3728 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| ... | @@ -3765,7 +3765,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3765,7 +3765,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3765 | \\const x : u8 = 300; | 3765 | \\const x : u8 = 300; |
| 3766 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } | 3766 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 3767 | , | 3767 | , |
| 3768 | "tmp.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'", | 3768 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", |
| 3769 | ); | 3769 | ); |
| 3770 | 3770 | ||
| 3771 | cases.add( | 3771 | cases.add( |
| ... | @@ -3887,8 +3887,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3887,8 +3887,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3887 | "division by zero", | 3887 | "division by zero", |
| 3888 | \\const lit_int_x = 1 / 0; | 3888 | \\const lit_int_x = 1 / 0; |
| 3889 | \\const lit_float_x = 1.0 / 0.0; | 3889 | \\const lit_float_x = 1.0 / 0.0; |
| 3890 | \\const int_x = u32(1) / u32(0); | 3890 | \\const int_x = @as(u32, 1) / @as(u32, 0); |
| 3891 | \\const float_x = f32(1.0) / f32(0.0); | 3891 | \\const float_x = @as(f32, 1.0) / @as(f32, 0.0); |
| 3892 | \\ | 3892 | \\ |
| 3893 | \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); } | 3893 | \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); } |
| 3894 | \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } | 3894 | \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } |
| ... | @@ -3897,8 +3897,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3897,8 +3897,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3897 | , | 3897 | , |
| 3898 | "tmp.zig:1:21: error: division by zero", | 3898 | "tmp.zig:1:21: error: division by zero", |
| 3899 | "tmp.zig:2:25: error: division by zero", | 3899 | "tmp.zig:2:25: error: division by zero", |
| 3900 | "tmp.zig:3:22: error: division by zero", | 3900 | "tmp.zig:3:27: error: division by zero", |
| 3901 | "tmp.zig:4:26: error: division by zero", | 3901 | "tmp.zig:4:31: error: division by zero", |
| 3902 | ); | 3902 | ); |
| 3903 | 3903 | ||
| 3904 | cases.add( | 3904 | cases.add( |
| ... | @@ -4590,7 +4590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4590,7 +4590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4590 | \\var bytes: [ext()]u8 = undefined; | 4590 | \\var bytes: [ext()]u8 = undefined; |
| 4591 | \\export fn f() void { | 4591 | \\export fn f() void { |
| 4592 | \\ for (bytes) |*b, i| { | 4592 | \\ for (bytes) |*b, i| { |
| 4593 | \\ b.* = u8(i); | 4593 | \\ b.* = @as(u8, i); |
| 4594 | \\ } | 4594 | \\ } |
| 4595 | \\} | 4595 | \\} |
| 4596 | , | 4596 | , |
| ... | @@ -4874,7 +4874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4874,7 +4874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4874 | \\} | 4874 | \\} |
| 4875 | \\ | 4875 | \\ |
| 4876 | \\fn foo() i32 { | 4876 | \\fn foo() i32 { |
| 4877 | \\ return add(i32(1234)); | 4877 | \\ return add(@as(i32, 1234)); |
| 4878 | \\} | 4878 | \\} |
| 4879 | \\ | 4879 | \\ |
| 4880 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | 4880 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| ... | @@ -4886,7 +4886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4886,7 +4886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4886 | cases.add( | 4886 | cases.add( |
| 4887 | "pass integer literal to var args", | 4887 | "pass integer literal to var args", |
| 4888 | \\fn add(args: ...) i32 { | 4888 | \\fn add(args: ...) i32 { |
| 4889 | \\ var sum = i32(0); | 4889 | \\ var sum = @as(i32, 0); |
| 4890 | \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { | 4890 | \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { |
| 4891 | \\ sum += args[i]; | 4891 | \\ sum += args[i]; |
| 4892 | \\ }} | 4892 | \\ }} |
| ... | @@ -4908,7 +4908,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4908,7 +4908,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4908 | \\ var vga_mem: u16 = 0xB8000; | 4908 | \\ var vga_mem: u16 = 0xB8000; |
| 4909 | \\} | 4909 | \\} |
| 4910 | , | 4910 | , |
| 4911 | "tmp.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'", | 4911 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", |
| 4912 | ); | 4912 | ); |
| 4913 | 4913 | ||
| 4914 | cases.add( | 4914 | cases.add( |
| ... | @@ -5080,7 +5080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5080,7 +5080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5080 | cases.add( | 5080 | cases.add( |
| 5081 | "pass const ptr to mutable ptr fn", | 5081 | "pass const ptr to mutable ptr fn", |
| 5082 | \\fn foo() bool { | 5082 | \\fn foo() bool { |
| 5083 | \\ const a = ([]const u8)("a",); | 5083 | \\ const a = @as([]const u8, "a",); |
| 5084 | \\ const b = &a; | 5084 | \\ const b = &a; |
| 5085 | \\ return ptrEql(b, b); | 5085 | \\ return ptrEql(b, b); |
| 5086 | \\} | 5086 | \\} |
| ... | @@ -5581,10 +5581,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5581,10 +5581,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5581 | cases.add( | 5581 | cases.add( |
| 5582 | "explicit cast float literal to integer when there is a fraction component", | 5582 | "explicit cast float literal to integer when there is a fraction component", |
| 5583 | \\export fn entry() i32 { | 5583 | \\export fn entry() i32 { |
| 5584 | \\ return i32(12.34); | 5584 | \\ return @as(i32, 12.34); |
| 5585 | \\} | 5585 | \\} |
| 5586 | , | 5586 | , |
| 5587 | "tmp.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", | 5587 | "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", |
| 5588 | ); | 5588 | ); |
| 5589 | 5589 | ||
| 5590 | cases.add( | 5590 | cases.add( |
| ... | @@ -5599,7 +5599,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5599,7 +5599,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5599 | cases.add( | 5599 | cases.add( |
| 5600 | "@shlExact shifts out 1 bits", | 5600 | "@shlExact shifts out 1 bits", |
| 5601 | \\comptime { | 5601 | \\comptime { |
| 5602 | \\ const x = @shlExact(u8(0b01010101), 2); | 5602 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); |
| 5603 | \\} | 5603 | \\} |
| 5604 | , | 5604 | , |
| 5605 | "tmp.zig:2:15: error: operation caused overflow", | 5605 | "tmp.zig:2:15: error: operation caused overflow", |
| ... | @@ -5608,7 +5608,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5608,7 +5608,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5608 | cases.add( | 5608 | cases.add( |
| 5609 | "@shrExact shifts out 1 bits", | 5609 | "@shrExact shifts out 1 bits", |
| 5610 | \\comptime { | 5610 | \\comptime { |
| 5611 | \\ const x = @shrExact(u8(0b10101010), 2); | 5611 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); |
| 5612 | \\} | 5612 | \\} |
| 5613 | , | 5613 | , |
| 5614 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", | 5614 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", |
| ... | @@ -5671,16 +5671,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5671,16 +5671,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5671 | \\export fn entry() void { | 5671 | \\export fn entry() void { |
| 5672 | \\ var foo = Foo { .a = 1, .b = 10 }; | 5672 | \\ var foo = Foo { .a = 1, .b = 10 }; |
| 5673 | \\ foo.b += 1; | 5673 | \\ foo.b += 1; |
| 5674 | \\ bar((*[1]u32)(&foo.b)[0..]); | 5674 | \\ bar(@as(*[1]u32, &foo.b)[0..]); |
| 5675 | \\} | 5675 | \\} |
| 5676 | \\ | 5676 | \\ |
| 5677 | \\fn bar(x: []u32) void { | 5677 | \\fn bar(x: []u32) void { |
| 5678 | \\ x[0] += 1; | 5678 | \\ x[0] += 1; |
| 5679 | \\} | 5679 | \\} |
| 5680 | , | 5680 | , |
| 5681 | "tmp.zig:9:18: error: cast increases pointer alignment", | 5681 | "tmp.zig:9:9: error: cast increases pointer alignment", |
| 5682 | "tmp.zig:9:23: note: '*align(1) u32' has alignment 1", | 5682 | "tmp.zig:9:26: note: '*align(1) u32' has alignment 1", |
| 5683 | "tmp.zig:9:18: note: '*[1]u32' has alignment 4", | 5683 | "tmp.zig:9:9: note: '*[1]u32' has alignment 4", |
| 5684 | ); | 5684 | ); |
| 5685 | 5685 | ||
| 5686 | cases.add( | 5686 | cases.add( |
| ... | @@ -5699,10 +5699,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5699,10 +5699,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5699 | cases.add( | 5699 | cases.add( |
| 5700 | "@alignCast expects pointer or slice", | 5700 | "@alignCast expects pointer or slice", |
| 5701 | \\export fn entry() void { | 5701 | \\export fn entry() void { |
| 5702 | \\ @alignCast(4, u32(3)); | 5702 | \\ @alignCast(4, @as(u32, 3)); |
| 5703 | \\} | 5703 | \\} |
| 5704 | , | 5704 | , |
| 5705 | "tmp.zig:2:22: error: expected pointer or slice, found 'u32'", | 5705 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", |
| 5706 | ); | 5706 | ); |
| 5707 | 5707 | ||
| 5708 | cases.add( | 5708 | cases.add( |
| ... | @@ -5740,11 +5740,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5740,11 +5740,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5740 | ); | 5740 | ); |
| 5741 | 5741 | ||
| 5742 | cases.add( | 5742 | cases.add( |
| 5743 | "wrong pointer implicitly casted to pointer to @OpaqueType()", | 5743 | "wrong pointer coerced to pointer to @OpaqueType()", |
| 5744 | \\const Derp = @OpaqueType(); | 5744 | \\const Derp = @OpaqueType(); |
| 5745 | \\extern fn bar(d: *Derp) void; | 5745 | \\extern fn bar(d: *Derp) void; |
| 5746 | \\export fn foo() void { | 5746 | \\export fn foo() void { |
| 5747 | \\ var x = u8(1); | 5747 | \\ var x = @as(u8, 1); |
| 5748 | \\ bar(@ptrCast(*c_void, &x)); | 5748 | \\ bar(@ptrCast(*c_void, &x)); |
| 5749 | \\} | 5749 | \\} |
| 5750 | , | 5750 | , |
| ... | @@ -5793,27 +5793,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5793,27 +5793,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5793 | "tmp.zig:17:4: error: variable of type 'Opaque' not allowed", | 5793 | "tmp.zig:17:4: error: variable of type 'Opaque' not allowed", |
| 5794 | "tmp.zig:20:4: error: variable of type 'type' must be const or comptime", | 5794 | "tmp.zig:20:4: error: variable of type 'type' must be const or comptime", |
| 5795 | "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", | 5795 | "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", |
| 5796 | "tmp.zig:26:4: error: unreachable code", | 5796 | "tmp.zig:26:22: error: unreachable code", |
| 5797 | ); | 5797 | ); |
| 5798 | 5798 | ||
| 5799 | cases.add( | 5799 | cases.add( |
| 5800 | "wrong types given to atomic order args in cmpxchg", | 5800 | "wrong types given to atomic order args in cmpxchg", |
| 5801 | \\export fn entry() void { | 5801 | \\export fn entry() void { |
| 5802 | \\ var x: i32 = 1234; | 5802 | \\ var x: i32 = 1234; |
| 5803 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, u32(1234), u32(1234))) {} | 5803 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} |
| 5804 | \\} | 5804 | \\} |
| 5805 | , | 5805 | , |
| 5806 | "tmp.zig:3:50: error: expected type 'std.builtin.AtomicOrder', found 'u32'", | 5806 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", |
| 5807 | ); | 5807 | ); |
| 5808 | 5808 | ||
| 5809 | cases.add( | 5809 | cases.add( |
| 5810 | "wrong types given to @export", | 5810 | "wrong types given to @export", |
| 5811 | \\extern fn entry() void { } | 5811 | \\extern fn entry() void { } |
| 5812 | \\comptime { | 5812 | \\comptime { |
| 5813 | \\ @export("entry", entry, u32(1234)); | 5813 | \\ @export("entry", entry, @as(u32, 1234)); |
| 5814 | \\} | 5814 | \\} |
| 5815 | , | 5815 | , |
| 5816 | "tmp.zig:3:32: error: expected type 'std.builtin.GlobalLinkage', found 'u32'", | 5816 | "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'", |
| 5817 | ); | 5817 | ); |
| 5818 | 5818 | ||
| 5819 | cases.add( | 5819 | cases.add( |
| ... | @@ -6185,7 +6185,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6185,7 +6185,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6185 | \\}; | 6185 | \\}; |
| 6186 | \\ | 6186 | \\ |
| 6187 | \\export fn entry() void { | 6187 | \\export fn entry() void { |
| 6188 | \\ var y = u3(3); | 6188 | \\ var y = @as(u3, 3); |
| 6189 | \\ var x = @intToEnum(Small, y); | 6189 | \\ var x = @intToEnum(Small, y); |
| 6190 | \\} | 6190 | \\} |
| 6191 | , | 6191 | , |
| ... | @@ -6722,8 +6722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6722,8 +6722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6722 | "tmp.zig:1:1: note: declared here", | 6722 | "tmp.zig:1:1: note: declared here", |
| 6723 | ); | 6723 | ); |
| 6724 | 6724 | ||
| 6725 | // fixed bug #2032 | 6725 | cases.add( // fixed bug #2032 |
| 6726 | cases.add( | ||
| 6727 | "compile diagnostic string for top level decl type", | 6726 | "compile diagnostic string for top level decl type", |
| 6728 | \\export fn entry() void { | 6727 | \\export fn entry() void { |
| 6729 | \\ var foo: u32 = @This(){}; | 6728 | \\ var foo: u32 = @This(){}; |
| ... | @@ -6731,6 +6730,5 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6731,6 +6730,5 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6731 | , | 6730 | , |
| 6732 | "tmp.zig:2:27: error: expected type 'u32', found '(root)'", | 6731 | "tmp.zig:2:27: error: expected type 'u32', found '(root)'", |
| 6733 | "tmp.zig:1:1: note: (root) declared here", | 6732 | "tmp.zig:1:1: note: (root) declared here", |
| 6734 | "tmp.zig:2:5: note: referenced here", | ||
| 6735 | ); | 6733 | ); |
| 6736 | } | 6734 | } |
test/stage1/behavior/align.zig+2-2| ... | @@ -7,7 +7,7 @@ var foo: u8 align(4) = 100; | ... | @@ -7,7 +7,7 @@ var foo: u8 align(4) = 100; |
| 7 | test "global variable alignment" { | 7 | test "global variable alignment" { |
| 8 | expect(@typeOf(&foo).alignment == 4); | 8 | expect(@typeOf(&foo).alignment == 4); |
| 9 | expect(@typeOf(&foo) == *align(4) u8); | 9 | expect(@typeOf(&foo) == *align(4) u8); |
| 10 | const slice = (*[1]u8)(&foo)[0..]; | 10 | const slice = @as(*[1]u8, &foo)[0..]; |
| 11 | expect(@typeOf(slice) == []align(4) u8); | 11 | expect(@typeOf(slice) == []align(4) u8); |
| 12 | } | 12 | } |
| 13 | 13 | ||
| ... | @@ -61,7 +61,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 { | ... | @@ -61,7 +61,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 { |
| 61 | test "implicitly decreasing slice alignment" { | 61 | test "implicitly decreasing slice alignment" { |
| 62 | const a: u32 align(4) = 3; | 62 | const a: u32 align(4) = 3; |
| 63 | const b: u32 align(8) = 4; | 63 | const b: u32 align(8) = 4; |
| 64 | expect(addUnalignedSlice((*const [1]u32)(&a)[0..], (*const [1]u32)(&b)[0..]) == 7); | 64 | expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7); |
| 65 | } | 65 | } |
| 66 | fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 { | 66 | fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 { |
| 67 | return a[0] + b[0]; | 67 | return a[0] + b[0]; |
test/stage1/behavior/array.zig+2-2| ... | @@ -12,7 +12,7 @@ test "arrays" { | ... | @@ -12,7 +12,7 @@ test "arrays" { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | i = 0; | 14 | i = 0; |
| 15 | var accumulator = u32(0); | 15 | var accumulator = @as(u32, 0); |
| 16 | while (i < 5) { | 16 | while (i < 5) { |
| 17 | accumulator += array[i]; | 17 | accumulator += array[i]; |
| 18 | 18 | ||
| ... | @@ -149,7 +149,7 @@ test "implicit cast single-item pointer" { | ... | @@ -149,7 +149,7 @@ test "implicit cast single-item pointer" { |
| 149 | 149 | ||
| 150 | fn testImplicitCastSingleItemPtr() void { | 150 | fn testImplicitCastSingleItemPtr() void { |
| 151 | var byte: u8 = 100; | 151 | var byte: u8 = 100; |
| 152 | const slice = (*[1]u8)(&byte)[0..]; | 152 | const slice = @as(*[1]u8, &byte)[0..]; |
| 153 | slice[0] += 1; | 153 | slice[0] += 1; |
| 154 | expect(byte == 101); | 154 | expect(byte == 101); |
| 155 | } | 155 | } |
test/stage1/behavior/asm.zig+8-8| ... | @@ -45,42 +45,42 @@ test "alternative constraints" { | ... | @@ -45,42 +45,42 @@ test "alternative constraints" { |
| 45 | test "sized integer/float in asm input" { | 45 | test "sized integer/float in asm input" { |
| 46 | asm volatile ("" | 46 | asm volatile ("" |
| 47 | : | 47 | : |
| 48 | : [_] "m" (usize(3)) | 48 | : [_] "m" (@as(usize, 3)) |
| 49 | : "" | 49 | : "" |
| 50 | ); | 50 | ); |
| 51 | asm volatile ("" | 51 | asm volatile ("" |
| 52 | : | 52 | : |
| 53 | : [_] "m" (i15(-3)) | 53 | : [_] "m" (@as(i15, -3)) |
| 54 | : "" | 54 | : "" |
| 55 | ); | 55 | ); |
| 56 | asm volatile ("" | 56 | asm volatile ("" |
| 57 | : | 57 | : |
| 58 | : [_] "m" (u3(3)) | 58 | : [_] "m" (@as(u3, 3)) |
| 59 | : "" | 59 | : "" |
| 60 | ); | 60 | ); |
| 61 | asm volatile ("" | 61 | asm volatile ("" |
| 62 | : | 62 | : |
| 63 | : [_] "m" (i3(3)) | 63 | : [_] "m" (@as(i3, 3)) |
| 64 | : "" | 64 | : "" |
| 65 | ); | 65 | ); |
| 66 | asm volatile ("" | 66 | asm volatile ("" |
| 67 | : | 67 | : |
| 68 | : [_] "m" (u121(3)) | 68 | : [_] "m" (@as(u121, 3)) |
| 69 | : "" | 69 | : "" |
| 70 | ); | 70 | ); |
| 71 | asm volatile ("" | 71 | asm volatile ("" |
| 72 | : | 72 | : |
| 73 | : [_] "m" (i121(3)) | 73 | : [_] "m" (@as(i121, 3)) |
| 74 | : "" | 74 | : "" |
| 75 | ); | 75 | ); |
| 76 | asm volatile ("" | 76 | asm volatile ("" |
| 77 | : | 77 | : |
| 78 | : [_] "m" (f32(3.17)) | 78 | : [_] "m" (@as(f32, 3.17)) |
| 79 | : "" | 79 | : "" |
| 80 | ); | 80 | ); |
| 81 | asm volatile ("" | 81 | asm volatile ("" |
| 82 | : | 82 | : |
| 83 | : [_] "m" (f64(3.17)) | 83 | : [_] "m" (@as(f64, 3.17)) |
| 84 | : "" | 84 | : "" |
| 85 | ); | 85 | ); |
| 86 | } | 86 | } |
test/stage1/behavior/async_fn.zig+5-5| ... | @@ -191,7 +191,7 @@ async fn testSuspendBlock() void { | ... | @@ -191,7 +191,7 @@ async fn testSuspendBlock() void { |
| 191 | 191 | ||
| 192 | // Test to make sure that @frame() works as advertised (issue #1296) | 192 | // Test to make sure that @frame() works as advertised (issue #1296) |
| 193 | // var our_handle: anyframe = @frame(); | 193 | // var our_handle: anyframe = @frame(); |
| 194 | expect(a_promise == anyframe(@frame())); | 194 | expect(a_promise == @as(anyframe, @frame())); |
| 195 | 195 | ||
| 196 | global_result = true; | 196 | global_result = true; |
| 197 | } | 197 | } |
| ... | @@ -543,7 +543,7 @@ test "pass string literal to async function" { | ... | @@ -543,7 +543,7 @@ test "pass string literal to async function" { |
| 543 | fn hello(msg: []const u8) void { | 543 | fn hello(msg: []const u8) void { |
| 544 | frame = @frame(); | 544 | frame = @frame(); |
| 545 | suspend; | 545 | suspend; |
| 546 | expectEqual(([]const u8)("hello"), msg); | 546 | expectEqual(@as([]const u8, "hello"), msg); |
| 547 | ok = true; | 547 | ok = true; |
| 548 | } | 548 | } |
| 549 | }; | 549 | }; |
| ... | @@ -1048,7 +1048,7 @@ test "using @typeOf on a generic function call" { | ... | @@ -1048,7 +1048,7 @@ test "using @typeOf on a generic function call" { |
| 1048 | return await @asyncCall(frame, {}, amain, x - 1); | 1048 | return await @asyncCall(frame, {}, amain, x - 1); |
| 1049 | } | 1049 | } |
| 1050 | }; | 1050 | }; |
| 1051 | _ = async S.amain(u32(1)); | 1051 | _ = async S.amain(@as(u32, 1)); |
| 1052 | resume S.global_frame; | 1052 | resume S.global_frame; |
| 1053 | expect(S.global_ok); | 1053 | expect(S.global_ok); |
| 1054 | } | 1054 | } |
| ... | @@ -1080,8 +1080,8 @@ test "recursive call of await @asyncCall with struct return type" { | ... | @@ -1080,8 +1080,8 @@ test "recursive call of await @asyncCall with struct return type" { |
| 1080 | }; | 1080 | }; |
| 1081 | }; | 1081 | }; |
| 1082 | var res: S.Foo = undefined; | 1082 | var res: S.Foo = undefined; |
| 1083 | var frame: @typeOf(async S.amain(u32(1))) = undefined; | 1083 | var frame: @typeOf(async S.amain(@as(u32, 1))) = undefined; |
| 1084 | _ = @asyncCall(&frame, &res, S.amain, u32(1)); | 1084 | _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1)); |
| 1085 | resume S.global_frame; | 1085 | resume S.global_frame; |
| 1086 | expect(S.global_ok); | 1086 | expect(S.global_ok); |
| 1087 | expect(res.x == 1); | 1087 | expect(res.x == 1); |
test/stage1/behavior/atomics.zig+3-3| ... | @@ -98,12 +98,12 @@ test "cmpxchg with ignored result" { | ... | @@ -98,12 +98,12 @@ test "cmpxchg with ignored result" { |
| 98 | 98 | ||
| 99 | _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic); | 99 | _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic); |
| 100 | 100 | ||
| 101 | expectEqual(i32(5678), x); | 101 | expectEqual(@as(i32, 5678), x); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | var a_global_variable = u32(1234); | 104 | var a_global_variable = @as(u32, 1234); |
| 105 | 105 | ||
| 106 | test "cmpxchg on a global variable" { | 106 | test "cmpxchg on a global variable" { |
| 107 | _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic); | 107 | _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic); |
| 108 | expectEqual(u32(42), a_global_variable); | 108 | expectEqual(@as(u32, 42), a_global_variable); |
| 109 | } | 109 | } |
test/stage1/behavior/bitreverse.zig+14-14| ... | @@ -46,24 +46,24 @@ fn testBitReverse() void { | ... | @@ -46,24 +46,24 @@ fn testBitReverse() void { |
| 46 | expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48); | 46 | expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48); |
| 47 | 47 | ||
| 48 | // using comptime_ints, signed, positive | 48 | // using comptime_ints, signed, positive |
| 49 | expect(@bitReverse(u8, u8(0)) == 0); | 49 | expect(@bitReverse(u8, @as(u8, 0)) == 0); |
| 50 | expect(@bitReverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49))); | 50 | expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49))); |
| 51 | expect(@bitReverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48))); | 51 | expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48))); |
| 52 | expect(@bitReverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48))); | 52 | expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48))); |
| 53 | expect(@bitReverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48))); | 53 | expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48))); |
| 54 | expect(@bitReverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48))); | 54 | expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48))); |
| 55 | expect(@bitReverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48))); | 55 | expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48))); |
| 56 | expect(@bitReverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48))); | 56 | expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48))); |
| 57 | expect(@bitReverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48))); | 57 | expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48))); |
| 58 | expect(@bitReverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48))); | 58 | expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48))); |
| 59 | 59 | ||
| 60 | // using signed, negative. Compare to runtime ints returned from llvm. | 60 | // using signed, negative. Compare to runtime ints returned from llvm. |
| 61 | var neg8: i8 = -18; | 61 | var neg8: i8 = -18; |
| 62 | expect(@bitReverse(i8, i8(-18)) == @bitReverse(i8, neg8)); | 62 | expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8)); |
| 63 | var neg16: i16 = -32694; | 63 | var neg16: i16 = -32694; |
| 64 | expect(@bitReverse(i16, i16(-32694)) == @bitReverse(i16, neg16)); | 64 | expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16)); |
| 65 | var neg24: i24 = -6773785; | 65 | var neg24: i24 = -6773785; |
| 66 | expect(@bitReverse(i24, i24(-6773785)) == @bitReverse(i24, neg24)); | 66 | expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24)); |
| 67 | var neg32: i32 = -16773785; | 67 | var neg32: i32 = -16773785; |
| 68 | expect(@bitReverse(i32, i32(-16773785)) == @bitReverse(i32, neg32)); | 68 | expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32)); |
| 69 | } | 69 | } |
test/stage1/behavior/bool.zig+4-4| ... | @@ -8,14 +8,14 @@ test "bool literals" { | ... | @@ -8,14 +8,14 @@ test "bool literals" { |
| 8 | test "cast bool to int" { | 8 | test "cast bool to int" { |
| 9 | const t = true; | 9 | const t = true; |
| 10 | const f = false; | 10 | const f = false; |
| 11 | expect(@boolToInt(t) == u32(1)); | 11 | expect(@boolToInt(t) == @as(u32, 1)); |
| 12 | expect(@boolToInt(f) == u32(0)); | 12 | expect(@boolToInt(f) == @as(u32, 0)); |
| 13 | nonConstCastBoolToInt(t, f); | 13 | nonConstCastBoolToInt(t, f); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn nonConstCastBoolToInt(t: bool, f: bool) void { | 16 | fn nonConstCastBoolToInt(t: bool, f: bool) void { |
| 17 | expect(@boolToInt(t) == u32(1)); | 17 | expect(@boolToInt(t) == @as(u32, 1)); |
| 18 | expect(@boolToInt(f) == u32(0)); | 18 | expect(@boolToInt(f) == @as(u32, 0)); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | test "bool cmp" { | 21 | test "bool cmp" { |
test/stage1/behavior/bugs/1322.zig+2-2| ... | @@ -13,7 +13,7 @@ const C = struct {}; | ... | @@ -13,7 +13,7 @@ const C = struct {}; |
| 13 | 13 | ||
| 14 | test "tagged union with all void fields but a meaningful tag" { | 14 | test "tagged union with all void fields but a meaningful tag" { |
| 15 | var a: A = A{ .b = B{ .c = C{} } }; | 15 | var a: A = A{ .b = B{ .c = C{} } }; |
| 16 | std.testing.expect(@TagType(B)(a.b) == @TagType(B).c); | 16 | std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).c); |
| 17 | a = A{ .b = B.None }; | 17 | a = A{ .b = B.None }; |
| 18 | std.testing.expect(@TagType(B)(a.b) == @TagType(B).None); | 18 | std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).None); |
| 19 | } | 19 | } |
test/stage1/behavior/bugs/1421.zig+1-1| ... | @@ -10,5 +10,5 @@ const S = struct { | ... | @@ -10,5 +10,5 @@ const S = struct { |
| 10 | 10 | ||
| 11 | test "functions with return type required to be comptime are generic" { | 11 | test "functions with return type required to be comptime are generic" { |
| 12 | const ti = S.method(); | 12 | const ti = S.method(); |
| 13 | expect(builtin.TypeId(ti) == builtin.TypeId.Struct); | 13 | expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct); |
| 14 | } | 14 | } |
test/stage1/behavior/bugs/2114.zig+4-4| ... | @@ -12,8 +12,8 @@ test "fixed" { | ... | @@ -12,8 +12,8 @@ test "fixed" { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | fn testClz() void { | 14 | fn testClz() void { |
| 15 | expect(ctz(u128(0x40000000000000000000000000000000)) == 126); | 15 | expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126); |
| 16 | expect(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1)) == u128(0x80000000000000000000000000000000)); | 16 | expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000)); |
| 17 | expect(ctz(u128(0x80000000000000000000000000000000)) == 127); | 17 | expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127); |
| 18 | expect(ctz(math.rotl(u128, u128(0x40000000000000000000000000000000), u8(1))) == 127); | 18 | expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127); |
| 19 | } | 19 | } |
test/stage1/behavior/bugs/3046.zig+1-1| ... | @@ -13,7 +13,7 @@ var some_struct: SomeStruct = undefined; | ... | @@ -13,7 +13,7 @@ var some_struct: SomeStruct = undefined; |
| 13 | 13 | ||
| 14 | test "fixed" { | 14 | test "fixed" { |
| 15 | some_struct = SomeStruct{ | 15 | some_struct = SomeStruct{ |
| 16 | .field = couldFail() catch |_| i32(0), | 16 | .field = couldFail() catch |_| @as(i32, 0), |
| 17 | }; | 17 | }; |
| 18 | expect(some_struct.field == 1); | 18 | expect(some_struct.field == 1); |
| 19 | } | 19 | } |
test/stage1/behavior/byteswap.zig+12-12| ... | @@ -11,24 +11,24 @@ test "@byteSwap integers" { | ... | @@ -11,24 +11,24 @@ test "@byteSwap integers" { |
| 11 | t(u24, 0x123456, 0x563412); | 11 | t(u24, 0x123456, 0x563412); |
| 12 | t(u32, 0x12345678, 0x78563412); | 12 | t(u32, 0x12345678, 0x78563412); |
| 13 | t(u40, 0x123456789a, 0x9a78563412); | 13 | t(u40, 0x123456789a, 0x9a78563412); |
| 14 | t(i48, 0x123456789abc, @bitCast(i48, u48(0xbc9a78563412))); | 14 | t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412))); |
| 15 | t(u56, 0x123456789abcde, 0xdebc9a78563412); | 15 | t(u56, 0x123456789abcde, 0xdebc9a78563412); |
| 16 | t(u64, 0x123456789abcdef1, 0xf1debc9a78563412); | 16 | t(u64, 0x123456789abcdef1, 0xf1debc9a78563412); |
| 17 | t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412); | 17 | t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412); |
| 18 | 18 | ||
| 19 | t(u0, u0(0), 0); | 19 | t(u0, @as(u0, 0), 0); |
| 20 | t(i8, i8(-50), -50); | 20 | t(i8, @as(i8, -50), -50); |
| 21 | t(i16, @bitCast(i16, u16(0x1234)), @bitCast(i16, u16(0x3412))); | 21 | t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412))); |
| 22 | t(i24, @bitCast(i24, u24(0x123456)), @bitCast(i24, u24(0x563412))); | 22 | t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412))); |
| 23 | t(i32, @bitCast(i32, u32(0x12345678)), @bitCast(i32, u32(0x78563412))); | 23 | t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412))); |
| 24 | t(u40, @bitCast(i40, u40(0x123456789a)), u40(0x9a78563412)); | 24 | t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412)); |
| 25 | t(i48, @bitCast(i48, u48(0x123456789abc)), @bitCast(i48, u48(0xbc9a78563412))); | 25 | t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412))); |
| 26 | t(i56, @bitCast(i56, u56(0x123456789abcde)), @bitCast(i56, u56(0xdebc9a78563412))); | 26 | t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412))); |
| 27 | t(i64, @bitCast(i64, u64(0x123456789abcdef1)), @bitCast(i64, u64(0xf1debc9a78563412))); | 27 | t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412))); |
| 28 | t( | 28 | t( |
| 29 | i128, | 29 | i128, |
| 30 | @bitCast(i128, u128(0x123456789abcdef11121314151617181)), | 30 | @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)), |
| 31 | @bitCast(i128, u128(0x8171615141312111f1debc9a78563412)), | 31 | @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)), |
| 32 | ); | 32 | ); |
| 33 | } | 33 | } |
| 34 | fn t(comptime I: type, input: I, expected_output: I) void { | 34 | fn t(comptime I: type, input: I, expected_output: I) void { |
test/stage1/behavior/cast.zig+12-12| ... | @@ -4,7 +4,7 @@ const mem = std.mem; | ... | @@ -4,7 +4,7 @@ const mem = std.mem; |
| 4 | const maxInt = std.math.maxInt; | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | ||
| 6 | test "int to ptr cast" { | 6 | test "int to ptr cast" { |
| 7 | const x = usize(13); | 7 | const x = @as(usize, 13); |
| 8 | const y = @intToPtr(*u8, x); | 8 | const y = @intToPtr(*u8, x); |
| 9 | const z = @ptrToInt(y); | 9 | const z = @ptrToInt(y); |
| 10 | expect(z == 13); | 10 | expect(z == 13); |
| ... | @@ -75,8 +75,8 @@ test "peer resolve array and const slice" { | ... | @@ -75,8 +75,8 @@ test "peer resolve array and const slice" { |
| 75 | comptime testPeerResolveArrayConstSlice(true); | 75 | comptime testPeerResolveArrayConstSlice(true); |
| 76 | } | 76 | } |
| 77 | fn testPeerResolveArrayConstSlice(b: bool) void { | 77 | fn testPeerResolveArrayConstSlice(b: bool) void { |
| 78 | const value1 = if (b) "aoeu" else ([]const u8)("zz"); | 78 | const value1 = if (b) "aoeu" else @as([]const u8, "zz"); |
| 79 | const value2 = if (b) ([]const u8)("zz") else "aoeu"; | 79 | const value2 = if (b) @as([]const u8, "zz") else "aoeu"; |
| 80 | expect(mem.eql(u8, value1, "aoeu")); | 80 | expect(mem.eql(u8, value1, "aoeu")); |
| 81 | expect(mem.eql(u8, value2, "zz")); | 81 | expect(mem.eql(u8, value2, "zz")); |
| 82 | } | 82 | } |
| ... | @@ -90,7 +90,7 @@ const A = struct { | ... | @@ -90,7 +90,7 @@ const A = struct { |
| 90 | a: i32, | 90 | a: i32, |
| 91 | }; | 91 | }; |
| 92 | fn castToOptionalTypeError(z: i32) void { | 92 | fn castToOptionalTypeError(z: i32) void { |
| 93 | const x = i32(1); | 93 | const x = @as(i32, 1); |
| 94 | const y: anyerror!?i32 = x; | 94 | const y: anyerror!?i32 = x; |
| 95 | expect((try y).? == 1); | 95 | expect((try y).? == 1); |
| 96 | 96 | ||
| ... | @@ -134,10 +134,10 @@ test "peer type resolution: ?T and T" { | ... | @@ -134,10 +134,10 @@ test "peer type resolution: ?T and T" { |
| 134 | } | 134 | } |
| 135 | fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { | 135 | fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| 136 | if (c) { | 136 | if (c) { |
| 137 | return if (b) null else usize(0); | 137 | return if (b) null else @as(usize, 0); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | return usize(3); | 140 | return @as(usize, 3); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | test "peer type resolution: [0]u8 and []const u8" { | 143 | test "peer type resolution: [0]u8 and []const u8" { |
| ... | @@ -256,9 +256,9 @@ test "@floatToInt" { | ... | @@ -256,9 +256,9 @@ test "@floatToInt" { |
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | fn testFloatToInts() void { | 258 | fn testFloatToInts() void { |
| 259 | const x = i32(1e4); | 259 | const x = @as(i32, 1e4); |
| 260 | expect(x == 10000); | 260 | expect(x == 10000); |
| 261 | const y = @floatToInt(i32, f32(1e4)); | 261 | const y = @floatToInt(i32, @as(f32, 1e4)); |
| 262 | expect(y == 10000); | 262 | expect(y == 10000); |
| 263 | expectFloatToInt(f16, 255.1, u8, 255); | 263 | expectFloatToInt(f16, 255.1, u8, 255); |
| 264 | expectFloatToInt(f16, 127.2, i8, 127); | 264 | expectFloatToInt(f16, 127.2, i8, 127); |
| ... | @@ -392,7 +392,7 @@ fn MakeType(comptime T: type) type { | ... | @@ -392,7 +392,7 @@ fn MakeType(comptime T: type) type { |
| 392 | } | 392 | } |
| 393 | 393 | ||
| 394 | fn getNonNull() ?T { | 394 | fn getNonNull() ?T { |
| 395 | return T(undefined); | 395 | return @as(T, undefined); |
| 396 | } | 396 | } |
| 397 | }; | 397 | }; |
| 398 | } | 398 | } |
| ... | @@ -442,7 +442,7 @@ fn incrementVoidPtrArray(array: ?*c_void, len: usize) void { | ... | @@ -442,7 +442,7 @@ fn incrementVoidPtrArray(array: ?*c_void, len: usize) void { |
| 442 | } | 442 | } |
| 443 | 443 | ||
| 444 | test "*usize to *void" { | 444 | test "*usize to *void" { |
| 445 | var i = usize(0); | 445 | var i = @as(usize, 0); |
| 446 | var v = @ptrCast(*void, &i); | 446 | var v = @ptrCast(*void, &i); |
| 447 | v.* = {}; | 447 | v.* = {}; |
| 448 | } | 448 | } |
| ... | @@ -535,12 +535,12 @@ test "peer type resolution: unreachable, error set, unreachable" { | ... | @@ -535,12 +535,12 @@ test "peer type resolution: unreachable, error set, unreachable" { |
| 535 | } | 535 | } |
| 536 | 536 | ||
| 537 | test "implicit cast comptime_int to comptime_float" { | 537 | test "implicit cast comptime_int to comptime_float" { |
| 538 | comptime expect(comptime_float(10) == f32(10)); | 538 | comptime expect(@as(comptime_float, 10) == @as(f32, 10)); |
| 539 | expect(2 == 2.0); | 539 | expect(2 == 2.0); |
| 540 | } | 540 | } |
| 541 | 541 | ||
| 542 | test "implicit cast *[0]T to E![]const u8" { | 542 | test "implicit cast *[0]T to E![]const u8" { |
| 543 | var x = (anyerror![]const u8)(&[0]u8{}); | 543 | var x = @as(anyerror![]const u8, &[0]u8{}); |
| 544 | expect((x catch unreachable).len == 0); | 544 | expect((x catch unreachable).len == 0); |
| 545 | } | 545 | } |
| 546 | 546 |
test/stage1/behavior/defer.zig+1-1| ... | @@ -52,7 +52,7 @@ fn testBreakContInDefer(x: usize) void { | ... | @@ -52,7 +52,7 @@ fn testBreakContInDefer(x: usize) void { |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | test "defer and labeled break" { | 54 | test "defer and labeled break" { |
| 55 | var i = usize(0); | 55 | var i = @as(usize, 0); |
| 56 | 56 | ||
| 57 | blk: { | 57 | blk: { |
| 58 | defer i += 1; | 58 | defer i += 1; |
test/stage1/behavior/enum.zig+2-2| ... | @@ -788,7 +788,7 @@ fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void { | ... | @@ -788,7 +788,7 @@ fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void { |
| 788 | expect(1234 == switch (x) { | 788 | expect(1234 == switch (x) { |
| 789 | MultipleChoice.A => 1, | 789 | MultipleChoice.A => 1, |
| 790 | MultipleChoice.B => 2, | 790 | MultipleChoice.B => 2, |
| 791 | MultipleChoice.C => u32(1234), | 791 | MultipleChoice.C => @as(u32, 1234), |
| 792 | MultipleChoice.D => 4, | 792 | MultipleChoice.D => 4, |
| 793 | }); | 793 | }); |
| 794 | } | 794 | } |
| ... | @@ -816,7 +816,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { | ... | @@ -816,7 +816,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 816 | MultipleChoice2.A => 1, | 816 | MultipleChoice2.A => 1, |
| 817 | MultipleChoice2.B => 2, | 817 | MultipleChoice2.B => 2, |
| 818 | MultipleChoice2.C => 3, | 818 | MultipleChoice2.C => 3, |
| 819 | MultipleChoice2.D => u32(1234), | 819 | MultipleChoice2.D => @as(u32, 1234), |
| 820 | MultipleChoice2.Unspecified1 => 5, | 820 | MultipleChoice2.Unspecified1 => 5, |
| 821 | MultipleChoice2.Unspecified2 => 6, | 821 | MultipleChoice2.Unspecified2 => 6, |
| 822 | MultipleChoice2.Unspecified3 => 7, | 822 | MultipleChoice2.Unspecified3 => 7, |
test/stage1/behavior/error.zig+2-2| ... | @@ -51,7 +51,7 @@ test "error binary operator" { | ... | @@ -51,7 +51,7 @@ test "error binary operator" { |
| 51 | expect(b == 10); | 51 | expect(b == 10); |
| 52 | } | 52 | } |
| 53 | fn errBinaryOperatorG(x: bool) anyerror!isize { | 53 | fn errBinaryOperatorG(x: bool) anyerror!isize { |
| 54 | return if (x) error.ItBroke else isize(10); | 54 | return if (x) error.ItBroke else @as(isize, 10); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | test "unwrap simple value from error" { | 57 | test "unwrap simple value from error" { |
| ... | @@ -295,7 +295,7 @@ test "nested error union function call in optional unwrap" { | ... | @@ -295,7 +295,7 @@ test "nested error union function call in optional unwrap" { |
| 295 | test "widen cast integer payload of error union function call" { | 295 | test "widen cast integer payload of error union function call" { |
| 296 | const S = struct { | 296 | const S = struct { |
| 297 | fn errorable() !u64 { | 297 | fn errorable() !u64 { |
| 298 | var x = u64(try number()); | 298 | var x = @as(u64, try number()); |
| 299 | return x; | 299 | return x; |
| 300 | } | 300 | } |
| 301 | 301 |
test/stage1/behavior/eval.zig+18-18| ... | @@ -405,19 +405,19 @@ test "float literal at compile time not lossy" { | ... | @@ -405,19 +405,19 @@ test "float literal at compile time not lossy" { |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | test "f32 at compile time is lossy" { | 407 | test "f32 at compile time is lossy" { |
| 408 | expect(f32(1 << 24) + 1 == 1 << 24); | 408 | expect(@as(f32, 1 << 24) + 1 == 1 << 24); |
| 409 | } | 409 | } |
| 410 | 410 | ||
| 411 | test "f64 at compile time is lossy" { | 411 | test "f64 at compile time is lossy" { |
| 412 | expect(f64(1 << 53) + 1 == 1 << 53); | 412 | expect(@as(f64, 1 << 53) + 1 == 1 << 53); |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | test "f128 at compile time is lossy" { | 415 | test "f128 at compile time is lossy" { |
| 416 | expect(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); | 416 | expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); |
| 417 | } | 417 | } |
| 418 | 418 | ||
| 419 | comptime { | 419 | comptime { |
| 420 | expect(f128(1 << 113) == 10384593717069655257060992658440192); | 420 | expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192); |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { | 423 | pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { |
| ... | @@ -434,9 +434,9 @@ test "string literal used as comptime slice is memoized" { | ... | @@ -434,9 +434,9 @@ test "string literal used as comptime slice is memoized" { |
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | test "comptime slice of undefined pointer of length 0" { | 436 | test "comptime slice of undefined pointer of length 0" { |
| 437 | const slice1 = ([*]i32)(undefined)[0..0]; | 437 | const slice1 = @as([*]i32, undefined)[0..0]; |
| 438 | expect(slice1.len == 0); | 438 | expect(slice1.len == 0); |
| 439 | const slice2 = ([*]i32)(undefined)[100..100]; | 439 | const slice2 = @as([*]i32, undefined)[100..100]; |
| 440 | expect(slice2.len == 0); | 440 | expect(slice2.len == 0); |
| 441 | } | 441 | } |
| 442 | 442 | ||
| ... | @@ -444,10 +444,10 @@ fn copyWithPartialInline(s: []u32, b: []u8) void { | ... | @@ -444,10 +444,10 @@ fn copyWithPartialInline(s: []u32, b: []u8) void { |
| 444 | comptime var i: usize = 0; | 444 | comptime var i: usize = 0; |
| 445 | inline while (i < 4) : (i += 1) { | 445 | inline while (i < 4) : (i += 1) { |
| 446 | s[i] = 0; | 446 | s[i] = 0; |
| 447 | s[i] |= u32(b[i * 4 + 0]) << 24; | 447 | s[i] |= @as(u32, b[i * 4 + 0]) << 24; |
| 448 | s[i] |= u32(b[i * 4 + 1]) << 16; | 448 | s[i] |= @as(u32, b[i * 4 + 1]) << 16; |
| 449 | s[i] |= u32(b[i * 4 + 2]) << 8; | 449 | s[i] |= @as(u32, b[i * 4 + 2]) << 8; |
| 450 | s[i] |= u32(b[i * 4 + 3]) << 0; | 450 | s[i] |= @as(u32, b[i * 4 + 3]) << 0; |
| 451 | } | 451 | } |
| 452 | } | 452 | } |
| 453 | 453 | ||
| ... | @@ -557,14 +557,14 @@ test "array concat of slices gives slice" { | ... | @@ -557,14 +557,14 @@ test "array concat of slices gives slice" { |
| 557 | 557 | ||
| 558 | test "comptime shlWithOverflow" { | 558 | test "comptime shlWithOverflow" { |
| 559 | const ct_shifted: u64 = comptime amt: { | 559 | const ct_shifted: u64 = comptime amt: { |
| 560 | var amt = u64(0); | 560 | var amt = @as(u64, 0); |
| 561 | _ = @shlWithOverflow(u64, ~u64(0), 16, &amt); | 561 | _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt); |
| 562 | break :amt amt; | 562 | break :amt amt; |
| 563 | }; | 563 | }; |
| 564 | 564 | ||
| 565 | const rt_shifted: u64 = amt: { | 565 | const rt_shifted: u64 = amt: { |
| 566 | var amt = u64(0); | 566 | var amt = @as(u64, 0); |
| 567 | _ = @shlWithOverflow(u64, ~u64(0), 16, &amt); | 567 | _ = @shlWithOverflow(u64, ~@as(u64, 0), 16, &amt); |
| 568 | break :amt amt; | 568 | break :amt amt; |
| 569 | }; | 569 | }; |
| 570 | 570 | ||
| ... | @@ -670,7 +670,7 @@ fn loopNTimes(comptime n: usize) void { | ... | @@ -670,7 +670,7 @@ fn loopNTimes(comptime n: usize) void { |
| 670 | } | 670 | } |
| 671 | 671 | ||
| 672 | test "variable inside inline loop that has different types on different iterations" { | 672 | test "variable inside inline loop that has different types on different iterations" { |
| 673 | testVarInsideInlineLoop(true, u32(42)); | 673 | testVarInsideInlineLoop(true, @as(u32, 42)); |
| 674 | } | 674 | } |
| 675 | 675 | ||
| 676 | fn testVarInsideInlineLoop(args: ...) void { | 676 | fn testVarInsideInlineLoop(args: ...) void { |
| ... | @@ -757,11 +757,11 @@ test "comptime bitwise operators" { | ... | @@ -757,11 +757,11 @@ test "comptime bitwise operators" { |
| 757 | expect(-3 | -1 == -1); | 757 | expect(-3 | -1 == -1); |
| 758 | expect(3 ^ -1 == -4); | 758 | expect(3 ^ -1 == -4); |
| 759 | expect(-3 ^ -1 == 2); | 759 | expect(-3 ^ -1 == 2); |
| 760 | expect(~i8(-1) == 0); | 760 | expect(~@as(i8, -1) == 0); |
| 761 | expect(~i128(-1) == 0); | 761 | expect(~@as(i128, -1) == 0); |
| 762 | expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611); | 762 | expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611); |
| 763 | expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615); | 763 | expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615); |
| 764 | expect(~u128(0) == 0xffffffffffffffffffffffffffffffff); | 764 | expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff); |
| 765 | } | 765 | } |
| 766 | } | 766 | } |
| 767 | 767 |
test/stage1/behavior/floatop.zig+2-2| ... | @@ -117,11 +117,11 @@ test "@ln" { | ... | @@ -117,11 +117,11 @@ test "@ln" { |
| 117 | fn testLn() void { | 117 | fn testLn() void { |
| 118 | { | 118 | { |
| 119 | var a: f32 = e; | 119 | var a: f32 = e; |
| 120 | expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, u32(0x3f7fffff))); | 120 | expect(@ln(f32, a) == 1 or @ln(f32, a) == @bitCast(f32, @as(u32, 0x3f7fffff))); |
| 121 | } | 121 | } |
| 122 | { | 122 | { |
| 123 | var a: f64 = e; | 123 | var a: f64 = e; |
| 124 | expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, u64(0x3ff0000000000000))); | 124 | expect(@ln(f64, a) == 1 or @ln(f64, a) == @bitCast(f64, @as(u64, 0x3ff0000000000000))); |
| 125 | } | 125 | } |
| 126 | } | 126 | } |
| 127 | 127 |
test/stage1/behavior/fn.zig+2-2| ... | @@ -29,7 +29,7 @@ test "mutable local variables" { | ... | @@ -29,7 +29,7 @@ test "mutable local variables" { |
| 29 | var zero: i32 = 0; | 29 | var zero: i32 = 0; |
| 30 | expect(zero == 0); | 30 | expect(zero == 0); |
| 31 | 31 | ||
| 32 | var i = i32(0); | 32 | var i = @as(i32, 0); |
| 33 | while (i != 3) { | 33 | while (i != 3) { |
| 34 | i += 1; | 34 | i += 1; |
| 35 | } | 35 | } |
| ... | @@ -43,7 +43,7 @@ test "separate block scopes" { | ... | @@ -43,7 +43,7 @@ test "separate block scopes" { |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | const c = x: { | 45 | const c = x: { |
| 46 | const no_conflict = i32(10); | 46 | const no_conflict = @as(i32, 10); |
| 47 | break :x no_conflict; | 47 | break :x no_conflict; |
| 48 | }; | 48 | }; |
| 49 | expect(c == 10); | 49 | expect(c == 10); |
test/stage1/behavior/if.zig+2-2| ... | @@ -32,7 +32,7 @@ fn elseIfExpressionF(c: u8) u8 { | ... | @@ -32,7 +32,7 @@ fn elseIfExpressionF(c: u8) u8 { |
| 32 | } else if (c == 1) { | 32 | } else if (c == 1) { |
| 33 | return 1; | 33 | return 1; |
| 34 | } else { | 34 | } else { |
| 35 | return u8(2); | 35 | return @as(u8, 2); |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | 38 | ||
| ... | @@ -58,7 +58,7 @@ test "labeled break inside comptime if inside runtime if" { | ... | @@ -58,7 +58,7 @@ test "labeled break inside comptime if inside runtime if" { |
| 58 | var c = true; | 58 | var c = true; |
| 59 | if (c) { | 59 | if (c) { |
| 60 | answer = if (true) blk: { | 60 | answer = if (true) blk: { |
| 61 | break :blk i32(42); | 61 | break :blk @as(i32, 42); |
| 62 | }; | 62 | }; |
| 63 | } | 63 | } |
| 64 | expect(answer == 42); | 64 | expect(answer == 42); |
test/stage1/behavior/import.zig+2-2| ... | @@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual; | ... | @@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual; |
| 3 | const a_namespace = @import("import/a_namespace.zig"); | 3 | const a_namespace = @import("import/a_namespace.zig"); |
| 4 | 4 | ||
| 5 | test "call fn via namespace lookup" { | 5 | test "call fn via namespace lookup" { |
| 6 | expectEqual(i32(1234), a_namespace.foo()); | 6 | expectEqual(@as(i32, 1234), a_namespace.foo()); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | test "importing the same thing gives the same import" { | 9 | test "importing the same thing gives the same import" { |
| ... | @@ -14,5 +14,5 @@ test "import in non-toplevel scope" { | ... | @@ -14,5 +14,5 @@ test "import in non-toplevel scope" { |
| 14 | const S = struct { | 14 | const S = struct { |
| 15 | usingnamespace @import("import/a_namespace.zig"); | 15 | usingnamespace @import("import/a_namespace.zig"); |
| 16 | }; | 16 | }; |
| 17 | expectEqual(i32(1234), S.foo()); | 17 | expectEqual(@as(i32, 1234), S.foo()); |
| 18 | } | 18 | } |
test/stage1/behavior/math.zig+12-12| ... | @@ -186,9 +186,9 @@ fn testThreeExprInARow(f: bool, t: bool) void { | ... | @@ -186,9 +186,9 @@ fn testThreeExprInARow(f: bool, t: bool) void { |
| 186 | assertFalse(90 >> 1 >> 2 != 90 >> 3); | 186 | assertFalse(90 >> 1 >> 2 != 90 >> 3); |
| 187 | assertFalse(100 - 1 + 1000 != 1099); | 187 | assertFalse(100 - 1 + 1000 != 1099); |
| 188 | assertFalse(5 * 4 / 2 % 3 != 1); | 188 | assertFalse(5 * 4 / 2 % 3 != 1); |
| 189 | assertFalse(i32(i32(5)) != 5); | 189 | assertFalse(@as(i32, @as(i32, 5)) != 5); |
| 190 | assertFalse(!!false); | 190 | assertFalse(!!false); |
| 191 | assertFalse(i32(7) != --(i32(7))); | 191 | assertFalse(@as(i32, 7) != --(@as(i32, 7))); |
| 192 | } | 192 | } |
| 193 | fn assertFalse(b: bool) void { | 193 | fn assertFalse(b: bool) void { |
| 194 | expect(!b); | 194 | expect(!b); |
| ... | @@ -256,10 +256,10 @@ const DivResult = struct { | ... | @@ -256,10 +256,10 @@ const DivResult = struct { |
| 256 | 256 | ||
| 257 | test "binary not" { | 257 | test "binary not" { |
| 258 | expect(comptime x: { | 258 | expect(comptime x: { |
| 259 | break :x ~u16(0b1010101010101010) == 0b0101010101010101; | 259 | break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101; |
| 260 | }); | 260 | }); |
| 261 | expect(comptime x: { | 261 | expect(comptime x: { |
| 262 | break :x ~u64(2147483647) == 18446744071562067968; | 262 | break :x ~@as(u64, 2147483647) == 18446744071562067968; |
| 263 | }); | 263 | }); |
| 264 | testBinaryNot(0b1010101010101010); | 264 | testBinaryNot(0b1010101010101010); |
| 265 | } | 265 | } |
| ... | @@ -472,7 +472,7 @@ test "comptime_int multiplication" { | ... | @@ -472,7 +472,7 @@ test "comptime_int multiplication" { |
| 472 | 472 | ||
| 473 | test "comptime_int shifting" { | 473 | test "comptime_int shifting" { |
| 474 | comptime { | 474 | comptime { |
| 475 | expect((u128(1) << 127) == 0x80000000000000000000000000000000); | 475 | expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000); |
| 476 | } | 476 | } |
| 477 | } | 477 | } |
| 478 | 478 | ||
| ... | @@ -480,13 +480,13 @@ test "comptime_int multi-limb shift and mask" { | ... | @@ -480,13 +480,13 @@ test "comptime_int multi-limb shift and mask" { |
| 480 | comptime { | 480 | comptime { |
| 481 | var a = 0xefffffffa0000001eeeeeeefaaaaaaab; | 481 | var a = 0xefffffffa0000001eeeeeeefaaaaaaab; |
| 482 | 482 | ||
| 483 | expect(u32(a & 0xffffffff) == 0xaaaaaaab); | 483 | expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab); |
| 484 | a >>= 32; | 484 | a >>= 32; |
| 485 | expect(u32(a & 0xffffffff) == 0xeeeeeeef); | 485 | expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef); |
| 486 | a >>= 32; | 486 | a >>= 32; |
| 487 | expect(u32(a & 0xffffffff) == 0xa0000001); | 487 | expect(@as(u32, a & 0xffffffff) == 0xa0000001); |
| 488 | a >>= 32; | 488 | a >>= 32; |
| 489 | expect(u32(a & 0xffffffff) == 0xefffffff); | 489 | expect(@as(u32, a & 0xffffffff) == 0xefffffff); |
| 490 | a >>= 32; | 490 | a >>= 32; |
| 491 | 491 | ||
| 492 | expect(a == 0); | 492 | expect(a == 0); |
| ... | @@ -552,7 +552,7 @@ fn should_not_be_zero(x: f128) void { | ... | @@ -552,7 +552,7 @@ fn should_not_be_zero(x: f128) void { |
| 552 | 552 | ||
| 553 | test "comptime float rem int" { | 553 | test "comptime float rem int" { |
| 554 | comptime { | 554 | comptime { |
| 555 | var x = f32(1) % 2; | 555 | var x = @as(f32, 1) % 2; |
| 556 | expect(x == 1.0); | 556 | expect(x == 1.0); |
| 557 | } | 557 | } |
| 558 | } | 558 | } |
| ... | @@ -568,8 +568,8 @@ test "remainder division" { | ... | @@ -568,8 +568,8 @@ test "remainder division" { |
| 568 | } | 568 | } |
| 569 | 569 | ||
| 570 | fn remdiv(comptime T: type) void { | 570 | fn remdiv(comptime T: type) void { |
| 571 | expect(T(1) == T(1) % T(2)); | 571 | expect(@as(T, 1) == @as(T, 1) % @as(T, 2)); |
| 572 | expect(T(1) == T(7) % T(3)); | 572 | expect(@as(T, 1) == @as(T, 7) % @as(T, 3)); |
| 573 | } | 573 | } |
| 574 | 574 | ||
| 575 | test "@sqrt" { | 575 | test "@sqrt" { |
test/stage1/behavior/misc.zig+8-8| ... | @@ -241,14 +241,14 @@ fn memFree(comptime T: type, memory: []T) void {} | ... | @@ -241,14 +241,14 @@ fn memFree(comptime T: type, memory: []T) void {} |
| 241 | 241 | ||
| 242 | test "cast undefined" { | 242 | test "cast undefined" { |
| 243 | const array: [100]u8 = undefined; | 243 | const array: [100]u8 = undefined; |
| 244 | const slice = ([]const u8)(array); | 244 | const slice = @as([]const u8, array); |
| 245 | testCastUndefined(slice); | 245 | testCastUndefined(slice); |
| 246 | } | 246 | } |
| 247 | fn testCastUndefined(x: []const u8) void {} | 247 | fn testCastUndefined(x: []const u8) void {} |
| 248 | 248 | ||
| 249 | test "cast small unsigned to larger signed" { | 249 | test "cast small unsigned to larger signed" { |
| 250 | expect(castSmallUnsignedToLargerSigned1(200) == i16(200)); | 250 | expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200)); |
| 251 | expect(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); | 251 | expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999)); |
| 252 | } | 252 | } |
| 253 | fn castSmallUnsignedToLargerSigned1(x: u8) i16 { | 253 | fn castSmallUnsignedToLargerSigned1(x: u8) i16 { |
| 254 | return x; | 254 | return x; |
| ... | @@ -268,7 +268,7 @@ fn outer() i64 { | ... | @@ -268,7 +268,7 @@ fn outer() i64 { |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | test "pointer dereferencing" { | 270 | test "pointer dereferencing" { |
| 271 | var x = i32(3); | 271 | var x = @as(i32, 3); |
| 272 | const y = &x; | 272 | const y = &x; |
| 273 | 273 | ||
| 274 | y.* += 1; | 274 | y.* += 1; |
| ... | @@ -350,7 +350,7 @@ fn testTakeAddressOfParameter(f: f32) void { | ... | @@ -350,7 +350,7 @@ fn testTakeAddressOfParameter(f: f32) void { |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | test "pointer comparison" { | 352 | test "pointer comparison" { |
| 353 | const a = ([]const u8)("a"); | 353 | const a = @as([]const u8, "a"); |
| 354 | const b = &a; | 354 | const b = &a; |
| 355 | expect(ptrEql(b, b)); | 355 | expect(ptrEql(b, b)); |
| 356 | } | 356 | } |
| ... | @@ -500,7 +500,7 @@ fn TypeFromFn(comptime T: type) type { | ... | @@ -500,7 +500,7 @@ fn TypeFromFn(comptime T: type) type { |
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | test "double implicit cast in same expression" { | 502 | test "double implicit cast in same expression" { |
| 503 | var x = i32(u16(nine())); | 503 | var x = @as(i32, @as(u16, nine())); |
| 504 | expect(x == 9); | 504 | expect(x == 9); |
| 505 | } | 505 | } |
| 506 | fn nine() u8 { | 506 | fn nine() u8 { |
| ... | @@ -642,7 +642,7 @@ test "self reference through fn ptr field" { | ... | @@ -642,7 +642,7 @@ test "self reference through fn ptr field" { |
| 642 | 642 | ||
| 643 | test "volatile load and store" { | 643 | test "volatile load and store" { |
| 644 | var number: i32 = 1234; | 644 | var number: i32 = 1234; |
| 645 | const ptr = (*volatile i32)(&number); | 645 | const ptr = @as(*volatile i32, &number); |
| 646 | ptr.* += 1; | 646 | ptr.* += 1; |
| 647 | expect(ptr.* == 1235); | 647 | expect(ptr.* == 1235); |
| 648 | } | 648 | } |
| ... | @@ -761,7 +761,7 @@ test "nested optional field in struct" { | ... | @@ -761,7 +761,7 @@ test "nested optional field in struct" { |
| 761 | 761 | ||
| 762 | fn maybe(x: bool) anyerror!?u32 { | 762 | fn maybe(x: bool) anyerror!?u32 { |
| 763 | return switch (x) { | 763 | return switch (x) { |
| 764 | true => u32(42), | 764 | true => @as(u32, 42), |
| 765 | else => null, | 765 | else => null, |
| 766 | }; | 766 | }; |
| 767 | } | 767 | } |
test/stage1/behavior/popcount.zig+1-1| ... | @@ -35,7 +35,7 @@ fn testPopCount() void { | ... | @@ -35,7 +35,7 @@ fn testPopCount() void { |
| 35 | expect(@popCount(i8, x) == 2); | 35 | expect(@popCount(i8, x) == 2); |
| 36 | } | 36 | } |
| 37 | comptime { | 37 | comptime { |
| 38 | expect(@popCount(u8, @bitCast(u8, i8(-120))) == 2); | 38 | expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2); |
| 39 | } | 39 | } |
| 40 | comptime { | 40 | comptime { |
| 41 | expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24); | 41 | expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24); |
test/stage1/behavior/pub_enum.zig+1-1| ... | @@ -9,5 +9,5 @@ fn pubEnumTest(foo: other.APubEnum) void { | ... | @@ -9,5 +9,5 @@ fn pubEnumTest(foo: other.APubEnum) void { |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | test "cast with imported symbol" { | 11 | test "cast with imported symbol" { |
| 12 | expect(other.size_t(42) == 42); | 12 | expect(@as(other.size_t, 42) == 42); |
| 13 | } | 13 | } |
test/stage1/behavior/shuffle.zig+13-13| ... | @@ -7,39 +7,39 @@ test "@shuffle" { | ... | @@ -7,39 +7,39 @@ test "@shuffle" { |
| 7 | fn doTheTest() void { | 7 | fn doTheTest() void { |
| 8 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; | 8 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 9 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; | 9 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; |
| 10 | const mask: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 3, ~i32(3) }; | 10 | const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; |
| 11 | var res = @shuffle(i32, v, x, mask); | 11 | var res = @shuffle(i32, v, x, mask); |
| 12 | expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 })); | 12 | expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 })); |
| 13 | 13 | ||
| 14 | // Implicit cast from array (of mask) | 14 | // Implicit cast from array (of mask) |
| 15 | res = @shuffle(i32, v, x, [4]i32{ 0, ~i32(2), 3, ~i32(3) }); | 15 | res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }); |
| 16 | expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 40, 4 })); | 16 | expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 })); |
| 17 | 17 | ||
| 18 | // Undefined | 18 | // Undefined |
| 19 | const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 }; | 19 | const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 }; |
| 20 | res = @shuffle(i32, v, undefined, mask2); | 20 | res = @shuffle(i32, v, undefined, mask2); |
| 21 | expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 40, -2, 30, 2147483647 })); | 21 | expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 })); |
| 22 | 22 | ||
| 23 | // Upcasting of b | 23 | // Upcasting of b |
| 24 | var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; | 24 | var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; |
| 25 | const mask3: @Vector(4, i32) = [4]i32{ ~i32(0), 2, ~i32(0), 3 }; | 25 | const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; |
| 26 | res = @shuffle(i32, x, v2, mask3); | 26 | res = @shuffle(i32, x, v2, mask3); |
| 27 | expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, 2147483647, 4 })); | 27 | expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 })); |
| 28 | 28 | ||
| 29 | // Upcasting of a | 29 | // Upcasting of a |
| 30 | var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; | 30 | var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; |
| 31 | const mask4: @Vector(4, i32) = [4]i32{ 0, ~i32(2), 1, ~i32(3) }; | 31 | const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; |
| 32 | res = @shuffle(i32, v3, x, mask4); | 32 | res = @shuffle(i32, v3, x, mask4); |
| 33 | expect(mem.eql(i32, ([4]i32)(res), [4]i32{ 2147483647, 3, -2, 4 })); | 33 | expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 })); |
| 34 | 34 | ||
| 35 | // bool | 35 | // bool |
| 36 | // Disabled because of #3317 | 36 | // Disabled because of #3317 |
| 37 | if (@import("builtin").arch != .mipsel) { | 37 | if (@import("builtin").arch != .mipsel) { |
| 38 | var x2: @Vector(4, bool) = [4]bool{ false, true, false, true }; | 38 | var x2: @Vector(4, bool) = [4]bool{ false, true, false, true }; |
| 39 | var v4: @Vector(2, bool) = [2]bool{ true, false }; | 39 | var v4: @Vector(2, bool) = [2]bool{ true, false }; |
| 40 | const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 }; | 40 | const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; |
| 41 | var res2 = @shuffle(bool, x2, v4, mask5); | 41 | var res2 = @shuffle(bool, x2, v4, mask5); |
| 42 | expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false })); | 42 | expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | // TODO re-enable when LLVM codegen is fixed | 45 | // TODO re-enable when LLVM codegen is fixed |
| ... | @@ -47,9 +47,9 @@ test "@shuffle" { | ... | @@ -47,9 +47,9 @@ test "@shuffle" { |
| 47 | if (false) { | 47 | if (false) { |
| 48 | var x2: @Vector(3, bool) = [3]bool{ false, true, false }; | 48 | var x2: @Vector(3, bool) = [3]bool{ false, true, false }; |
| 49 | var v4: @Vector(2, bool) = [2]bool{ true, false }; | 49 | var v4: @Vector(2, bool) = [2]bool{ true, false }; |
| 50 | const mask5: @Vector(4, i32) = [4]i32{ 0, ~i32(1), 1, 2 }; | 50 | const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; |
| 51 | var res2 = @shuffle(bool, x2, v4, mask5); | 51 | var res2 = @shuffle(bool, x2, v4, mask5); |
| 52 | expect(mem.eql(bool, ([4]bool)(res2), [4]bool{ false, false, true, false })); | 52 | expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); |
| 53 | } | 53 | } |
| 54 | } | 54 | } |
| 55 | }; | 55 | }; |
test/stage1/behavior/slicetobytes.zig+1-1| ... | @@ -10,7 +10,7 @@ test "@sliceToBytes packed struct at runtime and comptime" { | ... | @@ -10,7 +10,7 @@ test "@sliceToBytes packed struct at runtime and comptime" { |
| 10 | const S = struct { | 10 | const S = struct { |
| 11 | fn doTheTest() void { | 11 | fn doTheTest() void { |
| 12 | var foo: Foo = undefined; | 12 | var foo: Foo = undefined; |
| 13 | var slice = @sliceToBytes(((*[1]Foo)(&foo))[0..1]); | 13 | var slice = @sliceToBytes(@as(*[1]Foo, &foo)[0..1]); |
| 14 | slice[0] = 0x13; | 14 | slice[0] = 0x13; |
| 15 | switch (builtin.endian) { | 15 | switch (builtin.endian) { |
| 16 | builtin.Endian.Big => { | 16 | builtin.Endian.Big => { |
test/stage1/behavior/struct.zig+8-8| ... | @@ -388,8 +388,8 @@ test "runtime struct initialization of bitfield" { | ... | @@ -388,8 +388,8 @@ test "runtime struct initialization of bitfield" { |
| 388 | expect(s2.y == @intCast(u4, x2)); | 388 | expect(s2.y == @intCast(u4, x2)); |
| 389 | } | 389 | } |
| 390 | 390 | ||
| 391 | var x1 = u4(1); | 391 | var x1 = @as(u4, 1); |
| 392 | var x2 = u8(2); | 392 | var x2 = @as(u8, 2); |
| 393 | 393 | ||
| 394 | const Nibbles = packed struct { | 394 | const Nibbles = packed struct { |
| 395 | x: u4, | 395 | x: u4, |
| ... | @@ -545,9 +545,9 @@ test "packed struct with fp fields" { | ... | @@ -545,9 +545,9 @@ test "packed struct with fp fields" { |
| 545 | s.data[1] = 2.0; | 545 | s.data[1] = 2.0; |
| 546 | s.data[2] = 3.0; | 546 | s.data[2] = 3.0; |
| 547 | s.frob(); | 547 | s.frob(); |
| 548 | expectEqual(f32(6.0), s.data[0]); | 548 | expectEqual(@as(f32, 6.0), s.data[0]); |
| 549 | expectEqual(f32(11.0), s.data[1]); | 549 | expectEqual(@as(f32, 11.0), s.data[1]); |
| 550 | expectEqual(f32(20.0), s.data[2]); | 550 | expectEqual(@as(f32, 20.0), s.data[2]); |
| 551 | } | 551 | } |
| 552 | 552 | ||
| 553 | test "use within struct scope" { | 553 | test "use within struct scope" { |
| ... | @@ -558,7 +558,7 @@ test "use within struct scope" { | ... | @@ -558,7 +558,7 @@ test "use within struct scope" { |
| 558 | } | 558 | } |
| 559 | }; | 559 | }; |
| 560 | }; | 560 | }; |
| 561 | expectEqual(i32(42), S.inner()); | 561 | expectEqual(@as(i32, 42), S.inner()); |
| 562 | } | 562 | } |
| 563 | 563 | ||
| 564 | test "default struct initialization fields" { | 564 | test "default struct initialization fields" { |
| ... | @@ -583,7 +583,7 @@ test "extern fn returns struct by value" { | ... | @@ -583,7 +583,7 @@ test "extern fn returns struct by value" { |
| 583 | const S = struct { | 583 | const S = struct { |
| 584 | fn entry() void { | 584 | fn entry() void { |
| 585 | var x = makeBar(10); | 585 | var x = makeBar(10); |
| 586 | expectEqual(i32(10), x.handle); | 586 | expectEqual(@as(i32, 10), x.handle); |
| 587 | } | 587 | } |
| 588 | 588 | ||
| 589 | const ExternBar = extern struct { | 589 | const ExternBar = extern struct { |
| ... | @@ -614,7 +614,7 @@ test "for loop over pointers to struct, getting field from struct pointer" { | ... | @@ -614,7 +614,7 @@ test "for loop over pointers to struct, getting field from struct pointer" { |
| 614 | 614 | ||
| 615 | const ArrayList = struct { | 615 | const ArrayList = struct { |
| 616 | fn toSlice(self: *ArrayList) []*Foo { | 616 | fn toSlice(self: *ArrayList) []*Foo { |
| 617 | return ([*]*Foo)(undefined)[0..0]; | 617 | return @as([*]*Foo, undefined)[0..0]; |
| 618 | } | 618 | } |
| 619 | }; | 619 | }; |
| 620 | 620 |
test/stage1/behavior/switch.zig+4-4| ... | @@ -68,7 +68,7 @@ test "switch statement" { | ... | @@ -68,7 +68,7 @@ test "switch statement" { |
| 68 | } | 68 | } |
| 69 | fn nonConstSwitch(foo: SwitchStatmentFoo) void { | 69 | fn nonConstSwitch(foo: SwitchStatmentFoo) void { |
| 70 | const val = switch (foo) { | 70 | const val = switch (foo) { |
| 71 | SwitchStatmentFoo.A => i32(1), | 71 | SwitchStatmentFoo.A => @as(i32, 1), |
| 72 | SwitchStatmentFoo.B => 2, | 72 | SwitchStatmentFoo.B => 2, |
| 73 | SwitchStatmentFoo.C => 3, | 73 | SwitchStatmentFoo.C => 3, |
| 74 | SwitchStatmentFoo.D => 4, | 74 | SwitchStatmentFoo.D => 4, |
| ... | @@ -127,7 +127,7 @@ test "switch with multiple expressions" { | ... | @@ -127,7 +127,7 @@ test "switch with multiple expressions" { |
| 127 | const x = switch (returnsFive()) { | 127 | const x = switch (returnsFive()) { |
| 128 | 1, 2, 3 => 1, | 128 | 1, 2, 3 => 1, |
| 129 | 4, 5, 6 => 2, | 129 | 4, 5, 6 => 2, |
| 130 | else => i32(3), | 130 | else => @as(i32, 3), |
| 131 | }; | 131 | }; |
| 132 | expect(x == 2); | 132 | expect(x == 2); |
| 133 | } | 133 | } |
| ... | @@ -186,7 +186,7 @@ fn testSwitchHandleAllCases() void { | ... | @@ -186,7 +186,7 @@ fn testSwitchHandleAllCases() void { |
| 186 | 186 | ||
| 187 | fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { | 187 | fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { |
| 188 | return switch (x) { | 188 | return switch (x) { |
| 189 | 0 => u2(3), | 189 | 0 => @as(u2, 3), |
| 190 | 1 => 2, | 190 | 1 => 2, |
| 191 | 2 => 1, | 191 | 2 => 1, |
| 192 | 3 => 0, | 192 | 3 => 0, |
| ... | @@ -195,7 +195,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { | ... | @@ -195,7 +195,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { |
| 195 | 195 | ||
| 196 | fn testSwitchHandleAllCasesRange(x: u8) u8 { | 196 | fn testSwitchHandleAllCasesRange(x: u8) u8 { |
| 197 | return switch (x) { | 197 | return switch (x) { |
| 198 | 0...100 => u8(0), | 198 | 0...100 => @as(u8, 0), |
| 199 | 101...200 => 1, | 199 | 101...200 => 1, |
| 200 | 201, 203 => 2, | 200 | 201, 203 => 2, |
| 201 | 202 => 4, | 201 | 202 => 4, |
test/stage1/behavior/try.zig+3-3| ... | @@ -8,7 +8,7 @@ test "try on error union" { | ... | @@ -8,7 +8,7 @@ test "try on error union" { |
| 8 | fn tryOnErrorUnionImpl() void { | 8 | fn tryOnErrorUnionImpl() void { |
| 9 | const x = if (returnsTen()) |val| val + 1 else |err| switch (err) { | 9 | const x = if (returnsTen()) |val| val + 1 else |err| switch (err) { |
| 10 | error.ItBroke, error.NoMem => 1, | 10 | error.ItBroke, error.NoMem => 1, |
| 11 | error.CrappedOut => i32(2), | 11 | error.CrappedOut => @as(i32, 2), |
| 12 | else => unreachable, | 12 | else => unreachable, |
| 13 | }; | 13 | }; |
| 14 | expect(x == 11); | 14 | expect(x == 11); |
| ... | @@ -19,10 +19,10 @@ fn returnsTen() anyerror!i32 { | ... | @@ -19,10 +19,10 @@ fn returnsTen() anyerror!i32 { |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | test "try without vars" { | 21 | test "try without vars" { |
| 22 | const result1 = if (failIfTrue(true)) 1 else |_| i32(2); | 22 | const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2); |
| 23 | expect(result1 == 2); | 23 | expect(result1 == 2); |
| 24 | 24 | ||
| 25 | const result2 = if (failIfTrue(false)) 1 else |_| i32(2); | 25 | const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2); |
| 26 | expect(result2 == 1); | 26 | expect(result2 == 1); |
| 27 | } | 27 | } |
| 28 | 28 |
test/stage1/behavior/type_info.zig+23-23| ... | @@ -13,7 +13,7 @@ test "type info: tag type, void info" { | ... | @@ -13,7 +13,7 @@ test "type info: tag type, void info" { |
| 13 | fn testBasic() void { | 13 | fn testBasic() void { |
| 14 | expect(@TagType(TypeInfo) == TypeId); | 14 | expect(@TagType(TypeInfo) == TypeId); |
| 15 | const void_info = @typeInfo(void); | 15 | const void_info = @typeInfo(void); |
| 16 | expect(TypeId(void_info) == TypeId.Void); | 16 | expect(@as(TypeId, void_info) == TypeId.Void); |
| 17 | expect(void_info.Void == {}); | 17 | expect(void_info.Void == {}); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| ... | @@ -24,12 +24,12 @@ test "type info: integer, floating point type info" { | ... | @@ -24,12 +24,12 @@ test "type info: integer, floating point type info" { |
| 24 | 24 | ||
| 25 | fn testIntFloat() void { | 25 | fn testIntFloat() void { |
| 26 | const u8_info = @typeInfo(u8); | 26 | const u8_info = @typeInfo(u8); |
| 27 | expect(TypeId(u8_info) == TypeId.Int); | 27 | expect(@as(TypeId, u8_info) == TypeId.Int); |
| 28 | expect(!u8_info.Int.is_signed); | 28 | expect(!u8_info.Int.is_signed); |
| 29 | expect(u8_info.Int.bits == 8); | 29 | expect(u8_info.Int.bits == 8); |
| 30 | 30 | ||
| 31 | const f64_info = @typeInfo(f64); | 31 | const f64_info = @typeInfo(f64); |
| 32 | expect(TypeId(f64_info) == TypeId.Float); | 32 | expect(@as(TypeId, f64_info) == TypeId.Float); |
| 33 | expect(f64_info.Float.bits == 64); | 33 | expect(f64_info.Float.bits == 64); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| ... | @@ -40,7 +40,7 @@ test "type info: pointer type info" { | ... | @@ -40,7 +40,7 @@ test "type info: pointer type info" { |
| 40 | 40 | ||
| 41 | fn testPointer() void { | 41 | fn testPointer() void { |
| 42 | const u32_ptr_info = @typeInfo(*u32); | 42 | const u32_ptr_info = @typeInfo(*u32); |
| 43 | expect(TypeId(u32_ptr_info) == TypeId.Pointer); | 43 | expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer); |
| 44 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One); | 44 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One); |
| 45 | expect(u32_ptr_info.Pointer.is_const == false); | 45 | expect(u32_ptr_info.Pointer.is_const == false); |
| 46 | expect(u32_ptr_info.Pointer.is_volatile == false); | 46 | expect(u32_ptr_info.Pointer.is_volatile == false); |
| ... | @@ -55,7 +55,7 @@ test "type info: unknown length pointer type info" { | ... | @@ -55,7 +55,7 @@ test "type info: unknown length pointer type info" { |
| 55 | 55 | ||
| 56 | fn testUnknownLenPtr() void { | 56 | fn testUnknownLenPtr() void { |
| 57 | const u32_ptr_info = @typeInfo([*]const volatile f64); | 57 | const u32_ptr_info = @typeInfo([*]const volatile f64); |
| 58 | expect(TypeId(u32_ptr_info) == TypeId.Pointer); | 58 | expect(@as(TypeId,u32_ptr_info) == TypeId.Pointer); |
| 59 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); | 59 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); |
| 60 | expect(u32_ptr_info.Pointer.is_const == true); | 60 | expect(u32_ptr_info.Pointer.is_const == true); |
| 61 | expect(u32_ptr_info.Pointer.is_volatile == true); | 61 | expect(u32_ptr_info.Pointer.is_volatile == true); |
| ... | @@ -70,7 +70,7 @@ test "type info: C pointer type info" { | ... | @@ -70,7 +70,7 @@ test "type info: C pointer type info" { |
| 70 | 70 | ||
| 71 | fn testCPtr() void { | 71 | fn testCPtr() void { |
| 72 | const ptr_info = @typeInfo([*c]align(4) const i8); | 72 | const ptr_info = @typeInfo([*c]align(4) const i8); |
| 73 | expect(TypeId(ptr_info) == TypeId.Pointer); | 73 | expect(@as(TypeId,ptr_info) == TypeId.Pointer); |
| 74 | expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C); | 74 | expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C); |
| 75 | expect(ptr_info.Pointer.is_const); | 75 | expect(ptr_info.Pointer.is_const); |
| 76 | expect(!ptr_info.Pointer.is_volatile); | 76 | expect(!ptr_info.Pointer.is_volatile); |
| ... | @@ -85,7 +85,7 @@ test "type info: slice type info" { | ... | @@ -85,7 +85,7 @@ test "type info: slice type info" { |
| 85 | 85 | ||
| 86 | fn testSlice() void { | 86 | fn testSlice() void { |
| 87 | const u32_slice_info = @typeInfo([]u32); | 87 | const u32_slice_info = @typeInfo([]u32); |
| 88 | expect(TypeId(u32_slice_info) == TypeId.Pointer); | 88 | expect(@as(TypeId, u32_slice_info) == TypeId.Pointer); |
| 89 | expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice); | 89 | expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice); |
| 90 | expect(u32_slice_info.Pointer.is_const == false); | 90 | expect(u32_slice_info.Pointer.is_const == false); |
| 91 | expect(u32_slice_info.Pointer.is_volatile == false); | 91 | expect(u32_slice_info.Pointer.is_volatile == false); |
| ... | @@ -100,7 +100,7 @@ test "type info: array type info" { | ... | @@ -100,7 +100,7 @@ test "type info: array type info" { |
| 100 | 100 | ||
| 101 | fn testArray() void { | 101 | fn testArray() void { |
| 102 | const arr_info = @typeInfo([42]bool); | 102 | const arr_info = @typeInfo([42]bool); |
| 103 | expect(TypeId(arr_info) == TypeId.Array); | 103 | expect(@as(TypeId, arr_info) == TypeId.Array); |
| 104 | expect(arr_info.Array.len == 42); | 104 | expect(arr_info.Array.len == 42); |
| 105 | expect(arr_info.Array.child == bool); | 105 | expect(arr_info.Array.child == bool); |
| 106 | } | 106 | } |
| ... | @@ -112,7 +112,7 @@ test "type info: optional type info" { | ... | @@ -112,7 +112,7 @@ test "type info: optional type info" { |
| 112 | 112 | ||
| 113 | fn testOptional() void { | 113 | fn testOptional() void { |
| 114 | const null_info = @typeInfo(?void); | 114 | const null_info = @typeInfo(?void); |
| 115 | expect(TypeId(null_info) == TypeId.Optional); | 115 | expect(@as(TypeId, null_info) == TypeId.Optional); |
| 116 | expect(null_info.Optional.child == void); | 116 | expect(null_info.Optional.child == void); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| ... | @@ -129,18 +129,18 @@ fn testErrorSet() void { | ... | @@ -129,18 +129,18 @@ fn testErrorSet() void { |
| 129 | }; | 129 | }; |
| 130 | 130 | ||
| 131 | const error_set_info = @typeInfo(TestErrorSet); | 131 | const error_set_info = @typeInfo(TestErrorSet); |
| 132 | expect(TypeId(error_set_info) == TypeId.ErrorSet); | 132 | expect(@as(TypeId, error_set_info) == TypeId.ErrorSet); |
| 133 | expect(error_set_info.ErrorSet.?.len == 3); | 133 | expect(error_set_info.ErrorSet.?.len == 3); |
| 134 | expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First")); | 134 | expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First")); |
| 135 | expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third)); | 135 | expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third)); |
| 136 | 136 | ||
| 137 | const error_union_info = @typeInfo(TestErrorSet!usize); | 137 | const error_union_info = @typeInfo(TestErrorSet!usize); |
| 138 | expect(TypeId(error_union_info) == TypeId.ErrorUnion); | 138 | expect(@as(TypeId, error_union_info) == TypeId.ErrorUnion); |
| 139 | expect(error_union_info.ErrorUnion.error_set == TestErrorSet); | 139 | expect(error_union_info.ErrorUnion.error_set == TestErrorSet); |
| 140 | expect(error_union_info.ErrorUnion.payload == usize); | 140 | expect(error_union_info.ErrorUnion.payload == usize); |
| 141 | 141 | ||
| 142 | const global_info = @typeInfo(anyerror); | 142 | const global_info = @typeInfo(anyerror); |
| 143 | expect(TypeId(global_info) == TypeId.ErrorSet); | 143 | expect(@as(TypeId, global_info) == TypeId.ErrorSet); |
| 144 | expect(global_info.ErrorSet == null); | 144 | expect(global_info.ErrorSet == null); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| ... | @@ -158,7 +158,7 @@ fn testEnum() void { | ... | @@ -158,7 +158,7 @@ fn testEnum() void { |
| 158 | }; | 158 | }; |
| 159 | 159 | ||
| 160 | const os_info = @typeInfo(Os); | 160 | const os_info = @typeInfo(Os); |
| 161 | expect(TypeId(os_info) == TypeId.Enum); | 161 | expect(@as(TypeId, os_info) == TypeId.Enum); |
| 162 | expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto); | 162 | expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto); |
| 163 | expect(os_info.Enum.fields.len == 4); | 163 | expect(os_info.Enum.fields.len == 4); |
| 164 | expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); | 164 | expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); |
| ... | @@ -174,7 +174,7 @@ test "type info: union info" { | ... | @@ -174,7 +174,7 @@ test "type info: union info" { |
| 174 | 174 | ||
| 175 | fn testUnion() void { | 175 | fn testUnion() void { |
| 176 | const typeinfo_info = @typeInfo(TypeInfo); | 176 | const typeinfo_info = @typeInfo(TypeInfo); |
| 177 | expect(TypeId(typeinfo_info) == TypeId.Union); | 177 | expect(@as(TypeId, typeinfo_info) == TypeId.Union); |
| 178 | expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); | 178 | expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); |
| 179 | expect(typeinfo_info.Union.tag_type.? == TypeId); | 179 | expect(typeinfo_info.Union.tag_type.? == TypeId); |
| 180 | expect(typeinfo_info.Union.fields.len == 26); | 180 | expect(typeinfo_info.Union.fields.len == 26); |
| ... | @@ -189,7 +189,7 @@ fn testUnion() void { | ... | @@ -189,7 +189,7 @@ fn testUnion() void { |
| 189 | }; | 189 | }; |
| 190 | 190 | ||
| 191 | const notag_union_info = @typeInfo(TestNoTagUnion); | 191 | const notag_union_info = @typeInfo(TestNoTagUnion); |
| 192 | expect(TypeId(notag_union_info) == TypeId.Union); | 192 | expect(@as(TypeId, notag_union_info) == TypeId.Union); |
| 193 | expect(notag_union_info.Union.tag_type == null); | 193 | expect(notag_union_info.Union.tag_type == null); |
| 194 | expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto); | 194 | expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto); |
| 195 | expect(notag_union_info.Union.fields.len == 2); | 195 | expect(notag_union_info.Union.fields.len == 2); |
| ... | @@ -214,7 +214,7 @@ test "type info: struct info" { | ... | @@ -214,7 +214,7 @@ test "type info: struct info" { |
| 214 | 214 | ||
| 215 | fn testStruct() void { | 215 | fn testStruct() void { |
| 216 | const struct_info = @typeInfo(TestStruct); | 216 | const struct_info = @typeInfo(TestStruct); |
| 217 | expect(TypeId(struct_info) == TypeId.Struct); | 217 | expect(@as(TypeId, struct_info) == TypeId.Struct); |
| 218 | expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed); | 218 | expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed); |
| 219 | expect(struct_info.Struct.fields.len == 3); | 219 | expect(struct_info.Struct.fields.len == 3); |
| 220 | expect(struct_info.Struct.fields[1].offset == null); | 220 | expect(struct_info.Struct.fields[1].offset == null); |
| ... | @@ -244,7 +244,7 @@ test "type info: function type info" { | ... | @@ -244,7 +244,7 @@ test "type info: function type info" { |
| 244 | 244 | ||
| 245 | fn testFunction() void { | 245 | fn testFunction() void { |
| 246 | const fn_info = @typeInfo(@typeOf(foo)); | 246 | const fn_info = @typeInfo(@typeOf(foo)); |
| 247 | expect(TypeId(fn_info) == TypeId.Fn); | 247 | expect(@as(TypeId, fn_info) == TypeId.Fn); |
| 248 | expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified); | 248 | expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified); |
| 249 | expect(fn_info.Fn.is_generic); | 249 | expect(fn_info.Fn.is_generic); |
| 250 | expect(fn_info.Fn.args.len == 2); | 250 | expect(fn_info.Fn.args.len == 2); |
| ... | @@ -253,7 +253,7 @@ fn testFunction() void { | ... | @@ -253,7 +253,7 @@ fn testFunction() void { |
| 253 | 253 | ||
| 254 | const test_instance: TestStruct = undefined; | 254 | const test_instance: TestStruct = undefined; |
| 255 | const bound_fn_info = @typeInfo(@typeOf(test_instance.foo)); | 255 | const bound_fn_info = @typeInfo(@typeOf(test_instance.foo)); |
| 256 | expect(TypeId(bound_fn_info) == TypeId.BoundFn); | 256 | expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn); |
| 257 | expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); | 257 | expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); |
| 258 | } | 258 | } |
| 259 | 259 | ||
| ... | @@ -275,7 +275,7 @@ test "type info: vectors" { | ... | @@ -275,7 +275,7 @@ test "type info: vectors" { |
| 275 | 275 | ||
| 276 | fn testVector() void { | 276 | fn testVector() void { |
| 277 | const vec_info = @typeInfo(@Vector(4, i32)); | 277 | const vec_info = @typeInfo(@Vector(4, i32)); |
| 278 | expect(TypeId(vec_info) == TypeId.Vector); | 278 | expect(@as(TypeId, vec_info) == TypeId.Vector); |
| 279 | expect(vec_info.Vector.len == 4); | 279 | expect(vec_info.Vector.len == 4); |
| 280 | expect(vec_info.Vector.child == i32); | 280 | expect(vec_info.Vector.child == i32); |
| 281 | } | 281 | } |
| ... | @@ -288,13 +288,13 @@ test "type info: anyframe and anyframe->T" { | ... | @@ -288,13 +288,13 @@ test "type info: anyframe and anyframe->T" { |
| 288 | fn testAnyFrame() void { | 288 | fn testAnyFrame() void { |
| 289 | { | 289 | { |
| 290 | const anyframe_info = @typeInfo(anyframe->i32); | 290 | const anyframe_info = @typeInfo(anyframe->i32); |
| 291 | expect(TypeId(anyframe_info) == .AnyFrame); | 291 | expect(@as(TypeId,anyframe_info) == .AnyFrame); |
| 292 | expect(anyframe_info.AnyFrame.child.? == i32); | 292 | expect(anyframe_info.AnyFrame.child.? == i32); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | { | 295 | { |
| 296 | const anyframe_info = @typeInfo(anyframe); | 296 | const anyframe_info = @typeInfo(anyframe); |
| 297 | expect(TypeId(anyframe_info) == .AnyFrame); | 297 | expect(@as(TypeId,anyframe_info) == .AnyFrame); |
| 298 | expect(anyframe_info.AnyFrame.child == null); | 298 | expect(anyframe_info.AnyFrame.child == null); |
| 299 | } | 299 | } |
| 300 | } | 300 | } |
| ... | @@ -334,7 +334,7 @@ test "type info: extern fns with and without lib names" { | ... | @@ -334,7 +334,7 @@ test "type info: extern fns with and without lib names" { |
| 334 | if (std.mem.eql(u8, decl.name, "bar1")) { | 334 | if (std.mem.eql(u8, decl.name, "bar1")) { |
| 335 | expect(decl.data.Fn.lib_name == null); | 335 | expect(decl.data.Fn.lib_name == null); |
| 336 | } else { | 336 | } else { |
| 337 | std.testing.expectEqual(([]const u8)("cool"), decl.data.Fn.lib_name.?); | 337 | std.testing.expectEqual(@as([]const u8,"cool"), decl.data.Fn.lib_name.?); |
| 338 | } | 338 | } |
| 339 | } | 339 | } |
| 340 | } | 340 | } |
| ... | @@ -342,7 +342,7 @@ test "type info: extern fns with and without lib names" { | ... | @@ -342,7 +342,7 @@ test "type info: extern fns with and without lib names" { |
| 342 | 342 | ||
| 343 | test "data field is a compile-time value" { | 343 | test "data field is a compile-time value" { |
| 344 | const S = struct { | 344 | const S = struct { |
| 345 | const Bar = isize(-1); | 345 | const Bar = @as(isize, -1); |
| 346 | }; | 346 | }; |
| 347 | comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize); | 347 | comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize); |
| 348 | } | 348 | } |
test/stage1/behavior/union.zig+12-12| ... | @@ -14,7 +14,7 @@ const Agg = struct { | ... | @@ -14,7 +14,7 @@ const Agg = struct { |
| 14 | const v1 = Value{ .Int = 1234 }; | 14 | const v1 = Value{ .Int = 1234 }; |
| 15 | const v2 = Value{ .Array = [_]u8{3} ** 9 }; | 15 | const v2 = Value{ .Array = [_]u8{3} ** 9 }; |
| 16 | 16 | ||
| 17 | const err = (anyerror!Agg)(Agg{ | 17 | const err = @as(anyerror!Agg, Agg{ |
| 18 | .val1 = v1, | 18 | .val1 = v1, |
| 19 | .val2 = v2, | 19 | .val2 = v2, |
| 20 | }); | 20 | }); |
| ... | @@ -110,11 +110,11 @@ fn doTest() void { | ... | @@ -110,11 +110,11 @@ fn doTest() void { |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | fn bar(value: Payload) i32 { | 112 | fn bar(value: Payload) i32 { |
| 113 | expect(Letter(value) == Letter.A); | 113 | expect(@as(Letter,value) == Letter.A); |
| 114 | return switch (value) { | 114 | return switch (value) { |
| 115 | Payload.A => |x| return x - 1244, | 115 | Payload.A => |x| return x - 1244, |
| 116 | Payload.B => |x| if (x == 12.34) i32(20) else 21, | 116 | Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21, |
| 117 | Payload.C => |x| if (x) i32(30) else 31, | 117 | Payload.C => |x| if (x) @as(i32, 30) else 31, |
| 118 | }; | 118 | }; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| ... | @@ -127,7 +127,7 @@ const MultipleChoice = union(enum(u32)) { | ... | @@ -127,7 +127,7 @@ const MultipleChoice = union(enum(u32)) { |
| 127 | test "simple union(enum(u32))" { | 127 | test "simple union(enum(u32))" { |
| 128 | var x = MultipleChoice.C; | 128 | var x = MultipleChoice.C; |
| 129 | expect(x == MultipleChoice.C); | 129 | expect(x == MultipleChoice.C); |
| 130 | expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60); | 130 | expect(@enumToInt(@as(@TagType(MultipleChoice), x)) == 60); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | const MultipleChoice2 = union(enum(u32)) { | 133 | const MultipleChoice2 = union(enum(u32)) { |
| ... | @@ -149,11 +149,11 @@ test "union(enum(u32)) with specified and unspecified tag values" { | ... | @@ -149,11 +149,11 @@ test "union(enum(u32)) with specified and unspecified tag values" { |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { | 151 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 152 | expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60); | 152 | expect(@enumToInt(@as(@TagType(MultipleChoice2), x)) == 60); |
| 153 | expect(1123 == switch (x) { | 153 | expect(1123 == switch (x) { |
| 154 | MultipleChoice2.A => 1, | 154 | MultipleChoice2.A => 1, |
| 155 | MultipleChoice2.B => 2, | 155 | MultipleChoice2.B => 2, |
| 156 | MultipleChoice2.C => |v| i32(1000) + v, | 156 | MultipleChoice2.C => |v| @as(i32, 1000) + v, |
| 157 | MultipleChoice2.D => 4, | 157 | MultipleChoice2.D => 4, |
| 158 | MultipleChoice2.Unspecified1 => 5, | 158 | MultipleChoice2.Unspecified1 => 5, |
| 159 | MultipleChoice2.Unspecified2 => 6, | 159 | MultipleChoice2.Unspecified2 => 6, |
| ... | @@ -208,12 +208,12 @@ test "cast union to tag type of union" { | ... | @@ -208,12 +208,12 @@ test "cast union to tag type of union" { |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | fn testCastUnionToTagType(x: TheUnion) void { | 210 | fn testCastUnionToTagType(x: TheUnion) void { |
| 211 | expect(TheTag(x) == TheTag.B); | 211 | expect(@as(TheTag,x) == TheTag.B); |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | test "cast tag type of union to union" { | 214 | test "cast tag type of union to union" { |
| 215 | var x: Value2 = Letter2.B; | 215 | var x: Value2 = Letter2.B; |
| 216 | expect(Letter2(x) == Letter2.B); | 216 | expect(@as(Letter2, x) == Letter2.B); |
| 217 | } | 217 | } |
| 218 | const Letter2 = enum { | 218 | const Letter2 = enum { |
| 219 | A, | 219 | A, |
| ... | @@ -297,7 +297,7 @@ const TaggedUnionWithAVoid = union(enum) { | ... | @@ -297,7 +297,7 @@ const TaggedUnionWithAVoid = union(enum) { |
| 297 | 297 | ||
| 298 | fn testTaggedUnionInit(x: var) bool { | 298 | fn testTaggedUnionInit(x: var) bool { |
| 299 | const y = TaggedUnionWithAVoid{ .A = x }; | 299 | const y = TaggedUnionWithAVoid{ .A = x }; |
| 300 | return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A; | 300 | return @as(@TagType(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A; |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | pub const UnionEnumNoPayloads = union(enum) { | 303 | pub const UnionEnumNoPayloads = union(enum) { |
| ... | @@ -326,7 +326,7 @@ test "union with only 1 field casted to its enum type" { | ... | @@ -326,7 +326,7 @@ test "union with only 1 field casted to its enum type" { |
| 326 | var e = Expr{ .Literal = Literal{ .Bool = true } }; | 326 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 327 | const Tag = @TagType(Expr); | 327 | const Tag = @TagType(Expr); |
| 328 | comptime expect(@TagType(Tag) == u0); | 328 | comptime expect(@TagType(Tag) == u0); |
| 329 | var t = Tag(e); | 329 | var t = @as(Tag, e); |
| 330 | expect(t == Expr.Literal); | 330 | expect(t == Expr.Literal); |
| 331 | } | 331 | } |
| 332 | 332 | ||
| ... | @@ -346,7 +346,7 @@ test "union with only 1 field casted to its enum type which has enum value speci | ... | @@ -346,7 +346,7 @@ test "union with only 1 field casted to its enum type which has enum value speci |
| 346 | 346 | ||
| 347 | var e = Expr{ .Literal = Literal{ .Bool = true } }; | 347 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 348 | comptime expect(@TagType(Tag) == comptime_int); | 348 | comptime expect(@TagType(Tag) == comptime_int); |
| 349 | var t = Tag(e); | 349 | var t = @as(Tag, e); |
| 350 | expect(t == Expr.Literal); | 350 | expect(t == Expr.Literal); |
| 351 | expect(@enumToInt(t) == 33); | 351 | expect(@enumToInt(t) == 33); |
| 352 | comptime expect(@enumToInt(t) == 33); | 352 | comptime expect(@enumToInt(t) == 33); |
test/stage1/behavior/var_args.zig+5-5| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const expect = @import("std").testing.expect; | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | ||
| 3 | fn add(args: ...) i32 { | 3 | fn add(args: ...) i32 { |
| 4 | var sum = i32(0); | 4 | var sum = @as(i32, 0); |
| 5 | { | 5 | { |
| 6 | comptime var i: usize = 0; | 6 | comptime var i: usize = 0; |
| 7 | inline while (i < args.len) : (i += 1) { | 7 | inline while (i < args.len) : (i += 1) { |
| ... | @@ -12,8 +12,8 @@ fn add(args: ...) i32 { | ... | @@ -12,8 +12,8 @@ fn add(args: ...) i32 { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | test "add arbitrary args" { | 14 | test "add arbitrary args" { |
| 15 | expect(add(i32(1), i32(2), i32(3), i32(4)) == 10); | 15 | expect(add(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10); |
| 16 | expect(add(i32(1234)) == 1234); | 16 | expect(add(@as(i32, 1234)) == 1234); |
| 17 | expect(add() == 0); | 17 | expect(add() == 0); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| ... | @@ -26,8 +26,8 @@ test "send void arg to var args" { | ... | @@ -26,8 +26,8 @@ test "send void arg to var args" { |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | test "pass args directly" { | 28 | test "pass args directly" { |
| 29 | expect(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10); | 29 | expect(addSomeStuff(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10); |
| 30 | expect(addSomeStuff(i32(1234)) == 1234); | 30 | expect(addSomeStuff(@as(i32, 1234)) == 1234); |
| 31 | expect(addSomeStuff() == 0); | 31 | expect(addSomeStuff() == 0); |
| 32 | } | 32 | } |
| 33 | 33 |
test/stage1/behavior/vector.zig+25-25| ... | @@ -20,11 +20,11 @@ test "vector wrap operators" { | ... | @@ -20,11 +20,11 @@ test "vector wrap operators" { |
| 20 | fn doTheTest() void { | 20 | fn doTheTest() void { |
| 21 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; | 21 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 22 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; | 22 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; |
| 23 | expect(mem.eql(i32, ([4]i32)(v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 })); | 23 | expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 })); |
| 24 | expect(mem.eql(i32, ([4]i32)(v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 })); | 24 | expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 })); |
| 25 | expect(mem.eql(i32, ([4]i32)(v *% x), [4]i32{ 2147483647, 2, 90, 160 })); | 25 | expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 })); |
| 26 | var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; | 26 | var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; |
| 27 | expect(mem.eql(i32, ([4]i32)(-%z), [4]i32{ -1, -2, -3, -2147483648 })); | 27 | expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 })); |
| 28 | } | 28 | } |
| 29 | }; | 29 | }; |
| 30 | S.doTheTest(); | 30 | S.doTheTest(); |
| ... | @@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" { | ... | @@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" { |
| 36 | fn doTheTest() void { | 36 | fn doTheTest() void { |
| 37 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; | 37 | var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 38 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; | 38 | var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; |
| 39 | expect(mem.eql(bool, ([4]bool)(v == x), [4]bool{ false, false, true, false })); | 39 | expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false })); |
| 40 | expect(mem.eql(bool, ([4]bool)(v != x), [4]bool{ true, true, false, true })); | 40 | expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true })); |
| 41 | expect(mem.eql(bool, ([4]bool)(v < x), [4]bool{ false, true, false, false })); | 41 | expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false })); |
| 42 | expect(mem.eql(bool, ([4]bool)(v > x), [4]bool{ true, false, false, true })); | 42 | expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true })); |
| 43 | expect(mem.eql(bool, ([4]bool)(v <= x), [4]bool{ false, true, true, false })); | 43 | expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false })); |
| 44 | expect(mem.eql(bool, ([4]bool)(v >= x), [4]bool{ true, false, true, true })); | 44 | expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true })); |
| 45 | } | 45 | } |
| 46 | }; | 46 | }; |
| 47 | S.doTheTest(); | 47 | S.doTheTest(); |
| ... | @@ -53,10 +53,10 @@ test "vector int operators" { | ... | @@ -53,10 +53,10 @@ test "vector int operators" { |
| 53 | fn doTheTest() void { | 53 | fn doTheTest() void { |
| 54 | var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; | 54 | var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; |
| 55 | var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; | 55 | var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; |
| 56 | expect(mem.eql(i32, ([4]i32)(v + x), [4]i32{ 11, 22, 33, 44 })); | 56 | expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 })); |
| 57 | expect(mem.eql(i32, ([4]i32)(v - x), [4]i32{ 9, 18, 27, 36 })); | 57 | expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 })); |
| 58 | expect(mem.eql(i32, ([4]i32)(v * x), [4]i32{ 10, 40, 90, 160 })); | 58 | expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 })); |
| 59 | expect(mem.eql(i32, ([4]i32)(-v), [4]i32{ -10, -20, -30, -40 })); | 59 | expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 })); |
| 60 | } | 60 | } |
| 61 | }; | 61 | }; |
| 62 | S.doTheTest(); | 62 | S.doTheTest(); |
| ... | @@ -68,10 +68,10 @@ test "vector float operators" { | ... | @@ -68,10 +68,10 @@ test "vector float operators" { |
| 68 | fn doTheTest() void { | 68 | fn doTheTest() void { |
| 69 | var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 }; | 69 | var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 }; |
| 70 | var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 }; | 70 | var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 }; |
| 71 | expect(mem.eql(f32, ([4]f32)(v + x), [4]f32{ 11, 22, 33, 44 })); | 71 | expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 })); |
| 72 | expect(mem.eql(f32, ([4]f32)(v - x), [4]f32{ 9, 18, 27, 36 })); | 72 | expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 })); |
| 73 | expect(mem.eql(f32, ([4]f32)(v * x), [4]f32{ 10, 40, 90, 160 })); | 73 | expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 })); |
| 74 | expect(mem.eql(f32, ([4]f32)(-x), [4]f32{ -1, -2, -3, -4 })); | 74 | expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 })); |
| 75 | } | 75 | } |
| 76 | }; | 76 | }; |
| 77 | S.doTheTest(); | 77 | S.doTheTest(); |
| ... | @@ -83,9 +83,9 @@ test "vector bit operators" { | ... | @@ -83,9 +83,9 @@ test "vector bit operators" { |
| 83 | fn doTheTest() void { | 83 | fn doTheTest() void { |
| 84 | var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; | 84 | var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; |
| 85 | var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; | 85 | var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; |
| 86 | expect(mem.eql(u8, ([4]u8)(v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); | 86 | expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); |
| 87 | expect(mem.eql(u8, ([4]u8)(v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); | 87 | expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); |
| 88 | expect(mem.eql(u8, ([4]u8)(v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); | 88 | expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); |
| 89 | } | 89 | } |
| 90 | }; | 90 | }; |
| 91 | S.doTheTest(); | 91 | S.doTheTest(); |
| ... | @@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" { | ... | @@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" { |
| 120 | { | 120 | { |
| 121 | var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; | 121 | var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; |
| 122 | var x: [4]u3 = v; | 122 | var x: [4]u3 = v; |
| 123 | expect(mem.eql(u3, x, ([4]u3)(v))); | 123 | expect(mem.eql(u3, x, @as([4]u3, v))); |
| 124 | } | 124 | } |
| 125 | { | 125 | { |
| 126 | var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; | 126 | var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; |
| 127 | var x: [4]u2 = v; | 127 | var x: [4]u2 = v; |
| 128 | expect(mem.eql(u2, x, ([4]u2)(v))); | 128 | expect(mem.eql(u2, x, @as([4]u2, v))); |
| 129 | } | 129 | } |
| 130 | { | 130 | { |
| 131 | var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; | 131 | var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; |
| 132 | var x: [4]u1 = v; | 132 | var x: [4]u1 = v; |
| 133 | expect(mem.eql(u1, x, ([4]u1)(v))); | 133 | expect(mem.eql(u1, x, @as([4]u1, v))); |
| 134 | } | 134 | } |
| 135 | { | 135 | { |
| 136 | var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; | 136 | var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; |
| 137 | var x: [4]bool = v; | 137 | var x: [4]bool = v; |
| 138 | expect(mem.eql(bool, x, ([4]bool)(v))); | 138 | expect(mem.eql(bool, x, @as([4]bool, v))); |
| 139 | } | 139 | } |
| 140 | } | 140 | } |
| 141 | }; | 141 | }; |
test/stage1/behavior/void.zig+1-1| ... | @@ -26,7 +26,7 @@ test "iterate over a void slice" { | ... | @@ -26,7 +26,7 @@ test "iterate over a void slice" { |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | fn times(n: usize) []const void { | 28 | fn times(n: usize) []const void { |
| 29 | return ([*]void)(undefined)[0..n]; | 29 | return @as([*]void, undefined)[0..n]; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | test "void optional" { | 32 | test "void optional" { |
test/stage1/behavior/while.zig+8-8| ... | @@ -137,7 +137,7 @@ test "while on optional with else result follow else prong" { | ... | @@ -137,7 +137,7 @@ test "while on optional with else result follow else prong" { |
| 137 | const result = while (returnNull()) |value| { | 137 | const result = while (returnNull()) |value| { |
| 138 | break value; | 138 | break value; |
| 139 | } else | 139 | } else |
| 140 | i32(2); | 140 | @as(i32, 2); |
| 141 | expect(result == 2); | 141 | expect(result == 2); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| ... | @@ -145,7 +145,7 @@ test "while on optional with else result follow break prong" { | ... | @@ -145,7 +145,7 @@ test "while on optional with else result follow break prong" { |
| 145 | const result = while (returnOptional(10)) |value| { | 145 | const result = while (returnOptional(10)) |value| { |
| 146 | break value; | 146 | break value; |
| 147 | } else | 147 | } else |
| 148 | i32(2); | 148 | @as(i32, 2); |
| 149 | expect(result == 10); | 149 | expect(result == 10); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| ... | @@ -153,7 +153,7 @@ test "while on error union with else result follow else prong" { | ... | @@ -153,7 +153,7 @@ test "while on error union with else result follow else prong" { |
| 153 | const result = while (returnError()) |value| { | 153 | const result = while (returnError()) |value| { |
| 154 | break value; | 154 | break value; |
| 155 | } else |err| | 155 | } else |err| |
| 156 | i32(2); | 156 | @as(i32, 2); |
| 157 | expect(result == 2); | 157 | expect(result == 2); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| ... | @@ -161,23 +161,23 @@ test "while on error union with else result follow break prong" { | ... | @@ -161,23 +161,23 @@ test "while on error union with else result follow break prong" { |
| 161 | const result = while (returnSuccess(10)) |value| { | 161 | const result = while (returnSuccess(10)) |value| { |
| 162 | break value; | 162 | break value; |
| 163 | } else |err| | 163 | } else |err| |
| 164 | i32(2); | 164 | @as(i32, 2); |
| 165 | expect(result == 10); | 165 | expect(result == 10); |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | test "while on bool with else result follow else prong" { | 168 | test "while on bool with else result follow else prong" { |
| 169 | const result = while (returnFalse()) { | 169 | const result = while (returnFalse()) { |
| 170 | break i32(10); | 170 | break @as(i32, 10); |
| 171 | } else | 171 | } else |
| 172 | i32(2); | 172 | @as(i32, 2); |
| 173 | expect(result == 2); | 173 | expect(result == 2); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | test "while on bool with else result follow break prong" { | 176 | test "while on bool with else result follow break prong" { |
| 177 | const result = while (returnTrue()) { | 177 | const result = while (returnTrue()) { |
| 178 | break i32(10); | 178 | break @as(i32, 10); |
| 179 | } else | 179 | } else |
| 180 | i32(2); | 180 | @as(i32, 2); |
| 181 | expect(result == 10); | 181 | expect(result == 10); |
| 182 | } | 182 | } |
| 183 | 183 |
test/tests.zig+2-2| ... | @@ -411,7 +411,7 @@ pub fn addPkgTests( | ... | @@ -411,7 +411,7 @@ pub fn addPkgTests( |
| 411 | const ArchTag = @TagType(builtin.Arch); | 411 | const ArchTag = @TagType(builtin.Arch); |
| 412 | if (test_target.disable_native and | 412 | if (test_target.disable_native and |
| 413 | test_target.target.getOs() == builtin.os and | 413 | test_target.target.getOs() == builtin.os and |
| 414 | ArchTag(test_target.target.getArch()) == ArchTag(builtin.arch)) | 414 | @as(ArchTag,test_target.target.getArch()) == @as(ArchTag,builtin.arch)) |
| 415 | { | 415 | { |
| 416 | continue; | 416 | continue; |
| 417 | } | 417 | } |
| ... | @@ -429,7 +429,7 @@ pub fn addPkgTests( | ... | @@ -429,7 +429,7 @@ pub fn addPkgTests( |
| 429 | "bare"; | 429 | "bare"; |
| 430 | 430 | ||
| 431 | const triple_prefix = if (test_target.target == .Native) | 431 | const triple_prefix = if (test_target.target == .Native) |
| 432 | ([]const u8)("native") | 432 | @as([]const u8,"native") |
| 433 | else | 433 | else |
| 434 | test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable; | 434 | test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable; |
| 435 | 435 |
test/translate_c.zig+57-57| ... | @@ -28,9 +28,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -28,9 +28,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 28 | , | 28 | , |
| 29 | \\pub fn foo() void { | 29 | \\pub fn foo() void { |
| 30 | \\ var a: c_int = undefined; | 30 | \\ var a: c_int = undefined; |
| 31 | \\ var b: u8 = u8(123); | 31 | \\ var b: u8 = @as(u8, 123); |
| 32 | \\ const c: c_int = undefined; | 32 | \\ const c: c_int = undefined; |
| 33 | \\ const d: c_uint = c_uint(440); | 33 | \\ const d: c_uint = @as(c_uint, 440); |
| 34 | \\} | 34 | \\} |
| 35 | ); | 35 | ); |
| 36 | 36 | ||
| ... | @@ -144,7 +144,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -144,7 +144,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 144 | \\pub extern fn foo() void; | 144 | \\pub extern fn foo() void; |
| 145 | \\pub fn bar() void { | 145 | \\pub fn bar() void { |
| 146 | \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo); | 146 | \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo); |
| 147 | \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, c_ulong(@ptrToInt(func_ptr))); | 147 | \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr))); |
| 148 | \\} | 148 | \\} |
| 149 | ); | 149 | ); |
| 150 | 150 | ||
| ... | @@ -561,43 +561,43 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -561,43 +561,43 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 561 | cases.add("u integer suffix after hex literal", | 561 | cases.add("u integer suffix after hex literal", |
| 562 | \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ | 562 | \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ |
| 563 | , | 563 | , |
| 564 | \\pub const SDL_INIT_VIDEO = c_uint(32); | 564 | \\pub const SDL_INIT_VIDEO = @as(c_uint, 32); |
| 565 | ); | 565 | ); |
| 566 | 566 | ||
| 567 | cases.add("l integer suffix after hex literal", | 567 | cases.add("l integer suffix after hex literal", |
| 568 | \\#define SDL_INIT_VIDEO 0x00000020l /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ | 568 | \\#define SDL_INIT_VIDEO 0x00000020l /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ |
| 569 | , | 569 | , |
| 570 | \\pub const SDL_INIT_VIDEO = c_long(32); | 570 | \\pub const SDL_INIT_VIDEO = @as(c_long, 32); |
| 571 | ); | 571 | ); |
| 572 | 572 | ||
| 573 | cases.add("ul integer suffix after hex literal", | 573 | cases.add("ul integer suffix after hex literal", |
| 574 | \\#define SDL_INIT_VIDEO 0x00000020ul /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ | 574 | \\#define SDL_INIT_VIDEO 0x00000020ul /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ |
| 575 | , | 575 | , |
| 576 | \\pub const SDL_INIT_VIDEO = c_ulong(32); | 576 | \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32); |
| 577 | ); | 577 | ); |
| 578 | 578 | ||
| 579 | cases.add("lu integer suffix after hex literal", | 579 | cases.add("lu integer suffix after hex literal", |
| 580 | \\#define SDL_INIT_VIDEO 0x00000020lu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ | 580 | \\#define SDL_INIT_VIDEO 0x00000020lu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ |
| 581 | , | 581 | , |
| 582 | \\pub const SDL_INIT_VIDEO = c_ulong(32); | 582 | \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32); |
| 583 | ); | 583 | ); |
| 584 | 584 | ||
| 585 | cases.add("ll integer suffix after hex literal", | 585 | cases.add("ll integer suffix after hex literal", |
| 586 | \\#define SDL_INIT_VIDEO 0x00000020ll /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ | 586 | \\#define SDL_INIT_VIDEO 0x00000020ll /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ |
| 587 | , | 587 | , |
| 588 | \\pub const SDL_INIT_VIDEO = c_longlong(32); | 588 | \\pub const SDL_INIT_VIDEO = @as(c_longlong, 32); |
| 589 | ); | 589 | ); |
| 590 | 590 | ||
| 591 | cases.add("ull integer suffix after hex literal", | 591 | cases.add("ull integer suffix after hex literal", |
| 592 | \\#define SDL_INIT_VIDEO 0x00000020ull /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ | 592 | \\#define SDL_INIT_VIDEO 0x00000020ull /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ |
| 593 | , | 593 | , |
| 594 | \\pub const SDL_INIT_VIDEO = c_ulonglong(32); | 594 | \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32); |
| 595 | ); | 595 | ); |
| 596 | 596 | ||
| 597 | cases.add("llu integer suffix after hex literal", | 597 | cases.add("llu integer suffix after hex literal", |
| 598 | \\#define SDL_INIT_VIDEO 0x00000020llu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ | 598 | \\#define SDL_INIT_VIDEO 0x00000020llu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ |
| 599 | , | 599 | , |
| 600 | \\pub const SDL_INIT_VIDEO = c_ulonglong(32); | 600 | \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32); |
| 601 | ); | 601 | ); |
| 602 | 602 | ||
| 603 | cases.add("zig keywords in C code", | 603 | cases.add("zig keywords in C code", |
| ... | @@ -676,8 +676,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -676,8 +676,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 676 | \\pub export fn log2(_arg_a: c_uint) c_int { | 676 | \\pub export fn log2(_arg_a: c_uint) c_int { |
| 677 | \\ var a = _arg_a; | 677 | \\ var a = _arg_a; |
| 678 | \\ var i: c_int = 0; | 678 | \\ var i: c_int = 0; |
| 679 | \\ while (a > c_uint(0)) { | 679 | \\ while (a > @as(c_uint, 0)) { |
| 680 | \\ a >>= @import("std").math.Log2Int(c_uint)(1); | 680 | \\ a >>= @as(@import("std").math.Log2Int(c_uint), 1); |
| 681 | \\ } | 681 | \\ } |
| 682 | \\ return i; | 682 | \\ return i; |
| 683 | \\} | 683 | \\} |
| ... | @@ -848,8 +848,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -848,8 +848,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 848 | \\pub export fn log2(_arg_a: u32) c_int { | 848 | \\pub export fn log2(_arg_a: u32) c_int { |
| 849 | \\ var a = _arg_a; | 849 | \\ var a = _arg_a; |
| 850 | \\ var i: c_int = 0; | 850 | \\ var i: c_int = 0; |
| 851 | \\ while (a > c_uint(0)) { | 851 | \\ while (a > @as(c_uint, 0)) { |
| 852 | \\ a >>= u5(1); | 852 | \\ a >>= @as(u5, 1); |
| 853 | \\ } | 853 | \\ } |
| 854 | \\ return i; | 854 | \\ return i; |
| 855 | \\} | 855 | \\} |
| ... | @@ -937,7 +937,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -937,7 +937,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 937 | \\} | 937 | \\} |
| 938 | , | 938 | , |
| 939 | \\pub export fn float_to_int(a: f32) c_int { | 939 | \\pub export fn float_to_int(a: f32) c_int { |
| 940 | \\ return c_int(a); | 940 | \\ return @as(c_int, a); |
| 941 | \\} | 941 | \\} |
| 942 | ); | 942 | ); |
| 943 | 943 | ||
| ... | @@ -1027,7 +1027,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1027,7 +1027,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1027 | \\} | 1027 | \\} |
| 1028 | , | 1028 | , |
| 1029 | \\pub export fn foo() c_int { | 1029 | \\pub export fn foo() c_int { |
| 1030 | \\ return (1 << @import("std").math.Log2Int(c_int)(2)) >> @import("std").math.Log2Int(c_int)(1); | 1030 | \\ return (1 << @as(@import("std").math.Log2Int(c_int), 2)) >> @as(@import("std").math.Log2Int(c_int), 1); |
| 1031 | \\} | 1031 | \\} |
| 1032 | ); | 1032 | ); |
| 1033 | 1033 | ||
| ... | @@ -1076,14 +1076,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1076,14 +1076,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1076 | \\ _ref.* = (_ref.* ^ 1); | 1076 | \\ _ref.* = (_ref.* ^ 1); |
| 1077 | \\ break :x _ref.*; | 1077 | \\ break :x _ref.*; |
| 1078 | \\ }); | 1078 | \\ }); |
| 1079 | \\ a >>= @import("std").math.Log2Int(c_int)((x: { | 1079 | \\ a >>= @as(@import("std").math.Log2Int(c_int), (x: { |
| 1080 | \\ const _ref = &a; | 1080 | \\ const _ref = &a; |
| 1081 | \\ _ref.* = (_ref.* >> @import("std").math.Log2Int(c_int)(1)); | 1081 | \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_int), 1)); |
| 1082 | \\ break :x _ref.*; | 1082 | \\ break :x _ref.*; |
| 1083 | \\ })); | 1083 | \\ })); |
| 1084 | \\ a <<= @import("std").math.Log2Int(c_int)((x: { | 1084 | \\ a <<= @as(@import("std").math.Log2Int(c_int), (x: { |
| 1085 | \\ const _ref = &a; | 1085 | \\ const _ref = &a; |
| 1086 | \\ _ref.* = (_ref.* << @import("std").math.Log2Int(c_int)(1)); | 1086 | \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_int), 1)); |
| 1087 | \\ break :x _ref.*; | 1087 | \\ break :x _ref.*; |
| 1088 | \\ })); | 1088 | \\ })); |
| 1089 | \\} | 1089 | \\} |
| ... | @@ -1103,45 +1103,45 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1103,45 +1103,45 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1103 | \\} | 1103 | \\} |
| 1104 | , | 1104 | , |
| 1105 | \\pub export fn foo() void { | 1105 | \\pub export fn foo() void { |
| 1106 | \\ var a: c_uint = c_uint(0); | 1106 | \\ var a: c_uint = @as(c_uint, 0); |
| 1107 | \\ a +%= (x: { | 1107 | \\ a +%= (x: { |
| 1108 | \\ const _ref = &a; | 1108 | \\ const _ref = &a; |
| 1109 | \\ _ref.* = (_ref.* +% c_uint(1)); | 1109 | \\ _ref.* = (_ref.* +% @as(c_uint, 1)); |
| 1110 | \\ break :x _ref.*; | 1110 | \\ break :x _ref.*; |
| 1111 | \\ }); | 1111 | \\ }); |
| 1112 | \\ a -%= (x: { | 1112 | \\ a -%= (x: { |
| 1113 | \\ const _ref = &a; | 1113 | \\ const _ref = &a; |
| 1114 | \\ _ref.* = (_ref.* -% c_uint(1)); | 1114 | \\ _ref.* = (_ref.* -% @as(c_uint, 1)); |
| 1115 | \\ break :x _ref.*; | 1115 | \\ break :x _ref.*; |
| 1116 | \\ }); | 1116 | \\ }); |
| 1117 | \\ a *%= (x: { | 1117 | \\ a *%= (x: { |
| 1118 | \\ const _ref = &a; | 1118 | \\ const _ref = &a; |
| 1119 | \\ _ref.* = (_ref.* *% c_uint(1)); | 1119 | \\ _ref.* = (_ref.* *% @as(c_uint, 1)); |
| 1120 | \\ break :x _ref.*; | 1120 | \\ break :x _ref.*; |
| 1121 | \\ }); | 1121 | \\ }); |
| 1122 | \\ a &= (x: { | 1122 | \\ a &= (x: { |
| 1123 | \\ const _ref = &a; | 1123 | \\ const _ref = &a; |
| 1124 | \\ _ref.* = (_ref.* & c_uint(1)); | 1124 | \\ _ref.* = (_ref.* & @as(c_uint, 1)); |
| 1125 | \\ break :x _ref.*; | 1125 | \\ break :x _ref.*; |
| 1126 | \\ }); | 1126 | \\ }); |
| 1127 | \\ a |= (x: { | 1127 | \\ a |= (x: { |
| 1128 | \\ const _ref = &a; | 1128 | \\ const _ref = &a; |
| 1129 | \\ _ref.* = (_ref.* | c_uint(1)); | 1129 | \\ _ref.* = (_ref.* | @as(c_uint, 1)); |
| 1130 | \\ break :x _ref.*; | 1130 | \\ break :x _ref.*; |
| 1131 | \\ }); | 1131 | \\ }); |
| 1132 | \\ a ^= (x: { | 1132 | \\ a ^= (x: { |
| 1133 | \\ const _ref = &a; | 1133 | \\ const _ref = &a; |
| 1134 | \\ _ref.* = (_ref.* ^ c_uint(1)); | 1134 | \\ _ref.* = (_ref.* ^ @as(c_uint, 1)); |
| 1135 | \\ break :x _ref.*; | 1135 | \\ break :x _ref.*; |
| 1136 | \\ }); | 1136 | \\ }); |
| 1137 | \\ a >>= @import("std").math.Log2Int(c_uint)((x: { | 1137 | \\ a >>= @as(@import("std").math.Log2Int(c_uint), (x: { |
| 1138 | \\ const _ref = &a; | 1138 | \\ const _ref = &a; |
| 1139 | \\ _ref.* = (_ref.* >> @import("std").math.Log2Int(c_uint)(1)); | 1139 | \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_uint), 1)); |
| 1140 | \\ break :x _ref.*; | 1140 | \\ break :x _ref.*; |
| 1141 | \\ })); | 1141 | \\ })); |
| 1142 | \\ a <<= @import("std").math.Log2Int(c_uint)((x: { | 1142 | \\ a <<= @as(@import("std").math.Log2Int(c_uint), (x: { |
| 1143 | \\ const _ref = &a; | 1143 | \\ const _ref = &a; |
| 1144 | \\ _ref.* = (_ref.* << @import("std").math.Log2Int(c_uint)(1)); | 1144 | \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_uint), 1)); |
| 1145 | \\ break :x _ref.*; | 1145 | \\ break :x _ref.*; |
| 1146 | \\ })); | 1146 | \\ })); |
| 1147 | \\} | 1147 | \\} |
| ... | @@ -1174,7 +1174,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1174,7 +1174,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1174 | , | 1174 | , |
| 1175 | \\pub export fn foo() void { | 1175 | \\pub export fn foo() void { |
| 1176 | \\ var i: c_int = 0; | 1176 | \\ var i: c_int = 0; |
| 1177 | \\ var u: c_uint = c_uint(0); | 1177 | \\ var u: c_uint = @as(c_uint, 0); |
| 1178 | \\ i += 1; | 1178 | \\ i += 1; |
| 1179 | \\ i -= 1; | 1179 | \\ i -= 1; |
| 1180 | \\ u +%= 1; | 1180 | \\ u +%= 1; |
| ... | @@ -1222,7 +1222,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1222,7 +1222,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1222 | , | 1222 | , |
| 1223 | \\pub export fn foo() void { | 1223 | \\pub export fn foo() void { |
| 1224 | \\ var i: c_int = 0; | 1224 | \\ var i: c_int = 0; |
| 1225 | \\ var u: c_uint = c_uint(0); | 1225 | \\ var u: c_uint = @as(c_uint, 0); |
| 1226 | \\ i += 1; | 1226 | \\ i += 1; |
| 1227 | \\ i -= 1; | 1227 | \\ i -= 1; |
| 1228 | \\ u +%= 1; | 1228 | \\ u +%= 1; |
| ... | @@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1539 | cases.add("macro pointer cast", | 1539 | cases.add("macro pointer cast", |
| 1540 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) | 1540 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) |
| 1541 | , | 1541 | , |
| 1542 | \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else ([*c]NRF_GPIO_Type)(NRF_GPIO_BASE); | 1542 | \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE); |
| 1543 | ); | 1543 | ); |
| 1544 | 1544 | ||
| 1545 | cases.add("if on non-bool", | 1545 | cases.add("if on non-bool", |
| ... | @@ -1564,7 +1564,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1564,7 +1564,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1564 | \\ if (a != 0) return 0; | 1564 | \\ if (a != 0) return 0; |
| 1565 | \\ if (b != 0) return 1; | 1565 | \\ if (b != 0) return 1; |
| 1566 | \\ if (c != null) return 2; | 1566 | \\ if (c != null) return 2; |
| 1567 | \\ if (d != @bitCast(enum_SomeEnum, @TagType(enum_SomeEnum)(0))) return 3; | 1567 | \\ if (d != @bitCast(enum_SomeEnum, @as(@TagType(enum_SomeEnum), 0))) return 3; |
| 1568 | \\ return 4; | 1568 | \\ return 4; |
| 1569 | \\} | 1569 | \\} |
| 1570 | ); | 1570 | ); |
| ... | @@ -1646,49 +1646,49 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1646,49 +1646,49 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1646 | cases.addC( | 1646 | cases.addC( |
| 1647 | "u integer suffix after 0 (zero) in macro definition", | 1647 | "u integer suffix after 0 (zero) in macro definition", |
| 1648 | "#define ZERO 0U", | 1648 | "#define ZERO 0U", |
| 1649 | "pub const ZERO = c_uint(0);", | 1649 | "pub const ZERO = @as(c_uint, 0);", |
| 1650 | ); | 1650 | ); |
| 1651 | 1651 | ||
| 1652 | cases.addC( | 1652 | cases.addC( |
| 1653 | "l integer suffix after 0 (zero) in macro definition", | 1653 | "l integer suffix after 0 (zero) in macro definition", |
| 1654 | "#define ZERO 0L", | 1654 | "#define ZERO 0L", |
| 1655 | "pub const ZERO = c_long(0);", | 1655 | "pub const ZERO = @as(c_long, 0);", |
| 1656 | ); | 1656 | ); |
| 1657 | 1657 | ||
| 1658 | cases.addC( | 1658 | cases.addC( |
| 1659 | "ul integer suffix after 0 (zero) in macro definition", | 1659 | "ul integer suffix after 0 (zero) in macro definition", |
| 1660 | "#define ZERO 0UL", | 1660 | "#define ZERO 0UL", |
| 1661 | "pub const ZERO = c_ulong(0);", | 1661 | "pub const ZERO = @as(c_ulong, 0);", |
| 1662 | ); | 1662 | ); |
| 1663 | 1663 | ||
| 1664 | cases.addC( | 1664 | cases.addC( |
| 1665 | "lu integer suffix after 0 (zero) in macro definition", | 1665 | "lu integer suffix after 0 (zero) in macro definition", |
| 1666 | "#define ZERO 0LU", | 1666 | "#define ZERO 0LU", |
| 1667 | "pub const ZERO = c_ulong(0);", | 1667 | "pub const ZERO = @as(c_ulong, 0);", |
| 1668 | ); | 1668 | ); |
| 1669 | 1669 | ||
| 1670 | cases.addC( | 1670 | cases.addC( |
| 1671 | "ll integer suffix after 0 (zero) in macro definition", | 1671 | "ll integer suffix after 0 (zero) in macro definition", |
| 1672 | "#define ZERO 0LL", | 1672 | "#define ZERO 0LL", |
| 1673 | "pub const ZERO = c_longlong(0);", | 1673 | "pub const ZERO = @as(c_longlong, 0);", |
| 1674 | ); | 1674 | ); |
| 1675 | 1675 | ||
| 1676 | cases.addC( | 1676 | cases.addC( |
| 1677 | "ull integer suffix after 0 (zero) in macro definition", | 1677 | "ull integer suffix after 0 (zero) in macro definition", |
| 1678 | "#define ZERO 0ULL", | 1678 | "#define ZERO 0ULL", |
| 1679 | "pub const ZERO = c_ulonglong(0);", | 1679 | "pub const ZERO = @as(c_ulonglong, 0);", |
| 1680 | ); | 1680 | ); |
| 1681 | 1681 | ||
| 1682 | cases.addC( | 1682 | cases.addC( |
| 1683 | "llu integer suffix after 0 (zero) in macro definition", | 1683 | "llu integer suffix after 0 (zero) in macro definition", |
| 1684 | "#define ZERO 0LLU", | 1684 | "#define ZERO 0LLU", |
| 1685 | "pub const ZERO = c_ulonglong(0);", | 1685 | "pub const ZERO = @as(c_ulonglong, 0);", |
| 1686 | ); | 1686 | ); |
| 1687 | 1687 | ||
| 1688 | cases.addC( | 1688 | cases.addC( |
| 1689 | "bitwise not on u-suffixed 0 (zero) in macro definition", | 1689 | "bitwise not on u-suffixed 0 (zero) in macro definition", |
| 1690 | "#define NOT_ZERO (~0U)", | 1690 | "#define NOT_ZERO (~0U)", |
| 1691 | "pub const NOT_ZERO = ~c_uint(0);", | 1691 | "pub const NOT_ZERO = ~@as(c_uint, 0);", |
| 1692 | ); | 1692 | ); |
| 1693 | 1693 | ||
| 1694 | cases.addC("implicit casts", | 1694 | cases.addC("implicit casts", |
| ... | @@ -1733,9 +1733,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1733,9 +1733,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1733 | \\ fn_int(1094861636); | 1733 | \\ fn_int(1094861636); |
| 1734 | \\ fn_f32(@intToFloat(f32, 3)); | 1734 | \\ fn_f32(@intToFloat(f32, 3)); |
| 1735 | \\ fn_f64(@intToFloat(f64, 3)); | 1735 | \\ fn_f64(@intToFloat(f64, 3)); |
| 1736 | \\ fn_char(u8('3')); | 1736 | \\ fn_char(@as(u8, '3')); |
| 1737 | \\ fn_char(u8('\x01')); | 1737 | \\ fn_char(@as(u8, '\x01')); |
| 1738 | \\ fn_char(u8(0)); | 1738 | \\ fn_char(@as(u8, 0)); |
| 1739 | \\ fn_f32(3.000000); | 1739 | \\ fn_f32(3.000000); |
| 1740 | \\ fn_f64(3.000000); | 1740 | \\ fn_f64(3.000000); |
| 1741 | \\ fn_bool(true); | 1741 | \\ fn_bool(true); |
| ... | @@ -1798,17 +1798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -1798,17 +1798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1798 | \\ | 1798 | \\ |
| 1799 | , | 1799 | , |
| 1800 | \\pub export fn escapes() [*c]const u8 { | 1800 | \\pub export fn escapes() [*c]const u8 { |
| 1801 | \\ var a: u8 = u8('\''); | 1801 | \\ var a: u8 = @as(u8, '\''); |
| 1802 | \\ var b: u8 = u8('\\'); | 1802 | \\ var b: u8 = @as(u8, '\\'); |
| 1803 | \\ var c: u8 = u8('\x07'); | 1803 | \\ var c: u8 = @as(u8, '\x07'); |
| 1804 | \\ var d: u8 = u8('\x08'); | 1804 | \\ var d: u8 = @as(u8, '\x08'); |
| 1805 | \\ var e: u8 = u8('\x0c'); | 1805 | \\ var e: u8 = @as(u8, '\x0c'); |
| 1806 | \\ var f: u8 = u8('\n'); | 1806 | \\ var f: u8 = @as(u8, '\n'); |
| 1807 | \\ var g: u8 = u8('\r'); | 1807 | \\ var g: u8 = @as(u8, '\r'); |
| 1808 | \\ var h: u8 = u8('\t'); | 1808 | \\ var h: u8 = @as(u8, '\t'); |
| 1809 | \\ var i: u8 = u8('\x0b'); | 1809 | \\ var i: u8 = @as(u8, '\x0b'); |
| 1810 | \\ var j: u8 = u8('\x00'); | 1810 | \\ var j: u8 = @as(u8, '\x00'); |
| 1811 | \\ var k: u8 = u8('\"'); | 1811 | \\ var k: u8 = @as(u8, '\"'); |
| 1812 | \\ return c"\'\\\x07\x08\x0c\n\r\t\x0b\x00\""; | 1812 | \\ return c"\'\\\x07\x08\x0c\n\r\t\x0b\x00\""; |
| 1813 | \\} | 1813 | \\} |
| 1814 | \\ | 1814 | \\ |