Author: Stephan <[email protected]>
Branch:
Changeset: r76:e6b560437221
Date: 2011-05-18 17:48 +0200
http://bitbucket.org/pypy/lang-js/changeset/e6b560437221/
Log: allow for loops with missing setup, condition and update
diff --git a/js/astbuilder.py b/js/astbuilder.py
--- a/js/astbuilder.py
+++ b/js/astbuilder.py
@@ -443,6 +443,16 @@
condition = operations.Boolean(pos, True)
update, i = self.get_next_expr(node, i)
body, i = self.get_next_expr(node, i)
+
+ if setup is None:
+ setup = operations.EmptyExpression(pos)
+ if condition is None:
+ condition = operations.Boolean(pos, True)
+ if update is None:
+ update = operations.EmptyExpression(pos)
+ if body is None:
+ body = operations.EmptyExpression(pos)
+
return operations.For(pos, setup, condition, update, body)
visit_regularvarfor = visit_regularfor
diff --git a/js/test/test_interp.py b/js/test/test_interp.py
--- a/js/test/test_interp.py
+++ b/js/test/test_interp.py
@@ -808,3 +808,38 @@
}
n;
""", 400
+
+def test_partial_for_loop():
+ yield assertv, """
+ var i = 0;
+ for(;;){
+ i++;
+ if(i == 2)
+ break;
+ }
+ i;
+ """, 2
+ yield assertv, """
+ var i = 0;
+ for(;;i++){
+ if(i == 2)
+ break;
+ }
+ i;
+ """, 2
+ yield assertv, """
+ var i = 0;
+ for(i = 2;;){
+ if(i == 2)
+ break;
+ i = 99;
+ }
+ i;
+ """, 2
+ yield assertv, """
+ var i = 0;
+ for(;i <= 1;){
+ i++;
+ }
+ i;
+ """, 2
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit