rubyx/lib/vool/statements/while_statement.rb

38 lines
903 B
Ruby
Raw Normal View History

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