[pypy-svn] r77277 - in pypy/branch/jitffi/pypy/rlib: . test

antocuni at codespeak.net antocuni at codespeak.net
Wed Sep 22 17:34:49 CEST 2010


Author: antocuni
Date: Wed Sep 22 17:34:47 2010
New Revision: 77277

Added:
   pypy/branch/jitffi/pypy/rlib/jitffi.py   (contents, props changed)
   pypy/branch/jitffi/pypy/rlib/test/test_jitffi.py   (contents, props changed)
Log:
first try for a jit-friendly interface to libffi



Added: pypy/branch/jitffi/pypy/rlib/jitffi.py
==============================================================================
--- (empty file)
+++ pypy/branch/jitffi/pypy/rlib/jitffi.py	Wed Sep 22 17:34:47 2010
@@ -0,0 +1,37 @@
+class AbstractArg(object):
+    next = None
+
+class IntArg(AbstractArg):
+
+    def __init__(self, intval):
+        self.intval = intval
+
+    def push(self, funcptr):
+        funcptr.push_arg(self.intval)
+
+class FloatArg(AbstractArg):
+
+    def __init__(self, floatval):
+        self.floatval = floatval
+
+    def push(self, funcptr):
+        funcptr.push_arg(self.floatval)
+
+
+class Func(object):
+
+    def __init__(self, funcptr):
+        # XXX: for now, this is just a wrapper around libffi.FuncPtr, but in
+        # the future it will replace it completely
+        self.funcptr = funcptr
+
+    def call(self, argchain, RESULT):
+        # implementation detail
+        arg = argchain
+        while arg:
+            arg.push(self.funcptr)
+            arg = arg.next
+        return self.funcptr.call(RESULT)
+    call._annspecialcase_ = 'specialize:arg(1)'
+
+

Added: pypy/branch/jitffi/pypy/rlib/test/test_jitffi.py
==============================================================================
--- (empty file)
+++ pypy/branch/jitffi/pypy/rlib/test/test_jitffi.py	Wed Sep 22 17:34:47 2010
@@ -0,0 +1,23 @@
+import sys
+from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.rlib.clibffi import CDLL, ffi_type_double
+from pypy.rlib.jitffi import Func, FloatArg
+from pypy.rlib.test.test_libffi import get_libc_name, get_libm_name
+
+class TestJitffi(object):
+
+    def get_libc(self):
+        return CDLL(get_libc_name())
+    
+    def get_libm(self):
+        return CDLL(get_libm_name(sys.platform))
+    
+    def test_call_argchain(self):
+        libm = self.get_libm()
+        pow_ptr = libm.getpointer('pow', [ffi_type_double, ffi_type_double],
+                              ffi_type_double)
+        pow = Func(pow_ptr)
+        argchain = FloatArg(2.0)
+        argchain.next = FloatArg(3.0)
+        res = pow.call(argchain, rffi.DOUBLE)
+        assert res == 8.0



More information about the Pypy-commit mailing list