[pypy-svn] r32067 - in pypy/branch/more-gckinds/pypy: annotation rpython rpython/lltypesystem rpython/lltypesystem/test translator/c
mwh at codespeak.net
mwh at codespeak.net
Thu Sep 7 19:20:40 CEST 2006
Author: mwh
Date: Thu Sep 7 19:20:38 2006
New Revision: 32067
Modified:
pypy/branch/more-gckinds/pypy/annotation/model.py
pypy/branch/more-gckinds/pypy/rpython/annlowlevel.py
pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lltype.py
pypy/branch/more-gckinds/pypy/rpython/lltypesystem/rstr.py
pypy/branch/more-gckinds/pypy/rpython/lltypesystem/test/test_lltype.py
pypy/branch/more-gckinds/pypy/translator/c/funcgen.py
Log:
push lltype.py in one direction a fair bit.
breaks lots and lots of tests, but i want to stop going in this direction for
now...
Modified: pypy/branch/more-gckinds/pypy/annotation/model.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/annotation/model.py (original)
+++ pypy/branch/more-gckinds/pypy/annotation/model.py Thu Sep 7 19:20:38 2006
@@ -515,6 +515,13 @@
def can_be_none(self):
return False
+class SomeInteriorPtr(SomeObject):
+ immutable = True
+ def __init__(self, ll_parentptrtype, field):
+ assert isinstance(ll_ptrtype, lltype.Ptr)
+ self.ll_parentptrtype = ll_parentptrtype
+ self.field = field
+
class SomeLLADTMeth(SomeObject):
immutable = True
def __init__(self, ll_ptrtype, func):
Modified: pypy/branch/more-gckinds/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/annlowlevel.py (original)
+++ pypy/branch/more-gckinds/pypy/rpython/annlowlevel.py Thu Sep 7 19:20:38 2006
@@ -178,7 +178,7 @@
return Constant(p, lltype.typeOf(p))
def graph2delayed(self, graph):
- FUNCTYPE = lltype.FuncForwardReference()
+ FUNCTYPE = lltype.ForwardReference()
# obscure hack: embed the name of the function in the string, so
# that the genc database can get it even before the delayedptr
# is really computed
Modified: pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lltype.py Thu Sep 7 19:20:38 2006
@@ -168,13 +168,14 @@
class Struct(ContainerType):
- _gckind = 'raw'
+ _gckind = 'prebuilt'
def __init__(self, name, *fields, **kwds):
self._name = self.__name__ = name
flds = {}
names = []
self._arrayfld = None
+ firstfield = True
for name, typ in fields:
if name.startswith('_'):
raise NameError, ("%s: field name %r should not start with "
@@ -183,12 +184,19 @@
if name in flds:
raise TypeError("%s: repeated field name" % self._name)
flds[name] = typ
- if isinstance(typ, ContainerType) and typ._gckind != 'raw':
- if name == fields[0][0] and typ._gckind == self._gckind:
+ if isinstance(typ, ContainerType):
+ if firstfield and typ._gckind == self._gckind:
pass # can inline a XxContainer as 1st field of XxStruct
+ elif self._gckind == 'prebuilt' and typ._gckind == 'prebuilt':
+ pass
+ elif typ._gckind == 'raw':
+ 1/0
+ elif typ._gckind == 'gcinterior' and self._gckind in ('gcinterior', 'gc'):
+ pass
else:
raise TypeError("%s: cannot inline %s container %r" % (
self._name, typ._gckind, typ))
+ firstfield = False
# look if we have an inlined variable-sized array as the last field
if fields:
@@ -277,6 +285,12 @@
n = 1
return _struct(self, n, initialization='example')
+class EmbeddedStruct(Struct):
+ _gckind = 'gcinterior'
+
+class RawStruct(Struct):
+ _gckind = 'raw'
+
class RttiStruct(Struct):
_runtime_type_info = None
@@ -316,12 +330,13 @@
raise TypeError("a PyStruct must have another PyStruct or "
"PyObject as first field")
-STRUCT_BY_FLAVOR = {'raw': Struct,
+STRUCT_BY_FLAVOR = {'prebuilt': Struct,
+ 'gcinterior': EmbeddedStruct,
'gc': GcStruct,
'cpy': PyStruct}
class Array(ContainerType):
- _gckind = 'raw'
+ _gckind = 'prebuilt'
__name__ = 'array'
_anonym_struct = False
@@ -329,11 +344,16 @@
if len(fields) == 1 and isinstance(fields[0], LowLevelType):
self.OF = fields[0]
else:
- self.OF = Struct("<arrayitem>", *fields)
+ self.OF = EmbeddedStruct("<arrayitem>", *fields)
self._anonym_struct = True
- if isinstance(self.OF, ContainerType) and self.OF._gckind != 'raw':
- raise TypeError("cannot have a %s container as array item type"
- % (self.OF._gckind,))
+ if isinstance(self.OF, ContainerType):
+ if self._gckind in ('gcinterior', 'gc') and self.OF._gckind == 'gcinterior':
+ pass
+ elif self._gckind == 'prebuilt' and self.OF._gckind == 'prebuilt':
+ pass
+ else:
+ raise TypeError("cannot have a %s container as array item type"
+ % (self.OF._gckind,))
self.OF._inline_is_varsize(False)
self._install_extras(**kwds)
@@ -373,6 +393,9 @@
def _container_example(self):
return _array(self, 1, initialization='example')
+class EmbeddedArray(Array):
+ _gckind = 'gcinterior'
+
class GcArray(Array):
_gckind = 'gc'
def _inline_is_varsize(self, last):
@@ -389,9 +412,14 @@
**kwds)
self.OF = OF
self.length = length
- if isinstance(self.OF, ContainerType) and self.OF._gckind != 'raw':
- raise TypeError("cannot have a %s container as array item type"
- % (self.OF._gckind,))
+ if isinstance(self.OF, ContainerType):
+ if self._gckind in ('gcinterior', 'gc') and self.OF._gckind == 'gcinterior':
+ pass
+ elif self._gckind == 'prebuilt' and self.OF._gckind == 'prebuilt':
+ pass
+ else:
+ raise TypeError("cannot have a %s container as array item type"
+ % (self.OF._gckind,))
self.OF._inline_is_varsize(False)
def _str_fields(self):
@@ -409,6 +437,9 @@
self.OF._short_name(),)
_short_name = saferecursive(_short_name, '...')
+class EmbeddedFixedSizeArray(FixedSizeArray):
+ _gckind = 'gcinterior'
+
class FuncType(ContainerType):
_gckind = 'prebuilt'
@@ -445,7 +476,8 @@
class OpaqueType(ContainerType):
- _gckind = 'raw'
+ _gckind = 'prebuilt' # XXX ?
+ _gckind = 'gcinterior' # XXX ?
def __init__(self, tag):
self.tag = tag
@@ -492,7 +524,7 @@
PyObject = PyObjectType()
class ForwardReference(ContainerType):
- _gckind = 'raw'
+ _gckind = 'prebuilt'
def become(self, realcontainertype):
if not isinstance(realcontainertype, ContainerType):
raise TypeError("ForwardReference can only be to a container, "
@@ -512,12 +544,13 @@
class PyForwardReference(ForwardReference):
_gckind = 'cpy'
-class FuncForwardReference(ForwardReference):
- _gckind = 'prebuilt'
+class EmbeddedForwardReference(ForwardReference):
+ _gckind = 'gcinterior'
-FORWARDREF_BY_FLAVOR = {'raw': ForwardReference,
+FORWARDREF_BY_FLAVOR = {'prebuilt': ForwardReference,
'gc': GcForwardReference,
- 'cpy': PyForwardReference}
+ 'cpy': PyForwardReference,
+ 'gcinterior': EmbeddedForwardReference}
class Primitive(LowLevelType):
@@ -593,7 +626,7 @@
def _needsgc(self):
# XXX deprecated interface
- return self.TO._gckind != 'raw'
+ return self.TO._gckind not in ('gcinterior', 'prebuilt')
def __str__(self):
return '* %s' % (self.TO, )
@@ -602,7 +635,7 @@
return 'Ptr %s' % (self.TO._short_name(), )
def _is_atomic(self):
- return self.TO._gckind == 'raw'
+ return not self.TO._gckind not in ('gcinterior', 'prebuilt')
def _defl(self, parent=None, parentindex=None):
return _ptr(self, None)
@@ -943,8 +976,7 @@
def _setobj(self, pointing_to, solid=False):
if pointing_to is None:
obj0 = None
- elif (solid or self._T._gckind != 'raw' or
- isinstance(self._T, FuncType)):
+ elif (solid or self._T._gckind != 'gcinterior'):
obj0 = pointing_to
else:
self._set_weak(True)
@@ -1589,9 +1621,7 @@
solid = immortal or not flavor.startswith('gc') # immortal or non-gc case
return _ptr(Ptr(T), o, solid)
-def free(p, flavor):
- if flavor.startswith('gc'):
- raise TypeError, "gc flavor free"
+def free(p):
T = typeOf(p)
if not isinstance(T, Ptr) or p._togckind() != 'raw':
raise TypeError, "free(): only for pointers to non-gc containers"
Modified: pypy/branch/more-gckinds/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/lltypesystem/rstr.py (original)
+++ pypy/branch/more-gckinds/pypy/rpython/lltypesystem/rstr.py Thu Sep 7 19:20:38 2006
@@ -10,7 +10,7 @@
AbstractLLHelpers
from pypy.rpython.lltypesystem import ll_str
from pypy.rpython.lltypesystem.lltype import \
- GcStruct, Signed, Array, Char, UniChar, Ptr, malloc, \
+ GcStruct, Signed, EmbeddedArray, Char, UniChar, Ptr, malloc, \
Bool, Void, GcArray, nullptr, pyobjectptr
@@ -24,8 +24,8 @@
# }
STR = GcStruct('rpy_string', ('hash', Signed),
- ('chars', Array(Char, hints={'immutable': True,
- 'isrpystring': True})))
+ ('chars', EmbeddedArray(Char, hints={'immutable': True,
+ 'isrpystring': True})))
SIGNED_ARRAY = GcArray(Signed)
CONST_STR_CACHE = WeakValueDictionary()
Modified: pypy/branch/more-gckinds/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/lltypesystem/test/test_lltype.py (original)
+++ pypy/branch/more-gckinds/pypy/rpython/lltypesystem/test/test_lltype.py Thu Sep 7 19:20:38 2006
@@ -82,14 +82,14 @@
assert iwitem(l, 1).v == 3
# not allowed
- S = Struct("s", ('v', Signed))
+ S = EmbeddedStruct("s", ('v', Signed))
List_typ, iwnewlistzzz, iwappendzzz, iwitemzzz = define_list(S) # works but
l = iwnewlistzzz()
S1 = GcStruct("strange", ('s', S))
py.test.raises(TypeError, "iwappendzzz(l, malloc(S1).s)")
def test_varsizestruct():
- S1 = GcStruct("s1", ('a', Signed), ('rest', Array(('v', Signed))))
+ S1 = GcStruct("s1", ('a', Signed), ('rest', EmbeddedArray(('v', Signed))))
py.test.raises(TypeError, "malloc(S1)")
s1 = malloc(S1, 4)
s1.a = 0
@@ -114,8 +114,8 @@
py.test.raises(TypeError, "Struct('invalid', ('x', S1))")
def test_substructure_ptr():
- S3 = Struct("s3", ('a', Signed))
- S2 = Struct("s2", ('s3', S3))
+ S3 = EmbeddedStruct("s3", ('a', Signed))
+ S2 = EmbeddedStruct("s2", ('s3', S3))
S1 = GcStruct("s1", ('sub1', S2), ('sub2', S2))
p1 = malloc(S1)
assert isweak(p1.sub1, S2)
@@ -126,7 +126,7 @@
def test_gc_substructure_ptr():
S1 = GcStruct("s2", ('a', Signed))
- S2 = Struct("s3", ('a', Signed))
+ S2 = EmbeddedStruct("s3", ('a', Signed))
S0 = GcStruct("s1", ('sub1', S1), ('sub2', S2))
p1 = malloc(S0)
assert typeOf(p1.sub1) == Ptr(S1)
@@ -202,8 +202,8 @@
py.test.raises(RuntimeError, "cast_pointer(Ptr(S1), p3)")
def test_best_effort_gced_parent_detection():
- S2 = Struct("s2", ('a', Signed))
- S1 = GcStruct("s1", ('sub1', S2), ('sub2', S2), ('tail', Array(('e', Signed))))
+ S2 = EmbeddedStruct("s2", ('a', Signed))
+ S1 = GcStruct("s1", ('sub1', S2), ('sub2', S2), ('tail', EmbeddedArray(('e', Signed))))
p1 = malloc(S1, 1)
p2 = p1.sub2
p3 = p1.tail
@@ -229,7 +229,7 @@
def test_examples():
A1 = GcArray(('v', Signed))
S = GcStruct("s", ('v', Signed))
- St = GcStruct("st", ('v', Signed),('trail', Array(('v', Signed))))
+ St = GcStruct("st", ('v', Signed),('trail', EmbeddedArray(('v', Signed))))
PA1 = Ptr(A1)
PS = Ptr(S)
@@ -263,6 +263,7 @@
assert Void not in F._trueargs()
def test_inconsistent_gc_containers():
+ # XXX write more here!
A = GcArray(('y', Signed))
S = GcStruct('b', ('y', Signed))
py.test.raises(TypeError, "Struct('a', ('x', S))")
@@ -333,12 +334,12 @@
S = GcStruct('s', ('x', Signed))
py.test.raises(TypeError, "Array(S)")
py.test.raises(TypeError, "Array(As)")
- S = Struct('s', ('x', Signed))
+ S = EmbeddedStruct('s', ('x', Signed))
A = GcArray(S)
a = malloc(A, 2)
s = S._container_example() # should not happen anyway
py.test.raises(TypeError, "a[0] = s")
- S = Struct('s', ('last', Array(S)))
+ S = EmbeddedStruct('s', ('last', EmbeddedArray(S)))
py.test.raises(TypeError, "Array(S)")
def test_immortal_parent():
@@ -422,14 +423,13 @@
assert runtime_type_info(s1.sub) == getRuntimeTypeInfo(S1)
def test_flavor_malloc():
- S = Struct('s', ('x', Signed))
- py.test.raises(TypeError, malloc, S)
- p = malloc(S, flavor="raw")
+ S = RawStruct('s', ('x', Signed))
+ p = malloc(S, flavor='raw')
assert typeOf(p).TO == S
assert not isweak(p, S)
- free(p, flavor="raw")
+ free(p)
T = GcStruct('T', ('y', Signed))
- p = malloc(T, flavor="gc")
+ p = malloc(T)
assert typeOf(p).TO == T
assert not isweak(p, T)
Modified: pypy/branch/more-gckinds/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/translator/c/funcgen.py (original)
+++ pypy/branch/more-gckinds/pypy/translator/c/funcgen.py Thu Sep 7 19:20:38 2006
@@ -10,7 +10,7 @@
from pypy.rpython.lltypesystem.lltype import UnsignedLongLong, Char, UniChar
from pypy.rpython.lltypesystem.lltype import pyobjectptr, ContainerType
from pypy.rpython.lltypesystem.lltype import Struct, Array, FixedSizeArray
-from pypy.rpython.lltypesystem.lltype import FuncForwardReference
+from pypy.rpython.lltypesystem.lltype import ForwardReference
from pypy.rpython.lltypesystem.llmemory import Address, WeakGcAddress
from pypy.translator.backendopt.ssa import SSI_to_SSA
@@ -58,7 +58,7 @@
T = getattr(v, 'concretetype', PyObjPtr)
# obscure: skip forward references and hope for the best
# (needed for delayed function pointers)
- if isinstance(T, Ptr) and T.TO.__class__ == FuncForwardReference:
+ if isinstance(T, Ptr) and T.TO.__class__ == ForwardReference:
continue
db.gettype(T) # force the type to be considered by the database
More information about the Pypy-commit
mailing list