[pypy-svn] r68680 - in pypy/branch/warmspot-jitinfo/pypy/rpython/lltypesystem: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Oct 21 14:45:33 CEST 2009
Author: arigo
Date: Wed Oct 21 14:45:32 2009
New Revision: 68680
Modified:
pypy/branch/warmspot-jitinfo/pypy/rpython/lltypesystem/opimpl.py
pypy/branch/warmspot-jitinfo/pypy/rpython/lltypesystem/test/test_lloperation.py
Log:
Add a test, and a missing case.
Modified: pypy/branch/warmspot-jitinfo/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/warmspot-jitinfo/pypy/rpython/lltypesystem/opimpl.py (original)
+++ pypy/branch/warmspot-jitinfo/pypy/rpython/lltypesystem/opimpl.py Wed Oct 21 14:45:32 2009
@@ -142,7 +142,12 @@
# we can constant-fold this if the innermost structure from which we
# read the final field is immutable.
T = lltype.typeOf(innermostcontainer).TO
- if not T._hints.get('immutable'):
+ if T._hints.get('immutable'):
+ pass
+ elif ('immutable_fields' in T._hints and
+ offsets[-1] in T._hints['immutable_fields'].fields):
+ pass
+ else:
raise TypeError("cannot fold getinteriorfield on mutable struct")
assert not isinstance(ob, lltype._interior_ptr)
return ob
Modified: pypy/branch/warmspot-jitinfo/pypy/rpython/lltypesystem/test/test_lloperation.py
==============================================================================
--- pypy/branch/warmspot-jitinfo/pypy/rpython/lltypesystem/test/test_lloperation.py (original)
+++ pypy/branch/warmspot-jitinfo/pypy/rpython/lltypesystem/test/test_lloperation.py Wed Oct 21 14:45:32 2009
@@ -96,6 +96,27 @@
assert llop.getfield.is_pure([v_s3, Constant('x')])
assert not llop.getfield.is_pure([v_s3, Constant('y')])
+def test_getfield_pure():
+ S1 = lltype.GcStruct('S', ('x', lltype.Signed), ('y', lltype.Signed))
+ S2 = lltype.GcStruct('S', ('x', lltype.Signed), ('y', lltype.Signed),
+ hints={'immutable': True})
+ accessor = rclass.FieldListAccessor()
+ S3 = lltype.GcStruct('S', ('x', lltype.Signed), ('y', lltype.Signed),
+ hints={'immutable_fields': accessor})
+ accessor.initialize(S3, ['x'])
+ #
+ s1 = lltype.malloc(S1); s1.x = 45
+ py.test.raises(TypeError, llop.getfield, lltype.Signed, s1, 'x')
+ s2 = lltype.malloc(S2); s2.x = 45
+ assert llop.getfield(lltype.Signed, s2, 'x') == 45
+ s3 = lltype.malloc(S3); s3.x = 46; s3.y = 47
+ assert llop.getfield(lltype.Signed, s3, 'x') == 46
+ py.test.raises(TypeError, llop.getfield, lltype.Signed, s3, 'y')
+ #
+ py.test.raises(TypeError, llop.getinteriorfield, lltype.Signed, s1, 'x')
+ assert llop.getinteriorfield(lltype.Signed, s2, 'x') == 45
+ assert llop.getinteriorfield(lltype.Signed, s3, 'x') == 46
+ py.test.raises(TypeError, llop.getinteriorfield, lltype.Signed, s3, 'y')
# ___________________________________________________________________________
# This tests that the LLInterpreter and the LL_OPERATIONS tables are in sync.
More information about the Pypy-commit
mailing list