aboutsummaryrefslogtreecommitdiff
path: root/test/incremental/assert_function.8.zig
blob: c8c30cfac67856b9990676111cce4328f6b5c9cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
//
// :3:21: error: unable to resolve comptime value