Class: EleetScript::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/lang/runtime/memory.rb

Constant Summary collapse

ROOT_OBJECTS =
{
  'Object' => nil,
  'Number' => nil,
  'Integer' => 'Number',
  'Float' => 'Number',
  'Enumerable' => nil,
  'List' => 'Enumerable',
  'String' => 'Enumerable',
  'Symbol' => nil,
  'Regex' => nil,
  'IO' => nil,
  'Lambda' => nil,
  'TrueClass' => nil,
  'FalseClass' => nil,
  'NilClass' => nil,
  'Random' => nil
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemory

Returns a new instance of Memory.



41
42
43
44
# 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

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



11
12
13
# File 'lib/lang/runtime/memory.rb', line 11

def root
  @root
end

#root_contextObject (readonly)

Returns the value of attribute root_context.



11
12
13
# File 'lib/lang/runtime/memory.rb', line 11

def root_context
  @root_context
end

#root_namespaceObject (readonly)

Returns the value of attribute root_namespace.



11
12
13
# File 'lib/lang/runtime/memory.rb', line 11

def root_namespace
  @root_namespace
end

Class Method Details

.core_definersObject



36
37
38
# File 'lib/lang/runtime/memory.rb', line 36

def core_definers
  @core_definers ||= []
end

.define_core_methods(&block) ⇒ Object



32
33
34
# File 'lib/lang/runtime/memory.rb', line 32

def define_core_methods(&block)
  core_definers << block
end

Instance Method Details

#bootstrap(loader) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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