Fix if logic error

ifs may have an empty true block
Especially for unlesses thet is normal, so allow
This commit is contained in:
Torsten Ruger 2019-03-05 20:30:24 +02:00
parent 9bd2195a15
commit 11c5389e24
3 changed files with 10 additions and 7 deletions

View File

@ -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 )

View File

@ -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.
#

View File

@ -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