2019-11-15 00:04:40 +01:00
|
|
|
module builtin
|
|
|
|
|
2019-12-03 23:40:26 +01:00
|
|
|
// called by the generated main/init
|
|
|
|
fn init() {
|
|
|
|
}
|
|
|
|
|
2019-11-23 17:35:57 +01:00
|
|
|
pub fn isnil(p voidptr) bool {
|
|
|
|
return p == 0
|
|
|
|
}
|
2019-11-15 00:04:40 +01:00
|
|
|
|
2019-11-23 17:35:57 +01:00
|
|
|
pub fn print(s string) {
|
|
|
|
sys_write(1, s.str, u64(s.len))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn println(s string) {
|
|
|
|
print(s)
|
2021-03-24 19:39:59 +01:00
|
|
|
print('\n')
|
2019-11-26 04:12:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn panic(s string) {
|
2019-12-08 11:44:52 +01:00
|
|
|
eprint('V panic: ')
|
|
|
|
eprintln(s)
|
2019-11-26 04:12:37 +01:00
|
|
|
sys_exit(1)
|
2019-11-15 00:04:40 +01:00
|
|
|
}
|
|
|
|
|
2019-11-23 17:35:57 +01:00
|
|
|
// replaces panic when -debug arg is passed
|
2021-03-24 19:39:59 +01:00
|
|
|
fn panic_debug(line_no int, file string, mod string, fn_name string, s string) {
|
2019-12-08 11:44:52 +01:00
|
|
|
eprintln('================ V panic ================')
|
|
|
|
eprint(' module: ')
|
|
|
|
eprintln('mod')
|
|
|
|
eprint(' function: ')
|
|
|
|
eprint(fn_name)
|
|
|
|
eprintln('()')
|
|
|
|
eprintln(' file: ')
|
|
|
|
eprintln(file)
|
2021-03-24 19:39:59 +01:00
|
|
|
// println(' line: ${line_no}')
|
2019-12-08 11:44:52 +01:00
|
|
|
eprint(' message: ')
|
|
|
|
eprintln(s)
|
|
|
|
eprintln('=========================================')
|
2019-11-23 17:35:57 +01:00
|
|
|
sys_exit(1)
|
2019-11-16 09:33:04 +01:00
|
|
|
}
|
2021-03-24 19:39:59 +01:00
|
|
|
|
2019-11-26 04:12:37 +01:00
|
|
|
pub fn eprint(s string) {
|
|
|
|
if isnil(s.str) {
|
|
|
|
panic('eprint(NIL)')
|
|
|
|
}
|
|
|
|
sys_write(2, s.str, u64(s.len))
|
|
|
|
}
|
2019-11-16 09:33:04 +01:00
|
|
|
|
2019-11-26 04:12:37 +01:00
|
|
|
pub fn eprint_ln(s string) {
|
|
|
|
eprint(s)
|
2021-03-24 19:39:59 +01:00
|
|
|
eprint('\n')
|
2019-11-23 17:35:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn eprintln(s string) {
|
|
|
|
if isnil(s.str) {
|
|
|
|
panic('eprintln(NIL)')
|
|
|
|
}
|
2019-11-26 04:12:37 +01:00
|
|
|
eprint_ln(s)
|
2019-11-23 17:35:57 +01:00
|
|
|
}
|