[pypy-svn] r64950 - in pypy/branch/pyjitpl5/pypy: annotation rpython/ootypesystem rpython/ootypesystem/test

antocuni at codespeak.net antocuni at codespeak.net
Fri May 1 19:15:26 CEST 2009


Author: antocuni
Date: Fri May  1 19:15:18 2009
New Revision: 64950

Modified:
   pypy/branch/pyjitpl5/pypy/annotation/unaryop.py
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rootype.py
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py
Log:
implement call_args for oo low level bound methods


Modified: pypy/branch/pyjitpl5/pypy/annotation/unaryop.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/annotation/unaryop.py	(original)
+++ pypy/branch/pyjitpl5/pypy/annotation/unaryop.py	Fri May  1 19:15:18 2009
@@ -779,6 +779,18 @@
             METH = ootype.typeOf(meth)
             return lltype_to_annotation(METH.RESULT)
 
+    def call(m, args):
+        args_s, kwds_s = args.unpack()
+        if kwds_s:
+            raise Exception("keyword arguments to call to a low-level bound method")
+        info = 'argument to ll bound method call'
+        llargs = [annotation_to_lltype(s_arg,info)._defl() for s_arg in args_s]
+        inst = m.ootype._example()
+        meth = getattr(inst, m.name)
+        v = meth(*llargs)
+        return ll_to_annotation(v)
+
+
 class __extend__(SomeOOStaticMeth):
 
     def call(m, args):

Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rootype.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rootype.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rootype.py	Fri May  1 19:15:18 2009
@@ -145,6 +145,13 @@
         return hop.genop("oosend", [cname]+vlist,
                          resulttype = hop.r_result.lowleveltype)
 
+    def rtype_call_args(self, hop):
+        from pypy.rpython.rbuiltin import call_args_expand
+        hop, _ = call_args_expand(hop, takes_kwds=False)
+        hop.swap_fst_snd_args()
+        hop.r_s_popfirstarg()
+        return self.rtype_simple_call(hop)
+
 
 class OOStaticMethRepr(Repr):
     def __init__(self, METHODTYPE):

Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py	Fri May  1 19:15:18 2009
@@ -421,3 +421,21 @@
 
     res = interpret(fn, [1], type_system='ootype')
     assert res
+
+
+def test_boundmeth_callargs():
+    A = Instance("A", ROOT, {'a': (Signed, 3)})
+    M = Meth([Signed, Signed], Signed)
+    def m_(self, x, y):
+       return self.a + x + y
+    m = meth(M, _name="m", _callable=m_)
+    addMethods(A, {"m": m})
+
+    def fn(x, y):
+        a = ootype.new(A)
+        meth = a.m
+        args = (x, y)
+        return meth(*args)
+
+    res = interpret(fn, [4, 5], type_system='ootype')
+    assert res == 3+4+5



More information about the Pypy-commit mailing list