Class: SyntaxTree::YARV::ObjToString

Inherits:
Object
  • Object
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

Constructor Details

#initialize(calldata) ⇒ ObjToString

Returns a new instance of ObjToString.



2425
2426
2427
# File 'lib/syntax_tree/yarv/instructions.rb', line 2425

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2423
2424
2425
# File 'lib/syntax_tree/yarv/instructions.rb', line 2423

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



2453
2454
2455
# File 'lib/syntax_tree/yarv/instructions.rb', line 2453

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

#canonicalObject



2449
2450
2451
# File 'lib/syntax_tree/yarv/instructions.rb', line 2449

def canonical
  self
end

#disasm(fmt) ⇒ Object



2429
2430
2431
# File 'lib/syntax_tree/yarv/instructions.rb', line 2429

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

#lengthObject



2437
2438
2439
# File 'lib/syntax_tree/yarv/instructions.rb', line 2437

def length
  2
end

#popsObject



2441
2442
2443
# File 'lib/syntax_tree/yarv/instructions.rb', line 2441

def pops
  1
end

#pushesObject



2445
2446
2447
# File 'lib/syntax_tree/yarv/instructions.rb', line 2445

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2433
2434
2435
# File 'lib/syntax_tree/yarv/instructions.rb', line 2433

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