[pypy-svn] r17063 - in pypy/dist/pypy/rpython: . test
ericvrp at codespeak.net
ericvrp at codespeak.net
Mon Aug 29 20:32:45 CEST 2005
Author: ericvrp
Date: Mon Aug 29 20:32:44 2005
New Revision: 17063
Modified:
pypy/dist/pypy/rpython/lltype.py
pypy/dist/pypy/rpython/test/test_lltype.py
Log:
* Added _is_atomic method (+test) so backends can know if a Struct/Array/
Primitive/Ptr/etc (incl. children) contains pointers.
If they do not contain pointers (i.e. are atomic) then the gc can
do a less time consuming job on it.
Modified: pypy/dist/pypy/rpython/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltype.py (original)
+++ pypy/dist/pypy/rpython/lltype.py Mon Aug 29 20:32:44 2005
@@ -79,6 +79,9 @@
def _inline_is_varsize(self, last):
return False
+ def _is_atomic(self):
+ return False
+
class ContainerType(LowLevelType):
def _gcstatus(self):
@@ -87,6 +90,7 @@
def _inline_is_varsize(self, last):
raise TypeError, "%r cannot be inlined in structure" % self
+
class Struct(ContainerType):
def __init__(self, name, *fields):
self._name = self.__name__ = name
@@ -133,6 +137,12 @@
"inside another container")
return False
+ def _is_atomic(self):
+ for typ in self._flds.values():
+ if not typ._is_atomic():
+ return False
+ return True
+
def __getattr__(self, name):
try:
return self._flds[name]
@@ -140,15 +150,8 @@
raise AttributeError, 'struct %s has no field %r' % (self._name,
name)
-
-
-
- def _names_without_voids(self, at_root=True):
- #if at_root: #XXX debug stuff
- # log('_names_without_voids: ' + self._str_without_voids())
+ def _names_without_voids(self):
names_without_voids = [name for name in self._names if self._flds[name] is not Void]
- #if names_without_voids != list(self._names):
- # log('_names_without_voids: removed Void(s) _names=%s, return=%s' % (str(list(self._names)), str(names_without_voids)))
return names_without_voids
def _str_fields_without_voids(self):
@@ -160,9 +163,6 @@
return "%s %s { %s }" % (self.__class__.__name__,
self._name, self._str_fields_without_voids())
-
-
-
def _str_fields(self):
return ', '.join(['%s: %s' % (name, self._flds[name])
for name in self._names])
@@ -219,6 +219,9 @@
" unless as the last field of a structure")
return True
+ def _is_atomic(self):
+ return self.OF._is_atomic()
+
def _str_fields(self):
if isinstance(self.OF, Struct):
of = self.OF
@@ -324,7 +327,10 @@
def _defl(self, parent=None, parentindex=None):
return self._default
-
+
+ def _is_atomic(self):
+ return True
+
_example = _defl
Modified: pypy/dist/pypy/rpython/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_lltype.py (original)
+++ pypy/dist/pypy/rpython/test/test_lltype.py Mon Aug 29 20:32:44 2005
@@ -407,3 +407,17 @@
assert typeOf(p2) == Ptr(S)
assert typeOf(p2.stuff) == Ptr(O)
assert parentlink(p2.stuff._obj) == (p2._obj, 'stuff')
+
+def test_is_atomic():
+ U = Struct('inlined', ('z', Signed))
+ P = Ptr(RuntimeTypeInfo)
+ Q = GcStruct('q', ('i', Signed), ('u', U), ('p', P))
+ O = OpaqueType('O')
+ F = GcForwardReference()
+ assert P._is_atomic() is False
+ assert Q.i._is_atomic() is True
+ assert Q.u._is_atomic() is True
+ assert Q.p._is_atomic() is False
+ assert Q._is_atomic() is False
+ assert O._is_atomic() is False
+ assert F._is_atomic() is False
More information about the Pypy-commit
mailing list