2014-05-10 18:02:51 +02:00
|
|
|
module Ast
|
|
|
|
class WhileExpression < Expression
|
2014-06-04 21:03:45 +02:00
|
|
|
# attr_reader :condition, :body
|
2014-06-10 22:57:56 +02:00
|
|
|
def compile context
|
|
|
|
into = context.function
|
|
|
|
while_block = into.new_block "while"
|
2014-06-10 23:38:46 +02:00
|
|
|
ret = into.new_block "return"
|
2014-06-10 22:57:56 +02:00
|
|
|
into.insert_at while_block
|
2014-06-10 23:38:46 +02:00
|
|
|
|
2014-06-02 14:11:48 +02:00
|
|
|
puts "compiling while condition #{condition}"
|
2014-06-10 22:57:56 +02:00
|
|
|
cond_val = condition.compile(context)
|
2014-06-10 23:38:46 +02:00
|
|
|
into.b ret , condition_code: cond_val.not_operator
|
|
|
|
into.insertion_point.branch = ret
|
2014-06-09 18:24:09 +02:00
|
|
|
|
2014-05-14 10:33:23 +02:00
|
|
|
last = nil
|
2014-06-10 22:57:56 +02:00
|
|
|
|
2014-05-13 15:24:19 +02:00
|
|
|
body.each do |part|
|
2014-06-02 14:11:48 +02:00
|
|
|
puts "compiling in while #{part}"
|
2014-06-10 22:57:56 +02:00
|
|
|
last = part.compile(context)
|
2014-05-13 15:24:19 +02:00
|
|
|
end
|
2014-06-10 23:38:46 +02:00
|
|
|
into.b while_block
|
|
|
|
into.insertion_point.branch = while_block
|
|
|
|
|
2014-05-22 20:38:57 +02:00
|
|
|
puts "compile while end"
|
2014-05-23 19:27:14 +02:00
|
|
|
into.insert_at ret
|
2014-05-14 10:33:23 +02:00
|
|
|
return last
|
2014-05-13 15:24:19 +02:00
|
|
|
end
|
2014-05-10 18:02:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|