[pypy-svn] r64112 - in pypy/branch/pyjitpl5-simplify/pypy/rpython: . ootypesystem test

antocuni at codespeak.net antocuni at codespeak.net
Wed Apr 15 19:31:45 CEST 2009


Author: antocuni
Date: Wed Apr 15 19:31:42 2009
New Revision: 64112

Modified:
   pypy/branch/pyjitpl5-simplify/pypy/rpython/annlowlevel.py
   pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rootype.py
   pypy/branch/pyjitpl5-simplify/pypy/rpython/test/test_llann.py
Log:
manually replay r53076, to make llhelper() working also with ootype


Modified: pypy/branch/pyjitpl5-simplify/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/annlowlevel.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/annlowlevel.py	Wed Apr 15 19:31:42 2009
@@ -360,7 +360,11 @@
     #       prebuilt_g()
 
     # the next line is the implementation for the purpose of direct running
-    return lltype.functionptr(F.TO, f.func_name, _callable=f)
+    if isinstance(F, ootype.OOType):
+        return ootype.static_meth(F, f.func_name, _callable=f)
+    else:
+        return lltype.functionptr(F.TO, f.func_name, _callable=f)
+
 
 class LLHelperEntry(extregistry.ExtRegistryEntry):
     _about_ = llhelper
@@ -369,11 +373,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/pyjitpl5-simplify/pypy/rpython/ootypesystem/rootype.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rootype.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rootype.py	Wed Apr 15 19:31:42 2009
@@ -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
@@ -146,6 +147,23 @@
         hop.r_s_popfirstarg()
         return self.rtype_simple_call(hop)
 
+    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/pyjitpl5-simplify/pypy/rpython/test/test_llann.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/test/test_llann.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/test/test_llann.py	Wed Apr 15 19:31:42 2009
@@ -1,4 +1,5 @@
 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
@@ -446,6 +447,34 @@
     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_cast_instance_to_base_ptr():
     class A:



More information about the Pypy-commit mailing list