From f8688cbe1773fa3bcbe5435b5a2eaa60e1d2a736 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 8 Jun 2015 12:19:53 +0200 Subject: [PATCH] it actually assembles again --- lib/elf/object_writer.rb | 4 ++-- lib/register/assembler.rb | 21 ++++++++++++++++++--- lib/virtual/parfait_adapter.rb | 4 +++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index c0958758..655794d9 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -22,9 +22,9 @@ module Elf set_text assembler.assemble # for debug add labels to the block positions - space.classes.values.each do |clazz| + @object_machine.space.classes.values.each do |clazz| clazz.instance_methods.each do |f| - f.blocks.each do |b| + f.info.blocks.each do |b| add_symbol "#{clazz.name}::#{f.name}@#{b.name}" , b.position end end diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index b517296e..980414c1 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -157,11 +157,20 @@ module Register end puts "layout length=#{layout.get_length.to_s(16)} mem_len=#{layout.word_length.to_s(16)}" l = layout.get_length + if( object.is_a? Parfait::List) + object.each do |inst| + write_ref_for(inst) + end + l += object.get_length + end pad_after( l * 4) object.position end def assemble_List array + assemble_object array + return + type = type_word(array) @stream.write_uint32( type ) write_ref_for(array.layout[:names]) #ref @@ -177,7 +186,7 @@ module Register end def assemble_Dictionary hash # so here we can be sure to have _identical_ keys/values arrays - assemble_object( hash , [ hash.keys , hash.values ] ) + assemble_object( hash ) end def assemble_Space(space) @@ -196,7 +205,8 @@ module Register end def assemble_Method(method) - raise "no" + assemble_object(method) + return count = method.info.blocks.inject(0) { |c , block| c += block.word_length } word = (count+7) / 32 # all object are multiple of 8 words (7 for header) raise "Method too long, splitting not implemented #{method.name}/#{count}" if word > 15 @@ -245,7 +255,12 @@ module Register # write means we write the resulting address straight into the assembler stream # object means the object of which we write the address def write_ref_for object - @stream.write_sint32 object.position + if object.nil? + pos = 0 + else + pos = object.position + end + @stream.write_sint32 pos end # pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary diff --git a/lib/virtual/parfait_adapter.rb b/lib/virtual/parfait_adapter.rb index 67e7c86e..642d572f 100644 --- a/lib/virtual/parfait_adapter.rb +++ b/lib/virtual/parfait_adapter.rb @@ -37,6 +37,8 @@ module Virtual end class Symbol include Positioned + include Padding + def init_layout; end def has_layout? true @@ -45,7 +47,7 @@ class Symbol Virtual.machine.class_mappings[:Word].object_layout end def word_length - to_s.length + padded to_s.length end # not the prettiest addition to the game, but it wasn't me who decided symbols are frozen in 2.x def cache_positions