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.



3545
3546
3547
# File 'lib/syntax_tree/yarv/instructions.rb', line 3545

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3543
3544
3545
# File 'lib/syntax_tree/yarv/instructions.rb', line 3543

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3561
3562
3563
# File 'lib/syntax_tree/yarv/instructions.rb', line 3561

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

#call(vm) ⇒ Object



3581
3582
3583
# File 'lib/syntax_tree/yarv/instructions.rb', line 3581

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

#canonicalObject



3577
3578
3579
# File 'lib/syntax_tree/yarv/instructions.rb', line 3577

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3557
3558
3559
# File 'lib/syntax_tree/yarv/instructions.rb', line 3557

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3549
3550
3551
# File 'lib/syntax_tree/yarv/instructions.rb', line 3549

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

#lengthObject



3565
3566
3567
# File 'lib/syntax_tree/yarv/instructions.rb', line 3565

def length
  2
end

#popsObject



3569
3570
3571
# File 'lib/syntax_tree/yarv/instructions.rb', line 3569

def pops
  2
end

#pushesObject



3573
3574
3575
# File 'lib/syntax_tree/yarv/instructions.rb', line 3573

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3553
3554
3555
# File 'lib/syntax_tree/yarv/instructions.rb', line 3553

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