Class: SyntaxTree::YARV::ConcatArray

Inherits:
Instruction show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

‘concatarray` concatenates the two Arrays on top of the stack.

It coerces the two objects at the top of the stack into Arrays by calling ‘to_a` if necessary, and makes sure to `dup` the first Array if it was already an Array, to avoid mutating it when concatenating.

### Usage

~~~ruby

1, *2

~~~

Instance Method Summary collapse

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #length, #side_effects?

Instance Method Details

#==(other) ⇒ Object



687
688
689
# File 'lib/syntax_tree/yarv/instructions.rb', line 687

def ==(other)
  other.is_a?(ConcatArray)
end

#call(vm) ⇒ Object



699
700
701
702
# File 'lib/syntax_tree/yarv/instructions.rb', line 699

def call(vm)
  left, right = vm.pop(2)
  vm.push([*left, *right])
end

#deconstruct_keys(_keys) ⇒ Object



683
684
685
# File 'lib/syntax_tree/yarv/instructions.rb', line 683

def deconstruct_keys(_keys)
  {}
end

#disasm(fmt) ⇒ Object



675
676
677
# File 'lib/syntax_tree/yarv/instructions.rb', line 675

def disasm(fmt)
  fmt.instruction("concatarray")
end

#popsObject



691
692
693
# File 'lib/syntax_tree/yarv/instructions.rb', line 691

def pops
  2
end

#pushesObject



695
696
697
# File 'lib/syntax_tree/yarv/instructions.rb', line 695

def pushes
  1
end

#to_a(_iseq) ⇒ Object



679
680
681
# File 'lib/syntax_tree/yarv/instructions.rb', line 679

def to_a(_iseq)
  [:concatarray]
end