diff --git a/test/mom/assign/test_assign_arg_const.rb b/test/mom/assign/test_assign_arg_const.rb deleted file mode 100644 index 811ceaa2..00000000 --- a/test/mom/assign/test_assign_arg_const.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../helper' - -module Risc - class TestAssignArgConst < MiniTest::Test - include Statements - - def setup - super - @input = "arg = 5;return" - @expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, Branch] - end - def test_local_assign_instructions - assert_nil msg = check_nil , msg - end - - def test_constant_load - produced = produce_body - assert_equal 5 , produced.constant.value - end - - def test_slot_move - produced = produce_body - assert_equal produced.next(2).register , produced.register - end - def test_load_args_from_message - produced = produce_body - assert_equal :r0 , produced.next.array.symbol , produced.next.to_rxf[0..200] - assert_equal 9 , produced.next.index , produced.next.to_rxf[0..200] - end - - end -end diff --git a/test/mom/assign/test_assign_ivar_const.rb b/test/mom/assign/test_assign_ivar_const.rb deleted file mode 100644 index 70b5049b..00000000 --- a/test/mom/assign/test_assign_ivar_const.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../helper' - -module Risc - class TestAssignIvarConst < MiniTest::Test - include Statements - - def setup - @input = "@nil_object = 5;return" - @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, Branch] - end - - def test_local_assign_instructions - assert_nil msg = check_nil , msg - end - - def test_constant_load - produced = produce_body - assert_equal 5 , produced.constant.value - end - - def test_slot_move - produced = produce_body - assert_equal produced.next.next.register , produced.register - end - - def test_load_self_from_message - produced = produce_body - assert_equal :r0 , produced.next.array.symbol , produced.next.to_rxf[0..200] - assert_equal 2 , produced.next.index , produced.next.to_rxf[0..200] - end - - end -end diff --git a/test/mom/assign/test_assign_local_arg.rb b/test/mom/assign/test_assign_local_arg.rb deleted file mode 100644 index 91c5c0a6..00000000 --- a/test/mom/assign/test_assign_local_arg.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../helper' - -module Risc - class TestAssignLocalArg < MiniTest::Test - include Statements - - def setup - @input = "local = arg; return local" - @expect = [SlotToReg, RegToSlot, SlotToReg, RegToSlot, Branch] #4 - end - def test_local_assign_instructions - assert_nil msg = check_nil , msg - end - - def test_slot_move - produced = produce_body - assert_equal produced.next(3).register , produced.register - end - def test_load_args_from_message - produced = produce_body - assert_equal :r0 , produced.array.symbol , produced.next.to_rxf[0..200] - assert_equal 9 , produced.index , produced.next.to_rxf[0..200] - end - def test_load_frame_from_message - produced = produce_body - assert_equal 16 , produced.next.index , produced.next.to_rxf[0..200] - assert_equal :r0 , produced.next(2).array.symbol - end - end -end diff --git a/test/mom/assign/test_assign_local_false.rb b/test/mom/assign/test_assign_local_false.rb deleted file mode 100644 index 51743cc7..00000000 --- a/test/mom/assign/test_assign_local_false.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../helper' - -module Risc - class TestAssignLocalFalse < MiniTest::Test - include Statements - - def setup - @input = "r = false;return" - @expect = [LoadConstant, RegToSlot,LoadConstant, RegToSlot, Branch] - end - def test_local_assign_instructions - assert_nil msg = check_nil , msg - end - - def test_constant_load - produced = produce_body - assert_equal Parfait::FalseClass , produced.constant.class - end - - def test_frame_load - produced = produce_body - assert_equal :Message , produced.next(1).array.type.class_name - assert_equal 16 , produced.next(1).index # 3 is frame - end - def test_value_load - produced = produce_body - assert_equal produced.next(2).register , produced.register - assert_equal 16 , produced.next(1).index #type == 0 , r == 16 - end - - end -end diff --git a/test/mom/assign/test_assign_local_int.rb b/test/mom/assign/test_assign_local_int.rb deleted file mode 100644 index eae312f5..00000000 --- a/test/mom/assign/test_assign_local_int.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative '../helper' - -module Risc - class TestAssignLocalInt < MiniTest::Test - include Statements - - def setup - @input = "r = 5;return" - @expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, Branch] - end - def test_local_assign_instructions - assert_nil msg = check_nil , msg - end - - def test_constant_load - produced = produce_body - assert_equal 5 , produced.constant.value - end - - def test_frame_load - produced = produce_body - assert_equal :Message , produced.next(1).array.type.class_name - assert_equal 16 , produced.next(1).index # 4 is frame - end - def test_value_load - produced = produce_body - assert_equal produced.next(1).register , produced.register - end - - end -end diff --git a/test/mom/assign/test_assign_local_ivar.rb b/test/mom/assign/test_assign_local_ivar.rb deleted file mode 100644 index 795258d4..00000000 --- a/test/mom/assign/test_assign_local_ivar.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../helper' - -module Risc - class TestAssignLocalIvar < MiniTest::Test - include Statements - - def setup - @input = "@nil_object = 5 ; r = @nil_object;return" - @expect = [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #4 - RegToSlot, LoadConstant, RegToSlot, Branch] #9 - end - def test_local_assign_instructions - assert_nil msg = check_nil , msg - end - - def test_constant_load - produced = produce_body - assert_equal 5 , produced.constant.value - end - - def test_slot_move - produced = produce_body - assert_equal produced.next(2).register , produced.register - end - - end -end diff --git a/test/mom/assign/test_assign_local_send.rb b/test/mom/assign/test_assign_local_send.rb deleted file mode 100644 index 39cf09a4..00000000 --- a/test/mom/assign/test_assign_local_send.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../helper' - -module Risc - class TestAssignLocalSend < MiniTest::Test - include Statements - - def setup - @preload = "Integer.div4" - @input = "r = 5.div4;return" - @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 - end - - def test_constant_load - produced = produce_body - load = produced.next(3) - assert_equal LoadConstant , load.class - assert_equal 5 , load.constant.value - end - end -end diff --git a/test/mom/blocks/test_block_assign.rb b/test/mom/blocks/test_block_assign.rb deleted file mode 100644 index e8909e01..00000000 --- a/test/mom/blocks/test_block_assign.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative "../helper" - -module Risc - class TestBlockAssign < MiniTest::Test - include Statements - - def setup - @input = as_block("a = 5") - @expect = [LoadConstant, RegToSlot] - end - def test_send_instructions - assert_nil msg = check_nil(:main_block) , msg - end - def test_load_5 - produced = produce_block.next - assert_load( produced , Parfait::Integer) - assert_equal 5 , produced.constant.value - end - end -end diff --git a/test/mom/blocks/test_block_compiler.rb b/test/mom/blocks/test_block_compiler.rb deleted file mode 100644 index 2e07c34c..00000000 --- a/test/mom/blocks/test_block_compiler.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative "../helper" - -module Risc - class TestBlockSetupBlock < MiniTest::Test - include Statements - - def setup - @input = as_block("return 5") - @mom = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(as_main) - end - def main_risc - @mom.to_risc.method_compilers.find{|c| c.callable.name == :main } - end - def test_mom - assert_equal Mom::MomCollection , @mom.class - end - def test_mom_block_comp - assert_equal 1 , @mom.method_compilers.first.block_compilers.length - end - def test_risc - assert_equal Risc::RiscCollection , @mom.to_risc.class - end - def test_risc_comp - assert_equal :main , main_risc.callable.name - end - def test_risc_block_comp - assert_equal 1 , main_risc.block_compilers.length - end - - end -end diff --git a/test/mom/blocks/test_block_setup.rb b/test/mom/blocks/test_block_setup.rb deleted file mode 100644 index a240420c..00000000 --- a/test/mom/blocks/test_block_setup.rb +++ /dev/null @@ -1,50 +0,0 @@ -require_relative "../helper" - -module Risc - class TestBlockSetup < MiniTest::Test - include Statements - - def setup - - @input = as_block("return 5") - @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 - assert_nil msg = check_nil(:main) , msg - end - def test_load_5_block - produced = produce_block.next - assert_load( produced , Parfait::Integer) - assert_equal 5 , produced.constant.value - end - def test_load_5 - produced = produce_body - assert_load( produced , Parfait::Integer) - assert_equal 5 , produced.constant.value - end - def test_load_block - 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(11) - assert_load( produced , Label) - assert produced.constant.name.start_with?("continue_") - end - def test_function_call - 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(16) - assert_equal Label , produced.class - assert produced.name.start_with?("continue_") , produced.name - end - end -end diff --git a/test/mom/class_send/test_send_simple.rb b/test/mom/class_send/test_send_simple.rb deleted file mode 100644 index 8a71f0b9..00000000 --- a/test/mom/class_send/test_send_simple.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative "../helper" - -module Risc - class TestClassCallSimple < MiniTest::Test - include Statements - - def setup - @class_input = "def self.simple_return; return 1 ; end;" - @input = "return Space.simple_return" - @expect = [LoadConstant, RegToSlot, Branch] - end - - def test_send_instructions - assert_nil msg = check_nil(:simple_return) , msg - end - def test_load_simple - produced = produce_target(:simple_return).next(1) - assert_load( produced , Parfait::Integer) - assert_equal 1 , produced.constant.value - end - end -end diff --git a/test/mom/helper.rb b/test/mom/helper.rb index 2ab1cc66..3f91a123 100644 --- a/test/mom/helper.rb +++ b/test/mom/helper.rb @@ -1,76 +1 @@ require_relative '../helper' - -module Risc - module Statements - include Output - include Preloader - - def preamble - [ Label ] - end - def postamble - [Label, SlotToReg, SlotToReg, RegToSlot,SlotToReg, - SlotToReg, SlotToReg, FunctionReturn, Label,] - end - def produce_body - produced = produce_main - preamble.each{ produced = produced.next } - produced - end - - def as_block( block_input , method_input = "main_local = 5") - "#{method_input} ; self.main{|val| #{block_input}}" - end - def as_main - "#{preload}class Space; #{@class_input};def main(arg);#{@input};end;end" - end - def to_target - assert @expect , "No output given" - compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options) - vool = compiler.ruby_to_vool(as_main) - compiler.to_target(:interpreter) - end - def produce_main - produce_target(:main) - end - def produce_block - produce_target(:main_block) - end - def produce_target(name = :main_block) - linker = to_target - block = linker.assemblers.find {|c| c.callable.name == name } - assert_equal Risc::Assembler , block.class - block.instructions - end - def check_nil( name = :main ) - produced = produce_target( name ) - compare_instructions( produced , @expect ) - end - def check_return - was = check_nil - raise was if was - test = Parfait.object_space.get_class_by_name :Test - test.instance_type.get_method :main - end - def compare_instructions( instruction , expect ) - index = 0 - all = instruction.to_arr - full_expect = preamble + expect + postamble - #full_expect = expect - begin - should = full_expect[index] - return "No instruction at #{index-1}\n#{should(all)[0..100]}" unless should - return "Expected at #{index-1}\n#{should(all)} was #{instruction.to_s[0..100]}" unless instruction.class == should - #puts "#{index-1}:#{instruction.to_s}" if (index > preamble.length) and (index + postamble.length <= full_expect.length) - index += 1 - instruction = instruction.next - end while( instruction ) - nil - end - def should( all ) - preamble.each {all.shift} - postamble.each {all.pop} - class_list(all.collect{|i| i.class}) - end - end -end diff --git a/test/mom/send/test_send_dynamic.rb b/test/mom/send/test_send_dynamic.rb deleted file mode 100644 index 72497da6..00000000 --- a/test/mom/send/test_send_dynamic.rb +++ /dev/null @@ -1,48 +0,0 @@ -require_relative "../helper" - -module Risc - class TestSendDynamic < MiniTest::Test - include Statements - - def setup - @preload = "Integer.div4" - @input = "@classes.div4" - @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 - assert_nil msg = check_nil , msg - end - def test_sys - produced = produce_body - assert_equal Syscall , produced.next(29).class - assert_equal :died , produced.next(29).name - end - def test_load_address - produced = produce_body - assert_equal LoadConstant , produced.next(26).class - assert_equal Parfait::Factory , produced.next(26).constant.class - end - def test_function_call - produced = produce_body - assert_equal DynamicJump , produced.next(51).class - end - def test_cache_check - produced = produce_body - assert_equal IsZero , produced.next(6).class - assert_equal Label , produced.next(36).class - assert_equal produced.next(36) , produced.next(6).label - end - end -end diff --git a/test/mom/send/test_send_simple.rb b/test/mom/send/test_send_simple.rb deleted file mode 100644 index 394ebed4..00000000 --- a/test/mom/send/test_send_simple.rb +++ /dev/null @@ -1,39 +0,0 @@ -require_relative "../helper" - -module Risc - class TestCallSimple < MiniTest::Test - include Statements - - def setup - @preload = "Integer.div4" - @input = "5.div4" - @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(3) - assert_load( produced , Parfait::Integer) - assert_equal 5 , produced.constant.value - end - def test_load_label - produced = produce_body.next(6) - assert_load( produced , Label) - end - def test_function_call - 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(11) - assert_equal Label , produced.class - assert produced.name.start_with?("continue_") - end - #TODO check the message setup, type and frame moves - end -end diff --git a/test/mom/send/test_send_simple_args.rb b/test/mom/send/test_send_simple_args.rb deleted file mode 100644 index c399ea54..00000000 --- a/test/mom/send/test_send_simple_args.rb +++ /dev/null @@ -1,68 +0,0 @@ -require_relative "../helper" - -module Risc - class TestCallSimpleArgs < MiniTest::Test - include Statements - - def setup - @preload = "Object.get" - @input = "5.get_internal_word(1)" - @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 - assert_nil msg = check_nil , msg - end - def test_load_5 - produced = produce_body - assert_equal LoadConstant , produced.next(3).class - assert_equal 5 , produced.next(3).constant.value - end - def base - 6 - end - def test_load_arg_const - produced = produce_body - assert_load( produced.next(base) , Parfait::Integer ) - assert_equal 1 , produced.next(base).constant.value - end - def test_load_next_m - produced = produce_body.next(base+1) - assert_slot_to_reg( produced ,:r0 ,1 , :r2 ) - end - def test_store_arg_at - produced = produce_body.next(base+2) - assert_reg_to_slot( produced ,:r1 ,:r2 , 9 ) - end - def test_load_label - produced = produce_body.next(base+3) - assert_load( produced , Label ) - end - def test_load_some - produced = produce_body.next(base+4) - assert_slot_to_reg( produced ,:r0 ,1 , :r2 ) - end - def test_store_ - produced = produce_body.next(base+5) - assert_reg_to_slot( produced ,:r1 ,:r2 , 4 ) - end - - def test_swap_messages - produced = produce_body.next(base+6) - assert_slot_to_reg( produced ,:r0 ,1 , :r0 ) - end - - def test_function_call - produced = produce_body - assert_equal FunctionCall , produced.next(base+7).class - assert_equal :get_internal_word , produced.next(base+7).method.name - end - def test_check_continue - produced = produce_body - assert produced.next(base+8).name.start_with?("continue_") - end - end -end diff --git a/test/mom/send/test_setup_simple.rb b/test/mom/send/test_setup_simple.rb deleted file mode 100644 index 368d97a6..00000000 --- a/test/mom/send/test_setup_simple.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative "../helper" - -module Risc - class TestMessageSetupSimple < MiniTest::Test - include Statements - - def setup - @preload = "Integer.div4" - @input = "return 5.div4" - @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5 - RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10 - FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15 - @produced = produce_body - end - - def test_send_instructions - assert_nil msg = check_nil , msg - end - def test_load_method - method = @produced - assert_load( method, Parfait::CallableMethod ,:r1) - assert_equal :div4 , method.constant.name - end - def test_store_method_in_message - sl = @produced.next( 2 ) - assert_reg_to_slot( sl , :r1 , :r2 , 7 ) - end - end -end diff --git a/test/mom/test_if_else.rb b/test/mom/test_if_else.rb deleted file mode 100644 index 0233a032..00000000 --- a/test/mom/test_if_else.rb +++ /dev/null @@ -1,58 +0,0 @@ -require_relative "helper" - -module Risc - class TestIfElse < MiniTest::Test - include Statements - - def setup - @input = "if(@true_object) ; arg = 5 ; else; arg = 6; end;return" - @expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4 - LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9 - RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14 - Label, LoadConstant, RegToSlot, Branch] #19 - end - - def test_if_instructions - assert_nil msg = check_nil , msg - end - - def test_false_load - produced = produce_body - assert_equal Parfait::FalseClass , produced.next(2).constant.class - end - def test_false_check - produced = produce_body - assert_equal IsZero , produced.next(7).class - assert_equal Label , produced.next(12).class - assert_equal produced.next(12).name , produced.next(7).label.name - end - def test_nil_load - produced = produce_body - assert_equal Parfait::NilClass , produced.next(5).constant.class - end - def test_nil_check - produced = produce_body - assert_equal IsZero , produced.next(4).class - assert_equal Label , produced.next(12).class - assert_equal produced.next(12).name , produced.next(4).label.name - end - - def test_true_label - produced = produce_body - assert_equal Label , produced.next(8).class - assert produced.next(8).name.start_with?("true_label") - end - - def test_merge_label - produced = produce_body - assert_equal Label , produced.next(15).class - assert produced.next(15).name.start_with?("merge_label") - end - - def test_true_jump # should jumpp to merge label - produced = produce_body - assert_equal Branch , produced.next(11).class - assert produced.next(11).label.name.start_with?("merge_label") - end - end -end diff --git a/test/mom/test_if_no_else.rb b/test/mom/test_if_no_else.rb deleted file mode 100644 index 6018a8b5..00000000 --- a/test/mom/test_if_no_else.rb +++ /dev/null @@ -1,44 +0,0 @@ -require_relative "helper" - -module Risc - class TestIfNoElse < MiniTest::Test - include Statements - - def setup - @input = "if(@true_object) ; arg = 5 ; end;return" - @expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4 - LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9 - RegToSlot, Label, LoadConstant, RegToSlot, Branch] #14 - end - - def test_if_instructions - assert_nil msg = check_nil , msg - end - def test_false_load - produced = produce_body - assert_equal Parfait::FalseClass , produced.next(2).constant.class - end - def test_isnotzero - assert_equal IsZero , produce_body.next(4).class - end - def test_false_label - produced = produce_body - assert_equal Label , produced.next(11).class - end - def test_false_check - produced = produce_body - assert_equal IsZero , produce_body.next(4).class - assert_equal Label , produced.next(11).class - assert_equal produced.next(11).name , produced.next(4).label.name - end - def test_nil_load - produced = produce_body - assert_equal Parfait::NilClass , produced.next(5).constant.class - end - def test_true_label - produced = produce_body - assert produced.next(8).name.start_with?("true_label") - end - - end -end diff --git a/test/mom/test_if_no_if.rb b/test/mom/test_if_no_if.rb deleted file mode 100644 index 88db1c0f..00000000 --- a/test/mom/test_if_no_if.rb +++ /dev/null @@ -1,53 +0,0 @@ -require_relative "helper" - -module Risc - class TestIfNoIf < MiniTest::Test - include Statements - - def setup - super - @input = "unless(@true_object) ; arg = 5 ; end;return" - @expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4 - LoadConstant, OperatorInstruction, IsZero, Label, Branch, #9 - Label, LoadConstant, RegToSlot, Label, LoadConstant, #14 - RegToSlot, Branch] #19 - end - - def test_if_instructions - assert_nil msg = check_nil , msg - end - - def test_false_load - produced = produce_body - assert_equal Parfait::FalseClass , produced.next(2).constant.class - end - def test_isnotzero - produced = produce_body - check = produced.next(4) - assert_equal IsZero , check.class - assert check.label.name.start_with?("false_") , check.label.name - end - def test_false_label - produced = produce_body - assert_equal Label , produced.next(10).class - end - def test_false_check - produced = produce_body - assert_equal produced.next(10).name , produced.next(4).label.name - end - def test_nil_load - produced = produce_body - assert_equal Parfait::NilClass , produced.next(5).constant.class - end - def test_true_label - produced = produce_body - assert produced.next(8).name.start_with?("true_label") - end - def test_merge_label - produced = produce_body - assert_equal Label , produced.next(13).class - assert produced.next(13).name.start_with?("merge_label") - end - - end -end diff --git a/test/mom/test_return_call.rb b/test/mom/test_return_call.rb deleted file mode 100644 index f073e737..00000000 --- a/test/mom/test_return_call.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative "helper" - -module Risc - class TestReturnCall < MiniTest::Test - include Statements - - def setup - @preload = "Integer.div4" - @input = "return 5.div4" - @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(14) - assert_equal Branch , produced.class - assert_equal "return_label" , produced.label.name - end - def test_load_5 - produced = produce_body.next(3) - assert_equal LoadConstant , produced.class - assert_equal 5 , produced.constant.value - end - end -end diff --git a/test/mom/test_return_dynamic.rb b/test/mom/test_return_dynamic.rb deleted file mode 100644 index db07fad2..00000000 --- a/test/mom/test_return_dynamic.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative "helper" - -module Risc - class TestReturnDynamic < MiniTest::Test - include Statements - - def setup - @preload = "Integer.div4" - @input = "arg = 1 ;return arg.div4" - @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #5 - SlotToReg, OperatorInstruction, IsZero, 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, RegToSlot, LoadConstant, #45 - SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #50 - DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #55 - end - - def test_return_instructions - assert_nil msg = check_nil , msg - end - def test_function_return - produced = produce_body - assert_equal Branch , produced.next(54).class - end - def test_cache_check - produced = produce_body - assert_equal IsZero , produced.next(7).class - end - end -end diff --git a/test/mom/test_return_sequence.rb b/test/mom/test_return_sequence.rb deleted file mode 100644 index 5a3e37ca..00000000 --- a/test/mom/test_return_sequence.rb +++ /dev/null @@ -1,52 +0,0 @@ -require_relative "helper" - -module Risc - class TestReturnSequence < MiniTest::Test - include Statements - - def setup - @preload = "Integer.div4" - @input = "return 5.div4" - @expect = "something" - end - 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| - assert_equal ins , instruction( index).class , "wrong at #{index}" - end - end - def test_main_label - assert_equal Label , instruction(0).class - assert_equal "return_label" , instruction(0).name - end - def test_move_ret - assert_slot_to_reg( instruction( 1 ) , :r0 , 5 , :r1 ) - end - def test_move_caller - assert_slot_to_reg( instruction( 2 ) , :r0 , 6 , :r2 ) - end - def test_save_ret - assert_reg_to_slot( instruction( 3 ) , :r1 , :r2 , 5 ) - end - def test_get_next - assert_slot_to_reg( instruction( 4 ) , :r0 , 4 , :r3 ) - end - def test_save_addr - assert_slot_to_reg( instruction( 5 ) , :r3 , 2 , :r3 ) - end - def test_reduce_caller - assert_slot_to_reg( instruction( 6 ) , :r0 , 6 , :r0 ) - end - def test_function_return - ret = instruction(7) - assert_equal FunctionReturn , ret.class - assert_equal :r3 , ret.register.symbol - end - def test_unreachable - assert_equal Label , instruction(8).class - assert_equal "unreachable" , instruction(8).name - end - end -end diff --git a/test/mom/test_return_simple.rb b/test/mom/test_return_simple.rb deleted file mode 100644 index c6227422..00000000 --- a/test/mom/test_return_simple.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative "helper" - -module Risc - class TestReturnSimple < MiniTest::Test - include Statements - - def setup - @input = "return 5" - @expect = [LoadConstant, RegToSlot, Branch] - end - - def test_return_instructions - assert_nil msg = check_nil , msg - end - def test_function_return - produced = produce_body - assert_equal Branch , produced.next(2).class - end - def test_load_5 - produced = produce_body - assert_equal 5 , produced.constant.value - end - end -end diff --git a/test/mom/test_while_cmp.rb b/test/mom/test_while_cmp.rb deleted file mode 100644 index 53b53c84..00000000 --- a/test/mom/test_while_cmp.rb +++ /dev/null @@ -1,57 +0,0 @@ -require_relative "helper" - -module Risc - class TestWhileCmp < MiniTest::Test - include Statements - - def setup - @preload = "Integer.gt" - @input = "while(5 > 0) ; @false_object = true; end;return" - @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 - assert_nil msg = check_nil , msg - end - def test_label - assert_equal Risc::Label , produce_body.class - end - def test_int_load_5 - produced = produce_body - 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(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(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(23).class - assert_equal Parfait::TrueClass , produced.next(23).constant.class - end - - def test_back_jump # should jump back to condition label - produced = produce_body - assert_equal Risc::Branch , produced.next(26).class - assert_equal produced.name , produced.next(26).label.name - end - - end -end diff --git a/test/mom/test_while_simple.rb b/test/mom/test_while_simple.rb deleted file mode 100644 index 18abb5f3..00000000 --- a/test/mom/test_while_simple.rb +++ /dev/null @@ -1,43 +0,0 @@ -require_relative "helper" - -module Risc - class TestWhileSimple < MiniTest::Test - include Statements - - def setup - @input = "while(@true_object) ; arg = 5 end;return" - @expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, #4 - IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #9 - RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14 - Branch] #19 - end - - def test_while_instructions - assert_nil msg = check_nil , msg - end - - def test_false_load - produced = produce_body - assert_equal Parfait::FalseClass , produced.next(3).constant.class - end - def test_false_check - produced = produce_body - assert_equal IsZero , produced.next(5).class - assert_equal Label , produced.next(12).class - assert_equal produced.next(12).name , produced.next(5).label.name - end - def test_nil_load - produced = produce_body - assert_equal Parfait::NilClass , produced.next(6).constant.class - end - def test_merge_label - produced = produce_body - assert produced.next(12).name.start_with?("merge_label") - end - def test_back_jump # should jump back to condition label - produced = produce_body - assert_equal Branch , produced.next(11).class - assert_equal produced.name , produced.next(11).label.name - end - end -end