minor whitespace and renaming

This commit is contained in:
Torsten Ruger 2016-12-30 18:39:49 +02:00
parent 4ef8997854
commit a82c9e8fb1
8 changed files with 37 additions and 48 deletions

View File

@ -15,11 +15,13 @@ module Register
cl cl
end end
end end
# another ruby object to shadow the parfait, just during booting. # another ruby object to shadow the parfait, just during booting.
# all it needs is the type, which we make the Parfait type # all it needs is the type, which we make the Parfait type
class BootClass class BootClass
attr_reader :instance_type attr_reader :instance_type
def initialize type
def initialize( type)
@instance_type = type @instance_type = type
end end
end end
@ -43,8 +45,10 @@ module Register
# There are some helpers below, but the roadmap is something like: # There are some helpers below, but the roadmap is something like:
# - create all the Type instances, with their basic types, but no classes # - create all the Type instances, with their basic types, but no classes
# - create a space by "hand" , using allocate, not new # - create a BootSpace that has BootClasses , used only during booting
# - create the Class objects and assign them to the types # - create the Class objects and assign them to the types
# - flesh out the types , create the real space
# - and finally load the methods
def boot_parfait! def boot_parfait!
types = boot_types types = boot_types
boot_boot_space( types ) boot_boot_space( types )
@ -54,8 +58,8 @@ module Register
space = Parfait::Space.new( classes ) space = Parfait::Space.new( classes )
Parfait.set_object_space( space ) Parfait.set_object_space( space )
#puts Sof.write(@space) #puts Sof.write(space)
boot_functions!( space ) boot_functions( space )
end end
# types is where the snake bites its tail. Every chain ends at a type and then it # types is where the snake bites its tail. Every chain ends at a type and then it
@ -73,15 +77,6 @@ module Register
types types
end end
def fix_types(types , classes)
type_names.each do |name , ivars |
type = types[name]
clazz = classes[name]
type.set_object_class( clazz )
type.init_lists(ivars)
end
end
# The BootSpace is an object that holds fake classes, that hold _real_ types # The BootSpace is an object that holds fake classes, that hold _real_ types
# Once we plug it in we can use .new # Once we plug it in we can use .new
# then we need to create the parfait classes and fix the types before creating a Space # then we need to create the parfait classes and fix the types before creating a Space
@ -91,14 +86,20 @@ module Register
clazz = BootClass.new(type) clazz = BootClass.new(type)
boot_space.classes[name] = clazz boot_space.classes[name] = clazz
end end
Parfait.set_object_space boot_space Parfait.set_object_space( boot_space )
end end
# superclasses other than default object # Types are hollow shells before this, so we need to set the object_class
def super_class_names # and initialize the list variables (which we now can with .new)
{ :Object => :Kernel , :Kernel => :Value, def fix_types(types , classes)
:Integer => :Value , :BinaryCode => :Word } type_names.each do |name , ivars |
type = types[name]
clazz = classes[name]
type.set_object_class( clazz )
type.init_lists({:type => :Type }.merge(ivars))
end end
end
# when running code instantiates a class, a type is created automatically # when running code instantiates a class, a type is created automatically
# but even to get our space up, we have already instantiated all types # but even to get our space up, we have already instantiated all types
# so we have to continue and allocate classes and fill the data by hand # so we have to continue and allocate classes and fill the data by hand
@ -112,19 +113,9 @@ module Register
classes classes
end end
def set_ivars_for(type , name , ivars) # superclasses other than default object
type.send(:private_add_instance_variable , :type , name) def super_class_names
ivars.each {|n,t| type.send(:private_add_instance_variable, n , t) } { :Object => :Kernel , :Kernel => :Value , :Integer => :Value , :BinaryCode => :Word }
end
# create an object with type (ie allocate it and assign type)
# meaning the lauouts have to be booted, @types filled
# here we pass the actual (ruby) class
def object_with_type(cl)
o = cl.allocate
name = cl.name.split("::").last.to_sym
o.set_type @types[name]
o
end end
# the function really just returns a constant (just avoiding the constant) # the function really just returns a constant (just avoiding the constant)
@ -149,7 +140,6 @@ module Register
:Dictionary => {:keys => :List , :values => :List } , :Dictionary => {:keys => :List , :values => :List } ,
:TypedMethod => {:name => :Word, :source => :Object, :instructions => :Object, :binary => :Object, :TypedMethod => {:name => :Word, :source => :Object, :instructions => :Object, :binary => :Object,
:arguments => :Type , :for_type => :Type, :locals => :Type } , :arguments => :Type , :for_type => :Type, :locals => :Type } ,
:Value => {},
} }
end end
@ -158,7 +148,7 @@ module Register
# Methods are grabbed from respective modules by sending the method name. This should return the # 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 # implementation of the method (ie a method object), not actually try to implement it
# (as that's impossible in ruby) # (as that's impossible in ruby)
def boot_functions!( space ) def boot_functions( space )
# very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we # 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 # 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 # TODO go through the virtual parfait layer and adjust function names to what they really are

View File

@ -2,8 +2,8 @@ module Register
# collect anything that is in the space but and reachable from init # collect anything that is in the space but and reachable from init
module Collector module Collector
def collect def collect_space
self.objects.clear @objects.clear
keep Parfait.object_space , 0 keep Parfait.object_space , 0
constants.each {|o| keep(o,0)} constants.each {|o| keep(o,0)}
end end

View File

@ -51,13 +51,14 @@ module Register
end end
# Objects are data and get assembled after functions # Objects are data and get assembled after functions
def add_object o def add_object objekt
return false if @objects[o.object_id] return false if @objects[objekt.object_id]
return true if o.is_a? Fixnum return true if objekt.is_a? Fixnum
unless o.is_a? Parfait::Object or o.is_a? Symbol or o.is_a? Register::Label unless objekt.is_a?( Parfait::Object) or objekt.is_a?( Symbol) or objekt.is_a?( Register::Label)
raise "adding non parfait #{o.class}" raise "adding non parfait #{objekt.class}"
end end
@objects[o.object_id] = o #raise "Method #{objekt.name}" if objekt.is_a? Parfait::TypedMethod
@objects[objekt.object_id] = objekt
true true
end end

View File

@ -1,5 +1,5 @@
# Integer class for representing mathods on Integers # Integer class for representing maths on Integers
# Integers are Values (not Objects), # Integers are Values (not Objects),
# - they have fixed value # - they have fixed value
# - they are immutable # - they are immutable

View File

@ -17,8 +17,6 @@ module Parfait
class Object class Object
# we define new, so we can do memory layout also at compile time.
# At compile time we fake memory by using a global array for pages
def self.new *args def self.new *args
object = self.allocate object = self.allocate

View File

@ -8,7 +8,7 @@ module Ticker
machine = Register.machine.boot machine = Register.machine.boot
do_clean_compile do_clean_compile
Typed.compile( @input ) Typed.compile( @input )
machine.collect machine.collect_space
@interpreter = Register::Interpreter.new @interpreter = Register::Interpreter.new
@interpreter.start Register.machine.init @interpreter.start Register.machine.init
end end

View File

@ -17,7 +17,7 @@ class TestPositioning < MiniTest::Test
assert_equal 32 , list.padded_length assert_equal 32 , list.padded_length
end end
def test_type def test_type
type = Parfait::Type.new Parfait.object_space.get_class_by_name(:Object) type = Parfait::Type.for_hash Parfait.object_space.get_class_by_name(:Object) , {}
type.set_type( type ) type.set_type( type )
assert_equal 32 , type.padded_length assert_equal 32 , type.padded_length
end end

View File

@ -5,8 +5,8 @@ class TypeApi < MiniTest::Test
def setup def setup
Register.machine.boot Register.machine.boot
@space = Parfait.object_space @space = Parfait.object_space
tc = @space.get_class_by_name( :Type ) tc = @space.get_class_by_name( :NamedList )
@type = Parfait::Type.new tc @type = tc.instance_type
end end
def test_inspect def test_inspect