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



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

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

#call(vm) ⇒ Object



5532
5533
5534
5535
# File 'lib/syntax_tree/yarv/instructions.rb', line 5532

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

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  {}
end

#disasm(fmt) ⇒ Object



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

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

#popsObject



5524
5525
5526
# File 'lib/syntax_tree/yarv/instructions.rb', line 5524

def pops
  2
end

#pushesObject



5528
5529
5530
# File 'lib/syntax_tree/yarv/instructions.rb', line 5528

def pushes
  2
end

#to_a(_iseq) ⇒ Object



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

def to_a(_iseq)
  [:swap]
end