Class: SyntaxTree::YARV::VM::Stack

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

Overview

This represents the global VM stack. It effectively is an array, but wraps mutating functions with instrumentation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events) ⇒ Stack

Returns a new instance of Stack.



167
168
169
170
# File 'lib/syntax_tree/yarv/vm.rb', line 167

def initialize(events)
  @events = events
  @values = []
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



165
166
167
# File 'lib/syntax_tree/yarv/vm.rb', line 165

def events
  @events
end

#valuesObject (readonly)

Returns the value of attribute values.



165
166
167
# File 'lib/syntax_tree/yarv/vm.rb', line 165

def values
  @values
end

Instance Method Details

#[]Object



196
197
198
# File 'lib/syntax_tree/yarv/vm.rb', line 196

def [](...)
  values.[](...)
end

#[]=Object



200
201
202
# File 'lib/syntax_tree/yarv/vm.rb', line 200

def []=(...)
  values.[]=(...).tap { events.publish_stack_change(self) }
end

#concatObject



172
173
174
# File 'lib/syntax_tree/yarv/vm.rb', line 172

def concat(...)
  values.concat(...).tap { events.publish_stack_change(self) }
end

#lastObject



176
177
178
# File 'lib/syntax_tree/yarv/vm.rb', line 176

def last
  values.last
end

#lengthObject



180
181
182
# File 'lib/syntax_tree/yarv/vm.rb', line 180

def length
  values.length
end

#popObject



188
189
190
# File 'lib/syntax_tree/yarv/vm.rb', line 188

def pop(...)
  values.pop(...).tap { events.publish_stack_change(self) }
end

#pushObject



184
185
186
# File 'lib/syntax_tree/yarv/vm.rb', line 184

def push(...)
  values.push(...).tap { events.publish_stack_change(self) }
end

#slice!Object



192
193
194
# File 'lib/syntax_tree/yarv/vm.rb', line 192

def slice!(...)
  values.slice!(...).tap { events.publish_stack_change(self) }
end