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



3293
3294
3295
# File 'lib/syntax_tree/yarv/instructions.rb', line 3293

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3291
3292
3293
# File 'lib/syntax_tree/yarv/instructions.rb', line 3291

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



3321
3322
3323
# File 'lib/syntax_tree/yarv/instructions.rb', line 3321

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

#canonicalObject



3317
3318
3319
# File 'lib/syntax_tree/yarv/instructions.rb', line 3317

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



3297
3298
3299
# File 'lib/syntax_tree/yarv/instructions.rb', line 3297

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

#lengthObject



3305
3306
3307
# File 'lib/syntax_tree/yarv/instructions.rb', line 3305

def length
  2
end

#popsObject



3309
3310
3311
# File 'lib/syntax_tree/yarv/instructions.rb', line 3309

def pops
  2
end

#pushesObject



3313
3314
3315
# File 'lib/syntax_tree/yarv/instructions.rb', line 3313

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3301
3302
3303
# File 'lib/syntax_tree/yarv/instructions.rb', line 3301

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