2018-03-15 06:54:14 +01:00
|
|
|
require_relative "normalizer"
|
2017-09-05 11:04:52 +02:00
|
|
|
|
2017-04-01 20:28:57 +02:00
|
|
|
module Vool
|
|
|
|
class WhileStatement < Statement
|
2018-03-15 06:54:14 +01:00
|
|
|
include Normalizer
|
2018-03-16 08:03:11 +01:00
|
|
|
attr_reader :condition , :body
|
2017-04-03 10:49:21 +02:00
|
|
|
|
2018-03-16 08:03:11 +01:00
|
|
|
def initialize( condition , body )
|
2017-04-03 10:49:21 +02:00
|
|
|
@condition = condition
|
2018-03-16 08:03:11 +01:00
|
|
|
@body = body
|
2017-04-03 10:49:21 +02:00
|
|
|
end
|
2017-04-06 15:06:51 +02:00
|
|
|
|
2018-03-16 08:03:11 +01:00
|
|
|
def normalize
|
2018-03-16 14:11:17 +01:00
|
|
|
cond , rest = *normalize_name(@condition)
|
2018-03-16 08:03:11 +01:00
|
|
|
me = WhileStatement.new(cond , @body.normalize)
|
2018-03-15 06:54:14 +01:00
|
|
|
return me unless rest
|
|
|
|
rest << me
|
2018-03-16 08:03:11 +01:00
|
|
|
rest
|
2018-03-15 06:54:14 +01:00
|
|
|
end
|
|
|
|
|
2017-09-05 11:04:52 +02:00
|
|
|
def to_mom( method )
|
2018-03-16 08:03:11 +01:00
|
|
|
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 11:04:52 +02:00
|
|
|
end
|
|
|
|
|
2018-03-16 08:03:11 +01:00
|
|
|
def each(&block)
|
|
|
|
block.call(self)
|
2018-03-20 08:59:18 +01:00
|
|
|
block.call(@condition)
|
2018-03-16 08:03:11 +01:00
|
|
|
@body.each(&block)
|
2017-04-08 11:10:42 +02:00
|
|
|
end
|
|
|
|
|
2017-04-01 20:28:57 +02:00
|
|
|
end
|
|
|
|
end
|