From 76a87dd418ccd932a768681ec3598df2e6236f15 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 5 Sep 2017 12:04:12 +0300 Subject: [PATCH] extract hoisting to module to be used in while statement --- lib/vool/statements/hoister.rb | 10 ++++++++++ lib/vool/statements/if_statement.rb | 9 +++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 lib/vool/statements/hoister.rb diff --git a/lib/vool/statements/hoister.rb b/lib/vool/statements/hoister.rb new file mode 100644 index 00000000..eee5bce3 --- /dev/null +++ b/lib/vool/statements/hoister.rb @@ -0,0 +1,10 @@ +module Vool + module Hoister + def hoist_condition( method ) + return [@condition] if @condition.is_a?(Vool::Named) + local = method.create_tmp + assign = LocalAssignment.new( local , @condition) + [Vool::LocalVariable.new(local) , assign] + end + end +end diff --git a/lib/vool/statements/if_statement.rb b/lib/vool/statements/if_statement.rb index bab08c8b..8a1e4e49 100644 --- a/lib/vool/statements/if_statement.rb +++ b/lib/vool/statements/if_statement.rb @@ -1,5 +1,8 @@ +require_relative "hoister" module Vool class IfStatement < Statement + include Hoister + attr_reader :condition , :if_true , :if_false def initialize( cond , if_true , if_false = nil) @@ -19,12 +22,6 @@ module Vool check end - def hoist_condition( method ) - return [@condition] if @condition.is_a?(Vool::Named) - local = method.create_tmp - assign = LocalAssignment.new( local , @condition) - [Vool::LocalVariable.new(local) , assign] - end def collect(arr) @if_true.collect(arr)