2014-09-16 15:06:56 +02:00
|
|
|
require_relative "type"
|
|
|
|
|
2014-06-26 17:39:02 +02:00
|
|
|
module Virtual
|
|
|
|
# our machine is made up of objects, some of which are code, some data
|
|
|
|
#
|
|
|
|
# during compilation objects are module Virtual objects, but during execution they are not scoped
|
|
|
|
#
|
2014-08-28 07:24:37 +02:00
|
|
|
# So compiling/linking/assembly turns ::virtual objects into binary that represents ruby objects at runtime
|
|
|
|
# The equivalence is listed below (i'll try and work on clearer correspondence later)
|
|
|
|
# ::Virtual Runtime / parfait
|
|
|
|
# Object Object
|
|
|
|
# BootClass Class
|
|
|
|
# MetaClass self/Object
|
|
|
|
# BootSpace ObjectSpace
|
|
|
|
# CompiledMethod Function
|
|
|
|
# (ruby)Array Array
|
|
|
|
# String String
|
2014-06-26 17:39:02 +02:00
|
|
|
class Object
|
2014-09-16 15:06:56 +02:00
|
|
|
def initialize
|
|
|
|
@position = -1
|
|
|
|
@length = -1
|
2014-06-26 17:39:02 +02:00
|
|
|
end
|
2014-09-16 15:06:56 +02:00
|
|
|
attr_accessor :position , :length , :layout
|
|
|
|
def position
|
|
|
|
raise "position accessed but not set at #{length} for #{self.objekt}" if @position == -1
|
|
|
|
@position
|
|
|
|
end
|
|
|
|
|
2014-07-14 10:29:38 +02:00
|
|
|
def inspect
|
2014-08-22 09:21:12 +02:00
|
|
|
Sof::Writer.write(self)
|
2014-07-14 10:29:38 +02:00
|
|
|
end
|
2014-09-16 15:06:56 +02:00
|
|
|
|
|
|
|
@@EMPTY = { :names => [] , :types => []}
|
|
|
|
def layout
|
|
|
|
raise "Find me #{self}"
|
|
|
|
self.class.layout
|
|
|
|
end
|
|
|
|
def self.layout
|
|
|
|
@@EMPTY
|
|
|
|
end
|
|
|
|
# class variables to have _identical_ objects passed back (stops recursion)
|
|
|
|
@@ARRAY = { :names => [] , :types => []}
|
|
|
|
# @@HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]}
|
|
|
|
# @@CLAZZ = { :names => [:name , :super_class_name , :instance_methods] , :types => [Virtual::Reference,Virtual::Reference,Virtual::Reference]}
|
|
|
|
# @@SPACE = { :names => [:classes,:objects] , :types => [Virtual::Reference,Virtual::Reference]}
|
|
|
|
|
|
|
|
def layout_for(object)
|
|
|
|
case object
|
|
|
|
when Array , Symbol , String , Virtual::CompiledMethod , Virtual::Block , Virtual::StringConstant
|
|
|
|
@@ARRAY
|
|
|
|
when Hash
|
|
|
|
@@HASH.merge :keys => object.keys , :values => object.values
|
|
|
|
when Virtual::BootClass
|
|
|
|
@@CLAZZ
|
|
|
|
when Virtual::BootSpace
|
|
|
|
@@SPACE
|
|
|
|
else
|
|
|
|
raise "linker encounters unknown class #{object.class}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Parfait::Hash.class_eval do
|
|
|
|
@@HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]}
|
|
|
|
def layout
|
|
|
|
@@HASH
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Array.class_eval do
|
|
|
|
def layout
|
|
|
|
Virtual::Object.layout
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Symbol.class_eval do
|
|
|
|
def layout
|
|
|
|
Virtual::Object.layout
|
2014-06-26 17:39:02 +02:00
|
|
|
end
|
|
|
|
end
|