fix most interpreter tests

This commit is contained in:
Torsten 2020-03-22 10:42:50 +02:00
parent 06ade75593
commit a93a3c8af5
13 changed files with 35 additions and 32 deletions

View File

@ -267,7 +267,7 @@ module Risc
end
def handle_putstring
str = get_register( :"syscall_1" ) # should test length, ie r2
str = get_register( :r0 ) # should test length, ie r2
case str
when Symbol
@stdout << str.to_s

View File

@ -40,6 +40,8 @@ module Risc
:r0
when :syscall_2
:r1
when :saved_message
:r15
else
nil
end

View File

@ -24,7 +24,7 @@ module Risc
assert :main , call_ins.method.name
end
def test_load_15
assert_load 1 , Parfait::Integer , "id_integer_"
assert_load 1 , Parfait::Integer , :r1
assert_equal 15 , @interpreter.get_register(@interpreter.instruction.register).value
end
def test_branch
@ -37,7 +37,7 @@ module Risc
assert_equal Parfait::ReturnAddress , link.class
end
def test_transfer
assert_transfer 12 , :message , :saved_message
assert_transfer 12 , :r0 , :r15
end
def test_sys
assert_syscall 16 , :exit

View File

@ -28,17 +28,17 @@ module Risc
end
def test_load_factory
assert_load( 15 , Parfait::Factory , "id_factory_")
assert_load( 15 , Parfait::Factory , :r1)
assert_equal :next_integer , @instruction.constant.attribute_name
end
def test_load_nil
assert_load( 16 , Parfait::NilClass , "id_nilclass_")
assert_load( 16 , Parfait::NilClass , :r2)
end
def test_slot_receiver #load next_object from factory
assert_slot_to_reg( 17 , "id_factory_" , 2 , "id_factory_.next_object")
assert_slot_to_reg( 17 , :r1 , 2 , :r3)
end
def test_nil_check
assert_operator 18 , :- , "id_nilclass_" , "id_factory_.next_object" , "op_-_"
assert_operator 18 , :- , :r2 , :r3 , :r4
value = @interpreter.get_register(@instruction.result)
assert_equal ::Integer , value.class
assert 0 != value
@ -47,10 +47,10 @@ module Risc
assert_not_zero 19 , "cont_label"
end
def test_load_next_int
assert_slot_to_reg( 20 , "id_factory_.next_object" , 1 , "id_factory_.next_object.next_integer")
assert_slot_to_reg( 20 , :r3 , 1 , :r2)
end
def test_move_next_back_to_factory
assert_reg_to_slot( 21 , "id_factory_.next_object.next_integer" , "id_factory_" , 2)
assert_reg_to_slot( 21 , :r2 , :r1 , 2)
end
end
end

View File

@ -26,16 +26,16 @@ module Risc
assert_equal 1 , get_return
end
def test_op
assert_operator 26 , :- , "message.receiver.data_1" , "message.arg1.data_1" , "op_-_"
assert_operator 26 , :- , :r2 , :r4 , :r1
assert_equal 1 , @interpreter.get_register(@instruction.result)
assert_equal 6 , @interpreter.get_register(:"message.receiver.data_1")
assert_equal 5 , @interpreter.get_register(:"message.arg1.data_1")
assert_equal 6 , @interpreter.get_register(:r2)
assert_equal 5 , @interpreter.get_register(:r4)
end
def test_return
ret = main_ticks(46)
assert_equal FunctionReturn , ret.class
assert_equal :"message.return_address" , ret.register.symbol
assert_equal 36572 , @interpreter.get_register(ret.register).value
assert_equal :r1 , ret.register.symbol
assert_equal 36540 , @interpreter.get_register(ret.register).value
end
end
end

View File

@ -26,9 +26,9 @@ module Risc
end
def test_op
assert_operator 22 , :>>, "message.receiver.data_1" , "integer_1" , "op_>>_"
assert_equal 2 , @interpreter.get_register(:integer_1)
assert_equal 9 , @interpreter.get_register(:"message.receiver.data_1")
assert_operator 22 , :>>, :r2 , :r1 , :r4
assert_equal 2 , @interpreter.get_register(:r1)
assert_equal 9 , @interpreter.get_register(:r2)
end
end
end

View File

@ -30,9 +30,9 @@ module Risc
assert @interpreter.flags[:zero]
end
def test_op
assert_operator 26 , :*, "message.receiver.data_1" , "message.arg1.data_1" , "op_*_"
assert_equal 2147483648 , @interpreter.get_register(:"message.arg1.data_1")
assert_equal 2147483648 , @interpreter.get_register(:"message.receiver.data_1")
assert_operator 26 , :*, :r2 , :r4 , :r1
assert_equal 2147483648 , @interpreter.get_register(:r4)
assert_equal 2147483648 , @interpreter.get_register(:r2)
end
def test_overflow
main_ticks( 26 )

View File

@ -26,14 +26,14 @@ module Risc
assert_equal 10 , get_return
end
def test_op
assert_operator 26, :+ , "message.receiver.data_1" , "message.arg1.data_1" , "op_+_"
assert_operator 26, :+ , :r2 , :r4 , :r1
assert_equal 10 , @interpreter.get_register(@instruction.result.symbol)
end
def test_move_res_to_int
assert_reg_to_slot( 27 , "op_+_" , "id_factory_.next_object" , 2)
assert_reg_to_slot( 27 , :r1 , :r3 , 2)
end
def test_move_int_to_reg
assert_reg_to_slot( 28 , "id_factory_.next_object" , :message , 5)
assert_reg_to_slot( 28 , :r3 , :r0 , 5)
end
end
end

View File

@ -11,7 +11,7 @@ module Risc
end
def test_chain
#show_main_ticks # get output of what is
show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
FunctionCall, LoadConstant, LoadConstant, SlotToReg, OperatorInstruction, #15
@ -48,7 +48,7 @@ module Risc
end
def test_move_sys_return
assert_transfer(26, :syscall_1 ,:integer_tmp)
assert_transfer(26, :r0 ,:r1)
assert_equal 11 , @interpreter.get_register(:integer_tmp)
end
def test_restore_message

View File

@ -12,7 +12,7 @@ module Risc
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #5
check_main_chain [LoadConstant, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #5
SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, #10
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
SlotToReg, LoadConstant, OperatorInstruction, IsZero, SlotToReg, #20
@ -26,7 +26,8 @@ module Risc
Branch, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #60
FunctionReturn, SlotToReg, RegToSlot, Branch, SlotToReg, #65
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn, #70
Transfer, SlotToReg, SlotToReg, Transfer ,Syscall, NilClass,] #75
Transfer, SlotToReg, SlotToReg, Transfer, Syscall, #75
NilClass,] #80
assert_equal ::Integer , get_return.class
assert_equal 1 , get_return
end

View File

@ -18,7 +18,7 @@ module Risc
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn, #25
Transfer, SlotToReg, SlotToReg, Transfer, Syscall, #30
NilClass,] #35
assert_kind_of NilClass , get_return
assert_kind_of Parfait::NilClass , get_return
end
def test_load_false_const
load = main_ticks(1)

View File

@ -54,7 +54,7 @@ module Risc
end
def test_pc
@interpreter.tick
assert_equal t = 36136 , @interpreter.pc
assert_equal t = 36104 , @interpreter.pc
@interpreter.tick
assert_equal t + 4 , @interpreter.pc
end

View File

@ -48,8 +48,8 @@ module Risc
end
def get_return
assert_equal Parfait::Message , @interpreter.get_register(:saved_message).class
@interpreter.get_register(:syscall_1)
assert_equal Parfait::Message , @interpreter.get_register(:r15).class
@interpreter.get_register(:r0)
end
# do as many as given ticks in the main, ie main_at more
@ -98,7 +98,7 @@ module Risc
# get the return from the message (not exit code)
# exit code must be int
def get_message_return
@interpreter.get_register(:message).return_value
@interpreter.get_register(:r15).return_value
end
# wrap the input so it is a main, compile and run it