Class: SyntaxTree::YARV::OptSize

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

Overview

### Summary

opt_size is a specialization of opt_send_without_block, when the size method is called. There are fast paths when the receiver is either a string, hash, or array. It pops the receiver off the stack and pushes on the result.

### Usage

~~~ruby “”.size ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calldata) ⇒ OptSize

Returns a new instance of OptSize.



4501
4502
4503
# File 'lib/syntax_tree/yarv/instructions.rb', line 4501

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4499
4500
4501
# File 'lib/syntax_tree/yarv/instructions.rb', line 4499

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



4517
4518
4519
# File 'lib/syntax_tree/yarv/instructions.rb', line 4517

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

#call(vm) ⇒ Object



4537
4538
4539
# File 'lib/syntax_tree/yarv/instructions.rb', line 4537

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

#canonicalObject



4533
4534
4535
# File 'lib/syntax_tree/yarv/instructions.rb', line 4533

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



4513
4514
4515
# File 'lib/syntax_tree/yarv/instructions.rb', line 4513

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



4505
4506
4507
# File 'lib/syntax_tree/yarv/instructions.rb', line 4505

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

#lengthObject



4521
4522
4523
# File 'lib/syntax_tree/yarv/instructions.rb', line 4521

def length
  2
end

#popsObject



4525
4526
4527
# File 'lib/syntax_tree/yarv/instructions.rb', line 4525

def pops
  1
end

#pushesObject



4529
4530
4531
# File 'lib/syntax_tree/yarv/instructions.rb', line 4529

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4509
4510
4511
# File 'lib/syntax_tree/yarv/instructions.rb', line 4509

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