Class: SyntaxTree::YARV::OptLTLT

Inherits:
Instruction show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

‘opt_ltlt` is a specialization of the `opt_send_without_block` instruction that occurs when the `<<` operator is used. Fast paths exists when the receiver is either a String or an Array. It pops both the receiver and the argument off the stack and pushes on the result.

### Usage

~~~ruby “” << 2 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(calldata) ⇒ OptLTLT

Returns a new instance of OptLTLT.



3598
3599
3600
# File 'lib/syntax_tree/yarv/instructions.rb', line 3598

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3596
3597
3598
# File 'lib/syntax_tree/yarv/instructions.rb', line 3596

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3614
3615
3616
# File 'lib/syntax_tree/yarv/instructions.rb', line 3614

def ==(other)
  other.is_a?(OptLTLT) && other.calldata == calldata
end

#call(vm) ⇒ Object



3634
3635
3636
# File 'lib/syntax_tree/yarv/instructions.rb', line 3634

def call(vm)
  canonical.call(vm)
end

#canonicalObject



3630
3631
3632
# File 'lib/syntax_tree/yarv/instructions.rb', line 3630

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3610
3611
3612
# File 'lib/syntax_tree/yarv/instructions.rb', line 3610

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3602
3603
3604
# File 'lib/syntax_tree/yarv/instructions.rb', line 3602

def disasm(fmt)
  fmt.instruction("opt_ltlt", [fmt.calldata(calldata)])
end

#lengthObject



3618
3619
3620
# File 'lib/syntax_tree/yarv/instructions.rb', line 3618

def length
  2
end

#popsObject



3622
3623
3624
# File 'lib/syntax_tree/yarv/instructions.rb', line 3622

def pops
  2
end

#pushesObject



3626
3627
3628
# File 'lib/syntax_tree/yarv/instructions.rb', line 3626

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3606
3607
3608
# File 'lib/syntax_tree/yarv/instructions.rb', line 3606

def to_a(_iseq)
  [:opt_ltlt, calldata.to_h]
end