2017-09-05 12:04:52 +03:00
|
|
|
|
|
|
|
module Mom
|
2017-09-06 12:11:30 +03:00
|
|
|
class WhileStatement < Statement
|
2017-09-05 12:04:52 +03:00
|
|
|
attr_reader :condition , :statements
|
|
|
|
|
|
|
|
attr_accessor :hoisted
|
|
|
|
|
|
|
|
def initialize( cond , statements)
|
|
|
|
@condition = cond
|
|
|
|
@statements = statements
|
|
|
|
end
|
2017-09-08 13:22:20 +03:00
|
|
|
|
2018-03-12 18:13:26 +05:30
|
|
|
def flatten(options = {})
|
2017-09-08 13:22:20 +03:00
|
|
|
merge_label = Label.new( "merge_label_#{object_id}")
|
2018-03-13 16:16:06 +05:30
|
|
|
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 13:22:20 +03:00
|
|
|
end
|
|
|
|
|
2017-09-05 12:04:52 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|