[pypy-svn] r69951 - in pypy/branch/virtual-forcing/pypy/rlib: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Dec 7 16:22:58 CET 2009
Author: arigo
Date: Mon Dec 7 16:22:58 2009
New Revision: 69951
Modified:
pypy/branch/virtual-forcing/pypy/rlib/jit.py
pypy/branch/virtual-forcing/pypy/rlib/test/test__jit_vref.py
Log:
Write docstrings for the functions virtual_ref and virtual_ref_finish.
Fix the tests according to the docstrings. Note that this behavior
would be more relaxed than what 'metainterp' currently implements,
but I think it's possible and a good idea for the pypy interpreter.
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 Mon Dec 7 16:22:58 2009
@@ -1,7 +1,7 @@
import py
import sys
from pypy.rpython.extregistry import ExtRegistryEntry
-from pypy.rlib.objectmodel import CDefinedIntSymbolic, we_are_translated
+from pypy.rlib.objectmodel import CDefinedIntSymbolic
from pypy.rlib.objectmodel import keepalive_until_here
from pypy.rlib.unroll import unrolling_iterable
@@ -103,22 +103,30 @@
# VRefs
def virtual_ref(x):
+ """Creates a 'vref' object that contains a reference to 'x'. Calls
+ to virtual_ref/virtual_ref_finish must be properly nested. The idea
+ is that the object 'x' is supposed to be JITted as a virtual (the
+ JIT will abort if it is not), at least between the calls to
+ virtual_ref and virtual_ref_finish. The point is that the 'vref'
+ returned by virtual_ref may escape early. If at runtime it is
+ dereferenced (by calling it, as in 'vref()') before the
+ virtual_ref_finish, then we get out of the assembler. If it is not
+ dereferenced at all, or only after the virtual_ref_finish, then
+ nothing special occurs.
+ """
return DirectVRef(x)
virtual_ref.oopspec = 'virtual_ref(x)'
def virtual_ref_finish(x):
- if not we_are_translated():
- x._forced = x._forced or -1
+ """See docstring in virtual_ref(x). Note that virtual_ref_finish
+ takes as argument the real object, not the vref."""
keepalive_until_here(x) # otherwise the whole function call is removed
virtual_ref_finish.oopspec = 'virtual_ref_finish(x)'
class DirectVRef(object):
- _forced = 0
def __init__(self, x):
self._x = x
def __call__(self):
- assert self._forced >= 0, "too late to force the virtual_ref!"
- self._forced = 1
return self._x
def _freeze_(self):
raise Exception("should not see a prebuilt virtual_ref")
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 Mon Dec 7 16:22:58 2009
@@ -18,20 +18,17 @@
pass
-def test_direct():
+def test_direct_1():
x1 = X()
vref = virtual_ref(x1)
assert vref() is x1
+ virtual_ref_finish(x1)
+ assert vref() is x1
-def test_finish():
- vref = virtual_ref(X())
- virtual_ref_finish(vref)
- py.test.raises(AssertionError, "vref()")
- #
+def test_direct_2():
x1 = X()
vref = virtual_ref(x1)
- assert vref() is x1
- virtual_ref_finish(vref)
+ virtual_ref_finish(x1)
assert vref() is x1
def test_annotate_1():
@@ -45,8 +42,11 @@
def test_annotate_2():
def f():
- vref = virtual_ref(X())
- return vref()
+ x1 = X()
+ vref = virtual_ref(x1)
+ x2 = vref()
+ virtual_ref_finish(x1)
+ return x2
a = RPythonAnnotator()
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeInstance)
@@ -84,8 +84,11 @@
def test_rtype_2():
def f():
- vref = virtual_ref(X())
- return vref()
+ x1 = X()
+ vref = virtual_ref(x1)
+ x2 = vref()
+ virtual_ref_finish(x2)
+ return x2
x = interpret(f, [])
assert lltype.castable(OBJECTPTR, lltype.typeOf(x)) > 0
@@ -107,5 +110,3 @@
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