[pypy-svn] r12197 - in pypy/dist/pypy: annotation annotation/test rpython rpython/test translator/genc translator/genc/test
pedronis at codespeak.net
pedronis at codespeak.net
Wed May 11 19:33:47 CEST 2005
Author: pedronis
Date: Wed May 11 19:33:47 2005
New Revision: 12197
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/model.py
pypy/dist/pypy/annotation/test/test_model.py
pypy/dist/pypy/annotation/unaryop.py
pypy/dist/pypy/rpython/lltypes.py
pypy/dist/pypy/rpython/test/test_llann.py
pypy/dist/pypy/translator/genc/ctyper.py
pypy/dist/pypy/translator/genc/test/test_lltyped.py
Log:
some more annotation support for lltypes; tests; removed debug view graph from test_lltyped.py
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Wed May 11 19:33:47 2005
@@ -454,19 +454,31 @@
# annotation of low-level types
from pypy.rpython import lltypes
-from pypy.annotation.model import SomePtr
+from pypy.annotation.model import SomePtr, ll_to_annotation
-class __extend__(SomePtr, SomePtr):
+class __extend__(pairtype(SomePtr, SomePtr)):
def union((p1, p2)):
- assert p1.ll_ptrtype == p2.ll_prttype,("mixing of incompatible pointer types: %r, %r" %
- (p1.ll_prttype, p2.ll_prttype))
+ assert p1.ll_ptrtype == p2.ll_ptrtype,("mixing of incompatible pointer types: %r, %r" %
+ (p1.ll_ptrtype, p2.ll_ptrtype))
return SomePtr(p1.ll_ptrtype)
-class __extend__(SomePtr, SomeObject):
- def union((p1, obj)):
- assert False, ("mixing pointer type %r with something else %r" % (p1.ll_ptrtype, obj))
+class __extend__(pairtype(SomePtr, SomeInteger)):
-class __extend__(SomeObject, SomePtr):
+ def getitem((p, int1)):
+ v = p.ll_ptrtype._example()[0]
+ return ll_to_annotation(v)
+
+class __extend__(pairtype(SomePtr, SomeObject)):
+ def union((p, obj)):
+ assert False, ("mixing pointer type %r with something else %r" % (p.ll_ptrtype, obj))
+
+ def gettitem((p, obj)):
+ assert False,"ptr %r getitem index not an int: %r" % (p.ll_ptrtype, obj)
+
+ def settitem((p, obj)):
+ assert False,"ptr setitem is not a valid operation"
+
+class __extend__(pairtype(SomeObject, SomePtr)):
def union((obj, p2)):
return pair(p2, obj).union()
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Wed May 11 19:33:47 2005
@@ -274,6 +274,37 @@
def __init__(self, ll_ptrtype):
self.ll_ptrtype = ll_ptrtype
+from pypy.rpython import lltypes
+
+annotation_to_ll_map = [
+ (SomeBool(), lltypes.Bool),
+ (SomeInteger(), lltypes.Signed),
+ (SomeInteger(nonneg=True, unsigned=True), lltypes.Unsigned),
+ (SomeChar(), lltypes.Char),
+]
+
+def annotation_to_lltype(s_val):
+ if isinstance(s_val, SomePtr):
+ return s_val.ll_ptrtype
+ for witness, lltype in annotation_to_ll_map:
+ if witness.contains(s_val):
+ return lltype
+ raise AssertionError("trying find a matching low-level type for unexpected"
+ "%r" % s_val)
+
+ll_to_annotation_map = dict([(ll, ann) for ann,ll in annotation_to_ll_map])
+
+def ll_to_annotation(v):
+ if v is None:
+ assert False, "cannot retrieve Void low-level type value"
+ typ = lltypes.typeOf(v)
+ s = ll_to_annotation_map.get(typ)
+ if s is None:
+ return SomePtr(typ)
+ else:
+ return s
+
+
# ____________________________________________________________
def unionof(*somevalues):
Modified: pypy/dist/pypy/annotation/test/test_model.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_model.py (original)
+++ pypy/dist/pypy/annotation/test/test_model.py Wed May 11 19:33:47 2005
@@ -1,5 +1,6 @@
import autopath
+import py
from pypy.annotation.model import *
from pypy.annotation.listdef import ListDef, MOST_GENERAL_LISTDEF
@@ -101,7 +102,72 @@
assert not s1.contains(s2)
assert s1 != s2
+def test_ll_to_annotation():
+ s_z = ll_to_annotation(lltypes.Signed._defl())
+ s_s = SomeInteger()
+ s_u = SomeInteger(nonneg=True, unsigned=True)
+ assert s_z.contains(s_s)
+ assert not s_z.contains(s_u)
+ s_uz = ll_to_annotation(lltypes.Unsigned._defl())
+ assert s_uz.contains(s_u)
+ assert ll_to_annotation(lltypes.Bool._defl()).contains(SomeBool())
+ assert ll_to_annotation(lltypes.Char._defl()).contains(SomeChar())
+ S = lltypes.Struct('s')
+ A = lltypes.Array()
+ s_p = ll_to_annotation(lltypes.malloc(S))
+ assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltypes.GcPtr(S)
+ s_p = ll_to_annotation(lltypes.malloc(A, 0))
+ assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltypes.GcPtr(A)
+
+def test_annotation_to_lltype():
+ from pypy.rpython.rarithmetic import r_uint
+ s_i = SomeInteger()
+ s_pos = SomeInteger(nonneg=True)
+ s_1 = SomeInteger(nonneg=True); s_1.const = 1
+ s_m1 = SomeInteger(nonneg=False); s_m1.const = -1
+ s_u = SomeInteger(nonneg=True, unsigned=True);
+ s_u1 = SomeInteger(nonneg=True, unsigned=True);
+ s_u1.const = r_uint(1)
+ assert annotation_to_lltype(s_i) == lltypes.Signed
+ assert annotation_to_lltype(s_pos) == lltypes.Signed
+ assert annotation_to_lltype(s_1) == lltypes.Signed
+ assert annotation_to_lltype(s_m1) == lltypes.Signed
+ assert annotation_to_lltype(s_u) == lltypes.Unsigned
+ assert annotation_to_lltype(s_u1) == lltypes.Unsigned
+ assert annotation_to_lltype(SomeBool()) == lltypes.Bool
+ assert annotation_to_lltype(SomeChar()) == lltypes.Char
+ PS = lltypes.GcPtr(lltypes.Struct('s'))
+ s_p = SomePtr(ll_ptrtype=PS)
+ assert annotation_to_lltype(s_p) == PS
+ py.test.raises(AssertionError, "annotation_to_lltype(si0)")
+
+def test_ll_union():
+ PS1 = lltypes.GcPtr(lltypes.Struct('s'))
+ PS2 = lltypes.GcPtr(lltypes.Struct('s'))
+ PS3 = lltypes.GcPtr(lltypes.Struct('s3'))
+ PA1 = lltypes.GcPtr(lltypes.Array())
+ PA2 = lltypes.GcPtr(lltypes.Array())
+
+ assert unionof(SomePtr(PS1),SomePtr(PS1)) == SomePtr(PS1)
+ assert unionof(SomePtr(PS1),SomePtr(PS2)) == SomePtr(PS2)
+ assert unionof(SomePtr(PS1),SomePtr(PS2)) == SomePtr(PS1)
+
+ assert unionof(SomePtr(PA1),SomePtr(PA1)) == SomePtr(PA1)
+ assert unionof(SomePtr(PA1),SomePtr(PA2)) == SomePtr(PA2)
+ assert unionof(SomePtr(PA1),SomePtr(PA2)) == SomePtr(PA1)
+
+ assert unionof(SomePtr(PS1),SomeImpossibleValue()) == SomePtr(PS1)
+ assert unionof(SomeImpossibleValue(), SomePtr(PS1)) == SomePtr(PS1)
+
+ py.test.raises(AssertionError, "unionof(SomePtr(PA1), SomePtr(PS1))")
+ py.test.raises(AssertionError, "unionof(SomePtr(PS1), SomePtr(PS3))")
+ py.test.raises(AssertionError, "unionof(SomePtr(PS1), SomeInteger())")
+ py.test.raises(AssertionError, "unionof(SomePtr(PS1), SomeObject())")
+ py.test.raises(AssertionError, "unionof(SomeInteger(), SomePtr(PS1))")
+ py.test.raises(AssertionError, "unionof(SomeObject(), SomePtr(PS1))")
+
if __name__ == '__main__':
for name, value in globals().items():
if name.startswith('test_'):
value()
+
Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py (original)
+++ pypy/dist/pypy/annotation/unaryop.py Wed May 11 19:33:47 2005
@@ -426,25 +426,7 @@
# annotation of low-level types
from pypy.rpython import lltypes
-from pypy.annotation.model import SomePtr
-
-ll_to_annotation_map = {
- lltypes.Signed: SomeInteger(),
- lltypes.Unsigned: SomeInteger(nonneg=True, unsigned=True),
- lltypes.Char: SomeChar(),
- lltypes.Bool: SomeBool(),
-}
-
-def ll_to_annotation(v):
- if v is None:
- assert False, "cannot retrieve Void low-level type value"
- typ = lltypes.typeOf(v)
- s = ll_to_annotation_map.get(typ)
- if s is None:
- return SomePtr(typ)
- else:
- return s
-
+from pypy.annotation.model import SomePtr, ll_to_annotation, annotation_to_lltype
class __extend__(SomePtr):
def getattr(p, s_attr):
@@ -452,3 +434,8 @@
v = getattr(p.ll_ptrtype._example(), s_attr.const)
return ll_to_annotation(v)
+ def setattr(p, s_attr, s_value): # just doing checking
+ assert s_attr.is_constant(), "getattr on ptr %r with non-constant field-name" % p.ll_ptrtype
+ v_lltype = annotation_to_lltype(s_value)
+ setattr(p.ll_ptrtype._example(), s_attr.const,
+ v_lltype._example())
Modified: pypy/dist/pypy/rpython/lltypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypes.py (original)
+++ pypy/dist/pypy/rpython/lltypes.py Wed May 11 19:33:47 2005
@@ -80,7 +80,7 @@
def _defl(self, parent=None):
return _struct(self, parent=parent)
- def _example(self):
+ def _container_example(self):
if self._arrayfld is None:
n = None
else:
@@ -96,7 +96,7 @@
def __str__(self):
return "Array of { %s }" % (self.OF._str_fields(),)
- def _example(self):
+ def _container_example(self):
return _array(self, 1)
@@ -110,6 +110,8 @@
def _defl(self, parent=None):
return self._default
+
+ _example = _defl
Signed = Primitive("Signed", 0)
@@ -144,7 +146,7 @@
return _ptr(self, None)
def _example(self):
- o = self.TO._example()
+ o = self.TO._container_example()
return _ptr(self, o)
Modified: pypy/dist/pypy/rpython/test/test_llann.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llann.py (original)
+++ pypy/dist/pypy/rpython/test/test_llann.py Wed May 11 19:33:47 2005
@@ -24,3 +24,13 @@
a = self.RPythonAnnotator()
s = a.build_types(llf, [])
assert s.knowntype == int
+
+ def test_array(self):
+ A = Array(('v', Signed))
+ def llf():
+ a = malloc(A, 1)
+ return a[0].v
+ a = self.RPythonAnnotator()
+ s = a.build_types(llf, [])
+ assert s.knowntype == int
+
Modified: pypy/dist/pypy/translator/genc/ctyper.py
==============================================================================
--- pypy/dist/pypy/translator/genc/ctyper.py (original)
+++ pypy/dist/pypy/translator/genc/ctyper.py Wed May 11 19:33:47 2005
@@ -83,6 +83,11 @@
)
def annotation2concretetype(self, s_value):
+ if isinstance(s_value, SomePtr): # XXX moved here to avoid contains failures
+ besttype = self.annotator.translator.getconcretetype(
+ CPtrType, s_value.ll_ptrtype)
+ return besttype
+
besttype = Specializer.annotation2concretetype(self, s_value)
if besttype == self.defaultconcretetype:
@@ -119,9 +124,6 @@
# besttype = self.annotator.translator.getconcretetype(
# CListType, item_ct)
- elif isinstance(s_value, SomePtr):
- besttype = self.annotator.translator.getconcretetype(
- CPtrType, s_value.ll_ptrtype)
return besttype
Modified: pypy/dist/pypy/translator/genc/test/test_lltyped.py
==============================================================================
--- pypy/dist/pypy/translator/genc/test/test_lltyped.py (original)
+++ pypy/dist/pypy/translator/genc/test/test_lltyped.py Wed May 11 19:33:47 2005
@@ -14,7 +14,7 @@
a.simplify()
GenCSpecializer(a).specialize()
t.checkgraphs()
- t.view()
+ #t.view()
return skip_missing_compiler(t.ccompile)
def test_simple(self):
More information about the Pypy-commit
mailing list