remove the space instance from register machine
bad design, probably from the booting
This commit is contained in:
@ -21,8 +21,8 @@ module Elf
|
||||
set_text assembler.write_as_string
|
||||
|
||||
# for debug add labels for labels
|
||||
Register.machine.space.types.values.each do |type|
|
||||
type.instance_methods.each do |f|
|
||||
Parfait::Space.object_space.types.values.each do |type|
|
||||
type.methods.each do |f|
|
||||
f.instructions.each_label do |label|
|
||||
add_symbol "#{clazz.name}::#{f.name}:#{label.name}" , label.position
|
||||
end
|
||||
|
@ -47,15 +47,15 @@ module Register
|
||||
# - create the Class objects and assign them to the types
|
||||
def boot_parfait!
|
||||
types = boot_types
|
||||
boot_boot_space(types)
|
||||
classes = boot_classes(types)
|
||||
fix_types(types , classes)
|
||||
boot_boot_space( types )
|
||||
classes = boot_classes( types )
|
||||
fix_types( types , classes )
|
||||
|
||||
@space = Parfait::Space.new(classes)
|
||||
Parfait::Space.set_object_space @space
|
||||
space = Parfait::Space.new( classes )
|
||||
Parfait::Space.set_object_space( space )
|
||||
|
||||
#puts Sof.write(@space)
|
||||
boot_functions!
|
||||
boot_functions!( space )
|
||||
end
|
||||
|
||||
# types is where the snake bites its tail. Every chain ends at a type and then it
|
||||
@ -158,29 +158,29 @@ module Register
|
||||
# Methods are grabbed from respective modules by sending the method name. This should return the
|
||||
# implementation of the method (ie a method object), not actually try to implement it
|
||||
# (as that's impossible in ruby)
|
||||
def boot_functions!
|
||||
def boot_functions!( space )
|
||||
# very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we
|
||||
# have to define some dummies, just for the others to compile
|
||||
# TODO go through the virtual parfait layer and adjust function names to what they really are
|
||||
space = @space.get_class_by_name(:Space)
|
||||
space.instance_type.add_method Builtin::Space.send(:main, nil)
|
||||
space_class = space.get_class_by_name(:Space)
|
||||
space_class.instance_type.add_method Builtin::Space.send(:main, nil)
|
||||
|
||||
obj = @space.get_class_by_name(:Object)
|
||||
obj = space.get_class_by_name(:Object)
|
||||
[ :get_internal_word , :set_internal_word ].each do |f|
|
||||
obj.instance_type.add_method Builtin::Object.send(f , nil)
|
||||
end
|
||||
obj = @space.get_class_by_name(:Kernel)
|
||||
obj = space.get_class_by_name(:Kernel)
|
||||
# create __init__ main first, __init__ calls it
|
||||
[:exit , :__init__ ].each do |f|
|
||||
obj.instance_type.add_method Builtin::Kernel.send(f , nil)
|
||||
end
|
||||
|
||||
obj = @space.get_class_by_name(:Word)
|
||||
obj = space.get_class_by_name(:Word)
|
||||
[:putstring , :get_internal_byte , :set_internal_byte ].each do |f|
|
||||
obj.instance_type.add_method Builtin::Word.send(f , nil)
|
||||
end
|
||||
|
||||
obj = @space.get_class_by_name(:Integer)
|
||||
obj = space.get_class_by_name(:Integer)
|
||||
[ :putint, :mod4, :div10].each do |f| #mod4 is just a forward declaration
|
||||
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
||||
end
|
||||
|
@ -21,7 +21,7 @@ module Register
|
||||
ret_tmp = compiler.use_reg(:Label)
|
||||
compiler.add_load_constant("__init__ load return", exit_label , ret_tmp)
|
||||
compiler.add_reg_to_slot("__init__ store return", ret_tmp , :message , :return_address)
|
||||
compiler.add_code Register.function_call( "__init__ issue call" , Register.machine.space.get_main )
|
||||
compiler.add_code Register.function_call( "__init__ issue call" , Parfait::Space.object_space.get_main )
|
||||
compiler.add_code exit_label
|
||||
emit_syscall( compiler , :exit )
|
||||
return compiler.method
|
||||
|
@ -21,29 +21,18 @@ module Register
|
||||
@booted = false
|
||||
@constants = []
|
||||
end
|
||||
attr_reader :constants
|
||||
attr_reader :space , :class_mappings , :init , :objects , :booted
|
||||
attr_reader :constants , :init , :objects , :booted
|
||||
|
||||
# idea being that later method missing could catch translate_xxx and translate to target xxx
|
||||
# now we just instantiate ArmTranslater and pass instructions
|
||||
def translate_arm
|
||||
methods = collect_methods
|
||||
methods = Parfait::Space.object_space.collect_methods
|
||||
translate_methods( methods )
|
||||
label = @init.next
|
||||
@init = Arm::Translator.new.translate( @init )
|
||||
@init.append label
|
||||
end
|
||||
|
||||
def collect_methods
|
||||
methods = []
|
||||
self.space.types.each do |hash , t|
|
||||
t.methods.each do |f|
|
||||
methods << f
|
||||
end
|
||||
end
|
||||
methods
|
||||
end
|
||||
|
||||
def translate_methods(methods)
|
||||
translator = Arm::Translator.new
|
||||
methods.each do |method|
|
||||
@ -75,7 +64,7 @@ module Register
|
||||
def boot
|
||||
initialize
|
||||
boot_parfait!
|
||||
@init = Branch.new( "__initial_branch__" , self.space.get_init.instructions )
|
||||
@init = Branch.new( "__initial_branch__" , Parfait::Space.object_space.get_init.instructions )
|
||||
@booted = true
|
||||
self
|
||||
end
|
||||
|
@ -108,7 +108,7 @@ module Typed
|
||||
# class_name and method_name are pretty clear, args are given as a ruby array
|
||||
def create_method( class_name , method_name , args = {})
|
||||
raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol
|
||||
clazz = Register.machine.space.get_class_by_name! class_name
|
||||
clazz = Parfait::Space.object_space.get_class_by_name! class_name
|
||||
create_method_for( clazz.instance_type , method_name , args)
|
||||
end
|
||||
|
||||
|
@ -46,7 +46,7 @@ module Typed
|
||||
when Parfait::Type
|
||||
type = me.type
|
||||
when Symbol
|
||||
type = Register.machine.space.get_class_by_name(me.type).instance_type
|
||||
type = Parfait::Space.object_space.get_class_by_name(me.type).instance_type
|
||||
else
|
||||
raise me.inspect
|
||||
end
|
||||
|
@ -52,6 +52,23 @@ module Parfait
|
||||
@@object_space = space
|
||||
end
|
||||
|
||||
def each_type
|
||||
@types.values.each do |type|
|
||||
yield(type)
|
||||
end
|
||||
end
|
||||
|
||||
# all methods form all types
|
||||
def collect_methods
|
||||
methods = []
|
||||
each_type do | type |
|
||||
type.methods.each do |meth|
|
||||
methods << meth
|
||||
end
|
||||
end
|
||||
methods
|
||||
end
|
||||
|
||||
def get_main
|
||||
kernel = get_class_by_name :Space
|
||||
kernel.instance_type.get_method :main
|
||||
|
@ -7,7 +7,7 @@ class Symbol
|
||||
true
|
||||
end
|
||||
def get_type
|
||||
l = Register.machine.space.classes[:Word].instance_type
|
||||
l = Parfait::Space.object_space.classes[:Word].instance_type
|
||||
#puts "LL #{l.class}"
|
||||
l
|
||||
end
|
||||
|
Reference in New Issue
Block a user