rubyx/lib/vool/while_statement.rb
Torsten Ruger ae3d64eb53 moved all the normalize stuff over to the ruby layer
Which is how it should have been from the start
2018-07-19 14:47:29 +03:00

36 lines
952 B
Ruby

module Vool
class WhileStatement < Statement
attr_reader :condition , :body , :hoisted
def initialize( condition , body , hoisted = nil)
@hoisted = hoisted
@condition = condition
@body = body
end
def to_mom( compiler )
merge_label = Mom::Label.new( "merge_label_#{object_id.to_s(16)}")
cond_label = Mom::Label.new( "cond_label_#{object_id.to_s(16)}")
codes = cond_label
codes << @hoisted.to_mom(compiler) if @hoisted
codes << Mom::TruthCheck.new(condition.slot_definition(compiler) , merge_label)
codes << @body.to_mom(compiler)
codes << Mom::Jump.new(cond_label)
codes << merge_label
end
def each(&block)
block.call(self)
block.call(@condition)
@hoisted.each(&block) if @hoisted
@body.each(&block)
end
def to_s(depth = 0)
at_depth(depth , "while (#{@condition})" , @body.to_s(depth + 1) , "end" )
end
end
end