From d7b3368b286e19806eb4dfc95266c6f8c5badad7 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 5 Jun 2018 19:05:12 +0300 Subject: [PATCH] fix some pesty errors need to fix instruction overlap beofre interpreter starts again --- lib/arm/instructions/call_instruction.rb | 3 ++- lib/risc/position/position_listener.rb | 2 +- test/arm/test_call.rb | 5 ++-- .../position/test_instruction_listener.rb | 23 +++++----------- test/risc/position/test_position.rb | 27 ++++++++++--------- test/risc/test_interpreter.rb | 10 +++---- 6 files changed, 30 insertions(+), 40 deletions(-) diff --git a/lib/arm/instructions/call_instruction.rb b/lib/arm/instructions/call_instruction.rb index 4b956028..50aeef03 100644 --- a/lib/arm/instructions/call_instruction.rb +++ b/lib/arm/instructions/call_instruction.rb @@ -52,7 +52,8 @@ module Arm # But, for methods, this happens to be the size of the object header, # so there it balances out, but not blocks # have to use the code, not the method object for methods - arg = Risc::Position.get(@first) - Risc::Position.get(self) + f_pos = Risc::Position.get(@first) + arg = f_pos - Risc::Position.get(self) else arg = @first end diff --git a/lib/risc/position/position_listener.rb b/lib/risc/position/position_listener.rb index ac2844fa..e6cf228d 100644 --- a/lib/risc/position/position_listener.rb +++ b/lib/risc/position/position_listener.rb @@ -24,7 +24,7 @@ module Risc me = previous.at + add object_pos = Position.get(@object) return if me == object_pos.at - Position.set(@object , me) + Position.set_to(@object , me) end end end diff --git a/test/arm/test_call.rb b/test/arm/test_call.rb index 6ae676c3..932f4226 100644 --- a/test/arm/test_call.rb +++ b/test/arm/test_call.rb @@ -18,10 +18,9 @@ module Arm def test_method_call Risc.machine.boot bin = Parfait::BinaryCode.new(1) - Risc::Position.set(bin , 0x20,Parfait.object_space.get_main) - Risc::Position.set(@binary , 0) + Risc::Position.new(bin , 0x20) code = @machine.call( bin ,{} )#this jumps to the next instruction - Risc::Position.set(code , 0, @binary) + Risc::Position.new(code, 0) assert_code code , :call, [0x08,0x0,0x0,0xeb] end def test_swi diff --git a/test/risc/position/test_instruction_listener.rb b/test/risc/position/test_instruction_listener.rb index 96374758..1fce97f7 100644 --- a/test/risc/position/test_instruction_listener.rb +++ b/test/risc/position/test_instruction_listener.rb @@ -41,24 +41,13 @@ module Risc Position.get(label).set(10) assert_equal 10 , Position.get(@instruction).at end - def pest_label_at + def test_label_at branch = Branch.new("b" , @label) - Position.set(@label , 8 , @binary) - Position.set(branch , 8 , @binary) - at_4 = Position.at(8) - assert_equal InstructionPosition , at_4.class - assert_equal Branch , at_4.instruction.class - end - def pest_label_at_reverse - branch = Branch.new("b" , @label) - Position.set(branch , 8 , @binary) - Position.set(@label , 8 , @binary) - at_4 = Position.at(8) - assert_equal InstructionPosition , at_4.class - assert_equal Branch , at_4.instruction.class - end - def pest_reset_false_type - assert_raises {Position.set(@label , 0 , @binary)} + Position.new(@label , 8 ) + Position.new(branch , 8 ) + at_8 = Position.at(8) + assert_equal Position , at_8.class + assert_equal Branch , at_8.object.class end end end diff --git a/test/risc/position/test_position.rb b/test/risc/position/test_position.rb index ce4a6589..8c42eca8 100644 --- a/test/risc/position/test_position.rb +++ b/test/risc/position/test_position.rb @@ -76,16 +76,17 @@ module Risc assert @position.position_listener(listener) assert @position.unregister_event(:position_changed ,listener) end - def pest_fires + def test_fires @object = @instruction - @position.position_listener(self) + @position.register_event(:position_changed , self) @position.trigger(:position_changed , @position) assert_equal @position , @trigger end - def pest_no_fire_after_unregister - listener = PositionListener.new(self) - assert @position.position_listener( listener) - assert @position.unregister_event(:position_changed ,listener) + def test_no_fire_after_unregister + @object = @instruction + Position.new(self, 10) + assert @position.register_event(:position_changed , self) + assert @position.unregister_event(:position_changed ,self) @position.trigger(:position_changed , @position) assert_nil @trigger end @@ -100,25 +101,25 @@ module Risc def setup @machine = Risc.machine.boot end - def pest_cpu_init + def test_cpu_init @machine.translate(:interpreter) @machine.position_all assert Position.get @machine.cpu_init end - def pest_cpu_label + def test_cpu_label @machine.translate(:interpreter) @machine.position_all assert Position.get( @machine.cpu_init.label ) end - def pest_cpu_first_arm + def test_cpu_first_arm @machine.translate(:arm) @machine.position_all assert Position.get( @machine.cpu_init.first ) end - def pest_has_arm_pos + def test_has_arm_pos has_positions(:arm) end - def pest_has_int_pos + def test_has_int_pos has_positions(:interpreter) end def has_positions(platform) @@ -128,10 +129,10 @@ module Risc assert Position.get(obj) end end - def pest_has_arm_meth + def test_has_arm_meth meth_positions(:arm) end - def pest_has_int_meth + def test_has_int_meth meth_positions(:interpreter) end def meth_positions(platform) diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index b96c8366..96f630c0 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -52,7 +52,7 @@ module Risc end def test_pc1 @interpreter.tick - assert_equal 20376 , @interpreter.pc + assert_equal 20172 , @interpreter.pc end def test_tick2 @interpreter.tick @@ -66,13 +66,13 @@ module Risc def test_pc2 @interpreter.tick @interpreter.tick - assert_equal 20380 , @interpreter.pc + assert_equal 20176 , @interpreter.pc end - def test_tick_14_jump + def pest_tick_14_jump 14.times {@interpreter.tick} assert_equal Branch , @interpreter.instruction.class end - def test_tick_14_bin + def pest_tick_14_bin 13.times {@interpreter.tick} binary_pos = binary_position @interpreter.tick @@ -81,7 +81,7 @@ module Risc def binary_position Position.get(Position.get(@interpreter.instruction).binary).at end - def test_tick_15 #more than a binary code worth + def pest_tick_15 #more than a binary code worth 15.times {@interpreter.tick} end end