extract hoisting to module
to be used in while statement
This commit is contained in:
parent
65ba867aa9
commit
76a87dd418
10
lib/vool/statements/hoister.rb
Normal file
10
lib/vool/statements/hoister.rb
Normal 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
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user