[pypy-svn] r77593 - in pypy/branch/jitffi/pypy: jit/metainterp/test rlib rlib/test

antocuni at codespeak.net antocuni at codespeak.net
Tue Oct 5 10:02:46 CEST 2010


Author: antocuni
Date: Tue Oct  5 10:02:44 2010
New Revision: 77593

Modified:
   pypy/branch/jitffi/pypy/jit/metainterp/test/test_fficall.py
   pypy/branch/jitffi/pypy/rlib/libffi.py
   pypy/branch/jitffi/pypy/rlib/test/test_libffi.py
Log:
unify the float() and int() methods of ArgChain into arg(), which is specialized by the type of the argument


Modified: pypy/branch/jitffi/pypy/jit/metainterp/test/test_fficall.py
==============================================================================
--- pypy/branch/jitffi/pypy/jit/metainterp/test/test_fficall.py	(original)
+++ pypy/branch/jitffi/pypy/jit/metainterp/test/test_fficall.py	Tue Oct  5 10:02:44 2010
@@ -47,7 +47,7 @@
                 driver.can_enter_jit(n=n, func=func)
                 func = hint(func, promote=True)
                 argchain = ArgChain()
-                argchain.int(n).float(1.2)
+                argchain.arg(n).arg(1.2)
                 n = func.call(argchain, rffi.LONG)
             return n
             
@@ -73,7 +73,7 @@
                 driver.can_enter_jit(n=n, func=func, res=res)
                 func = hint(func, promote=True)
                 argchain = ArgChain()
-                argchain.float(float(-n))
+                argchain.arg(float(-n))
                 res = func.call(argchain, rffi.DOUBLE)
                 n += 1
             return res
@@ -95,7 +95,7 @@
                 driver.can_enter_jit(n=n, func=func, res=res)
                 func = hint(func, promote=True)
                 argchain = ArgChain()
-                argchain.int(0)
+                argchain.arg(0)
                 res = func.call(argchain, rffi.UCHAR)
                 n += 1
             return res

Modified: pypy/branch/jitffi/pypy/rlib/libffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/rlib/libffi.py	(original)
+++ pypy/branch/jitffi/pypy/rlib/libffi.py	Tue Oct  5 10:02:44 2010
@@ -48,12 +48,16 @@
     last = None
     numargs = 0
 
-    def int(self, intval):
-        self._append(IntArg(intval))
-        return self
-
-    def float(self, floatval):
-        self._append(FloatArg(floatval))
+    @specialize.argtype(1)
+    def arg(self, val):
+        TYPE = lltype.typeOf(val)
+        if TYPE is rffi.LONG:
+            cls = IntArg
+        elif TYPE is rffi.DOUBLE:
+            cls = FloatArg
+        else:
+            raise TypeError, 'Unsupported argument type: %s' % TYPE
+        self._append(cls(val))
         return self
 
     def _append(self, arg):

Modified: pypy/branch/jitffi/pypy/rlib/test/test_libffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/rlib/test/test_libffi.py	(original)
+++ pypy/branch/jitffi/pypy/rlib/test/test_libffi.py	Tue Oct  5 10:02:44 2010
@@ -20,13 +20,13 @@
     def test_argchain(self):
         chain = ArgChain()
         assert chain.numargs == 0
-        chain2 = chain.int(42)
+        chain2 = chain.arg(42)
         assert chain2 is chain
         assert chain.numargs == 1
         intarg = chain.first
         assert chain.last is intarg
         assert intarg.intval == 42
-        chain.float(123.45)
+        chain.arg(123.45)
         assert chain.numargs == 2
         assert chain.first is intarg
         assert intarg.next is chain.last
@@ -51,6 +51,6 @@
         pow = libm.getpointer('pow', [types.double, types.double],
                               types.double)
         argchain = ArgChain()
-        argchain.float(2.0).float(3.0)
+        argchain.arg(2.0).arg(3.0)
         res = pow.call(argchain, rffi.DOUBLE)
         assert res == 8.0



More information about the Pypy-commit mailing list