Class: SyntaxTree::YARV::Legacy::OptNewArrayMax

Inherits:
Instruction
  • Object
show all
Defined in:
lib/syntax_tree/yarv/legacy.rb

Overview

### Summary

‘opt_newarray_max` is a specialization that occurs when the `max` 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].max ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(number) ⇒ OptNewArrayMax

Returns a new instance of OptNewArrayMax.



142
143
144
# File 'lib/syntax_tree/yarv/legacy.rb', line 142

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



140
141
142
# File 'lib/syntax_tree/yarv/legacy.rb', line 140

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



158
159
160
# File 'lib/syntax_tree/yarv/legacy.rb', line 158

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

#call(vm) ⇒ Object



174
175
176
# File 'lib/syntax_tree/yarv/legacy.rb', line 174

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

#deconstruct_keys(_keys) ⇒ Object



154
155
156
# File 'lib/syntax_tree/yarv/legacy.rb', line 154

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



146
147
148
# File 'lib/syntax_tree/yarv/legacy.rb', line 146

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

#lengthObject



162
163
164
# File 'lib/syntax_tree/yarv/legacy.rb', line 162

def length
  2
end

#popsObject



166
167
168
# File 'lib/syntax_tree/yarv/legacy.rb', line 166

def pops
  number
end

#pushesObject



170
171
172
# File 'lib/syntax_tree/yarv/legacy.rb', line 170

def pushes
  1
end

#to_a(_iseq) ⇒ Object



150
151
152
# File 'lib/syntax_tree/yarv/legacy.rb', line 150

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