From d86282b007da411daabb55ebf83e828f5932537d Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 8 Sep 2017 13:22:20 +0300 Subject: [PATCH] flattening of moms while --- lib/mom/while_statement.rb | 11 ++++++++ ...test_if_simple.rb => test_if_statement.rb} | 0 test/mom/test_while_statement.rb | 27 +++++++++++++++++++ 3 files changed, 38 insertions(+) rename test/mom/{test_if_simple.rb => test_if_statement.rb} (100%) create mode 100644 test/mom/test_while_statement.rb diff --git a/lib/mom/while_statement.rb b/lib/mom/while_statement.rb index b9a17e31..18de8e07 100644 --- a/lib/mom/while_statement.rb +++ b/lib/mom/while_statement.rb @@ -9,6 +9,17 @@ module Mom @condition = cond @statements = statements end + + def flatten + cond_label = Label.new( "cond_label_#{object_id}") + head = cond_label + head.append hoisted.flatten + merge_label = Label.new( "merge_label_#{object_id}") + head.append condition.flatten( true_label: cond_label , false_label: merge_label) + head.append merge_label + head + end + end end diff --git a/test/mom/test_if_simple.rb b/test/mom/test_if_statement.rb similarity index 100% rename from test/mom/test_if_simple.rb rename to test/mom/test_if_statement.rb diff --git a/test/mom/test_while_statement.rb b/test/mom/test_while_statement.rb new file mode 100644 index 00000000..a7bc0fc2 --- /dev/null +++ b/test/mom/test_while_statement.rb @@ -0,0 +1,27 @@ + +require_relative "helper" + +module Mom + class TestWhileConditionMom < MiniTest::Test + include MomCompile + + def setup + Risc.machine.boot + @stats = compile_first_method_flat( "while(@a == 5) ; 5.mod4 ; end") + @first = @stats.next.next + end + + def test_if_compiles + assert IfStatement != @stats.class , @stats + end + def test_check + assert_equal TruthCheck , @first.class + end + def test_condition_is_slot + assert_equal SlotDefinition , @first.condition.class , @first + end + def test_length + assert_equal 4 , @stats.length + end + end +end