[pypy-svn] r22587 - pypy/dist/pypy/rpython/test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jan 24 13:36:56 CET 2006


Author: cfbolz
Date: Tue Jan 24 13:36:54 2006
New Revision: 22587

Modified:
   pypy/dist/pypy/rpython/test/test_rgenop.py
Log:
(arigo, cfbolz)

yet another test that didn't find bugs but was annoying to write :-(


Modified: pypy/dist/pypy/rpython/test/test_rgenop.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rgenop.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rgenop.py	Tue Jan 24 13:36:54 2006
@@ -37,3 +37,40 @@
     assert res == 0
     res = runlink(startlink, [42])
     assert res == 42
+
+def test_loop():
+    """
+    def f(v0):
+        i = 1
+        result = 1
+        while i <= v0:
+            result *= i
+            i += 1
+        return result
+    """
+    startlink = newgraph("loop")
+    block = newblock()
+    v0 = geninputarg(block, Signed)
+    const1 = genconst(block, 1)
+    link = newlink(block, [const1, const1, v0])
+    closeblock1(block, link)
+    closelink(startlink, block)
+    loopblock = newblock()
+    result0 = geninputarg(loopblock, Signed)
+    i0 = geninputarg(loopblock, Signed)
+    v1 = geninputarg(loopblock, Signed)
+    closelink(link, loopblock)
+    const1 = genconst(block, 1)
+    result1 = genop(loopblock, 'int_mul', [result0, i0], Signed)
+    i1 = genop(loopblock, 'int_add', [i0, const1], Signed)
+    v2 = genop(loopblock, 'int_le', [i1, v1], Bool)
+    false_link = newreturnlink(loopblock, result1)
+    true_link = newlink(loopblock, [result1, i1, v1])
+    closelink(true_link, loopblock)
+    closeblock2(loopblock, v2, false_link, true_link)
+    res = runlink(startlink, [0])
+    assert res == 1
+    res = runlink(startlink, [1])
+    assert res == 1
+    res = runlink(startlink, [7])
+    assert res == 5040



More information about the Pypy-commit mailing list