[pypy-svn] r22608 - in pypy/dist/pypy: doc/discussion rpython rpython/test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jan 24 18:02:05 CET 2006


Author: cfbolz
Date: Tue Jan 24 18:02:02 2006
New Revision: 22608

Modified:
   pypy/dist/pypy/doc/discussion/draft-jit-ideas.txt
   pypy/dist/pypy/rpython/rgenop.py
   pypy/dist/pypy/rpython/test/test_rgenop.py
Log:
(cfbolz, samuele, arigo)

Yet another iteration of the genop() functions.


Modified: pypy/dist/pypy/doc/discussion/draft-jit-ideas.txt
==============================================================================
--- pypy/dist/pypy/doc/discussion/draft-jit-ideas.txt	(original)
+++ pypy/dist/pypy/doc/discussion/draft-jit-ideas.txt	Tue Jan 24 18:02:02 2006
@@ -92,8 +92,6 @@
 
 Functions:
 
-* newgraph(name) -> (opaque start link object)
-
 * newblock() -> (opaque block object)
 
 * geninputarg(block, CONCRETE_TYPE) -> (input var)
@@ -102,17 +100,15 @@
 
 * genconst(block, llvalue) -> (result var)
 
-* newlink(block, [list-of-vars]) -> (opaque link object)
-
-* newreturnlink(block, return-var) -> (opaque link object)
+* closeblock1(block) -> link
 
-* closeblock1(block, link)
+* closeblock2(block, exitswitch-var) -> (false_link, true_link)
 
-* closeblock2(block, exitswitch-var, false_link, true_link)
+* closelink(link, [link-vars], targetblock)
 
-* closelink(link, targetblock)
+* closereturnlink(link, return-var)
 
-* runlink(link, [list-of-llvalues])
+* runblock(block, [list-of-llvalues])
 
 
 L3 interpreter

Modified: pypy/dist/pypy/rpython/rgenop.py
==============================================================================
--- pypy/dist/pypy/rpython/rgenop.py	(original)
+++ pypy/dist/pypy/rpython/rgenop.py	Tue Jan 24 18:02:02 2006
@@ -8,10 +8,6 @@
 from pypy.objspace.flow import model as flowmodel
 
 
-def newgraph(name):
-    startblock_to_throw_away = flowmodel.Block([])   # grumble
-    return flowmodel.FunctionGraph(name, startblock_to_throw_away)
-
 def newblock():
     return flowmodel.Block([])
 
@@ -33,32 +29,27 @@
     v.concretetype = lltype.typeOf(llvalue)
     return v
 
-def newlink(block, vars):
-    return flowmodel.Link(vars, None)
-
-def newreturnlink(block, var):
-    v = flowmodel.Variable()
-    v.concretetype = var.concretetype
-    pseudoreturnblock = flowmodel.Block([v])
-    pseudoreturnblock.operations = ()
-    return flowmodel.Link([var], pseudoreturnblock)
-
-def closeblock1(block, link):
+def closeblock1(block):
+    link = flowmodel.Link([], None)
     block.closeblock(link)
+    return link
 
-def closeblock2(block, exitswitch, false_link, true_link):
+def closeblock2(block, exitswitch):
     block.exitswitch = exitswitch
+    false_link = flowmodel.Link([], None)
     false_link.exitcase = False
     false_link.llexitcase = False
+    true_link = flowmodel.Link([], None)
     true_link.exitcase = True
     true_link.llexitcase = True
     block.closeblock(false_link, true_link)
+    return false_link, true_link
 
-def closelink(link, targetblock):
+def closelink(link, vars, targetblock):
     if isinstance(link, flowmodel.Link):
-        assert link.target is None, "%r already closed" % (link,)
-        assert ([v.concretetype for v in link.args] ==
+        assert ([v.concretetype for v in vars] ==
                 [v.concretetype for v in targetblock.inputargs])
+        link.args[:] = vars
         link.target = targetblock
     elif isinstance(link, flowmodel.FunctionGraph):
         graph = link
@@ -67,6 +58,13 @@
     else:
         raise TypeError
 
+def closereturnlink(link, returnvar):
+    v = flowmodel.Variable()
+    v.concretetype = returnvar.concretetype
+    pseudoreturnblock = flowmodel.Block([v])
+    pseudoreturnblock.operations = ()
+    closelink(link, [returnvar], pseudoreturnblock)
+
 def _patchgraph(graph):
     returntype = None
     for link in graph.iterlinks():
@@ -86,10 +84,9 @@
         from pypy.rpython.typesystem import LowLevelTypeSystem
         self.type_system = LowLevelTypeSystem.instance
 
-def runlink(startlink, args):
+def runblock(block, args):
     from pypy.rpython.llinterp import LLInterpreter
-    assert isinstance(startlink, flowmodel.FunctionGraph), "XXX"
-    graph = startlink  # for now
+    graph = flowmodel.FunctionGraph('?', block)
     _patchgraph(graph)
     flowmodel.checkgraph(graph)
     llinterp = LLInterpreter(PseudoRTyper())

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 18:02:02 2006
@@ -4,15 +4,13 @@
 
 def test_square():
     """def square(v0): return v0*v0"""
-    startlink = newgraph("square")
     block = newblock()
     v0 = geninputarg(block, Signed)
     v1 = genop(block, 'int_mul', [v0, v0], Signed)
-    link = newreturnlink(block, v1)
-    closeblock1(block, link)
-    closelink(startlink, block)
+    link = closeblock1(block)
+    closereturnlink(link, v1)
 
-    res = runlink(startlink, [17])
+    res = runblock(block, [17])
     assert res == 289
 
 def test_if():
@@ -23,19 +21,17 @@
         else:
             return v0
     """
-    startlink = newgraph("if")
     block = newblock()
     v0 = geninputarg(block, Signed)
     const0 = genconst(block, 0)
     v1 = genop(block, 'int_lt', [v0, const0], Bool)
-    true_link = newreturnlink(block, const0)
-    false_link = newreturnlink(block, v0)
-    closeblock2(block, v1, false_link, true_link)
-    closelink(startlink, block)
+    false_link, true_link = closeblock2(block, v1)
+    closereturnlink(true_link, const0)
+    closereturnlink(false_link, v0)
 
-    res = runlink(startlink, [-1])
+    res = runblock(block, [-1])
     assert res == 0
-    res = runlink(startlink, [42])
+    res = runblock(block, [42])
     assert res == 42
 
 def test_loop():
@@ -48,29 +44,26 @@
             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)
+    link = closeblock1(block)
     loopblock = newblock()
     result0 = geninputarg(loopblock, Signed)
     i0 = geninputarg(loopblock, Signed)
     v1 = geninputarg(loopblock, Signed)
-    closelink(link, loopblock)
+    closelink(link, [const1, const1, v0], 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])
+    false_link, true_link = closeblock2(loopblock, v2)
+    closereturnlink(false_link, result1)
+    closelink(true_link, [result1, i1, v1], loopblock)
+    
+    res = runblock(block, [0])
     assert res == 1
-    res = runlink(startlink, [1])
+    res = runblock(block, [1])
     assert res == 1
-    res = runlink(startlink, [7])
+    res = runblock(block, [7])
     assert res == 5040



More information about the Pypy-commit mailing list