move the code insertion functionality up to function. makes more sense. block still carries code though

This commit is contained in:
Torsten Ruger
2014-06-10 23:57:56 +03:00
parent e9fc8ac6aa
commit e9519d4f05
15 changed files with 130 additions and 115 deletions

View File

@@ -1,18 +1,21 @@
module Ast
class WhileExpression < Expression
# attr_reader :condition, :body
def compile context , into
while_block = into.new_block "#{into.name}_while"
ret = while_block.new_block "#{into.name}_return"
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)
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 , while_block )
last = part.compile(context)
end
while_block.b while_block
puts "compile while end"