insertion pushes, split position tests
This commit is contained in:
parent
c22aff4c4f
commit
7fa8397b56
@ -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
|
||||
|
@ -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
|
||||
|
@ -24,7 +24,7 @@ module Risc
|
||||
@instruction.insert DummyInstruction.new
|
||||
assert Position.get(@instruction.next)
|
||||
end
|
||||
def pest_insert_pushes
|
||||
def test_insert_pushes
|
||||
@instruction.insert DummyInstruction.new
|
||||
assert_equal 76 , Position.get(@instruction.last).at
|
||||
end
|
||||
|
@ -27,6 +27,9 @@ module Risc
|
||||
def test_has_trigger_inserted
|
||||
assert_equal [] , @pos.trigger_inserted
|
||||
end
|
||||
def test_has_trigger_changed
|
||||
assert_equal [] , @pos.trigger_changed
|
||||
end
|
||||
def test_listeners_empty
|
||||
assert @pos.position_listeners.empty?
|
||||
end
|
||||
@ -38,130 +41,4 @@ module Risc
|
||||
assert_equal 0 , @pos.set(0)
|
||||
end
|
||||
end
|
||||
class TestPositionMath < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@pos = Position.new(self , 5)
|
||||
end
|
||||
def test_add
|
||||
res = @pos + 5
|
||||
assert_equal 10 , res
|
||||
end
|
||||
def test_sub
|
||||
res = @pos - 3
|
||||
assert_equal 2 , res
|
||||
end
|
||||
def test_sub_pos
|
||||
res = @pos - Position.new(@pos,4)
|
||||
assert_equal 1 , res
|
||||
end
|
||||
def test_lg
|
||||
assert @pos > Position.new(@pos,4)
|
||||
end
|
||||
def test_tos
|
||||
assert_equal "0x5" , @pos.to_s
|
||||
end
|
||||
def test_reset_ok
|
||||
pos = @pos.set(10)
|
||||
assert_equal 10 , pos
|
||||
end
|
||||
def test_at
|
||||
pos = Position.at(5)
|
||||
assert_equal 5 , pos.at
|
||||
end
|
||||
end
|
||||
class TestPositionEvents < MiniTest::Test
|
||||
def setup
|
||||
Position.clear_positions
|
||||
@instruction = DummyInstruction.new
|
||||
@position = Position.new(@instruction , 0)
|
||||
@listener = PositionListener.new( @instruction )
|
||||
end
|
||||
def test_has_register
|
||||
assert @position.position_listener( @instruction )
|
||||
end
|
||||
def test_can_unregister
|
||||
listener = PositionListener.new(self)
|
||||
assert @position.position_listener(listener)
|
||||
assert @position.remove_position_listener(listener)
|
||||
end
|
||||
def test_fires
|
||||
@object = @instruction
|
||||
@position.register_event(:position_changed , self)
|
||||
@position.trigger(:position_changed , @position)
|
||||
assert_equal @position , @trigger
|
||||
end
|
||||
def test_no_fire_after_unregister
|
||||
@object = @instruction
|
||||
Position.new(self, 10)
|
||||
assert @position.register_event(:position_changed , self)
|
||||
assert @position.remove_position_listener(self)
|
||||
@position.trigger(:position_changed , @position)
|
||||
assert_nil @trigger
|
||||
end
|
||||
def test_can_trigger_inserted
|
||||
@object = @instruction
|
||||
@position.register_event(:position_changed , self)
|
||||
@position.trigger_inserted
|
||||
assert_equal @position , @trigger
|
||||
end
|
||||
def position_changed(pos)
|
||||
@trigger = pos
|
||||
end
|
||||
def position_inserted(pos)
|
||||
@trigger = pos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Risc
|
||||
class TestMachinePositions < MiniTest::Test
|
||||
def setup
|
||||
@machine = Risc.machine.boot
|
||||
end
|
||||
def test_cpu_init
|
||||
@machine.translate(:interpreter)
|
||||
@machine.position_all
|
||||
assert Position.get @machine.cpu_init
|
||||
end
|
||||
def test_cpu_label
|
||||
@machine.translate(:interpreter)
|
||||
@machine.position_all
|
||||
assert Position.get( @machine.cpu_init.label )
|
||||
end
|
||||
def test_cpu_first_arm
|
||||
@machine.translate(:arm)
|
||||
@machine.position_all
|
||||
assert Position.get( @machine.cpu_init.first )
|
||||
end
|
||||
def test_has_arm_pos
|
||||
has_positions(:arm)
|
||||
end
|
||||
def test_has_int_pos
|
||||
has_positions(:interpreter)
|
||||
end
|
||||
def has_positions(platform)
|
||||
@machine.translate(:arm)
|
||||
@machine.position_all
|
||||
@machine.objects.each do |id,obj|
|
||||
assert Position.get(obj)
|
||||
end
|
||||
end
|
||||
def test_has_arm_meth
|
||||
meth_positions(:arm)
|
||||
end
|
||||
def test_has_int_meth
|
||||
meth_positions(:interpreter)
|
||||
end
|
||||
def meth_positions(platform)
|
||||
@machine.translate(:arm)
|
||||
@machine.position_all
|
||||
Parfait.object_space.each_type do |type|
|
||||
type.each_method do |method|
|
||||
assert Position.get(method.binary)
|
||||
assert Position.get(method.cpu_instructions)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
46
test/risc/position/test_position1.rb
Normal file
46
test/risc/position/test_position1.rb
Normal file
@ -0,0 +1,46 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
class TestPositionEvents < MiniTest::Test
|
||||
def setup
|
||||
Position.clear_positions
|
||||
@instruction = DummyInstruction.new
|
||||
@position = Position.new(@instruction , 0)
|
||||
@listener = PositionListener.new( @instruction )
|
||||
end
|
||||
def test_has_register
|
||||
assert @position.position_listener( @instruction )
|
||||
end
|
||||
def test_can_unregister
|
||||
listener = PositionListener.new(self)
|
||||
assert @position.position_listener(listener)
|
||||
assert @position.remove_position_listener(listener)
|
||||
end
|
||||
def test_fires
|
||||
@object = @instruction
|
||||
@position.register_event(:position_changed , self)#can't use helper
|
||||
@position.trigger_changed
|
||||
assert_equal @position , @trigger
|
||||
end
|
||||
def test_no_fire_after_unregister
|
||||
@object = @instruction
|
||||
Position.new(self, 10)
|
||||
assert @position.register_event(:position_changed , self)#can't use helper
|
||||
assert @position.remove_position_listener(self)
|
||||
@position.trigger(:position_changed , @position)
|
||||
assert_nil @trigger
|
||||
end
|
||||
def test_can_trigger_inserted
|
||||
@object = @instruction
|
||||
@position.register_event(:position_changed , self) #can't use helper
|
||||
@position.trigger_inserted
|
||||
assert_equal @position , @trigger
|
||||
end
|
||||
def position_changed(pos)
|
||||
@trigger = pos
|
||||
end
|
||||
def position_inserted(pos)
|
||||
@trigger = pos
|
||||
end
|
||||
end
|
||||
end
|
36
test/risc/position/test_position2.rb
Normal file
36
test/risc/position/test_position2.rb
Normal file
@ -0,0 +1,36 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
class TestPositionMath < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@pos = Position.new(self , 5)
|
||||
end
|
||||
def test_add
|
||||
res = @pos + 5
|
||||
assert_equal 10 , res
|
||||
end
|
||||
def test_sub
|
||||
res = @pos - 3
|
||||
assert_equal 2 , res
|
||||
end
|
||||
def test_sub_pos
|
||||
res = @pos - Position.new(@pos,4)
|
||||
assert_equal 1 , res
|
||||
end
|
||||
def test_lg
|
||||
assert @pos > Position.new(@pos,4)
|
||||
end
|
||||
def test_tos
|
||||
assert_equal "0x5" , @pos.to_s
|
||||
end
|
||||
def test_reset_ok
|
||||
pos = @pos.set(10)
|
||||
assert_equal 10 , pos
|
||||
end
|
||||
def test_at
|
||||
pos = Position.at(5)
|
||||
assert_equal 5 , pos.at
|
||||
end
|
||||
end
|
||||
end
|
53
test/risc/position/test_position3.rb
Normal file
53
test/risc/position/test_position3.rb
Normal file
@ -0,0 +1,53 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
class TestMachinePositions < MiniTest::Test
|
||||
def setup
|
||||
@machine = Risc.machine.boot
|
||||
end
|
||||
def test_cpu_init
|
||||
@machine.translate(:interpreter)
|
||||
@machine.position_all
|
||||
assert Position.get @machine.cpu_init
|
||||
end
|
||||
def test_cpu_label
|
||||
@machine.translate(:interpreter)
|
||||
@machine.position_all
|
||||
assert Position.get( @machine.cpu_init.label )
|
||||
end
|
||||
def test_cpu_first_arm
|
||||
@machine.translate(:arm)
|
||||
@machine.position_all
|
||||
assert Position.get( @machine.cpu_init.first )
|
||||
end
|
||||
def test_has_arm_pos
|
||||
has_positions(:arm)
|
||||
end
|
||||
def test_has_int_pos
|
||||
has_positions(:interpreter)
|
||||
end
|
||||
def has_positions(platform)
|
||||
@machine.translate(:arm)
|
||||
@machine.position_all
|
||||
@machine.objects.each do |id,obj|
|
||||
assert Position.get(obj)
|
||||
end
|
||||
end
|
||||
def test_has_arm_meth
|
||||
meth_positions(:arm)
|
||||
end
|
||||
def test_has_int_meth
|
||||
meth_positions(:interpreter)
|
||||
end
|
||||
def meth_positions(platform)
|
||||
@machine.translate(:arm)
|
||||
@machine.position_all
|
||||
Parfait.object_space.each_type do |type|
|
||||
type.each_method do |method|
|
||||
assert Position.get(method.binary)
|
||||
assert Position.get(method.cpu_instructions)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user