From 4f2f56fff88dfbc70fde49ff686b5b0b24253bb7 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 2 Jul 2015 13:49:33 +0300 Subject: [PATCH] minors --- lib/register/assembler.rb | 22 +++++++++++----------- test/parfait/test_space.rb | 5 +++-- test/virtual/test_hello.rb | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index 80b92f30..79f90860 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -39,7 +39,7 @@ module Register @machine.objects.each do |objekt| next unless objekt.is_a? Parfait::BinaryCode objekt.set_position at - # puts "CODE #{objekt.name} at #{objekt.position}" + #puts "CODE #{objekt.name} at #{objekt.position}" at += objekt.word_length end # and then everything else @@ -98,7 +98,7 @@ module Register next if objekt.is_a? Parfait::BinaryCode write_any( objekt ) end - puts "Assembled 0x#{stream_position.to_s(16)}/#{stream_position.to_s(16)} bytes" + puts "Assembled #{stream_position} bytes" return @stream.string end @@ -130,9 +130,9 @@ module Register end def write_any obj - #puts "Assemble #{obj.class}(#{obj.object_id.to_s(16)}) at stream #{stream_position.to_s(16)} pos:#{obj.position.to_s(16)} , len:#{obj.word_length.to_s(16)}" - if stream_position != obj.position - raise "Assemble #{obj.class} #{obj.object_id.to_s(16)} at #{stream_position.to_s(16)} not #{obj.position.to_s(16)}" + #puts "Assemble #{obj.class}(#{obj.object_id.to_s(16)}) at stream #{stream_position} pos:#{obj.position.to_s(16)} , len:#{obj.word_length.to_s(16)}" + if @stream.length != obj.position + raise "Assemble #{obj.class} #{obj.object_id.to_s(16)} at #{stream_position} not #{obj.position.to_s(16)}" end if obj.is_a?(Parfait::Word) or obj.is_a?(Symbol) write_String obj @@ -191,15 +191,14 @@ module Register str = string.to_string if string.is_a? Parfait::Word str = string.to_s if string.is_a? Symbol word = (str.length + 7) / 32 # all object are multiple of 8 words (7 for header) - raise "String too long (implement split string!) #{word}" if word > 15 # first line is integers, convention is that following lines are the same TYPE_LENGTH.times { word = ((word << TYPE_BITS) + TYPE_INT) } @stream.write_uint32( word ) - #puts "String is #{string} at #{string.position.to_s(16)} length #{string.length.to_s(16)}" + #puts "String is #{string} at #{string.position.to_s(16)} length #{string.length}" write_ref_for( string.get_layout ) #ref @stream.write str pad_after(str.length) - #puts "String (#{slot.word_length}) stream #{@stream.word_length.to_s(16)}" + #puts "String (#{string.length.to_s(16)}) stream #{@stream.length.to_s(16)}" end def write_Symbol(sym) @@ -221,17 +220,18 @@ module Register # pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary def pad_after length - before = stream_position.to_s(16) + before = stream_position pad = padding_for(length) pad.times do @stream.write_uint8(0) end - after = stream_position.to_s(16) + after = stream_position #puts "padded #{length.to_s(16)} with #{pad.to_s(16)} stream #{before}/#{after}" end + # return the stream length as hex def stream_position - @stream.length + @stream.length.to_s(16) end end diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index d1bf41e1..840dfc76 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -12,13 +12,14 @@ class TestSpace < MiniTest::Test def test_machine_space assert_equal Parfait::Space , @machine.space.class end - def test_gloabl_space + def test_global_space assert_equal Parfait::Space , Parfait::Space.object_space.class end def test_classes assert_equal 16 , @machine.space.classes.length [:Kernel,:Word,:List,:Message,:Frame,:Layout,:Class,:Dictionary,:Method].each do |name| - assert @machine.space.classes[name] + assert_equal Parfait::Class , @machine.space.classes[name].class + assert_equal Parfait::Layout , @machine.space.classes[name].get_layout.class end end def test_messages diff --git a/test/virtual/test_hello.rb b/test/virtual/test_hello.rb index 5b1b0f62..aa28d510 100644 --- a/test/virtual/test_hello.rb +++ b/test/virtual/test_hello.rb @@ -33,7 +33,7 @@ HERE def test_string_put @string_input = <