rubyx/lib/ast/while_expression.rb

28 lines
709 B
Ruby
Raw Normal View History

2014-05-10 18:02:51 +02:00
module Ast
class WhileExpression < Expression
# attr_reader :condition, :body
def compile context
into = context.function
while_block = into.new_block "while"
ret = while_block.new_block "return"
into.insert_at while_block
puts "compiling while condition #{condition}"
cond_val = condition.compile(context)
while_block.b ret , condition_code: cond_val.not_operator
while_block.branch = ret
last = nil
body.each do |part|
puts "compiling in while #{part}"
last = part.compile(context)
end
2014-05-22 13:56:31 +02:00
while_block.b while_block
2014-05-22 20:38:57 +02:00
puts "compile while end"
into.insert_at ret
return last
end
2014-05-10 18:02:51 +02:00
end
end