diff --git a/lib/risc/builtin/object.rb b/lib/risc/builtin/object.rb index 7004cb35..8a8ac27f 100644 --- a/lib/risc/builtin/object.rb +++ b/lib/risc/builtin/object.rb @@ -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 diff --git a/lib/risc/builtin/word.rb b/lib/risc/builtin/word.rb index 282724f6..c094a83c 100644 --- a/lib/risc/builtin/word.rb +++ b/lib/risc/builtin/word.rb @@ -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 diff --git a/test/risc/builtin/test_int_cmp.rb b/test/risc/builtin/test_int_cmp.rb index 7bcfb8c1..e3ed2866 100644 --- a/test/risc/builtin/test_int_cmp.rb +++ b/test/risc/builtin/test_int_cmp.rb @@ -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 diff --git a/test/risc/builtin/test_int_math.rb b/test/risc/builtin/test_int_math.rb index 8984f1d7..30ab9137 100644 --- a/test/risc/builtin/test_int_math.rb +++ b/test/risc/builtin/test_int_math.rb @@ -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 diff --git a/test/risc/interpreter/assign/test_assign_local.rb b/test/risc/interpreter/assign/test_assign_local.rb index 99c5bde9..330b7b4f 100644 --- a/test/risc/interpreter/assign/test_assign_local.rb +++ b/test/risc/interpreter/assign/test_assign_local.rb @@ -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 diff --git a/test/risc/interpreter/assign/test_assign_return.rb b/test/risc/interpreter/assign/test_assign_return.rb index 27df52bc..925dd9d0 100644 --- a/test/risc/interpreter/assign/test_assign_return.rb +++ b/test/risc/interpreter/assign/test_assign_return.rb @@ -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 diff --git a/test/risc/interpreter/assign/test_assign_thrice.rb b/test/risc/interpreter/assign/test_assign_thrice.rb index d821db62..754b5c6c 100644 --- a/test/risc/interpreter/assign/test_assign_thrice.rb +++ b/test/risc/interpreter/assign/test_assign_thrice.rb @@ -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 diff --git a/test/risc/interpreter/assign/test_assign_twice.rb b/test/risc/interpreter/assign/test_assign_twice.rb index a344c509..c2520f73 100644 --- a/test/risc/interpreter/assign/test_assign_twice.rb +++ b/test/risc/interpreter/assign/test_assign_twice.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_div10.rb b/test/risc/interpreter/calling/test_div10.rb index 7137ac59..3b7794b1 100644 --- a/test/risc/interpreter/calling/test_div10.rb +++ b/test/risc/interpreter/calling/test_div10.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_get_byte.rb b/test/risc/interpreter/calling/test_get_byte.rb index fabb85b8..d084cb80 100644 --- a/test/risc/interpreter/calling/test_get_byte.rb +++ b/test/risc/interpreter/calling/test_get_byte.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_minus.rb b/test/risc/interpreter/calling/test_minus.rb index 2a13d790..40db8e2b 100644 --- a/test/risc/interpreter/calling/test_minus.rb +++ b/test/risc/interpreter/calling/test_minus.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_mod.rb b/test/risc/interpreter/calling/test_mod.rb index 24216bc2..a9aa7939 100644 --- a/test/risc/interpreter/calling/test_mod.rb +++ b/test/risc/interpreter/calling/test_mod.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_mult.rb b/test/risc/interpreter/calling/test_mult.rb index 0ee6bf9c..7906ebfd 100644 --- a/test/risc/interpreter/calling/test_mult.rb +++ b/test/risc/interpreter/calling/test_mult.rb @@ -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 ) diff --git a/test/risc/interpreter/calling/test_plus.rb b/test/risc/interpreter/calling/test_plus.rb index bc4ae463..2027d5fa 100644 --- a/test/risc/interpreter/calling/test_plus.rb +++ b/test/risc/interpreter/calling/test_plus.rb @@ -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 diff --git a/test/risc/interpreter/calling/test_puts.rb b/test/risc/interpreter/calling/test_puts.rb index 988e38fd..28e5019b 100644 --- a/test/risc/interpreter/calling/test_puts.rb +++ b/test/risc/interpreter/calling/test_puts.rb @@ -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) diff --git a/test/risc/interpreter/calling/test_set_byte.rb b/test/risc/interpreter/calling/test_set_byte.rb index 26d660b0..c4aef7e0 100644 --- a/test/risc/interpreter/calling/test_set_byte.rb +++ b/test/risc/interpreter/calling/test_set_byte.rb @@ -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 diff --git a/test/risc/interpreter/conditional/test_if_constant.rb b/test/risc/interpreter/conditional/test_if_constant.rb index ec9692f9..2f77b7fc 100644 --- a/test/risc/interpreter/conditional/test_if_constant.rb +++ b/test/risc/interpreter/conditional/test_if_constant.rb @@ -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 diff --git a/test/risc/interpreter/conditional/test_if_greater.rb b/test/risc/interpreter/conditional/test_if_greater.rb index 8fccdba9..55f018a3 100644 --- a/test/risc/interpreter/conditional/test_if_greater.rb +++ b/test/risc/interpreter/conditional/test_if_greater.rb @@ -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 diff --git a/test/risc/interpreter/conditional/test_if_greater_or.rb b/test/risc/interpreter/conditional/test_if_greater_or.rb index 3dfdea3b..c5c134bb 100644 --- a/test/risc/interpreter/conditional/test_if_greater_or.rb +++ b/test/risc/interpreter/conditional/test_if_greater_or.rb @@ -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 diff --git a/test/risc/interpreter/conditional/test_if_smaller.rb b/test/risc/interpreter/conditional/test_if_smaller.rb index 51c9403a..52d8f1e9 100644 --- a/test/risc/interpreter/conditional/test_if_smaller.rb +++ b/test/risc/interpreter/conditional/test_if_smaller.rb @@ -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 diff --git a/test/risc/interpreter/conditional/test_if_smaller_or.rb b/test/risc/interpreter/conditional/test_if_smaller_or.rb index a225857e..2d723319 100644 --- a/test/risc/interpreter/conditional/test_if_smaller_or.rb +++ b/test/risc/interpreter/conditional/test_if_smaller_or.rb @@ -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 diff --git a/test/risc/interpreter/test_dynamic_call.rb b/test/risc/interpreter/test_dynamic_call.rb index f6745591..ff2bc88c 100644 --- a/test/risc/interpreter/test_dynamic_call.rb +++ b/test/risc/interpreter/test_dynamic_call.rb @@ -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 diff --git a/test/risc/interpreter/test_events.rb b/test/risc/interpreter/test_events.rb index 7ee43005..7f11e3f1 100644 --- a/test/risc/interpreter/test_events.rb +++ b/test/risc/interpreter/test_events.rb @@ -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 diff --git a/test/risc/interpreter/test_return.rb b/test/risc/interpreter/test_return.rb index b4b25de8..b8d07243 100644 --- a/test/risc/interpreter/test_return.rb +++ b/test/risc/interpreter/test_return.rb @@ -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 diff --git a/test/risc/interpreter/while/test_while_cmp.rb b/test/risc/interpreter/while/test_while_cmp.rb index a8c837aa..3e0ca8d9 100644 --- a/test/risc/interpreter/while/test_while_cmp.rb +++ b/test/risc/interpreter/while/test_while_cmp.rb @@ -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 diff --git a/test/risc/interpreter/while/test_while_count.rb b/test/risc/interpreter/while/test_while_count.rb index c47c359d..12314ea2 100644 --- a/test/risc/interpreter/while/test_while_count.rb +++ b/test/risc/interpreter/while/test_while_count.rb @@ -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 diff --git a/test/risc/interpreter/while/test_while_simple.rb b/test/risc/interpreter/while/test_while_simple.rb index def6d343..eb66fd7a 100644 --- a/test/risc/interpreter/while/test_while_simple.rb +++ b/test/risc/interpreter/while/test_while_simple.rb @@ -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 diff --git a/test/risc/mains/test_adds.rb b/test/risc/mains/test_adds.rb index ec2347f9..4c9ad3ee 100644 --- a/test/risc/mains/test_adds.rb +++ b/test/risc/mains/test_adds.rb @@ -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 <