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

arigo at codespeak.net arigo at codespeak.net
Thu Dec 3 22:02:38 CET 2009


Author: arigo
Date: Thu Dec  3 22:02:37 2009
New Revision: 69880

Modified:
   pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py
   pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py
Log:
Mixing with None, more of it.


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 22:02:37 2009
@@ -5,6 +5,8 @@
 from pypy.rpython.rmodel import Repr
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.lltypesystem.rclass import OBJECTPTR
+from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.error import TyperError
 
 
 class SomeVRef(annmodel.SomeObject):
@@ -19,9 +21,7 @@
         return self.s_instance
 
     def rtyper_makerepr(self, rtyper):
-        if not hasattr(rtyper, '_vrefrepr'):
-            rtyper._vrefrepr = VRefRepr(rtyper)
-        return rtyper._vrefrepr
+        return vrefrepr
 
     def rtyper_makekey(self):
         return self.__class__,
@@ -30,8 +30,7 @@
 
 
 class VRefRepr(Repr):
-    def __init__(self, rtyper):
-        self.lowleveltype = getinstancerepr(rtyper, None).lowleveltype
+    lowleveltype = OBJECTPTR
 
     def specialize_call(self, hop):
         [v] = hop.inputargs(getinstancerepr(hop.rtyper, None))
@@ -41,3 +40,10 @@
         [v] = hop.inputargs(self)
         v = hop.genop('jit_force_virtual', [v], resulttype = OBJECTPTR)
         return hop.genop('cast_pointer', [v], resulttype = hop.r_result)
+
+    def convert_const(self, value):
+        if value:
+            raise TyperError("only supports None as a prebuilt virtual_ref")
+        return lltype.nullptr(OBJECTPTR.TO)
+
+vrefrepr = VRefRepr()

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 22:02:37 2009
@@ -86,4 +86,14 @@
     x = interpret(f, [-5])
     assert lltype.typeOf(x) == OBJECTPTR
 
+def test_rtype_4():
+    def f(n):
+        if n > 0:
+            return virtual_ref(X())
+        else:
+            return None
+    x = interpret(f, [-5])
+    assert lltype.typeOf(x) == OBJECTPTR
+    assert not x
+
 # the path "we_are_jitted()" is tested in jit/metainterp/test/test_codewriter.



More information about the Pypy-commit mailing list