(module main)

(fn make_words ((head string)) -> (array string 3)
  (array string head "middle" "tail"))

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

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

(fn call_return_index ((i i32)) -> string
  (index (make_words "call") i))

(fn local_array_flow ((i i32)) -> string
  (let words (array string 3) (make_words "local"))
  (at words i))

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

(test "string array parameter value flow"
  (= (at (make_words "alpha") 0) "alpha"))

(test "string array dynamic index"
  (= (at (make_words "alpha") 2) "tail"))

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

(test "string array parameter local copy"
  (= (parameter_local_copy (make_words "omega") 0) "omega"))

(test "string array return call value flow"
  (= (index (echo (make_words "zeta")) 2) "tail"))

(fn main () -> i32
  (if (= (call_return_index 1) "middle")
    0
    1))
