Class: SyntaxTree::YARV::Legacy::OptNewArrayMin

Inherits:
Instruction
  • Object
show all
Defined in:
lib/syntax_tree/yarv/legacy.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.



194
195
196
# File 'lib/syntax_tree/yarv/legacy.rb', line 194

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



192
193
194
# File 'lib/syntax_tree/yarv/legacy.rb', line 192

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



210
211
212
# File 'lib/syntax_tree/yarv/legacy.rb', line 210

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

#call(vm) ⇒ Object



226
227
228
# File 'lib/syntax_tree/yarv/legacy.rb', line 226

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

#deconstruct_keys(_keys) ⇒ Object



206
207
208
# File 'lib/syntax_tree/yarv/legacy.rb', line 206

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



198
199
200
# File 'lib/syntax_tree/yarv/legacy.rb', line 198

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

#lengthObject



214
215
216
# File 'lib/syntax_tree/yarv/legacy.rb', line 214

def length
  2
end

#popsObject



218
219
220
# File 'lib/syntax_tree/yarv/legacy.rb', line 218

def pops
  number
end

#pushesObject



222
223
224
# File 'lib/syntax_tree/yarv/legacy.rb', line 222

def pushes
  1
end

#to_a(_iseq) ⇒ Object



202
203
204
# File 'lib/syntax_tree/yarv/legacy.rb', line 202

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