Class: SyntaxTree::YARV::ObjToString

Inherits:
Instruction show all
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

Instance Method Summary collapse

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?

Constructor Details

#initialize(calldata) ⇒ ObjToString

Returns a new instance of ObjToString.



2618
2619
2620
# File 'lib/syntax_tree/yarv/instructions.rb', line 2618

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2616
2617
2618
# File 'lib/syntax_tree/yarv/instructions.rb', line 2616

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



2634
2635
2636
# File 'lib/syntax_tree/yarv/instructions.rb', line 2634

def ==(other)
  other.is_a?(ObjToString) && other.calldata == calldata
end

#call(vm) ⇒ Object



2650
2651
2652
# File 'lib/syntax_tree/yarv/instructions.rb', line 2650

def call(vm)
  vm.push(vm.pop.to_s)
end

#deconstruct_keys(_keys) ⇒ Object



2630
2631
2632
# File 'lib/syntax_tree/yarv/instructions.rb', line 2630

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



2622
2623
2624
# File 'lib/syntax_tree/yarv/instructions.rb', line 2622

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

#lengthObject



2638
2639
2640
# File 'lib/syntax_tree/yarv/instructions.rb', line 2638

def length
  2
end

#popsObject



2642
2643
2644
# File 'lib/syntax_tree/yarv/instructions.rb', line 2642

def pops
  1
end

#pushesObject



2646
2647
2648
# File 'lib/syntax_tree/yarv/instructions.rb', line 2646

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2626
2627
2628
# File 'lib/syntax_tree/yarv/instructions.rb', line 2626

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