[pypy-svn] r17487 - pypy/dist/pypy/rpython/test
tismer at codespeak.net
tismer at codespeak.net
Mon Sep 12 03:22:59 CEST 2005
Author: tismer
Date: Mon Sep 12 03:22:55 2005
New Revision: 17487
Modified:
pypy/dist/pypy/rpython/test/test_rrange.py
Log:
this check-in is just to show a funny observation.
When a variable is conditionally assigned two different ranges,
the ranges are kept, unless the steps are different.
Well, after all this is not surprizing.
But I thing the action taken is not pleasant:
the range is turned into a list in this case!
I guess what we want is either special-casing the respective blocks,
or at least map this to the variable step case, if this is possible.
Please let me know what you think.
Modified: pypy/dist/pypy/rpython/test/test_rrange.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rrange.py (original)
+++ pypy/dist/pypy/rpython/test/test_rrange.py Mon Sep 12 03:22:55 2005
@@ -104,3 +104,44 @@
assert res == failingfn_var(step)
step = 0
assert check_failed(failingfn_var, [step])
+
+def test_range_iter():
+ def fn(start, stop, step):
+ res = 0
+ if step == 0:
+ if stop >= start:
+ r = range(start, stop, 1)
+ else:
+ r = range(start, stop, -1)
+ else:
+ r = range(start, stop, step)
+ for i in r:
+ res = res * 51 + i
+ return res
+ res = interpret(fn, [2, 7, 1])#, view=True)
+ # XXX not finished, stunned
+
+# XXX the above test works, but it always turns the range into a list!!!
+#
+# here another test that show that this even happens in a simple case.
+# I think this is an annotator problem
+
+def test_range_funny():
+ # this is just an example.
+ # making start/stop different is ok
+ def fn(start, stop):
+ if stop >= start:
+ r = range(start, stop, 1)
+ else:
+ r = range(start, stop-1, 1)
+ return r[-2]
+ # making step different turns the range into a list!
+ # I think, we should instead either specialize the blocks,
+ # or morph the whole thing into the variable step case???
+ def fn(start, stop):
+ if stop >= start:
+ r = range(start, stop, 1)
+ else:
+ r = range(start, stop, -1)
+ return r[-2]
+ res = interpret(fn, [2, 7])#, view=True)
More information about the Pypy-commit
mailing list