fix the exit sequence

was returning wrong register (1, not 0)
also saving the message for test, which changes order as the return value destroys the message
This commit is contained in:
Torsten Ruger 2018-06-19 19:52:06 +03:00
parent 5f7683efcf
commit ce79617875
26 changed files with 57 additions and 65 deletions

@ -146,15 +146,16 @@ module Arm
end
def exit( int_code )
codes = ArmMachine.ldr( :r0 , :r0 , arm_index(Risc.resolve_to_index(:Message , :return_value)) )
syscall int_code , codes
codes = ArmMachine.mov( :r7 , int_code )
codes.append ArmMachine.swi( 0 )
codes
end
private
# syscall is always triggered by swi(0)
# The actual code (ie the index of the kernel function) is in r7
def syscall int_code , codes
def syscall( int_code , codes)
codes.append ArmMachine.mov( :r7 , int_code )
codes.append ArmMachine.swi( 0 )
codes

@ -78,10 +78,10 @@ module Risc
# a sort of inline version of exit method.
# Used by exit and __init__ (so it doesn't have to call it)
def exit_sequence(builder)
r1 = RiscValue.new( :r1 , :Integer )
builder.add_slot_to_reg "get return" , :message , :return_value , r1
builder.reduce_int( "reduce return" , r1)
emit_syscall( builder , :exit )
save_message( builder )
builder.add_slot_to_reg "get return" , :message , :return_value , :message
builder.reduce_int( "reduce return" , :message)
builder.add_code Syscall.new("emit_syscall(exit)", :exit )
end
def exit( context )

@ -13,8 +13,8 @@ module Risc
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
Branch, SlotToReg, Syscall, NilClass]
assert_equal 15 , get_return
end
@ -36,7 +36,7 @@ module Risc
assert_equal Fixnum , link.class
end
def test_transfer
transfer = main_ticks(17)
transfer = main_ticks(14)
assert_equal Transfer , transfer.class
end
def test_sys

@ -23,8 +23,8 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, Branch, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
SlotToReg, Branch, FunctionReturn, Transfer, SlotToReg,
Branch, SlotToReg, Syscall, NilClass]
assert_equal 10 , get_return
end
end

@ -35,7 +35,7 @@ module Risc
FunctionReturn, SlotToReg, SlotToReg, RegToSlot, Branch,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
Transfer, SlotToReg, Branch, SlotToReg, Syscall,
NilClass]
assert_equal 15 , get_return
end

@ -24,8 +24,8 @@ module Risc
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, Branch, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, Branch,
Transfer, Syscall, NilClass]
SlotToReg, FunctionReturn, Transfer, SlotToReg, Branch,
SlotToReg, Syscall, NilClass]
assert_equal 10 , get_return
end
end

@ -28,8 +28,8 @@ module Risc
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, Branch, Transfer, Syscall, NilClass]
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
SlotToReg, Branch, SlotToReg, Syscall, NilClass]
assert_equal 2 , get_return
end

@ -22,8 +22,8 @@ module Risc
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
Branch, FunctionReturn, SlotToReg, SlotToReg, Branch,
Transfer, Syscall, NilClass]
Branch, FunctionReturn, Transfer, SlotToReg, Branch,
SlotToReg, Syscall, NilClass]
assert_equal "H".ord , get_return
end
def test_byte_to_reg

@ -23,8 +23,8 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, Branch, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
SlotToReg, Branch, FunctionReturn, Transfer, SlotToReg,
Branch, SlotToReg, Syscall, NilClass]
assert_equal 1 , get_return
end
def test_load_5

@ -22,7 +22,7 @@ module Risc
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
Branch, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, SlotToReg, SlotToReg, Branch, Transfer,
FunctionReturn, Transfer, SlotToReg, Branch, SlotToReg,
Syscall, NilClass]
assert_equal 2 , get_return
end

@ -23,8 +23,8 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, Branch, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
SlotToReg, Branch, FunctionReturn, Transfer, SlotToReg,
Branch, SlotToReg, Syscall, NilClass]
assert_equal 0 , get_return
end
def test_zero

@ -23,8 +23,8 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, Branch, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
SlotToReg, Branch, FunctionReturn, Transfer, SlotToReg,
Branch, SlotToReg, Syscall, NilClass]
assert_equal 10 , get_return
end
def test_load_5

@ -22,10 +22,9 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
Branch, SlotToReg, Syscall, NilClass]
assert_equal "Hello again" , @interpreter.stdout
assert_equal Fixnum , get_return.class
assert_equal 11 , get_return #bytes written
end
def test_call

@ -24,9 +24,8 @@ module Risc
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
Branch, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, SlotToReg, SlotToReg, Branch, Transfer,
FunctionReturn, Transfer, SlotToReg, Branch, SlotToReg,
Syscall, NilClass]
assert_equal Fixnum , get_return.class
assert_equal "K".ord , get_return
end
def test_reg_to_byte

@ -14,9 +14,8 @@ module Risc
check_main_chain [LoadConstant, LoadConstant, OperatorInstruction, IsZero, LoadConstant,
OperatorInstruction, IsZero, LoadConstant, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, Branch, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, Branch,
Transfer, Syscall, NilClass]
assert_equal Fixnum , get_return.class
SlotToReg, FunctionReturn, Transfer, SlotToReg, Branch,
SlotToReg, Syscall, NilClass]
assert_equal 1 , get_return
end
def test_load_10

@ -24,9 +24,8 @@ module Risc
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
LoadConstant, RegToSlot, SlotToReg, SlotToReg, Branch,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
Transfer, SlotToReg, Branch, SlotToReg, Syscall,
NilClass]
assert_equal Fixnum , get_return.class
assert_equal 2 , get_return
end
def test_exit

@ -24,9 +24,8 @@ module Risc
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
LoadConstant, OperatorInstruction, IsZero, LoadConstant, Branch,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_equal Fixnum , get_return.class
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
Branch, SlotToReg, Syscall, NilClass]
assert_equal 1 , get_return
end
def test_exit

@ -24,9 +24,8 @@ module Risc
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
LoadConstant, RegToSlot, SlotToReg, SlotToReg, Branch,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
Transfer, SlotToReg, Branch, SlotToReg, Syscall,
NilClass]
assert_equal Fixnum , get_return.class
assert_equal 2 , get_return
end
def test_exit

@ -24,9 +24,8 @@ module Risc
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
LoadConstant, OperatorInstruction, IsZero, LoadConstant, Branch,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_equal Fixnum , get_return.class
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
Branch, SlotToReg, Syscall, NilClass]
assert_equal 1 , get_return
end
def test_exit

@ -39,7 +39,7 @@ module Risc
FunctionReturn, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, Branch, FunctionReturn,
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
Transfer, SlotToReg, Branch, SlotToReg, Syscall,
NilClass]
assert_equal Fixnum , get_return.class
assert_equal 1 , get_return

@ -56,8 +56,8 @@ module Risc
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, Branch, FunctionReturn, SlotToReg,
SlotToReg, Branch, Transfer, Syscall, NilClass]
SlotToReg, SlotToReg, Branch, FunctionReturn, Transfer,
SlotToReg, Branch, SlotToReg, Syscall, NilClass]
assert_equal Fixnum , get_return.class
assert_equal 12 , get_return
end

@ -12,8 +12,8 @@ module Risc
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, Branch, Transfer, Syscall, NilClass]
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
SlotToReg, Branch, SlotToReg, Syscall, NilClass]
assert_equal 5 , get_return
end
@ -33,22 +33,22 @@ module Risc
link = @interpreter.get_register( ret.register )
assert_equal Fixnum , link.class
end
def test_transfer
transfer = main_ticks(10)
assert_equal Transfer , transfer.class
end
def test_return_save
save = main_ticks(10)
save = main_ticks(11)
assert_equal SlotToReg , save.class
assert_equal :r1 , save.register.symbol
assert_equal :r0 , save.register.symbol
assert_equal 5 , save.index
end
def test_return_reduce
save = main_ticks(11)
save = main_ticks(13)
assert_equal SlotToReg , save.class
assert_equal :r1 , save.register.symbol
assert_equal :r0 , save.register.symbol
assert_equal 2 , save.index
end
def test_transfer
transfer = main_ticks(13)
assert_equal Transfer , transfer.class
end
def test_sys
sys = main_ticks(14)
assert_equal Syscall , sys.class

@ -47,9 +47,8 @@ module Risc
SlotToReg, RegToSlot, SlotToReg, SlotToReg, LoadConstant,
OperatorInstruction, IsZero, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, Branch, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_kind_of Fixnum , get_return
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
Branch, SlotToReg, Syscall, NilClass]
assert_equal 1 , get_return
end
def test_exit

@ -48,9 +48,8 @@ module Risc
SlotToReg, LoadConstant, OperatorInstruction, IsZero, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, Branch, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
Transfer, SlotToReg, Branch, SlotToReg, Syscall,
NilClass]
assert_kind_of Fixnum , get_return
assert_equal 0 , get_return
end
def test_exit

@ -17,7 +17,7 @@ module Risc
Branch, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction,
IsZero, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, SlotToReg, SlotToReg, Branch, Transfer,
FunctionReturn, Transfer, SlotToReg, Branch, SlotToReg,
Syscall, NilClass]
assert_kind_of Parfait::NilClass , get_return
end

@ -35,8 +35,8 @@ module Risc
end
def get_return
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
@interpreter.get_register(:r1)
assert_equal Parfait::Message , @interpreter.get_register(:r8).class
@interpreter.get_register(:r0)
end
# do as many as given ticks in the main, ie main_at more