rubyx/lib/vool/statements/while_statement.rb
2018-03-16 18:41:17 +05:30

38 lines
904 B
Ruby

require_relative "normalizer"
module Vool
class WhileStatement < Statement
include Normalizer
attr_reader :condition , :body
def initialize( condition , body )
@condition = condition
@body = body
end
def normalize
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)
@condition.each(&block)
@body.each(&block)
end
end
end