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

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



118
119
120
# File 'lib/syntax_tree/yarv/instructions.rb', line 118

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

#canonicalObject



114
115
116
# File 'lib/syntax_tree/yarv/instructions.rb', line 114

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { number: number }
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



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

def length
  2
end

#popsObject



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

def pops
  number
end

#pushesObject



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

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