class EleetScript::Memory

Constants

ROOT_OBJECTS

Attributes

root[R]
root_context[R]
root_namespace[R]

Public Class Methods

core_definers() click to toggle source
# File lib/lang/runtime/memory.rb, line 36
def core_definers
  @core_definers ||= []
end
define_core_methods(&block) click to toggle source
# File lib/lang/runtime/memory.rb, line 32
def define_core_methods(&block)
  core_definers << block
end
new() click to toggle source
# File lib/lang/runtime/memory.rb, line 41
def initialize
  @root_namespace = NamespaceContext.new(nil, nil)
  @root_path = File.join(File.dirname(__FILE__), 'eleetscript')
end

Public Instance Methods

bootstrap(loader) click to toggle source
# File lib/lang/runtime/memory.rb, line 46
def bootstrap(loader)
  return if @bootstrapped
  @bootstrapped = true

  ROOT_OBJECTS.each do |obj_name, parent_class|
    if parent_class.nil?
      root_namespace[obj_name] = EleetScriptClass.create(root_namespace, obj_name)
    else
      root_namespace[obj_name] = EleetScriptClass.create(root_namespace, obj_name, root_namespace[parent_class])
    end
  end

  @root = root_namespace['Object'].new(root_namespace)
  root_namespace.current_self = @root
  root_namespace.current_class = @root.runtime_class

  root_namespace['true'] = root_namespace['TrueClass'].new_with_value(true, root_namespace)
  root_namespace['false'] = root_namespace['FalseClass'].new_with_value(false, root_namespace)
  root_namespace['nil'] = root_namespace['NilClass'].new_with_value(nil, root_namespace)

  # Global Errors Object
  root_namespace['Errors'] = root_namespace['List'].new_with_value(ListBase.new, root_namespace)

  self.class.core_definers.each do |definer_block|
    instance_eval(&definer_block)
  end

  files = Dir.glob(File.join(@root_path, '**', '*.es'))
  files.each do |file|
    loader.load(file)
  end
end