Class: SyntaxTree::YARV::LocalTable
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::LocalTable
- Defined in:
- lib/syntax_tree/yarv/local_table.rb
Overview
This represents every local variable associated with an instruction sequence. There are two kinds of locals: plain locals that are what you expect, and block proxy locals, which represent local variables associated with blocks that were passed into the current instruction sequence.
Defined Under Namespace
Classes: BlockLocal, Lookup, PlainLocal
Instance Attribute Summary collapse
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
Instance Method Summary collapse
-
#block(name) ⇒ Object
Add a BlockLocal to the local table.
- #empty? ⇒ Boolean
- #find(name, level = 0) ⇒ Object
- #has?(name) ⇒ Boolean
-
#initialize ⇒ LocalTable
constructor
A new instance of LocalTable.
- #name_at(index) ⇒ Object
- #names ⇒ Object
-
#offset(index) ⇒ Object
This is the offset from the top of the stack where this local variable lives.
-
#plain(name) ⇒ Object
Add a PlainLocal to the local table.
- #size ⇒ Object
Constructor Details
#initialize ⇒ LocalTable
Returns a new instance of LocalTable.
43 44 45 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 43 def initialize @locals = [] end |
Instance Attribute Details
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
41 42 43 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 41 def locals @locals end |
Instance Method Details
#block(name) ⇒ Object
Add a BlockLocal to the local table.
73 74 75 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 73 def block(name) locals << BlockLocal.new(name) unless has?(name) end |
#empty? ⇒ Boolean
47 48 49 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 47 def empty? locals.empty? end |
#find(name, level = 0) ⇒ Object
51 52 53 54 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 51 def find(name, level = 0) index = locals.index { |local| local.name == name } Lookup.new(locals[index], index, level) if index end |
#has?(name) ⇒ Boolean
56 57 58 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 56 def has?(name) locals.any? { |local| local.name == name } end |
#name_at(index) ⇒ Object
64 65 66 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 64 def name_at(index) locals[index].name end |
#names ⇒ Object
60 61 62 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 60 def names locals.map(&:name) end |
#offset(index) ⇒ Object
This is the offset from the top of the stack where this local variable lives.
84 85 86 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 84 def offset(index) size - (index - 3) - 1 end |
#plain(name) ⇒ Object
Add a PlainLocal to the local table.
78 79 80 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 78 def plain(name) locals << PlainLocal.new(name) unless has?(name) end |
#size ⇒ Object
68 69 70 |
# File 'lib/syntax_tree/yarv/local_table.rb', line 68 def size locals.length end |