pass return integer back out through exit

for testing of binaries later (and off course general correctness)
Some tests were using the fact that the interpreter was used, changed those to return ints rather than strings
This commit is contained in:
Torsten Ruger 2018-06-19 18:55:47 +03:00
parent db459fcd3d
commit 5f7683efcf
33 changed files with 174 additions and 152 deletions

View File

@ -71,13 +71,23 @@ module Risc
add_code exit_label
end
compiler.reset_regs
emit_syscall( builder , :exit )
exit_sequence(builder)
return compiler.method
end
# 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 )
end
def exit( context )
compiler = compiler_for(:Object,:exit ,{})
emit_syscall( compiler.builder(true, compiler.method) , :exit )
builder = compiler.builder(true, compiler.method)
exit_sequence(builder)
return compiler.method
end

View File

@ -45,7 +45,8 @@ module Risc
builder.reduce_int( source + " fix me", value )
builder.reduce_int( source + " fix arg", index )
builder.add_reg_to_byte( source , value , me , index)
builder.add_reg_to_slot( source , me , :message , :return_value)
value = builder.load_int_arg_at(source , 1 )
builder.add_reg_to_slot( source , value , :message , :return_value)
compiler.add_mom( Mom::ReturnSequence.new)
return compiler.method
end

View File

@ -6,52 +6,52 @@ module Risc
def test_smaller_true
run_main_return "4 < 5"
assert_equal Parfait::TrueClass , get_return.class
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_smaller_false
run_main_return "6 < 5"
assert_equal Parfait::FalseClass , get_return.class
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_smaller_false_same
run_main_return "5 < 5"
assert_equal Parfait::FalseClass , get_return.class
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_larger_true
run_main_return "5 > 4"
assert_equal Parfait::TrueClass , get_return.class
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_larger_false
run_main_return "5 > 6"
assert_equal Parfait::FalseClass , get_return.class
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_larger_false_same
run_main_return "5 > 5"
assert_equal Parfait::FalseClass , get_return.class
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_smaller_or_true
run_main_return "4 <= 5"
assert_equal Parfait::TrueClass , get_return.class
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_smaller_or_false
run_main_return "6 <= 5"
assert_equal Parfait::FalseClass , get_return.class
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_smaller_or_same
run_main_return "5 <= 5"
assert_equal Parfait::TrueClass , get_return.class
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_larger_or_true
run_main_return "5 >= 4"
assert_equal Parfait::TrueClass , get_return.class
assert_equal Parfait::TrueClass , get_message_return.class
end
def test_larger_or_false
run_main_return "5 >= 6"
assert_equal Parfait::FalseClass , get_return.class
assert_equal Parfait::FalseClass , get_message_return.class
end
def test_larger_or_same
run_main_return "5 >= 5"
assert_equal Parfait::TrueClass , get_return.class
assert_equal Parfait::TrueClass , get_message_return.class
end
end
end

View File

@ -6,36 +6,35 @@ module Risc
def test_add
run_main_return "5 + 5"
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
assert_equal 10 , get_return
end
def test_minus
run_main_return "5 - 5"
assert_equal 0 , get_return.value
assert_equal 0 , get_return
end
def test_minus_neg
run_main_return "5 - 15"
assert_equal -10 , get_return.value
assert_equal -10 , get_return
end
def test_rshift
run_main_return "#{2**8} >> 3"
assert_equal 2**5 , get_return.value
assert_equal 2**5 , get_return
end
def test_lshift
run_main_return "#{2**8} << 3"
assert_equal 2**11 , get_return.value
assert_equal 2**11 , get_return
end
def test_div10
run_main_return "45.div10"
assert_equal 4 , get_return.value
assert_equal 4 , get_return
end
def test_div4
run_main_return "45.div4"
assert_equal 11 , get_return.value
assert_equal 11 , get_return
end
def test_mult
run_main_return "4 * 4"
assert_equal 16 , get_return.value
assert_equal 16 , get_return
end
end
end

View File

@ -13,9 +13,9 @@ 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, Transfer, Syscall,
NilClass]
assert_equal 15 , get_return.value
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_equal 15 , get_return
end
def test_call_main
@ -36,11 +36,11 @@ module Risc
assert_equal Fixnum , link.class
end
def test_transfer
transfer = main_ticks(14)
transfer = main_ticks(17)
assert_equal Transfer , transfer.class
end
def test_sys
sys = main_ticks(15)
sys = main_ticks(18)
assert_equal Syscall , sys.class
end
end

View File

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

View File

@ -35,8 +35,9 @@ module Risc
FunctionReturn, SlotToReg, SlotToReg, RegToSlot, Branch,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
Transfer, Syscall, NilClass]
assert_equal 15 , get_return.value
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
NilClass]
assert_equal 15 , get_return
end
end

View File

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

View File

@ -28,10 +28,9 @@ module Risc
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
Syscall, NilClass]
assert_equal Parfait::Integer , get_return.class
assert_equal 2 , get_return.value
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, Branch, Transfer, Syscall, NilClass]
assert_equal 2 , get_return
end
def test_load_25
@ -46,7 +45,7 @@ module Risc
assert_equal Fixnum , link.class
end
def test_sys
sys = main_ticks(91)
sys = main_ticks(94)
assert_equal Syscall , sys.class
assert_equal :exit , sys.name
end

View File

@ -22,9 +22,9 @@ module Risc
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
Branch, FunctionReturn, Transfer, Syscall, NilClass]
assert_equal Parfait::Integer , get_return.class
assert_equal "H".ord , get_return.value
Branch, FunctionReturn, SlotToReg, SlotToReg, Branch,
Transfer, Syscall, NilClass]
assert_equal "H".ord , get_return
end
def test_byte_to_reg
done = main_ticks(34)
@ -32,7 +32,7 @@ module Risc
assert_equal "H".ord , @interpreter.get_register(done.register)
end
def test_exit
done = main_ticks(64)
done = main_ticks(67)
assert_equal Syscall , done.class
end
end

View File

@ -23,10 +23,9 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, Branch, FunctionReturn, Transfer, Syscall,
NilClass]
assert_equal Parfait::Integer , get_return.class
assert_equal 1 , get_return.value
SlotToReg, Branch, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_equal 1 , get_return
end
def test_load_5
lod = main_ticks( 20 )
@ -49,7 +48,7 @@ module Risc
assert_equal 20580 , @interpreter.get_register(ret.register)
end
def test_sys
sys = main_ticks(65)
sys = main_ticks(68)
assert_equal Syscall , sys.class
assert_equal :exit , sys.name
end

View File

@ -22,9 +22,9 @@ module Risc
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
Branch, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, Transfer, Syscall, NilClass]
assert_equal Parfait::Integer , get_return.class
assert_equal 2 , get_return.value
FunctionReturn, SlotToReg, SlotToReg, Branch, Transfer,
Syscall, NilClass]
assert_equal 2 , get_return
end
def test_load
@ -42,7 +42,7 @@ module Risc
end
def test_sys
sys = main_ticks(58)
sys = main_ticks(61)
assert_equal Syscall , sys.class
assert_equal :exit , sys.name
end

View File

@ -23,10 +23,9 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, Branch, FunctionReturn, Transfer, Syscall,
NilClass]
assert_equal Parfait::Integer , get_return.class
assert_equal 0 , get_return.value
SlotToReg, Branch, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_equal 0 , get_return
end
def test_zero
ticks( 12 )

View File

@ -23,10 +23,9 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, Branch, FunctionReturn, Transfer, Syscall,
NilClass]
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
SlotToReg, Branch, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_equal 10 , get_return
end
def test_load_5
lod = main_ticks( 20 )
@ -103,7 +102,7 @@ module Risc
assert_equal :r4 , sl.register.symbol
end
def test_sys
sys = main_ticks(65)
sys = main_ticks(68)
assert_equal Syscall , sys.class
assert_equal :exit , sys.name
end

View File

@ -11,7 +11,7 @@ module Risc
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
@ -22,11 +22,11 @@ module Risc
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, Syscall,
NilClass]
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_equal "Hello again" , @interpreter.stdout
assert_equal Parfait::Integer , get_return.class
assert_equal 11 , get_return.value #bytes written
assert_equal Fixnum , get_return.class
assert_equal 11 , get_return #bytes written
end
def test_call
cal = main_ticks(24)

View File

@ -19,14 +19,15 @@ module Risc
SlotToReg, RegToSlot, Branch, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, FunctionCall, SlotToReg, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToByte, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, Branch, SlotToReg, SlotToReg, FunctionReturn,
RegToByte, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, Branch, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, Branch, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer,
Branch, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, SlotToReg, SlotToReg, Branch, Transfer,
Syscall, NilClass]
assert_equal Parfait::Word , get_return.class
assert_equal "Kello" , get_return.to_string
assert_equal Fixnum , get_return.class
assert_equal "K".ord , get_return
end
def test_reg_to_byte
done = main_ticks(41)
@ -34,7 +35,7 @@ module Risc
assert_equal "K".ord , @interpreter.get_register(done.register)
end
def test_exit
done = main_ticks(66)
done = main_ticks(71)
assert_equal Syscall , done.class
end

View File

@ -5,7 +5,7 @@ module Risc
include Ticker
def setup
@string_input = as_main 'if( 10 ); return "then";else;return "else";end'
@string_input = as_main 'if( 10 ); return 1;else;return 2;end'
super
end
@ -14,9 +14,10 @@ module Risc
check_main_chain [LoadConstant, LoadConstant, OperatorInstruction, IsZero, LoadConstant,
OperatorInstruction, IsZero, LoadConstant, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, Branch, SlotToReg,
SlotToReg, FunctionReturn, Transfer, Syscall, NilClass]
assert_equal Parfait::Word , get_return.class
assert_equal "then" , get_return.to_string
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, Branch,
Transfer, Syscall, NilClass]
assert_equal Fixnum , get_return.class
assert_equal 1 , get_return
end
def test_load_10
load = main_ticks(1)
@ -39,7 +40,7 @@ module Risc
assert check.label.name.start_with?("false_label") , check.label.name
end
def test_exit
done = main_ticks(19)
done = main_ticks(22)
assert_equal Syscall , done.class
end
end

View File

@ -5,13 +5,13 @@ module Risc
include Ticker
def setup
@string_input = as_main 'if( 5 > 5 ); return "then";else;return "else";end'
@string_input = as_main 'if( 5 > 5 ); return 1;else;return 2;end'
super
end
def test_if
#show_main_ticks # get output of what is in main
check_main_chain [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
check_main_chain [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, Branch, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
@ -24,12 +24,13 @@ module Risc
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
LoadConstant, RegToSlot, SlotToReg, SlotToReg, Branch,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
Transfer, Syscall, NilClass]
assert_equal Parfait::Word , get_return.class
assert_equal "else" , get_return.to_string
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
NilClass]
assert_equal Fixnum , get_return.class
assert_equal 2 , get_return
end
def test_exit
done = main_ticks(67)
done = main_ticks(70)
assert_equal Syscall , done.class
end
end

View File

@ -5,7 +5,7 @@ module Risc
include Ticker
def setup
@string_input = as_main 'if( 5 >= 5 ); return "then";else;return "else";end'
@string_input = as_main 'if( 5 >= 5 ); return 1;else;return 2;end'
super
end
@ -24,13 +24,13 @@ module Risc
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
LoadConstant, OperatorInstruction, IsZero, LoadConstant, Branch,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, Syscall,
NilClass]
assert_equal Parfait::Word , get_return.class
assert_equal "then" , get_return.to_string
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_equal Fixnum , get_return.class
assert_equal 1 , get_return
end
def test_exit
done = main_ticks(70)
done = main_ticks(73)
assert_equal Syscall , done.class
end
end

View File

@ -5,7 +5,7 @@ module Risc
include Ticker
def setup
@string_input = as_main 'if( 5 < 5 ); return "then";else;return "else";end'
@string_input = as_main 'if( 5 < 5 ); return 1;else;return 2;end'
super
end
@ -24,12 +24,13 @@ module Risc
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
LoadConstant, RegToSlot, SlotToReg, SlotToReg, Branch,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
Transfer, Syscall, NilClass]
assert_equal Parfait::Word , get_return.class
assert_equal "else" , get_return.to_string
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
NilClass]
assert_equal Fixnum , get_return.class
assert_equal 2 , get_return
end
def test_exit
done = main_ticks(67)
done = main_ticks(70)
assert_equal Syscall , done.class
end
end

View File

@ -5,7 +5,7 @@ module Risc
include Ticker
def setup
@string_input = as_main 'if( 5 <= 5 ); return "then";else;return "else";end'
@string_input = as_main 'if( 5 <= 5 ); return 1;else;return 2;end'
super
end
@ -24,13 +24,13 @@ module Risc
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
LoadConstant, OperatorInstruction, IsZero, LoadConstant, Branch,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, Syscall,
NilClass]
assert_equal Parfait::Word , get_return.class
assert_equal "then" , get_return.to_string
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_equal Fixnum , get_return.class
assert_equal 1 , get_return
end
def test_exit
done = main_ticks(70)
done = main_ticks(73)
assert_equal Syscall , done.class
end
end

View File

@ -39,9 +39,10 @@ module Risc
FunctionReturn, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, Branch, FunctionReturn,
Transfer, Syscall, NilClass]
assert_equal Parfait::Integer , get_return.class
assert_equal 1 , get_return.value
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
NilClass]
assert_equal Fixnum , get_return.class
assert_equal 1 , get_return
end
def test_call_main
@ -66,7 +67,7 @@ module Risc
assert_equal Fixnum , link.class
end
def test_sys
sys = main_ticks(142)
sys = main_ticks(145)
assert_equal Syscall , sys.class
end
end

View File

@ -19,7 +19,7 @@ module Risc
@instruction_events << was
end
def length
91
94
end
def test_state_change
@interpreter.register_event :state_changed , self
@ -56,10 +56,10 @@ module Risc
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, Branch, FunctionReturn, Transfer,
Syscall, NilClass]
assert_equal Parfait::Integer , get_return.class
assert_equal 12 , get_return.value
SlotToReg, SlotToReg, Branch, FunctionReturn, SlotToReg,
SlotToReg, Branch, Transfer, Syscall, NilClass]
assert_equal Fixnum , get_return.class
assert_equal 12 , get_return
end
def test_length
run_all

View File

@ -12,9 +12,9 @@ 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, Transfer,
Syscall, NilClass]
assert_equal 5 , get_return.value
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, Branch, Transfer, Syscall, NilClass]
assert_equal 5 , get_return
end
def test_call_main
@ -33,12 +33,24 @@ module Risc
link = @interpreter.get_register( ret.register )
assert_equal Fixnum , link.class
end
def test_return_save
save = main_ticks(10)
assert_equal SlotToReg , save.class
assert_equal :r1 , save.register.symbol
assert_equal 5 , save.index
end
def test_return_reduce
save = main_ticks(11)
assert_equal SlotToReg , save.class
assert_equal :r1 , save.register.symbol
assert_equal 2 , save.index
end
def test_transfer
transfer = main_ticks(10)
transfer = main_ticks(13)
assert_equal Transfer , transfer.class
end
def test_sys
sys = main_ticks(11)
sys = main_ticks(14)
assert_equal Syscall , sys.class
end
end

View File

@ -47,13 +47,13 @@ module Risc
SlotToReg, RegToSlot, SlotToReg, SlotToReg, LoadConstant,
OperatorInstruction, IsZero, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, Branch, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, FunctionReturn, Transfer, Syscall,
NilClass]
assert_kind_of Parfait::Integer , get_return
assert_equal 1 , get_return.value
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
Branch, Transfer, Syscall, NilClass]
assert_kind_of Fixnum , get_return
assert_equal 1 , get_return
end
def test_exit
done = main_ticks(185)
done = main_ticks(188)
assert_equal Syscall , done.class
end
end

View File

@ -48,12 +48,13 @@ module Risc
SlotToReg, LoadConstant, OperatorInstruction, IsZero, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, Branch, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
Transfer, Syscall, NilClass]
assert_kind_of Parfait::Integer , get_return
assert_equal 0 , get_return.value
SlotToReg, SlotToReg, Branch, Transfer, Syscall,
NilClass]
assert_kind_of Fixnum , get_return
assert_equal 0 , get_return
end
def test_exit
done = main_ticks(187)
done = main_ticks(190)
assert_equal Syscall , done.class
end
end

View File

@ -17,8 +17,9 @@ module Risc
Branch, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction,
IsZero, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, Transfer, Syscall, NilClass]
assert_kind_of Parfait::FalseClass , get_return
FunctionReturn, SlotToReg, SlotToReg, Branch, Transfer,
Syscall, NilClass]
assert_kind_of Parfait::NilClass , get_return
end
def test_load_false_const
load = main_ticks(1)
@ -54,7 +55,7 @@ module Risc
assert check.label.name.start_with?("merge_label") , check.label.name
end
def test_exit
done = main_ticks(33)
done = main_ticks(36)
assert_equal Syscall , done.class
end
end

View File

@ -13,8 +13,7 @@ module Mains
end
return a
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
assert_equal 10 , get_return
end
def test_ruby_subs
run_main <<HERE
@ -24,8 +23,7 @@ HERE
end
return b
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 0 , get_return.value
assert_equal 0 , get_return
end
def test_ruby_adds_fibo
run_main <<HERE
@ -41,8 +39,7 @@ HERE
end
return result
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 8 , get_return.value
assert_equal 8 , get_return
end
end
end

View File

@ -1,13 +1,12 @@
require_relative 'helper'
module Mains
class TestPuts #< MainsTest
class TestPuts < MainsTest
def test_say_hi
hi = "Hello there"
run_main "'#{hi}'.putstring"
assert_equal Parfait::Integer , get_return.class
assert_equal hi.length , get_return.value
run_main_return "'#{hi}'.putstring"
assert_equal hi.length , get_return
assert_equal hi , @interpreter.stdout
end
end

View File

@ -20,13 +20,11 @@ HERE
end
def test_call_sm
run_space if_cond(8)
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
assert_equal 10 , get_return
end
def test_call_lg
run_space if_cond(18)
assert_equal Parfait::Integer , get_return.class
assert_equal 20 , get_return.value
assert_equal 20 , get_return
end
end
end

View File

@ -18,8 +18,7 @@ module Methods
return down(8)
end
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 1 , get_return.value
assert_equal 1 , get_return
end
def est_fibo
@ -38,8 +37,7 @@ HERE
return fibo_r(8)
end
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 8 , get_return.value
assert_equal 8 , get_return
end
end
end

View File

@ -12,8 +12,7 @@ module Methods
return same(8)
end
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 8 , get_return.value
assert_equal 8 , get_return
end
def test_call_with_call
@ -26,8 +25,7 @@ HERE
return a
end
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 7 , get_return.value
assert_equal 7 , get_return
end
end
end

View File

@ -36,7 +36,7 @@ module Risc
def get_return
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
@interpreter.get_register(:r0).return_value
@interpreter.get_register(:r1)
end
# do as many as given ticks in the main, ie main_at more
@ -78,6 +78,11 @@ module Risc
run_main("return #{input}")
end
# get the return from the message (not exit code)
# exit code must be int
def get_message_return
@interpreter.get_register(:r8).return_value
end
def run_main(input)
@string_input = as_main(input)
do_setup