seperate position create and register
many test fixes
This commit is contained in:
@@ -18,7 +18,7 @@ module Arm
|
||||
@machine = Arm::ArmMachine
|
||||
@binary = FakeBin.new
|
||||
Risc::Position.clear_positions
|
||||
Risc::Position.new(@binary , 0)
|
||||
Risc::Position.create(@binary).set(0)
|
||||
end
|
||||
|
||||
# code is what the generator spits out, at least one instruction worth (.first)
|
||||
|
@@ -18,9 +18,9 @@ module Arm
|
||||
def test_method_call
|
||||
Risc.machine.boot
|
||||
bin = Parfait::BinaryCode.new(1)
|
||||
Risc::Position.new(bin , 0x20)
|
||||
Risc::Position.new(bin).set(0x20)
|
||||
code = @machine.call( bin ,{} )#this jumps to the next instruction
|
||||
Risc::Position.new(code, 0)
|
||||
Risc::Position.new(code).set(0)
|
||||
assert_code code , :call, [0x08,0x0,0x0,0xeb]
|
||||
end
|
||||
def test_swi
|
||||
|
@@ -82,7 +82,7 @@ module Arm
|
||||
end
|
||||
def test_too_big_add
|
||||
code = @machine.add :r1 , :r1, 0x222
|
||||
Risc::Position.new(code,0)
|
||||
Risc::Position.create(code).set(0)
|
||||
# add 0x02 (first instruction) and then 0x220 shifted
|
||||
assert_code code , :add , [0x02,0x1c,0x91,0xe2] #e2 91 1e 02
|
||||
# added extra instruction to add "extra"
|
||||
@@ -91,14 +91,14 @@ module Arm
|
||||
|
||||
def label( pos = 0x22 + 8)
|
||||
label = Risc::Label.new("some" , "Label" , FakeAddress.new(pos))
|
||||
Risc::Position.new(label , pos)
|
||||
Risc::Position.create(label).set(pos)
|
||||
#Risc::Position.set(l , pos , @binary)
|
||||
label
|
||||
end
|
||||
|
||||
def test_move_object
|
||||
code = @machine.add( :r1 , label)
|
||||
Risc::Position.new(code,0)
|
||||
Risc::Position.create(code).set(0)
|
||||
assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22
|
||||
end
|
||||
|
||||
|
@@ -26,7 +26,7 @@ module Arm
|
||||
end
|
||||
def test_mov_big
|
||||
code = @machine.mov :r0, 0x222 # is not 8 bit and can't be rotated by the arm system in one instruction
|
||||
Risc::Position.new(code,0)
|
||||
Risc::Position.new(code).set(0)
|
||||
# mov 512(0x200) = e3 a0 0c 02 add 34(0x22) = e2 90 00 22
|
||||
assert_code code , :mov , [ 0x02,0x0c,0xb0,0xe3]
|
||||
assert_code code.next , :add , [ 0x22,0x00,0x90,0xe2]
|
||||
|
@@ -5,13 +5,13 @@ module Risc
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
@bin_pos = Position.new(@binary,0)
|
||||
@bin_pos = Position.new(@binary).set(0)
|
||||
@instruction = DummyInstruction.new(DummyInstruction.new)
|
||||
@position = InstructionListener.init(@instruction , @binary)
|
||||
end
|
||||
def test_label_address
|
||||
label = Label.new("hi" ,"ho" , FakeAddress.new(0))
|
||||
label_pos = Position.new( label , -1 )
|
||||
label_pos = Position.new( label )
|
||||
label_pos.position_listener(InstructionListener.new(@binary))
|
||||
label_pos.set(8)
|
||||
assert_equal 8 , label_pos.object.address.value
|
||||
@@ -52,8 +52,8 @@ module Risc
|
||||
def test_label_at_branch
|
||||
label = Label.new("Hi","Ho" , FakeAddress.new(5) , @instruction)
|
||||
branch = Branch.new("b" , label)
|
||||
Position.new(label , 8 )
|
||||
Position.new(branch , 8 )
|
||||
Position.new(label ).set(8)
|
||||
Position.new(branch).set(8)
|
||||
at_8 = Position.at(8)
|
||||
assert_equal Position , at_8.class
|
||||
assert_equal Branch , at_8.object.class
|
||||
|
@@ -6,9 +6,9 @@ module Risc
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@label = Label.new("Hi","Ho" , FakeAddress.new(5))
|
||||
@label_pos = Position.new(@label , -1)
|
||||
@label_pos = Position.new(@label ).set(4)
|
||||
@code = Parfait::BinaryCode.new(1)
|
||||
@code_pos = Position.new(@code , -1)
|
||||
@code_pos = Position.new(@code)
|
||||
@code_pos.position_listener( LabelListener.new(@label))
|
||||
end
|
||||
|
||||
|
@@ -5,7 +5,7 @@ module Risc
|
||||
class TestPosition < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@pos = Position.new(self , -1)
|
||||
@pos = Position.new(self )
|
||||
end
|
||||
def test_new
|
||||
assert @pos
|
||||
@@ -15,7 +15,7 @@ module Risc
|
||||
end
|
||||
def test_next_slot
|
||||
mov = Arm::ArmMachine.mov(:r1 , :r1)
|
||||
position = Position.new(mov , 0)
|
||||
position = Position.new(mov ).set(0)
|
||||
assert_equal 4, position.next_slot
|
||||
end
|
||||
def test_has_get_code
|
||||
@@ -38,7 +38,7 @@ module Risc
|
||||
assert_equal 1 , @pos.position_listeners.length
|
||||
end
|
||||
def test_set
|
||||
assert_equal 0 , @pos.set(0)
|
||||
assert_equal 0 , @pos.set(0).at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -5,7 +5,7 @@ module Risc
|
||||
def setup
|
||||
Position.clear_positions
|
||||
@instruction = DummyInstruction.new
|
||||
@position = Position.new(@instruction , 0)
|
||||
@position = Position.new(@instruction).set(0)
|
||||
@listener = PositionListener.new( @instruction )
|
||||
end
|
||||
def test_has_register
|
||||
@@ -24,7 +24,7 @@ module Risc
|
||||
end
|
||||
def test_no_fire_after_unregister
|
||||
@object = @instruction
|
||||
Position.new(self, 10)
|
||||
Position.new(self).set(10)
|
||||
assert @position.register_event(:position_changed , self)#can't use helper
|
||||
assert @position.remove_position_listener(self)
|
||||
@position.trigger(:position_changed , @position)
|
||||
@@ -38,7 +38,7 @@ module Risc
|
||||
end
|
||||
def test_position_set_triggers
|
||||
@object = @instruction
|
||||
Position.new(self, 0)
|
||||
Position.new(self).set(0)
|
||||
@position.register_event(:position_changed , self)#can't use helper
|
||||
@position.set(10)
|
||||
assert_equal @position , @trigger
|
||||
|
@@ -4,7 +4,7 @@ module Risc
|
||||
class TestPositionMath < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@pos = Position.new(self , 5)
|
||||
@pos = Position.new(self).set(5)
|
||||
end
|
||||
def test_add
|
||||
res = @pos + 5
|
||||
@@ -15,24 +15,24 @@ module Risc
|
||||
assert_equal 2 , res
|
||||
end
|
||||
def test_sub_pos
|
||||
res = @pos - Position.new(@pos,4)
|
||||
res = @pos - Position.new(@pos).set(4)
|
||||
assert_equal 1 , res
|
||||
end
|
||||
def test_lg
|
||||
assert @pos > Position.new(@pos,4)
|
||||
assert @pos > Position.new(@pos).set(2)
|
||||
end
|
||||
def test_tos
|
||||
assert_equal "0x5" , @pos.to_s
|
||||
end
|
||||
def test_reset_ok
|
||||
pos = @pos.set(10)
|
||||
assert_equal 10 , pos
|
||||
assert_equal 10 , pos.at
|
||||
end
|
||||
def test_object_class_test
|
||||
assert_equal :object , @pos.object_class
|
||||
end
|
||||
def test_object_class_instr
|
||||
assert_equal :instruction , Position.new(Label.new("hi","ho",FakeAddress.new(1)),4).object_class
|
||||
assert_equal :instruction , Position.new(Label.new("hi","ho",FakeAddress.new(1))).set(4).object_class
|
||||
end
|
||||
def test_at
|
||||
pos = Position.at(5)
|
||||
|
@@ -6,8 +6,8 @@ module Risc
|
||||
def setup
|
||||
@object = Dummy.new
|
||||
@dependent = Dummy.new
|
||||
@pos = Position.new(@object,0)
|
||||
Position.new(@dependent,0)
|
||||
@pos = Position.new(@object).set(0)
|
||||
Position.new(@dependent).set(0)
|
||||
@listener = PositionListener.new(@dependent)
|
||||
end
|
||||
def test_register
|
||||
|
@@ -20,6 +20,7 @@ module Risc
|
||||
@machine = Risc.machine.boot
|
||||
@machine.translate(:arm)
|
||||
@machine.position_all
|
||||
@machine.create_binary
|
||||
@text_writer = TextWriter.new(@machine)
|
||||
end
|
||||
def test_write_all
|
||||
|
Reference in New Issue
Block a user