insertion pushes, split position tests

This commit is contained in:
Torsten Ruger
2018-06-06 10:19:18 +03:00
parent c22aff4c4f
commit 7fa8397b56
7 changed files with 155 additions and 136 deletions

View File

@ -45,23 +45,23 @@ module Risc
# before the insert, ie:
# position : the arg is the first instruction in the chain where insert happened
# position.object.next : is the newly inserted instruction we need to setup
# @instruction : previously dependent on position, now on .next's position
# @instruction : previously dependent on position, now on inserted's position
#
# So we need to :
# - move the listener of @instruction to listen to the inserted instruction
# - move the listener self to listen to the inserted instruction
# - add a listener for the new instruction (to listen to the arg)
# - set the new position (moving the chain along)
def position_inserted(position)
inserted = position.object.next
raise "uups" unless inserted ## TODO: remove
position.remove_position_listener(InstructionListener)
new_pos = Position.get(inserted)
new_pos.position_listener(old_listener)
position.remove_position_listener(self)
new_pos = Position.new(inserted , -1)
new_pos.position_listener(self)
my_pos = Position.get(@instruction)
listen = InstructionListener.new(position.object , @binary)
my_pos.position_listener(listen)
listen = InstructionListener.new(inserted , @binary)
position.position_listener(listen)
position.trigger_changed
end
# check that the binary we use is the one where the current position falls

View File

@ -69,10 +69,17 @@ module Risc
return int if int == self.at
Position.set_to(self , int)
@at = int
trigger(:position_changed , self )
trigger_changed
int
end
# helper to fire the event that the position 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
trigger(:position_changed , self )
end
def trigger_inserted
event_table[:position_changed].each { |handler| handler.position_inserted( self) }
end