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
|
class LinkSlot
|
||||||
def initialize at
|
def initialize at
|
||||||
@position = position
|
@position = position
|
||||||
|
@length = 0
|
||||||
end
|
end
|
||||||
attr_accessor :position
|
attr_accessor :position , :length
|
||||||
end
|
end
|
||||||
class Assembler
|
class Assembler
|
||||||
|
|
||||||
@ -12,49 +13,68 @@ module Register
|
|||||||
@objects = {}
|
@objects = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def link at = 0
|
def link
|
||||||
link_object @space , at
|
link_object(@space , 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_object object , at
|
def link_object(object , at)
|
||||||
slot = @objects[object.object_id]
|
slot = @objects[object.object_id]
|
||||||
unless slot
|
unless slot
|
||||||
slot = LinkSlot.new at
|
slot = LinkSlot.new at
|
||||||
@objects[object.object_id] = slot
|
@objects[object.object_id] = slot
|
||||||
end
|
end
|
||||||
# return if object.is_a? Instruction
|
if object.is_a? Instruction
|
||||||
clazz = object.class.name.split("::").last
|
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
|
end
|
||||||
|
|
||||||
def link_BootSpace space , at
|
def link_BootSpace(space , at)
|
||||||
|
len = 0
|
||||||
space.classes.values.each do |cl|
|
space.classes.values.each do |cl|
|
||||||
link_object cl , at
|
len += link_object(cl , at + len)
|
||||||
end
|
end
|
||||||
|
len
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_BootClass clazz , at
|
def link_BootClass(clazz , at)
|
||||||
link_object clazz.name , at
|
len = link_object(clazz.name , at)
|
||||||
link_object clazz.super_class_name , at
|
len += link_object(clazz.super_class_name , at + len)
|
||||||
clazz.instance_methods.each do |meth|
|
clazz.instance_methods.each do |meth|
|
||||||
link_object meth , at
|
len += link_object(meth , at + len)
|
||||||
end
|
end
|
||||||
|
len
|
||||||
end
|
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|
|
method.blocks.each do |block|
|
||||||
link_object block , at
|
link_object( block , at + len)
|
||||||
end
|
end
|
||||||
|
len
|
||||||
end
|
end
|
||||||
def link_Block block , at
|
|
||||||
|
def link_Block(block , at)
|
||||||
|
len = 0
|
||||||
block.codes.each do |code|
|
block.codes.each do |code|
|
||||||
link_object code , at
|
len += link_object(code , at + len)
|
||||||
end
|
end
|
||||||
|
len
|
||||||
end
|
end
|
||||||
def link_String str , at
|
|
||||||
|
def link_String( str , at)
|
||||||
|
return (str.length / 4) + 1 + 2
|
||||||
end
|
end
|
||||||
def link_Symbol sym , at
|
|
||||||
|
def link_Symbol(sym , at)
|
||||||
|
return link_String(sym.to_s , at)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Sof::Volotile.add(Register::Assembler , [:objects])
|
Sof::Volotile.add(Register::Assembler , [:objects])
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user