(module main)

(fn make_values ((base i32)) -> (array i32 3)
  (array i32 base (+ base 1) (+ base 2)))

(fn first ((values (array i32 3))) -> i32
  (index values 0))

(fn at ((values (array i32 3)) (i i32)) -> i32
  (index values i))

(fn echo ((values (array i32 3))) -> (array i32 3)
  values)

(fn call_return_index ((i i32)) -> i32
  (index (make_values 10) i))

(fn local_array_flow ((i i32)) -> i32
  (let values (array i32 3) (make_values 20))
  (at values i))

(fn parameter_local_copy ((values (array i32 3)) (i i32)) -> i32
  (let copy (array i32 3) values)
  (index copy i))

(test "array parameter value flow"
  (= (first (make_values 7)) 7))

(test "array dynamic index"
  (= (at (make_values 4) 2) 6))

(test "array local call value flow"
  (= (local_array_flow 1) 21))

(test "array parameter local copy"
  (= (parameter_local_copy (make_values 40) 2) 42))

(test "array return call value flow"
  (= (index (echo (make_values 30)) 2) 32))

(fn main () -> i32
  (call_return_index 1))
