make all instances attr read writers

unfortunately the writers have to have self.var =
otherwise it is just a local var
Also need to make the type explicit for all
Protocol included memory_length on the class for now
This commit is contained in:
Torsten Ruger
2018-08-11 19:15:34 +03:00
parent e6df473647
commit b0aefe31fe
19 changed files with 243 additions and 216 deletions

View File

@ -36,7 +36,11 @@ module Parfait
class Type < Object
attr_reader :object_class , :names , :types , :methods
attr :type, :object_class , :names , :types , :methods
def self.type_length
5
end
def self.for_hash( object_class , hash)
hash = {type: object_class.name }.merge(hash) unless hash[:type]
@ -53,9 +57,9 @@ module Parfait
# this part of the init is seperate because at boot time we can not use normal new
# new is overloaded to grab the type from space, and before boot, that is not set up
def init_lists(hash)
@methods = nil
@names = List.new
@types = List.new
self.methods = nil
self.names = List.new
self.types = List.new
raise "No type Type in #{hash}" unless hash[:type]
private_add_instance_variable(:type , hash[:type]) #first
hash.each do |name , type|
@ -64,13 +68,13 @@ module Parfait
end
def class_name
@object_class.name
object_class.name
end
def to_s
str = "#{class_name}-["
first = false
@names.each do |name|
names.each do |name|
unless(first)
first = true
str += ":#{name}"
@ -83,8 +87,8 @@ module Parfait
def method_names
names = List.new
return names unless @methods
@methods.each_method do |method|
return names unless methods
methods.each_method do |method|
names.push method.name
end
names
@ -114,19 +118,19 @@ module Parfait
if get_method( method.name )
remove_method(method.name)
end
method.set_next( @methods )
@methods = method
method.set_next( methods )
self.methods = method
#puts "#{self.name} add #{method.name}"
method
end
def remove_method( method_name )
raise "No such method #{method_name} in #{self.name}" unless @methods
if( @methods.name == method_name)
@methods = @methods.next
raise "No such method #{method_name} in #{self.name}" unless methods
if( methods.name == method_name)
self.methods = methods.next
return true
end
method = @methods
method = methods
while(method && method.next)
if( method.next.name == method_name)
method.set_next( method.next.next )
@ -140,8 +144,8 @@ module Parfait
def get_method( fname )
raise "get_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
return nil unless @methods
@methods.each_method do |m|
return nil unless methods
methods.each_method do |m|
return m if(m.name == fname )
end
nil
@ -163,9 +167,9 @@ module Parfait
end
def methods_length
return 0 unless @methods
return 0 unless methods
len = 0
@methods.each_method { len += 1}
methods.each_method { len += 1}
return len
end
@ -181,38 +185,38 @@ module Parfait
raise "No nil type" unless type
hash = to_hash
hash[name] = type
return Type.for_hash( @object_class , hash)
return Type.for_hash( object_class , hash)
end
def set_object_class(oc)
raise "object class should be a class, not #{oc.class}" unless oc.is_a?(Class)
@object_class = oc
self.object_class = oc
end
def instance_length
@names.get_length()
names.get_length()
end
# index of the variable when using get_internal_word
# (get_internal_word is 0 based and 0 is always the type)
def variable_index( name )
has = @names.index_of(name)
has = names.index_of(name)
return nil unless has
raise "internal error #{name}:#{has}" if has < 0
has
end
def get_length()
@names.get_length()
names.get_length()
end
def name_at( index )
raise "No names #{index}" unless @names
@names.get(index)
raise "No names #{index}" unless names
names.get(index)
end
def type_at( index )
@types.get(index)
types.get(index)
end
def type_for( name )
@ -226,7 +230,7 @@ module Parfait
end
def rxf_reference_name
"#{@object_class.name}_Type"
"#{object_class.name}_Type"
end
alias :name :rxf_reference_name
@ -239,8 +243,8 @@ module Parfait
end
def each_method(&block)
return unless @methods
@methods.each_method(&block)
return unless methods
methods.each_method(&block)
end
def to_hash
hash = {}
@ -254,7 +258,7 @@ module Parfait
def hash
index = 1
hash_code = Type.str_hash( @object_class.name )
hash_code = Type.str_hash( object_class.name )
each do |name , type|
item_hash = Type.str_hash(name) + Type.str_hash(type)
hash_code += item_hash + (item_hash / 256 ) * index
@ -280,8 +284,8 @@ module Parfait
def private_add_instance_variable( name , type)
raise "Name shouldn't be nil" unless name
raise "Value Type shouldn't be nil" unless type
@names.push(name)
@types.push(type)
names.push(name)
types.push(type)
end
end