fold old link and length into one function
This commit is contained in:
parent
1379b4ea4e
commit
8f9bbe2f1d
@ -2,8 +2,9 @@ module Register
|
||||
class LinkSlot
|
||||
def initialize at
|
||||
@position = position
|
||||
@length = 0
|
||||
end
|
||||
attr_accessor :position
|
||||
attr_accessor :position , :length
|
||||
end
|
||||
class Assembler
|
||||
|
||||
@ -12,49 +13,68 @@ module Register
|
||||
@objects = {}
|
||||
end
|
||||
|
||||
def link at = 0
|
||||
link_object @space , at
|
||||
def link
|
||||
link_object(@space , 0)
|
||||
end
|
||||
|
||||
def link_object object , at
|
||||
def link_object(object , at)
|
||||
slot = @objects[object.object_id]
|
||||
unless slot
|
||||
slot = LinkSlot.new at
|
||||
@objects[object.object_id] = slot
|
||||
end
|
||||
# return if object.is_a? Instruction
|
||||
if object.is_a? Instruction
|
||||
clazz = object.class.name.split("::").last
|
||||
send("link_#{clazz}".to_sym , object , at)
|
||||
len = send("link_#{clazz}".to_sym , object , at)
|
||||
else
|
||||
len = 4
|
||||
end
|
||||
slot.length = len
|
||||
len
|
||||
end
|
||||
|
||||
def link_BootSpace space , at
|
||||
def link_BootSpace(space , at)
|
||||
len = 0
|
||||
space.classes.values.each do |cl|
|
||||
link_object cl , at
|
||||
len += link_object(cl , at + len)
|
||||
end
|
||||
len
|
||||
end
|
||||
|
||||
def link_BootClass clazz , at
|
||||
link_object clazz.name , at
|
||||
link_object clazz.super_class_name , at
|
||||
def link_BootClass(clazz , at)
|
||||
len = link_object(clazz.name , at)
|
||||
len += link_object(clazz.super_class_name , at + len)
|
||||
clazz.instance_methods.each do |meth|
|
||||
link_object meth , at
|
||||
len += link_object(meth , at + len)
|
||||
end
|
||||
len
|
||||
end
|
||||
def link_MethodDefinition method , at
|
||||
link_object method.name ,at
|
||||
|
||||
def link_MethodDefinition(method , at)
|
||||
len = link_object method.name ,at
|
||||
method.blocks.each do |block|
|
||||
link_object block , at
|
||||
link_object( block , at + len)
|
||||
end
|
||||
len
|
||||
end
|
||||
def link_Block block , at
|
||||
|
||||
def link_Block(block , at)
|
||||
len = 0
|
||||
block.codes.each do |code|
|
||||
link_object code , at
|
||||
len += link_object(code , at + len)
|
||||
end
|
||||
len
|
||||
end
|
||||
def link_String str , at
|
||||
|
||||
def link_String( str , at)
|
||||
return (str.length / 4) + 1 + 2
|
||||
end
|
||||
def link_Symbol sym , at
|
||||
|
||||
def link_Symbol(sym , at)
|
||||
return link_String(sym.to_s , at)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Sof::Volotile.add(Register::Assembler , [:objects])
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user