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