[pypy-svn] r20380 - pypy/branch/somepbc-refactoring/pypy/translator/c/test

arigo at codespeak.net arigo at codespeak.net
Tue Nov 29 11:34:38 CET 2005


Author: arigo
Date: Tue Nov 29 11:34:36 2005
New Revision: 20380

Modified:
   pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_annotated.py
   pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_backendoptimized.py
   pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_typed.py
Log:
Refactored getcompiled() in these three genc tests.


Modified: pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_annotated.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_annotated.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_annotated.py	Tue Nov 29 11:34:36 2005
@@ -11,7 +11,7 @@
 
 class TestAnnotatedTestCase:
 
-    def getcompiled(self, func):
+    def annotatefunc(self, func):
         t = TranslationContext(simplifying=True)
         # builds starting-types from func_defs 
         argstypelist = []
@@ -23,6 +23,9 @@
         a = t.buildannotator()
         a.build_types(func, argstypelist)
         a.simplify()
+        return t
+
+    def compilefunc(self, t, func):
         from pypy.translator.c import genc
         builder = genc.CExtModuleBuilder(t, func)
         builder.generate_source()
@@ -30,6 +33,17 @@
         builder.import_module()
         return builder.get_entry_point()
 
+    def process(self, t):
+        pass
+
+    def getcompiled(self, func, view=False):
+        t = self.annotatefunc(func)
+        self.process(t)
+        if view:
+            t.view()
+        t.checkgraphs()
+        return self.compilefunc(t, func)
+
     def test_set_attr(self):
         set_attr = self.getcompiled(snippet.set_attr)
         assert set_attr() == 2

Modified: pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_backendoptimized.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_backendoptimized.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_backendoptimized.py	Tue Nov 29 11:34:36 2005
@@ -1,27 +1,13 @@
 import autopath
-from pypy.translator.tool.cbuild import skip_missing_compiler
-from pypy.translator.translator import Translator
-
 from pypy.translator.c.test.test_typed import TestTypedTestCase as _TestTypedTestCase
+from pypy.translator.backendopt.all import backend_optimizations
 
 
 class TestTypedOptimizedTestCase(_TestTypedTestCase):
 
-    def getcompiled(self, func):
-        t = Translator(func, simplifying=True)
-        # builds starting-types from func_defs 
-        argstypelist = []
-        if func.func_defaults:
-            for spec in func.func_defaults:
-                if isinstance(spec, tuple):
-                    spec = spec[0] # use the first type only for the tests
-                argstypelist.append(spec)
-        a = t.annotate(argstypelist)
-        a.simplify()
-        t.specialize()
-        t.backend_optimizations()
-        t.checkgraphs()
-        return skip_missing_compiler(t.ccompile)
+    def process(self, t):
+        _TestTypedTestCase.process(self, t)
+        backend_optimizations(t)
 
     def test_remove_same_as(self):
         def f(n=bool):

Modified: pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/c/test/test_typed.py	Tue Nov 29 11:34:36 2005
@@ -2,9 +2,7 @@
 import sys
 import py
 from py.test import raises
-from pypy.translator.translator import Translator
 from pypy.translator.test import snippet 
-from pypy.translator.tool.cbuild import skip_missing_compiler
 from pypy.rpython.rarithmetic import r_uint, intmask
 
 from pypy.translator.c.test.test_annotated import TestAnnotatedTestCase as _TestAnnotatedTestCase
@@ -12,22 +10,9 @@
 
 class TestTypedTestCase(_TestAnnotatedTestCase):
 
-    def getcompiled(self, func, view=False):
-        t = Translator(func, simplifying=True)
-        # builds starting-types from func_defs 
-        argstypelist = []
-        if func.func_defaults:
-            for spec in func.func_defaults:
-                if isinstance(spec, tuple):
-                    spec = spec[0] # use the first type only for the tests
-                argstypelist.append(spec)
-        a = t.annotate(argstypelist)
-        a.simplify()
-        t.specialize()
-        t.checkgraphs()
-        if view:
-            t.view()
-        return skip_missing_compiler(t.ccompile)
+    def process(self, t):
+        _TestAnnotatedTestCase.process(self, t)
+        t.buildrtyper().specialize()
 
     def test_call_five(self):
         # --  the result of call_five() isn't a real list, but an rlist



More information about the Pypy-commit mailing list