2017-09-05 11:04:52 +02:00
|
|
|
|
|
|
|
module Mom
|
2017-09-06 11:11:30 +02:00
|
|
|
class WhileStatement < Statement
|
2017-09-05 11:04:52 +02:00
|
|
|
attr_reader :condition , :statements
|
|
|
|
|
|
|
|
attr_accessor :hoisted
|
|
|
|
|
|
|
|
def initialize( cond , statements)
|
|
|
|
@condition = cond
|
|
|
|
@statements = statements
|
|
|
|
end
|
2017-09-08 12:22:20 +02:00
|
|
|
|
|
|
|
def flatten
|
|
|
|
cond_label = Label.new( "cond_label_#{object_id}")
|
|
|
|
head = cond_label
|
|
|
|
head.append hoisted.flatten
|
|
|
|
merge_label = Label.new( "merge_label_#{object_id}")
|
|
|
|
head.append condition.flatten( true_label: cond_label , false_label: merge_label)
|
|
|
|
head.append merge_label
|
|
|
|
head
|
|
|
|
end
|
|
|
|
|
2017-09-05 11:04:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|