propagating binary code position on extend
This commit is contained in:
parent
6a1528e75a
commit
1169fa7220
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user