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

arigo at codespeak.net arigo at codespeak.net
Thu Dec 3 18:36:31 CET 2009


Author: arigo
Date: Thu Dec  3 18:36:30 2009
New Revision: 69873

Added:
   pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py   (contents, props changed)
   pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py   (contents, props changed)
Modified:
   pypy/branch/virtual-forcing/pypy/rlib/jit.py
Log:
Write tests and implement them: annotation, easy case.


Added: pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py
==============================================================================
--- (empty file)
+++ pypy/branch/virtual-forcing/pypy/rlib/_jit_vref.py	Thu Dec  3 18:36:30 2009
@@ -0,0 +1,10 @@
+from pypy.annotation import model as annmodel
+
+
+class SomeVRef(annmodel.SomeObject):
+
+    def __init__(self, s_instance):
+        self.s_instance = s_instance
+
+    def simple_call(self):
+        return self.s_instance

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:36:30 2009
@@ -98,8 +98,30 @@
         hop.exception_cannot_occur()
         return hop.inputconst(lltype.Signed, _we_are_jitted)
 
+# ____________________________________________________________
+# VRefs
+
 def virtual_ref(x):
-    return None        # XXX!
+    return DirectVRef(x)
+
+class DirectVRef(object):
+    def __init__(self, x):
+        self._x = x
+    def __call__(self):
+        return self._x
+    def _freeze_(self):
+        raise Exception("should not see a prebuilt pypy.rlib.jit.virtual_ref")
+
+class Entry(ExtRegistryEntry):
+    _about_ = virtual_ref
+
+    def compute_result_annotation(self, s_obj):
+        from pypy.rlib import _jit_vref
+        return _jit_vref.SomeVRef(s_obj)
+
+    def specialize_call(self, hop):
+        from pypy.rlib import _jit_vref
+        return _jit_vref.specialize_call(self, hop)
 
 # ____________________________________________________________
 # User interface for the hotpath JIT policy

Added: pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py
==============================================================================
--- (empty file)
+++ pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py	Thu Dec  3 18:36:30 2009
@@ -0,0 +1,32 @@
+from pypy.rlib.jit import virtual_ref
+from pypy.rlib._jit_vref import SomeVRef
+from pypy.annotation import model as annmodel
+from pypy.annotation.annrpython import RPythonAnnotator
+
+
+class X(object):
+    pass
+
+
+def test_direct():
+    x1 = X()
+    vref = virtual_ref(x1)
+    assert vref() is x1
+
+def test_annotate_1():
+    def f():
+        return virtual_ref(X())
+    a = RPythonAnnotator()
+    s = a.build_types(f, [])
+    assert isinstance(s, SomeVRef)
+    assert isinstance(s.s_instance, annmodel.SomeInstance)
+    assert s.s_instance.classdef == a.bookkeeper.getuniqueclassdef(X)
+
+def test_annotate_2():
+    def f():
+        vref = virtual_ref(X())
+        return vref()
+    a = RPythonAnnotator()
+    s = a.build_types(f, [])
+    assert isinstance(s, annmodel.SomeInstance)
+    assert s.classdef == a.bookkeeper.getuniqueclassdef(X)



More information about the Pypy-commit mailing list