Skip to content

Commit

Permalink
Added support for multiple compare (0 < n < 4)
Browse files Browse the repository at this point in the history
git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@1973 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information
keesbos committed Oct 8, 2009
1 parent 89b8407 commit c9f966e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,6 +1,8 @@
Changes made to Pyjamas since 0.6
---------------------------------

* Add support for multiple compare (0 < n < 4)

* Add PUT and DELETE into XMLHttpRequest (thanks to Nick <thretwon@gmail.com>)

* Added for in tuple
Expand Down
19 changes: 19 additions & 0 deletions examples/libtest/BoolTest.py
Expand Up @@ -105,6 +105,25 @@ def testIfStatement(self):
self.fail("'[] and not {}' shoul evaluate to False")
else:
self.assertTrue(True)
if 0 < 1 < 2:
self.assertTrue(True)
else:
self.fail("if 0 < 1 < 2")
i = [0, 2, 4]
i = i.__iter__();
if 0 < i.next() < 4:
self.fail("iter (0)")
else:
self.assertTrue(True)
if 0 < i.next() < 4:
self.assertTrue(True)
else:
self.fail("iter (2)")
if 0 < i.next() < 4:
self.fail("iter (4)")
else:
self.assertTrue(True)


def testWhileStatement(self):
while([]):
Expand Down
10 changes: 10 additions & 0 deletions pyjs/src/pyjs/translator.py
Expand Up @@ -2980,13 +2980,23 @@ def _compare(self, node, current_klass):
lhs = self.expr(node.expr, current_klass)

if len(node.ops) != 1:
cmp = []
for op, rhs_node in node.ops:
rhsname = self.uniqid("$compare")
rhs = self.expr(rhs_node, current_klass)
rhs = "(%s = %s)" % (rhsname, rhs)
cmp.append(self.compare_code(op, lhs, rhs))
lhs = rhsname
return "(%s)" % "&&".join(cmp)
raise TranslationError(
"only one ops supported (in _compare)", node, self.module_name)

op = node.ops[0][0]
rhs_node = node.ops[0][1]
rhs = self.expr(rhs_node, current_klass)
return self.compare_code(op, lhs, rhs)

def compare_code(self, op, lhs, rhs):
if op == "==":
return self.inline_eq_code(lhs, rhs)
if op == "!=":
Expand Down

0 comments on commit c9f966e

Please sign in to comment.