From 349dd37c82458ebf7d8e12c9e11e19c2bbe24c9e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 30 Aug 2017 18:23:54 +0300 Subject: [PATCH] small refactor --- lib/vool/statements/if_statement.rb | 17 ++++++++++------- .../to_mom/{test_if.rb => test_simple_if.rb} | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) rename test/vool/to_mom/{test_if.rb => test_simple_if.rb} (94%) diff --git a/lib/vool/statements/if_statement.rb b/lib/vool/statements/if_statement.rb index 62620057..bbe73d90 100644 --- a/lib/vool/statements/if_statement.rb +++ b/lib/vool/statements/if_statement.rb @@ -12,18 +12,14 @@ module Vool def to_mom( method ) if_true = @if_true.to_mom( method ) if_false = @if_false.to_mom( method ) - make_condition( if_true , if_false ) + merge = Mom::Noop.new(:merge) + make_condition( add_jump(if_true,merge) , add_jump(if_false,merge) , merge) end # conditions in ruby are almost always method sends (as even comparisons are) # currently we just deal with straight up values which get tested # for the funny ruby logic (everything but false and nil is true) - def make_condition( if_true , if_false ) - merge = Mom::Noop.new(:merge) - if_true = [if_true] unless if_true.is_a?(Array) - if_true << Mom::Jump.new(merge) - if_false = [if_false] unless if_false.is_a?(Array) - if_false << Mom::Jump.new(merge) + def make_condition( if_true , if_false , merge) check = Mom::TruthCheck.new( @condition , if_true , if_false , merge) [ check , if_true , if_false , merge ] end @@ -46,5 +42,12 @@ module Vool def has_true? @if_true != nil end + + private + def add_jump( block , merge) + block = [block] unless block.is_a?(Array) + block << Mom::Jump.new(merge) + block + end end end diff --git a/test/vool/to_mom/test_if.rb b/test/vool/to_mom/test_simple_if.rb similarity index 94% rename from test/vool/to_mom/test_if.rb rename to test/vool/to_mom/test_simple_if.rb index 033c61d8..4e5730c5 100644 --- a/test/vool/to_mom/test_if.rb +++ b/test/vool/to_mom/test_simple_if.rb @@ -2,7 +2,7 @@ require_relative "helper" module Vool - class TestIfMom < MiniTest::Test + class TestSimpleIfMom < MiniTest::Test include MomCompile def setup