add position_chaning to event interface

by reacting to the change _before it happens, we can move any BinaryCode out of the way

So when Instruction are inserted and code gets inserted, we don't need to set up the correct listener explicitly (which is tricky across mathods and changing chains), but instead just move anything that is in the way along
This commit is contained in:
Torsten Ruger
2018-06-09 08:10:41 +03:00
parent 74c15d45a3
commit ad3040a846
9 changed files with 65 additions and 48 deletions

View File

@ -67,13 +67,20 @@ module Risc
def set(int)
return int if int == self.at
trigger_changing( int )
Position.set_to(self , int)
@at = int
trigger_changed
int
end
# helper to fire the event that the position changed
# helper to fire the event that the position is about to change
# the argument is the new position (as int)
def trigger_changing( to )
event_table[:position_changed].each { |handler| handler.position_changing( self , to) }
end
# helper to fire the event that the position has changed
# Note: set checks if the position actually has changed, before fireing
# but during insert it is helpful to trigger just to set the next
def trigger_changed
@ -116,8 +123,9 @@ module Risc
def next_slot
return -1 if at < 0
self.log.debug "Next Slot @#{at.to_s(16)} for #{object.class} == #{(at + object.byte_length).to_s(16)}"
at + object.byte_length
slot = at + object.padded_length
self.log.debug "Next Slot @#{at.to_s(16)} for #{object.class}(#{object.padded_length.to_s(16)}) == #{(slot).to_s(16)}"
slot
end
## class level forward and reverse cache