bryancatanzaro / copperhead

Data Parallel Python
Apache License 2.0
207 stars 28 forks source link

Short circuit binary operators #3

Open bryancatanzaro opened 12 years ago

bryancatanzaro commented 12 years ago

Short circuit binary operators are currently not short-circuiting.

This deviates from Python's conditional evaluation semantics and should be fixed.

bryancatanzaro commented 12 years ago

The main problem with fixing this has to do with expression flattening: compound expressions are all flattened in the front end of the compiler, so this: if y or sum(x) > 1 : pass

becomes e0 = sum(x) e1 = e0 > 1 if y or e1: pass

Later on, e1 will be evaluated before we get to the conditional, so the short-circuiting behavior of "or" is not respected.

To fix this, we're going to need to lift all expressions in conditionals into lambdas: if y or (lambda:sum(x) > 1)(): pass

Before lambda lifting occurs. Arguments to these lambdas occur via closures.

Doing this will require fixing issue #4 (entry point model).