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

arigo at codespeak.net arigo at codespeak.net
Mon Oct 13 14:57:50 CEST 2008


Author: arigo
Date: Mon Oct 13 14:57:49 2008
New Revision: 59069

Modified:
   pypy/dist/pypy/translator/backendopt/mallocv.py
   pypy/dist/pypy/translator/backendopt/test/test_mallocv.py
Log:
Test and fix and some slight renamings in the code.


Modified: pypy/dist/pypy/translator/backendopt/mallocv.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/mallocv.py	(original)
+++ pypy/dist/pypy/translator/backendopt/mallocv.py	Mon Oct 13 14:57:49 2008
@@ -9,7 +9,7 @@
 from pypy.rpython.lltypesystem.lloperation import llop
 
 
-def virtualize_mallocs(translator, graphs, verbose=True):
+def virtualize_mallocs(translator, graphs, verbose=False):
     newgraphs = graphs[:]
     mallocv = MallocVirtualizer(newgraphs, translator.rtyper, verbose)
     while mallocv.remove_mallocs_once():
@@ -141,20 +141,25 @@
     def get_nodes_in_use(self):
         return dict(zip(self.varlist, self.nodelist))
 
-    def copy(self, memo, flagreadonly={}):
+    def shallowcopy(self):
         newframe = VirtualFrame.__new__(VirtualFrame)
         newframe.varlist = self.varlist
-        newframe.nodelist = [node.copy(memo, flagreadonly)
-                             for node in self.nodelist]
+        newframe.nodelist = self.nodelist
         newframe.sourceblock = self.sourceblock
         newframe.nextopindex = self.nextopindex
-        if self.callerframe is None:
-            newframe.callerframe = None
-        else:
-            newframe.callerframe = self.callerframe.copy(memo, flagreadonly)
+        newframe.callerframe = self.callerframe
         newframe.calledgraphs = self.calledgraphs
         return newframe
 
+    def copy(self, memo, flagreadonly={}):
+        newframe = self.shallowcopy()
+        newframe.nodelist = [node.copy(memo, flagreadonly)
+                             for node in newframe.nodelist]
+        if newframe.callerframe is not None:
+            newframe.callerframe = newframe.callerframe.copy(memo,
+                                                             flagreadonly)
+        return newframe
+
     def enum_call_stack(self):
         frame = self
         while frame is not None:
@@ -450,9 +455,13 @@
         callerframe = currentframe.callerframe
         if callerframe is None:
             raise ForcedInline("return block")
-        for i in range(len(callerframe.nodelist)):
-            if isinstance(callerframe.nodelist[i], FutureReturnValue):
-                callerframe.nodelist[i] = retnode
+        nodelist = callerframe.nodelist
+        callerframe = callerframe.shallowcopy()
+        callerframe.nodelist = []
+        for node in nodelist:
+            if isinstance(node, FutureReturnValue):
+                node = retnode
+            callerframe.nodelist.append(node)
         return callerframe
 
     def handle_catch(self, catchingframe, nodelist, renamings):
@@ -675,14 +684,14 @@
 
         if not catch_exc and isinstance(self.specblock.exitswitch, Constant):
             # constant-fold the switch
-            for exit in links:
-                if exit.exitcase == 'default':
+            for link in links:
+                if link.exitcase == 'default':
                     break
-                if exit.llexitcase == self.specblock.exitswitch.value:
+                if link.llexitcase == self.specblock.exitswitch.value:
                     break
             else:
                 raise Exception("exit case not found?")
-            links = (exit,)
+            links = (link,)
             self.specblock.exitswitch = None
 
         if catch_exc and self.ops_produced_by_last_op == 0:

Modified: pypy/dist/pypy/translator/backendopt/test/test_mallocv.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_mallocv.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_mallocv.py	Mon Oct 13 14:57:49 2008
@@ -479,6 +479,30 @@
             return a.n
         self.check(fn13, [int], [10], 4)
 
+    def test_constfold_indirect_call(self):
+        skip("write me")
+
+    def test_bug_on_links_to_return(self):
+        class A:
+            pass
+        def h1(n):
+            return n - 1
+        def h2(n):
+            return n - 2
+        def g(a):
+            a.n += 1
+            if a.n > 5:
+                return h1
+            else:
+                return h2
+        def fn15(n):
+            a = A()
+            a.n = n
+            m = g(a)(n)
+            return a.n * m
+        assert fn15(10) == 99
+        self.check(fn15, [int], [10], 99)
+
     def test_preserve_annotations_on_graph(self):
         class A:
             pass



More information about the Pypy-commit mailing list