fn string_push_char(str: string, value: int) -> string #[builtin(StringPushChar)] {} fn string_char_at(str: string, index: int) -> int #[builtin(StringCharAt)] {} fn string_length(str: string) -> int #[builtin(StringLength)] {} fn string_array_new() -> [string] #[builtin(ArrayNew)] {} fn string_array_push(array: [string], value: string) #[builtin(ArrayPush)] {} fn string_array_length(array: [string]) -> int #[builtin(ArrayLength)] {} fn string_array_at(array: [string], index: int) -> string #[builtin(ArrayAt)] {} fn int_array_new() -> [int] #[builtin(ArrayNew)] {} fn int_array_push(array: [int], value: int) #[builtin(ArrayPush)] {} fn int_array_length(array: [int]) -> int #[builtin(ArrayLength)] {} fn int_array_at(array: [int], index: int) -> int #[builtin(ArrayAt)] {} fn file_open(filename: string, mode: string) -> int #[builtin(FileOpen)] {} fn file_close(file: int) #[builtin(FileClose)] {} fn file_write_string(file: int, content: string) -> int #[builtin(FileWriteString)] {} fn file_read_char(file: int) -> int #[builtin(FileReadChar)] {} fn file_read_to_string(file: int) -> string #[builtin(FileReadToString)] {} fn file_flush(file: int) #[builtin(FileFlush)] {} fn file_eof(file: int) -> bool #[builtin(FileEof)] {} fn stdin() -> int { 0 } fn stdout() -> int { 1 } fn stderr() -> int { 2 } fn file_read_line(file: int) -> string { let line = ""; loop { if file_eof(file) { break; } let ch = file_read_char(file); if ch == "\n"[0] { break; } line = string_push_char(line, ch); } line } fn print(msg: string) #[builtin(Print)] {} fn println(msg: string) { print(msg + "\n") } fn input(prompt: string) -> string { print("> "); file_flush(stdout()); file_read_line(stdin()) }