| 1 | module builtin |
| 2 | |
| 3 | // print prints a message to stdout. Unlike `println` stdout is not automatically flushed. |
| 4 | pub fn print(s string) { |
| 5 | elm := CIOVec{ |
| 6 | buf: s.str |
| 7 | len: usize(s.len) |
| 8 | } |
| 9 | |
| 10 | WASM.fd_write(1, &elm, 1, 0) |
| 11 | } |
| 12 | |
| 13 | // println prints a message with a line end, to stdout. |
| 14 | pub fn println(s string) { |
| 15 | elm := [CIOVec{ |
| 16 | buf: s.str |
| 17 | len: usize(s.len) |
| 18 | }, CIOVec{ |
| 19 | buf: c'\n' |
| 20 | len: 1 |
| 21 | }]! |
| 22 | |
| 23 | WASM.fd_write(1, &elm[0], 2, 0) |
| 24 | } |
| 25 | |
| 26 | // eprint prints a message to stderr. |
| 27 | pub fn eprint(s string) { |
| 28 | elm := CIOVec{ |
| 29 | buf: s.str |
| 30 | len: usize(s.len) |
| 31 | } |
| 32 | |
| 33 | WASM.fd_write(2, &elm, 1, 0) |
| 34 | } |
| 35 | |
| 36 | // eprintln prints a message with a line end, to stderr. |
| 37 | pub fn eprintln(s string) { |
| 38 | elm := [CIOVec{ |
| 39 | buf: s.str |
| 40 | len: usize(s.len) |
| 41 | }, CIOVec{ |
| 42 | buf: c'\n' |
| 43 | len: 1 |
| 44 | }]! |
| 45 | |
| 46 | WASM.fd_write(2, &elm[0], 2, 0) |
| 47 | } |
| 48 | |
| 49 | // exit terminates execution immediately and returns exit `code` to the shell. |
| 50 | @[noreturn] |
| 51 | pub fn exit(code int) { |
| 52 | WASM.proc_exit(code) |
| 53 | } |
| 54 | |
| 55 | // panic prints a nice error message, then exits the process with exit code of 1. |
| 56 | @[noreturn] |
| 57 | pub fn panic(s string) { |
| 58 | eprint('V panic: ') |
| 59 | eprintln(s) |
| 60 | exit(1) |
| 61 | } |
| 62 | |