mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
test: fix x86_64-macos failures
This is just a temporary fix - I would like to unify all of x86_64 tests across linux and macos OSes.
This commit is contained in:
parent
5a5648c0f0
commit
2875216f8e
@ -1,36 +0,0 @@
|
||||
const builtin = @import("builtin");
|
||||
|
||||
extern "c" fn write(usize, usize, usize) usize;
|
||||
|
||||
pub fn main() void {
|
||||
var i: u32 = 0;
|
||||
inline while (i < 4) : (i += 1) print();
|
||||
assert(i == 4);
|
||||
}
|
||||
|
||||
fn print() void {
|
||||
switch (builtin.os.tag) {
|
||||
.linux => {
|
||||
asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{rax}" (1),
|
||||
[arg1] "{rdi}" (1),
|
||||
[arg2] "{rsi}" (@ptrToInt("hello\n")),
|
||||
[arg3] "{rdx}" (6),
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
},
|
||||
.macos => {
|
||||
_ = write(1, @ptrToInt("hello\n"), 6);
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :7:21: error: unable to resolve comptime value
|
||||
@ -1,34 +0,0 @@
|
||||
const builtin = @import("builtin");
|
||||
|
||||
extern "c" fn write(usize, usize, usize) usize;
|
||||
|
||||
pub fn main() void {
|
||||
comptime var len: u32 = 5;
|
||||
print(len);
|
||||
len += 9;
|
||||
print(len);
|
||||
}
|
||||
|
||||
fn print(len: usize) void {
|
||||
switch (builtin.os.tag) {
|
||||
.linux => {
|
||||
asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{rax}" (1),
|
||||
[arg1] "{rdi}" (1),
|
||||
[arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
|
||||
[arg3] "{rdx}" (len),
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
},
|
||||
.macos => {
|
||||
_ = write(1, @ptrToInt("Hello, World!\n"), len);
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
// HelloHello, World!
|
||||
//
|
||||
@ -1,32 +0,0 @@
|
||||
const builtin = @import("builtin");
|
||||
|
||||
extern "c" fn write(usize, usize, usize) usize;
|
||||
|
||||
pub fn main() void {
|
||||
comptime var i: u64 = 2;
|
||||
inline while (i < 6) : (i += 1) {
|
||||
print(i);
|
||||
}
|
||||
}
|
||||
fn print(len: usize) void {
|
||||
switch (builtin.os.tag) {
|
||||
.linux => {
|
||||
asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{rax}" (1),
|
||||
[arg1] "{rdi}" (1),
|
||||
[arg2] "{rsi}" (@ptrToInt("Hello")),
|
||||
[arg3] "{rdx}" (len),
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
},
|
||||
.macos => {
|
||||
_ = write(1, @ptrToInt("Hello"), len);
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
// HeHelHellHello
|
||||
@ -8,5 +8,5 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -8,5 +8,5 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -9,5 +9,5 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -9,5 +9,5 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -6,6 +6,6 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
// :3:21: error: expected *anyopaque, found ?usize
|
||||
|
||||
@ -18,5 +18,5 @@ pub fn main() void {
|
||||
|
||||
// run
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -8,5 +8,5 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -12,5 +12,5 @@ pub fn main() void {
|
||||
|
||||
// run
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -6,7 +6,7 @@ pub fn main() void {
|
||||
|
||||
// run
|
||||
// backend=llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
// hello world!
|
||||
//
|
||||
|
||||
@ -8,6 +8,6 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
// :2:12: error: expected *i32, found *addrspace(.gs) i32
|
||||
|
||||
@ -8,6 +8,6 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
// :2:12: error: expected *i32, found *addrspace(.gs) i32
|
||||
|
||||
@ -20,5 +20,5 @@ pub fn main() void {
|
||||
|
||||
// run
|
||||
// backend=stage2, llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -41,5 +41,5 @@ pub fn main() void {
|
||||
|
||||
// run
|
||||
// backend=llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -8,5 +8,5 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -8,5 +8,5 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -8,5 +8,5 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -8,6 +8,6 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
// :2:12: error: expected *addrspace(.fs) i32, found *addrspace(.gs) i32
|
||||
|
||||
@ -8,6 +8,6 @@ pub fn main() void {
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
// :2:13: error: expected *i32, found *addrspace(.gs) i32
|
||||
|
||||
@ -11,5 +11,5 @@ pub fn main() void {
|
||||
|
||||
// run
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -8,5 +8,5 @@ fn assert(a: u32, b: u32) void {
|
||||
|
||||
// run
|
||||
// backend=llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -16,5 +16,5 @@ fn assert(ok: bool) void {
|
||||
|
||||
// run
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -12,5 +12,5 @@ pub fn main() void {
|
||||
|
||||
// run
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -14,5 +14,5 @@ pub fn main() void {
|
||||
|
||||
// run
|
||||
// backend=stage2,llvm
|
||||
// target=x86_64-linux
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
//
|
||||
|
||||
@ -11,5 +11,5 @@ pub fn assert(ok: bool) void {
|
||||
}
|
||||
|
||||
// run
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
// target=x86_64-linux
|
||||
//
|
||||
28
test/incremental/x86_64-linux/assert_function.7.zig
Normal file
28
test/incremental/x86_64-linux/assert_function.7.zig
Normal file
@ -0,0 +1,28 @@
|
||||
pub fn main() void {
|
||||
var i: u32 = 0;
|
||||
while (i < 4) : (i += 1) print();
|
||||
assert(i == 4);
|
||||
}
|
||||
|
||||
fn print() void {
|
||||
asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{rax}" (1),
|
||||
[arg1] "{rdi}" (1),
|
||||
[arg2] "{rsi}" (@ptrToInt("hello\n")),
|
||||
[arg3] "{rdx}" (6),
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
// hello
|
||||
// hello
|
||||
// hello
|
||||
// hello
|
||||
//
|
||||
24
test/incremental/x86_64-linux/assert_function.8.zig
Normal file
24
test/incremental/x86_64-linux/assert_function.8.zig
Normal file
@ -0,0 +1,24 @@
|
||||
pub fn main() void {
|
||||
var i: u32 = 0;
|
||||
inline while (i < 4) : (i += 1) print();
|
||||
assert(i == 4);
|
||||
}
|
||||
|
||||
fn print() void {
|
||||
asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{rax}" (1),
|
||||
[arg1] "{rdi}" (1),
|
||||
[arg2] "{rsi}" (@ptrToInt("hello\n")),
|
||||
[arg3] "{rdx}" (6),
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :5:21: error: unable to resolve comptime value
|
||||
@ -6,7 +6,7 @@ pub fn main() void {
|
||||
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// target=x86_64-linux,x86_64-macos
|
||||
// target=x86_64-linux
|
||||
//
|
||||
// :4:21: error: store to comptime variable depends on runtime condition
|
||||
// :4:11: note: runtime condition here
|
||||
22
test/incremental/x86_64-linux/comptime_var.2.zig
Normal file
22
test/incremental/x86_64-linux/comptime_var.2.zig
Normal file
@ -0,0 +1,22 @@
|
||||
pub fn main() void {
|
||||
comptime var len: u32 = 5;
|
||||
print(len);
|
||||
len += 9;
|
||||
print(len);
|
||||
}
|
||||
|
||||
fn print(len: usize) void {
|
||||
asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{rax}" (1),
|
||||
[arg1] "{rdi}" (1),
|
||||
[arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
|
||||
[arg3] "{rdx}" (len),
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
// HelloHello, World!
|
||||
//
|
||||
20
test/incremental/x86_64-linux/comptime_var.6.zig
Normal file
20
test/incremental/x86_64-linux/comptime_var.6.zig
Normal file
@ -0,0 +1,20 @@
|
||||
pub fn main() void {
|
||||
comptime var i: u64 = 2;
|
||||
inline while (i < 6) : (i += 1) {
|
||||
print(i);
|
||||
}
|
||||
}
|
||||
fn print(len: usize) void {
|
||||
asm volatile ("syscall"
|
||||
:
|
||||
: [number] "{rax}" (1),
|
||||
[arg1] "{rdi}" (1),
|
||||
[arg2] "{rsi}" (@ptrToInt("Hello")),
|
||||
[arg3] "{rdx}" (len),
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
// HeHelHellHello
|
||||
15
test/incremental/x86_64-macos/assert_function.0.zig
Normal file
15
test/incremental/x86_64-macos/assert_function.0.zig
Normal file
@ -0,0 +1,15 @@
|
||||
pub fn main() void {
|
||||
add(3, 4);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) void {
|
||||
assert(a + b == 7);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
// target=x86_64-macos
|
||||
//
|
||||
17
test/incremental/x86_64-macos/assert_function.1.zig
Normal file
17
test/incremental/x86_64-macos/assert_function.1.zig
Normal file
@ -0,0 +1,17 @@
|
||||
pub fn main() void {
|
||||
add(3, 4);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) void {
|
||||
const c = a + b; // 7
|
||||
const d = a + c; // 10
|
||||
const e = d + b; // 14
|
||||
assert(e == 14);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
27
test/incremental/x86_64-macos/assert_function.10.zig
Normal file
27
test/incremental/x86_64-macos/assert_function.10.zig
Normal file
@ -0,0 +1,27 @@
|
||||
pub fn main() void {
|
||||
assert(add(3, 4) == 116);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) u32 {
|
||||
const x: u32 = blk: {
|
||||
const c = a + b; // 7
|
||||
const d = a + c; // 10
|
||||
const e = d + b; // 14
|
||||
const f = d + e; // 24
|
||||
const g = e + f; // 38
|
||||
const h = f + g; // 62
|
||||
const i = g + h; // 100
|
||||
const j = i + d; // 110
|
||||
break :blk j;
|
||||
};
|
||||
const y = x + a; // 113
|
||||
const z = y + a; // 116
|
||||
return z;
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
66
test/incremental/x86_64-macos/assert_function.11.zig
Normal file
66
test/incremental/x86_64-macos/assert_function.11.zig
Normal file
@ -0,0 +1,66 @@
|
||||
pub fn main() void {
|
||||
assert(add(3, 4) == 1221);
|
||||
assert(mul(3, 4) == 21609);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) u32 {
|
||||
const x: u32 = blk: {
|
||||
const c = a + b; // 7
|
||||
const d = a + c; // 10
|
||||
const e = d + b; // 14
|
||||
const f = d + e; // 24
|
||||
const g = e + f; // 38
|
||||
const h = f + g; // 62
|
||||
const i = g + h; // 100
|
||||
const j = i + d; // 110
|
||||
const k = i + j; // 210
|
||||
const l = j + k; // 320
|
||||
const m = l + c; // 327
|
||||
const n = m + d; // 337
|
||||
const o = n + e; // 351
|
||||
const p = o + f; // 375
|
||||
const q = p + g; // 413
|
||||
const r = q + h; // 475
|
||||
const s = r + i; // 575
|
||||
const t = s + j; // 685
|
||||
const u = t + k; // 895
|
||||
const v = u + l; // 1215
|
||||
break :blk v;
|
||||
};
|
||||
const y = x + a; // 1218
|
||||
const z = y + a; // 1221
|
||||
return z;
|
||||
}
|
||||
|
||||
fn mul(a: u32, b: u32) u32 {
|
||||
const x: u32 = blk: {
|
||||
const c = a * a * a * a; // 81
|
||||
const d = a * a * a * b; // 108
|
||||
const e = a * a * b * a; // 108
|
||||
const f = a * a * b * b; // 144
|
||||
const g = a * b * a * a; // 108
|
||||
const h = a * b * a * b; // 144
|
||||
const i = a * b * b * a; // 144
|
||||
const j = a * b * b * b; // 192
|
||||
const k = b * a * a * a; // 108
|
||||
const l = b * a * a * b; // 144
|
||||
const m = b * a * b * a; // 144
|
||||
const n = b * a * b * b; // 192
|
||||
const o = b * b * a * a; // 144
|
||||
const p = b * b * a * b; // 192
|
||||
const q = b * b * b * a; // 192
|
||||
const r = b * b * b * b; // 256
|
||||
const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
|
||||
break :blk s;
|
||||
};
|
||||
const y = x * a; // 7203
|
||||
const z = y * a; // 21609
|
||||
return z;
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
47
test/incremental/x86_64-macos/assert_function.12.zig
Normal file
47
test/incremental/x86_64-macos/assert_function.12.zig
Normal file
@ -0,0 +1,47 @@
|
||||
pub fn main() void {
|
||||
assert(add(3, 4) == 791);
|
||||
assert(add(4, 3) == 79);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) u32 {
|
||||
const x: u32 = if (a < b) blk: {
|
||||
const c = a + b; // 7
|
||||
const d = a + c; // 10
|
||||
const e = d + b; // 14
|
||||
const f = d + e; // 24
|
||||
const g = e + f; // 38
|
||||
const h = f + g; // 62
|
||||
const i = g + h; // 100
|
||||
const j = i + d; // 110
|
||||
const k = i + j; // 210
|
||||
const l = k + c; // 217
|
||||
const m = l + d; // 227
|
||||
const n = m + e; // 241
|
||||
const o = n + f; // 265
|
||||
const p = o + g; // 303
|
||||
const q = p + h; // 365
|
||||
const r = q + i; // 465
|
||||
const s = r + j; // 575
|
||||
const t = s + k; // 785
|
||||
break :blk t;
|
||||
} else blk: {
|
||||
const t = b + b + a; // 10
|
||||
const c = a + t; // 14
|
||||
const d = c + t; // 24
|
||||
const e = d + t; // 34
|
||||
const f = e + t; // 44
|
||||
const g = f + t; // 54
|
||||
const h = c + g; // 68
|
||||
break :blk h + b; // 71
|
||||
};
|
||||
const y = x + a; // 788, 75
|
||||
const z = y + a; // 791, 79
|
||||
return z;
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
19
test/incremental/x86_64-macos/assert_function.13.zig
Normal file
19
test/incremental/x86_64-macos/assert_function.13.zig
Normal file
@ -0,0 +1,19 @@
|
||||
pub fn main() void {
|
||||
const ignore =
|
||||
\\ cool thx
|
||||
\\
|
||||
;
|
||||
_ = ignore;
|
||||
add('ぁ', '\x03');
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) void {
|
||||
assert(a + b == 12356);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
17
test/incremental/x86_64-macos/assert_function.14.zig
Normal file
17
test/incremental/x86_64-macos/assert_function.14.zig
Normal file
@ -0,0 +1,17 @@
|
||||
pub fn main() void {
|
||||
add(aa, bb);
|
||||
}
|
||||
|
||||
const aa = 'ぁ';
|
||||
const bb = '\x03';
|
||||
|
||||
fn add(a: u32, b: u32) void {
|
||||
assert(a + b == 12356);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
10
test/incremental/x86_64-macos/assert_function.15.zig
Normal file
10
test/incremental/x86_64-macos/assert_function.15.zig
Normal file
@ -0,0 +1,10 @@
|
||||
pub fn main() void {
|
||||
assert("hello"[0] == 'h');
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
11
test/incremental/x86_64-macos/assert_function.16.zig
Normal file
11
test/incremental/x86_64-macos/assert_function.16.zig
Normal file
@ -0,0 +1,11 @@
|
||||
const hello = "hello".*;
|
||||
pub fn main() void {
|
||||
assert(hello[1] == 'e');
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
11
test/incremental/x86_64-macos/assert_function.17.zig
Normal file
11
test/incremental/x86_64-macos/assert_function.17.zig
Normal file
@ -0,0 +1,11 @@
|
||||
pub fn main() void {
|
||||
var i: u64 = 0xFFEEDDCCBBAA9988;
|
||||
assert(i == 0xFFEEDDCCBBAA9988);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
@ -3,9 +3,7 @@ const builtin = @import("builtin");
|
||||
extern "c" fn write(usize, usize, usize) usize;
|
||||
|
||||
pub fn main() void {
|
||||
var i: u32 = 0;
|
||||
while (i < 4) : (i += 1) print();
|
||||
assert(i == 4);
|
||||
for ("hello") |_| print();
|
||||
}
|
||||
|
||||
fn print() void {
|
||||
@ -27,14 +25,11 @@ fn print() void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
// hello
|
||||
// hello
|
||||
// hello
|
||||
// hello
|
||||
// hello
|
||||
//
|
||||
21
test/incremental/x86_64-macos/assert_function.2.zig
Normal file
21
test/incremental/x86_64-macos/assert_function.2.zig
Normal file
@ -0,0 +1,21 @@
|
||||
pub fn main() void {
|
||||
add(3, 4);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) void {
|
||||
const c = a + b; // 7
|
||||
const d = a + c; // 10
|
||||
const e = d + b; // 14
|
||||
const f = d + e; // 24
|
||||
const g = e + f; // 38
|
||||
const h = f + g; // 62
|
||||
const i = g + h; // 100
|
||||
assert(i == 100);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
22
test/incremental/x86_64-macos/assert_function.3.zig
Normal file
22
test/incremental/x86_64-macos/assert_function.3.zig
Normal file
@ -0,0 +1,22 @@
|
||||
pub fn main() void {
|
||||
add(3, 4);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) void {
|
||||
const c = a + b; // 7
|
||||
const d = a + c; // 10
|
||||
const e = d + b; // 14
|
||||
const f = d + e; // 24
|
||||
const g = e + f; // 38
|
||||
const h = f + g; // 62
|
||||
const i = g + h; // 100
|
||||
const j = i + d; // 110
|
||||
assert(j == 110);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
15
test/incremental/x86_64-macos/assert_function.4.zig
Normal file
15
test/incremental/x86_64-macos/assert_function.4.zig
Normal file
@ -0,0 +1,15 @@
|
||||
pub fn main() void {
|
||||
assert(add(3, 4) == 7);
|
||||
assert(add(20, 10) == 30);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) u32 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
19
test/incremental/x86_64-macos/assert_function.5.zig
Normal file
19
test/incremental/x86_64-macos/assert_function.5.zig
Normal file
@ -0,0 +1,19 @@
|
||||
pub fn main() void {
|
||||
assert(add(3, 4) == 7);
|
||||
assert(add(20, 10) == 30);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) u32 {
|
||||
var x: u32 = undefined;
|
||||
x = 0;
|
||||
x += a;
|
||||
x += b;
|
||||
return x;
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
9
test/incremental/x86_64-macos/assert_function.6.zig
Normal file
9
test/incremental/x86_64-macos/assert_function.6.zig
Normal file
@ -0,0 +1,9 @@
|
||||
pub fn main() void {
|
||||
const a: u32 = 2;
|
||||
const b: ?u32 = a;
|
||||
const c = b.?;
|
||||
if (c != 2) unreachable;
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
23
test/incremental/x86_64-macos/assert_function.7.zig
Normal file
23
test/incremental/x86_64-macos/assert_function.7.zig
Normal file
@ -0,0 +1,23 @@
|
||||
extern "c" fn write(usize, usize, usize) usize;
|
||||
|
||||
pub fn main() void {
|
||||
var i: u32 = 0;
|
||||
while (i < 4) : (i += 1) print();
|
||||
assert(i == 4);
|
||||
}
|
||||
|
||||
fn print() void {
|
||||
_ = write(1, @ptrToInt("hello\n"), 6);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
// hello
|
||||
// hello
|
||||
// hello
|
||||
// hello
|
||||
//
|
||||
19
test/incremental/x86_64-macos/assert_function.8.zig
Normal file
19
test/incremental/x86_64-macos/assert_function.8.zig
Normal file
@ -0,0 +1,19 @@
|
||||
extern "c" fn write(usize, usize, usize) usize;
|
||||
|
||||
pub fn main() void {
|
||||
var i: u32 = 0;
|
||||
inline while (i < 4) : (i += 1) print();
|
||||
assert(i == 4);
|
||||
}
|
||||
|
||||
fn print() void {
|
||||
_ = write(1, @ptrToInt("hello\n"), 6);
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :5:21: error: unable to resolve comptime value
|
||||
22
test/incremental/x86_64-macos/assert_function.9.zig
Normal file
22
test/incremental/x86_64-macos/assert_function.9.zig
Normal file
@ -0,0 +1,22 @@
|
||||
pub fn main() void {
|
||||
assert(add(3, 4) == 20);
|
||||
}
|
||||
|
||||
fn add(a: u32, b: u32) u32 {
|
||||
const x: u32 = blk: {
|
||||
const c = a + b; // 7
|
||||
const d = a + c; // 10
|
||||
const e = d + b; // 14
|
||||
break :blk e;
|
||||
};
|
||||
const y = x + a; // 17
|
||||
const z = y + a; // 20
|
||||
return z;
|
||||
}
|
||||
|
||||
pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
12
test/incremental/x86_64-macos/comptime_var.0.zig
Normal file
12
test/incremental/x86_64-macos/comptime_var.0.zig
Normal file
@ -0,0 +1,12 @@
|
||||
pub fn main() void {
|
||||
var a: u32 = 0;
|
||||
comptime var b: u32 = 0;
|
||||
if (a == 0) b = 3;
|
||||
}
|
||||
|
||||
// error
|
||||
// output_mode=Exe
|
||||
// target=x86_64-macos
|
||||
//
|
||||
// :4:21: error: store to comptime variable depends on runtime condition
|
||||
// :4:11: note: runtime condition here
|
||||
13
test/incremental/x86_64-macos/comptime_var.1.zig
Normal file
13
test/incremental/x86_64-macos/comptime_var.1.zig
Normal file
@ -0,0 +1,13 @@
|
||||
pub fn main() void {
|
||||
var a: u32 = 0;
|
||||
comptime var b: u32 = 0;
|
||||
switch (a) {
|
||||
0 => {},
|
||||
else => b = 3,
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :6:21: error: store to comptime variable depends on runtime condition
|
||||
// :4:13: note: runtime condition here
|
||||
17
test/incremental/x86_64-macos/comptime_var.2.zig
Normal file
17
test/incremental/x86_64-macos/comptime_var.2.zig
Normal file
@ -0,0 +1,17 @@
|
||||
extern "c" fn write(usize, usize, usize) usize;
|
||||
|
||||
pub fn main() void {
|
||||
comptime var len: u32 = 5;
|
||||
print(len);
|
||||
len += 9;
|
||||
print(len);
|
||||
}
|
||||
|
||||
fn print(len: usize) void {
|
||||
_ = write(1, @ptrToInt("Hello, World!\n"), len);
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
// HelloHello, World!
|
||||
//
|
||||
10
test/incremental/x86_64-macos/comptime_var.3.zig
Normal file
10
test/incremental/x86_64-macos/comptime_var.3.zig
Normal file
@ -0,0 +1,10 @@
|
||||
comptime {
|
||||
var x: i32 = 1;
|
||||
x += 1;
|
||||
if (x != 1) unreachable;
|
||||
}
|
||||
pub fn main() void {}
|
||||
|
||||
// error
|
||||
//
|
||||
// :4:17: error: unable to resolve comptime value
|
||||
9
test/incremental/x86_64-macos/comptime_var.4.zig
Normal file
9
test/incremental/x86_64-macos/comptime_var.4.zig
Normal file
@ -0,0 +1,9 @@
|
||||
pub fn main() void {
|
||||
comptime var i: u64 = 0;
|
||||
while (i < 5) : (i += 1) {}
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :3:24: error: cannot store to comptime variable in non-inline loop
|
||||
// :3:5: note: non-inline loop here
|
||||
15
test/incremental/x86_64-macos/comptime_var.5.zig
Normal file
15
test/incremental/x86_64-macos/comptime_var.5.zig
Normal file
@ -0,0 +1,15 @@
|
||||
pub fn main() void {
|
||||
var a: u32 = 0;
|
||||
if (a == 0) {
|
||||
comptime var b: u32 = 0;
|
||||
b = 1;
|
||||
}
|
||||
}
|
||||
comptime {
|
||||
var x: i32 = 1;
|
||||
x += 1;
|
||||
if (x != 2) unreachable;
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
15
test/incremental/x86_64-macos/comptime_var.6.zig
Normal file
15
test/incremental/x86_64-macos/comptime_var.6.zig
Normal file
@ -0,0 +1,15 @@
|
||||
extern "c" fn write(usize, usize, usize) usize;
|
||||
|
||||
pub fn main() void {
|
||||
comptime var i: u64 = 2;
|
||||
inline while (i < 6) : (i += 1) {
|
||||
print(i);
|
||||
}
|
||||
}
|
||||
fn print(len: usize) void {
|
||||
_ = write(1, @ptrToInt("Hello"), len);
|
||||
}
|
||||
|
||||
// run
|
||||
//
|
||||
// HeHelHellHello
|
||||
Loading…
x
Reference in New Issue
Block a user