[pypy-svn] r70510 - in pypy/branch/separate-compilation/pypy/translator: . c c/test test

afa at codespeak.net afa at codespeak.net
Mon Jan 11 17:31:58 CET 2010


Author: afa
Date: Mon Jan 11 17:31:57 2010
New Revision: 70510

Added:
   pypy/branch/separate-compilation/pypy/translator/separate.py   (contents, props changed)
      - copied, changed from r70507, pypy/branch/separate-compilation/pypy/translator/c/separate.py
   pypy/branch/separate-compilation/pypy/translator/test/test_separate.py   (contents, props changed)
Removed:
   pypy/branch/separate-compilation/pypy/translator/c/separate.py
Modified:
   pypy/branch/separate-compilation/pypy/translator/c/test/test_separate.py
Log:
Move @export to pypy/translate/, and make it compatible with the one used by cli/carbonpython.py


Modified: pypy/branch/separate-compilation/pypy/translator/c/test/test_separate.py
==============================================================================
--- pypy/branch/separate-compilation/pypy/translator/c/test/test_separate.py	(original)
+++ pypy/branch/separate-compilation/pypy/translator/c/test/test_separate.py	Mon Jan 11 17:31:57 2010
@@ -1,4 +1,4 @@
-from pypy.translator.c.separate import export
+from pypy.translator.separate import export
 from pypy.translator.translator import TranslationContext
 from pypy.translator.c.genc import CExtModuleBuilder, CLibraryBuilder, gen_forwarddecl
 from pypy.translator.tool.cbuild import ExternalCompilationInfo

Copied: pypy/branch/separate-compilation/pypy/translator/separate.py (from r70507, pypy/branch/separate-compilation/pypy/translator/c/separate.py)
==============================================================================
--- pypy/branch/separate-compilation/pypy/translator/c/separate.py	(original)
+++ pypy/branch/separate-compilation/pypy/translator/separate.py	Mon Jan 11 17:31:57 2010
@@ -1,31 +1,37 @@
-import types
-
-class export(object):
-    """decorator to mark a function as exported by a shared module.
-    Can be used with a signature::
-        @export(float, float)
-        def f(x, y):
-            return x + y
-    or without any argument at all::
-        @export
-        def f(x, y):
-            return x + y
-    in which case the function must be used somewhere else, which will
-    trigger its annotation."""
-    argtypes = None
-
-    def __new__(cls, *args, **kwds):
-        if len(args) == 1 and isinstance(args[0], types.FunctionType):
-            func = args[0]
-            decorated = export()(func)
-            del decorated.argtypes
-            return decorated
-        return object.__new__(cls, *args, **kwds)
-
-    def __init__(self, *args):
-        self.argtypes = args
-
-    def __call__(self, func):
-        if self.argtypes is not None:
-            func.argtypes = self.argtypes
-        return func
+import types
+
+class export(object):
+    """decorator to mark a function as exported by a shared module.
+    Can be used with a signature::
+        @export(float, float)
+        def f(x, y):
+            return x + y
+    or without any argument at all::
+        @export
+        def f(x, y):
+            return x + y
+    in which case the function must be used somewhere else, which will
+    trigger its annotation."""
+
+    argtypes = None
+    namespace = None
+
+    def __new__(cls, *args, **kwds):
+        if len(args) == 1 and isinstance(args[0], types.FunctionType):
+            func = args[0]
+            decorated = export()(func)
+            del decorated.argtypes
+            return decorated
+        return object.__new__(cls, *args, **kwds)
+
+    def __init__(self, *args, **kwargs):
+        self.argtypes = args
+        self.namespace = kwargs.get('namespace')
+
+    def __call__(self, func):
+        func.exported = True
+        if self.argtypes is not None:
+            func.argtypes = self.argtypes
+        if self.namespace is not None:
+            func.namespace = self.namespace
+        return func

Added: pypy/branch/separate-compilation/pypy/translator/test/test_separate.py
==============================================================================
--- (empty file)
+++ pypy/branch/separate-compilation/pypy/translator/test/test_separate.py	Mon Jan 11 17:31:57 2010
@@ -0,0 +1,20 @@
+from pypy.translator.separate import export
+
+class TestSeparate:
+    def test_export(self):
+        @export(int, float)
+        def foo(x, y):
+            pass
+        @export(int, float, namespace='test')
+        def bar(x, y):
+            pass
+        @export
+        def baz():
+            pass
+
+        assert foo.argtypes == (int, float)
+        assert not hasattr(foo, '_namespace_')
+        assert bar.argtypes == (int, float)
+        assert bar.namespace == 'test'
+        assert not hasattr(baz, 'argtypes')
+        assert baz.exported



More information about the Pypy-commit mailing list