Class: SyntaxTree::YARV::OptLength

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

Overview

### Summary

opt_length is a specialization of opt_send_without_block, when the length 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 of the method call.

### Usage

~~~ruby “”.length ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calldata) ⇒ OptLength



3195
3196
3197
# File 'lib/syntax_tree/yarv/instructions.rb', line 3195

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3193
3194
3195
# File 'lib/syntax_tree/yarv/instructions.rb', line 3193

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



3223
3224
3225
# File 'lib/syntax_tree/yarv/instructions.rb', line 3223

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

#canonicalObject



3219
3220
3221
# File 'lib/syntax_tree/yarv/instructions.rb', line 3219

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



3199
3200
3201
# File 'lib/syntax_tree/yarv/instructions.rb', line 3199

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

#lengthObject



3207
3208
3209
# File 'lib/syntax_tree/yarv/instructions.rb', line 3207

def length
  2
end

#popsObject



3211
3212
3213
# File 'lib/syntax_tree/yarv/instructions.rb', line 3211

def pops
  1
end

#pushesObject



3215
3216
3217
# File 'lib/syntax_tree/yarv/instructions.rb', line 3215

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3203
3204
3205
# File 'lib/syntax_tree/yarv/instructions.rb', line 3203

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