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.



2565
2566
2567
# File 'lib/syntax_tree/yarv/instructions.rb', line 2565

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2563
2564
2565
# File 'lib/syntax_tree/yarv/instructions.rb', line 2563

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



2581
2582
2583
# File 'lib/syntax_tree/yarv/instructions.rb', line 2581

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

#call(vm) ⇒ Object



2597
2598
2599
# File 'lib/syntax_tree/yarv/instructions.rb', line 2597

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

#deconstruct_keys(_keys) ⇒ Object



2577
2578
2579
# File 'lib/syntax_tree/yarv/instructions.rb', line 2577

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



2569
2570
2571
# File 'lib/syntax_tree/yarv/instructions.rb', line 2569

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

#lengthObject



2585
2586
2587
# File 'lib/syntax_tree/yarv/instructions.rb', line 2585

def length
  2
end

#popsObject



2589
2590
2591
# File 'lib/syntax_tree/yarv/instructions.rb', line 2589

def pops
  1
end

#pushesObject



2593
2594
2595
# File 'lib/syntax_tree/yarv/instructions.rb', line 2593

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2573
2574
2575
# File 'lib/syntax_tree/yarv/instructions.rb', line 2573

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