CodeTools::AST << {

ArrayAssembly < Node {
  node_type array
  field body

  bytecode: |g| {
    pos(g)

    self.body.empty? &? (
      g.make_array(0)
    ) ?? (
      # Group the self.body into chunks of splats and non-splats
      chunked = self.body.chunk |item| { item.is_a?(SplatValue) }

      # Each SplatValue outputs the bytecode of a single array
      # Non-SplatValues are grouped to output the bytecode of
      # a single array for each contiguous group.  Along the way, the
      # arrays are concatenated to form one final array on the stack.
      first_bytecode = true
      chunked.each |is_splat_group, group| {
        is_splat_group &? (
          group.each |item| {
            item.bytecode(g)
            first_bytecode || g.send(:concat, 1)
            first_bytecode = false
          }
        ) ?? (
          group.each |item| {
            item.bytecode(g)
          }
          g.make_array(group.size)
          first_bytecode || g.send(:concat, 1)
          first_bytecode = false
        )
      }
    )
  }
}

}