fix assembly (at least lositions and padding)
This commit is contained in:
parent
197ecd576e
commit
bfa3f28e97
@ -31,7 +31,7 @@ module Elf
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
assembler.objects.values.each do |slot|
|
assembler.objects.values.each do |slot|
|
||||||
add_symbol "#{slot.object.class.name}::#{(4*slot.position).to_s(16)}" , slot.position * 4
|
add_symbol "#{slot.objekt.class.name}::#{(4*slot.position).to_s(16)}" , slot.position * 4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
attr_reader :text
|
attr_reader :text
|
||||||
|
@ -4,12 +4,12 @@ module Register
|
|||||||
def initialize o
|
def initialize o
|
||||||
@position = -1
|
@position = -1
|
||||||
@length = -1
|
@length = -1
|
||||||
@object = o
|
@objekt = o
|
||||||
end
|
end
|
||||||
attr_reader :object
|
attr_reader :objekt
|
||||||
attr_accessor :position , :length , :layout
|
attr_accessor :position , :length , :layout
|
||||||
def position
|
def position
|
||||||
raise "position accessed but not set at #{length} for #{self.object}" if @position == -1
|
raise "position accessed but not set at #{length} for #{self.objekt}" if @position == -1
|
||||||
@position
|
@position
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -32,13 +32,13 @@ module Register
|
|||||||
collect_object(@space)
|
collect_object(@space)
|
||||||
at = 0
|
at = 0
|
||||||
@objects.each do |id , slot|
|
@objects.each do |id , slot|
|
||||||
next unless slot.object.is_a? Virtual::CompiledMethod
|
next unless slot.objekt.is_a? Virtual::CompiledMethod
|
||||||
slot.position = at
|
slot.position = at
|
||||||
slot.object.set_position at
|
slot.objekt.set_position at
|
||||||
at += slot.length
|
at += slot.length
|
||||||
end
|
end
|
||||||
@objects.each do |id , slot|
|
@objects.each do |id , slot|
|
||||||
next if slot.object.is_a? Virtual::CompiledMethod
|
next if slot.objekt.is_a? Virtual::CompiledMethod
|
||||||
slot.position = at
|
slot.position = at
|
||||||
at += slot.length
|
at += slot.length
|
||||||
end
|
end
|
||||||
@ -48,12 +48,12 @@ module Register
|
|||||||
link
|
link
|
||||||
@stream = StringIO.new
|
@stream = StringIO.new
|
||||||
@objects.each do |id , slot|
|
@objects.each do |id , slot|
|
||||||
next unless slot.object.is_a? Virtual::CompiledMethod
|
next unless slot.objekt.is_a? Virtual::CompiledMethod
|
||||||
assemble_object( slot.object )
|
assemble_object( slot )
|
||||||
end
|
end
|
||||||
@objects.each do |id , slot|
|
@objects.each do |id , slot|
|
||||||
next if slot.object.is_a? Virtual::CompiledMethod
|
next if slot.objekt.is_a? Virtual::CompiledMethod
|
||||||
assemble_object( slot.object )
|
assemble_object( slot )
|
||||||
end
|
end
|
||||||
puts "Assembled #{@stream.length.to_s(16)}"
|
puts "Assembled #{@stream.length.to_s(16)}"
|
||||||
return @stream.string
|
return @stream.string
|
||||||
@ -70,12 +70,11 @@ module Register
|
|||||||
slot.length = send("collect_#{clazz}".to_sym , object)
|
slot.length = send("collect_#{clazz}".to_sym , object)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble_object object
|
def assemble_object slot
|
||||||
slot = get_slot(object)
|
obj = slot.objekt
|
||||||
raise "Object not linked #{object_id}=>#{object.class}, #{object.inspect}" unless slot
|
puts "Assemble #{obj.class}(#{obj.object_id}) at stream #{(@stream.length).to_s(16)} pos:#{(4*slot.position).to_s(16)} , len:#{slot.length}"
|
||||||
puts "Assemble #{slot.object.class} at stream #{(@stream.length).to_s(16)} pos:#{(4*slot.position).to_s(16)} , len:#{slot.length}"
|
raise "Assemble #{obj.class} at #{(@stream.length).to_s(16)} #{(4*slot.position).to_s(16)}" if @stream.length != slot.position*4
|
||||||
raise "Assemble #{slot.object.class} at #{(@stream.length).to_s(16)} #{(4*slot.position).to_s(16)}" if @stream.length != slot.position*4
|
clazz = obj.class.name.split("::").last
|
||||||
clazz = object.class.name.split("::").last
|
|
||||||
send("assemble_#{clazz}".to_sym , slot)
|
send("assemble_#{clazz}".to_sym , slot)
|
||||||
slot.position
|
slot.position
|
||||||
end
|
end
|
||||||
@ -84,7 +83,7 @@ module Register
|
|||||||
# variables ar values, ie int or refs. For refs the object needs to save the object first
|
# variables ar values, ie int or refs. For refs the object needs to save the object first
|
||||||
def assemble_self( object , variables )
|
def assemble_self( object , variables )
|
||||||
slot = get_slot(object)
|
slot = get_slot(object)
|
||||||
raise "Object not linked #{object.inspect}" unless slot
|
raise "Object(#{object.object_id}) not linked #{object.inspect}" unless slot
|
||||||
layout = slot.layout
|
layout = slot.layout
|
||||||
@stream.write_uint32( 0 ) #TODO types
|
@stream.write_uint32( 0 ) #TODO types
|
||||||
write_ref(layout[:names])
|
write_ref(layout[:names])
|
||||||
@ -104,7 +103,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assemble_Array slot
|
def assemble_Array slot
|
||||||
array = slot.object
|
array = slot.objekt
|
||||||
layout = slot.layout
|
layout = slot.layout
|
||||||
@stream.write_uint32( 0 ) #TODO types
|
@stream.write_uint32( 0 ) #TODO types
|
||||||
write_ref layout[:names] #ref
|
write_ref layout[:names] #ref
|
||||||
@ -125,7 +124,7 @@ module Register
|
|||||||
|
|
||||||
def assemble_Hash slot
|
def assemble_Hash slot
|
||||||
# so here we can be sure to have _identical_ keys/values arrays
|
# so here we can be sure to have _identical_ keys/values arrays
|
||||||
assemble_self( slot.object , [ slot.layout[:keys] , slot.layout[:values] ] )
|
assemble_self( slot.objekt , [ slot.layout[:keys] , slot.layout[:values] ] )
|
||||||
end
|
end
|
||||||
|
|
||||||
def collect_BootSpace(space)
|
def collect_BootSpace(space)
|
||||||
@ -135,7 +134,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assemble_BootSpace(slot)
|
def assemble_BootSpace(slot)
|
||||||
space = slot.object
|
space = slot.objekt
|
||||||
assemble_self(space , [space.classes,space.objects] )
|
assemble_self(space , [space.classes,space.objects] )
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -147,7 +146,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assemble_BootClass(slot)
|
def assemble_BootClass(slot)
|
||||||
clazz = slot.object
|
clazz = slot.objekt
|
||||||
assemble_self( clazz , [clazz.name , clazz.super_class_name, clazz.instance_methods] )
|
assemble_self( clazz , [clazz.name , clazz.super_class_name, clazz.instance_methods] )
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -159,7 +158,7 @@ module Register
|
|||||||
|
|
||||||
|
|
||||||
def assemble_CompiledMethod(slot)
|
def assemble_CompiledMethod(slot)
|
||||||
method = slot.object
|
method = slot.objekt
|
||||||
@stream.write_uint32( 0 ) #TODO types
|
@stream.write_uint32( 0 ) #TODO types
|
||||||
write_ref(slot.layout[:names]) #ref of layout
|
write_ref(slot.layout[:names]) #ref of layout
|
||||||
# TODO the assembly may have to move to the object to be more extensible
|
# TODO the assembly may have to move to the object to be more extensible
|
||||||
@ -186,18 +185,18 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assemble_String( slot )
|
def assemble_String( slot )
|
||||||
str = slot.object
|
str = slot.objekt
|
||||||
str = str.string if str.is_a? Virtual::StringConstant
|
str = str.string if str.is_a? Virtual::StringConstant
|
||||||
str = str.to_s if str.is_a? Symbol
|
str = str.to_s if str.is_a? Symbol
|
||||||
layout = slot.layout
|
layout = slot.layout
|
||||||
@stream.write_uint32( 0 ) #TODO types
|
@stream.write_uint32( 0 ) #TODO types
|
||||||
@stream.write_uint32( assemble_object(layout[:names]) ) #ref
|
write_ref( slot.layout[:names] ) #ref
|
||||||
@stream.write str
|
@stream.write str
|
||||||
pad = slot.length - 8 - str.length
|
pad = (slot.length*4) - 8 - str.length
|
||||||
pad.times do
|
pad.times do
|
||||||
@stream.write_uint8(0)
|
@stream.write_uint8(0)
|
||||||
end
|
end
|
||||||
puts "String stream #{@stream.length}"
|
#puts "String (#{slot.length}) stream #{@stream.length.to_s(16)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble_Symbol(sym)
|
def assemble_Symbol(sym)
|
||||||
@ -214,13 +213,13 @@ module Register
|
|||||||
return slot if slot
|
return slot if slot
|
||||||
if(object.is_a? Array)
|
if(object.is_a? Array)
|
||||||
@objects.each do |k,slot|
|
@objects.each do |k,slot|
|
||||||
next unless slot.object.is_a? Array
|
next unless slot.objekt.is_a? Array
|
||||||
if(slot.object.length == object.length)
|
if(slot.objekt.length == object.length)
|
||||||
same = true
|
same = true
|
||||||
slot.object.each_with_index do |v,index|
|
slot.objekt.each_with_index do |v,index|
|
||||||
same = false unless v == object[index]
|
same = false unless v == object[index]
|
||||||
end
|
end
|
||||||
puts slot.object.first.class if same
|
puts slot.objekt.first.class if same
|
||||||
return slot if same
|
return slot if same
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -230,7 +229,7 @@ module Register
|
|||||||
|
|
||||||
def write_ref object
|
def write_ref object
|
||||||
slot = get_slot(object)
|
slot = get_slot(object)
|
||||||
raise "Object not linked #{object.inspect}" unless slot
|
raise "Object (#{object.object_id}) not linked #{object.inspect}" unless slot
|
||||||
@stream.write_uint32 slot.position
|
@stream.write_uint32 slot.position
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user