2018-03-15 11:24:14 +05:30
|
|
|
require_relative "normalizer"
|
2017-09-05 12:04:52 +03:00
|
|
|
|
2017-04-01 21:28:57 +03:00
|
|
|
module Vool
|
|
|
|
class WhileStatement < Statement
|
2018-03-15 11:24:14 +05:30
|
|
|
include Normalizer
|
2018-03-16 12:33:11 +05:30
|
|
|
attr_reader :condition , :body
|
2017-04-03 11:49:21 +03:00
|
|
|
|
2018-03-16 12:33:11 +05:30
|
|
|
def initialize( condition , body )
|
2017-04-03 11:49:21 +03:00
|
|
|
@condition = condition
|
2018-03-16 12:33:11 +05:30
|
|
|
@body = body
|
2017-04-03 11:49:21 +03:00
|
|
|
end
|
2017-04-06 16:06:51 +03:00
|
|
|
|
2018-03-16 12:33:11 +05:30
|
|
|
def normalize
|
2018-03-16 18:41:17 +05:30
|
|
|
cond , rest = *normalize_name(@condition)
|
2018-03-16 12:33:11 +05:30
|
|
|
me = WhileStatement.new(cond , @body.normalize)
|
2018-03-15 11:24:14 +05:30
|
|
|
return me unless rest
|
|
|
|
rest << me
|
2018-03-16 12:33:11 +05:30
|
|
|
rest
|
2018-03-15 11:24:14 +05:30
|
|
|
end
|
|
|
|
|
2017-09-05 12:04:52 +03:00
|
|
|
def to_mom( method )
|
2018-03-16 12:33:11 +05:30
|
|
|
merge_label = Mom::Label.new( "merge_label_#{object_id}")
|
|
|
|
cond_label = Mom::Label.new( "cond_label_#{object_id}")
|
|
|
|
cond_label << Mom::TruthCheck.new(condition.slot_definition(method) , merge_label)
|
|
|
|
cond_label << @body.to_mom(method)
|
|
|
|
cond_label << Mom::Jump.new(cond_label)
|
|
|
|
cond_label << merge_label
|
2017-09-05 12:04:52 +03:00
|
|
|
end
|
|
|
|
|
2018-03-16 12:33:11 +05:30
|
|
|
def each(&block)
|
|
|
|
block.call(self)
|
2018-03-20 13:29:18 +05:30
|
|
|
block.call(@condition)
|
2018-03-16 12:33:11 +05:30
|
|
|
@body.each(&block)
|
2017-04-08 12:10:42 +03:00
|
|
|
end
|
|
|
|
|
2017-04-01 21:28:57 +03:00
|
|
|
end
|
|
|
|
end
|