2015-04-08 19:24:50 +02:00
|
|
|
# to be precise, this should be an ObjectReference, as the Reference is a Value
|
|
|
|
# but we don't want to make that distinction all the time , so we don't.
|
2014-08-05 14:55:24 +02:00
|
|
|
|
2015-05-11 17:55:49 +02:00
|
|
|
# that does lead to the fact that we have Reference functions on the Object though
|
2014-08-05 14:55:24 +02:00
|
|
|
|
2015-05-17 13:40:02 +02:00
|
|
|
# Objects are arranged or layed out (in memory) according to their Layout
|
|
|
|
# every object has a Layout. Layout objects are immutalbe and may be resued for a group/class
|
|
|
|
# off objects.
|
|
|
|
# The Layout of an object may change, but then a new Layout is created
|
|
|
|
# The Layout also defines the class of the object
|
|
|
|
# The Layout is **always** the first entry (index 1) in an object, but the type word is index 0
|
|
|
|
|
2015-05-11 17:55:49 +02:00
|
|
|
module Parfait
|
|
|
|
class Object < Value
|
2015-04-08 19:24:50 +02:00
|
|
|
|
2015-05-17 13:40:02 +02:00
|
|
|
TYPE_WORD = 0
|
|
|
|
LAYOUT_INDEX = 1
|
|
|
|
CLASS_INDEX = 2 #only used in class, but keep constants together
|
|
|
|
|
2015-05-18 11:35:01 +02:00
|
|
|
def self.new_object *args
|
|
|
|
object = self.new(*args)
|
2015-05-20 16:29:08 +02:00
|
|
|
#puts "NEW #{object.class}"
|
2015-05-18 11:35:01 +02:00
|
|
|
object
|
|
|
|
end
|
|
|
|
|
2015-06-03 09:01:59 +02:00
|
|
|
def == other
|
|
|
|
self.object_id == other.object_id
|
|
|
|
end
|
|
|
|
|
2015-05-17 13:40:02 +02:00
|
|
|
def get_type_of( index )
|
|
|
|
type_word = internal_object_get( TYPE_WORD )
|
|
|
|
res = type_word >> (index*4)
|
2015-05-18 11:35:01 +02:00
|
|
|
# least significant nibble, this is still adhoc, not tested. but the idea is there
|
2015-05-17 13:40:02 +02:00
|
|
|
res & 0xF
|
2015-05-11 17:55:49 +02:00
|
|
|
end
|
2015-04-08 19:24:50 +02:00
|
|
|
|
2015-05-11 17:55:49 +02:00
|
|
|
# This is the crux of the object system. The class of an object is stored in the objects
|
|
|
|
# memory (as opposed to an integer that has no memory and so always has the same class)
|
|
|
|
#
|
|
|
|
# In Salama we store the class in the Layout, and so the Layout is the only fixed
|
|
|
|
# data that every object carries.
|
|
|
|
def get_class()
|
2015-05-16 11:53:10 +02:00
|
|
|
l = get_layout()
|
2015-05-22 21:51:36 +02:00
|
|
|
puts "Layout #{l.class} in #{self.class} , #{self}"
|
2015-05-16 11:53:10 +02:00
|
|
|
l.get_object_class()
|
2015-05-11 17:55:49 +02:00
|
|
|
end
|
2015-04-08 19:24:50 +02:00
|
|
|
|
2015-05-22 21:51:36 +02:00
|
|
|
# private
|
|
|
|
def set_layout(layout)
|
2015-05-31 10:07:49 +02:00
|
|
|
#if( was = internal_object_get(LAYOUT_INDEX) )
|
2015-05-30 10:55:46 +02:00
|
|
|
#TODO find out wat these objects are
|
2015-05-31 10:07:49 +02:00
|
|
|
#puts "Layout was set for #{self.class}"
|
|
|
|
#puts "#{self}" if self.class == Parfait::Word
|
|
|
|
# Space.object_space.check was
|
|
|
|
# return
|
|
|
|
#end
|
|
|
|
raise "Nil layout" unless layout
|
2015-05-22 21:51:36 +02:00
|
|
|
internal_object_set(LAYOUT_INDEX , layout)
|
|
|
|
end
|
|
|
|
|
2015-05-31 12:02:29 +02:00
|
|
|
# so we can keep the raise in get_layout
|
|
|
|
def has_layout?
|
|
|
|
! internal_object_get(LAYOUT_INDEX).nil?
|
|
|
|
end
|
|
|
|
|
2015-05-16 11:53:10 +02:00
|
|
|
def get_layout()
|
2015-05-25 17:48:35 +02:00
|
|
|
l = internal_object_get(LAYOUT_INDEX)
|
2015-06-22 21:48:42 +02:00
|
|
|
raise "No layout #{self.to_s}:#{self.class} #{self.object_id}" unless l
|
2015-05-25 17:48:35 +02:00
|
|
|
return l
|
2015-05-16 11:53:10 +02:00
|
|
|
end
|
|
|
|
|
2015-05-20 09:57:20 +02:00
|
|
|
def get_instance_variables
|
|
|
|
get_layout().get_instance_variables
|
2015-05-14 18:53:56 +02:00
|
|
|
end
|
|
|
|
|
2015-05-20 09:57:20 +02:00
|
|
|
def get_instance_variable name
|
2015-05-14 18:53:56 +02:00
|
|
|
index = instance_variable_defined(name)
|
|
|
|
return nil if index == nil
|
|
|
|
return internal_get(index)
|
|
|
|
end
|
|
|
|
|
2015-05-20 09:57:20 +02:00
|
|
|
def set_instance_variable name , value
|
2015-05-14 18:53:56 +02:00
|
|
|
index = instance_variable_defined(name)
|
|
|
|
return nil if index == nil
|
|
|
|
return internal_set(index , value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def instance_variable_defined name
|
2015-05-24 15:55:03 +02:00
|
|
|
get_layout().index_of(name)
|
2015-05-14 18:53:56 +02:00
|
|
|
end
|
|
|
|
|
2015-06-05 08:20:43 +02:00
|
|
|
def word_length
|
2015-06-06 18:46:53 +02:00
|
|
|
padded_words( get_layout().get_length() )
|
2015-05-24 17:05:20 +02:00
|
|
|
end
|
|
|
|
|
2015-05-11 17:55:49 +02:00
|
|
|
# Object
|
|
|
|
# :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint,
|
|
|
|
# :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods,
|
2015-05-20 09:57:20 +02:00
|
|
|
# :private_methods, :public_methods, :get_instance_variables, :get_instance_variable, :set_instance_variable, :instance_variable_defined?,
|
2015-05-11 17:55:49 +02:00
|
|
|
# :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?,
|
|
|
|
# :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method,
|
|
|
|
# :object_id, :to_enum, :enum_for
|
|
|
|
#
|
|
|
|
# BasicObject
|
|
|
|
# :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__
|
|
|
|
end
|
2014-07-30 20:43:12 +02:00
|
|
|
end
|