class SyntaxTree::YARV::LocalTable
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.
Attributes
locals[R]
Public Class Methods
new()
click to toggle source
# File lib/syntax_tree/yarv/local_table.rb, line 43 def initialize @locals = [] end
Public Instance Methods
block(name)
click to toggle source
Add a BlockLocal
to the local table.
# File lib/syntax_tree/yarv/local_table.rb, line 73 def block(name) locals << BlockLocal.new(name) unless has?(name) end
empty?()
click to toggle source
# File lib/syntax_tree/yarv/local_table.rb, line 47 def empty? locals.empty? end
find(name, level = 0)
click to toggle source
# 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)
click to toggle source
# File lib/syntax_tree/yarv/local_table.rb, line 56 def has?(name) locals.any? { |local| local.name == name } end
name_at(index)
click to toggle source
# File lib/syntax_tree/yarv/local_table.rb, line 64 def name_at(index) locals[index].name end
names()
click to toggle source
# File lib/syntax_tree/yarv/local_table.rb, line 60 def names locals.map(&:name) end
offset(index)
click to toggle source
This is the offset from the top of the stack where this local variable lives.
# File lib/syntax_tree/yarv/local_table.rb, line 84 def offset(index) size - (index - 3) - 1 end
plain(name)
click to toggle source
Add a PlainLocal
to the local table.
# File lib/syntax_tree/yarv/local_table.rb, line 78 def plain(name) locals << PlainLocal.new(name) unless has?(name) end
size()
click to toggle source
# File lib/syntax_tree/yarv/local_table.rb, line 68 def size locals.length end