From 5ab021de5a90eac07ae9e24d44c4fb50e12ed4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Sun, 15 Sep 2019 18:31:10 +0300 Subject: [PATCH] Continue testing mom instructions especially with the custom asserts, gadda say mesa lika disa --- lib/mom/instruction/slot_definition.rb | 2 +- test/mom/instruction/helper.rb | 2 +- .../mom/instruction/test_argument_transfer.rb | 29 +++++++++++++++ test/mom/instruction/test_block_yield.rb | 35 +++++++++++++++++++ test/mom/instruction/test_dynamic_call.rb | 1 + test/mom/test_callable_compiler.rb | 2 +- test/risc/test_callable_compiler.rb | 2 -- test/support/fake_compiler.rb | 7 ++-- 8 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 test/mom/instruction/test_argument_transfer.rb create mode 100644 test/mom/instruction/test_block_yield.rb diff --git a/lib/mom/instruction/slot_definition.rb b/lib/mom/instruction/slot_definition.rb index ca5bee1e..6b19b6f1 100644 --- a/lib/mom/instruction/slot_definition.rb +++ b/lib/mom/instruction/slot_definition.rb @@ -96,7 +96,7 @@ module Mom # type information inferred from their names / type hierachy def sym_to_risc(compiler , source) slots = @slots.dup - raise "Not Message #{object}" unless @known_object == :message + raise "Not Message #{@known_object}" unless @known_object == :message left = Risc.message_reg left = left.resolve_and_add( slots.shift , compiler) reg = compiler.current.register diff --git a/test/mom/instruction/helper.rb b/test/mom/instruction/helper.rb index e2b82d49..c3fb815c 100644 --- a/test/mom/instruction/helper.rb +++ b/test/mom/instruction/helper.rb @@ -12,7 +12,7 @@ module Mom def setup Parfait.boot!(Parfait.default_test_options) @instruction = instruction - @compiler = Risc::MethodCompiler.new(FakeCallable.new , Label.new("source","start")) + @compiler = Risc::MethodCompiler.new(Risc::FakeCallable.new , Label.new("source","start")) @instruction.to_risc(@compiler) @risc = @compiler.risc_instructions end diff --git a/test/mom/instruction/test_argument_transfer.rb b/test/mom/instruction/test_argument_transfer.rb new file mode 100644 index 00000000..dc71ea13 --- /dev/null +++ b/test/mom/instruction/test_argument_transfer.rb @@ -0,0 +1,29 @@ +require_relative "helper" + +module Mom + class TestArgumentTransfer < MomInstructionTest + def instruction + receiver = SlotDefinition.new(:message , [:receiver]) + arg = SlotLoad.new("test", [:message, :caller] , [:message,:type] ) + ArgumentTransfer.new("" , receiver ,[arg]) + end + def test_len + assert_equal 6 , all.length , all_str + end + def test_1_slot + assert_slot_to_reg risc(1) ,:r0 , 2 , :r2 + end + def test_2_slot + assert_slot_to_reg risc(2) ,:r0 , 1 , :r3 + end + def test_3_reg + assert_reg_to_slot risc(3) , :r2 , :r3 , 2 + end + def test_4_slot + assert_slot_to_reg risc(4) ,:r0 , 0 , :r2 + end + def test_5_reg + assert_reg_to_slot risc(5) , :r2 , :r0 , 6 + end + end +end diff --git a/test/mom/instruction/test_block_yield.rb b/test/mom/instruction/test_block_yield.rb new file mode 100644 index 00000000..8188c742 --- /dev/null +++ b/test/mom/instruction/test_block_yield.rb @@ -0,0 +1,35 @@ +require_relative "helper" + +module Mom + class TesBlockYield < MomInstructionTest + def instruction + BlockYield.new("source",1) + end + def test_len + assert_equal 8 , all.length , all_str + end + def test_1_slot + assert_slot_to_reg risc(1) ,:r0 , 1 , :r1 + end + def test_2_load + assert_load risc(2) , Risc::Label , :r2 + assert_label risc(2).constant , "continue_" + end + def test_3_reg + assert_reg_to_slot risc(3) , :r2 , :r1 , 4 + end + def test_4_slot + assert_slot_to_reg risc(4) ,:r0 , 9 , :r3 + end + def test_5_slot + assert_slot_to_reg risc(5) ,:r0 , 1 , :r0 + end + def test_6_jump + assert_equal Risc::DynamicJump , risc(6).class + assert_equal :r3 , risc(6).register.symbol + end + def test_7_label + assert_label risc(7) , "continue_" + end + end +end diff --git a/test/mom/instruction/test_dynamic_call.rb b/test/mom/instruction/test_dynamic_call.rb index f02389be..7c7c0985 100644 --- a/test/mom/instruction/test_dynamic_call.rb +++ b/test/mom/instruction/test_dynamic_call.rb @@ -10,6 +10,7 @@ module Mom end def test_1_load assert_load risc(1) , Risc::Label , :r1 + assert_label risc(1).constant , "continue_" end def test_2_slot assert_slot_to_reg risc(2) ,:r0 , 1 , :r2 diff --git a/test/mom/test_callable_compiler.rb b/test/mom/test_callable_compiler.rb index 23061212..3bce6d37 100644 --- a/test/mom/test_callable_compiler.rb +++ b/test/mom/test_callable_compiler.rb @@ -8,7 +8,7 @@ module Mom class TestCallableCompiler < MiniTest::Test def setup - @compiler = FakeCallableCompiler.new(FakeCallable.new) + @compiler = FakeCallableCompiler.new(Risc::FakeCallable.new) end def test_ok assert @compiler diff --git a/test/risc/test_callable_compiler.rb b/test/risc/test_callable_compiler.rb index 9d7022dd..db3dd02d 100644 --- a/test/risc/test_callable_compiler.rb +++ b/test/risc/test_callable_compiler.rb @@ -1,7 +1,5 @@ require_relative "helper" module Risc - class FakeCallable - end class FakeCallableCompiler < CallableCompiler def initialize(a,c) super(a,c) diff --git a/test/support/fake_compiler.rb b/test/support/fake_compiler.rb index 9fa8cd2e..e13ae252 100644 --- a/test/support/fake_compiler.rb +++ b/test/support/fake_compiler.rb @@ -1,6 +1,9 @@ -class FakeCallable -end module Risc + class FakeCallable + def self_type + Parfait.object_space.types.values.first + end + end class FakeCompiler attr_reader :instructions def initialize