| ... | @@ -965,7 +965,8 @@ const nan = std.math.nan(f128); | ... | @@ -965,7 +965,8 @@ const nan = std.math.nan(f128); |
| 965 | but you can switch to {#syntax#}Optimized{#endsyntax#} mode on a per-block basis:</p> | 965 | but you can switch to {#syntax#}Optimized{#endsyntax#} mode on a per-block basis:</p> |
| 966 | {#code_begin|obj|foo#} | 966 | {#code_begin|obj|foo#} |
| 967 | {#code_release_fast#} | 967 | {#code_release_fast#} |
| 968 | const builtin = @import("builtin"); | 968 | const std = @import("std"); |
| | 969 | const builtin = std.builtin; |
| 969 | const big = @as(f64, 1 << 40); | 970 | const big = @as(f64, 1 << 40); |
| 970 | | 971 | |
| 971 | export fn foo_strict(x: f64) f64 { | 972 | export fn foo_strict(x: f64) f64 { |
| ... | @@ -2063,15 +2064,15 @@ test "pointer child type" { | ... | @@ -2063,15 +2064,15 @@ test "pointer child type" { |
| 2063 | alignment of the underlying type, it can be omitted from the type: | 2064 | alignment of the underlying type, it can be omitted from the type: |
| 2064 | </p> | 2065 | </p> |
| 2065 | {#code_begin|test#} | 2066 | {#code_begin|test#} |
| 2066 | const assert = @import("std").debug.assert; | 2067 | const std = @import("std"); |
| 2067 | const builtin = @import("builtin"); | 2068 | const assert = std.debug.assert; |
| 2068 | | 2069 | |
| 2069 | test "variable alignment" { | 2070 | test "variable alignment" { |
| 2070 | var x: i32 = 1234; | 2071 | var x: i32 = 1234; |
| 2071 | const align_of_i32 = @alignOf(@TypeOf(x)); | 2072 | const align_of_i32 = @alignOf(@TypeOf(x)); |
| 2072 | assert(@TypeOf(&x) == *i32); | 2073 | assert(@TypeOf(&x) == *i32); |
| 2073 | assert(*i32 == *align(align_of_i32) i32); | 2074 | assert(*i32 == *align(align_of_i32) i32); |
| 2074 | if (builtin.arch == builtin.Arch.x86_64) { | 2075 | if (std.Target.current.cpu.arch == .x86_64) { |
| 2075 | assert((*i32).alignment == 4); | 2076 | assert((*i32).alignment == 4); |
| 2076 | } | 2077 | } |
| 2077 | } | 2078 | } |
| ... | @@ -2474,7 +2475,7 @@ test "default struct initialization fields" { | ... | @@ -2474,7 +2475,7 @@ test "default struct initialization fields" { |
| 2474 | </p> | 2475 | </p> |
| 2475 | {#code_begin|test#} | 2476 | {#code_begin|test#} |
| 2476 | const std = @import("std"); | 2477 | const std = @import("std"); |
| 2477 | const builtin = @import("builtin"); | 2478 | const builtin = std.builtin; |
| 2478 | const assert = std.debug.assert; | 2479 | const assert = std.debug.assert; |
| 2479 | | 2480 | |
| 2480 | const Full = packed struct { | 2481 | const Full = packed struct { |
| ... | @@ -3204,8 +3205,8 @@ test "separate scopes" { | ... | @@ -3204,8 +3205,8 @@ test "separate scopes" { |
| 3204 | | 3205 | |
| 3205 | {#header_open|switch#} | 3206 | {#header_open|switch#} |
| 3206 | {#code_begin|test|switch#} | 3207 | {#code_begin|test|switch#} |
| 3207 | const assert = @import("std").debug.assert; | 3208 | const std = @import("std"); |
| 3208 | const builtin = @import("builtin"); | 3209 | const assert = std.debug.assert; |
| 3209 | | 3210 | |
| 3210 | test "switch simple" { | 3211 | test "switch simple" { |
| 3211 | const a: u64 = 10; | 3212 | const a: u64 = 10; |
| ... | @@ -3249,16 +3250,16 @@ test "switch simple" { | ... | @@ -3249,16 +3250,16 @@ test "switch simple" { |
| 3249 | } | 3250 | } |
| 3250 | | 3251 | |
| 3251 | // Switch expressions can be used outside a function: | 3252 | // Switch expressions can be used outside a function: |
| 3252 | const os_msg = switch (builtin.os) { | 3253 | const os_msg = switch (std.Target.current.os.tag) { |
| 3253 | builtin.Os.linux => "we found a linux user", | 3254 | .linux => "we found a linux user", |
| 3254 | else => "not a linux user", | 3255 | else => "not a linux user", |
| 3255 | }; | 3256 | }; |
| 3256 | | 3257 | |
| 3257 | // Inside a function, switch statements implicitly are compile-time | 3258 | // Inside a function, switch statements implicitly are compile-time |
| 3258 | // evaluated if the target expression is compile-time known. | 3259 | // evaluated if the target expression is compile-time known. |
| 3259 | test "switch inside function" { | 3260 | test "switch inside function" { |
| 3260 | switch (builtin.os) { | 3261 | switch (std.Target.current.os.tag) { |
| 3261 | builtin.Os.fuchsia => { | 3262 | .fuchsia => { |
| 3262 | // On an OS other than fuchsia, block is not even analyzed, | 3263 | // On an OS other than fuchsia, block is not even analyzed, |
| 3263 | // so this compile error is not triggered. | 3264 | // so this compile error is not triggered. |
| 3264 | // On fuchsia this compile error would be triggered. | 3265 | // On fuchsia this compile error would be triggered. |
| ... | @@ -7364,8 +7365,6 @@ test "main" { | ... | @@ -7364,8 +7365,6 @@ test "main" { |
| 7364 | the {#syntax#}export{#endsyntax#} keyword used on a function: | 7365 | the {#syntax#}export{#endsyntax#} keyword used on a function: |
| 7365 | </p> | 7366 | </p> |
| 7366 | {#code_begin|obj#} | 7367 | {#code_begin|obj#} |
| 7367 | const builtin = @import("builtin"); | | |
| 7368 | | | |
| 7369 | comptime { | 7368 | comptime { |
| 7370 | @export(internalName, .{ .name = "foo", .linkage = .Strong }); | 7369 | @export(internalName, .{ .name = "foo", .linkage = .Strong }); |
| 7371 | } | 7370 | } |
| ... | @@ -9397,7 +9396,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/'; | ... | @@ -9397,7 +9396,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/'; |
| 9397 | </p> | 9396 | </p> |
| 9398 | {#code_begin|test|detect_test#} | 9397 | {#code_begin|test|detect_test#} |
| 9399 | const std = @import("std"); | 9398 | const std = @import("std"); |
| 9400 | const builtin = @import("builtin"); | 9399 | const builtin = std.builtin; |
| 9401 | const assert = std.debug.assert; | 9400 | const assert = std.debug.assert; |
| 9402 | | 9401 | |
| 9403 | test "builtin.is_test" { | 9402 | test "builtin.is_test" { |
| ... | @@ -9715,7 +9714,8 @@ WebAssembly.instantiate(typedArray, { | ... | @@ -9715,7 +9714,8 @@ WebAssembly.instantiate(typedArray, { |
| 9715 | <pre><code>$ node test.js | 9714 | <pre><code>$ node test.js |
| 9716 | The result is 3</code></pre> | 9715 | The result is 3</code></pre> |
| 9717 | {#header_open|WASI#} | 9716 | {#header_open|WASI#} |
| 9718 | <p>Zig's support for WebAssembly System Interface (WASI) is under active development. Example of using the standard library and reading command line arguments:</p> | 9717 | <p>Zig's support for WebAssembly System Interface (WASI) is under active development. |
| | 9718 | Example of using the standard library and reading command line arguments:</p> |
| 9719 | {#code_begin|exe|wasi#} | 9719 | {#code_begin|exe|wasi#} |
| 9720 | {#target_wasi#} | 9720 | {#target_wasi#} |
| 9721 | const std = @import("std"); | 9721 | const std = @import("std"); |