moving to instance variables in parfait

This commit is contained in:
2019-09-09 20:26:54 +03:00
parent fc8de10964
commit 81e3c0c270
21 changed files with 212 additions and 187 deletions

View File

@ -14,7 +14,10 @@
module Parfait
class Object
attr :type
attr_reader :type
def type=(t)
set_type( t )
end
def == other
self.object_id == other.object_id
@ -34,38 +37,39 @@ module Parfait
# private
def set_type(typ)
raise "not type" + typ.class.to_s + "in " + object_id.to_s(16) unless typ.is_a?(Type)
self.type = typ
@type = typ
end
# so we can keep the raise in get_type
def has_type?
! type.nil?
! @type.nil?
end
def get_type()
raise "No type " + self.object_id.to_s(16) + ":" + self.class.name unless has_type?
type
@type
end
def get_instance_variables
type.names
@type.names
end
def get_instance_variable( name )
index = instance_variable_defined(name)
#puts "getting #{name} at #{index}"
#raise "at :#{name}:" if name.to_s[0] == "@"
return nil if index == nil
return get_internal_word(index)
end
def set_instance_variable( name , value )
index = instance_variable_defined(name)
#puts "setting #{name} at #{index}"
return nil if index == nil
return set_internal_word(index , value)
end
def instance_variable_defined( name )
type.variable_index(name)
@type.variable_index(name)
end
# objects only come in lengths of multiple of 8 words / 32 bytes
@ -81,7 +85,7 @@ module Parfait
end
def padded_length
Object.padded_words( type.instance_length )
Object.padded_words( @type.instance_length )
end
# parfait versions are deliberately called different, so we "relay"