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