mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 23:06:32 +00:00
81 lines
2.2 KiB
Plaintext
81 lines
2.2 KiB
Plaintext
|
|
||
|
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())
|
||
|
}
|
||
|
|
||
|
//
|
||
|
|
||
|
fn main() {
|
||
|
let i = 0;
|
||
|
while i < 3 {
|
||
|
println("hello world");
|
||
|
i += 1;
|
||
|
}
|
||
|
|
||
|
let chars = string_to_array("12435");
|
||
|
|
||
|
for char in chars {
|
||
|
println(string_push_char("", char));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn string_to_array(value: string) -> [int] {
|
||
|
let result = int_array_new();
|
||
|
let length = string_length(value);
|
||
|
|
||
|
for (let i = 0; i < length; i += 1) {
|
||
|
int_array_push(result, value[i]);
|
||
|
}
|
||
|
|
||
|
result
|
||
|
}
|
||
|
|
||
|
|
||
|
|