Class: SyntaxTree::YARV::DupN

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

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?

Constructor Details

#initialize(number) ⇒ DupN

Returns a new instance of DupN.



1345
1346
1347
# File 'lib/syntax_tree/yarv/instructions.rb', line 1345

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



1343
1344
1345
# File 'lib/syntax_tree/yarv/instructions.rb', line 1343

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



1361
1362
1363
# File 'lib/syntax_tree/yarv/instructions.rb', line 1361

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

#call(vm) ⇒ Object



1373
1374
1375
1376
1377
# File 'lib/syntax_tree/yarv/instructions.rb', line 1373

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

#deconstruct_keys(_keys) ⇒ Object



1357
1358
1359
# File 'lib/syntax_tree/yarv/instructions.rb', line 1357

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



1349
1350
1351
# File 'lib/syntax_tree/yarv/instructions.rb', line 1349

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

#lengthObject



1365
1366
1367
# File 'lib/syntax_tree/yarv/instructions.rb', line 1365

def length
  2
end

#pushesObject



1369
1370
1371
# File 'lib/syntax_tree/yarv/instructions.rb', line 1369

def pushes
  number
end

#to_a(_iseq) ⇒ Object



1353
1354
1355
# File 'lib/syntax_tree/yarv/instructions.rb', line 1353

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