diff --git a/lib/parfait/typed_method.rb b/lib/parfait/typed_method.rb index 6b17962e..5ba0f9c8 100644 --- a/lib/parfait/typed_method.rb +++ b/lib/parfait/typed_method.rb @@ -117,6 +117,13 @@ module Parfait "#{@for_type.object_class.name}:#{name}(#{arguments_type.inspect})" end + def each_binary( &block ) + bin = binary + while(bin) do + block.call( bin ) + bin = bin.next + end + end def each_method( &block ) block.call( self ) next_method.each_method( &block ) if next_method diff --git a/lib/risc/text_writer.rb b/lib/risc/text_writer.rb index da84df5e..dda7cd30 100644 --- a/lib/risc/text_writer.rb +++ b/lib/risc/text_writer.rb @@ -53,6 +53,7 @@ module Risc def write_objects sorted_objects.each do |objekt| next if objekt.is_a? Risc::Label # ignore + next if objekt.is_a? Parfait::BinaryCode # ignore write_any( objekt ) end end @@ -60,12 +61,11 @@ module Risc # Write the BinaryCode objects of all methods to stream. # Really like any other object, it's just about the ordering def write_code - @machine.objects.each do |id, method| - next unless method.is_a? Parfait::TypedMethod - binary = method.binary - while(binary) do - write_any( binary ) - binary = binary.next + Parfait.object_space.each_type do |type| + type.each_method do |method| + method.each_binary do |code| + write_any(code) + end end end end @@ -73,8 +73,8 @@ module Risc # Write any object just logs a bit and passes to write_any_out def write_any( obj ) write_any_log( obj , "Write") - if @stream.length != Position.get(obj).at - #puts "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not #{Position.get(obj)}" + if stream_position != Position.get(obj).at + raise "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not #{Position.get(obj)}" end write_any_out(obj) write_any_log( obj , "Wrote") diff --git a/test/risc/test_machine.rb b/test/risc/test_machine.rb index fdd79fe8..f8c2e127 100644 --- a/test/risc/test_machine.rb +++ b/test/risc/test_machine.rb @@ -39,10 +39,10 @@ module Risc assert_equal 0 , Position.get(@machine.cpu_init).at end def test_cpu_at - assert_equal "0x5ad0" , Position.get(@machine.cpu_init.first).to_s + assert_equal "0x5ad8" , Position.get(@machine.cpu_init.first).to_s end def test_cpu_bin - assert_equal "0x5ac4" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s + assert_equal "0x5acc" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s end def test_cpu_label assert_equal Position::InstructionPosition , Position.get(@machine.cpu_init.first).class diff --git a/test/risc/test_text_writer.rb b/test/risc/test_text_writer.rb index 1c5c36bb..c77700b5 100644 --- a/test/risc/test_text_writer.rb +++ b/test/risc/test_text_writer.rb @@ -30,6 +30,7 @@ module Risc def test_sorted_positions1 sorted_objects = @text_writer.sorted_objects sorted_objects.each_slice(2) do |l,r| + next unless r assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.class}, #{r.class}" end end @@ -37,7 +38,6 @@ module Risc sorted_objects = @text_writer.sorted_objects sorted_objects.shift sorted_objects.each_slice(2) do |l,r| - next unless l next unless r assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.class}, #{r.class}" end