rubyx/lib/mom/statement/while_statement.rb

26 lines
595 B
Ruby
Raw Normal View History

module Mom
2017-09-06 11:11:30 +02:00
class WhileStatement < Statement
attr_reader :condition , :statements
attr_accessor :hoisted
def initialize( cond , statements)
@condition = cond
@statements = statements
end
2017-09-08 12:22:20 +02:00
2018-03-12 13:43:26 +01:00
def flatten(options = {})
2017-09-08 12:22:20 +02:00
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
2017-09-08 12:22:20 +02:00
end
end
end