slige/examples/example_3.slg

39 lines
816 B
Plaintext
Raw Permalink Normal View History

2024-12-13 15:03:01 +00:00
fn print(msg: string) #[builtin(Print)] {}
fn println(msg: string) { print(msg + "\n") }
fn array_length_int(array: [int]) -> int #[builtin(ArrayLength)] {}
fn array_new_int() -> [int] #[builtin(ArrayNew)] {}
fn array_push_int(array: [int], value: int) #[builtin(ArrayPush)] {}
fn int_to_string(number: int) -> string #[builtin(IntToString)] {}
fn add(a: int, b: int) -> int {
a + b
}
fn main() -> int {
let result = 0;
let array = array_new_int();
let i = 0;
loop {
if i >= 10 {
break;
}
array_push_int(array, i);
i = i + 1;
}
i = 0;
loop {
if i >= array_length_int(array) {
break;
}
result = add(array[i], array[i]);
println(int_to_string(result));
i = i + 1;
}
result
}