Class: SyntaxTree::YARV::OptNewArrayMax
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
Returns a new instance of OptNewArrayMax.
3834
3835
3836
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3834
def initialize(number)
@number = number
end
|
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
3832
3833
3834
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3832
def number
@number
end
|
Instance Method Details
#==(other) ⇒ Object
3850
3851
3852
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3850
def ==(other)
other.is_a?(OptNewArrayMax) && other.number == number
end
|
#call(vm) ⇒ Object
3866
3867
3868
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3866
def call(vm)
vm.push(vm.pop(number).max)
end
|
#deconstruct_keys(_keys) ⇒ Object
3846
3847
3848
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3846
def deconstruct_keys(_keys)
{ number: number }
end
|
#disasm(fmt) ⇒ Object
3838
3839
3840
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3838
def disasm(fmt)
fmt.instruction("opt_newarray_max", [fmt.object(number)])
end
|
#length ⇒ Object
3854
3855
3856
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3854
def length
2
end
|
#pops ⇒ Object
3858
3859
3860
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3858
def pops
number
end
|
#pushes ⇒ Object
3862
3863
3864
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3862
def pushes
1
end
|
#to_a(_iseq) ⇒ Object
3842
3843
3844
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3842
def to_a(_iseq)
[:opt_newarray_max, number]
end
|