Class: SyntaxTree::YARV::SetN

Inherits:
Object
  • Object
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

Constructor Details

#initialize(number) ⇒ SetN

Returns a new instance of SetN.



5723
5724
5725
# File 'lib/syntax_tree/yarv/instructions.rb', line 5723

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



5721
5722
5723
# File 'lib/syntax_tree/yarv/instructions.rb', line 5721

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



5739
5740
5741
# File 'lib/syntax_tree/yarv/instructions.rb', line 5739

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

#call(vm) ⇒ Object



5759
5760
5761
# File 'lib/syntax_tree/yarv/instructions.rb', line 5759

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

#canonicalObject



5755
5756
5757
# File 'lib/syntax_tree/yarv/instructions.rb', line 5755

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



5735
5736
5737
# File 'lib/syntax_tree/yarv/instructions.rb', line 5735

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



5727
5728
5729
# File 'lib/syntax_tree/yarv/instructions.rb', line 5727

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

#lengthObject



5743
5744
5745
# File 'lib/syntax_tree/yarv/instructions.rb', line 5743

def length
  2
end

#popsObject



5747
5748
5749
# File 'lib/syntax_tree/yarv/instructions.rb', line 5747

def pops
  1
end

#pushesObject



5751
5752
5753
# File 'lib/syntax_tree/yarv/instructions.rb', line 5751

def pushes
  1
end

#to_a(_iseq) ⇒ Object



5731
5732
5733
# File 'lib/syntax_tree/yarv/instructions.rb', line 5731

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