[pypy-svn] r48575 - in pypy/dist/pypy/translator/llvm: . test

rxe at codespeak.net rxe at codespeak.net
Sun Nov 11 16:45:42 CET 2007


Author: rxe
Date: Sun Nov 11 16:45:42 2007
New Revision: 48575

Modified:
   pypy/dist/pypy/translator/llvm/modwrapper.py
   pypy/dist/pypy/translator/llvm/test/runtest.py
Log:
make isolate work again - re-enable llvm testssvn diff test/runtest.py modwrapper.py | less

Modified: pypy/dist/pypy/translator/llvm/modwrapper.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/modwrapper.py	(original)
+++ pypy/dist/pypy/translator/llvm/modwrapper.py	Sun Nov 11 16:45:42 2007
@@ -10,7 +10,6 @@
 
     prolog = """
 import ctypes
-from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
 from os.path import join, dirname, realpath
 
 _c = ctypes.CDLL(join(dirname(realpath(__file__)), "%s"))
@@ -49,32 +48,29 @@
 def identity(res):
     return res
 
-def from_unichar(arg):
-    return ord(arg)
-
-def from_float(arg):
-    return ctypes.c_double(arg)
-
-def to_unichar(res):
-    return unichr(res)
-
 def from_str(arg):
-    # XXX wont work over isolate : arg should be converted into a string first
-    n = len(arg.chars)
     class Chars(ctypes.Structure):
         _fields_ = [("size", ctypes.c_int),
-                    ("data", ctypes.c_byte * n)]
-
+                    ("data", ctypes.c_byte * len(arg))]
     class STR(ctypes.Structure):
         _fields_ = [("hash", ctypes.c_int),
                     ("chars", Chars)]
     s = STR()
     s.hash = 0
-    s.chars.size = len(arg.chars)
-    for ii in range(s.chars.size):
-        s.chars.data[ii] = ord(arg.chars[ii])
+    s.chars.size = len(arg)
+    for ii in range(len(arg)):
+        s.chars.data[ii] = ord(arg[ii])
     return ctypes.addressof(s)
 
+def to_r_uint(res):
+    return {'type':'r_uint', 'value':long(res)}
+
+def to_r_longlong(res):
+    return {'type':'r_longlong', 'value':long(res)}
+
+def to_r_ulonglong(res):
+    return {'type':'r_ulonglong', 'value':long(res)}
+
 def to_str(res):
     class Chars(ctypes.Structure):
         _fields_ = [("size", ctypes.c_int),
@@ -197,10 +193,10 @@
             ctype_s.append(self.to_ctype(A))
 
             if A is lltype.UniChar:
-                action = 'from_unichar'
+                action = 'ord'
 
             elif A is lltype.Float:
-                action = 'from_float'
+                action = 'ctypes.c_double'
 
             elif isinstance(A, lltype.Ptr) and A.TO is STR:
                 action = 'from_str'
@@ -220,13 +216,13 @@
             action = 'unichr'
 
         elif T is lltype.Unsigned:
-            action = 'r_uint'
+            action = 'to_r_uint'
 
         elif T is lltype.SignedLongLong:
-            action = 'r_longlong'
+            action = 'to_r_longlong'
 
         elif T is lltype.UnsignedLongLong:
-            action = 'r_ulonglong'
+            action = 'to_r_ulonglong'
 
         elif isinstance(T, lltype.Ptr) and T.TO is STR:
             action = 'to_str'

Modified: pypy/dist/pypy/translator/llvm/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/runtest.py	Sun Nov 11 16:45:42 2007
@@ -1,7 +1,7 @@
 import py
-py.test.skip("llvm is a state of flux")
 
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin
+from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
 from pypy.translator.llvm.buildllvm import llvm_is_on_path, llvm_version, gcc_version
 from pypy.translator.llvm.genllvm import GenLLVM
 from pypy.annotation.model import lltype_to_annotation
@@ -9,32 +9,36 @@
 
 optimize_tests = False
 native_llvm_backend = True
-MINIMUM_LLVM_VERSION = 2.0
+MINIMUM_LLVM_VERSION = 2.1
 FLOAT_PRECISION = 8
 
-ext_modules = []
-
 # prevents resource leaking
-use_isolate = False
+use_isolate = True
 
 # if test can't be run using isolate, skip the test (useful for buildbots)
-run_isolated_only = False
+run_isolated_only = True
 
 from pypy import conftest
 
+_ext_modules = []
+
 def _cleanup(leave=0):
     from pypy.tool import isolate
     if leave:
-        mods = ext_modules[:-leave]
+        mods = _ext_modules[:-leave]
     else:        
-        mods = ext_modules
+        mods = _ext_modules
     for mod in mods:
         if isinstance(mod, isolate.Isolate):
-            isolate.close_isolate(mod)        
+            try:
+                isolate.close_isolate(mod)
+            except EOFError:
+                pass
+                
     if leave:
-        del ext_modules[:-leave]
+        del _ext_modules[:-leave]
     else:
-        del ext_modules[:]
+        del _ext_modules[:]
             
 def teardown_module(mod):
     _cleanup()
@@ -49,6 +53,43 @@
 
 #______________________________________________________________________________
 
+class ExceptionWrapper:
+    def __init__(self, class_name):
+        self.class_name = class_name
+
+    def __repr__(self):
+        return 'ExceptionWrapper(%s)' % repr(self.class_name)
+
+class StructTuple(tuple):
+    def __getattr__(self, name):
+        if name.startswith('item'):
+            i = int(name[len('item'):])
+            return self[i]
+        else:
+            raise AttributeError, name
+        
+def wrapfn(fn):
+    def wrapped(*args):
+        callargs = []
+        for a in args:
+            if hasattr(a, 'chars'):
+                callargs.append(''.join(a.chars))
+            else:
+                callargs.append(a)
+        res = fn(*callargs)
+        if isinstance(res, dict):
+            # these mappings are a simple protocol to work over isolate
+            mapping = {
+                "exceptiontypename": ExceptionWrapper,
+                "tuple": StructTuple,
+                "r_uint": r_uint,
+                "r_longlong": r_longlong,
+                "r_ulonglong": r_ulonglong,
+                }
+            res = mapping[res["type"]](res["value"])
+        return res
+    return wrapped
+
 def genllvm_compile(function,
                     annotation,
                     
@@ -107,25 +148,21 @@
     mod, fn = genllvm_compile(function, annotation, optimize=optimize,
                               isolate=isolate, **kwds)
     if isolate:
-        ext_modules.append(mod)
-    return mod, fn
+        _ext_modules.append(mod)
+    return mod, wrapfn(fn)
 
 def compile_function(function, annotation, isolate_hint=True, **kwds):
     " returns compiled function "
     return compile_test(function, annotation, isolate_hint=isolate_hint, **kwds)[1]
 
+#______________________________________________________________________________
+
 # XXX Work in progress, this was mostly copied from cli
-class InstanceWrapper:
-    def __init__(self, class_name):
-        self.class_name = class_name
 
-class ExceptionWrapper:
+class InstanceWrapper:
     def __init__(self, class_name):
         self.class_name = class_name
 
-    def __repr__(self):
-        return 'ExceptionWrapper(%s)' % repr(self.class_name)
-
 class LLVMTest(BaseRtypingTest, LLRtypeMixin):
     def __init__(self):
         self._func = None
@@ -155,17 +192,12 @@
         pass
 
     def interpret(self, fn, args, annotation=None):
-        f = self._compile(fn, args, annotation)
-        res = f(*args)
-
-        # a start to making this work over Isolate
-        if isinstance(res, dict):
-            if res["type"] == "exceptiontypename":
-                raise ExceptionWrapper(res["value"]) 
-            elif res["type"] == "tuple":
-                res = StructTuple(res["value"])
+        fn = self._compile(fn, args, annotation)
+        res = fn(*args)
+        if isinstance(res, ExceptionWrapper):
+            raise res
         return res
-
+    
     def interpret_raises(self, exception, fn, args):
         import exceptions # needed by eval
         try:
@@ -200,10 +232,4 @@
     def read_attr(self, obj, name):
         py.test.skip('read_attr not supported on llvm tests')
 
-class StructTuple(tuple):
-    def __getattr__(self, name):
-        if name.startswith('item'):
-            i = int(name[len('item'):])
-            return self[i]
-        else:
-            raise AttributeError, name
+



More information about the Pypy-commit mailing list