Class: SyntaxTree::YARV::Dup

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

Methods inherited from Instruction

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

Instance Method Details

#==(other) ⇒ Object



1161
1162
1163
# File 'lib/syntax_tree/yarv/instructions.rb', line 1161

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

#call(vm) ⇒ Object



1173
1174
1175
# File 'lib/syntax_tree/yarv/instructions.rb', line 1173

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

#deconstruct_keys(_keys) ⇒ Object



1157
1158
1159
# File 'lib/syntax_tree/yarv/instructions.rb', line 1157

def deconstruct_keys(_keys)
  {}
end

#disasm(fmt) ⇒ Object



1149
1150
1151
# File 'lib/syntax_tree/yarv/instructions.rb', line 1149

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

#popsObject



1165
1166
1167
# File 'lib/syntax_tree/yarv/instructions.rb', line 1165

def pops
  1
end

#pushesObject



1169
1170
1171
# File 'lib/syntax_tree/yarv/instructions.rb', line 1169

def pushes
  2
end

#side_effects?Boolean

Returns:

  • (Boolean)


1177
1178
1179
# File 'lib/syntax_tree/yarv/instructions.rb', line 1177

def side_effects?
  false
end

#to_a(_iseq) ⇒ Object



1153
1154
1155
# File 'lib/syntax_tree/yarv/instructions.rb', line 1153

def to_a(_iseq)
  [:dup]
end