move branch counter to branch instruction (from if) in preperation of while

This commit is contained in:
Torsten Ruger
2014-07-16 22:28:28 +03:00
parent 7534626d87
commit efeb910843
3 changed files with 11 additions and 7 deletions

View File

@ -1,21 +1,18 @@
module Ast
class IfExpression < Expression
# attr_reader :cond, :if_true, :if_false
@@counter = 0 #naming the braches by counting mainly to get them back together in testing
def compile frame , method
is = cond.compile(frame , method)
# is.is_false(frame,method)
# TODO should/will use different branches for different conditions.
branch_name = "if_merge_#{@@counter}".to_sym
@@counter += 1
branch = Virtual::ImplicitBranch.new branch_name
branch = Virtual::ImplicitBranch.new "if_merge"
method.add branch
last = is
if_true.each do |part|
last = part.compile(frame,method )
raise part.inspect if last.nil?
end
merge = Virtual::Label.new(branch_name)
merge = Virtual::Label.new(branch.name)
method.add merge
branch.swap
method.current = branch