move message to stack_pointer

changing a bunch of register names
some of which get names now
This commit is contained in:
Torsten 2020-03-22 11:29:56 +02:00
parent a93a3c8af5
commit be684c0c43
17 changed files with 78 additions and 68 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 )

View File

@ -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

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
@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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