[pypy-svn] r40441 - in pypy/dist/pypy: rpython rpython/test translator/cli translator/cli/src translator/cli/test

antocuni at codespeak.net antocuni at codespeak.net
Tue Mar 13 15:47:18 CET 2007


Author: antocuni
Date: Tue Mar 13 15:47:17 2007
New Revision: 40441

Added:
   pypy/dist/pypy/translator/cli/src/ll_os_path.cs
Modified:
   pypy/dist/pypy/rpython/extfuncregistry.py
   pypy/dist/pypy/rpython/test/test_rbuiltin.py
   pypy/dist/pypy/translator/cli/rte.py
   pypy/dist/pypy/translator/cli/test/test_builtin.py
Log:
We can't use the default os.path.join with ootype because we would get
the version for the platform we did the translation on. Instead, rely
on the backend doing the proper thing.



Modified: pypy/dist/pypy/rpython/extfuncregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/extfuncregistry.py	(original)
+++ pypy/dist/pypy/rpython/extfuncregistry.py	Tue Mar 13 15:47:17 2007
@@ -1,12 +1,12 @@
 # this registry use the new interface for external functions
 # all the above declarations in extfunctable should be moved here at some point.
 
-import math
 from extfunc import register_external
 
 # ___________________________
 # math functions
 
+import math
 from pypy.rpython.lltypesystem.module import ll_math
 from pypy.rpython.ootypesystem.module import ll_math as oo_math
 from pypy.rpython.module import ll_os
@@ -49,3 +49,29 @@
     register_external(func, args, res, 'll_math.ll_math_%s' % name,
                       llfakeimpl=llfake, oofakeimpl=oofake,
                       annotation_hook = hook)
+
+# ___________________________
+# os.path functions
+
+from pypy.tool.sourcetools import func_with_new_name
+import os.path
+
+# os.path.join is RPython, but we don't want to compile it directly
+# because it's platform dependant. This is ok for lltype where the
+# execution platform is the same as the translation platform, but not
+# for ootype where the executable produced by some backends (e.g. CLI,
+# JVM) are expected to run everywhere.  Thus, we register it as an
+# external function, but we provide a clone for lltype using
+# func_with_new_name.
+
+# XXX: I can't see any easy way to provide an oofakeimpl for the
+# llinterpreter
+
+path_functions = [
+    ('join',     [str, str], str),
+    ]
+
+for name, args, res in path_functions:
+    func = getattr(os.path, name)
+    llimpl = func_with_new_name(func, name)
+    register_external(func, args, res, 'll_os_path.ll_%s' % name, llimpl=llimpl)

Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py	Tue Mar 13 15:47:17 2007
@@ -336,7 +336,14 @@
         assert self.class_name(res) == 'A'
         res = self.interpret(f, [2])
         assert self.class_name(res) == 'B'
-        
+
+    def test_os_path_join(self):
+        self._skip_oo('os.path.join oofakeimpl')
+        import os.path
+        def fn(a, b):
+            return os.path.join(a, b)
+        res = self.ll_to_string(self.interpret(fn, ['a', 'b']))
+        assert res == os.path.join('a', 'b')
 
 class TestLLtype(BaseTestRbuiltin, LLRtypeMixin):
     from pypy.rpython.lltypesystem.module import ll_os

Modified: pypy/dist/pypy/translator/cli/rte.py
==============================================================================
--- pypy/dist/pypy/translator/cli/rte.py	(original)
+++ pypy/dist/pypy/translator/cli/rte.py	Tue Mar 13 15:47:17 2007
@@ -77,7 +77,7 @@
     get_COMPILER = classmethod(get_COMPILER)
     
 class FrameworkDLL(Target):
-    SOURCES = ['pypylib.cs', 'll_os.cs', 'errno.cs', 'll_math.cs']
+    SOURCES = ['pypylib.cs', 'll_os.cs', 'll_os_path.cs', 'errno.cs', 'll_math.cs']
     OUTPUT = 'pypylib.dll'
     ALIAS = 'pypylib-framework.dll'
     FLAGS = ['/t:library', '/unsafe', '/r:main.exe']

Added: pypy/dist/pypy/translator/cli/src/ll_os_path.cs
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/cli/src/ll_os_path.cs	Tue Mar 13 15:47:17 2007
@@ -0,0 +1,14 @@
+using System;
+using System.IO;
+using pypy.runtime;
+
+namespace pypy.builtin
+{
+    public class ll_os_path
+    {
+        public static string ll_join(string a, string b)
+        {
+            return Path.Combine(a, b);
+        }
+    }
+}

Modified: pypy/dist/pypy/translator/cli/test/test_builtin.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_builtin.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_builtin.py	Tue Mar 13 15:47:17 2007
@@ -124,3 +124,10 @@
 
     # XXX: remember to test ll_os_readlink and ll_os_pipe as soon as
     # they are implemented
+
+    def test_os_path_join(self):
+        import os.path
+        def fn(a, b):
+            return os.path.join(a, b)
+        res = self.ll_to_string(self.interpret(fn, ['a', 'b']))
+        assert res == os.path.join('a', 'b')



More information about the Pypy-commit mailing list