Class: SyntaxTree::YARV::ConcatToArray

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

Overview

### Summary

‘concattoarray` pops a single value off the stack and attempts to concat it to the Array on top of the stack. If the value is not an Array, it will be coerced into one.

### Usage

~~~ruby

1, *2

~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(object) ⇒ ConcatToArray

Returns a new instance of ConcatToArray.



775
776
777
# File 'lib/syntax_tree/yarv/instructions.rb', line 775

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



773
774
775
# File 'lib/syntax_tree/yarv/instructions.rb', line 773

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



791
792
793
# File 'lib/syntax_tree/yarv/instructions.rb', line 791

def ==(other)
  other.is_a?(ConcatToArray) && other.object == object
end

#call(vm) ⇒ Object



807
808
809
810
# File 'lib/syntax_tree/yarv/instructions.rb', line 807

def call(vm)
  array, value = vm.pop(2)
  vm.push(array.concat(Array(value)))
end

#deconstruct_keys(_keys) ⇒ Object



787
788
789
# File 'lib/syntax_tree/yarv/instructions.rb', line 787

def deconstruct_keys(_keys)
  { object: object }
end

#disasm(fmt) ⇒ Object



779
780
781
# File 'lib/syntax_tree/yarv/instructions.rb', line 779

def disasm(fmt)
  fmt.instruction("concattoarray", [fmt.object(object)])
end

#lengthObject



795
796
797
# File 'lib/syntax_tree/yarv/instructions.rb', line 795

def length
  2
end

#popsObject



799
800
801
# File 'lib/syntax_tree/yarv/instructions.rb', line 799

def pops
  1
end

#pushesObject



803
804
805
# File 'lib/syntax_tree/yarv/instructions.rb', line 803

def pushes
  1
end

#to_a(_iseq) ⇒ Object



783
784
785
# File 'lib/syntax_tree/yarv/instructions.rb', line 783

def to_a(_iseq)
  [:concattoarray, object]
end