Class: SyntaxTree::YARV::OptNewArraySend
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::OptNewArraySend
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘opt_newarray_send` is a specialization that occurs when a dynamic array literal is created and immediately sent the `min`, `max`, or `hash` methods. It pops the values of the array off the stack and pushes on the result of the method call.
### Usage
~~~ruby [a, b, c].max ~~~
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(number, method) ⇒ OptNewArraySend
constructor
A new instance of OptNewArraySend.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?
Constructor Details
#initialize(number, method) ⇒ OptNewArraySend
Returns a new instance of OptNewArraySend.
3835 3836 3837 3838 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3835 def initialize(number, method) @number = number @method = method end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
3833 3834 3835 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3833 def method @method end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
3833 3834 3835 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3833 def number @number end |
Instance Method Details
#==(other) ⇒ Object
3855 3856 3857 3858 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3855 def ==(other) other.is_a?(OptNewArraySend) && other.number == number && other.method == method end |
#call(vm) ⇒ Object
3872 3873 3874 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3872 def call(vm) vm.push(vm.pop(number).__send__(method)) end |
#deconstruct_keys(_keys) ⇒ Object
3851 3852 3853 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3851 def deconstruct_keys(_keys) { number: number, method: method } end |
#disasm(fmt) ⇒ Object
3840 3841 3842 3843 3844 3845 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3840 def disasm(fmt) fmt.instruction( "opt_newarray_send", [fmt.object(number), fmt.object(method)] ) end |
#length ⇒ Object
3860 3861 3862 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3860 def length 3 end |
#pops ⇒ Object
3864 3865 3866 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3864 def pops number end |
#pushes ⇒ Object
3868 3869 3870 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3868 def pushes 1 end |
#to_a(_iseq) ⇒ Object
3847 3848 3849 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3847 def to_a(_iseq) [:opt_newarray_send, number, method] end |