equivalent transformation, just looks

This commit is contained in:
Torsten Ruger 2014-08-27 17:23:50 +03:00
parent fc9615a649
commit aad3f7ca15

View File

@ -24,9 +24,26 @@ module Register
puts "leng #{@stream.length}" puts "leng #{@stream.length}"
end end
def link_object(object , at)
slot = @objects[object.object_id]
unless slot
slot = LinkSlot.new at
@objects[object.object_id] = slot
end
if object.is_a? Instruction
total_length = 4
else
clazz = object.class.name.split("::").last
object_length = 0 #link_self(object , at)
total_length = object_length + send("link_#{clazz}".to_sym , object , at + object_length)
end
slot.length = total_length
total_length
end
def assemble_object object def assemble_object object
slot = @objects[object.object_id] slot = @objects[object.object_id]
raise "No slot for #{object_id}" unless slot raise "Object not linked #{object_id}" unless slot
if object.is_a? Instruction if object.is_a? Instruction
object.assemble( @stream , self ) object.assemble( @stream , self )
else else
@ -35,31 +52,17 @@ module Register
end end
end end
def link_object(object , at) def link_Array( array , at)
slot = @objects[object.object_id] length = 0
unless slot array.each do |elem|
slot = LinkSlot.new at length += link_object(elem , at + length)
@objects[object.object_id] = slot
end end
if object.is_a? Instruction length
len = 4
else
clazz = object.class.name.split("::").last
len = send("link_#{clazz}".to_sym , object , at)
end
slot.length = len
len
end end
def link_BootSpace(space , at) def link_BootSpace(space , at)
len = 0 length = link_Array( space.classes.values , at )
space.classes.values.each do |cl| length + link_Array(space.objects , at + length)
len += link_object(cl , at + len)
end
space.objects.each do |o|
len += link_object(o , at + len)
end
len
end end
def assemble_BootSpace(space) def assemble_BootSpace(space)
@ -73,12 +76,9 @@ module Register
end end
def link_BootClass(clazz , at) def link_BootClass(clazz , at)
len = link_object(clazz.name , at) length = link_object(clazz.name , at)
len += link_object(clazz.super_class_name , at + len) length += link_object(clazz.super_class_name , at + length)
clazz.instance_methods.each do |meth| length + link_Array(clazz.instance_methods , at + length)
len += link_object(meth , at + len)
end
len
end end
def assemble_BootClass(clazz) def assemble_BootClass(clazz)
@ -90,11 +90,8 @@ module Register
end end
def link_MethodDefinition(method , at) def link_MethodDefinition(method , at)
len = link_object method.name ,at length = link_object(method.name ,at)
method.blocks.each do |block| length + link_Array(method.blocks ,at + length)
len += link_object( block , at + len)
end
len
end end
def assemble_MethodDefinition(method) def assemble_MethodDefinition(method)