program main
  enum Signal
    variant Red
    variant Yellow
    variant Green
  enum Reading
    variant Missing
    variant Value i32
  struct Point
    field x: i32
    field y: i32
  struct PrimitiveRecord
    field id: i32
    field active: bool
    field label: string
  struct NumericRecord
    field wide: i64
    field ratio: f64
  struct TaggedReading
    field status: Signal
    field reading: Reading
  fn make_point(x: i32, y: i32) -> Point
    construct Point
      field x
        var x
      field y
        var y
  fn make_primitive_record(id: i32, label: string) -> PrimitiveRecord
    construct PrimitiveRecord
      field id
        var id
      field active
        binary =
          var id
          int 7
      field label
        var label
  fn make_numeric_record(wide: i64, ratio: f64) -> NumericRecord
    construct NumericRecord
      field wide
        var wide
      field ratio
        var ratio
  fn make_tagged(status: Signal, reading: Reading) -> TaggedReading
    construct TaggedReading
      field status
        var status
      field reading
        var reading
  fn vec_i32_pair(base: i32) -> (vec i32)
    local let values: (vec i32)
      call std.vec.i32.empty
    local let first: (vec i32)
      call std.vec.i32.append
        var values
        var base
    call std.vec.i32.append
      var first
      binary +
        var base
        int 1
  fn vec_i64_pair(base: i64) -> (vec i64)
    local let values: (vec i64)
      call std.vec.i64.empty
    local let first: (vec i64)
      call std.vec.i64.append
        var values
        var base
    call std.vec.i64.append
      var first
      binary +
        var base
        i64 1
  fn vec_f64_pair(base: f64) -> (vec f64)
    local let values: (vec f64)
      call std.vec.f64.empty
    local let first: (vec f64)
      call std.vec.f64.append
        var values
        var base
    call std.vec.f64.append
      var first
      binary +
        var base
        float 1
  fn vec_bool_pair(first: bool, second: bool) -> (vec bool)
    local let values: (vec bool)
      call std.vec.bool.empty
    local let left: (vec bool)
      call std.vec.bool.append
        var values
        var first
    call std.vec.bool.append
      var left
      var second
  fn vec_string_pair(first: string, second: string) -> (vec string)
    local let values: (vec string)
      call std.vec.string.empty
    local let left: (vec string)
      call std.vec.string.append
        var values
        var first
    call std.vec.string.append
      var left
      var second
  fn swap_string(first: string, second: string) -> string
    local var current: string
      var first
    set current
      var second
    var current
  fn vec_i32_local_value() -> i32
    local var current: (vec i32)
      call vec_i32_pair
        int 10
    set current
      call vec_i32_pair
        int 40
    call std.vec.i32.index
      var current
      int 1
  fn vec_i64_local_value() -> i64
    local var current: (vec i64)
      call vec_i64_pair
        i64 10
    set current
      call vec_i64_pair
        i64 40
    call std.vec.i64.index
      var current
      int 1
  fn vec_f64_local_value() -> f64
    local var current: (vec f64)
      call vec_f64_pair
        float 10
    set current
      call vec_f64_pair
        float 40
    call std.vec.f64.index
      var current
      int 1
  fn vec_bool_local_value() -> bool
    local var current: (vec bool)
      call vec_bool_pair
        bool true
        bool false
    set current
      call vec_bool_pair
        bool false
        bool true
    call std.vec.bool.index
      var current
      int 1
  fn vec_string_local_value() -> string
    local var current: (vec string)
      call vec_string_pair
        string "oak"
        string "elm"
    set current
      call vec_string_pair
        string "pine"
        string "slovo"
    call std.vec.string.index
      var current
      int 1
  fn option_i32_local_value() -> i32
    local var current: (option i32)
      none i32
    set current
      some i32
        int 42
    match
      subject
        var current
      arm some payload
        var payload
      arm none
        int 0
  fn option_i64_local_value() -> i64
    local var current: (option i64)
      none i64
    set current
      some i64
        i64 42000000000
    match
      subject
        var current
      arm some payload
        var payload
      arm none
        i64 0
  fn option_f64_local_value() -> f64
    local var current: (option f64)
      none f64
    set current
      some f64
        float 42.5
    match
      subject
        var current
      arm some payload
        var payload
      arm none
        float 0
  fn option_bool_local_value() -> bool
    local var current: (option bool)
      none bool
    set current
      some bool
        bool true
    match
      subject
        var current
      arm some payload
        var payload
      arm none
        bool false
  fn option_string_local_value() -> string
    local var current: (option string)
      none string
    set current
      some string
        string "branch"
    match
      subject
        var current
      arm some payload
        var payload
      arm none
        string "fallback"
  fn result_i32_local_value() -> i32
    local var current: (result i32 i32)
      err i32 i32
        int 7
    set current
      ok i32 i32
        int 42
    match
      subject
        var current
      arm ok payload
        var payload
      arm err code
        var code
  fn result_i64_local_value() -> i64
    local var current: (result i64 i32)
      err i64 i32
        int 7
    set current
      ok i64 i32
        i64 42000000000
    match
      subject
        var current
      arm ok payload
        var payload
      arm err code
        i64 0
  fn result_f64_local_value() -> f64
    local var current: (result f64 i32)
      err f64 i32
        int 7
    set current
      ok f64 i32
        float 42.5
    match
      subject
        var current
      arm ok payload
        var payload
      arm err code
        float 0
  fn result_bool_local_value() -> bool
    local var current: (result bool i32)
      err bool i32
        int 7
    set current
      ok bool i32
        bool true
    match
      subject
        var current
      arm ok payload
        var payload
      arm err code
        bool false
  fn result_string_local_value() -> string
    local var current: (result string i32)
      err string i32
        int 7
    set current
      ok string i32
        string "slovo"
    match
      subject
        var current
      arm ok payload
        var payload
      arm err code
        string "fallback"
  fn point_local_sum() -> i32
    local var current: Point
      call make_point
        int 1
        int 2
    set current
      call make_point
        int 20
        int 22
    binary +
      field-access x
        var current
      field-access y
        var current
  fn primitive_record_local_label() -> string
    local var current: PrimitiveRecord
      call make_primitive_record
        int 3
        string "alpha"
    set current
      call make_primitive_record
        int 7
        string "beta"
    field-access label
      var current
  fn numeric_record_local_ratio() -> f64
    local var current: NumericRecord
      call make_numeric_record
        i64 10
        float 1
    set current
      call make_numeric_record
        i64 20
        float 3.5
    field-access ratio
      var current
  fn signal_local_code() -> i32
    local var current: Signal
      enum-variant Signal.Red
    set current
      enum-variant Signal.Green
    match
      subject
        var current
      arm Signal.Red
        int 1
      arm Signal.Yellow
        int 2
      arm Signal.Green
        int 3
  fn reading_local_code() -> i32
    local var current: Reading
      enum-variant Reading.Missing
    set current
      enum-variant Reading.Value
        int 42
    match
      subject
        var current
      arm Reading.Missing
        int 0
      arm Reading.Value payload
        var payload
  fn tagged_local_code() -> i32
    local var current: TaggedReading
      call make_tagged
        enum-variant Signal.Yellow
        enum-variant Reading.Missing
    set current
      call make_tagged
        enum-variant Signal.Green
        enum-variant Reading.Value
          int 42
    match
      subject
        field-access reading
          var current
      arm Reading.Missing
        int 0
      arm Reading.Value payload
        var payload
  fn main() -> i32
    call tagged_local_code
  test "mutable string local set works"
    binary =
      call swap_string
        string "oak"
        string "slovo"
      string "slovo"
  test "mutable vec i32 local set works"
    binary =
      call vec_i32_local_value
      int 41
  test "mutable vec i64 local set works"
    binary =
      call vec_i64_local_value
      i64 41
  test "mutable vec f64 local set works"
    binary =
      call vec_f64_local_value
      float 41
  test "mutable vec bool local set works"
    call vec_bool_local_value
  test "mutable vec string local set works"
    binary =
      call vec_string_local_value
      string "slovo"
  test "mutable option i32 local set works"
    binary =
      call option_i32_local_value
      int 42
  test "mutable option i64 local set works"
    binary =
      call option_i64_local_value
      i64 42000000000
  test "mutable option f64 local set works"
    binary =
      call option_f64_local_value
      float 42.5
  test "mutable option bool local set works"
    call option_bool_local_value
  test "mutable option string local set works"
    binary =
      call option_string_local_value
      string "branch"
  test "mutable result i32 local set works"
    binary =
      call result_i32_local_value
      int 42
  test "mutable result i64 local set works"
    binary =
      call result_i64_local_value
      i64 42000000000
  test "mutable result f64 local set works"
    binary =
      call result_f64_local_value
      float 42.5
  test "mutable result bool local set works"
    call result_bool_local_value
  test "mutable result string local set works"
    binary =
      call result_string_local_value
      string "slovo"
  test "mutable plain struct local set works"
    binary =
      call point_local_sum
      int 42
  test "mutable primitive struct local set works"
    binary =
      call primitive_record_local_label
      string "beta"
  test "mutable numeric struct local set works"
    binary =
      call numeric_record_local_ratio
      float 3.5
  test "mutable payloadless enum local set works"
    binary =
      call signal_local_code
      int 3
  test "mutable payload enum local set works"
    binary =
      call reading_local_code
      int 42
  test "mutable enum struct local set works"
    binary =
      call tagged_local_code
      int 42
