continue with #11

slots are the most tricky, especially testing
This commit is contained in:
Torsten Ruger
2018-08-19 13:06:00 +03:00
parent 047a36178f
commit b294208025
4 changed files with 43 additions and 32 deletions

View File

@ -5,34 +5,35 @@ module Mom
def setup
Parfait.boot!
@load = SlotLoad.new( [:message, :caller] , [:message,:type] )
load = SlotLoad.new( [:message, :caller] , [:message,:type] )
@compiler = Risc::FakeCompiler.new
@instruction = @load.to_risc(@compiler)
load.to_risc(@compiler)
@instructions = @compiler.instructions
end
def test_ins_class
assert_equal Risc::SlotToReg , @instruction.class
assert_equal Risc::SlotToReg , @instructions[0].class
end
def test_ins_next_class
assert_equal Risc::RegToSlot , @instruction.next.class
assert_equal Risc::RegToSlot , @instructions[1].class
end
def test_ins_arr
assert_equal :r0 , @instruction.array.symbol
assert_equal :r0 , @instructions[0].array.symbol
end
def test_ins_reg
assert_equal :r1 , @instruction.register.symbol
assert_equal :r1 , @instructions[0].register.symbol
end
def test_ins_index
assert_equal 0 , @instruction.index
assert_equal 0 , @instructions[0].index
end
def test_ins_next_reg
assert_equal :r1 , @instruction.next.register.symbol
assert_equal :r1 , @instructions[1].register.symbol
end
def test_ins_next_arr
assert_equal :r0 , @instruction.next.array.symbol
assert_equal :r0 , @instructions[1].array.symbol
end
def test_ins_next_index
assert_equal 6 , @instruction.next.index
assert_equal 6 , @instructions[1].index
end
end
end

View File

@ -5,47 +5,48 @@ module Mom
def setup
Parfait.boot!
@load = SlotLoad.new( [:message, :caller, :type] , [:message, :caller , :type] )
@compiler = Risc::FakeCompiler.new
@instruction = @load.to_risc(@compiler)
load = SlotLoad.new( [:message, :caller, :type] , [:message, :caller , :type] )
load.to_risc(@compiler)
@instructions = @compiler.instructions
end
def test_ins_next_class
assert_equal Risc::SlotToReg , @instruction.next(1).class
assert_equal Risc::SlotToReg , @instruction.next(2).class
assert_equal Risc::SlotToReg , @instructions[1].class
assert_equal Risc::SlotToReg , @instructions[2].class
end
def test_ins_next_next_class
assert_equal Risc::RegToSlot , @instruction.next(3).class
assert_equal Risc::RegToSlot , @instructions[3].class
end
def test_ins_next_reg
assert_equal :r1 , @instruction.next.register.symbol
assert_equal :r1 , @instructions[1].register.symbol
end
def test_ins_next_arr
assert_equal :r1 , @instruction.next.array.symbol
assert_equal :r1 , @instructions[1].array.symbol
end
def test_ins_next_index
assert_equal 0 , @instruction.next.index
assert_equal 0 , @instructions[1].index
end
def test_ins_next_2_reg
assert_equal :r1 , @instruction.next(2).register.symbol
assert_equal :r1 , @instructions[2].register.symbol
end
def test_ins_next_2_arr
assert_equal :r0 , @instruction.next(2).array.symbol
assert_equal :r0 , @instructions[2].array.symbol
end
def test_ins_next_2_index
assert_equal 6 , @instruction.next(2).index
assert_equal 6 , @instructions[2].index
end
def test_ins_next_3_reg
assert_equal :r1 , @instruction.next(3).register.symbol
assert_equal :r1 , @instructions[3].register.symbol
end
def test_ins_next_3_arr
assert_equal :r1 , @instruction.next(3).array.symbol
assert_equal :r1 , @instructions[3].array.symbol
end
def test_ins_next_3_index
assert_equal 0 , @instruction.next(3).index
assert_equal 0 , @instructions[3].index
end
end
end