Class: SyntaxTree::YARV::Dup

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

Overview

### Summary

dup copies the top value of the stack and pushes it onto the stack.

### Usage

~~~ruby $global = 5 ~~~

Instance Method Summary collapse

Instance Method Details

#call(vm) ⇒ Object



1137
1138
1139
# File 'lib/syntax_tree/yarv/instructions.rb', line 1137

def call(vm)
  vm.push(vm.stack.last.dup)
end

#canonicalObject



1133
1134
1135
# File 'lib/syntax_tree/yarv/instructions.rb', line 1133

def canonical
  self
end

#disasm(fmt) ⇒ Object



1113
1114
1115
# File 'lib/syntax_tree/yarv/instructions.rb', line 1113

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

#lengthObject



1121
1122
1123
# File 'lib/syntax_tree/yarv/instructions.rb', line 1121

def length
  1
end

#popsObject



1125
1126
1127
# File 'lib/syntax_tree/yarv/instructions.rb', line 1125

def pops
  1
end

#pushesObject



1129
1130
1131
# File 'lib/syntax_tree/yarv/instructions.rb', line 1129

def pushes
  2
end

#to_a(_iseq) ⇒ Object



1117
1118
1119
# File 'lib/syntax_tree/yarv/instructions.rb', line 1117

def to_a(_iseq)
  [:dup]
end