remove instance_names from class again

and use types names instead. For now assuming Object class
This commit is contained in:
Torsten Ruger 2016-12-19 14:20:47 +02:00
parent af9fed863f
commit aa5f48e3c6
5 changed files with 13 additions and 15 deletions

View File

@ -18,7 +18,8 @@ module Melon
def on_class statement def on_class statement
name , sup , body = *statement name , sup , body = *statement
clazz = Parfait::Space.object_space.create_class(get_name(name) , get_name(sup) ) clazz = Parfait::Space.object_space.create_class(get_name(name) , get_name(sup) )
clazz.set_instance_names( TypeCollector.new.collect(body) ) ivar_hash = TypeCollector.new.collect(body)
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
end end
end end
end end

View File

@ -3,16 +3,17 @@ module Melon
class TypeCollector < AST::Processor class TypeCollector < AST::Processor
def initialize def initialize
@ivar_names = [] @ivars = {}
end end
def collect(statement) def collect(statement)
process statement process statement
@ivar_names @ivars
end end
def on_ivar(statement) def on_ivar(statement)
@ivar_names.push statement.children[0].to_s[1..-1].to_sym var = statement.children[0].to_s[1..-1].to_sym
@ivars[var] = :Object #guess, can maybe guess better
end end
def handler_missing(node) def handler_missing(node)

View File

@ -76,7 +76,6 @@ module Register
@types[name].object_class = cl @types[name].object_class = cl
@types[name].instance_methods = object_with_type Parfait::List @types[name].instance_methods = object_with_type Parfait::List
cl.instance_methods = object_with_type Parfait::List cl.instance_methods = object_with_type Parfait::List
cl.instance_names = object_with_type Parfait::List
#puts "instance_methods is #{cl.instance_methods.class}" #puts "instance_methods is #{cl.instance_methods.class}"
cl.name = name cl.name = name
classes[name] = cl classes[name] = cl

View File

@ -26,21 +26,12 @@ module Parfait
# as an instance. The relation is from an object through the Type to it's class # as an instance. The relation is from an object through the Type to it's class
# TODO the object type should copy the stuff from superclass # TODO the object type should copy the stuff from superclass
self.instance_type = Type.new(self) self.instance_type = Type.new(self)
self.instance_names = List.new()
end end
def allocate_object def allocate_object
#space, and ruby allocate #space, and ruby allocate
end end
def set_instance_names( names )
self.instance_names = names
end
def add_instance_name name
self.instance_names << name
self.instance_type.push name
end
def sof_reference_name def sof_reference_name
name name
end end
@ -49,6 +40,12 @@ module Parfait
"Class(#{name})" "Class(#{name})"
end end
# setting the type generates all methods for this type
# (or will do, once we storet the methods code to do that)
def set_instance_type( type )
self.instance_type = type
end
# this needs to be done during booting as we can't have all the classes and superclassses # this needs to be done during booting as we can't have all the classes and superclassses
# instantiated. By that logic it should maybe be part of vm rather. # instantiated. By that logic it should maybe be part of vm rather.
# On the other hand vague plans to load the hierachy from sof exist, so for now... # On the other hand vague plans to load the hierachy from sof exist, so for now...

View File

@ -22,7 +22,7 @@ module Melon
def test_picks_up_an_ivar_name def test_picks_up_an_ivar_name
Compiler.compile "class TestIvar < Object ; def meth; return @ivar;end; end" Compiler.compile "class TestIvar < Object ; def meth; return @ivar;end; end"
itest = Parfait::Space.object_space.get_class_by_name(:TestIvar) itest = Parfait::Space.object_space.get_class_by_name(:TestIvar)
assert itest.instance_names.include?(:ivar) , itest.instance_names.inspect assert itest.instance_type.instance_names.include?(:ivar) , itest.instance_type.instance_names.inspect
end end
end end