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



4980
4981
4982
# File 'lib/syntax_tree/yarv/instructions.rb', line 4980

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



4978
4979
4980
# File 'lib/syntax_tree/yarv/instructions.rb', line 4978

def number
  @number
end

Instance Method Details

#call(vm) ⇒ Object



5008
5009
5010
# File 'lib/syntax_tree/yarv/instructions.rb', line 5008

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

#canonicalObject



5004
5005
5006
# File 'lib/syntax_tree/yarv/instructions.rb', line 5004

def canonical
  self
end

#disasm(fmt) ⇒ Object



4984
4985
4986
# File 'lib/syntax_tree/yarv/instructions.rb', line 4984

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

#lengthObject



4992
4993
4994
# File 'lib/syntax_tree/yarv/instructions.rb', line 4992

def length
  2
end

#popsObject



4996
4997
4998
# File 'lib/syntax_tree/yarv/instructions.rb', line 4996

def pops
  1
end

#pushesObject



5000
5001
5002
# File 'lib/syntax_tree/yarv/instructions.rb', line 5000

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4988
4989
4990
# File 'lib/syntax_tree/yarv/instructions.rb', line 4988

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