[pypy-svn] r13453 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Wed Jun 15 22:04:55 CEST 2005


Author: arigo
Date: Wed Jun 15 22:04:53 2005
New Revision: 13453

Modified:
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/rpython/test/test_rptr.py
Log:
rtyping runtime_type_info() and getRuntimeTypeInfo().



Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Wed Jun 15 22:04:53 2005
@@ -2,7 +2,7 @@
 from pypy.annotation import model as annmodel
 from pypy.rpython import lltype
 from pypy.rpython import rarithmetic
-from pypy.rpython.lltype import Void, Signed
+from pypy.rpython.lltype import Void, Signed, Ptr, RuntimeTypeInfo
 from pypy.rpython.rtyper import TyperError
 from pypy.rpython.rrange import rtype_builtin_range
 from pypy.rpython.rmodel import Repr, TyperError
@@ -127,9 +127,20 @@
     return hop.genop('cast_pointer', [v_input],    # v_type implicit in r_result
                      resulttype = hop.r_result.lowleveltype)
 
+def rtype_getRuntimeTypeInfo(hop):
+    return hop.inputconst(Ptr(RuntimeTypeInfo), hop.s_result.const)
+
+def rtype_runtime_type_info(hop):
+    assert isinstance(hop.args_r[0], rptr.PtrRepr)
+    vlist = hop.inputargs(hop.args_r[0])
+    return hop.genop('runtime_type_info', vlist,
+                     resulttype = rptr.PtrRepr(Ptr(RuntimeTypeInfo)))
+
 
 BUILTIN_TYPER[lltype.malloc] = rtype_malloc
 BUILTIN_TYPER[lltype.cast_pointer] = rtype_cast_pointer
 BUILTIN_TYPER[lltype.typeOf] = rtype_const_result
 BUILTIN_TYPER[lltype.nullptr] = rtype_const_result
+BUILTIN_TYPER[lltype.getRuntimeTypeInfo] = rtype_getRuntimeTypeInfo
+BUILTIN_TYPER[lltype.runtime_type_info] = rtype_runtime_type_info
 BUILTIN_TYPER[rarithmetic.intmask] = rtype_intmask

Modified: pypy/dist/pypy/rpython/test/test_rptr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rptr.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rptr.py	Wed Jun 15 22:04:53 2005
@@ -31,3 +31,15 @@
         return cast_pointer(PS2, p)
     s, t = ll_rtype(llup, [annmodel.SomePtr(PS)])
     assert s.ll_ptrtype == PS2
+
+def test_runtime_type_info():
+    S = GcStruct('s', ('x', Signed))
+    attachRuntimeTypeInfo(S)
+    def ll_example(p):
+        return (runtime_type_info(p),
+                runtime_type_info(p) == getRuntimeTypeInfo(S))
+
+    assert ll_example(malloc(S)) == (getRuntimeTypeInfo(S), True)
+    s, t = ll_rtype(ll_example, [annmodel.SomePtr(Ptr(S))])
+    assert s == annmodel.SomeTuple([annmodel.SomePtr(Ptr(RuntimeTypeInfo)),
+                                    annmodel.SomeBool()])



More information about the Pypy-commit mailing list