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-05-13 15:24:19 +02:00
|
|
|
def compile context , into
|
2014-05-23 19:27:14 +02:00
|
|
|
while_block = into.new_block "#{into.name}_while"
|
|
|
|
ret = while_block.new_block "#{into.name}_return"
|
2014-06-02 14:11:48 +02:00
|
|
|
puts "compiling while condition #{condition}"
|
2014-05-22 13:56:31 +02:00
|
|
|
cond_val = condition.compile(context , while_block)
|
2014-05-28 13:55:13 +02:00
|
|
|
while_block.b ret , condition_code: cond_val.not_operator
|
2014-05-14 10:33:23 +02:00
|
|
|
last = nil
|
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-05-22 13:56:31 +02:00
|
|
|
last = part.compile(context , while_block )
|
2014-05-13 15:24:19 +02:00
|
|
|
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"
|
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
|