Class: SyntaxTree::YARV::Swap

Inherits:
Instruction 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

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #length, #side_effects?

Instance Method Details

#==(other) ⇒ Object



5508
5509
5510
# File 'lib/syntax_tree/yarv/instructions.rb', line 5508

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

#call(vm) ⇒ Object



5520
5521
5522
5523
# File 'lib/syntax_tree/yarv/instructions.rb', line 5520

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

#deconstruct_keys(_keys) ⇒ Object



5504
5505
5506
# File 'lib/syntax_tree/yarv/instructions.rb', line 5504

def deconstruct_keys(_keys)
  {}
end

#disasm(fmt) ⇒ Object



5496
5497
5498
# File 'lib/syntax_tree/yarv/instructions.rb', line 5496

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

#popsObject



5512
5513
5514
# File 'lib/syntax_tree/yarv/instructions.rb', line 5512

def pops
  2
end

#pushesObject



5516
5517
5518
# File 'lib/syntax_tree/yarv/instructions.rb', line 5516

def pushes
  2
end

#to_a(_iseq) ⇒ Object



5500
5501
5502
# File 'lib/syntax_tree/yarv/instructions.rb', line 5500

def to_a(_iseq)
  [:swap]
end