diff --git a/lib/parfait/binary_code.rb b/lib/parfait/binary_code.rb index 6779be4c..d85a8a5e 100644 --- a/lib/parfait/binary_code.rb +++ b/lib/parfait/binary_code.rb @@ -17,13 +17,18 @@ module Parfait end def extend_to(total_size) if total_size > self.data_length - @next = BinaryCode.new(1) unless @next + unless @next + @next = BinaryCode.new(1) + #puts "extending #{total_size - data_length} in #{self}" + Risc::Position.reset(self) if Risc::Position.set?(self) + end @next.extend_to(total_size - data_length) end end def to_s - "BinaryCode #{}" + "BinaryCode #{Risc::Position.set?(self) ? Risc::Position.get(self): self.object_id.to_s(16)}" end + def each_word index = 1 while( index <= data_length) diff --git a/lib/risc/position.rb b/lib/risc/position.rb index 701b38e4..c87123e0 100644 --- a/lib/risc/position.rb +++ b/lib/risc/position.rb @@ -66,6 +66,13 @@ module Risc pos end + # set to the same position as before, thus triggering whatever code that propagates + # position _must have been set, otherwise raises + def self.reset(obj) + old = self.get(obj) + old.reset_to( old.at ) + end + def self.set( object , pos , extra = nil) # resetting of position used to be error, but since relink and dynamic instruction size it is ok. # in measures (of 32) @@ -92,6 +99,7 @@ module Risc end end end + # handle event propagation class IPosition < Position attr_reader :instruction , :binary @@ -131,5 +139,10 @@ module Risc return unless code.next Position.set(code.next , at + code.padded_length, method) end + def reset_to(pos) + super(pos) + #puts "Reset (#{changed}) #{instruction}" + init(pos) + end end end diff --git a/test/risc/test_position2.rb b/test/risc/test_position2.rb index 06c3d280..db6e546f 100644 --- a/test/risc/test_position2.rb +++ b/test/risc/test_position2.rb @@ -29,10 +29,15 @@ module Risc Position.set( @label , 0 , @binary) assert_equal 0 , Position.get(@label.next).at end - def test_bin_propagates + def test_bin_propagates_existing @binary.extend_to(16) Position.set( @binary , 0 , Parfait.object_space.get_main) assert_equal @binary.padded_length , Position.get(@binary.next).at end + def test_bin_propagates_after + Position.set( @binary , 0 , Parfait.object_space.get_main) + @binary.extend_to(16) + assert_equal @binary.padded_length , Position.get(@binary.next).at + end end end