[pypy-svn] r75006 - in pypy/branch/fast-ctypes/pypy/module/jitffi: . test

getxsick at codespeak.net getxsick at codespeak.net
Tue Jun 1 19:47:38 CEST 2010


Author: getxsick
Date: Tue Jun  1 19:47:37 2010
New Revision: 75006

Modified:
   pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
   pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py
Log:
first try of a list of arguments. deadly limited, only for integers etc.


Modified: pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py	(original)
+++ pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py	Tue Jun  1 19:47:37 2010
@@ -21,7 +21,11 @@
         self.space = space
         self.cpu = CPU(None, None)
 
-    def call(self, space, func, a, b, res_type):  # XXX temporary fixed number of func args (ints)
+    def call(self, space, func, w_func_args, res_type='void'):
+        # only integers are supported for now
+        func_args_w = space.listview(w_func_args)
+        assert isinstance(func_args_w, list)
+
         if res_type == 'int':
             bres = BoxInt()
         elif res_type == 'float':
@@ -38,21 +42,19 @@
         except KeyError:
             raise operationerrfmt(space.w_ValueError,
                                   "Cannot find symbol %s", func)
-
         bfuncaddr = BoxInt(addr)
-        barg0 = BoxInt(a)
-        barg1 = BoxInt(b)
 
-        FPTR = lltype.Ptr(lltype.FuncType([lltype.Signed, lltype.Signed],
-                          lltype.Signed))
+        args_type = [ lltype.Signed for i in func_args_w ]
+        FPTR = lltype.Ptr(lltype.FuncType(args_type, lltype.Signed))
         FUNC = deref(FPTR)
         calldescr = self.cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT)
 
-        oplist = [ResOperation(rop.CALL, [bfuncaddr, barg0, barg1], bres,
-                               descr=calldescr),
+        bargs = [ BoxInt(x.intval) for x in func_args_w ]
+        inputargs = [bfuncaddr] + bargs
+
+        oplist = [ResOperation(rop.CALL, inputargs, bres, descr=calldescr),
                   ResOperation(rop.FINISH, [bres], None,
                                descr=BasicFailDescr(0))]
-        inputargs = [bfuncaddr, barg0, barg1]
         looptoken = LoopToken()
         self.cpu.compile_loop(inputargs, oplist, looptoken)
 
@@ -78,7 +80,7 @@
         else:
             raise ValueError(res_type)
         return space.wrap(r)
-    call.unwrap_spec = ['self', ObjSpace, str, int, int, str]
+    call.unwrap_spec = ['self', ObjSpace, str, W_Root, str]
 
 def descr_new_cdll(space, w_type, name):
     try:

Modified: pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py	(original)
+++ pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py	Tue Jun  1 19:47:37 2010
@@ -19,6 +19,14 @@
         {
            return a+b;
         }
+
+        int max3(int a, int b, int c)
+        {
+           int max = a;
+           if (b > max) max = b;
+           if (c > max) max = c;
+           return max;
+        }
         '''
         ))
 
@@ -38,14 +46,19 @@
         import jitffi
         lib = jitffi.CDLL(self.lib_name)
 
-        res = lib.call('add_integers', 1, 2, 'int')
+        res = lib.call('add_integers', [1, 2], 'int')
         assert 3 == res
         assert isinstance(res, int)
-        res = lib.call('add_integers', -1, 2, 'int')
+        res = lib.call('add_integers', [-1, 2], 'int')
         assert 1 == res
-        res = lib.call('add_integers', 0, 0, 'int')
+        res = lib.call('add_integers', [0, 0], 'int')
         assert 0 == res
 
-        res = lib.call('return_float', 1, 2, 'float')
+        res = lib.call('max3', [2, 8, 3], 'int')
+        assert 8 == res
+
+        res = lib.call('return_float', [1, 2], 'float')
         assert 3.0 == res
         assert isinstance(res, float)
+        #res = lib.call('return_float', [1.5, 1.2], 'float')
+        #assert 2.7 == res



More information about the Pypy-commit mailing list