From 4656ea8ffb912b4a9352b37628b61deb652ef2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Fri, 23 Aug 2019 19:24:18 +0300 Subject: [PATCH] fix all mom tests still quite brittle, but easy to fix --- test/mom/assign/test_assign_local_send.rb | 10 +++---- test/mom/blocks/test_block_setup.rb | 16 +++++------ test/mom/builtin/test_div10.rb | 2 +- test/mom/builtin/test_div4.rb | 3 ++- test/mom/builtin/test_exit.rb | 2 +- test/mom/builtin/test_get_internal_byte.rb | 2 +- test/mom/builtin/test_init.rb | 2 +- test/mom/builtin/test_method_missing.rb | 2 +- test/mom/builtin/test_object.rb | 5 +++- test/mom/builtin/test_operator.rb | 2 +- test/mom/builtin/test_putstring.rb | 2 +- test/mom/send/test_send_dynamic.rb | 25 ++++++++--------- test/mom/send/test_send_simple.rb | 14 +++++----- test/mom/send/test_send_simple_args.rb | 14 +++++----- test/mom/send/test_setup_simple.rb | 8 +++--- test/mom/test_return_call.rb | 10 +++---- test/mom/test_return_dynamic.rb | 25 ++++++++--------- test/mom/test_return_sequence.rb | 4 +-- test/mom/test_while_cmp.rb | 31 +++++++++++----------- 19 files changed, 93 insertions(+), 86 deletions(-) diff --git a/test/mom/assign/test_assign_local_send.rb b/test/mom/assign/test_assign_local_send.rb index e9c4e174..8c3b22c6 100644 --- a/test/mom/assign/test_assign_local_send.rb +++ b/test/mom/assign/test_assign_local_send.rb @@ -7,10 +7,10 @@ module Risc def setup super @input = "r = 5.div4;return" - @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 - LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9 - Label, SlotToReg, RegToSlot, LoadConstant, RegToSlot, #14 - Branch,] #19 + @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5 + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10 + FunctionCall, Label, SlotToReg, RegToSlot, LoadConstant, #15 + RegToSlot, Branch,] #20 end def test_local_assign_instructions assert_nil msg = check_nil , msg @@ -18,7 +18,7 @@ module Risc def test_constant_load produced = produce_body - load = produced.next(2) + load = produced.next(3) assert_equal LoadConstant , load.class assert_equal 5 , load.constant.value end diff --git a/test/mom/blocks/test_block_setup.rb b/test/mom/blocks/test_block_setup.rb index 235a38c3..56ac676b 100644 --- a/test/mom/blocks/test_block_setup.rb +++ b/test/mom/blocks/test_block_setup.rb @@ -7,10 +7,10 @@ module Risc def setup super @input = as_block("return 5") - @expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, SlotToReg, #4 - SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #9 - LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #14 - Label,] #19 + @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #5 + SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #10 + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #15 + FunctionCall, Label,] #20 end def test_send_instructions @@ -27,22 +27,22 @@ module Risc assert_equal 5 , produced.constant.value end def test_load_block - produced = produce_body.next(7) + produced = produce_body.next(8) assert_load( produced , Parfait::Block) assert_equal :main_block , produced.constant.name end def test_load_return - produced = produce_body.next(10) + produced = produce_body.next(11) assert_load( produced , Label) assert produced.constant.name.start_with?("continue_") end def test_function_call - produced = produce_body.next(14) + produced = produce_body.next(15) assert_equal FunctionCall , produced.class assert_equal :main , produced.method.name end def test_check_continue - produced = produce_body.next(15) + produced = produce_body.next(16) assert_equal Label , produced.class assert produced.name.start_with?("continue_") , produced.name end diff --git a/test/mom/builtin/test_div10.rb b/test/mom/builtin/test_div10.rb index e1b013a1..2b0af89c 100644 --- a/test/mom/builtin/test_div10.rb +++ b/test/mom/builtin/test_div10.rb @@ -11,7 +11,7 @@ module Mom assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 66 , @method.to_risc.risc_instructions.length + assert_equal 67 , @method.to_risc.risc_instructions.length end end end diff --git a/test/mom/builtin/test_div4.rb b/test/mom/builtin/test_div4.rb index edb3860c..571a58b4 100644 --- a/test/mom/builtin/test_div4.rb +++ b/test/mom/builtin/test_div4.rb @@ -9,9 +9,10 @@ module Mom end def test_compile assert_equal Risc::MethodCompiler , @method.to_risc.class + assert_equal :div4 , @method.callable.name end def test_risc_length - assert_equal 37 , @method.to_risc.risc_instructions.length + assert_equal 38 , @method.to_risc.risc_instructions.length end end end diff --git a/test/mom/builtin/test_exit.rb b/test/mom/builtin/test_exit.rb index c79f3177..ae29c441 100644 --- a/test/mom/builtin/test_exit.rb +++ b/test/mom/builtin/test_exit.rb @@ -11,7 +11,7 @@ module Mom assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 36 , @method.to_risc.risc_instructions.length + assert_equal 37 , @method.to_risc.risc_instructions.length end end end diff --git a/test/mom/builtin/test_get_internal_byte.rb b/test/mom/builtin/test_get_internal_byte.rb index 98a1384a..a6e894af 100644 --- a/test/mom/builtin/test_get_internal_byte.rb +++ b/test/mom/builtin/test_get_internal_byte.rb @@ -11,7 +11,7 @@ module Mom assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 37 , @method.to_risc.risc_instructions.length + assert_equal 38 , @method.to_risc.risc_instructions.length end end end diff --git a/test/mom/builtin/test_init.rb b/test/mom/builtin/test_init.rb index 0a67fe6b..d7b28288 100644 --- a/test/mom/builtin/test_init.rb +++ b/test/mom/builtin/test_init.rb @@ -11,7 +11,7 @@ module Mom assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 27 , @method.to_risc.risc_instructions.length + assert_equal 19 , @method.to_risc.risc_instructions.length end end end diff --git a/test/mom/builtin/test_method_missing.rb b/test/mom/builtin/test_method_missing.rb index 410ef4b1..59440213 100644 --- a/test/mom/builtin/test_method_missing.rb +++ b/test/mom/builtin/test_method_missing.rb @@ -11,7 +11,7 @@ module Mom assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 38 , @method.to_risc.risc_instructions.length + assert_equal 39 , @method.to_risc.risc_instructions.length end end end diff --git a/test/mom/builtin/test_object.rb b/test/mom/builtin/test_object.rb index c41b5663..85c50a5f 100644 --- a/test/mom/builtin/test_object.rb +++ b/test/mom/builtin/test_object.rb @@ -13,6 +13,9 @@ module Mom def test_mom_length assert_equal 5 , @method.mom_instructions.length end + def test_return + assert_equal ReturnSequence , @method.mom_instructions.next(3).class + end end class TestObjectSet < BootTest def setup @@ -59,7 +62,7 @@ module Mom assert_equal Mom::MethodCompiler , @method.class end def test_mom_length - assert_equal 5 , @method.mom_instructions.length + assert_equal 2 , @method.mom_instructions.length end end end diff --git a/test/mom/builtin/test_operator.rb b/test/mom/builtin/test_operator.rb index 3f256629..ae576a2e 100644 --- a/test/mom/builtin/test_operator.rb +++ b/test/mom/builtin/test_operator.rb @@ -19,7 +19,7 @@ module Mom end def test_risc_length each_method do |method| - assert_equal 38 , method.to_risc.risc_instructions.length + assert_equal 39 , method.to_risc.risc_instructions.length end end end diff --git a/test/mom/builtin/test_putstring.rb b/test/mom/builtin/test_putstring.rb index 6ae7b051..1eecaf54 100644 --- a/test/mom/builtin/test_putstring.rb +++ b/test/mom/builtin/test_putstring.rb @@ -11,7 +11,7 @@ module Mom assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 40 , @method.to_risc.risc_instructions.length + assert_equal 41 , @method.to_risc.risc_instructions.length end end end diff --git a/test/mom/send/test_send_dynamic.rb b/test/mom/send/test_send_dynamic.rb index a3571a32..38e38651 100644 --- a/test/mom/send/test_send_dynamic.rb +++ b/test/mom/send/test_send_dynamic.rb @@ -7,17 +7,18 @@ module Risc def setup super @input = "@a.div4" - @expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4 - OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9 - LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14 - SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19 - SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24 - Label, LoadConstant, SlotToReg, Transfer, Syscall, #29 - Transfer, Transfer, SlotToReg, RegToSlot, Label, #34 - RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39 - SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44 - SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49 - DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54 + @expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5 + OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10 + LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15 + SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #20 + SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #25 + Label, LoadConstant, SlotToReg, Transfer, Syscall, #30 + Transfer, Transfer, SlotToReg, RegToSlot, Label, #35 + RegToSlot, Label, LoadConstant, SlotToReg, SlotToReg, #40 + RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #45 + LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #50 + SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, #55 + Branch,] #60 end def test_send_instructions @@ -35,7 +36,7 @@ module Risc end def test_function_call produced = produce_body - assert_equal DynamicJump , produced.next(50).class + assert_equal DynamicJump , produced.next(51).class end def test_cache_check produced = produce_body diff --git a/test/mom/send/test_send_simple.rb b/test/mom/send/test_send_simple.rb index 2f4c68d9..743b8e27 100644 --- a/test/mom/send/test_send_simple.rb +++ b/test/mom/send/test_send_simple.rb @@ -7,30 +7,30 @@ module Risc def setup super @input = "5.div4" - @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 - LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9 - Label, SlotToReg, RegToSlot, Branch,] #14 + @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5 + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10 + FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15 end def test_send_instructions assert_nil msg = check_nil , msg end def test_load_5 - produced = produce_body.next(2) + produced = produce_body.next(3) assert_load( produced , Parfait::Integer) assert_equal 5 , produced.constant.value end def test_load_label - produced = produce_body.next(5) + produced = produce_body.next(6) assert_load( produced , Label) end def test_function_call - produced = produce_body.next(9) + produced = produce_body.next(10) assert_equal FunctionCall , produced.class assert_equal :div4 , produced.method.name end def test_check_continue - produced = produce_body.next(10) + produced = produce_body.next(11) assert_equal Label , produced.class assert produced.name.start_with?("continue_") end diff --git a/test/mom/send/test_send_simple_args.rb b/test/mom/send/test_send_simple_args.rb index 2081fe3a..d09fc7ca 100644 --- a/test/mom/send/test_send_simple_args.rb +++ b/test/mom/send/test_send_simple_args.rb @@ -7,10 +7,10 @@ module Risc def setup super @input = "5.get_internal_word(1)" - @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 - LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #9 - RegToSlot, SlotToReg, FunctionCall, Label, SlotToReg, #14 - RegToSlot, Branch,] #19 + @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5 + RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #10 + SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #15 + SlotToReg, RegToSlot, Branch,] #20 end def test_send_instructions @@ -18,11 +18,11 @@ module Risc end def test_load_5 produced = produce_body - assert_equal LoadConstant , produced.next(2).class - assert_equal 5 , produced.next(2).constant.value + assert_equal LoadConstant , produced.next(3).class + assert_equal 5 , produced.next(3).constant.value end def base - 5 + 6 end def test_load_arg_const produced = produce_body diff --git a/test/mom/send/test_setup_simple.rb b/test/mom/send/test_setup_simple.rb index 590ed1f8..5076d072 100644 --- a/test/mom/send/test_setup_simple.rb +++ b/test/mom/send/test_setup_simple.rb @@ -7,9 +7,9 @@ module Risc def setup super @input = "return 5.div4" - @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 - LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9 - Label, SlotToReg, RegToSlot, Branch] #14 + @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5 + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10 + FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15 @produced = produce_body end @@ -22,7 +22,7 @@ module Risc assert_equal :div4 , method.constant.name end def test_store_method_in_message - sl = @produced.next( 1 ) + sl = @produced.next( 2 ) assert_reg_to_slot( sl , :r1 , :r2 , 7 ) end end diff --git a/test/mom/test_return_call.rb b/test/mom/test_return_call.rb index 81d0d78d..14f57619 100644 --- a/test/mom/test_return_call.rb +++ b/test/mom/test_return_call.rb @@ -7,21 +7,21 @@ module Risc def setup super @input = "return 5.div4" - @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 - LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9 - Label, SlotToReg, RegToSlot, Branch,] #14 + @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5 + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10 + FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15 end def test_return_instructions assert_nil msg = check_nil , msg end def test_function_return - produced = produce_body.next(13) + produced = produce_body.next(14) assert_equal Branch , produced.class assert_equal "return_label" , produced.label.name end def test_load_5 - produced = produce_body.next(2) + produced = produce_body.next(3) assert_equal LoadConstant , produced.class assert_equal 5 , produced.constant.value end diff --git a/test/mom/test_return_dynamic.rb b/test/mom/test_return_dynamic.rb index 11772ea7..9e74c82b 100644 --- a/test/mom/test_return_dynamic.rb +++ b/test/mom/test_return_dynamic.rb @@ -7,17 +7,18 @@ module Risc def setup super @input = "return @a.div4" - @expect =[LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4 - OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9 - LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14 - SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19 - SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24 - Label, LoadConstant, SlotToReg, Transfer, Syscall, #29 - Transfer, Transfer, SlotToReg, RegToSlot, Label, #34 - RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39 - SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44 - SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49 - DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54 + @expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5 + OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10 + LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15 + SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #20 + SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #25 + Label, LoadConstant, SlotToReg, Transfer, Syscall, #30 + Transfer, Transfer, SlotToReg, RegToSlot, Label, #35 + RegToSlot, Label, LoadConstant, SlotToReg, SlotToReg, #40 + RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #45 + LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #50 + SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, #55 + Branch,] #60 end def test_return_instructions @@ -25,7 +26,7 @@ module Risc end def test_function_return produced = produce_body - assert_equal Branch , produced.next(54).class + assert_equal Branch , produced.next(55).class end def test_cache_check produced = produce_body diff --git a/test/mom/test_return_sequence.rb b/test/mom/test_return_sequence.rb index a0211d8b..9749e3d3 100644 --- a/test/mom/test_return_sequence.rb +++ b/test/mom/test_return_sequence.rb @@ -9,8 +9,8 @@ module Risc @input = "return 5.div4" @expect = "something" end - def instruction(num) # 15 is the main, see length in support/risc_interpreter.rb main_at - produce_main.next( 15 + num) + def instruction(num) # 16 is the main, see length in support/risc_interpreter.rb main_at + produce_main.next( 16 + 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 b26e774a..08185b02 100644 --- a/test/mom/test_while_cmp.rb +++ b/test/mom/test_while_cmp.rb @@ -7,12 +7,13 @@ module Risc def setup super @input = "while(5 > 0) ; @a = true; end;return" - @expect = [Label, LoadConstant, RegToSlot, LoadConstant, SlotToReg, #4 - RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #9 - SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #14 - SlotToReg, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #19 - OperatorInstruction, IsZero, LoadConstant, SlotToReg, RegToSlot, #24 - Branch, Label, LoadConstant, RegToSlot, Branch,] #29 + @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #5 + SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #10 + LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #15 + Label, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #20 + LoadConstant, OperatorInstruction, IsZero, LoadConstant, SlotToReg, #25 + RegToSlot, Branch, Label, LoadConstant, RegToSlot, #30 + Branch,] #35 end def test_while_instructions @@ -23,33 +24,33 @@ module Risc end def test_int_load_5 produced = produce_body - load = produced.next(3) + load = produced.next(4) assert_equal Risc::LoadConstant , load.class assert_equal Parfait::Integer , load.constant.class assert_equal 5 , load.constant.value end def test_int_load_0 produced = produce_body - load = produced.next(6) + load = produced.next(7) assert_equal Risc::LoadConstant , load.class assert_equal Parfait::Integer , load.constant.class assert_equal 0 , load.constant.value end def test_false_check produced = produce_body - assert_equal Risc::IsZero , produced.next(18).class - assert produced.next(18).label.name.start_with?("merge_label") , produced.next(18).label.name + assert_equal Risc::IsZero , produced.next(19).class + assert produced.next(19).label.name.start_with?("merge_label") , produced.next(19).label.name end def test_nil_load produced = produce_body - assert_equal Risc::LoadConstant , produced.next(22).class - assert_equal Parfait::TrueClass , produced.next(22).constant.class + assert_equal Risc::LoadConstant , produced.next(23).class + assert_equal Parfait::TrueClass , produced.next(23).constant.class end - def ttest_back_jump # should jump back to condition label + def test_back_jump # should jump back to condition label produced = produce_body - assert_equal Risc::Branch , produced.next(31).class - assert_equal produced.name , produced.next(31).label.name + assert_equal Risc::Branch , produced.next(26).class + assert_equal produced.name , produced.next(26).label.name end end