Permalink
Browse files

Improved comments / label names for #compile_if and fixed rather brok…

…en 'or' logic
  • Loading branch information...
vidarh committed Sep 16, 2014
1 parent 7429885 commit 456a9894d1fb55cca7a34c231737f37cc4e8b2bb
Showing with 8 additions and 3 deletions.
  1. +8 −3 compiler.rb
View
@@ -296,9 +296,10 @@ def compile_defm(scope, name, args, body)
# the if and else arm.
# If no else arm is given, it defaults to nil.
def compile_if(scope, cond, if_arm, else_arm = nil)
@e.comment("if: #{cond.inspect}")
res = compile_eval_arg(scope, cond)
l_else_arm = @e.get_local
l_end_if_arm = @e.get_local
l_else_arm = @e.get_local + "_else"
l_end_if_arm = @e.get_local + "_endif"
if res && res.type == :object
@e.save_result(res)
@@ -310,8 +311,10 @@ def compile_if(scope, cond, if_arm, else_arm = nil)
@e.jmp_on_false(l_else_arm, res)
end
@e.comment("then: #{if_arm.inspect}")
ifret = compile_eval_arg(scope, if_arm)
@e.jmp(l_end_if_arm) if else_arm
@e.comment("else: #{else_arm.inspect}")
@e.local(l_else_arm)
elseret = compile_eval_arg(scope, else_arm) if else_arm
@e.local(l_end_if_arm) if else_arm
@@ -354,7 +357,9 @@ def compile_and scope, left, right
end
def compile_or scope, left, right
compile_if(scope, left, false, right)
@e.comment("compile_or: #{left.inspect} || #{right.inspect}")
compile_eval_arg(scope,[:assign, :__left, left])
compile_if(scope, :__left, :__left, right)
end
# Compiles the ternary if form (cond ? then : else)

0 comments on commit 456a989

Please sign in to comment.