Skip to content

Commit

Permalink
Add assert{,_fail}
Browse files Browse the repository at this point in the history
  • Loading branch information
N00byEdge committed Oct 28, 2023
1 parent 90e647d commit a0bbe7a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions selfhost/error.n
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ fn report(file_idx: u32, line: u32, column: u32, offset: u32, message: *const u8
std.os.print.flush();
std.os.syscalls.exit(1);
}

fn assert_fail(message: *const u8) noreturn {
std.os.print.str("\x1b[31;1m[ASSERT FAIL]\x1b[0m: ".&);
std.os.print.str(message);
std.os.print.flush();
std.os.syscalls.exit(1);
}

fn assert(b: bool, message: *const u8) inline void {
if(!b) {
assert_fail(message);
}
}

0 comments on commit a0bbe7a

Please sign in to comment.