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



1272
1273
1274
# File 'lib/syntax_tree/yarv/instructions.rb', line 1272

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

#call(vm) ⇒ Object



1284
1285
1286
# File 'lib/syntax_tree/yarv/instructions.rb', line 1284

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

#deconstruct_keys(_keys) ⇒ Object



1268
1269
1270
# File 'lib/syntax_tree/yarv/instructions.rb', line 1268

def deconstruct_keys(_keys)
  {}
end

#disasm(fmt) ⇒ Object



1260
1261
1262
# File 'lib/syntax_tree/yarv/instructions.rb', line 1260

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

#popsObject



1276
1277
1278
# File 'lib/syntax_tree/yarv/instructions.rb', line 1276

def pops
  1
end

#pushesObject



1280
1281
1282
# File 'lib/syntax_tree/yarv/instructions.rb', line 1280

def pushes
  2
end

#side_effects?Boolean

Returns:

  • (Boolean)


1288
1289
1290
# File 'lib/syntax_tree/yarv/instructions.rb', line 1288

def side_effects?
  false
end

#to_a(_iseq) ⇒ Object



1264
1265
1266
# File 'lib/syntax_tree/yarv/instructions.rb', line 1264

def to_a(_iseq)
  [:dup]
end