[pypy-svn] r72847 - in pypy/branch/kill-asm-call/pypy/jit/backend/llsupport: . test

fijal at codespeak.net fijal at codespeak.net
Thu Mar 25 21:06:19 CET 2010


Author: fijal
Date: Thu Mar 25 21:05:55 2010
New Revision: 72847

Modified:
   pypy/branch/kill-asm-call/pypy/jit/backend/llsupport/descr.py
   pypy/branch/kill-asm-call/pypy/jit/backend/llsupport/test/test_descr.py
Log:
Finish the test and make the test pass


Modified: pypy/branch/kill-asm-call/pypy/jit/backend/llsupport/descr.py
==============================================================================
--- pypy/branch/kill-asm-call/pypy/jit/backend/llsupport/descr.py	(original)
+++ pypy/branch/kill-asm-call/pypy/jit/backend/llsupport/descr.py	Thu Mar 25 21:05:55 2010
@@ -1,8 +1,9 @@
 import py
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, rffi, llmemory
 from pypy.jit.backend.llsupport import symbolic
 from pypy.jit.metainterp.history import AbstractDescr, getkind, BoxInt, BoxPtr
 from pypy.jit.metainterp.history import BasicFailDescr, LoopToken, BoxFloat
+from pypy.jit.metainterp import history
 from pypy.jit.metainterp.resoperation import ResOperation, rop
 
 # The point of the class organization in this file is to make instances
@@ -217,36 +218,38 @@
         return self.call_stub
 
     def create_call_stub(self, FUNC):
-        def no_result(arg):
-            return None
-
         def process(no, c):
             if c == 'i':
-                return 'lltype.cast_primitive(FUNC.ARGS[%d], arg[%d].getint())' % (no, no)
+                return 'lltype.cast_primitive(FUNC.ARGS[%d], args[%d].getint())' % (no - 1, no)
             elif c == 'f':
                 return 'args[%d].getfloat()' % (no,)
             elif c == 'r':
-                return 'arg[%d].getptr(FUNC.ARGS[%d])' % (no, no)
+                return 'args[%d].getref(FUNC.ARGS[%d])' % (no, no - 1)
             else:
                 raise Exception("Unknown type %s for type %s" % (c, TP))
-        
+            
+        args = ", ".join([process(i + 1, c) for i, c in
+                          enumerate(self.arg_classes)])
+
         if self.returns_a_pointer():
-            restype = 'BoxPtr'
+            result = 'history.BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, res))'
         elif self.returns_a_float():
-            restype = 'BoxFloat'
+            result = 'history.BoxFloat(res)'
         elif self.returns_a_void():
-            restype = 'no_result'
+            result = 'None'
         else:
-            restype = 'BoxInt'
-        args = ", ".join([process(i, c) for i, c in
-                          enumerate(self.arg_classes)])
+            result = 'history.BoxInt(lltype.cast_primitive(lltype.Signed, res))'
         source = py.code.Source("""
-        def call_stub(callable, args):
-            ll_callable = lltype.cast_opaque_ptr(FUNC, callable)
-            return %(restype)s(ll_callable(%(args)s))
+        def call_stub(args):
+            ll_callable = rffi.cast(lltype.Ptr(FUNC), args[0].getint())
+            res = ll_callable(%(args)s)
+            return %(result)s
         """ % locals())
         d = locals().copy()
         d['lltype'] = lltype
+        d['rffi'] = rffi
+        d['history'] = history
+        d['llmemory'] = llmemory
         exec source.compile() in d
         self.call_stub = d['call_stub']
 

Modified: pypy/branch/kill-asm-call/pypy/jit/backend/llsupport/test/test_descr.py
==============================================================================
--- pypy/branch/kill-asm-call/pypy/jit/backend/llsupport/test/test_descr.py	(original)
+++ pypy/branch/kill-asm-call/pypy/jit/backend/llsupport/test/test_descr.py	Thu Mar 25 21:05:55 2010
@@ -238,7 +238,24 @@
         return 'c'
 
     call_stub = descr1.get_call_stub()
-    fnptr = llhelper(lltype.FuncType(ARGS, RES), f)
+    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
 
-    res = call_stub(fnptr, [BoxInt(1), BoxInt(2)])
+    res = call_stub([BoxInt(rffi.cast(lltype.Signed, fnptr)),
+                     BoxInt(1), BoxInt(2)])
     assert res.getint() == ord('c')
+
+    ARRAY = lltype.GcArray(lltype.Signed)
+    ARGS = [lltype.Float, lltype.Ptr(ARRAY)]
+    RES = lltype.Float
+
+    def f(a, b):
+        return float(b[0]) + a
+
+    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
+    descr2 = get_call_descr(c0, ARGS, RES)
+    a = lltype.malloc(ARRAY, 3)
+    opaquea = lltype.cast_opaque_ptr(llmemory.GCREF, a)
+    a[0] = 1
+    res = descr2.get_call_stub()([BoxInt(rffi.cast(lltype.Signed, fnptr)),
+                                  BoxFloat(3.5), BoxPtr(opaquea)])
+    assert res.getfloat() == 4.5



More information about the Pypy-commit mailing list