diff --git a/lib/parfait/binary_code.rb b/lib/parfait/binary_code.rb index f6adfc20..6779be4c 100644 --- a/lib/parfait/binary_code.rb +++ b/lib/parfait/binary_code.rb @@ -17,7 +17,8 @@ module Parfait end def extend_to(total_size) if total_size > self.data_length - @next = BinaryCode.new(total_size - data_length) + @next = BinaryCode.new(1) unless @next + @next.extend_to(total_size - data_length) end end def to_s @@ -40,7 +41,8 @@ module Parfait def set_word(index , word) raise "invalid index #{index}" if index < 1 if index > data_length + 1 - raise "invalid index #{index}" unless @next + #raise "invalid index #{index}" unless @next + extend_to( index ) @next.set_word( index - data_length , word) end set_internal_word(index + 2 , word) diff --git a/lib/risc/binary_writer.rb b/lib/risc/binary_writer.rb index 335e65e8..d1eb9ab3 100644 --- a/lib/risc/binary_writer.rb +++ b/lib/risc/binary_writer.rb @@ -15,12 +15,15 @@ module Risc # LinkException may be thrown, possibly several times # So repeat until it works def assemble( instruction ) - ok = false - until(ok) + not_ok = 1 + while(not_ok) begin + #puts "Not ok #{not_ok}" + #FIXME really need to reposition here, so jumps go right assemble_all(instruction) - ok = true + not_ok = false rescue LinkException + not_ok += 1 end end end diff --git a/test/parfait/test_binary_code.rb b/test/parfait/test_binary_code.rb index e343232f..fbb162df 100644 --- a/test/parfait/test_binary_code.rb +++ b/test/parfait/test_binary_code.rb @@ -69,6 +69,17 @@ module Parfait assert @code.next assert_nil @code.next.next end + def test_auto_extend #extend by seting word + assert_nil @code.next + @code.set_word(20 , 1) + assert @code.next + end + def test_extend_extended + @code.extend_to(20) + @code.extend_to(30) + assert @code.next.next + assert_nil @code.next.next.next + end def test_each len = 0 @code.each_word{ len += 1}