adding legth of object itself
This commit is contained in:
parent
a71f55f661
commit
e09d3c2f65
@ -22,19 +22,13 @@ module Register
|
|||||||
@objects[object.object_id] = slot
|
@objects[object.object_id] = slot
|
||||||
end
|
end
|
||||||
if object.is_a? Instruction
|
if object.is_a? Instruction
|
||||||
total_length = 4
|
length = 4
|
||||||
else
|
else
|
||||||
clazz = object.class.name.split("::").last
|
clazz = object.class.name.split("::").last
|
||||||
object_length = link_self(object , at)
|
length = send("link_#{clazz}".to_sym , object , at)
|
||||||
total_length = object_length + send("link_#{clazz}".to_sym , object , at + object_length)
|
|
||||||
end
|
end
|
||||||
slot.length = total_length
|
slot.length = length
|
||||||
total_length
|
length
|
||||||
end
|
|
||||||
|
|
||||||
def link_self(object , at)
|
|
||||||
puts "Object #{object.class}"
|
|
||||||
0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_Array( array , at)
|
def link_Array( array , at)
|
||||||
@ -42,24 +36,31 @@ module Register
|
|||||||
array.each do |elem|
|
array.each do |elem|
|
||||||
length += link_object(elem , at + length)
|
length += link_object(elem , at + length)
|
||||||
end
|
end
|
||||||
length
|
# also array has constant overhead, the members helper fixes it to multiple of 8
|
||||||
|
members(length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_BootSpace(space , at)
|
def link_BootSpace(space , at)
|
||||||
length = link_Array( space.classes.values , at )
|
length = members( 2 )
|
||||||
|
length += link_Array( space.classes.values , at + length )
|
||||||
length + link_Array(space.objects , at + length)
|
length + link_Array(space.objects , at + length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_BootClass(clazz , at)
|
def link_BootClass(clazz , at)
|
||||||
length = link_object(clazz.name , at)
|
length = members(3)
|
||||||
|
length += link_object(clazz.name , at + length)
|
||||||
length += link_object(clazz.super_class_name , at + length)
|
length += link_object(clazz.super_class_name , at + length)
|
||||||
length + link_Array(clazz.instance_methods , at + length)
|
length + link_Array(clazz.instance_methods , at + length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_MethodDefinition(method , at)
|
def link_MethodDefinition(method , at)
|
||||||
length = link_object(method.name ,at)
|
length = members(2)
|
||||||
# NOT an ARRAY
|
length += link_object(method.name ,at + length)
|
||||||
length + link_Array(method.blocks ,at + length)
|
# NOT an ARRAY, just a bag of bytes
|
||||||
|
method.blocks.each do |block|
|
||||||
|
length += link_object( block ,at + length)
|
||||||
|
end
|
||||||
|
length
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_Block(block , at)
|
def link_Block(block , at)
|
||||||
@ -83,5 +84,13 @@ module Register
|
|||||||
return link_String(sc.string,at)
|
return link_String(sc.string,at)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# objects only come in lengths of multiple of 8
|
||||||
|
# but there is a constant overhead of 2, one for type, one for layout
|
||||||
|
# and as we would have to subtract 1 to make it work without overhead, we now have to add 1
|
||||||
|
def members len
|
||||||
|
8 * (1 + (len + 1) / 8)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user