Class: SyntaxTree::YARV::Swap

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

Overview

### Summary

swap swaps the top two elements in the stack.

### TracePoint

swap does not dispatch any events.

### Usage

~~~ruby !!defined?([]) ~~~

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



5930
5931
5932
# File 'lib/syntax_tree/yarv/instructions.rb', line 5930

def ==(other)
  other.is_a?(Swap)
end

#call(vm) ⇒ Object



5950
5951
5952
5953
# File 'lib/syntax_tree/yarv/instructions.rb', line 5950

def call(vm)
  left, right = vm.pop(2)
  vm.push(right, left)
end

#canonicalObject



5946
5947
5948
# File 'lib/syntax_tree/yarv/instructions.rb', line 5946

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



5926
5927
5928
# File 'lib/syntax_tree/yarv/instructions.rb', line 5926

def deconstruct_keys(_keys)
  {}
end

#disasm(fmt) ⇒ Object



5918
5919
5920
# File 'lib/syntax_tree/yarv/instructions.rb', line 5918

def disasm(fmt)
  fmt.instruction("swap")
end

#lengthObject



5934
5935
5936
# File 'lib/syntax_tree/yarv/instructions.rb', line 5934

def length
  1
end

#popsObject



5938
5939
5940
# File 'lib/syntax_tree/yarv/instructions.rb', line 5938

def pops
  2
end

#pushesObject



5942
5943
5944
# File 'lib/syntax_tree/yarv/instructions.rb', line 5942

def pushes
  2
end

#to_a(_iseq) ⇒ Object



5922
5923
5924
# File 'lib/syntax_tree/yarv/instructions.rb', line 5922

def to_a(_iseq)
  [:swap]
end