move space to parfait
Also make the machine the singleton and space hang off it Many repercussions, not all fixed in this commit
This commit is contained in:
@ -7,7 +7,7 @@ There is a mechanism for an actual machine (derived class) to generate harware s
|
||||
plain ones in this directory don't assemble to binary). Currently there is only the Arm module to actually do
|
||||
that.
|
||||
|
||||
The elf module is used to generate the actual binary from the final BootSpace. BootSpace is a virtual class representing
|
||||
The elf module is used to generate the actual binary from the final Space. Space is a virtual class representing
|
||||
all objects that will be in the executable. Other than CompiledMethods, objects get transformed to data.
|
||||
|
||||
But CompiledMethods, which are made up of Blocks, are compiled into a stream of bytes, which are the binary code for the
|
||||
|
@ -12,7 +12,7 @@ module Register
|
||||
TYPE_INT = 1
|
||||
TYPE_BITS = 4
|
||||
TYPE_LENGTH = 6
|
||||
|
||||
|
||||
def initialize space
|
||||
@space = space
|
||||
@objects = {}
|
||||
@ -41,7 +41,7 @@ module Register
|
||||
begin
|
||||
link
|
||||
@stream = StringIO.new
|
||||
mid , main = @objects.find{|k,objekt| objekt.is_a?(Virtual::CompiledMethod) and (objekt.name == :__init__ )}
|
||||
#TODOmid , main = @objects.find{|k,objekt| objekt.is_a?(Virtual::CompiledMethod) and (objekt.name == :__init__ )}
|
||||
initial_jump = @space.init
|
||||
initial_jump.codes.each do |code|
|
||||
code.assemble( @stream )
|
||||
@ -54,7 +54,7 @@ module Register
|
||||
next if objekt.is_a? Virtual::CompiledMethod
|
||||
assemble_object( objekt )
|
||||
end
|
||||
rescue LinkException => e
|
||||
rescue LinkException
|
||||
# knowing that we fix the problem, we hope to get away with retry.
|
||||
retry
|
||||
end
|
||||
@ -63,7 +63,7 @@ module Register
|
||||
end
|
||||
|
||||
def assemble_object obj
|
||||
#puts "Assemble #{obj.class}(#{obj.object_id}) at stream #{(@stream.length).to_s(16)} pos:#{obj.position.to_s(16)} , len:#{obj.mem_length}"
|
||||
#puts "Assemble #{obj.class}(#{obj.object_id}) at stream #{(@stream.length).to_s(16)} pos:#{obj.position.to_s(16)} , len:#{obj.mem_length}"
|
||||
raise "Assemble #{obj.class} at #{@stream.length.to_s(16)} not #{obj.position.to_s(16)}" if @stream.length != obj.position
|
||||
clazz = obj.class.name.split("::").last
|
||||
send("assemble_#{clazz}".to_sym , obj)
|
||||
@ -111,11 +111,11 @@ module Register
|
||||
assemble_self( hash , [ hash.keys , hash.values ] )
|
||||
end
|
||||
|
||||
def assemble_BootSpace(space)
|
||||
def assemble_Space(space)
|
||||
assemble_self(space , [space.classes,space.objects, space.symbols,space.messages,space.next_message,space.next_frame] )
|
||||
end
|
||||
|
||||
def assemble_BootClass(clazz)
|
||||
def assemble_Class(clazz)
|
||||
assemble_self( clazz , [clazz.name , clazz.super_class_name, clazz.instance_methods] )
|
||||
end
|
||||
|
||||
@ -179,7 +179,7 @@ module Register
|
||||
end
|
||||
def add_Array( array )
|
||||
# also array has constant overhead, the padded helper fixes it to multiple of 8
|
||||
array.each do |elem|
|
||||
array.each do |elem|
|
||||
add_object(elem)
|
||||
end
|
||||
end
|
||||
@ -189,7 +189,7 @@ module Register
|
||||
add_object(hash.values)
|
||||
end
|
||||
|
||||
def add_BootSpace(space)
|
||||
def add_Space(space)
|
||||
add_object(space.main)
|
||||
add_object(space.classes)
|
||||
add_object(space.objects)
|
||||
@ -199,7 +199,7 @@ module Register
|
||||
add_object(space.next_frame)
|
||||
end
|
||||
|
||||
def add_BootClass(clazz)
|
||||
def add_Class(clazz)
|
||||
add_object(clazz.name )
|
||||
add_object(clazz.super_class_name)
|
||||
add_object(clazz.instance_methods)
|
||||
@ -214,7 +214,7 @@ module Register
|
||||
def add_StringConstant(sc)
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
# write means we write the resulting address straight into the assembler stream (ie don't return it)
|
||||
# object means the object of which we write the address
|
||||
|
@ -12,7 +12,7 @@ module Builtin
|
||||
# so it is responsible for initial setup (and relocation)
|
||||
def __init__ context
|
||||
function = Virtual::CompiledMethod.new(:__init__ , [] , Virtual::Integer)
|
||||
clazz = Virtual::BootSpace.space.get_or_create_class :Kernel
|
||||
clazz = Virtual::Space.space.get_or_create_class :Kernel
|
||||
method = clazz.resolve_method :main
|
||||
me = Virtual::Self.new(Virtual::Reference)
|
||||
code = Virtual::Set.new(Virtual::Self.new(me.type), me)
|
||||
|
@ -29,7 +29,7 @@ module Builtin
|
||||
var_name = get_function.args.first
|
||||
return_to = get_function.return_type
|
||||
|
||||
index_function = ::Virtual::BootSpace.space.get_or_create_class(:Object).resolve_method(:index_of)
|
||||
index_function = ::Virtual::Space.space.get_or_create_class(:Object).resolve_method(:index_of)
|
||||
# get_function.push( [me] )
|
||||
# index = get_function.call( index_function )
|
||||
|
||||
|
@ -23,5 +23,5 @@ module Register
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual::BootSpace.space.add_pass "Register::CallImplementation"
|
||||
Virtual::Machine.instance.add_pass "Register::CallImplementation"
|
||||
end
|
||||
|
@ -18,5 +18,5 @@ module Register
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual::BootSpace.space.add_pass "Register::ReturnImplementation"
|
||||
Virtual::Machine.instance.add_pass "Register::ReturnImplementation"
|
||||
end
|
||||
|
@ -42,5 +42,5 @@ module Register
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual::BootSpace.space.add_pass "Register::SetImplementation"
|
||||
Virtual::Machine.instance.add_pass "Register::SetImplementation"
|
||||
end
|
||||
|
Reference in New Issue
Block a user