[pypy-svn] r13451 - in pypy/dist/pypy: annotation rpython/test
pedronis at codespeak.net
pedronis at codespeak.net
Wed Jun 15 21:37:47 CEST 2005
Author: pedronis
Date: Wed Jun 15 21:37:46 2005
New Revision: 13451
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/rpython/test/test_llann.py
Log:
annotation support for getRuntimeTypeInfo and runtime_type_info with small tests
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Wed Jun 15 21:37:46 2005
@@ -316,9 +316,18 @@
cast_p = lltype.cast_pointer(PtrT.const, s_p.ll_ptrtype._defl())
return SomePtr(ll_ptrtype=lltype.typeOf(cast_p))
+def getRuntimeTypeInfo(T):
+ assert T.is_constant()
+ return immutablevalue(lltype.getRuntimeTypeInfo(T.const))
+
+def runtime_type_info(s_p):
+ assert isinstance(s_p, SomePtr), "runtime_type_info of non-pointer: %r" % s_p
+ return SomePtr(lltype.typeOf(lltype.runtime_type_info(s_p.ll_ptrtype._example())))
BUILTIN_ANALYZERS[lltype.malloc] = malloc
BUILTIN_ANALYZERS[lltype.typeOf] = typeOf
BUILTIN_ANALYZERS[lltype.nullptr] = nullptr
BUILTIN_ANALYZERS[lltype.cast_pointer] = cast_pointer
+BUILTIN_ANALYZERS[lltype.getRuntimeTypeInfo] = getRuntimeTypeInfo
+BUILTIN_ANALYZERS[lltype.runtime_type_info] = runtime_type_info
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 Jun 15 21:37:46 2005
@@ -258,3 +258,25 @@
assert a.binding(vp).ll_ptrtype == T
assert a.binding(rv) == annmodel.lltype_to_annotation(T.TO.OF)
return a, vTs
+
+ def test_getRuntimeTypeInfo(self):
+ S = GcStruct('s', ('x', Signed))
+ attachRuntimeTypeInfo(S)
+ def llf():
+ return getRuntimeTypeInfo(S)
+ a = self.RPythonAnnotator()
+ s, dontcare = annotate_lowlevel_helper(a, llf, [])
+ assert isinstance(s, annmodel.SomePtr)
+ assert s.ll_ptrtype == Ptr(RuntimeTypeInfo)
+ assert s.const == getRuntimeTypeInfo(S)
+
+ def test_runtime_type_info(self):
+ S = GcStruct('s', ('x', Signed))
+ attachRuntimeTypeInfo(S)
+ def llf(p):
+ return runtime_type_info(p)
+ a = self.RPythonAnnotator()
+ s, dontcare = annotate_lowlevel_helper(a, llf, [annmodel.SomePtr(Ptr(S))])
+ assert isinstance(s, annmodel.SomePtr)
+ assert s.ll_ptrtype == Ptr(RuntimeTypeInfo)
+
More information about the Pypy-commit
mailing list