[pypy-svn] r32129 - in pypy/branch/more-gckinds/pypy/rpython: . lltypesystem test
mwh at codespeak.net
mwh at codespeak.net
Sun Sep 10 19:18:22 CEST 2006
Author: mwh
Date: Sun Sep 10 19:18:21 2006
New Revision: 32129
Modified:
pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/more-gckinds/pypy/rpython/lltypesystem/opimpl.py
pypy/branch/more-gckinds/pypy/rpython/rptr.py
pypy/branch/more-gckinds/pypy/rpython/test/test_rptr.py
Log:
support for len(interior pointer)
Modified: pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lloperation.py Sun Sep 10 19:18:21 2006
@@ -301,6 +301,7 @@
'getarraysize': LLOp(canfold=True),
'getsubstruct': LLOp(canfold=True),
'getinteriorfield': LLOp(canfold=True), # XXX not sure about the foldability...
+ 'getinteriorarraysize': LLOp(canfold=True),
'getarraysubstruct': LLOp(canfold=True),
'setfield': LLOp(),
'setinteriorfield': LLOp(),
Modified: pypy/branch/more-gckinds/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/lltypesystem/opimpl.py (original)
+++ pypy/branch/more-gckinds/pypy/rpython/lltypesystem/opimpl.py Sun Sep 10 19:18:21 2006
@@ -133,11 +133,20 @@
if isinstance(o, str):
ob = getattr(ob, o)
else:
- #1/0
ob = ob[o]
assert not isinstance(ob, lltype._interior_ptr)
return ob
+def op_getinteriorarraysize(obj, *offsets):
+ checkptr(obj)
+ ob = obj
+ for o in offsets:
+ if isinstance(o, str):
+ ob = getattr(ob, o)
+ else:
+ ob = ob[o]
+ return len(ob)
+
def op_getarraysubstruct(array, index):
checkptr(array)
result = array[index]
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 Sun Sep 10 19:18:21 2006
@@ -251,6 +251,12 @@
assert False
return vlist
+ def rtype_len(self, hop):
+ v_self, = hop.inputargs(self)
+ vlist = self.getinteriorfieldargs(hop, v_self)
+ return hop.genop('getinteriorarraysize', vlist,
+ resulttype=Signed)
+
def rtype_getattr(self, hop):
attr = hop.args_s[1].const
if isinstance(hop.s_result, annmodel.SomeLLADTMeth):
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 Sun Sep 10 19:18:21 2006
@@ -254,3 +254,12 @@
return u[0].s.x
res = interpret(f, [])
assert res == 1
+
+def test_interior_ptr_len():
+ S = Struct("S", ('x', Signed))
+ T = GcStruct("T", ('items', Array(S)))
+ def f():
+ t = malloc(T, 1)
+ return len(t.items)
+ res = interpret(f, [])
+ assert res == 1
More information about the Pypy-commit
mailing list