Class: SyntaxTree::YARV::OptNewArraySend

Inherits:
Instruction show all
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

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(number, method) ⇒ OptNewArraySend

Returns a new instance of OptNewArraySend.



3888
3889
3890
3891
# File 'lib/syntax_tree/yarv/instructions.rb', line 3888

def initialize(number, method)
  @number = number
  @method = method
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



3886
3887
3888
# File 'lib/syntax_tree/yarv/instructions.rb', line 3886

def method
  @method
end

#numberObject (readonly)

Returns the value of attribute number.



3886
3887
3888
# File 'lib/syntax_tree/yarv/instructions.rb', line 3886

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



3908
3909
3910
3911
# File 'lib/syntax_tree/yarv/instructions.rb', line 3908

def ==(other)
  other.is_a?(OptNewArraySend) && other.number == number &&
    other.method == method
end

#call(vm) ⇒ Object



3925
3926
3927
# File 'lib/syntax_tree/yarv/instructions.rb', line 3925

def call(vm)
  vm.push(vm.pop(number).__send__(method))
end

#deconstruct_keys(_keys) ⇒ Object



3904
3905
3906
# File 'lib/syntax_tree/yarv/instructions.rb', line 3904

def deconstruct_keys(_keys)
  { number: number, method: method }
end

#disasm(fmt) ⇒ Object



3893
3894
3895
3896
3897
3898
# File 'lib/syntax_tree/yarv/instructions.rb', line 3893

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

#lengthObject



3913
3914
3915
# File 'lib/syntax_tree/yarv/instructions.rb', line 3913

def length
  3
end

#popsObject



3917
3918
3919
# File 'lib/syntax_tree/yarv/instructions.rb', line 3917

def pops
  number
end

#pushesObject



3921
3922
3923
# File 'lib/syntax_tree/yarv/instructions.rb', line 3921

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3900
3901
3902
# File 'lib/syntax_tree/yarv/instructions.rb', line 3900

def to_a(_iseq)
  [:opt_newarray_send, number, method]
end