36 lines
664 B
Text
36 lines
664 B
Text
struct Point
|
|
x: int,
|
|
y: int,
|
|
end
|
|
|
|
enum Status
|
|
Ok,
|
|
Error,
|
|
end
|
|
|
|
fn add(a: int, b: int) -> int do
|
|
a + b
|
|
end
|
|
|
|
fn main() -> int do
|
|
# Test stack-allocated types (copyable)
|
|
let x = 10;
|
|
let y = 20;
|
|
let sum = add(x, y);
|
|
|
|
# Test struct (stack-allocated for now, but declared as such in language)
|
|
let p = Point { x: 5, y: 15 };
|
|
let point_sum = p.x + p.y;
|
|
|
|
# Test enum (stack-allocated for now)
|
|
let status = Status::Ok();
|
|
|
|
# Test array (heap-allocated)
|
|
let arr = [1, 2, 3, 4, 5];
|
|
let first = arr[0];
|
|
|
|
# Test string (heap-allocated)
|
|
let msg = "hello";
|
|
sum + point_sum + first
|
|
|
|
end
|