From a93a3c8af5170736fad9224bba0e9badf5a65e55 Mon Sep 17 00:00:00 2001 From: Torsten Date: Sun, 22 Mar 2020 10:42:50 +0200 Subject: [PATCH] fix most interpreter tests --- lib/risc/interpreter.rb | 2 +- lib/risc/platform.rb | 2 ++ test/risc/interpreter/assign/test_assign_local.rb | 4 ++-- test/risc/interpreter/calling/test_alloc.rb | 12 ++++++------ test/risc/interpreter/calling/test_minus.rb | 10 +++++----- test/risc/interpreter/calling/test_mod.rb | 6 +++--- test/risc/interpreter/calling/test_mult.rb | 6 +++--- test/risc/interpreter/calling/test_plus.rb | 6 +++--- test/risc/interpreter/calling/test_puts.rb | 4 ++-- test/risc/interpreter/test_dynamic_call.rb | 5 +++-- test/risc/interpreter/while/test_while_simple.rb | 2 +- test/risc/test_interpreter.rb | 2 +- test/support/risc_interpreter.rb | 6 +++--- 13 files changed, 35 insertions(+), 32 deletions(-) diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index 0bf91f2e..10b7aa16 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -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 diff --git a/lib/risc/platform.rb b/lib/risc/platform.rb index 6469ea39..50e4f284 100644 --- a/lib/risc/platform.rb +++ b/lib/risc/platform.rb @@ -40,6 +40,8 @@ module Risc :r0 when :syscall_2 :r1 + when :saved_message + :r15 else nil end diff --git a/test/risc/interpreter/assign/test_assign_local.rb b/test/risc/interpreter/assign/test_assign_local.rb index 60fa8afe..8d325b09 100644 --- a/test/risc/interpreter/assign/test_assign_local.rb +++ b/test/risc/interpreter/assign/test_assign_local.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_alloc.rb b/test/risc/interpreter/calling/test_alloc.rb index d5885b47..5164ec34 100644 --- a/test/risc/interpreter/calling/test_alloc.rb +++ b/test/risc/interpreter/calling/test_alloc.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_minus.rb b/test/risc/interpreter/calling/test_minus.rb index dde868d3..00ba8224 100644 --- a/test/risc/interpreter/calling/test_minus.rb +++ b/test/risc/interpreter/calling/test_minus.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_mod.rb b/test/risc/interpreter/calling/test_mod.rb index b70e4f19..09919045 100644 --- a/test/risc/interpreter/calling/test_mod.rb +++ b/test/risc/interpreter/calling/test_mod.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_mult.rb b/test/risc/interpreter/calling/test_mult.rb index bceef51e..df110163 100644 --- a/test/risc/interpreter/calling/test_mult.rb +++ b/test/risc/interpreter/calling/test_mult.rb @@ -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 ) diff --git a/test/risc/interpreter/calling/test_plus.rb b/test/risc/interpreter/calling/test_plus.rb index 41057e38..80538553 100644 --- a/test/risc/interpreter/calling/test_plus.rb +++ b/test/risc/interpreter/calling/test_plus.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_puts.rb b/test/risc/interpreter/calling/test_puts.rb index 3451d9f5..e60eb513 100644 --- a/test/risc/interpreter/calling/test_puts.rb +++ b/test/risc/interpreter/calling/test_puts.rb @@ -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 diff --git a/test/risc/interpreter/test_dynamic_call.rb b/test/risc/interpreter/test_dynamic_call.rb index 2e9232f3..6b6a6d07 100644 --- a/test/risc/interpreter/test_dynamic_call.rb +++ b/test/risc/interpreter/test_dynamic_call.rb @@ -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 diff --git a/test/risc/interpreter/while/test_while_simple.rb b/test/risc/interpreter/while/test_while_simple.rb index e6119cbd..b1746bed 100644 --- a/test/risc/interpreter/while/test_while_simple.rb +++ b/test/risc/interpreter/while/test_while_simple.rb @@ -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) diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index b5474b2a..339fe706 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -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 diff --git a/test/support/risc_interpreter.rb b/test/support/risc_interpreter.rb index 562ddb74..2b06cdf3 100644 --- a/test/support/risc_interpreter.rb +++ b/test/support/risc_interpreter.rb @@ -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