[pypy-svn] r25867 - in pypy/dist/pypy: rpython/ootypesystem rpython/ootypesystem/test translator/cli/src translator/cli/test
antocuni at codespeak.net
antocuni at codespeak.net
Sun Apr 16 10:23:25 CEST 2006
Author: antocuni
Date: Sun Apr 16 10:22:57 2006
New Revision: 25867
Modified:
pypy/dist/pypy/rpython/ootypesystem/ootype.py
pypy/dist/pypy/rpython/ootypesystem/rlist.py
pypy/dist/pypy/rpython/ootypesystem/test/test_oolist.py
pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py
pypy/dist/pypy/translator/cli/src/pypylib.cs
pypy/dist/pypy/translator/cli/test/compile.py
Log:
The interface of ootypesystem.ootype.List has been modified to reflect
the changes in lltypesystem's list. In particular the 'length',
'getitem_nonneg' and 'setitem_nonneg' have been renamed to
'll_length', 'll_getitem_fast' and 'll_setitem_fast'.
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Sun Apr 16 10:22:57 2006
@@ -200,18 +200,24 @@
self.ITEMTYPE_T: ITEMTYPE,
}
+ # the methods are named after the ADT methods of lltypesystem's lists
self._GENERIC_METHODS = frozendict({
# "name": Meth([ARGUMENT1_TYPE, ARGUMENT2_TYPE, ...], RESULT_TYPE)
- "length": Meth([], Signed),
- "append": Meth([self.ITEMTYPE_T], Void),
- "getitem_nonneg": Meth([Signed], self.ITEMTYPE_T),
- "setitem_nonneg": Meth([Signed, self.ITEMTYPE_T], Void),
+ "ll_length": Meth([], Signed),
+ "ll_getitem_fast": Meth([Signed], self.ITEMTYPE_T),
+ "ll_setitem_fast": Meth([Signed, self.ITEMTYPE_T], Void),
+ "append": Meth([self.ITEMTYPE_T], Void),
"extend": Meth([self.SELFTYPE_T], Void),
"remove_range": Meth([Signed, Signed], Void), # remove_range(start, count)
})
self._setup_methods(generic_types)
+ # this is the equivalent of the lltypesystem ll_newlist that is
+ # marked as typeMethod.
+ def ll_newlist(self):
+ return new(self)
+
def _setup_methods(self, generic_types):
methods = {}
for name, meth in self._GENERIC_METHODS.iteritems():
@@ -531,7 +537,7 @@
# use by the llinterpreter and ootype tests. There are NOT_RPYTHON
# because the annotator is not supposed to follow them.
- def length(self):
+ def ll_length(self):
# NOT_RPYTHON
return len(self._list)
@@ -540,13 +546,13 @@
assert typeOf(item) == self._TYPE._ITEMTYPE
self._list.append(item)
- def getitem_nonneg(self, index):
+ def ll_getitem_fast(self, index):
# NOT_RPYTHON
assert typeOf(index) == Signed
assert index >= 0
return self._list[index]
- def setitem_nonneg(self, index, item):
+ def ll_setitem_fast(self, index, item):
# NOT_RPYTHON
assert typeOf(item) == self._TYPE._ITEMTYPE
assert typeOf(index) == Signed
Modified: pypy/dist/pypy/rpython/ootypesystem/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rlist.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rlist.py Sun Apr 16 10:22:57 2006
@@ -56,7 +56,7 @@
return inputconst(Void, self.item_repr.get_ll_eq_function())
def rtype_len(self, hop):
- return self.send_message(hop, "length")
+ return self.send_message(hop, "ll_length")
def rtype_is_true(self, hop):
v_lst, = hop.inputargs(self)
@@ -87,7 +87,7 @@
def rtype_getitem((r_list, r_int), hop):
if hop.args_s[1].nonneg:
- return r_list.send_message(hop, "getitem_nonneg", can_raise=True)
+ return r_list.send_message(hop, "ll_getitem_fast", can_raise=True)
else:
v_list, v_index = hop.inputargs(r_list, Signed)
hop.exception_is_here()
@@ -96,7 +96,7 @@
def rtype_setitem((r_list, r_int), hop):
if hop.args_s[1].nonneg:
- return r_list.send_message(hop, "setitem_nonneg", can_raise=True)
+ return r_list.send_message(hop, "ll_setitem_fast", can_raise=True)
else:
v_list, v_index, v_item = hop.inputargs(r_list, Signed, r_list.item_repr)
hop.exception_is_here()
@@ -133,83 +133,84 @@
def ll_getitem(lst, index):
if index < 0:
- index += lst.length()
- return lst.getitem_nonneg(index)
+ index += lst.ll_length()
+ return lst.ll_getitem_fast(index)
def ll_setitem(lst, index, item):
if index < 0:
- index += lst.length()
- return lst.setitem_nonneg(index, item)
+ index += lst.ll_length()
+ return lst.ll_setitem_fast(index, item)
def ll_delitem(lst, index):
if index < 0:
- index += lst.length()
+ index += lst.ll_length()
return lst.remove_range(index, 1)
def ll_list_is_true(lst):
- return bool(lst) and lst.length() != 0
+ return bool(lst) and lst.ll_length() != 0
def ll_append(lst, item):
lst.append(item)
def ll_extend(l1, l2):
# This is a bit inefficient, could also add extend to the list interface
- len2 = l2.length()
+ len2 = l2.ll_length()
i = 0
while i < len2:
- l1.append(l2.getitem_nonneg(i))
+ l1.append(l2.ll_getitem_fast(i))
i += 1
def ll_concat(RESLIST, l1, l2):
- len1 = l1.length()
- len2 = l2.length()
- l = ootype.new(RESLIST)
+ len1 = l1.ll_length()
+ len2 = l2.ll_length()
+ #l = ootype.new(RESLIST)
+ l = RESLIST.ll_newlist()
i = 0
while i < len1:
- l.append(l1.getitem_nonneg(i))
+ l.append(l1.ll_getitem_fast(i))
i += 1
i = 0
while i < len2:
- l.append(l2.getitem_nonneg(i))
+ l.append(l2.ll_getitem_fast(i))
i += 1
return l
def ll_listslice_startonly(RESLIST, lst, start):
- len1 = lst.length()
+ len1 = lst.ll_length()
#newlength = len1 - start
res = ootype.new(RESLIST) # TODO: pre-allocate newlength elements
i = start
while i < len1:
- res.append(lst.getitem_nonneg(i))
+ res.append(lst.ll_getitem_fast(i))
i += 1
return res
def ll_listslice(RESLIST, lst, slice):
start = slice.start
stop = slice.stop
- length = lst.length()
+ length = lst.ll_length()
if stop > length:
stop = length
#newlength = stop - start
res = ootype.new(RESLIST) # TODO: pre-allocate newlength elements
i = start
while i < stop:
- res.append(lst.getitem_nonneg(i))
+ res.append(lst.ll_getitem_fast(i))
i += 1
return res
def ll_listslice_minusone(RESLIST, lst):
- newlength = lst.length() - 1
+ newlength = lst.ll_length() - 1
#assert newlength >= 0 # TODO: asserts seems to have problems with ootypesystem
res = ootype.new(RESLIST) # TODO: pre-allocate newlength elements
i = 0
while i < newlength:
- res.append(lst.getitem_nonneg(i))
+ res.append(lst.ll_getitem_fast(i))
i += 1
return res
def ll_listsetslice(l1, slice, l2):
- count = l2.length()
+ count = l2.ll_length()
## assert count == slice.stop - slice.start, ( # TODO: see above
## "setslice cannot resize lists in RPython")
# XXX but it should be easy enough to support, soon
@@ -217,19 +218,19 @@
j = start
i = 0
while i < count:
- l1.setitem_nonneg(j, l2.getitem_nonneg(i))
+ l1.ll_setitem_fast(j, l2.ll_getitem_fast(i))
i += 1
j += 1
def ll_listdelslice_startonly(lst, start):
- count = lst.length() - start
+ count = lst.ll_length() - start
if count > 0:
lst.remove_range(start, count)
def ll_listdelslice(lst, slice):
start = slice.start
stop = slice.stop
- length = lst.length()
+ length = lst.ll_length()
if stop > length:
stop = length
count = stop - start
@@ -237,14 +238,14 @@
lst.remove_range(start, count)
def ll_listindex(lst, obj, eqfn):
- lng = lst.length()
+ lng = lst.ll_length()
j = 0
while j < lng:
if eqfn is None:
- if lst.getitem_nonneg(j) == obj:
+ if lst.ll_getitem_fast(j) == obj:
return j
else:
- if eqfn(lst.getitem_nonneg(j), obj):
+ if eqfn(lst.ll_getitem_fast(j), obj):
return j
j += 1
raise ValueError # can't say 'list.index(x): x not in list'
@@ -273,8 +274,8 @@
def ll_listnext(iter):
l = iter.iterable
index = iter.index
- if index >= l.length():
+ if index >= l.ll_length():
raise StopIteration
iter.index = index + 1
- return l.getitem_nonneg(index)
+ return l.ll_getitem_fast(index)
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 Sun Apr 16 10:22:57 2006
@@ -10,13 +10,13 @@
def test_len():
LT = List(Signed)
l = new(LT)
- assert l.length() == 0
+ assert l.ll_length() == 0
def test_append():
LT = List(Signed)
l = new(LT)
l.append(1)
- assert l.length() == 1
+ assert l.ll_length() == 1
def test_extend():
LT = List(Signed)
@@ -25,21 +25,21 @@
l1.append(1)
l2.append(2)
l1.extend(l2)
- assert l1.length() == 2
+ assert l1.ll_length() == 2
def test_setitem_getitem():
LT = List(Signed)
l = new(LT)
l.append(2)
- assert l.getitem_nonneg(0) == 2
- l.setitem_nonneg(0, 3)
- assert l.getitem_nonneg(0) == 3
+ assert l.ll_getitem_fast(0) == 2
+ l.ll_setitem_fast(0, 3)
+ assert l.ll_getitem_fast(0) == 3
def test_setitem_indexerror():
LT = List(Signed)
l = new(LT)
- py.test.raises(IndexError, l.getitem_nonneg, 0)
- py.test.raises(IndexError, l.setitem_nonneg, 0, 1)
+ py.test.raises(IndexError, l.ll_getitem_fast, 0)
+ py.test.raises(IndexError, l.ll_setitem_fast, 0, 1)
def test_null():
LT = List(Signed)
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 Sun Apr 16 10:22:57 2006
@@ -104,7 +104,7 @@
def oof():
l = new(LT)
- return l.length()
+ return l.ll_length()
g = gengraph(oof, [])
rettype = g.getreturnvar().concretetype
@@ -116,7 +116,7 @@
def oof():
l = new(LT)
l.append(1)
- return l.length()
+ return l.ll_length()
g = gengraph(oof, [])
rettype = g.getreturnvar().concretetype
@@ -128,8 +128,8 @@
def oof():
l = new(LT)
l.append(1)
- l.setitem_nonneg(0, 2)
- return l.getitem_nonneg(0)
+ l.ll_setitem_fast(0, 2)
+ return l.ll_getitem_fast(0)
g = gengraph(oof, [])
rettype = g.getreturnvar().concretetype
@@ -141,7 +141,7 @@
def oof():
l = new(LT)
try:
- l.getitem_nonneg(0)
+ l.ll_getitem_fast(0)
except IndexError:
return -1
return 0
@@ -162,7 +162,7 @@
LIST = List(Signed)
def oof(lst):
- return lst.length()
+ return lst.ll_length()
lst = new(LIST)
lst.append(1)
Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/pypylib.cs (original)
+++ pypy/dist/pypy/translator/cli/src/pypylib.cs Sun Apr 16 10:22:57 2006
@@ -14,24 +14,24 @@
// rpython.ootypesystem.ootype.List.GENERIC_METHODS
public class List<T>: System.Collections.Generic.List<T>
{
- public int length()
+ public int ll_length()
{
return this.Count;
}
- public void append(T item)
+ public T ll_getitem_fast(int index)
{
- this.Add(item);
+ return this[index];
}
- public T getitem_nonneg(int index)
+ public void ll_setitem_fast(int index, T item)
{
- return this[index];
+ this[index] = item;
}
- public void setitem_nonneg(int index, T item)
+ public void append(T item)
{
- this[index] = item;
+ this.Add(item);
}
public void extend(List<T> other)
Modified: pypy/dist/pypy/translator/cli/test/compile.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/compile.py (original)
+++ pypy/dist/pypy/translator/cli/test/compile.py Sun Apr 16 10:22:57 2006
@@ -33,9 +33,9 @@
return total
def bar(x, y):
- lst = [1,2,3,x,y]
+ lst = [1,2,3,x,y] + [1,2]
#return sum_(list(lst))
- return sum_(lst[:])
+ return lst[4]
f = compile_function(bar, [int, int])
More information about the Pypy-commit
mailing list