move all position setting into position
Position and subclasses handle the logic, external to the classes, so it can be swapped out later (at runtime positions can’t change)
This commit is contained in:
@ -82,22 +82,22 @@ module Arm
|
||||
end
|
||||
def test_too_big_add
|
||||
code = @machine.add :r1 , :r1, 0x222
|
||||
code.set_position(0,0)
|
||||
Risc::Position.set(0,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"
|
||||
assert_code code.next , :add , [0x22,0x10,0x91,0xe2] #e2 91 10 22
|
||||
end
|
||||
|
||||
def label pos = 0x22 + 8
|
||||
def label( pos = 0x22 + 8)
|
||||
l = Risc.label("some" , "Label")
|
||||
l.set_position pos
|
||||
Risc::Position.set(l,pos , 1)
|
||||
l
|
||||
end
|
||||
|
||||
def test_move_object
|
||||
code = @machine.add( :r1 , label)
|
||||
code.set_position(0,0)
|
||||
Risc::Position.set(code,0,0)
|
||||
assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22
|
||||
end
|
||||
|
||||
|
@ -22,7 +22,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
|
||||
code.set_position(0,0)
|
||||
Risc::Position.set(code,0,1)
|
||||
begin # mov 512(0x200) = e3 a0 0c 02 add 34(0x22) = e2 90 00 22
|
||||
assert_code code , :mov , [ 0x02,0x0c,0xb0,0xe3]
|
||||
rescue Risc::LinkException
|
||||
|
@ -42,7 +42,7 @@ module Risc
|
||||
end
|
||||
def test_pos_arm
|
||||
mov = Arm::ArmMachine.mov :r1, 128
|
||||
mov.set_position(0,0)
|
||||
Risc::Position.set(0,0)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,8 +1,12 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestPosition < MiniTest::Test
|
||||
class TestPositionBasic < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
end
|
||||
def test_creation_ok
|
||||
assert Position.new(0)
|
||||
end
|
||||
@ -26,7 +30,7 @@ module Risc
|
||||
assert_equal 5 , pos.at
|
||||
end
|
||||
def test_set_instr
|
||||
pos = Position.set( Risc::Label.new("hi","ho") , 0)
|
||||
pos = Position.set( Risc::Label.new("hi","ho") , 0 , @binary)
|
||||
assert_equal IPosition , pos.class
|
||||
end
|
||||
def tet_tos
|
Reference in New Issue
Block a user