[pypy-svn] r22188 - in pypy/dist/pypy: jit jit/test rpython
arigo at codespeak.net
arigo at codespeak.net
Sun Jan 15 00:03:05 CET 2006
Author: arigo
Date: Sun Jan 15 00:03:03 2006
New Revision: 22188
Modified:
pypy/dist/pypy/jit/test/test_vlist.py
pypy/dist/pypy/jit/vlist.py
pypy/dist/pypy/rpython/rlist.py
Log:
A bunch of new list methods.
Modified: pypy/dist/pypy/jit/test/test_vlist.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_vlist.py (original)
+++ pypy/dist/pypy/jit/test/test_vlist.py Sun Jan 15 00:03:03 2006
@@ -62,3 +62,36 @@
hint(lst, nonvirtual=True)
graph2, insns = run(fn, [12])
assert insns == {'direct_call': 3}
+
+def test_simple_purely_virtual():
+ def fn(n):
+ return len([5]*n)
+ graph2, insns = run(fn, [12])
+ assert insns == {}
+
+def test_copy():
+ def fn(n):
+ lst = []
+ lst.append(n)
+ lst.append(n)
+ return len(list(lst))
+ graph2, insns = run(fn, [12])
+ assert insns == {}
+
+def test_is_true():
+ def fn(n):
+ lst = [5] * n
+ if lst:
+ return 654
+ else:
+ return 321
+ graph2, insns = run(fn, [12])
+ assert insns == {}
+
+def test_concat():
+ def fn(n):
+ lst1 = [2, 3]
+ lst2 = [4] * n
+ return len(lst1 + lst2)
+ graph2, insns = run(fn, [12])
+ assert insns == {}
Modified: pypy/dist/pypy/jit/vlist.py
==============================================================================
--- pypy/dist/pypy/jit/vlist.py (original)
+++ pypy/dist/pypy/jit/vlist.py Sun Jan 15 00:03:03 2006
@@ -51,6 +51,12 @@
# ____________________________________________________________
# High-level operations
+ def oop_len(self, op):
+ return LLAbstractValue(const(len(self.items_a)))
+
+ def oop_nonzero(self, op):
+ return LLAbstractValue(const(bool(self.items_a)))
+
def oop_getitem(self, op, a_index):
c_index = a_index.maybe_get_constant()
if c_index is None:
@@ -63,9 +69,21 @@
raise NotImplementedError
self.items_a[c_index.value] = a_newobj
+ def oop_delitem(self, op, a_index):
+ c_index = a_index.maybe_get_constant()
+ if c_index is None:
+ raise NotImplementedError
+ del self.items_a[c_index.value]
+
def oop_append(self, op, a_newobj):
self.items_a.append(a_newobj)
+ def oop_insert(self, op, a_index, a_newobj):
+ c_index = a_index.maybe_get_constant()
+ if c_index is None:
+ raise NotImplementedError
+ self.items_a.insert(c_index.value, a_newobj)
+
def oop_pop(self, op, a_index=None):
if a_index is None:
return self.items_a.pop()
@@ -75,6 +93,23 @@
raise NotImplementedError
return self.items_a.pop(c_index.value)
+ def oop_reverse(self, op):
+ self.items_a.reverse()
+
+ def oop_copy(self, op):
+ items_a = list(self.items_a)
+ LIST = op.result.concretetype.TO
+ virtuallist = LLVirtualList(LIST, items_a)
+ return LLAbstractValue(content=virtuallist)
+
+ def oop_concat(self, op, a_other):
+ if not isinstance(a_other.content, LLVirtualList):
+ raise NotImplementedError
+ items_a = self.items_a + a_other.content.items_a
+ LIST = op.result.concretetype.TO
+ virtuallist = LLVirtualList(LIST, items_a)
+ return LLAbstractValue(content=virtuallist)
+
def oop_newlist(op, a_numitems, a_item=ll_dummy_value):
c_numitems = a_numitems.maybe_get_constant()
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Sun Jan 15 00:03:03 2006
@@ -528,13 +528,16 @@
new_items[i] = items[i]
i += 1
return new_lst
+ll_copy.oopspec = 'list.copy(l)'
def ll_len(l):
return l.ll_length()
+ll_len.oopspec = 'list.len(l)'
def ll_list_is_true(l):
# check if a list is True, allowing for None
return bool(l) and l.ll_length() != 0
+ll_list_is_true.oopspec = 'list.nonzero(l)'
def ll_append(l, newitem):
length = l.length
@@ -712,6 +715,7 @@
i += 1
j += 1
return l
+ll_concat.oopspec = 'list.concat(l1, l2)'
def ll_extend(l1, l2):
len1 = l1.length
More information about the Pypy-commit
mailing list