Class: SyntaxTree::YARV::SetN

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

Overview

### Summary

‘setn` sets a value in the stack to a value popped off the top of the stack. It then pushes that value onto the top of the stack as well.

### Usage

~~~ruby = ‘val’ ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(number) ⇒ SetN

Returns a new instance of SetN.



5476
5477
5478
# File 'lib/syntax_tree/yarv/instructions.rb', line 5476

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



5474
5475
5476
# File 'lib/syntax_tree/yarv/instructions.rb', line 5474

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



5492
5493
5494
# File 'lib/syntax_tree/yarv/instructions.rb', line 5492

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

#call(vm) ⇒ Object



5508
5509
5510
# File 'lib/syntax_tree/yarv/instructions.rb', line 5508

def call(vm)
  vm.stack[-number - 1] = vm.stack.last
end

#deconstruct_keys(_keys) ⇒ Object



5488
5489
5490
# File 'lib/syntax_tree/yarv/instructions.rb', line 5488

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



5480
5481
5482
# File 'lib/syntax_tree/yarv/instructions.rb', line 5480

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

#lengthObject



5496
5497
5498
# File 'lib/syntax_tree/yarv/instructions.rb', line 5496

def length
  2
end

#popsObject



5500
5501
5502
# File 'lib/syntax_tree/yarv/instructions.rb', line 5500

def pops
  1
end

#pushesObject



5504
5505
5506
# File 'lib/syntax_tree/yarv/instructions.rb', line 5504

def pushes
  1
end

#to_a(_iseq) ⇒ Object



5484
5485
5486
# File 'lib/syntax_tree/yarv/instructions.rb', line 5484

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