Class: SyntaxTree::YARV::InstructionSequence::Stack
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::InstructionSequence::Stack
- 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
-
#current_size ⇒ Object
readonly
Returns the value of attribute current_size.
-
#maximum_size ⇒ Object
readonly
Returns the value of attribute maximum_size.
Instance Method Summary collapse
- #change_by(value) ⇒ Object
-
#initialize ⇒ Stack
constructor
A new instance of Stack.
Constructor Details
#initialize ⇒ Stack
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_size ⇒ Object (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_size ⇒ Object (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 |