fix remaining slot instruction tests

This commit is contained in:
Torsten 2020-03-08 18:49:55 +02:00
parent 07873ce068
commit a70f63e7bb
6 changed files with 28 additions and 58 deletions

View File

@ -12,13 +12,5 @@ module SlotMachine
def test_ins_fail1
assert_raises {SlotLoad.new( "test",[:message, :caller] , nil )}
end
def pest_fail_on_right
load = SlotLoad.new( "test",[:message, :caller] , [:message ,:receiver,:type] )
assert_raises {load.to_risc(Risc.test_compiler)}
end
def pest_fail_on_left_long
load = SlotLoad.new("test", [:message, :caller , :type , :type] , [:message,:type] )
assert_raises {load.to_risc(Risc.test_compiler)}
end
end
end

View File

@ -10,30 +10,16 @@ module SlotMachine
load.to_risc(compiler)
@instructions = compiler.risc_instructions.next
end
def test_ins_class
assert_equal Risc::SlotToReg , @instructions.class
def risc(i)
return @instructions if i == 0
@instructions.next(i)
end
def test_ins_next_class
assert_equal Risc::RegToSlot , @instructions.next.class
def test_ins_0
assert_slot_to_reg 0 , :message , 0 , "message.type"
end
def test_ins_arr
assert_equal :message , @instructions.array.symbol
end
def test_ins_reg
assert_equal :"message.type" , @instructions.register.symbol
end
def test_ins_index
assert_equal 0 , @instructions.index
end
def test_ins_next_reg
assert_equal :"message.type" , @instructions.next.register.symbol
end
def test_ins_next_arr
assert_equal :message , @instructions.next.array.symbol
end
def test_ins_next_index
assert_equal 6 , @instructions.next.index
def test_ins_1
assert_reg_to_slot 1 , "message.type" , :message , 6
assert_nil risc(2)
end
end
end

View File

@ -10,27 +10,22 @@ module SlotMachine
load.to_risc(compiler)
@instructions = compiler.risc_instructions.next
end
def test_ins_next_classes
assert_equal Risc::SlotToReg , @instructions.class
assert_equal Risc::SlotToReg , @instructions.next.class
assert_equal Risc::SlotToReg , @instructions.next(2).class
end
def test_ins_next_next_class
assert_equal Risc::RegToSlot , @instructions.next(3).class
assert_equal NilClass , @instructions.next(4).class
def risc(i)
return @instructions if i == 0
@instructions.next(i)
end
def test_ins
assert_slot_to_reg @instructions ,:message , 6 , "message.caller"
assert_slot_to_reg 0 ,:message , 6 , "message.caller"
end
def test_ins_next
assert_slot_to_reg @instructions.next ,"message.caller" , 0 , "message.caller.type"
assert_slot_to_reg 1 ,"message.caller" , 0 , "message.caller.type"
end
def test_ins_next_2
assert_slot_to_reg @instructions.next(2) , :message , 6 , "message.caller"
assert_slot_to_reg 2 , :message , 6 , "message.caller"
end
def test_ins_next_3
assert_reg_to_slot @instructions.next(3) ,"message.caller.type" , "message.caller" , 0
assert_reg_to_slot 3 ,"message.caller.type" , "message.caller" , 0
assert_equal NilClass , @instructions.next(4).class
end
end
end

View File

@ -13,22 +13,19 @@ module SlotMachine
load.to_risc(compiler)
@instructions = compiler.risc_instructions.next
end
def test_ins_next_class
assert_equal Risc::SlotToReg , @instructions.class
assert_equal Risc::LoadConstant, @instructions.next.class
end
def test_ins_next_class
assert_equal Risc::RegToSlot , @instructions.next(2).class
assert_equal NilClass , @instructions.next(3).class
def risc(i)
return @instructions if i == 0
@instructions.next(i)
end
def test_ins
assert_slot_to_reg @instructions , :message , 0 , "message.type"
assert_slot_to_reg 0 , :message , 0 , "message.type"
end
def test_ins_next
assert_load @instructions.next , Parfait::CacheEntry , "id_"
assert_load 1 , Parfait::CacheEntry , "id_"
end
def test_ins_next_2
assert_reg_to_slot @instructions.next(2) , :"message.type" , "id_", 1
assert_reg_to_slot 2 , :"message.type" , "id_", 1
assert_equal NilClass , @instructions.next(3).class
end
end

View File

@ -20,7 +20,7 @@ module SlotMachine
assert_operator 3, :- , "id_" , "message.caller"
end
def test_4_zero
assert_not_zero 4 , "target"
assert_zero 4 , "target"
end
def test_5_load
assert_load 5, Parfait::NilClass , "id_"
@ -29,7 +29,7 @@ module SlotMachine
assert_operator 6, :- , "id_", "message.caller"
end
def test_7_zero
assert_not_zero 7 , "target"
assert_zero 7 , "target"
end
end
end

View File

@ -109,16 +109,16 @@ module Minitest
def assert_zero ins_i , label
assert_equal Integer , ins_i.class, "assert_zero #{ins_i}"
ins = risc(ins_i)
assert_equal Risc::IsNotZero , ins.class , "Class at:#{ins_i}"
assert_equal Risc::IsZero , ins.class , "Class at:#{ins_i}"
assert_label ins.label , label , "Label at:#{ins_i}"
end
def assert_not_zero ins_i , label
assert_equal Integer , ins_i.class, "assert_not_zero #{ins_i}"
ins = risc(ins_i)
assert_equal Risc::IsZero , ins.class, "Class at:#{ins_i}"
assert_equal Risc::IsNotZero , ins.class, "Class at:#{ins_i}"
assert_label ins.label , label, "Label at:#{ins_i}"
end
def assert_syscall ins , name
def assert_syscall ins_i , name
assert_equal Integer , ins_i.class, "assert_syscall #{ins_i}"
ins = risc(ins_i)
assert_equal Risc::Syscall , ins.class, "Class at:#{ins_i}"