[pypy-svn] r25253 - in pypy/dist/pypy/rpython/ootypesystem: . test
nik at codespeak.net
nik at codespeak.net
Mon Apr 3 15:05:28 CEST 2006
Author: nik
Date: Mon Apr 3 15:05:20 2006
New Revision: 25253
Modified:
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:
add append method to the ootype list interface (to have a bit more
to work with for repr tests).
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 15:05:20 2006
@@ -175,11 +175,19 @@
def __init__(self, ITEMTYPE):
self._ITEMTYPE = ITEMTYPE
+ # This defines the abstract list interface that backends will have
+ # to map to their native list implementations.
+ self._METHODS = frozendict({
+ # "name": Meth([ARGUMENT1_TYPE, ARGUMENT2_TYPE, ...], RESULT_TYPE)
+ "length": Meth([], Unsigned),
+ "append": Meth([ITEMTYPE], Void),
+ })
+
def __str__(self):
return '%s(%s)' % (self.__class__.__name__, self._ITEMTYPE)
def _lookup(self, meth_name):
- METH = LIST_METHODS.get(meth_name)
+ METH = self._METHODS.get(meth_name)
meth = None
if METH is not None:
meth = _meth(METH, _name=meth_name,
@@ -438,13 +446,6 @@
return callb(self.inst, *checked_args)
-# This defines the abstract list interface that backends will have to map to
-# their native list implementations.
-LIST_METHODS = frozendict({
- # "method name": Meth([ARGUMENT1_TYPE, ARGUMENT2_TYPE, ...], RESULT_TYPE)
- "length": Meth([], Unsigned),
-})
-
class _list(object):
def __init__(self, LIST):
@@ -467,6 +468,10 @@
# NOT_RPYTHON
return len(self._list)
+ def append(self, item):
+ # NOT_RPYTHON
+ assert typeOf(item) == self._TYPE._ITEMTYPE
+ self._list.append(item)
def new(TYPE):
if isinstance(TYPE, Instance):
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 15:05:20 2006
@@ -10,3 +10,8 @@
l = new(LT)
assert l.length() == 0
+def test_append():
+ LT = List(Signed)
+ l = new(LT)
+ l.append(1)
+ assert l.length() == 1
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 15:05:20 2006
@@ -108,3 +108,15 @@
rettype = g.getreturnvar().concretetype
assert rettype == Signed
+def test_list_append():
+ LT = List(Signed)
+
+ def oof():
+ l = new(LT)
+ l.append(1)
+ return l.length()
+
+ g = gengraph(oof, [])
+ rettype = g.getreturnvar().concretetype
+ assert rettype == Signed
+
More information about the Pypy-commit
mailing list