Class: SyntaxTree::YARV::AdjustStack

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

Overview

### Summary

adjuststack accepts a single integer argument and removes that many elements from the top of the stack.

### Usage

~~~ruby x = [true] x ||= nil x ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ AdjustStack

Returns a new instance of AdjustStack.



82
83
84
# File 'lib/syntax_tree/yarv/instructions.rb', line 82

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



80
81
82
# File 'lib/syntax_tree/yarv/instructions.rb', line 80

def number
  @number
end

Instance Method Details

#call(vm) ⇒ Object



110
111
112
# File 'lib/syntax_tree/yarv/instructions.rb', line 110

def call(vm)
  vm.pop(number)
end

#canonicalObject



106
107
108
# File 'lib/syntax_tree/yarv/instructions.rb', line 106

def canonical
  self
end

#disasm(fmt) ⇒ Object



86
87
88
# File 'lib/syntax_tree/yarv/instructions.rb', line 86

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

#lengthObject



94
95
96
# File 'lib/syntax_tree/yarv/instructions.rb', line 94

def length
  2
end

#popsObject



98
99
100
# File 'lib/syntax_tree/yarv/instructions.rb', line 98

def pops
  number
end

#pushesObject



102
103
104
# File 'lib/syntax_tree/yarv/instructions.rb', line 102

def pushes
  0
end

#to_a(_iseq) ⇒ Object



90
91
92
# File 'lib/syntax_tree/yarv/instructions.rb', line 90

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