rubyx/lib/vool/statements/while_statement.rb

36 lines
863 B
Ruby
Raw Normal View History

require_relative "hoister"
2017-04-01 20:28:57 +02:00
module Vool
class WhileStatement < Statement
include Hoister
attr_reader :condition , :statements
2017-04-03 10:49:21 +02:00
def initialize( condition , statements )
2017-04-03 10:49:21 +02:00
@condition = condition
@statements = statements
simplify_condition
2017-04-03 10:49:21 +02:00
end
def to_mom( method )
statements = @statements.to_mom( method )
condition , hoisted = hoist_condition( method )
cond = Mom::TruthCheck.new(condition.to_mom(method))
check = Mom::WhileStatement.new( cond , statements )
check.hoisted = hoisted.to_mom(method) if hoisted
check
end
def simplify_condition
return unless @condition.is_a?(ScopeStatement)
@condition = @condition.first if @condition.single?
end
2017-04-08 11:10:42 +02:00
def collect(arr)
@condition.collect(arr)
@statements.collect(arr)
super
end
2017-04-01 20:28:57 +02:00
end
end