class EleetScript::BaseContext

Attributes

init_funcs[R]
constants[R]
current_class[RW]
current_self[RW]
global_vars[R]
local_vars[R]
namespaces[R]

Public Class Methods

init_with(*func_symbols) click to toggle source
# File lib/lang/runtime/context.rb, line 11
def init_with(*func_symbols)
  (@init_funcs ||= [])
  @init_funcs += func_symbols
end
new(*args) click to toggle source
# File lib/lang/runtime/context.rb, line 21
def initialize(*args)
  init(args)
  self
end

Public Instance Methods

[](key) click to toggle source
# File lib/lang/runtime/context.rb, line 66
def [](key)
  store = fetch_var_store(key)
  if store[key]
    store[key]
  elsif @parent_context
    @parent_context[key]
  else
    es_nil
  end
end
[]=(key, value) click to toggle source
# File lib/lang/runtime/context.rb, line 77
def []=(key, value)
  store = fetch_var_store(key)
  store[key] = value
end
class_vars() click to toggle source
# File lib/lang/runtime/context.rb, line 46
def class_vars
  @current_self.class_vars
end
es_nil() click to toggle source
# File lib/lang/runtime/context.rb, line 26
def es_nil
  @_es_nil ||= root_ns["nil"]
end
instance_vars() click to toggle source
# File lib/lang/runtime/context.rb, line 42
def instance_vars
  @current_self.instance_vars
end
local_constant(name) click to toggle source
# File lib/lang/runtime/context.rb, line 62
def local_constant(name)
  constants[name] || es_nil
end
local_var(name, value = nil) click to toggle source
# File lib/lang/runtime/context.rb, line 54
def local_var(name, value = nil)
  if value
    local_vars[name] = value
  else
    local_vars[name] || es_nil
  end
end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/lang/runtime/context.rb, line 86
def method_missing(name, *args)
  if @parent_context && @parent_context.respond_to?(name)
    @parent_context.send(name, *args)
  else
    super(name, *args)
  end
end
namespace_context() click to toggle source
# File lib/lang/runtime/context.rb, line 50
def namespace_context
  root_ns
end
respond_to_missing?(name, incl_priv = false) click to toggle source
# File lib/lang/runtime/context.rb, line 82
def respond_to_missing?(name, incl_priv = false)
  @parent_context && @parent_context.respond_to?(name, incl_priv)
end
root_ns() click to toggle source
# File lib/lang/runtime/context.rb, line 30
def root_ns
  @parent_context ? @parent_context.root_ns : nil
end

Protected Instance Methods

fetch_var_store(key) click to toggle source
# File lib/lang/runtime/context.rb, line 96
def fetch_var_store(key)
  if key[0] =~ /[A-Z]/
    constants
  elsif key[0] =~ /[a-z_]/
    local_vars
  elsif key[0] == "$"
    global_vars
  elsif key[0..1] == "@@"
    class_vars
  elsif key[0] == "@"
    instance_vars
  else
    {}
  end
end
parent_context=(context) click to toggle source
# File lib/lang/runtime/context.rb, line 112
def parent_context=(context)
  @parent_context = context
end

Private Instance Methods

init(args) click to toggle source
# File lib/lang/runtime/context.rb, line 118
def init(args)
  throw "Arguments for new context should contain a current self and current class (even if both are nil)." if args.length < 2
  @current_self = args.shift
  cc = if args.length > 0
    args.shift
  else
    nil
  end
  @current_class = if cc.nil?
    if @current_self
      if @current_self.class?
        @current_self
      else
        @current_self.runtime_class
      end
    else
      nil
    end
  else
    cc
  end
  @parent_context = nil
  @local_vars = ProcessedKeyHash.new
  @constants = ProcessedKeyHash.new
  @global_vars = {}
  @namespaces = {}
  self.class.init_funcs.each do |symbol|
    send(symbol, *args) if respond_to?(symbol, true)
  end
end