getter by position
extract and expand position testing never return labels (that have the same position as their target)
This commit is contained in:
parent
37d62d298e
commit
8966a50a8a
@ -21,6 +21,15 @@ module Risc
|
|||||||
@positions
|
@positions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.at( int )
|
||||||
|
self.positions.each do |object , position|
|
||||||
|
next unless position.at == int
|
||||||
|
return position unless position.is_a?(InstructionPosition)
|
||||||
|
return position unless position.instruction.is_a?(Label)
|
||||||
|
end
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def self.set?(object)
|
def self.set?(object)
|
||||||
self.positions.has_key?(object)
|
self.positions.has_key?(object)
|
||||||
end
|
end
|
||||||
|
@ -21,7 +21,7 @@ module Risc
|
|||||||
def length
|
def length
|
||||||
88
|
88
|
||||||
end
|
end
|
||||||
def est_state_change
|
def test_state_change
|
||||||
@interpreter.register_event :state_changed , self
|
@interpreter.register_event :state_changed , self
|
||||||
ticks length
|
ticks length
|
||||||
assert @state_events[:state_changed]
|
assert @state_events[:state_changed]
|
||||||
@ -30,7 +30,7 @@ module Risc
|
|||||||
@interpreter.unregister_event :state_changed , self
|
@interpreter.unregister_event :state_changed , self
|
||||||
end
|
end
|
||||||
|
|
||||||
def est_instruction_events
|
def test_instruction_events
|
||||||
@interpreter.register_event :instruction_changed , self
|
@interpreter.register_event :instruction_changed , self
|
||||||
ticks length
|
ticks length
|
||||||
assert_equal length , @instruction_events.length
|
assert_equal length , @instruction_events.length
|
||||||
|
@ -27,6 +27,14 @@ module Risc
|
|||||||
Position.set( @label , 0 , @binary)
|
Position.set( @label , 0 , @binary)
|
||||||
assert_equal 0 , Position.get(@label.next).at
|
assert_equal 0 , Position.get(@label.next).at
|
||||||
end
|
end
|
||||||
|
def test_label_at
|
||||||
|
branch = Branch.new("b" , @label)
|
||||||
|
Position.set(@label , 4 , @binary)
|
||||||
|
Position.set(branch , 4 , @binary)
|
||||||
|
at_4 = Position.at(4)
|
||||||
|
assert_equal InstructionPosition , at_4.class
|
||||||
|
assert_equal Branch , at_4.instruction.class
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -42,6 +42,11 @@ module Risc
|
|||||||
def test_raises_set_nil
|
def test_raises_set_nil
|
||||||
assert_raises { Position.set(self,nil)}
|
assert_raises { Position.set(self,nil)}
|
||||||
end
|
end
|
||||||
|
def test_at
|
||||||
|
pos = Position.set(self , 5)
|
||||||
|
pos = Position.at(5)
|
||||||
|
assert_equal 5 , pos.at
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require_relative "../helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Risc
|
module Risc
|
||||||
class TestMachineObjects < MiniTest::Test
|
class TestMachineObjects < MiniTest::Test
|
||||||
@ -18,18 +18,6 @@ module Risc
|
|||||||
assert @machine.add_constant( Parfait::Integer.new(5) )
|
assert @machine.add_constant( Parfait::Integer.new(5) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestMachinePositions < MiniTest::Test
|
|
||||||
def setup
|
|
||||||
@machine = Risc.machine.boot
|
|
||||||
@machine.translate(:arm)
|
|
||||||
@machine.position_all
|
|
||||||
end
|
|
||||||
def test_has_positions
|
|
||||||
@machine.objects.each do |id,obj|
|
|
||||||
assert Position.get(obj)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class TestMachineInit < MiniTest::Test
|
class TestMachineInit < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
@machine = Risc.machine.boot
|
@machine = Risc.machine.boot
|
||||||
|
53
test/risc/test_position.rb
Normal file
53
test/risc/test_position.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