rename object_type to instance_type

for better distinction that it is not every object
but only instances of the class
This commit is contained in:
Torsten Ruger 2016-02-25 12:16:13 -08:00
parent 278d71b56c
commit a8b815117f
11 changed files with 19 additions and 19 deletions

View File

@ -68,7 +68,7 @@ module Register
classes = space.classes
type_names.each do |name , vars|
cl = object_with_type Parfait::Class
cl.object_type = @types[name]
cl.instance_type = @types[name]
@types[name].object_class = cl
cl.instance_methods = object_with_type Parfait::List
# puts "instance_methods is #{cl.instance_methods.class}"
@ -121,7 +121,7 @@ module Register
:Space => {:classes => :Dictionary , :first_message => :Message},
:Frame => {:next_frame => :Frame, :indexed_length => :Integer},
:Type => {:object_class => :Class, :instance_methods => :List , :indexed_length => :Integer} ,
:Class => {:instance_methods => :List, :object_type => :Type, :name => :Word,
:Class => {:instance_methods => :List, :instance_type => :Type, :name => :Word,
:super_class_name => :Word},
:Dictionary => {:keys => :List , :values => :List } ,
:Method => {:name => :Word, :source => :Object, :instructions => :Object, :binary => :Object,

View File

@ -19,7 +19,7 @@
module Parfait
class Class < Object
include Behaviour
attributes [:object_type , :name , :super_class_name]
attributes [:instance_type , :name , :super_class_name]
def initialize name , superclass
super()
@ -28,7 +28,7 @@ module Parfait
# the type for this class (class = object of type Class) carries the 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
self.object_type = Type.new(self)
self.instance_type = Type.new(self)
end
def allocate_object
@ -36,7 +36,7 @@ module Parfait
end
def add_instance_name name
self.object_type.push name
self.instance_type.push name
end
def sof_reference_name
@ -50,7 +50,7 @@ module Parfait
def create_instance_method method_name , arguments
raise "create_instance_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
clazz = object_type().object_class()
clazz = instance_type().object_class()
raise "??? #{method_name}" unless clazz
#puts "Self: #{self.class} clazz: #{clazz.name}"
add_instance_method Method.new( clazz , method_name , arguments )

View File

@ -24,7 +24,7 @@ module Parfait
# have to grab the class, because we are in the ruby class not the parfait one
cl = Space.object_space.get_class_by_name( self.name.split("::").last.to_sym)
# and have to set the type before we let the object do anything. otherwise boom
object.set_type cl.object_type
object.set_type cl.instance_type
object.send :initialize , *args
object

View File

@ -7,7 +7,7 @@ class Symbol
true
end
def get_type
l = Register.machine.space.classes[:Word].object_type
l = Register.machine.space.classes[:Word].instance_type
#puts "LL #{l.class}"
l
end

View File

@ -92,7 +92,7 @@ module Register
real_name = clazz_name.to_s.split('_').last.capitalize.to_sym
clazz = Parfait::Space.object_space.get_class_by_name(real_name)
raise "Class name not given #{real_name}" unless clazz
index = clazz.object_type.variable_index( instance_name )
index = clazz.instance_type.variable_index( instance_name )
raise "Instance name=#{instance_name} not found on #{real_name}" unless index.is_a?(Numeric)
return index # the type word is at index 0, but type is a list and starts at 1 == type
end

View File

@ -7,10 +7,10 @@ module Soml
for_class = @clazz
raise "no class" unless for_class
index = for_class.object_type.variable_index(name)
index = for_class.instance_type.variable_index(name)
#raise "class field already defined:#{name} for class #{for_class.name}" if index
#puts "Define field #{name} on class #{for_class.name}"
index = for_class.object_type.add_instance_variable( name , type )
index = for_class.instance_type.add_instance_variable( name , type )
# not sure how to run class code yet. later
raise "value #{value}" if value

View File

@ -10,9 +10,9 @@ module Soml
field_name = field_ast.first_from(:name)
index = clazz.object_type.variable_index(field_name)
index = clazz.instance_type.variable_index(field_name)
raise "field access, but no such field:#{field_name} for class #{clazz.name}" unless index
value = use_reg(clazz.object_type.type_at(index))
value = use_reg(clazz.instance_type.type_at(index))
add_code Register.get_slot(statement , receiver , index, value)

View File

@ -1,6 +1,6 @@
class Class < Object
field List instance_methods
field Type object_type
field Type instance_type
field Word name
field Word super_class_name

View File

@ -65,7 +65,7 @@ class TestType < MiniTest::Test
def test_class_type
oc = Register.machine.boot.space.get_class_by_name( :Object )
assert_equal Parfait::Class , oc.class
type = oc.object_type
type = oc.instance_type
assert_equal Parfait::Type , type.class
assert_equal 1 , type.instance_names.get_length
assert_equal type.first , :type
@ -119,7 +119,7 @@ class TestType < MiniTest::Test
assert_equal 55 , @mess.get_internal_word(message_ind)
end
def test_object_type
def test_instance_type
assert_equal 2 , @mess.get_type.variable_index(:next_message)
end

View File

@ -25,7 +25,7 @@ HERE
end
def test_field
Register.machine.space.get_class_by_name(:Object).object_type.add_instance_variable(:bro,:Object)
Register.machine.space.get_class_by_name(:Object).instance_type.add_instance_variable(:bro,:Object)
@root = :field_access
@string_input = <<HERE
self.bro

View File

@ -31,13 +31,13 @@ module Register
end
def test_field_int
Register.machine.space.get_class_by_name(:Object).object_type.add_instance_variable(:bro,:int)
Register.machine.space.get_class_by_name(:Object).instance_type.add_instance_variable(:bro,:int)
@string_input = "self.bro + 3"
check
end
def test_int_field
Register.machine.space.get_class_by_name(:Object).object_type.add_instance_variable(:bro,:int)
Register.machine.space.get_class_by_name(:Object).instance_type.add_instance_variable(:bro,:int)
@string_input = "3 + self.bro"
check
end