adds mom while

much like the if, difference will show later in the jump arrangement
This commit is contained in:
Torsten Ruger
2017-09-05 12:04:52 +03:00
parent 76a87dd418
commit af85cb7c67
5 changed files with 81 additions and 0 deletions

View File

@ -1,5 +1,8 @@
require_relative "hoister"
module Vool
class WhileStatement < Statement
include Hoister
attr_reader :condition , :statements
def initialize( condition , statements )
@ -8,6 +11,15 @@ module Vool
simplify_condition
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?