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