[pypy-svn] r13344 - in pypy/dist/pypy: annotation rpython/test
pedronis at codespeak.net
pedronis at codespeak.net
Mon Jun 13 14:31:13 CEST 2005
Author: pedronis
Date: Mon Jun 13 14:31:08 2005
New Revision: 13344
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/rpython/test/test_llann.py
Log:
annotation for cast_pointer (given that null pointers are accepted is slightly saner),
refactored a bit the code in test_llann
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Mon Jun 13 14:31:08 2005
@@ -319,8 +319,16 @@
r.const = p
return r
+def cast_pointer(PtrT, s_p):
+ assert isinstance(s_p, SomePtr), "casting of non-pointer: %r" % s_p
+ assert PtrT.is_constant()
+ cast_p = lltype.cast_pointer(PtrT.const, s_p.ll_ptrtype._defl())
+ return SomePtr(ll_ptrtype=lltype.typeOf(cast_p))
+
+
BUILTIN_ANALYZERS[lltype.malloc] = malloc
BUILTIN_ANALYZERS[lltype.cast_parent] = cast_parent
BUILTIN_ANALYZERS[lltype.typeOf] = typeOf
BUILTIN_ANALYZERS[lltype.nullptr] = nullptr
+BUILTIN_ANALYZERS[lltype.cast_pointer] = cast_pointer
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 Mon Jun 13 14:31:08 2005
@@ -2,6 +2,20 @@
from pypy.annotation import model as annmodel
from pypy.rpython.annlowlevel import annotate_lowlevel_helper
+# helpers
+
+def annotated_calls(ann, ops=('simple_call,')):
+ for block in ann.annotated:
+ for op in block.operations:
+ if op.opname in ops:
+ yield op
+
+def derived(op, orig):
+ if op.args[0].value.__name__.startswith(orig):
+ return op.args[0].value
+ else:
+ return None
+
class TestLowLevelAnnotateTestCase:
objspacename = 'flow'
@@ -82,6 +96,38 @@
assert isinstance(s, annmodel.SomePtr)
assert s.ll_ptrtype == PS1
+ def test_cast_pointer(self):
+ S3 = GcStruct("s3", ('a', Signed))
+ S2 = GcStruct("s3", ('sub', S3))
+ S1 = GcStruct("s1", ('sub', S2))
+ PS1 = Ptr(S1)
+ PS2 = Ptr(S2)
+ PS3 = Ptr(S3)
+ def llwitness(p12, p13, p21, p23, p31, p32):
+ pass
+ def llf():
+ p1 = malloc(S1)
+ p2 = p1.sub
+ p3 = p2.sub
+ p12 = cast_pointer(PS1, p2)
+ p13 = cast_pointer(PS1, p3)
+ p21 = cast_pointer(PS2, p1)
+ p23 = cast_pointer(PS2, p3)
+ p31 = cast_pointer(PS3, p1)
+ p32 = cast_pointer(PS3, p2)
+ llwitness(p12, p13, p21, p23, p31, p32)
+ a = self.RPythonAnnotator()
+ s, dontcare = annotate_lowlevel_helper(a, llf, [])
+
+ spec_llwitness = None
+ for call in annotated_calls(a):
+ spec_llwitness = derived(call, 'llwitness')
+
+ g = a.translator.flowgraphs[spec_llwitness]
+ bindings = [a.binding(v) for v in g.getargs()]
+ assert [x.ll_ptrtype for x in bindings] == [PS1, PS1, PS2, PS2, PS3, PS3]
+
+
def test_array_length(self):
A = GcArray(('v', Signed))
def llf():
@@ -126,10 +172,9 @@
assert s == annmodel.SomeFloat()
g = a.translator.getflowgraph(llf)
for_ = {}
- for block in a.annotated:
- for op in block.operations:
- if op.opname == 'simple_call' and op.args[0].value.__name__.startswith("ll_"):
- for_[tuple([x.value for x in op.args[0:2]])] = True
+ for call in annotated_calls(a):
+ if derived(call, "ll_"):
+ for_[tuple([x.value for x in call.args[0:2]])] = True
assert len(for_) == 4
vTs = []
for func, T in for_.keys():
@@ -184,14 +229,11 @@
return s.const
else:
return s.ll_ptrtype
+
+ for call in annotated_calls(a):
+ if derived(call, "ll_") or derived(call, "makelen4"):
+ for_[tuple([q(x) for x in call.args[0:2]])] = True
- for block in a.annotated:
- for op in block.operations:
- if op.opname == 'simple_call':
- if op.args[0].value.__name__.startswith("ll_"):
- for_[tuple([q(x) for x in op.args[0:2]])] = True
- elif op.args[0].value.__name__.startswith("makelen4"):
- for_[tuple([q(x) for x in op.args[0:2]])] = True
assert len(for_) == 5
vTs = []
for func, T in for_.keys():
More information about the Pypy-commit
mailing list