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



1219
1220
1221
# File 'lib/syntax_tree/yarv/instructions.rb', line 1219

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

#call(vm) ⇒ Object



1231
1232
1233
# File 'lib/syntax_tree/yarv/instructions.rb', line 1231

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

#deconstruct_keys(_keys) ⇒ Object



1215
1216
1217
# File 'lib/syntax_tree/yarv/instructions.rb', line 1215

def deconstruct_keys(_keys)
  {}
end

#disasm(fmt) ⇒ Object



1207
1208
1209
# File 'lib/syntax_tree/yarv/instructions.rb', line 1207

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

#popsObject



1223
1224
1225
# File 'lib/syntax_tree/yarv/instructions.rb', line 1223

def pops
  1
end

#pushesObject



1227
1228
1229
# File 'lib/syntax_tree/yarv/instructions.rb', line 1227

def pushes
  2
end

#side_effects?Boolean

Returns:

  • (Boolean)


1235
1236
1237
# File 'lib/syntax_tree/yarv/instructions.rb', line 1235

def side_effects?
  false
end

#to_a(_iseq) ⇒ Object



1211
1212
1213
# File 'lib/syntax_tree/yarv/instructions.rb', line 1211

def to_a(_iseq)
  [:dup]
end