simplify writing binary

loop as should be, fixes the problem (one problem at least)
This commit is contained in:
Torsten Ruger 2018-05-13 18:01:45 +03:00
parent 866467ee5e
commit 4856b9891d
4 changed files with 18 additions and 11 deletions

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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