| ... | @@ -21,37 +21,41 @@ test "super basic invocations" { | ... | @@ -21,37 +21,41 @@ test "super basic invocations" { |
| 21 | | 21 | |
| 22 | test "basic invocations" { | 22 | test "basic invocations" { |
| 23 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 23 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 24 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | | |
| 25 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 24 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 26 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 25 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 27 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 26 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 28 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 27 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 29 | | 28 | |
| | 29 | if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support tail call modifiers |
| | 30 | |
| 30 | const foo = struct { | 31 | const foo = struct { |
| 31 | fn foo() i32 { | 32 | fn foo(_: i32) i32 { |
| 32 | return 1234; | 33 | return 1234; |
| 33 | } | 34 | } |
| 34 | }.foo; | 35 | }.foo; |
| 35 | try expect(@call(.auto, foo, .{}) == 1234); | 36 | try expect(@call(.auto, foo, .{1}) == 1234); |
| 36 | comptime { | 37 | comptime { |
| 37 | // modifiers that allow comptime calls | 38 | // comptime calls with supported modifiers |
| 38 | try expect(@call(.auto, foo, .{}) == 1234); | 39 | try expect(@call(.auto, foo, .{2}) == 1234); |
| 39 | try expect(@call(.no_async, foo, .{}) == 1234); | 40 | try expect(@call(.no_async, foo, .{3}) == 1234); |
| 40 | try expect(@call(.always_tail, foo, .{}) == 1234); | 41 | try expect(@call(.always_tail, foo, .{4}) == 1234); |
| 41 | try expect(@call(.always_inline, foo, .{}) == 1234); | 42 | try expect(@call(.always_inline, foo, .{5}) == 1234); |
| 42 | } | 43 | } |
| 43 | { | 44 | // comptime call without comptime keyword |
| 44 | // comptime call without comptime keyword | 45 | const result = @call(.compile_time, foo, .{6}) == 1234; |
| 45 | const result = @call(.compile_time, foo, .{}) == 1234; | 46 | comptime assert(result); |
| 46 | comptime assert(result); | 47 | // runtime calls of comptime-known function |
| 47 | } | 48 | try expect(@call(.no_async, foo, .{7}) == 1234); |
| 48 | { | 49 | try expect(@call(.never_tail, foo, .{8}) == 1234); |
| 49 | // call of non comptime-known function | 50 | try expect(@call(.never_inline, foo, .{9}) == 1234); |
| | 51 | // CBE does not support attributes on runtime functions |
| | 52 | if (builtin.zig_backend != .stage2_c) { |
| | 53 | // runtime calls of non comptime-known function |
| 50 | var alias_foo = &foo; | 54 | var alias_foo = &foo; |
| 51 | _ = &alias_foo; | 55 | _ = &alias_foo; |
| 52 | try expect(@call(.no_async, alias_foo, .{}) == 1234); | 56 | try expect(@call(.no_async, alias_foo, .{10}) == 1234); |
| 53 | try expect(@call(.never_tail, alias_foo, .{}) == 1234); | 57 | try expect(@call(.never_tail, alias_foo, .{11}) == 1234); |
| 54 | try expect(@call(.never_inline, alias_foo, .{}) == 1234); | 58 | try expect(@call(.never_inline, alias_foo, .{12}) == 1234); |
| 55 | } | 59 | } |
| 56 | } | 60 | } |
| 57 | | 61 | |