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
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ 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
Returns a new instance of OptLength.
3643 3644 3645 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3643 def initialize(calldata) @calldata = calldata end |
Instance Attribute Details
#calldata ⇒ Object (readonly)
Returns the value of attribute calldata.
3641 3642 3643 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3641 def calldata @calldata end |
Instance Method Details
#==(other) ⇒ Object
3659 3660 3661 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3659 def ==(other) other.is_a?(OptLength) && other.calldata == calldata end |
#call(vm) ⇒ Object
3679 3680 3681 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3679 def call(vm) canonical.call(vm) end |
#canonical ⇒ Object
3675 3676 3677 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3675 def canonical Send.new(calldata, nil) end |
#deconstruct_keys(_keys) ⇒ Object
3655 3656 3657 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3655 def deconstruct_keys(_keys) { calldata: calldata } end |
#disasm(fmt) ⇒ Object
3647 3648 3649 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3647 def disasm(fmt) fmt.instruction("opt_length", [fmt.calldata(calldata)]) end |
#length ⇒ Object
3663 3664 3665 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3663 def length 2 end |
#pops ⇒ Object
3667 3668 3669 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3667 def pops 1 end |
#pushes ⇒ Object
3671 3672 3673 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3671 def pushes 1 end |
#to_a(_iseq) ⇒ Object
3651 3652 3653 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 3651 def to_a(_iseq) [:opt_length, calldata.to_h] end |