79bf416e58
different slot operation have different right sides mom assignment tests work again 157 others don’t
53 lines
1.4 KiB
Ruby
53 lines
1.4 KiB
Ruby
require_relative "normalizer"
|
|
|
|
module Vool
|
|
class WhileStatement < Statement
|
|
include Normalizer
|
|
attr_reader :condition , :statements
|
|
|
|
def initialize( condition , statements )
|
|
@condition = condition
|
|
@statements = statements
|
|
simplify_condition
|
|
end
|
|
|
|
def normalize(method)
|
|
cond , rest = *normalize_name(@condition)
|
|
me = WhileStatement.new(cond , @statements.normalize(method))
|
|
return me unless rest
|
|
rest << me
|
|
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 flatten(options = {})
|
|
merge_label = Label.new( "merge_label_#{object_id}")
|
|
cond_label = Label.new( "cond_label_#{object_id}")
|
|
@nekst = cond_label
|
|
@nekst.append(hoisted.flatten) if hoisted
|
|
@nekst.append condition.flatten( true_label: cond_label , false_label: merge_label)
|
|
@nekst.append merge_label
|
|
@nekst
|
|
end
|
|
|
|
def simplify_condition
|
|
return unless @condition.is_a?(ScopeStatement)
|
|
@condition = @condition.first if @condition.single?
|
|
end
|
|
|
|
def collect(arr)
|
|
@condition.collect(arr)
|
|
@statements.collect(arr)
|
|
super
|
|
end
|
|
|
|
end
|
|
end
|