program main
  enum PacketState
    variant Missing
    variant Live Packet
    variant Cached Packet
  struct Packet
    field values: (array i32 3)
    field labels: (array string 2)
    field flags: (array bool 2)
  fn make_packet(base: i32, head: string) -> Packet
    construct Packet : Packet
      field values
        array : (array i32 3)
          var base : i32
          binary + : i32
            var base : i32
            int 1 : i32
          binary + : i32
            var base : i32
            int 2 : i32
      field labels
        array : (array string 2)
          var head : string
          string "tail" : string
      field flags
        array : (array bool 2)
          bool false : bool
          bool true : bool
  fn live(packet: Packet) -> PacketState
    enum-variant PacketState.Live #1 payload : PacketState
      var packet : Packet
  fn cached(packet: Packet) -> PacketState
    enum-variant PacketState.Cached #2 payload : PacketState
      var packet : Packet
  fn echo_state(state: PacketState) -> PacketState
    var state : PacketState
  fn local_state(base: i32, head: string) -> PacketState
    local let state : unit
      enum-variant PacketState.Live #1 payload : PacketState
        call make_packet : Packet
          var base : i32
          var head : string
    var state : PacketState
  fn call_state(base: i32, head: string) -> PacketState
    call echo_state : PacketState
      call cached : PacketState
        call make_packet : Packet
          var base : i32
          var head : string
  fn state_value(state: PacketState, i: i32) -> i32
    match : i32
      subject
        var state : PacketState
      arm PacketState.Missing
        int 0 : i32
      arm PacketState.Live payload
        index : i32
          field-access values : (array i32 3)
            var payload : Packet
          var i : i32
      arm PacketState.Cached payload
        index : i32
          field-access values : (array i32 3)
            var payload : Packet
          var i : i32
  fn state_label(state: PacketState, i: i32) -> string
    match : string
      subject
        var state : PacketState
      arm PacketState.Missing
        string "" : string
      arm PacketState.Live payload
        index : string
          field-access labels : (array string 2)
            var payload : Packet
          var i : i32
      arm PacketState.Cached payload
        index : string
          field-access labels : (array string 2)
            var payload : Packet
          var i : i32
  fn state_flag(state: PacketState, i: i32) -> bool
    match : bool
      subject
        var state : PacketState
      arm PacketState.Missing
        bool false : bool
      arm PacketState.Live payload
        index : bool
          field-access flags : (array bool 2)
            var payload : Packet
          var i : i32
      arm PacketState.Cached payload
        index : bool
          field-access flags : (array bool 2)
            var payload : Packet
          var i : i32
  fn main() -> i32
    call state_value : i32
      call call_state : PacketState
        int 7 : i32
        string "sun" : string
      int 2 : i32
  test "struct payload missing arm"
    binary = : bool
      call state_value : i32
        enum-variant PacketState.Missing #0 : PacketState
        int 0 : i32
      int 0 : i32
  test "struct payload live constructor flow"
    binary = : bool
      call state_value : i32
        call live : PacketState
          call make_packet : Packet
            int 7 : i32
            string "sun" : string
        int 2 : i32
      int 9 : i32
  test "struct payload cached param return call flow"
    binary = : bool
      call state_value : i32
        call call_state : PacketState
          int 7 : i32
          string "sun" : string
        int 1 : i32
      int 8 : i32
  test "struct payload string array field access"
    binary = : bool
      call state_label : string
        call call_state : PacketState
          int 7 : i32
          string "sun" : string
        int 0 : i32
      string "sun" : string
  test "struct payload bool array field access"
    call state_flag : bool
      call call_state : PacketState
        int 7 : i32
        string "sun" : string
      int 1 : i32
  test "struct payload local return flow"
    binary = : bool
      call state_label : string
        call local_state : PacketState
          int 9 : i32
          string "orb" : string
        int 1 : i32
      string "tail" : string
