[pypy-svn] r22231 - in pypy/dist/pypy/translator/backendopt: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jan 16 18:18:30 CET 2006


Author: cfbolz
Date: Mon Jan 16 18:18:29 2006
New Revision: 22231

Modified:
   pypy/dist/pypy/translator/backendopt/escape.py
   pypy/dist/pypy/translator/backendopt/test/test_escape.py
Log:
implemet getarraysubstruct + test


Modified: pypy/dist/pypy/translator/backendopt/escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/escape.py	Mon Jan 16 18:18:29 2006
@@ -274,6 +274,12 @@
         # state, the same creationpoints, etc.
         return objstate
 
+    def getarraysubstruct(self, op, arraystate, indexstate):
+        # since this is really a struct embedded somewhere in the array it has
+        # the same state, creationpoints, etc. in most cases the resulting
+        # pointer should not be used much anyway
+        return arraystate
+
     def getarraysize(self, op, arraystate):
         pass
 
@@ -323,6 +329,8 @@
     def ptr_eq(self, op, ptr1state, ptr2state):
         return None
 
+    ptr_neq = ptr_eq
+
     def same_as(self, op, objstate):
         return objstate
 

Modified: pypy/dist/pypy/translator/backendopt/test/test_escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_escape.py	Mon Jan 16 18:18:29 2006
@@ -165,6 +165,29 @@
     assert acrep.changes
     assert not acrep.escapes
 
+def test_dependencies():
+    class A(object):
+        pass
+    globala = A()
+    globala.l = [1]
+    def g(a):
+        a.append(1)
+        globala.l = a
+    def f():
+        a = [0]
+        a.append(1)
+        # g(a)
+        return globala.l[0]
+    t, adi, graph = build_adi(f, [])
+    t.view()
+    avar = graph.startblock.operations[0].result
+    astate = adi.getstate(avar)
+    appendgraph = graph.startblock.operations[3].args[0].value._obj.graph
+    resizegraph = appendgraph.startblock.operations[2].args[0].value._obj.graph
+    reallygraph = resizegraph.startblock.exits[0].target.operations[0].args[0].value._obj.graph
+#    assert astate.does_escape()
+    assert astate.does_change()
+
 def test_substruct():
     class A(object):
         pass
@@ -307,6 +330,22 @@
     # does not crash
     t, adi, graph = build_adi(f, [int])
 
+def test_getarraysubstruct():
+    def createdict(i, j):
+        d = {'hello' : 23,
+             'world' : 21}
+        l = ["hello", "world"]    
+        return d[l[i]] + d[l[j]]
+    # does not crash, for now
+    t, adi, graph = build_adi(createdict, [int, int])
+    t.view()
+    dvar = graph.startblock.operations[0].result
+    lvar = graph.startblock.operations[3].result
+    dstate = adi.getstate(dvar)
+    lstate = adi.getstate(lvar)
+    assert dstate.does_change()
+    assert lstate.does_change()
+
 def test_raise_escapes():
     def f():
         a = ValueError()
@@ -346,6 +385,7 @@
     state = adi.getstate(svar)
     assert not state.does_escape()
 
+
 #__________________________________________________________
 # test loop detection
 
@@ -422,6 +462,6 @@
             a.i = i
             result += a.i
         return result
-    t = check_malloc_removal(f, [int], [3], 3,must_remove=False)
+    t = check_malloc_removal(f, [int], [3], 3, must_remove=False)
     graph = graphof(t, f)
     assert graph.startblock.exits[0].target.exits[0].target.operations[0].opname == "malloc"



More information about the Pypy-commit mailing list