From be684c0c434d03ec5beb3f492a51135d31a8281c Mon Sep 17 00:00:00 2001 From: Torsten Date: Sun, 22 Mar 2020 11:29:56 +0200 Subject: [PATCH] move message to stack_pointer changing a bunch of register names some of which get names now --- lib/risc/interpreter.rb | 10 +++++- lib/risc/platform.rb | 6 ++-- .../interpreter/assign/test_assign_local.rb | 4 +-- .../interpreter/blocks/test_assign_outer.rb | 31 +++++++++---------- .../interpreter/blocks/test_block_return.rb | 19 ++++++------ test/risc/interpreter/calling/test_alloc.rb | 12 +++---- test/risc/interpreter/calling/test_minus.rb | 8 ++--- 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 | 14 ++++----- test/risc/test_collector.rb | 4 +-- test/risc/test_interpreter.rb | 4 +++ test/risc/test_method_compiler.rb | 2 +- test/risc/test_platform.rb | 4 +-- test/risc/test_standard_allocator.rb | 2 +- test/support/risc_interpreter.rb | 8 +++-- 17 files changed, 78 insertions(+), 68 deletions(-) diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index 10b7aa16..2e27c04d 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -47,6 +47,14 @@ module Risc trigger(:state_changed , old , state ) end + # return the name of the register that the argument is mapped to + # this info is in the Platform object in the linker instance + # eg: syscall_1 maps to :r0 , and :message to :r13 + # So as not to hardcode values (as used to ) + def std_reg(name) + @linker.platform.assign_reg?(name) + end + # set all flags to false def reset_flags @flags = { :zero => false , :plus => false , @@ -258,7 +266,7 @@ module Risc set_instruction(nil) return false when :died - raise "Method #{@registers[:r1]} not found for #{@registers[:r0].receiver}" + raise "Method #{@registers[std_reg(:syscall_2)]} not found for #{@registers[std_reg(:syscall_2)]}" else raise "un-implemented syscall #{name}" end diff --git a/lib/risc/platform.rb b/lib/risc/platform.rb index 50e4f284..0e18180f 100644 --- a/lib/risc/platform.rb +++ b/lib/risc/platform.rb @@ -20,7 +20,7 @@ module Risc # does not include :message # could be in interpreter and arm, but here for now def register_names - (1 ... 16).collect{|i| "r#{i}".to_sym } + (0 .. 12).collect{|i| "r#{i}".to_sym } end # return the Allocator for the platform @@ -35,13 +35,13 @@ module Risc def assign_reg?(name) case name when :message - :r0 + :r13 when :syscall_1 :r0 when :syscall_2 :r1 when :saved_message - :r15 + :r14 else nil end diff --git a/test/risc/interpreter/assign/test_assign_local.rb b/test/risc/interpreter/assign/test_assign_local.rb index 8d325b09..4672756b 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 , :r1 + assert_load 1 , Parfait::Integer , :r0 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 , :r0 , :r15 + assert_transfer 12 , :r13 , :r14 end def test_sys assert_syscall 16 , :exit diff --git a/test/risc/interpreter/blocks/test_assign_outer.rb b/test/risc/interpreter/blocks/test_assign_outer.rb index 7f0a0dd8..0bca7b70 100644 --- a/test/risc/interpreter/blocks/test_assign_outer.rb +++ b/test/risc/interpreter/blocks/test_assign_outer.rb @@ -16,16 +16,15 @@ module Risc RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #15 FunctionCall, LoadConstant, SlotToReg, OperatorInstruction, IsZero, #20 SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #25 - RegToSlot, SlotToReg, LoadConstant, RegToSlot, SlotToReg, #30 + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #30 SlotToReg, DynamicJump, LoadConstant, SlotToReg, SlotToReg, #35 RegToSlot, LoadConstant, RegToSlot, Branch, SlotToReg, #40 - SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, #45 - FunctionReturn, SlotToReg, RegToSlot, Branch, SlotToReg, #50 - SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, #55 - FunctionReturn, SlotToReg, RegToSlot, Branch, SlotToReg, #60 - SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, #65 - FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, #70 - NilClass,] #75 + SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn, #45 + SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, #50 + RegToSlot, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, #55 + RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, #60 + SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, #65 + SlotToReg, Transfer, Syscall, NilClass,] #70 assert_equal 10 , get_return end def base ; 32 ; end @@ -36,23 +35,21 @@ module Risc assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class end def test_block_load - load_ins = main_ticks(base+1) - assert_load load_ins , Parfait::Integer , :r1 - assert_equal 10 , @interpreter.get_register(load_ins.register).value + assert_load base+1 , Parfait::Integer , :r0 + assert_equal 10 , @interpreter.get_register(risc(base+1).register).value end def test_block_slot1 - assert_slot_to_reg main_ticks(base+2) ,:r0 , 6 , :r2 + assert_slot_to_reg base+2 ,:r13 , 6 , :r1 end def test_block_slot2 - assert_slot_to_reg main_ticks(base+3) ,:r2 , 6 , :r2 + assert_slot_to_reg base+3 ,:r1 , 6 , :r2 end def test_block_reg - assert_reg_to_slot main_ticks(base+4) ,:r1 , :r2 , 16 + assert_reg_to_slot base+4 ,:r0 , :r2 , 16 end def test_ret_load - load_ins = main_ticks(base+5) - assert_load load_ins , Parfait::Integer , :r1 - assert_equal 15 , @interpreter.get_register(load_ins.register).value + assert_load base+5 , Parfait::Integer , :r0 + assert_equal 15 , @interpreter.get_register(risc(base+5).register).value end end end diff --git a/test/risc/interpreter/blocks/test_block_return.rb b/test/risc/interpreter/blocks/test_block_return.rb index 07224121..fc3ad46f 100644 --- a/test/risc/interpreter/blocks/test_block_return.rb +++ b/test/risc/interpreter/blocks/test_block_return.rb @@ -15,21 +15,20 @@ module Risc RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #10 SlotToReg, RegToSlot, SlotToReg, FunctionCall, LoadConstant, #15 SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, #20 - RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, #25 - LoadConstant, RegToSlot, SlotToReg, SlotToReg, DynamicJump, #30 + RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #25 + SlotToReg, RegToSlot, SlotToReg, SlotToReg, DynamicJump, #30 LoadConstant, RegToSlot, Branch, SlotToReg, SlotToReg, #35 - RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, #40 - SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, #45 - RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, #50 - SlotToReg, RegToSlot, SlotToReg, RegToSlot, Branch, #55 - SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #60 - SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg, #65 - Syscall, NilClass,] #70 + RegToSlot, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, #40 + RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, #45 + SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot, #50 + SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, #55 + RegToSlot, SlotToReg, SlotToReg, FunctionReturn, Transfer, #60 + SlotToReg, SlotToReg, Transfer, Syscall, NilClass,] #65 assert_equal 15 , get_return end def test_load_return - load_ins = main_ticks(26) + load_ins = main_ticks(25) assert_equal LoadConstant , load_ins.class assert_equal Parfait::ReturnAddress , @interpreter.get_register(load_ins.register).class end diff --git a/test/risc/interpreter/calling/test_alloc.rb b/test/risc/interpreter/calling/test_alloc.rb index 5164ec34..3ae0968e 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 , :r1) + assert_load( 15 , Parfait::Factory , :r0) assert_equal :next_integer , @instruction.constant.attribute_name end def test_load_nil - assert_load( 16 , Parfait::NilClass , :r2) + assert_load( 16 , Parfait::NilClass , :r1) end def test_slot_receiver #load next_object from factory - assert_slot_to_reg( 17 , :r1 , 2 , :r3) + assert_slot_to_reg( 17 , :r0 , 2 , :r2) end def test_nil_check - assert_operator 18 , :- , :r2 , :r3 , :r4 + assert_operator 18 , :- , :r1 , :r2 , :r3 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 , :r3 , 1 , :r2) + assert_slot_to_reg( 20 , :r2 , 1 , :r1) end def test_move_next_back_to_factory - assert_reg_to_slot( 21 , :r2 , :r1 , 2) + assert_reg_to_slot( 21 , :r1 , :r0 , 2) end end end diff --git a/test/risc/interpreter/calling/test_minus.rb b/test/risc/interpreter/calling/test_minus.rb index 00ba8224..463f91fe 100644 --- a/test/risc/interpreter/calling/test_minus.rb +++ b/test/risc/interpreter/calling/test_minus.rb @@ -26,15 +26,15 @@ module Risc assert_equal 1 , get_return end def test_op - assert_operator 26 , :- , :r2 , :r4 , :r1 + assert_operator 26 , :- , :r1 , :r3 , :r0 assert_equal 1 , @interpreter.get_register(@instruction.result) - assert_equal 6 , @interpreter.get_register(:r2) - assert_equal 5 , @interpreter.get_register(:r4) + assert_equal 6 , @interpreter.get_register(:r1) + assert_equal 5 , @interpreter.get_register(:r3) end def test_return ret = main_ticks(46) assert_equal FunctionReturn , ret.class - assert_equal :r1 , ret.register.symbol + assert_equal :r0 , ret.register.symbol assert_equal 36540 , @interpreter.get_register(ret.register).value end end diff --git a/test/risc/interpreter/calling/test_mod.rb b/test/risc/interpreter/calling/test_mod.rb index 09919045..58395a4e 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 , :>>, :r2 , :r1 , :r4 - assert_equal 2 , @interpreter.get_register(:r1) - assert_equal 9 , @interpreter.get_register(:r2) + assert_operator 22 , :>>, :r1 , :r0 , :r3 + assert_equal 2 , @interpreter.get_register(:r0) + assert_equal 9 , @interpreter.get_register(:r1) end end end diff --git a/test/risc/interpreter/calling/test_mult.rb b/test/risc/interpreter/calling/test_mult.rb index df110163..b1eb4dd8 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 , :*, :r2 , :r4 , :r1 - assert_equal 2147483648 , @interpreter.get_register(:r4) - assert_equal 2147483648 , @interpreter.get_register(:r2) + assert_operator 26 , :*, :r1 , :r3 , :r0 + assert_equal 2147483648 , @interpreter.get_register(:r3) + assert_equal 2147483648 , @interpreter.get_register(:r1) 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 80538553..e3cdb918 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, :+ , :r2 , :r4 , :r1 + assert_operator 26, :+ , :r1 , :r3 , :r0 assert_equal 10 , @interpreter.get_register(@instruction.result.symbol) end def test_move_res_to_int - assert_reg_to_slot( 27 , :r1 , :r3 , 2) + assert_reg_to_slot( 27 , :r0 , :r2 , 2) end def test_move_int_to_reg - assert_reg_to_slot( 28 , :r3 , :r0 , 5) + assert_reg_to_slot( 28 , :r2 , :r13 , 5) end end end diff --git a/test/risc/interpreter/calling/test_puts.rb b/test/risc/interpreter/calling/test_puts.rb index e60eb513..f29bbcf9 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 @@ -25,7 +25,7 @@ module Risc SlotToReg, Transfer, Syscall, NilClass,] #55 assert_equal "Hello again" , @interpreter.stdout assert_equal Integer , get_return.class - assert_equal 11 , get_return #bytes written + assert_equal 11 , get_return.to_string #bytes written end def test_call cal = main_ticks(11) @@ -35,9 +35,9 @@ module Risc def test_pre_sys done = main_ticks(24) - assert_equal Parfait::Word , @interpreter.get_register(:syscall_1).class - assert_equal "Hello again" , @interpreter.get_register(:syscall_1).to_string - assert_equal 11 , @interpreter.get_register(:syscall_2) + assert_equal Parfait::Word , @interpreter.get_register(:r0).class + assert_equal "Hello again" , @interpreter.get_register(:r0).to_string + assert_equal 11 , @interpreter.get_register(:r1) end def test_sys @@ -52,8 +52,8 @@ module Risc assert_equal 11 , @interpreter.get_register(:integer_tmp) end def test_restore_message - assert_transfer(27, :saved_message ,:message) - assert_equal Parfait::Message , @interpreter.get_register(:message).class + assert_transfer(27, :r14 ,:r13) + assert_equal Parfait::Message , @interpreter.get_register(:r13).class end def test_return done = main_ticks(48) diff --git a/test/risc/test_collector.rb b/test/risc/test_collector.rb index 7c62668e..fec8e424 100644 --- a/test/risc/test_collector.rb +++ b/test/risc/test_collector.rb @@ -38,7 +38,7 @@ module Risc end def len - 1427 + 1426 end def test_collect_all_types @@ -70,7 +70,7 @@ module Risc end def len - 2907 + 2906 end end end diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index 339fe706..24819362 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -45,6 +45,10 @@ module Risc @string_input = as_main("return 5") super end + def test_mapping + assert_equal :r0 , @interpreter.std_reg(:syscall_1) + assert_equal :r13 , @interpreter.std_reg(:message) + end def test_tick1 assert_equal 2 , @interpreter.tick end diff --git a/test/risc/test_method_compiler.rb b/test/risc/test_method_compiler.rb index 9d309cbb..6877453f 100644 --- a/test/risc/test_method_compiler.rb +++ b/test/risc/test_method_compiler.rb @@ -23,7 +23,7 @@ module Risc assert_equal :meth , cpu.callable.name end def test_translate_method - ass = @compiler.translate_method(Platform.for(:arm).translator , []) + ass = @compiler.translate_method(Platform.for(:arm) , []) assert_equal Array , ass.class assert_equal Assembler , ass.first.class assert_equal :meth , ass.first.callable.name diff --git a/test/risc/test_platform.rb b/test/risc/test_platform.rb index 6071eb1f..6cccda7c 100644 --- a/test/risc/test_platform.rb +++ b/test/risc/test_platform.rb @@ -17,7 +17,7 @@ module Risc assert_equal FakeCompiler , allocator.compiler.class end def test_map_message - assert_equal :r0 , Platform.new.assign_reg?(:message) + assert_equal :r13 , Platform.new.assign_reg?(:message) end def test_map_sys assert_equal :r0 , Platform.new.assign_reg?(:syscall_1) @@ -26,7 +26,7 @@ module Risc assert_nil Platform.new.assign_reg?(:id_some_id) end def test_names_len - assert_equal 15 , Platform.new.register_names.length + assert_equal 13 , Platform.new.register_names.length end def test_names_r assert_equal "r" , Platform.new.register_names.first.to_s[0] diff --git a/test/risc/test_standard_allocator.rb b/test/risc/test_standard_allocator.rb index 8afeeb05..9282efa4 100644 --- a/test/risc/test_standard_allocator.rb +++ b/test/risc/test_standard_allocator.rb @@ -14,7 +14,7 @@ module Risc assert_equal Hash , @allocator.used_regs.class end def test_reg_names - assert_equal 15 , @allocator.reg_names.length + assert_equal 13 , @allocator.reg_names.length end def test_compiler assert_equal CallableCompiler , @allocator.compiler.class diff --git a/test/support/risc_interpreter.rb b/test/support/risc_interpreter.rb index 2b06cdf3..1470cf86 100644 --- a/test/support/risc_interpreter.rb +++ b/test/support/risc_interpreter.rb @@ -47,9 +47,11 @@ module Risc Risc.init_length end + # the return of syscall should be an integer def get_return - assert_equal Parfait::Message , @interpreter.get_register(:r15).class - @interpreter.get_register(:r0) + saved_in = @interpreter.std_reg(:saved_message) + assert_equal Parfait::Message , @interpreter.get_register(saved_in).class + @interpreter.get_register(@interpreter.std_reg(:syscall_1)) end # do as many as given ticks in the main, ie main_at more @@ -98,7 +100,7 @@ module Risc # get the return from the message (not exit code) # exit code must be int def get_message_return - @interpreter.get_register(:r15).return_value + @interpreter.get_register(@interpreter.std_reg(:saved_message)).return_value end # wrap the input so it is a main, compile and run it