[pypy-svn] r25265 - in pypy/dist/pypy: annotation rpython/ootypesystem rpython/ootypesystem/test
nik at codespeak.net
nik at codespeak.net
Mon Apr 3 18:59:48 CEST 2006
Author: nik
Date: Mon Apr 3 18:59:46 2006
New Revision: 25265
Modified:
pypy/dist/pypy/annotation/unaryop.py
pypy/dist/pypy/rpython/ootypesystem/ootype.py
pypy/dist/pypy/rpython/ootypesystem/test/test_oolist.py
pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py
Log:
implement getitem/setitem for ootype lists (ignoring exception issues
and negative indices for now). fix a subtle bug in annotation of bound
methods.
Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py (original)
+++ pypy/dist/pypy/annotation/unaryop.py Mon Apr 3 18:59:46 2006
@@ -561,7 +561,7 @@
# annotation of low-level types
from pypy.annotation.model import SomePtr, SomeLLADTMeth
from pypy.annotation.model import SomeOOInstance, SomeOOBoundMeth, SomeOOStaticMeth
-from pypy.annotation.model import ll_to_annotation, annotation_to_lltype
+from pypy.annotation.model import ll_to_annotation, lltype_to_annotation, annotation_to_lltype
class __extend__(SomePtr):
@@ -619,8 +619,8 @@
def simple_call(m, *args_s):
llargs = [annotation_to_lltype(arg_s)._example() for arg_s in args_s]
inst = m.ootype._example()
- v = getattr(inst, m.name)(*llargs)
- return ll_to_annotation(v)
+ RESULT = ootype.typeOf(m.ootype._lookup(m.name)[1]).RESULT
+ return lltype_to_annotation(RESULT)
class __extend__(SomeOOStaticMeth):
def simple_call(m, *args_s):
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Mon Apr 3 18:59:46 2006
@@ -181,6 +181,8 @@
# "name": Meth([ARGUMENT1_TYPE, ARGUMENT2_TYPE, ...], RESULT_TYPE)
"length": Meth([], Unsigned),
"append": Meth([ITEMTYPE], Void),
+ "getitem": Meth([Signed], ITEMTYPE),
+ "setitem": Meth([Signed, ITEMTYPE], Void),
})
def __str__(self):
@@ -473,6 +475,17 @@
assert typeOf(item) == self._TYPE._ITEMTYPE
self._list.append(item)
+ def getitem(self, index):
+ # NOT_RPYTHON
+ assert typeOf(index) == Signed
+ return self._list[index]
+
+ def setitem(self, index, item):
+ # NOT_RPYTHON
+ assert typeOf(item) == self._TYPE._ITEMTYPE
+ assert typeOf(index) == Signed
+ self._list[index] = item
+
def new(TYPE):
if isinstance(TYPE, Instance):
return make_instance(TYPE)
Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oolist.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_oolist.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_oolist.py Mon Apr 3 18:59:46 2006
@@ -17,6 +17,13 @@
l.append(1)
assert l.length() == 1
+def test_setitem_getitem():
+ LT = List(Signed)
+ l = new(LT)
+ l.append(2)
+ assert l.getitem(0) == 2
+ l.setitem(0, 3)
+ assert l.getitem(0) == 3
class TestInterpreted:
@@ -27,3 +34,13 @@
return len(l)
res = interpret(f, [2], type_system="ootype")
assert res == 1
+
+ def test_setitem_getitem(self):
+ def f(x):
+ l = []
+ l.append(3)
+ l[0] = x
+ return l[0]
+ res = interpret(f, [2], type_system="ootype")
+ assert res == 2
+
Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py Mon Apr 3 18:59:46 2006
@@ -106,7 +106,7 @@
g = gengraph(oof, [])
rettype = g.getreturnvar().concretetype
- assert rettype == Signed
+ assert rettype == Unsigned
def test_list_append():
LT = List(Signed)
@@ -118,5 +118,19 @@
g = gengraph(oof, [])
rettype = g.getreturnvar().concretetype
+ assert rettype == Unsigned
+
+def test_list_getitem_setitem():
+ # XXX need to test exceptions
+ LT = List(Signed)
+
+ def oof():
+ l = new(LT)
+ l.append(1)
+ l.setitem(0, 2)
+ return l.getitem(0)
+
+ g = gengraph(oof, [])
+ rettype = g.getreturnvar().concretetype
assert rettype == Signed
More information about the Pypy-commit
mailing list