Author: Maciej Fijalkowski <[email protected]>
Branch: vref-copy
Changeset: r56733:cb06fc43bfdc
Date: 2012-08-16 12:56 +0200
http://bitbucket.org/pypy/pypy/changeset/cb06fc43bfdc/
Log: hack differently - explicit getfield on vrefs (that does not
necesarilly force them)
diff --git a/pypy/rlib/_jit_vref.py b/pypy/rlib/_jit_vref.py
--- a/pypy/rlib/_jit_vref.py
+++ b/pypy/rlib/_jit_vref.py
@@ -28,10 +28,10 @@
def getattr(self, s_attr):
if s_attr.const == 'virtual':
return annmodel.s_Bool
- elif s_attr.const == 'dereference_or_copy':
- return self.s_instance
- else:
- raise AssertionError("Unknown attribute %s" % s_attr.const)
+ return annmodel.SomeObject.getattr(self, s_attr)
+
+ def method_getfield(self, s_name):
+ return self.s_instance.getattr(s_name)
def rtyper_makerepr(self, rtyper):
if rtyper.type_system.name == 'lltypesystem':
@@ -75,13 +75,17 @@
v = hop.inputarg(self, arg=0)
if s_attr.const == 'virtual':
return hop.genop('jit_is_virtual', [v], resulttype = lltype.Bool)
- elif s_attr.const == 'dereference_or_copy':
- v_result = hop.genop('jit_dereference_or_copy', [v],
- resulttype = OBJECTPTR)
- return hop.genop('cast_pointer', [v_result],
- resulttype = hop.r_result)
- else:
- raise AssertionError("Unknown attribute %s" % s_attr.const)
+ return Repr.rtype_getattr(self, hop)
+
+ def rtype_method_getfield(self, hop):
+ attr = hop.args_s[1].const
+ hop.exception_cannot_occur()
+ v = hop.inputarg(self, arg=0)
+ c_name = hop.inputconst(lltype.Void, attr)
+ r_arg = hop.rtyper.getrepr(hop.args_s[0].s_instance)
+ v2 = hop.genop('cast_pointer', [v], resulttype=r_arg)
+ return hop.genop('jit_vref_getfield', [v2, c_name],
+ resulttype = hop.r_result)
from pypy.rpython.ootypesystem.rclass import OBJECT
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -352,16 +352,12 @@
be forced by the '()' operator."""
return self._state == 'non-forced'
- @property
- def dereference_or_copy(self):
- """ Get a forced version, but without forcing the original virtual.
- Useful for things like profilers where we want the object, but
- we don't care if modifications will be reflected in the underlaying
- JIT code.
+ def getfield(self, fieldname):
+ """ Get a field, either by reading a field directly if the reference
+ is not virtual at all, or will fish it from the resume data. If
+ the field is itself virtual, you'll receive a null pointer.
"""
- # note that this always returns the original object and never
- # a copy when untranslated
- return self._x
+ return getattr(self._x, fieldname)
def _finish(self):
if self._state == 'non-forced':
diff --git a/pypy/rlib/test/test__jit_vref.py b/pypy/rlib/test/test__jit_vref.py
--- a/pypy/rlib/test/test__jit_vref.py
+++ b/pypy/rlib/test/test__jit_vref.py
@@ -145,12 +145,16 @@
x = self.interpret(f, [])
assert x is False
- def test_rtype_dereference_or_copy(self):
+ def test_rtype_getfield(self):
+ class X(object):
+ def __init__(self, x):
+ self.x = x
+
def f():
- vref = virtual_ref(X())
- return vref.dereference_or_copy.x
+ vref = virtual_ref(X(1))
+ return vref.getfield('x')
x = self.interpret(f, [])
- assert x == 3
+ assert x == 1
class TestLLtype(BaseTestVRef, LLRtypeMixin):
OBJECTTYPE = OBJECTPTR
@@ -162,5 +166,5 @@
def castable(self, TO, var):
return ootype.isSubclass(lltype.typeOf(var), TO)
- def test_rtype_dereference_or_copy(self):
+ def test_rtype_getfield(self):
py.test.skip("not supported")
diff --git a/pypy/rpython/lltypesystem/lloperation.py
b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -432,9 +432,9 @@
'jit_force_virtualizable':LLOp(canrun=True),
'jit_force_virtual': LLOp(canrun=True),
'jit_is_virtual': LLOp(canrun=True),
- 'jit_dereference_or_copy': LLOp(canrun=True),
'jit_force_quasi_immutable': LLOp(canrun=True),
'jit_record_known_class' : LLOp(canrun=True),
+ 'jit_vref_getfield' : LLOp(canrun=True),
'get_exception_addr': LLOp(),
'get_exc_value_addr': LLOp(),
'do_malloc_fixedsize_clear':LLOp(canmallocgc=True),
diff --git a/pypy/rpython/lltypesystem/opimpl.py
b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -557,12 +557,12 @@
def op_jit_force_virtual(x):
return x
+def op_jit_vref_getfield(x, field):
+ return getattr(x, 'inst_' + field)
+
def op_jit_is_virtual(x):
return False
-def op_jit_dereference_or_copy(x):
- return x
-
def op_jit_force_quasi_immutable(*args):
pass
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit