[pypy-svn] r69874 - in pypy/branch/virtual-forcing/pypy/rlib: . test

arigo at codespeak.net arigo at codespeak.net
Thu Dec 3 18:56:29 CET 2009


Author: arigo
Date: Thu Dec  3 18:56:29 2009
New Revision: 69874

Modified:
   pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py
   pypy/branch/virtual-forcing/pypy/rlib/jit.py
   pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py
Log:
Rtyping.  Still no real work.


Modified: pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py	(original)
+++ pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py	Thu Dec  3 18:56:29 2009
@@ -1,4 +1,6 @@
 from pypy.annotation import model as annmodel
+from pypy.rpython.rclass import getinstancerepr
+from pypy.rpython.rmodel import Repr
 
 
 class SomeVRef(annmodel.SomeObject):
@@ -8,3 +10,28 @@
 
     def simple_call(self):
         return self.s_instance
+
+    def rtyper_makerepr(self, rtyper):
+        return get_vref(rtyper)
+
+    def rtyper_makekey(self):
+        return self.__class__,
+
+
+def specialize_call(hop):
+    [v] = hop.inputargs(getinstancerepr(hop.rtyper, None))
+    return v
+
+def get_vref(rtyper):
+    if not hasattr(rtyper, '_vrefrepr'):
+        rtyper._vrefrepr = VRefRepr(rtyper)
+    return rtyper._vrefrepr
+
+
+class VRefRepr(Repr):
+    def __init__(self, rtyper):
+        self.lowleveltype = getinstancerepr(rtyper, None).lowleveltype
+
+    def rtype_simple_call(self, hop):
+        [v] = hop.inputargs(self)
+        return hop.genop('cast_pointer', [v], resulttype = hop.r_result)

Modified: pypy/branch/virtual-forcing/pypy/rlib/jit.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rlib/jit.py	(original)
+++ pypy/branch/virtual-forcing/pypy/rlib/jit.py	Thu Dec  3 18:56:29 2009
@@ -121,7 +121,7 @@
 
     def specialize_call(self, hop):
         from pypy.rlib import _jit_vref
-        return _jit_vref.specialize_call(self, hop)
+        return _jit_vref.specialize_call(hop)
 
 # ____________________________________________________________
 # User interface for the hotpath JIT policy

Modified: pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py	(original)
+++ pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py	Thu Dec  3 18:56:29 2009
@@ -2,6 +2,9 @@
 from pypy.rlib._jit_vref import SomeVRef
 from pypy.annotation import model as annmodel
 from pypy.annotation.annrpython import RPythonAnnotator
+from pypy.rpython.test.test_llinterp import interpret
+from pypy.rpython.lltypesystem.rclass import OBJECTPTR
+from pypy.rpython.lltypesystem import lltype
 
 
 class X(object):
@@ -30,3 +33,16 @@
     s = a.build_types(f, [])
     assert isinstance(s, annmodel.SomeInstance)
     assert s.classdef == a.bookkeeper.getuniqueclassdef(X)
+
+def test_rtype_1():
+    def f():
+        return virtual_ref(X())
+    x = interpret(f, [])
+    assert lltype.typeOf(x) == OBJECTPTR
+
+def test_rtype_2():
+    def f():
+        vref = virtual_ref(X())
+        return vref()
+    x = interpret(f, [])
+    assert lltype.castable(OBJECTPTR, lltype.typeOf(x)) > 0



More information about the Pypy-commit mailing list