class Atomy::EvalLocalState

Public Class Methods

new(variable_scope) click to toggle source
# File lib/atomy/locals.rb, line 25
def initialize(variable_scope)
  @variable_scope = variable_scope
end

Public Instance Methods

local_count() click to toggle source
# File lib/atomy/locals.rb, line 49
def local_count
  0
end
local_names() click to toggle source
# File lib/atomy/locals.rb, line 53
def local_names
  []
end
new_local(name) click to toggle source
# File lib/atomy/locals.rb, line 44
def new_local(name)
  variable = CodeTools::Compiler::EvalLocalVariable.new(name)
  variables[name] = variable
end
search_local(name) click to toggle source

Returns a cached reference to a variable or searches all surrounding scopes for a variable. If no variable is found, it returns nil and a nested scope will create the variable in itself.

# File lib/atomy/locals.rb, line 33
def search_local(name)
  if variable = variables[name]
    return variable.nested_reference
  end

  if variable = search_scopes(name)
    variables[name] = variable
    return variable.nested_reference
  end
end

Private Instance Methods

search_scopes(name) click to toggle source
# File lib/atomy/locals.rb, line 59
def search_scopes(name)
  depth = 1
  scope = @variable_scope

  while scope
    if !scope.method.for_eval? && (slot = scope.method.local_slot(name))
      return CodeTools::Compiler::NestedLocalVariable.new(depth, slot)
    elsif scope.eval_local_defined?(name, false)
      return CodeTools::Compiler::EvalLocalVariable.new(name)
    end

    depth += 1
    scope = scope.parent
  end
end