Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add && and || to partial evaluator.

  • Loading branch information...
commit 57bb65de7f0f3f62002c40923b9cec9f0d9a8979 1 parent ccedea4
whitequark authored
Showing with 17 additions and 1 deletion.
  1. +17 −1 lib/furnace-avm2/transform/evaluator.rb
18 lib/furnace-avm2/transform/evaluator.rb
View
@@ -9,6 +9,9 @@ def fold(expr)
expr
else
case expr.type
+ when :this
+ expr
+
when :"===", :"!==", :"==", :"!="
args = expr.children.map { |e| fold e }
return nil unless args.all?
@@ -24,6 +27,19 @@ def fold(expr)
when :"!="
emit !compare(*args)
end
+
+ when :or, :and
+ left, right = expr.children
+ if left = fold(left)
+ left_value = value(to_boolean(left))
+ compare_to = (expr.type == :and ? true : false)
+
+ if left_value ^ compare_to
+ left
+ else
+ right
+ end
+ end
end
end
end
@@ -109,7 +125,7 @@ def to_boolean(x)
str = value(x)
emit (str == "")
else
- true
+ emit true
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.