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

#call(vm) ⇒ Object



5175
5176
5177
5178
# File 'lib/syntax_tree/yarv/instructions.rb', line 5175

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

#canonicalObject



5171
5172
5173
# File 'lib/syntax_tree/yarv/instructions.rb', line 5171

def canonical
  self
end

#disasm(fmt) ⇒ Object



5151
5152
5153
# File 'lib/syntax_tree/yarv/instructions.rb', line 5151

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

#lengthObject



5159
5160
5161
# File 'lib/syntax_tree/yarv/instructions.rb', line 5159

def length
  1
end

#popsObject



5163
5164
5165
# File 'lib/syntax_tree/yarv/instructions.rb', line 5163

def pops
  2
end

#pushesObject



5167
5168
5169
# File 'lib/syntax_tree/yarv/instructions.rb', line 5167

def pushes
  2
end

#to_a(_iseq) ⇒ Object



5155
5156
5157
# File 'lib/syntax_tree/yarv/instructions.rb', line 5155

def to_a(_iseq)
  [:swap]
end