[pypy-svn] r34159 - pypy/dist/pypy/jit/codegen/test

niko at codespeak.net niko at codespeak.net
Sat Nov 4 12:27:04 CET 2006


Author: niko
Date: Sat Nov  4 12:27:03 2006
New Revision: 34159

Modified:
   pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
Log:
refactor the test_goto so that the flow of variables is clearer
  (and correct an accidental reuse of vars that we found)



Modified: pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/test/rgenop_tests.py	(original)
+++ pypy/dist/pypy/jit/codegen/test/rgenop_tests.py	Sat Nov  4 12:27:03 2006
@@ -94,20 +94,8 @@
         return res
     return branching_runner
 
-
-def make_goto(rgenop):
-    # z = 1
-    # while x > 0:
-    #     y += x
-    #     z *= x
-    #     x -= 1
-    # y += z
-    # return y
-    signed_kind = rgenop.kindToken(lltype.Signed)
-    sigtoken = rgenop.sigToken(FUNC2)
-    builder, entrypoint, [gv_x, gv_y] = rgenop.newgraph(sigtoken)
-
-    # loop start block
+# loop start block
+def loop_start(rgenop, builder, signed_kind, gv_x, gv_y):
     args_gv = [gv_x, gv_y, rgenop.genconst(1)]
     loopblock = builder.enter_next_block(
         [signed_kind, signed_kind, signed_kind], args_gv)
@@ -115,6 +103,10 @@
 
     gv_cond = builder.genop2("int_gt", gv_x, rgenop.genconst(0))
     bodybuilder = builder.jump_if_true(gv_cond)
+    return args_gv, loopblock, bodybuilder
+
+# loop exit
+def loop_exit(builder, sigtoken, signed_kind, gv_y, gv_z):
     args_gv = [gv_y, gv_z]
     builder.enter_next_block(
         [signed_kind, signed_kind], args_gv)
@@ -122,7 +114,8 @@
     gv_y3 = builder.genop2("int_add", gv_y, gv_z)
     builder.finish_and_return(sigtoken, gv_y3)
 
-    # loop body
+# loop body
+def loop_body(rgenop, loopblock, bodybuilder, signed_kind, gv_x, gv_y, gv_z):
     args_gv = [gv_z, gv_y, gv_x]
     bodybuilder.enter_next_block(
         [signed_kind, signed_kind, signed_kind], args_gv)
@@ -133,6 +126,25 @@
     gv_x2 = bodybuilder.genop2("int_sub", gv_x, rgenop.genconst(1))
     bodybuilder.finish_and_goto([gv_x2, gv_y2, gv_z2], loopblock)
 
+def make_goto(rgenop):
+    # z = 1
+    # while x > 0:
+    #     y += x
+    #     z *= x
+    #     x -= 1
+    # y += z
+    # return y
+    signed_kind = rgenop.kindToken(lltype.Signed)
+    sigtoken = rgenop.sigToken(FUNC2)
+    builder, entrypoint, [gv_x, gv_y] = rgenop.newgraph(sigtoken)
+
+    [gv_x, gv_y, gv_z],loopblock,bodybuilder = loop_start(
+        rgenop, builder, signed_kind, gv_x, gv_y)
+    loop_exit(
+        builder, sigtoken, signed_kind, gv_y, gv_z)
+    loop_body(
+        rgenop, loopblock, bodybuilder, signed_kind, gv_x, gv_y, gv_z)
+
     # done
     gv_gotofn = rgenop.gencallableconst(sigtoken, "goto", entrypoint)
     return gv_gotofn



More information about the Pypy-commit mailing list