diff --git a/.reek b/.reek index 7ed446d6..af0db6ad 100644 --- a/.reek +++ b/.reek @@ -13,13 +13,15 @@ FeatureEnvy: - "Arm::Translator" - "Vm::ToCode" TooManyMethods: + max_methods: 30 exclude: - "Vool::Compiler" - "RubyX::RubyCompiler" + - "Ruby::RubyCompiler" - "Risc::Interpreter" - "Risc::TextWriter" - "Arm::Translator" - - "Vm::ToCode" + - "Util::List" UtilityFunction: exclude: - "Vool::Compiler" diff --git a/.travis.yml b/.travis.yml index 19cfade4..8df26332 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ +before_install: + - sudo apt-get install -y qemu language: ruby -sudo: false before_install: gem install bundler --version '2.0.1' script: - ruby test/test_all.rb - bundle exec codeclimate-test-reporter rvm: - - 2.4.5 - - 2.5.3 - - 2.6.1 + - 2.4.6 + - 2.5.5 + - 2.6.3 diff --git a/lib/vool/if_statement.rb b/lib/vool/if_statement.rb index 3e4b26b8..92ed69a5 100644 --- a/lib/vool/if_statement.rb +++ b/lib/vool/if_statement.rb @@ -11,36 +11,23 @@ module Vool end def to_mom( compiler ) - if_false ? full_if(compiler) : simple_if(compiler) - end - - def simple_if(compiler) - true_label = Mom::Label.new( self,"true_label_#{object_id.to_s(16)}") - merge_label = Mom::Label.new( self,"merge_label_#{object_id.to_s(16)}") - - head = Mom::TruthCheck.new(condition.slot_definition(compiler) , merge_label) - head << true_label - head << if_true.to_mom(compiler) - head << merge_label - end - - def full_if(compiler) true_label = Mom::Label.new( self , "true_label_#{object_id.to_s(16)}") false_label = Mom::Label.new( self , "false_label_#{object_id.to_s(16)}") merge_label = Mom::Label.new( self , "merge_label_#{object_id.to_s(16)}") head = Mom::TruthCheck.new(condition.slot_definition(compiler) , false_label) head << true_label - head << if_true.to_mom(compiler) - head << Mom::Jump.new(merge_label) + head << if_true.to_mom(compiler) if @if_true + head << Mom::Jump.new(merge_label) if @if_false head << false_label - head << if_false.to_mom(compiler) - head << merge_label + head << if_false.to_mom(compiler) if @if_false + head << merge_label if @if_false + head end def each(&block) block.call(condition) - @if_true.each(&block) + @if_true.each(&block) if @if_true @if_false.each(&block) if @if_false end diff --git a/test/mom/test_if_no_else.rb b/test/mom/test_if_no_else.rb index 1407c1ec..79582afb 100644 --- a/test/mom/test_if_no_else.rb +++ b/test/mom/test_if_no_else.rb @@ -24,7 +24,6 @@ module Risc produced = produce_body check = produced.next(4) assert_equal IsZero , check.class - assert check.label.name.start_with?("merge_label") , check.label.name end def test_false_label produced = produce_body diff --git a/test/mom/test_if_no_if.rb b/test/mom/test_if_no_if.rb new file mode 100644 index 00000000..ca63c8cf --- /dev/null +++ b/test/mom/test_if_no_if.rb @@ -0,0 +1,56 @@ +require_relative "helper" + +module Risc + class TestIfNoIf < MiniTest::Test + include Statements + + def setup + super + @input = "unless(@a) ; arg = 5 ; end" + @expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4 + LoadConstant, OperatorInstruction, IsZero, Label, Branch, #9 + Label, LoadConstant, SlotToReg, RegToSlot, Label] #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 + 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 est_nil_check + produced = produce_body + assert_equal Label , produced.next(4).label.class + assert_equal produced.next(12) , produced.next(4).label + 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 produced.next(14).name.start_with?("merge_label") + end + + end +end diff --git a/test/vool/test_if_no_if.rb b/test/vool/test_if_no_if.rb new file mode 100644 index 00000000..066210c2 --- /dev/null +++ b/test/vool/test_if_no_if.rb @@ -0,0 +1,31 @@ + +require_relative "helper" + +module Vool + class TestIfNoIf < MiniTest::Test + include VoolCompile + + def setup + Parfait.boot!(Parfait.default_test_options) + @compiler = compile_first_method( "unless(@a) ; @a = 5 ; end") + @ins = @compiler.mom_instructions.next + end + + def test_condition_compiles_to_check + assert_equal TruthCheck , @ins.class , @ins + end + def test_condition_is_slot + assert_equal SlotDefinition , @ins.condition.class , @ins + end + def test_label_after_check + assert_equal Label , @ins.next.class , @ins + end + def test_label_last + assert_equal Label , @ins.last.class , @ins + end + def test_array + check_array [TruthCheck, Label, Jump, Label, SlotLoad , + Label, Label, ReturnSequence, Label] , @ins + end + end +end diff --git a/test/vool/test_if_condition.rb b/test/vool/test_if_statement.rb similarity index 100% rename from test/vool/test_if_condition.rb rename to test/vool/test_if_statement.rb