2019-11-15 02:04:40 +03:00
|
|
|
module builtin
|
|
|
|
|
2019-11-23 19:35:57 +03:00
|
|
|
pub fn isnil(p voidptr) bool {
|
|
|
|
return p == 0
|
|
|
|
}
|
2019-11-15 02:04:40 +03:00
|
|
|
|
2019-11-23 19:35:57 +03:00
|
|
|
pub fn print(s string) {
|
|
|
|
sys_write(1, s.str, u64(s.len))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn println(s string) {
|
|
|
|
print(s)
|
2019-11-26 06:12:37 +03:00
|
|
|
print("\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn panic(s string) {
|
|
|
|
print('V panic: ')
|
|
|
|
println(s)
|
|
|
|
sys_exit(1)
|
2019-11-15 02:04:40 +03:00
|
|
|
}
|
|
|
|
|
2019-11-23 19:35:57 +03:00
|
|
|
// replaces panic when -debug arg is passed
|
|
|
|
fn panic_debug(line_no int, file, mod, fn_name, s string) {
|
|
|
|
println('================ V panic ================')
|
|
|
|
print(' module: ')
|
|
|
|
println('mod')
|
|
|
|
print(' function: ')
|
|
|
|
print(fn_name)
|
|
|
|
println('()')
|
|
|
|
println(' file: ')
|
|
|
|
println(file)
|
|
|
|
//println(' line: ${line_no}')
|
|
|
|
print(' message: ')
|
|
|
|
println(s)
|
|
|
|
println('=========================================')
|
|
|
|
sys_exit(1)
|
2019-11-16 11:33:04 +03:00
|
|
|
}
|
2019-11-26 06:12:37 +03:00
|
|
|
pub fn eprint(s string) {
|
|
|
|
if isnil(s.str) {
|
|
|
|
panic('eprint(NIL)')
|
|
|
|
}
|
|
|
|
sys_write(2, s.str, u64(s.len))
|
|
|
|
}
|
2019-11-16 11:33:04 +03:00
|
|
|
|
2019-11-26 06:12:37 +03:00
|
|
|
pub fn eprint_ln(s string) {
|
|
|
|
eprint(s)
|
|
|
|
eprint("\n")
|
2019-11-23 19:35:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn eprintln(s string) {
|
|
|
|
if isnil(s.str) {
|
|
|
|
panic('eprintln(NIL)')
|
|
|
|
}
|
2019-11-26 06:12:37 +03:00
|
|
|
eprint_ln(s)
|
2019-11-23 19:35:57 +03:00
|
|
|
}
|