[pypy-svn] r32085 - in pypy/branch/more-gckinds/pypy/rpython: . test
mwh at codespeak.net
mwh at codespeak.net
Fri Sep 8 16:06:32 CEST 2006
Author: mwh
Date: Fri Sep 8 16:06:29 2006
New Revision: 32085
Modified:
pypy/branch/more-gckinds/pypy/rpython/rptr.py
pypy/branch/more-gckinds/pypy/rpython/test/test_rptr.py
Log:
beginnings of rtyping support for interior pointers and a test which fails
because of conflicting opinions about the lowleveltype of the result of a
getsubstructure.
Modified: pypy/branch/more-gckinds/pypy/rpython/rptr.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/rptr.py (original)
+++ pypy/branch/more-gckinds/pypy/rpython/rptr.py Fri Sep 8 16:06:29 2006
@@ -2,7 +2,8 @@
from pypy.annotation import model as annmodel
from pypy.objspace.flow import model as flowmodel
from pypy.rpython.lltypesystem.lltype import \
- Ptr, ContainerType, Void, Signed, Bool, FuncType, typeOf, FixedSizeArray
+ Ptr, ContainerType, Void, Signed, Bool, FuncType, typeOf, FixedSizeArray, \
+ InteriorPtr
from pypy.rpython.error import TyperError
from pypy.rpython.rmodel import Repr, IntegerRepr
@@ -21,9 +22,6 @@
class __extend__(annmodel.SomeInteriorPtr):
def rtyper_makerepr(self, rtyper):
-## if self.is_constant() and not self.const: # constant NULL
-## return nullptr_repr
-## else:
return InteriorPtrRepr(self.ll_ptrtype)
class PtrRepr(Repr):
@@ -187,4 +185,26 @@
return v
return NotImplemented
+class InteriorPtrRepr(Repr):
+ def __init__(self, ptrtype):
+ assert isinstance(ptrtype, InteriorPtr)
+ assert len(ptrtype.offsets) == 1
+ offset, = ptrtype.offsets
+ assert isinstance(offset, str)
+ self.lowleveltype = Ptr(ptrtype.PARENTTYPE)
+ self.coffset = flowmodel.Constant(offset, Void)
+ self.resulttype = Ptr(ptrtype.TO)
+
+ def access(self, hop):
+ assert hop.args_r[0] is self
+ return hop.genop('getsubstruct', [hop.args_v[0], self.coffset],
+ resulttype=self.resulttype)
+ def rtype_getattr(self, hop):
+ hop2 = hop.copy()
+ v_ptr = self.access(hop2)
+ hop2.r_s_popfirstarg()
+ hop2.v_s_insertfirstarg(v_ptr, annmodel.SomePtr(self.resulttype))
+ return hop2.dispatch()
+
+ rtype_setattr = rtype_getattr
Modified: pypy/branch/more-gckinds/pypy/rpython/test/test_rptr.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/test/test_rptr.py (original)
+++ pypy/branch/more-gckinds/pypy/rpython/test/test_rptr.py Fri Sep 8 16:06:29 2006
@@ -204,3 +204,16 @@
fptr(*(x,y))
py.test.raises(TypeError, "interpret(wrong, [1, 2])")
+
+
+def test_interior_ptr():
+ S = Struct("S", ('x', Signed))
+ T = GcStruct("T", ('s', S))
+ def g(s):
+ s.x = 1
+ def f():
+ t = malloc(T)
+ g(t.s)
+ return t.s.x
+ res = interpret(f, [])
+ assert res == 1
More information about the Pypy-commit
mailing list