Class: SyntaxTree::YARV::ObjToString
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::ObjToString
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
objtostring pops a value from the stack, calls to_s on that value and then pushes the result back to the stack.
It has various fast paths for classes like String, Symbol, Module, Class, etc. For everything else it calls to_s.
### Usage
~~~ruby “#5” ~~~
Instance Attribute Summary collapse
-
#calldata ⇒ Object
readonly
Returns the value of attribute calldata.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(calldata) ⇒ ObjToString
constructor
A new instance of ObjToString.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?
Constructor Details
#initialize(calldata) ⇒ ObjToString
Returns a new instance of ObjToString.
2507 2508 2509 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2507 def initialize(calldata) @calldata = calldata end |
Instance Attribute Details
#calldata ⇒ Object (readonly)
Returns the value of attribute calldata.
2505 2506 2507 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2505 def calldata @calldata end |
Instance Method Details
#==(other) ⇒ Object
2523 2524 2525 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2523 def ==(other) other.is_a?(ObjToString) && other.calldata == calldata end |
#call(vm) ⇒ Object
2539 2540 2541 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2539 def call(vm) vm.push(vm.pop.to_s) end |
#deconstruct_keys(_keys) ⇒ Object
2519 2520 2521 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2519 def deconstruct_keys(_keys) { calldata: calldata } end |
#disasm(fmt) ⇒ Object
2511 2512 2513 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2511 def disasm(fmt) fmt.instruction("objtostring", [fmt.calldata(calldata)]) end |
#length ⇒ Object
2527 2528 2529 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2527 def length 2 end |
#pops ⇒ Object
2531 2532 2533 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2531 def pops 1 end |
#pushes ⇒ Object
2535 2536 2537 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2535 def pushes 1 end |
#to_a(_iseq) ⇒ Object
2515 2516 2517 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2515 def to_a(_iseq) [:objtostring, calldata.to_h] end |