auto extend binary code

final solution will need repositioning
This commit is contained in:
Torsten Ruger 2018-04-03 15:07:36 +03:00
parent 30ca70e042
commit 52d389cdbf
3 changed files with 21 additions and 5 deletions

View File

@ -17,7 +17,8 @@ module Parfait
end end
def extend_to(total_size) def extend_to(total_size)
if total_size > self.data_length 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
end end
def to_s def to_s
@ -40,7 +41,8 @@ module Parfait
def set_word(index , word) def set_word(index , word)
raise "invalid index #{index}" if index < 1 raise "invalid index #{index}" if index < 1
if index > data_length + 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) @next.set_word( index - data_length , word)
end end
set_internal_word(index + 2 , word) set_internal_word(index + 2 , word)

View File

@ -15,12 +15,15 @@ module Risc
# LinkException may be thrown, possibly several times # LinkException may be thrown, possibly several times
# So repeat until it works # So repeat until it works
def assemble( instruction ) def assemble( instruction )
ok = false not_ok = 1
until(ok) while(not_ok)
begin begin
#puts "Not ok #{not_ok}"
#FIXME really need to reposition here, so jumps go right
assemble_all(instruction) assemble_all(instruction)
ok = true not_ok = false
rescue LinkException rescue LinkException
not_ok += 1
end end
end end
end end

View File

@ -69,6 +69,17 @@ module Parfait
assert @code.next assert @code.next
assert_nil @code.next.next assert_nil @code.next.next
end 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 def test_each
len = 0 len = 0
@code.each_word{ len += 1} @code.each_word{ len += 1}