Class: SyntaxTree::YARV::OptNewArrayMin

Inherits:
Object
  • Object
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

Constructor Details

#initialize(number) ⇒ OptNewArrayMin

Returns a new instance of OptNewArrayMin.



4106
4107
4108
# File 'lib/syntax_tree/yarv/instructions.rb', line 4106

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



4104
4105
4106
# File 'lib/syntax_tree/yarv/instructions.rb', line 4104

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



4122
4123
4124
# File 'lib/syntax_tree/yarv/instructions.rb', line 4122

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

#call(vm) ⇒ Object



4142
4143
4144
# File 'lib/syntax_tree/yarv/instructions.rb', line 4142

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

#canonicalObject



4138
4139
4140
# File 'lib/syntax_tree/yarv/instructions.rb', line 4138

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



4118
4119
4120
# File 'lib/syntax_tree/yarv/instructions.rb', line 4118

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



4110
4111
4112
# File 'lib/syntax_tree/yarv/instructions.rb', line 4110

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

#lengthObject



4126
4127
4128
# File 'lib/syntax_tree/yarv/instructions.rb', line 4126

def length
  2
end

#popsObject



4130
4131
4132
# File 'lib/syntax_tree/yarv/instructions.rb', line 4130

def pops
  number
end

#pushesObject



4134
4135
4136
# File 'lib/syntax_tree/yarv/instructions.rb', line 4134

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4114
4115
4116
# File 'lib/syntax_tree/yarv/instructions.rb', line 4114

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