Class: SyntaxTree::YARV::OptLength
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
Methods inherited from Instruction
#branch_targets, #falls_through?, #leaves?, #side_effects?
Constructor Details
#initialize(calldata) ⇒ OptLength
Returns a new instance of OptLength.
3431
3432
3433
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3431
def initialize(calldata)
@calldata = calldata
end
|
Instance Attribute Details
#calldata ⇒ Object
Returns the value of attribute calldata.
3429
3430
3431
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3429
def calldata
@calldata
end
|
Instance Method Details
#==(other) ⇒ Object
3447
3448
3449
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3447
def ==(other)
other.is_a?(OptLength) && other.calldata == calldata
end
|
#call(vm) ⇒ Object
3467
3468
3469
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3467
def call(vm)
canonical.call(vm)
end
|
#canonical ⇒ Object
3463
3464
3465
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3463
def canonical
Send.new(calldata, nil)
end
|
#deconstruct_keys(_keys) ⇒ Object
3443
3444
3445
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3443
def deconstruct_keys(_keys)
{ calldata: calldata }
end
|
#disasm(fmt) ⇒ Object
3435
3436
3437
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3435
def disasm(fmt)
fmt.instruction("opt_length", [fmt.calldata(calldata)])
end
|
#length ⇒ Object
3451
3452
3453
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3451
def length
2
end
|
#pops ⇒ Object
3455
3456
3457
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3455
def pops
1
end
|
#pushes ⇒ Object
3459
3460
3461
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3459
def pushes
1
end
|
#to_a(_iseq) ⇒ Object
3439
3440
3441
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 3439
def to_a(_iseq)
[:opt_length, calldata.to_h]
end
|