Class: SyntaxTree::YARV::InstructionSequence::Stack

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

Overview

This object is used to track the size of the stack at any given time. It is effectively a mini symbolic interpreter. It’s necessary because when instruction sequences get serialized they include a :stack_max field on them. This field is used to determine how much stack space to allocate for the instruction sequence.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStack

Returns a new instance of Stack.



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

def initialize
  @current_size = 0
  @maximum_size = 0
end

Instance Attribute Details

#current_sizeObject (readonly)

Returns the value of attribute current_size.



91
92
93
# File 'lib/syntax_tree/yarv/instruction_sequence.rb', line 91

def current_size
  @current_size
end

#maximum_sizeObject (readonly)

Returns the value of attribute maximum_size.



91
92
93
# File 'lib/syntax_tree/yarv/instruction_sequence.rb', line 91

def maximum_size
  @maximum_size
end

Instance Method Details

#change_by(value) ⇒ Object



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

def change_by(value)
  @current_size += value
  @maximum_size = @current_size if @current_size > @maximum_size
end