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

@ -30,9 +30,5 @@ module Risc
pos = Position.get(@binary)
assert_equal CodeListener , pos.event_table[:position_changed].first.class
end
def test_extends_creates_jump
@binary.extend_one
CodeListener.init(@binary)
end
end
end

View File

@ -4,25 +4,29 @@ module Risc
# tests that require a boot and test propagation
class TestCodeListenerFull < MiniTest::Test
def setup
#@machine = DummyPlatform.boot
@machine = Risc.machine.boot
@binary = Parfait::BinaryCode.new(1)
@method = Parfait.object_space.types.values.first.methods
@label = Risc.label("hi","ho")
#@machine.set_translated
@machine.translate(:interpreter)
@machine.position_all
end
def test_listener_after_extend
CodeListener.init(@binary).set(0)
CodeListener.init(@binary).set(10)
@binary.extend_one
pos = Position.get(@binary.next)
assert_equal CodeListener , pos.event_table[:position_changed].first.class
end
def test_extend_sets_next_pos
CodeListener.init(@binary).set(0)
CodeListener.init(@binary).set(10)
@binary.extend_one
assert Position.get(@binary.next)
end
def test_extends_creates_jump
CodeListener.init(@binary).set(10)
assert_equal 0 , @binary.get_last
@binary.extend_one
assert 0 != @binary.get_last
end
end
end

View File

@ -36,11 +36,23 @@ module Risc
@position.trigger_inserted
assert_equal @position , @trigger
end
def test_position_set_triggers
@object = @instruction
Position.new(self, 0)
@position.register_event(:position_changed , self)#can't use helper
@position.set(10)
assert_equal @position , @trigger
assert_equal @to , 10
end
def position_changed(pos)
@trigger = pos
end
def position_inserted(pos)
@trigger = pos
end
def position_changing(pos , to)
@trigger = pos
@to = to
end
end
end