Class: SyntaxTree::YARV::OptLTLT

Inherits:
Object
  • Object
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

Constructor Details

#initialize(calldata) ⇒ OptLTLT

Returns a new instance of OptLTLT.



3757
3758
3759
# File 'lib/syntax_tree/yarv/instructions.rb', line 3757

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3755
3756
3757
# File 'lib/syntax_tree/yarv/instructions.rb', line 3755

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3773
3774
3775
# File 'lib/syntax_tree/yarv/instructions.rb', line 3773

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

#call(vm) ⇒ Object



3793
3794
3795
# File 'lib/syntax_tree/yarv/instructions.rb', line 3793

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

#canonicalObject



3789
3790
3791
# File 'lib/syntax_tree/yarv/instructions.rb', line 3789

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3769
3770
3771
# File 'lib/syntax_tree/yarv/instructions.rb', line 3769

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3761
3762
3763
# File 'lib/syntax_tree/yarv/instructions.rb', line 3761

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

#lengthObject



3777
3778
3779
# File 'lib/syntax_tree/yarv/instructions.rb', line 3777

def length
  2
end

#popsObject



3781
3782
3783
# File 'lib/syntax_tree/yarv/instructions.rb', line 3781

def pops
  2
end

#pushesObject



3785
3786
3787
# File 'lib/syntax_tree/yarv/instructions.rb', line 3785

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3765
3766
3767
# File 'lib/syntax_tree/yarv/instructions.rb', line 3765

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