extract hoisting to module

to be used in while statement
This commit is contained in:
Torsten Ruger 2017-09-05 12:04:12 +03:00
parent 65ba867aa9
commit 76a87dd418
2 changed files with 13 additions and 6 deletions

View File

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

View File

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