[pypy-svn] r13345 - in pypy/dist/pypy/rpython: . test
pedronis at codespeak.net
pedronis at codespeak.net
Mon Jun 13 14:58:08 CEST 2005
Author: pedronis
Date: Mon Jun 13 14:58:01 2005
New Revision: 13345
Added:
pypy/dist/pypy/rpython/test/test_rptr.py (contents, props changed)
Modified:
pypy/dist/pypy/rpython/rbuiltin.py
Log:
added support for cast_pointer in the rtyper (with some testing)
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Mon Jun 13 14:58:01 2005
@@ -127,9 +127,17 @@
return hop.genop('cast_parent', [v_input], # v_type implicit in r_result
resulttype = hop.r_result.lowleveltype)
+def rtype_cast_pointer(hop):
+ assert hop.args_s[0].is_constant()
+ assert isinstance(hop.args_r[1], rptr.PtrRepr)
+ v_type, v_input = hop.inputargs(Void, hop.args_r[1])
+ return hop.genop('cast_pointer', [v_input], # v_type implicit in r_result
+ resulttype = hop.r_result.lowleveltype)
+
BUILTIN_TYPER[lltype.malloc] = rtype_malloc
BUILTIN_TYPER[lltype.cast_parent] = rtype_cast_parent
+BUILTIN_TYPER[lltype.cast_pointer] = rtype_cast_pointer
BUILTIN_TYPER[lltype.typeOf] = rtype_const_result
BUILTIN_TYPER[lltype.nullptr] = rtype_const_result
BUILTIN_TYPER[rarithmetic.intmask] = rtype_intmask
Added: pypy/dist/pypy/rpython/test/test_rptr.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/test/test_rptr.py Mon Jun 13 14:58:01 2005
@@ -0,0 +1,33 @@
+from pypy.translator.annrpython import RPythonAnnotator
+from pypy.rpython.annlowlevel import annotate_lowlevel_helper
+from pypy.rpython.lltype import *
+from pypy.rpython.rtyper import RPythonTyper
+from pypy.annotation import model as annmodel
+
+
+# ____________________________________________________________
+
+def ll_rtype(llfn, argtypes=[]):
+ a = RPythonAnnotator()
+ s, dontcare = annotate_lowlevel_helper(a, llfn, argtypes)
+ t = a.translator
+ typer = RPythonTyper(a)
+ typer.specialize()
+ #t.view()
+ t.checkgraphs()
+ return s, t
+
+def test_cast_pointer():
+ S = GcStruct('s', ('x', Signed))
+ S1 = GcStruct('s1', ('sub', S))
+ S2 = GcStruct('s2', ('sub', S1))
+ PS = Ptr(S)
+ PS2 = Ptr(S2)
+ def lldown(p):
+ return cast_pointer(PS, p)
+ s, t = ll_rtype(lldown, [annmodel.SomePtr(PS2)])
+ assert s.ll_ptrtype == PS
+ def llup(p):
+ return cast_pointer(PS2, p)
+ s, t = ll_rtype(llup, [annmodel.SomePtr(PS)])
+ assert s.ll_ptrtype == PS2
More information about the Pypy-commit
mailing list