From 11c5389e2490b3b7ad734f310cb9595e85a69a75 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 5 Mar 2019 20:30:24 +0200 Subject: [PATCH] Fix if logic error ifs may have an empty true block Especially for unlesses thet is normal, so allow --- lib/ruby/if_statement.rb | 5 +++-- lib/ruby/ruby_compiler.rb | 2 +- test/rubyx/helper.rb | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/ruby/if_statement.rb b/lib/ruby/if_statement.rb index f1377720..4f866d06 100644 --- a/lib/ruby/if_statement.rb +++ b/lib/ruby/if_statement.rb @@ -23,7 +23,7 @@ module Ruby def to_vool cond , rest = *normalize_name(@condition) - me = Vool::IfStatement.new(cond.to_vool , @if_true.to_vool, @if_false&.to_vool) + me = Vool::IfStatement.new(cond.to_vool , @if_true&.to_vool, @if_false&.to_vool) return me unless rest Vool::Statements.new([ rest.to_vool , me]) end @@ -37,7 +37,8 @@ module Ruby end def to_s(depth = 0) - parts = ["if(#{@condition})" , @if_true.to_s(depth + 1) ] + parts = ["if(#{@condition})" ] + parts << @if_true.to_s(depth + 1) if(@if_true) parts += ["else" , @if_false.to_s(depth + 1)] if(@if_false) parts << "end" at_depth(depth , *parts ) diff --git a/lib/ruby/ruby_compiler.rb b/lib/ruby/ruby_compiler.rb index 49f078aa..01b8ebfa 100644 --- a/lib/ruby/ruby_compiler.rb +++ b/lib/ruby/ruby_compiler.rb @@ -16,7 +16,7 @@ module Ruby end # This RubyCompiler compiles incoming ruby (string) into a typed - # version of theast, with the help of the parser gem. + # version of the ast, with the help of the parser gem. # The parser outputs an abstract ast (nodes) # that get transformed into concrete, specific classes. # diff --git a/test/rubyx/helper.rb b/test/rubyx/helper.rb index b57061bb..d6f7a191 100644 --- a/test/rubyx/helper.rb +++ b/test/rubyx/helper.rb @@ -6,17 +6,19 @@ module RubyX def setup end def ruby_to_risc(input , options = {}) - mom = ruby_to_mom(input) + mom = ruby_to_mom(input , options) mom.translate(options[:platform] || :interpreter) end def ruby_to_vool(input, options = {}) - RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(input) + options = RubyX.default_test_options.merge(options) + RubyXCompiler.new(options).ruby_to_vool(input) end def ruby_to_mom(input , options = {}) - RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input) + options = RubyX.default_test_options.merge(options) + RubyXCompiler.new(options).ruby_to_mom(input) end def compile_in_test( input , options = {}) - vool = ruby_to_vool in_Test(input) + vool = ruby_to_vool(in_Test(input) , options) vool.to_mom(nil) itest = Parfait.object_space.get_class_by_name(:Test) assert itest