[pypy-svn] r6219 - in pypy/branch/pypy-genc/translator: . test

arigo at codespeak.net arigo at codespeak.net
Mon Aug 30 13:34:16 CEST 2004


Author: arigo
Date: Mon Aug 30 13:34:15 2004
New Revision: 6219

Added:
   pypy/branch/pypy-genc/translator/test/test_ctrans.py
      - copied, changed from r6217, pypy/branch/pypy-genc/translator/test/test_pyrextrans.py
Modified:
   pypy/branch/pypy-genc/translator/translator.py
Log:
Added a method ccompile() to Translator.
Copied test_pyrextrans.py to test_ctrans.py.  Most tests fail, but some
already pass; now let's make more of them pass...


Copied: pypy/branch/pypy-genc/translator/test/test_ctrans.py (from r6217, pypy/branch/pypy-genc/translator/test/test_pyrextrans.py)
==============================================================================
--- pypy/branch/pypy-genc/translator/test/test_pyrextrans.py	(original)
+++ pypy/branch/pypy-genc/translator/test/test_ctrans.py	Mon Aug 30 13:34:15 2004
@@ -1,14 +1,14 @@
 import autopath
 from pypy.tool import testit
 from pypy.tool.udir import udir
-from pypy.translator.genpyrex import GenPyrex
+from pypy.translator.genc import GenC
 from pypy.objspace.flow.model import *
-from pypy.translator.tool.buildpyxmodule import build_cfunc
+from pypy.translator.tool.buildpyxmodule import make_module_from_c
 from pypy.translator.translator import Translator
 
 from pypy.translator.test import snippet 
 
-class NoTypePyrexGenTestCase(testit.IntTestCase):
+class NoTypeCGenTestCase(testit.IntTestCase):
 
     def setUp(self):
         self.space = testit.objspace('flow')
@@ -16,13 +16,8 @@
     def build_cfunc(self, func):
         try: func = func.im_func
         except AttributeError: pass
-
-        dot = testit.Options.verbose >0 and 1 or 0
-        options = {
-            'simplify' : 1,
-            'dot' : dot,
-            }
-        return build_cfunc(func, **options)
+        t = Translator(func)
+        return t.ccompile()
 
     def test_simple_func(self):
         cfunc = self.build_cfunc(snippet.simple_func)
@@ -101,7 +96,7 @@
                     spec = spec[0] # use the first type only for the tests
                 argstypelist.append(spec)
         t.annotate(argstypelist) 
-        return t.compile()
+        return t.ccompile()
 
     def test_set_attr(self):
         set_attr = self.getcompiled(snippet.set_attr)

Modified: pypy/branch/pypy-genc/translator/translator.py
==============================================================================
--- pypy/branch/pypy-genc/translator/translator.py	(original)
+++ pypy/branch/pypy-genc/translator/translator.py	Mon Aug 30 13:34:15 2004
@@ -39,6 +39,7 @@
 from pypy.translator.gencl import GenCL
 from pypy.translator.genc import GenC
 from pypy.translator.tool.buildpyxmodule import make_module_from_pyxstring
+from pypy.translator.tool.buildpyxmodule import make_module_from_c
 from pypy.objspace.flow import FlowObjSpace
 
 
@@ -157,12 +158,10 @@
         """
         return self.generatecode(GenCL, input_arg_types, func)
 
-    def c(self, input_arg_types=None, func=None):
-        """c(self[, input_arg_types][, func]) -> C (CPython) translation
+    def c(self):
+        """c(self) -> C (CPython) translation
         
-        Returns C (CPython)  translation. If input_arg_types is provided,
-        returns type annotated translation. Subsequent calls are
-        not affected by this.
+        Returns C (CPython) translation.
         """
         from StringIO import StringIO 
         out = StringIO()
@@ -217,6 +216,18 @@
         mod = make_module_from_pyxstring(name, udir, pyxcode)
         return getattr(mod, name)
 
+    def ccompile(self):
+        """Returns compiled function, compiled using the C generator.
+        """
+        from pypy.tool.udir import udir
+        name = self.entrypoint.func_name
+        cfile = udir.join('%s.c' % name)
+        f = cfile.open('w')
+        GenC(f, self, name)
+        f.close()
+        mod = make_module_from_c(cfile)
+        return getattr(mod, name)
+
     def call(self, *args):
         """Calls underlying Python function."""
         return self.entrypoint(*args)



More information about the Pypy-commit mailing list