Class: SyntaxTree::YARV::DupN

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

Overview

### Summary

dupn duplicates the top n stack elements.

### Usage

~~~ruby Object::X ||= true ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ DupN

Returns a new instance of DupN.



1389
1390
1391
# File 'lib/syntax_tree/yarv/instructions.rb', line 1389

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



1387
1388
1389
# File 'lib/syntax_tree/yarv/instructions.rb', line 1387

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



1405
1406
1407
# File 'lib/syntax_tree/yarv/instructions.rb', line 1405

def ==(other)
  other.is_a?(DupN) && other.number == number
end

#call(vm) ⇒ Object



1425
1426
1427
1428
1429
# File 'lib/syntax_tree/yarv/instructions.rb', line 1425

def call(vm)
  values = vm.pop(number)
  vm.push(*values)
  vm.push(*values)
end

#canonicalObject



1421
1422
1423
# File 'lib/syntax_tree/yarv/instructions.rb', line 1421

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



1401
1402
1403
# File 'lib/syntax_tree/yarv/instructions.rb', line 1401

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



1393
1394
1395
# File 'lib/syntax_tree/yarv/instructions.rb', line 1393

def disasm(fmt)
  fmt.instruction("dupn", [fmt.object(number)])
end

#lengthObject



1409
1410
1411
# File 'lib/syntax_tree/yarv/instructions.rb', line 1409

def length
  2
end

#popsObject



1413
1414
1415
# File 'lib/syntax_tree/yarv/instructions.rb', line 1413

def pops
  0
end

#pushesObject



1417
1418
1419
# File 'lib/syntax_tree/yarv/instructions.rb', line 1417

def pushes
  number
end

#to_a(_iseq) ⇒ Object



1397
1398
1399
# File 'lib/syntax_tree/yarv/instructions.rb', line 1397

def to_a(_iseq)
  [:dupn, number]
end