Class: SyntaxTree::YARV::ConcatStrings

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

concatstrings pops a number of strings from the stack joins them together into a single string and pushes that string back on the stack.

This does no coercion and so is always used in conjunction with objtostring and anytostring to ensure the stack contents are always strings.

### Usage

~~~ruby “#5” ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ ConcatStrings

Returns a new instance of ConcatStrings.



699
700
701
# File 'lib/syntax_tree/yarv/instructions.rb', line 699

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



697
698
699
# File 'lib/syntax_tree/yarv/instructions.rb', line 697

def number
  @number
end

Instance Method Details

#call(vm) ⇒ Object



727
728
729
# File 'lib/syntax_tree/yarv/instructions.rb', line 727

def call(vm)
  vm.push(vm.pop(number).join)
end

#canonicalObject



723
724
725
# File 'lib/syntax_tree/yarv/instructions.rb', line 723

def canonical
  self
end

#disasm(fmt) ⇒ Object



703
704
705
# File 'lib/syntax_tree/yarv/instructions.rb', line 703

def disasm(fmt)
  fmt.instruction("concatstrings", [fmt.object(number)])
end

#lengthObject



711
712
713
# File 'lib/syntax_tree/yarv/instructions.rb', line 711

def length
  2
end

#popsObject



715
716
717
# File 'lib/syntax_tree/yarv/instructions.rb', line 715

def pops
  number
end

#pushesObject



719
720
721
# File 'lib/syntax_tree/yarv/instructions.rb', line 719

def pushes
  1
end

#to_a(_iseq) ⇒ Object



707
708
709
# File 'lib/syntax_tree/yarv/instructions.rb', line 707

def to_a(_iseq)
  [:concatstrings, number]
end