[pypy-svn] r76840 - in pypy/branch/no-_immutable_/pypy/rpython: . lltypesystem lltypesystem/test
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 2 16:37:17 CEST 2010
Author: arigo
Date: Thu Sep 2 16:37:16 2010
New Revision: 76840
Modified:
pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py
pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/test/test_lloperation.py
pypy/branch/no-_immutable_/pypy/rpython/rclass.py
Log:
Fixes.
Modified: pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lloperation.py Thu Sep 2 16:37:16 2010
@@ -85,17 +85,20 @@
fold = roproperty(get_fold_impl)
def is_pure(self, args_v):
- return (
- self.canfold or # canfold => pure operation
- self is llop.debug_assert or # debug_assert is pure enough
- # reading from immutable (lltype)
- (self in (llop.getfield, llop.getarrayitem) and
- isinstance(args_v[1], Constant) and
- args_v[0].concretetype.TO._immutable_field(args_v[1].value)) or
- # reading from immutable (ootype) (xxx what about arrays?)
- (self is llop.oogetfield and
- isinstance(args_v[1], Constant) and
- args_v[0].concretetype._immutable_field(args_v[1].value)))
+ if self.canfold: # canfold => pure operation
+ return True
+ if self is llop.debug_assert: # debug_assert is pure enough
+ return True
+ # reading from immutable (lltype)
+ if self is llop.getfield or self is llop.getarrayitem:
+ field = getattr(args_v[1], 'value', None)
+ return args_v[0].concretetype.TO._immutable_field(field)
+ # reading from immutable (ootype) (xxx what about arrays?)
+ if self is llop.oogetfield:
+ field = getattr(args_v[1], 'value', None)
+ return args_v[0].concretetype._immutable_field(field)
+ # default
+ return False
def __repr__(self):
return '<LLOp %s>' % (getattr(self, 'opname', '?'),)
Modified: pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py Thu Sep 2 16:37:16 2010
@@ -400,7 +400,7 @@
def _container_example(self):
return _array(self, 1, initialization='example')
- def _immutable_field(self, index):
+ def _immutable_field(self, index=None):
return self._hints.get('immutable', False)
class GcArray(Array):
Modified: pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/test/test_lloperation.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/test/test_lloperation.py (original)
+++ pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/test/test_lloperation.py Thu Sep 2 16:37:16 2010
@@ -88,7 +88,7 @@
accessor = rclass.FieldListAccessor()
S3 = lltype.GcStruct('S', ('x', lltype.Signed), ('y', lltype.Signed),
hints={'immutable_fields': accessor})
- accessor.initialize(S3, ['x'])
+ accessor.initialize(S3, {'x': ''})
v_s3 = Variable()
v_s3.concretetype = lltype.Ptr(S3)
assert not llop.setfield.is_pure([v_s3, Constant('x'), Variable()])
@@ -103,7 +103,7 @@
accessor = rclass.FieldListAccessor()
S3 = lltype.GcStruct('S', ('x', lltype.Signed), ('y', lltype.Signed),
hints={'immutable_fields': accessor})
- accessor.initialize(S3, ['x'])
+ accessor.initialize(S3, {'x': ''})
#
s1 = lltype.malloc(S1); s1.x = 45
py.test.raises(TypeError, llop.getfield, lltype.Signed, s1, 'x')
Modified: pypy/branch/no-_immutable_/pypy/rpython/rclass.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/rpython/rclass.py (original)
+++ pypy/branch/no-_immutable_/pypy/rpython/rclass.py Thu Sep 2 16:37:16 2010
@@ -9,6 +9,7 @@
class FieldListAccessor(object):
def initialize(self, TYPE, fields):
+ assert type(fields) is dict
self.TYPE = TYPE
self.fields = fields
More information about the Pypy-commit
mailing list