Class: SyntaxTree::YARV::OptNewArrayMin

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

Overview

### Summary

opt_newarray_min is a specialization that occurs when the min method is called on an array literal. It pops the values of the array off the stack and pushes on the result.

### Usage

~~~ruby [a, b, c].min ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(number) ⇒ OptNewArrayMin

Returns a new instance of OptNewArrayMin.



3828
3829
3830
# File 'lib/syntax_tree/yarv/instructions.rb', line 3828

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



3826
3827
3828
# File 'lib/syntax_tree/yarv/instructions.rb', line 3826

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



3844
3845
3846
# File 'lib/syntax_tree/yarv/instructions.rb', line 3844

def ==(other)
  other.is_a?(OptNewArrayMin) && other.number == number
end

#call(vm) ⇒ Object



3860
3861
3862
# File 'lib/syntax_tree/yarv/instructions.rb', line 3860

def call(vm)
  vm.push(vm.pop(number).min)
end

#deconstruct_keys(_keys) ⇒ Object



3840
3841
3842
# File 'lib/syntax_tree/yarv/instructions.rb', line 3840

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



3832
3833
3834
# File 'lib/syntax_tree/yarv/instructions.rb', line 3832

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

#lengthObject



3848
3849
3850
# File 'lib/syntax_tree/yarv/instructions.rb', line 3848

def length
  2
end

#popsObject



3852
3853
3854
# File 'lib/syntax_tree/yarv/instructions.rb', line 3852

def pops
  number
end

#pushesObject



3856
3857
3858
# File 'lib/syntax_tree/yarv/instructions.rb', line 3856

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3836
3837
3838
# File 'lib/syntax_tree/yarv/instructions.rb', line 3836

def to_a(_iseq)
  [:opt_newarray_min, number]
end