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.



3932
3933
3934
# File 'lib/syntax_tree/yarv/instructions.rb', line 3932

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3930
3931
3932
# File 'lib/syntax_tree/yarv/instructions.rb', line 3930

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



3960
3961
3962
# File 'lib/syntax_tree/yarv/instructions.rb', line 3960

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

#canonicalObject



3956
3957
3958
# File 'lib/syntax_tree/yarv/instructions.rb', line 3956

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



3936
3937
3938
# File 'lib/syntax_tree/yarv/instructions.rb', line 3936

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

#lengthObject



3944
3945
3946
# File 'lib/syntax_tree/yarv/instructions.rb', line 3944

def length
  2
end

#popsObject



3948
3949
3950
# File 'lib/syntax_tree/yarv/instructions.rb', line 3948

def pops
  1
end

#pushesObject



3952
3953
3954
# File 'lib/syntax_tree/yarv/instructions.rb', line 3952

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3940
3941
3942
# File 'lib/syntax_tree/yarv/instructions.rb', line 3940

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