Steamline objectPosition init

check for resetting on the same position with different class, which
should not happen
Ie it’s ok for an object to push another object up,
but not for an instruction to land on code
This commit is contained in:
Torsten Ruger
2018-05-23 21:34:49 +03:00
parent f5d1090c39
commit 8ca70a6835
6 changed files with 39 additions and 31 deletions

View File

@ -7,25 +7,25 @@ module Risc
def setup
Risc.machine.boot
@binary = Parfait::BinaryCode.new(1)
Position.set(@binary , 0,Parfait.object_space.get_main)
Position.set(@binary , 0 , Parfait.object_space.get_main)
@label = Label.new("hi","ho")
end
def test_set_instr
pos = Position.set( @label , 0 , @binary)
pos = Position.set( @label , 8 , @binary)
assert_equal InstructionPosition , pos.class
end
def test_ins_propagates
@label.set_next Arm::ArmMachine.b( @label)
Position.set( @label , 0 , @binary)
assert_equal 0 , Position.get(@label.next).at
Position.set( @label , 8 , @binary)
assert_equal 8 , Position.get(@label.next).at
end
def test_ins_propagates_again
second = Arm::ArmMachine.b( @label)
@label.set_next(second)
Position.set( @label , 0 , @binary)
Position.set( @label , 8 , @binary)
Position.set(second , 2 , @binary)
Position.set( @label , 0 , @binary)
assert_equal 0 , Position.get(@label.next).at
Position.set( @label , 8 , @binary)
assert_equal 8 , Position.get(@label.next).at
end
def test_label_at
branch = Branch.new("b" , @label)
@ -35,6 +35,9 @@ module Risc
assert_equal InstructionPosition , at_4.class
assert_equal Branch , at_4.instruction.class
end
def test_reset_false_type
assert_raises {Position.set(@label , 0 , @binary)}
end
end
end
end

View File

@ -6,22 +6,22 @@ module Risc
class TestPositionBasic < MiniTest::Test
def test_creation_ok
assert ObjectPosition.new(0,self)
assert ObjectPosition.new(self,0)
end
def test_creation_fail
assert_raises {Position.new("0")}
end
def test_add
res = ObjectPosition.new(0,self) + 5
res = ObjectPosition.new(self,0) + 5
assert_equal 5 , res
end
def test_sub
res = ObjectPosition.new(5,self) - 1
assert_equal 4 , res
res = ObjectPosition.new(self,0) - 1
assert_equal -1 , res
end
def test_sub_pos
res = ObjectPosition.new(5,self) - ObjectPosition.new(1,self)
assert_equal 4 , res
res = ObjectPosition.new(self,0) - ObjectPosition.new(self,0)
assert_equal 0 , res
end
def test_set
pos = Position.set(self , 5)