From 5a43cbff15bb4b56475450956d75d5c874669293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Sat, 17 Aug 2019 23:29:42 +0300 Subject: [PATCH] Fixing tests for implicit return previous commit affected rather many test, as the implicit returns add extra instructions Also added some explicit returns, so as not to test the return logic too much. return (ie return nl) is a knonwn 3 risc operation. --- lib/parfait/object.rb | 2 +- test/mom/assign/test_assign_arg_const.rb | 4 +- test/mom/assign/test_assign_ivar_const.rb | 4 +- test/mom/assign/test_assign_local_arg.rb | 5 +- test/mom/assign/test_assign_local_false.rb | 4 +- test/mom/assign/test_assign_local_int.rb | 4 +- test/mom/assign/test_assign_local_ivar.rb | 4 +- test/mom/assign/test_assign_local_send.rb | 5 +- test/mom/blocks/test_block_setup.rb | 4 +- test/mom/send/test_send_dynamic.rb | 2 +- test/mom/send/test_send_simple.rb | 2 +- test/mom/send/test_send_simple_args.rb | 2 +- test/mom/send/test_setup_simple.rb | 6 +-- test/mom/test_if_else.rb | 5 +- test/mom/test_if_no_else.rb | 5 +- test/mom/test_if_no_if.rb | 5 +- test/mom/test_instruction.rb | 2 +- test/mom/test_method_compiler.rb | 4 +- test/mom/test_return_sequence.rb | 6 +-- test/mom/test_while_cmp.rb | 5 +- test/mom/test_while_simple.rb | 9 ++-- test/risc/test_method_compiler.rb | 10 ++-- test/ruby/test_method_statement.rb | 17 ------- test/ruby/test_method_statement2.rb | 53 ++++++++++++++++++++++ test/rubyx/parfait/test_object.rb | 9 ++-- test/support/compiling.rb | 1 - test/vool/class_send/helper.rb | 6 +-- test/vool/send/helper.rb | 5 +- test/vool/send/test_not_found.rb | 3 +- test/vool/send/test_send_args_send.rb | 6 +-- test/vool/send/test_send_cached_simple.rb | 5 +- test/vool/send/test_send_self.rb | 2 +- test/vool/send/test_send_simple.rb | 2 +- test/vool/send/test_send_simple_args.rb | 6 +-- test/vool/send/test_send_simple_string.rb | 2 +- test/vool/test_assignment.rb | 10 ++-- test/vool/test_class_statement.rb | 6 +-- test/vool/test_if_no_else.rb | 6 +-- test/vool/test_if_no_if.rb | 4 +- test/vool/test_if_simple.rb | 4 +- test/vool/test_if_statement.rb | 4 +- test/vool/test_while_statement.rb | 4 +- test/vool/test_while_statement1.rb | 5 +- 43 files changed, 152 insertions(+), 107 deletions(-) create mode 100644 test/ruby/test_method_statement2.rb diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index f107d393..4b26fd42 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -73,7 +73,7 @@ def self.padded( len ) a = 32 * (1 + ((len + 3)/32).floor ) #puts "#{a} for #{len}" - a + return a end def self.padded_words( words ) diff --git a/test/mom/assign/test_assign_arg_const.rb b/test/mom/assign/test_assign_arg_const.rb index 17dfd22f..bc5f4777 100644 --- a/test/mom/assign/test_assign_arg_const.rb +++ b/test/mom/assign/test_assign_arg_const.rb @@ -6,8 +6,8 @@ module Risc def setup super - @input = "arg = 5" - @expect = [LoadConstant, SlotToReg, RegToSlot] + @input = "arg = 5;return" + @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, Branch] end def test_local_assign_instructions assert_nil msg = check_nil , msg diff --git a/test/mom/assign/test_assign_ivar_const.rb b/test/mom/assign/test_assign_ivar_const.rb index b324985a..396c0599 100644 --- a/test/mom/assign/test_assign_ivar_const.rb +++ b/test/mom/assign/test_assign_ivar_const.rb @@ -6,8 +6,8 @@ module Risc def setup super - @input = "@ivar = 5" - @expect = [LoadConstant, SlotToReg, RegToSlot] + @input = "@ivar = 5;return" + @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, Branch] end def test_local_assign_instructions diff --git a/test/mom/assign/test_assign_local_arg.rb b/test/mom/assign/test_assign_local_arg.rb index baa3e6f2..a80555e6 100644 --- a/test/mom/assign/test_assign_local_arg.rb +++ b/test/mom/assign/test_assign_local_arg.rb @@ -6,8 +6,9 @@ module Risc def setup super - @input = "local = arg" - @expect = [SlotToReg, SlotToReg, SlotToReg, RegToSlot] + @input = "local = arg; return local" + @expect = [SlotToReg, SlotToReg, SlotToReg, RegToSlot, SlotToReg, #4 + SlotToReg, RegToSlot, Branch] #9 end def test_local_assign_instructions assert_nil msg = check_nil , msg diff --git a/test/mom/assign/test_assign_local_false.rb b/test/mom/assign/test_assign_local_false.rb index fd8ad78b..8d5114da 100644 --- a/test/mom/assign/test_assign_local_false.rb +++ b/test/mom/assign/test_assign_local_false.rb @@ -6,8 +6,8 @@ module Risc def setup super - @input = "r = false" - @expect = [LoadConstant,SlotToReg, RegToSlot] + @input = "r = false;return" + @expect = [LoadConstant,SlotToReg, RegToSlot,LoadConstant, RegToSlot, Branch] end def test_local_assign_instructions assert_nil msg = check_nil , msg diff --git a/test/mom/assign/test_assign_local_int.rb b/test/mom/assign/test_assign_local_int.rb index be51beb8..e7b960a1 100644 --- a/test/mom/assign/test_assign_local_int.rb +++ b/test/mom/assign/test_assign_local_int.rb @@ -6,8 +6,8 @@ module Risc def setup super - @input = "r = 5" - @expect = [LoadConstant,SlotToReg, RegToSlot] + @input = "r = 5;return" + @expect = [LoadConstant,SlotToReg, RegToSlot, LoadConstant, RegToSlot, Branch] end def test_local_assign_instructions assert_nil msg = check_nil , msg diff --git a/test/mom/assign/test_assign_local_ivar.rb b/test/mom/assign/test_assign_local_ivar.rb index 3bfb4897..fa60f856 100644 --- a/test/mom/assign/test_assign_local_ivar.rb +++ b/test/mom/assign/test_assign_local_ivar.rb @@ -6,9 +6,9 @@ module Risc def setup super - @input = "@ivar = 5 ; r = @ivar" + @input = "@ivar = 5 ; r = @ivar;return" @expect = [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg , - RegToSlot] + RegToSlot, LoadConstant, RegToSlot, Branch] end def test_local_assign_instructions assert_nil msg = check_nil , msg diff --git a/test/mom/assign/test_assign_local_send.rb b/test/mom/assign/test_assign_local_send.rb index a12e1003..4ef0081f 100644 --- a/test/mom/assign/test_assign_local_send.rb +++ b/test/mom/assign/test_assign_local_send.rb @@ -6,11 +6,12 @@ module Risc def setup super - @input = "r = 5.div4" + @input = "r = 5.div4;return" @expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, - FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot] + FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot, + LoadConstant, RegToSlot, Branch] end def test_local_assign_instructions assert_nil msg = check_nil , msg diff --git a/test/mom/blocks/test_block_setup.rb b/test/mom/blocks/test_block_setup.rb index f735989d..20d1bb2a 100644 --- a/test/mom/blocks/test_block_setup.rb +++ b/test/mom/blocks/test_block_setup.rb @@ -7,12 +7,12 @@ module Risc def setup super @input = as_block("return 5") - @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #4 + @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #4 RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #9 RegToSlot, RegToSlot, RegToSlot, RegToSlot, SlotToReg, #14 SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, #19 SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #24 - SlotToReg, FunctionCall, Label] + SlotToReg, FunctionCall, Label] #29 end def test_send_instructions diff --git a/test/mom/send/test_send_dynamic.rb b/test/mom/send/test_send_dynamic.rb index b30df512..fda2837d 100644 --- a/test/mom/send/test_send_dynamic.rb +++ b/test/mom/send/test_send_dynamic.rb @@ -18,7 +18,7 @@ module Risc SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #44 RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #49 LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #54 - SlotToReg, DynamicJump, Label] + SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, Branch] end def test_send_instructions diff --git a/test/mom/send/test_send_simple.rb b/test/mom/send/test_send_simple.rb index 02415527..50803a6a 100644 --- a/test/mom/send/test_send_simple.rb +++ b/test/mom/send/test_send_simple.rb @@ -10,7 +10,7 @@ module Risc @expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, - FunctionCall, Label] + FunctionCall, Label, SlotToReg, RegToSlot, Branch] end def test_send_instructions diff --git a/test/mom/send/test_send_simple_args.rb b/test/mom/send/test_send_simple_args.rb index bfafde3a..20eeecc8 100644 --- a/test/mom/send/test_send_simple_args.rb +++ b/test/mom/send/test_send_simple_args.rb @@ -11,7 +11,7 @@ module Risc RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, - Label] + Label, SlotToReg, RegToSlot, Branch] end def test_send_instructions diff --git a/test/mom/send/test_setup_simple.rb b/test/mom/send/test_setup_simple.rb index 54d29464..c643e07a 100644 --- a/test/mom/send/test_setup_simple.rb +++ b/test/mom/send/test_setup_simple.rb @@ -6,11 +6,11 @@ module Risc def setup super - @input = "5.div4" + @input = "return 5.div4" @expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, - FunctionCall, Label] + FunctionCall, Label, SlotToReg, RegToSlot, Branch] @produced = produce_body end @@ -51,7 +51,7 @@ module Risc assert_reg_to_slot( sl , :r1 , :r3 , 7 ) end def test_label - sl = @produced.next( 17 ) + sl = @produced.next( 20 ) assert_equal Risc::Label , sl.class assert_equal "return_label" , sl.name end diff --git a/test/mom/test_if_else.rb b/test/mom/test_if_else.rb index 4aa90156..158f7414 100644 --- a/test/mom/test_if_else.rb +++ b/test/mom/test_if_else.rb @@ -6,11 +6,12 @@ module Risc def setup super - @input = "if(@a) ; arg = 5 ; else; arg = 6; end" + @input = "if(@a) ; arg = 5 ; else; arg = 6; end;return" @expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label, LoadConstant, - SlotToReg, RegToSlot, Label] + SlotToReg, RegToSlot, Label, LoadConstant, #34 + RegToSlot, Branch] end def test_if_instructions diff --git a/test/mom/test_if_no_else.rb b/test/mom/test_if_no_else.rb index 79582afb..c1034c01 100644 --- a/test/mom/test_if_no_else.rb +++ b/test/mom/test_if_no_else.rb @@ -6,10 +6,11 @@ module Risc def setup super - @input = "if(@a) ; arg = 5 ; end" + @input = "if(@a) ; arg = 5 ; end;return" @expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, - SlotToReg, RegToSlot, Label] + SlotToReg, RegToSlot, Label, LoadConstant, #34 + RegToSlot, Branch] end def test_if_instructions diff --git a/test/mom/test_if_no_if.rb b/test/mom/test_if_no_if.rb index ca63c8cf..7b6721b5 100644 --- a/test/mom/test_if_no_if.rb +++ b/test/mom/test_if_no_if.rb @@ -6,10 +6,11 @@ module Risc def setup super - @input = "unless(@a) ; arg = 5 ; end" + @input = "unless(@a) ; arg = 5 ; end;return" @expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4 LoadConstant, OperatorInstruction, IsZero, Label, Branch, #9 - Label, LoadConstant, SlotToReg, RegToSlot, Label] #14 + Label, LoadConstant, SlotToReg, RegToSlot, Label, LoadConstant, #34 + RegToSlot, Branch] #14 end def test_if_instructions diff --git a/test/mom/test_instruction.rb b/test/mom/test_instruction.rb index 82b0d5d7..e5dc8c67 100644 --- a/test/mom/test_instruction.rb +++ b/test/mom/test_instruction.rb @@ -14,7 +14,7 @@ module Mom assert_nil Instruction.new("Hi").next end def test_raise - assert_raises {Instruction.new(5)} + assert_raises {Instruction.new(5)} end end end diff --git a/test/mom/test_method_compiler.rb b/test/mom/test_method_compiler.rb index 9ccf5d1d..8e845238 100644 --- a/test/mom/test_method_compiler.rb +++ b/test/mom/test_method_compiler.rb @@ -7,7 +7,7 @@ module Mom def setup end - def in_test_vool(body = "@ivar = 5") + def in_test_vool(body = "@ivar = 5;return") code = in_Test("def meth; #{body};end") RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(code) end @@ -30,7 +30,7 @@ module Mom def test_compiles_all_risc compiler = in_test_vool().compilers.first.to_risc assert_equal Risc::LoadConstant , compiler.risc_instructions.next.class - assert_equal 17 , compiler.risc_instructions.length + assert_equal 20 , compiler.risc_instructions.length end end end diff --git a/test/mom/test_return_sequence.rb b/test/mom/test_return_sequence.rb index b07d7310..a3b26f54 100644 --- a/test/mom/test_return_sequence.rb +++ b/test/mom/test_return_sequence.rb @@ -6,11 +6,11 @@ module Risc def setup super - @input = "5.div4" + @input = "return 5.div4" @expect = "something" end - def instruction(num) # 18 is the main, see length in test/mom/send/test_setup_simple.rb - produce_main.next( 18 + num) + def instruction(num) # 21 is the main, see length in test/mom/send/test_setup_simple.rb + produce_main.next( 21 + num) end def test_postamble_classes postamble.each_with_index do |ins , index| diff --git a/test/mom/test_while_cmp.rb b/test/mom/test_while_cmp.rb index 092df33f..d18126b3 100644 --- a/test/mom/test_while_cmp.rb +++ b/test/mom/test_while_cmp.rb @@ -6,14 +6,15 @@ module Risc def setup super - @input = "while(5 > 0) ; @a = true; end" + @input = "while(5 > 0) ; @a = true; end;return" @expect = [Label, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #4 RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, #9 SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #14 RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #19 FunctionCall, Label, SlotToReg, LoadConstant, OperatorInstruction, #24 IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #29 - SlotToReg, RegToSlot, Branch, Label] #34 + SlotToReg, RegToSlot, Branch, Label, LoadConstant, #34 + RegToSlot, Branch] #34 end def test_while_instructions diff --git a/test/mom/test_while_simple.rb b/test/mom/test_while_simple.rb index ab23764b..fdee7e8b 100644 --- a/test/mom/test_while_simple.rb +++ b/test/mom/test_while_simple.rb @@ -6,10 +6,11 @@ module Risc def setup super - @input = "while(@a) ; arg = 5 end" - @expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, - IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, - SlotToReg, RegToSlot, Branch, Label] + @input = "while(@a) ; arg = 5 end;return" + @expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, #4 + IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #9 + SlotToReg, RegToSlot, Branch, Label, LoadConstant, #14 + RegToSlot, Branch] #19 end def test_while_instructions diff --git a/test/risc/test_method_compiler.rb b/test/risc/test_method_compiler.rb index f2516592..2d1c4d89 100644 --- a/test/risc/test_method_compiler.rb +++ b/test/risc/test_method_compiler.rb @@ -12,7 +12,7 @@ module Risc vool.to_mom(nil) vool end - def create_method(body = "@ivar = 5") + def create_method(body = "@ivar = 5;return") in_test_vool("def meth; #{body};end") test = Parfait.object_space.get_class_by_name(:Test) test.get_method(:meth) @@ -20,7 +20,7 @@ module Risc def test_method_has_source method = create_method - assert_equal Vool::IvarAssignment , method.source.class + assert_equal Vool::ScopeStatement , method.source.class end def test_method_has_no_locals @@ -40,20 +40,20 @@ module Risc end def test_creates_method_statement_in_class - clazz = in_test_vool("def meth; @ivar = 5 ;end") + clazz = in_test_vool("def meth; @ivar = 5 ;return;end") assert_equal Vool::Statements , clazz.body.class assert_equal Vool::MethodStatement , clazz.body.first.class end def test_callable_method_instance_type - in_test_vool("def meth; @ivar = 5; @ibar = 4;end") + in_test_vool("def meth; @ivar = 5; @ibar = 4;return;end") test = Parfait.object_space.get_class_by_name(:Test) method = test.instance_type.get_method(:meth) assert_equal 1, method.self_type.variable_index(:ivar) assert_equal 2, method.self_type.variable_index(:ibar) end def test_callable_method_has_one_local - in_test_vool("def meth; local = 5 ; a = 6;end") + in_test_vool("def meth; local = 5 ; a = 6;return;end") test = Parfait.object_space.get_class_by_name(:Test) method = test.get_method(:meth) assert_equal 3 , method.frame_type.instance_length diff --git a/test/ruby/test_method_statement.rb b/test/ruby/test_method_statement.rb index 1818a86f..8269bc18 100644 --- a/test/ruby/test_method_statement.rb +++ b/test/ruby/test_method_statement.rb @@ -36,21 +36,4 @@ module Ruby assert_equal LocalAssignment , lst.body.class end end - - class TestMethodStatementTrans < MiniTest::Test - include RubyTests - def setup() - input = "def tryout(arg1, arg2) ; a = arg1 ; end " - @lst = compile( input ).to_vool - end - def test_method - assert_equal Vool::MethodStatement , @lst.class - end - def test_method_args - assert_equal [:arg1, :arg2] , @lst.args - end - def test_body_is_scope_zero_statement - assert_equal Vool::LocalAssignment , @lst.body.class - end - end end diff --git a/test/ruby/test_method_statement2.rb b/test/ruby/test_method_statement2.rb new file mode 100644 index 00000000..b71828e3 --- /dev/null +++ b/test/ruby/test_method_statement2.rb @@ -0,0 +1,53 @@ +require_relative "helper" + +module Ruby + # other Return tests (standalone?) only test the statement + # But to get the implicit return, we test the method, as it inserts + # the implicit return + class TestMethodStatementRet < MiniTest::Test + include RubyTests + def test_single_const + @lst = compile( "def tryout(arg1, arg2) ; true ; end " ).to_vool + assert_equal Vool::ReturnStatement , @lst.body.class + end + def test_single_instance + @lst = compile( "def tryout(arg1, arg2) ; @a ; end " ).to_vool + assert_equal Vool::ReturnStatement , @lst.body.class + end + def test_single_call + @lst = compile( "def tryout(arg1, arg2) ; is_true() ; end " ).to_vool + assert_equal Vool::ReturnStatement , @lst.body.class + end + + def test_multi_const + @lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); true ; end " ).to_vool + assert_equal Vool::ReturnStatement , @lst.body.last.class + end + def test_multi_instance + @lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); @a ; end " ).to_vool + assert_equal Vool::ReturnStatement , @lst.body.last.class + end + def test_multi_call + @lst = compile( "def tryout(arg1, arg2) ; is_true() ; some_call() ; end " ).to_vool + assert_equal Vool::ReturnStatement , @lst.body.last.class + end + + def test_return + @lst = compile( "def tryout(arg1, arg2) ; return 1 ; end " ).to_vool + assert_equal Vool::ReturnStatement , @lst.body.class + assert_equal Vool::IntegerConstant , @lst.body.return_value.class + end + def test_local_assign + @lst = compile( "def tryout(arg1, arg2) ; a = 1 ; end " ).to_vool + assert_equal Vool::Statements , @lst.body.class + assert_equal Vool::ReturnStatement , @lst.body.last.class + assert_equal Vool::LocalVariable , @lst.body.last.return_value.class + end + def test_local_assign + @lst = compile( "def tryout(arg1, arg2) ; @a = 1 ; end " ).to_vool + assert_equal Vool::Statements , @lst.body.class + assert_equal Vool::ReturnStatement , @lst.body.last.class + assert_equal Vool::InstanceVariable , @lst.body.last.return_value.class + end + end +end diff --git a/test/rubyx/parfait/test_object.rb b/test/rubyx/parfait/test_object.rb index 197a04ba..e4625620 100644 --- a/test/rubyx/parfait/test_object.rb +++ b/test/rubyx/parfait/test_object.rb @@ -5,21 +5,20 @@ module RubyX class TestObjecCompile < MiniTest::Test include ParfaitHelper def source - load_parfait(:object2) + load_parfait(:object) end def test_load assert source.include?("class Object") assert source.length > 2000 end - def est_vool + def test_vool vool = compiler.ruby_to_vool source assert_equal Vool::ClassStatement , vool.class assert_equal :Object , vool.name end - def est_mom + def test_mom vool = compiler.ruby_to_mom source - assert_equal Vool::ClassStatement , vool.class - assert_equal :Object , vool.name + assert_equal Mom::MomCollection , vool.class end end end diff --git a/test/support/compiling.rb b/test/support/compiling.rb index 9b74717b..a88b3ebc 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -26,7 +26,6 @@ module VoolCompile include ScopeHelper include Mom - def compile_first_method( input ) input = as_test_main( input ) collection = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input) diff --git a/test/vool/class_send/helper.rb b/test/vool/class_send/helper.rb index b303ac62..d1864cc9 100644 --- a/test/vool/class_send/helper.rb +++ b/test/vool/class_send/helper.rb @@ -20,7 +20,7 @@ module Vool assert_equal Mom::MessageSetup , @ins.class , @ins end def test_two_instructions_are_returned - assert_equal 6 , @ins.length , @ins + assert_equal 8 , @ins.length , @ins end def test_receiver_move_class assert_equal Mom::ArgumentTransfer, @ins.next(1).class @@ -38,8 +38,8 @@ module Vool assert_equal Parfait::CallableMethod, @ins.next(2).method.class end def test_array - check_array [MessageSetup,ArgumentTransfer,SimpleCall,Label, - ReturnSequence , Label] , @ins + check_array [MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad, + ReturnJump,Label, ReturnSequence , Label] , @ins end end diff --git a/test/vool/send/helper.rb b/test/vool/send/helper.rb index 1f860562..b38c46dc 100644 --- a/test/vool/send/helper.rb +++ b/test/vool/send/helper.rb @@ -20,7 +20,7 @@ module Vool assert_equal MessageSetup , @ins.class , @ins end def test_two_instructions_are_returned - assert_equal 6 , @ins.length , @ins + assert_equal 8 , @ins.length , @ins end def test_receiver_move_class assert_equal ArgumentTransfer, @ins.next(1).class @@ -40,7 +40,8 @@ module Vool assert_equal Parfait::CallableMethod, @ins.next(2).method.class end def test_array - check_array [MessageSetup,ArgumentTransfer,SimpleCall,Label, ReturnSequence , + check_array [MessageSetup,ArgumentTransfer,SimpleCall, + SlotLoad, ReturnJump, Label, ReturnSequence , Label] , @ins end end diff --git a/test/vool/send/test_not_found.rb b/test/vool/send/test_not_found.rb index 4fc1736b..d6ff8134 100644 --- a/test/vool/send/test_not_found.rb +++ b/test/vool/send/test_not_found.rb @@ -21,7 +21,8 @@ module Vool def test_array check_array [NotSameCheck, SlotLoad, ResolveMethod, Label, MessageSetup , - ArgumentTransfer, DynamicCall, Label, ReturnSequence, Label] , @ins + ArgumentTransfer, DynamicCall, SlotLoad, ReturnJump, + Label, ReturnSequence, Label] , @ins end end diff --git a/test/vool/send/test_send_args_send.rb b/test/vool/send/test_send_args_send.rb index de04c079..f3fb4fd5 100644 --- a/test/vool/send/test_send_args_send.rb +++ b/test/vool/send/test_send_args_send.rb @@ -7,14 +7,14 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) Risc.boot! - @compiler = compile_first_method( "a = main(1 + 2)" ) + @compiler = compile_first_method( "a = main(1 + 2);return a" ) @ins = @compiler.mom_instructions.next end def test_array check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, MessageSetup , - ArgumentTransfer, SimpleCall, SlotLoad ,Label, ReturnSequence , - Label] , @ins + ArgumentTransfer, SimpleCall, SlotLoad ,SlotLoad, ReturnJump, + Label, ReturnSequence , Label] , @ins end def test_one_call diff --git a/test/vool/send/test_send_cached_simple.rb b/test/vool/send/test_send_cached_simple.rb index 0e2989fc..b59d1060 100644 --- a/test/vool/send/test_send_cached_simple.rb +++ b/test/vool/send/test_send_cached_simple.rb @@ -5,7 +5,7 @@ module Vool include VoolCompile def setup - @compiler = compile_first_method( "a = 5; a.div4") + @compiler = compile_first_method( "a = 5; a.div4;return ") @ins = @compiler.mom_instructions.next end def test_check_type @@ -27,7 +27,8 @@ module Vool def test_array check_array [SlotLoad, NotSameCheck, SlotLoad, ResolveMethod , - Label, MessageSetup, ArgumentTransfer, DynamicCall, Label , + Label, MessageSetup, ArgumentTransfer, DynamicCall, + SlotLoad, ReturnJump, Label , ReturnSequence, Label] , @ins end diff --git a/test/vool/send/test_send_self.rb b/test/vool/send/test_send_self.rb index 89134a52..5c5e8451 100644 --- a/test/vool/send/test_send_self.rb +++ b/test/vool/send/test_send_self.rb @@ -5,7 +5,7 @@ module Vool include SimpleSendHarness def send_method - "self.get_internal_word(0)" + "self.get_internal_word(0);return" end def test_receiver assert_equal SlotDefinition, @ins.next.receiver.class diff --git a/test/vool/send/test_send_simple.rb b/test/vool/send/test_send_simple.rb index 8bff2433..7ff5d0e9 100644 --- a/test/vool/send/test_send_simple.rb +++ b/test/vool/send/test_send_simple.rb @@ -5,7 +5,7 @@ module Vool include SimpleSendHarness def send_method - "5.div4" + "5.div4;return" end def receiver [Mom::IntegerConstant , 5] diff --git a/test/vool/send/test_send_simple_args.rb b/test/vool/send/test_send_simple_args.rb index 4b32aa23..734fd710 100644 --- a/test/vool/send/test_send_simple_args.rb +++ b/test/vool/send/test_send_simple_args.rb @@ -5,7 +5,7 @@ module Vool include SimpleSendHarness def send_method - "5.div4(1,2)" + "5.div4(1,2);return" end def receiver @@ -20,8 +20,8 @@ module Vool assert_equal 2, @ins.next(1).arguments[1].right.known_object.value end def test_array - check_array [MessageSetup,ArgumentTransfer,SimpleCall, Label, ReturnSequence , - Label] , @ins + check_array [MessageSetup,ArgumentTransfer,SimpleCall, SlotLoad, ReturnJump, + Label, ReturnSequence , Label] , @ins end end end diff --git a/test/vool/send/test_send_simple_string.rb b/test/vool/send/test_send_simple_string.rb index 8bec7915..b6e3bd80 100644 --- a/test/vool/send/test_send_simple_string.rb +++ b/test/vool/send/test_send_simple_string.rb @@ -5,7 +5,7 @@ module Vool include SimpleSendHarness def send_method - "'5'.get_internal_byte(1)" + "'5'.get_internal_byte(1) ; return " end def receiver [Mom::StringConstant , "5"] diff --git a/test/vool/test_assignment.rb b/test/vool/test_assignment.rb index 9e556c63..9ddddc05 100644 --- a/test/vool/test_assignment.rb +++ b/test/vool/test_assignment.rb @@ -6,7 +6,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "local = 5") + @compiler = compile_first_method( "local = 5;return") @ins = @compiler.mom_instructions.next end @@ -38,7 +38,7 @@ module Vool include VoolCompile def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "@a = 5 ; local = @a") + @compiler = compile_first_method( "@a = 5 ; local = @a;return") @ins = @compiler.mom_instructions.next end def test_class_compiles @@ -52,7 +52,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "arg = 5") + @compiler = compile_first_method( "arg = 5;return") @ins = @compiler.mom_instructions.next end @@ -79,13 +79,13 @@ module Vool Parfait.boot!(Parfait.default_test_options) end def test_assigns_const - @compiler = compile_first_method( "@a = 5") + @compiler = compile_first_method( "@a = 5;return") @ins = @compiler.mom_instructions.next assert_equal Mom::SlotLoad , @ins.class , @ins assert_equal Mom::IntegerConstant , @ins.right.known_object.class , @ins end def test_assigns_move - @compiler = compile_first_method( "@a = arg") + @compiler = compile_first_method( "@a = arg;return") @ins = @compiler.mom_instructions.next assert_equal Mom::SlotLoad , @ins.class , @ins assert_equal Mom::SlotDefinition , @ins.right.class , @ins diff --git a/test/vool/test_class_statement.rb b/test/vool/test_class_statement.rb index b9198adf..b3656d3c 100644 --- a/test/vool/test_class_statement.rb +++ b/test/vool/test_class_statement.rb @@ -67,7 +67,7 @@ module Vool include VoolCompile def setup - @compiler = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end") + @compiler = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end; return") @ins = @compiler.mom_instructions end @@ -89,8 +89,8 @@ module Vool end def test_array check_array [Label, TruthCheck, Label, SlotLoad, Jump , - Label, SlotLoad, Label, Label, ReturnSequence , - Label] , @ins + Label, SlotLoad, Label, SlotLoad, ReturnJump , + Label, ReturnSequence, Label] , @ins end end end diff --git a/test/vool/test_if_no_else.rb b/test/vool/test_if_no_else.rb index 166e5948..6e3ba96a 100644 --- a/test/vool/test_if_no_else.rb +++ b/test/vool/test_if_no_else.rb @@ -7,7 +7,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "if(@a) ; @a = 5 ; end") + @compiler = compile_first_method( "if(@a) ; @a = 5 ; end;return") @ins = @compiler.mom_instructions.next end @@ -24,8 +24,8 @@ module Vool assert_equal Label , @ins.last.class , @ins end def test_array - check_array [TruthCheck, Label, SlotLoad, Label, Label , - ReturnSequence, Label], @ins + check_array [TruthCheck, Label, SlotLoad, Label, SlotLoad, ReturnJump, + Label ,ReturnSequence, Label], @ins end end end diff --git a/test/vool/test_if_no_if.rb b/test/vool/test_if_no_if.rb index 066210c2..0b744f3d 100644 --- a/test/vool/test_if_no_if.rb +++ b/test/vool/test_if_no_if.rb @@ -7,7 +7,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "unless(@a) ; @a = 5 ; end") + @compiler = compile_first_method( "unless(@a) ; @a = 5 ; end;return") @ins = @compiler.mom_instructions.next end @@ -25,7 +25,7 @@ module Vool end def test_array check_array [TruthCheck, Label, Jump, Label, SlotLoad , - Label, Label, ReturnSequence, Label] , @ins + Label, SlotLoad, ReturnJump,Label, ReturnSequence, Label] , @ins end end end diff --git a/test/vool/test_if_simple.rb b/test/vool/test_if_simple.rb index 6c2ce472..07e19c2b 100644 --- a/test/vool/test_if_simple.rb +++ b/test/vool/test_if_simple.rb @@ -7,7 +7,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end") + @compiler = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end;return") @ins = @compiler.mom_instructions.next end @@ -25,7 +25,7 @@ module Vool end def test_array check_array [TruthCheck, Label, SlotLoad, Jump, Label , - SlotLoad, Label, Label, ReturnSequence, Label], @ins + SlotLoad, Label, SlotLoad, ReturnJump,Label, ReturnSequence, Label], @ins end end end diff --git a/test/vool/test_if_statement.rb b/test/vool/test_if_statement.rb index 5a237a14..108a1d9e 100644 --- a/test/vool/test_if_statement.rb +++ b/test/vool/test_if_statement.rb @@ -6,7 +6,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end") + @compiler = compile_first_method( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end;return") @ins = @compiler.mom_instructions.next end @@ -23,7 +23,7 @@ module Vool def test_array check_array [MessageSetup, ArgumentTransfer, SimpleCall, TruthCheck, Label , SlotLoad, Jump, Label, SlotLoad, Label , - Label, ReturnSequence, Label] , @ins + SlotLoad, ReturnJump,Label, ReturnSequence, Label] , @ins end end diff --git a/test/vool/test_while_statement.rb b/test/vool/test_while_statement.rb index 761ff735..63a393ec 100644 --- a/test/vool/test_while_statement.rb +++ b/test/vool/test_while_statement.rb @@ -6,7 +6,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "while(@a) ; @a = 5 ; end") + @compiler = compile_first_method( "while(@a) ; @a = 5 ; end;return") @ins = @compiler.mom_instructions.next end @@ -21,7 +21,7 @@ module Vool end def test_array check_array [Label, TruthCheck, SlotLoad, Jump, Label , - Label, ReturnSequence, Label], @ins + SlotLoad, ReturnJump,Label, ReturnSequence, Label], @ins end end end diff --git a/test/vool/test_while_statement1.rb b/test/vool/test_while_statement1.rb index 3f97ce7a..494d18c4 100644 --- a/test/vool/test_while_statement1.rb +++ b/test/vool/test_while_statement1.rb @@ -7,7 +7,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "while(5.div4) ; 5.div4 ; end") + @compiler = compile_first_method( "while(5.div4) ; 5.div4 ; end;return") @ins = @compiler.mom_instructions.next end @@ -30,7 +30,8 @@ module Vool def test_array check_array [Label, MessageSetup, ArgumentTransfer, SimpleCall, TruthCheck , MessageSetup, ArgumentTransfer, SimpleCall, Jump, Label , - Label, ReturnSequence, Label] , @ins + SlotLoad, ReturnJump,Label, ReturnSequence, Label ,Label , + ReturnSequence, Label] , @ins end end