[pypy-svn] r53076 - in pypy/branch/jit-hotpath/pypy/rpython: . ootypesystem test

antocuni at codespeak.net antocuni at codespeak.net
Sat Mar 29 10:46:19 CET 2008


Author: antocuni
Date: Sat Mar 29 10:46:18 2008
New Revision: 53076

Modified:
   pypy/branch/jit-hotpath/pypy/rpython/annlowlevel.py
   pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rootype.py
   pypy/branch/jit-hotpath/pypy/rpython/test/test_llann.py
Log:
make llhelper() working also with ootype



Modified: pypy/branch/jit-hotpath/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/rpython/annlowlevel.py	(original)
+++ pypy/branch/jit-hotpath/pypy/rpython/annlowlevel.py	Sat Mar 29 10:46:18 2008
@@ -345,8 +345,12 @@
     # implementation for the purpose of direct running only
     # XXX need more cleverness to support translation of prebuilt llhelper ptr
     # (see test_prebuilt_llhelper)
-    return lltype.functionptr(F.TO, f.func_name, _callable=f,
-                              _debugexc = getattr(f, '_debugexc', False))
+    if isinstance(F, ootype.OOType):
+        return ootype.static_meth(F, f.func_name, _callable=f,
+                                  _debugexc = getattr(f, '_debugexc', False))
+    else:
+        return lltype.functionptr(F.TO, f.func_name, _callable=f,
+                                  _debugexc = getattr(f, '_debugexc', False))
 
 class LLHelperEntry(extregistry.ExtRegistryEntry):
     _about_ = llhelper
@@ -355,11 +359,18 @@
         assert s_F.is_constant()
         assert s_callable.is_constant()
         F = s_F.const
-        args_s = [annmodel.lltype_to_annotation(T) for T in F.TO.ARGS]
+        if isinstance(F, ootype.OOType):
+            FUNC = F
+            resultcls = annmodel.SomeOOStaticMeth
+        else:
+            FUNC = F.TO
+            resultcls = annmodel.SomePtr
+        
+        args_s = [annmodel.lltype_to_annotation(T) for T in FUNC.ARGS]
         key = (llhelper, s_callable.const)
         s_res = self.bookkeeper.emulate_pbc_call(key, s_callable, args_s)
-        assert annmodel.lltype_to_annotation(F.TO.RESULT).contains(s_res)
-        return annmodel.SomePtr(F)
+        assert annmodel.lltype_to_annotation(FUNC.RESULT).contains(s_res)
+        return resultcls(F)
 
     def specialize_call(self, hop):
         hop.exception_cannot_occur()

Modified: pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rootype.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rootype.py	(original)
+++ pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rootype.py	Sat Mar 29 10:46:18 2008
@@ -1,3 +1,4 @@
+from pypy.objspace.flow import model as flowmodel
 from pypy.annotation import model as annmodel
 from pypy.rpython.rmodel import Repr
 from pypy.rpython.ootypesystem import ootype
@@ -127,6 +128,23 @@
     def __init__(self, METHODTYPE):
         self.lowleveltype = METHODTYPE
 
+    def rtype_simple_call(self, hop):
+        vlist = hop.inputargs(*hop.args_r)
+        nexpected = len(self.lowleveltype.ARGS)
+        nactual = len(vlist)-1
+        if nactual != nexpected: 
+            raise TyperError("argcount mismatch:  expected %d got %d" %
+                            (nexpected, nactual))
+        if isinstance(vlist[0], flowmodel.Constant):
+            if hasattr(vlist[0].value, 'graph'):
+                hop.llops.record_extra_call(vlist[0].value.graph)
+            opname = 'direct_call'
+        else:
+            opname = 'indirect_call'
+            vlist.append(hop.inputconst(ootype.Void, None))
+        hop.exception_is_here()
+        return hop.genop(opname, vlist, resulttype = self.lowleveltype.RESULT)
+
 
 class __extend__(pairtype(OOInstanceRepr, OOBoundMethRepr)):
 

Modified: pypy/branch/jit-hotpath/pypy/rpython/test/test_llann.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/rpython/test/test_llann.py	(original)
+++ pypy/branch/jit-hotpath/pypy/rpython/test/test_llann.py	Sat Mar 29 10:46:18 2008
@@ -1,5 +1,6 @@
 import py
 from pypy.rpython.lltypesystem.lltype import *
+from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.lltypesystem.rclass import OBJECTPTR
 from pypy.rpython.rclass import fishllattr
 from pypy.translator.translator import TranslationContext
@@ -451,6 +452,33 @@
     res = interpret(h, [8, 5, 2])
     assert res == 99
 
+def test_oohelper():
+    S = ootype.Instance('S', ootype.ROOT, {'x': Signed, 'y': Signed})
+    def f(s,z):
+        #assert we_are_translated()
+        return s.x*s.y+z
+
+    def g(s):
+        #assert we_are_translated()
+        return s.x+s.y
+
+    F = ootype.StaticMethod([S, Signed], Signed)
+    G = ootype.StaticMethod([S], Signed)
+        
+    def h(x, y, z):
+        s = ootype.new(S)
+        s.x = x
+        s.y = y
+        fsm = llhelper(F, f)
+        gsm = llhelper(G, g)
+        assert typeOf(fsm) == F
+        return fsm(s, z)+fsm(s, z*2)+gsm(s)
+
+    res = h(8, 5, 2)
+    assert res == 99
+    res = interpret(h, [8, 5, 2], type_system='ootype')
+    assert res == 99
+
 
 def test_prebuilt_llhelper():
     py.test.skip("does not work")


More information about the pypy-svn mailing list