Class: SyntaxTree::YARV::OptLength
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::OptLength
- 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
-
#calldata ⇒ Object
readonly
Returns the value of attribute calldata.
Instance Method Summary collapse
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(calldata) ⇒ OptLength
constructor
A new instance of OptLength.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
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
#calldata ⇒ Object (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 |
#canonical ⇒ Object
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 |
#length ⇒ Object
3207 3208 3209 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3207 def length 2 end |
#pops ⇒ Object
3211 3212 3213 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3211 def pops 1 end |
#pushes ⇒ Object
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 |