[pypy-svn] r23281 - in pypy/dist/pypy/rpython: . test
pedronis at codespeak.net
pedronis at codespeak.net
Mon Feb 13 15:56:35 CET 2006
Author: pedronis
Date: Mon Feb 13 15:56:31 2006
New Revision: 23281
Modified:
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/test/test_rlist.py
Log:
(arre, pedronis)
make type erasure work again for lists (now with test).
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Mon Feb 13 15:56:31 2006
@@ -68,8 +68,8 @@
self.external_item_repr, self.item_repr = externalvsinternal(rtyper, item_repr)
self.listitem = listitem
self.list_cache = {}
- self.list_builder = ListBuilder()
# setup() needs to be called to finish this initialization
+ self.list_builder = ListBuilder()
def _setup_repr_final(self):
self.list_builder.setup(self)
@@ -155,12 +155,13 @@
"""Interface to allow lazy list building by the JIT."""
# This should not keep a reference to the RTyper, even indirectly via
# the list_repr.
-
+
def setup(self, list_repr):
# Precompute the c_newitem and c_setitem_nonneg function pointers,
# needed below.
if list_repr.rtyper is None:
return # only for test_rlist, which doesn't need this anyway
+
LIST = list_repr.LIST
LISTPTR = list_repr.lowleveltype
ITEM = list_repr.item_repr.lowleveltype
@@ -178,7 +179,7 @@
#self.c_dum_nocheck = inputconst(Void, dum_nocheck)
#self.c_LIST = inputconst(Void, self.LIST)
- def build(self, builder, items_v):
+ def __call__(self, builder, items_v):
"""Make the operations that would build a list containing the
provided items."""
from pypy.rpython import rgenop
@@ -196,6 +197,29 @@
Void)
return v_result
+ def __eq__(self, other):
+ return self.LISTPTR == other.LISTPTR
+
+ def __ne__(self, other):
+ return not (self == other)
+
+ def __hash__(self):
+ return 1 # bad but not used alone
+
+
+def list_builder(rtyper, list_repr):
+ ITEM = list_repr.item_repr.lowleveltype
+ if rtyper is None: # only for testing!
+ return ListBuilder(list_repr.__class__, ITEM)
+ key = list_repr.__class__, ITEM
+ try:
+ return rtyper._list_builders[key]
+ except KeyError:
+ builder = ListBuilder(list_repr.__class__, ITEM)
+ rtyper._list_builders[key] = builder
+ return builder
+
+
class ListRepr(BaseListRepr):
def _setup_repr(self):
@@ -211,7 +235,7 @@
"ll_newlist": ll_newlist,
"ll_length": ll_length,
"ll_items": ll_items,
- "list_builder": self.list_builder.build,
+ "list_builder": self.list_builder,
"ITEM": ITEM,
})
)
@@ -285,7 +309,7 @@
"ll_newlist": ll_fixed_newlist,
"ll_length": ll_fixed_length,
"ll_items": ll_fixed_items,
- "list_builder": self.list_builder.build,
+ "list_builder": self.list_builder,
"ITEM": ITEM,
})
Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py (original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py Mon Feb 13 15:56:31 2006
@@ -1,4 +1,5 @@
import sys
+from pypy.translator.translator import TranslationContext
from pypy.rpython.lltypesystem.lltype import *
from pypy.rpython.rlist import *
from pypy.rpython.rslice import ll_newslice
@@ -72,6 +73,7 @@
class TestListImpl(BaseTestListImpl):
+
def sample_list(self): # [42, 43, 44, 45]
rlist = ListRepr(None, signed_repr)
rlist.setup()
@@ -989,3 +991,56 @@
return len(lst)
res = interpret(f, [])
assert res == 2
+
+
+def test_type_erase_fixed_size():
+ class A(object):
+ pass
+ class B(object):
+ pass
+
+ def f():
+ return [A()], [B()]
+
+ t = TranslationContext()
+ s = t.buildannotator().build_types(f, [])
+ rtyper = t.buildrtyper()
+ rtyper.specialize()
+
+ s_A_list = s.items[0]
+ s_B_list = s.items[1]
+
+ r_A_list = rtyper.getrepr(s_A_list)
+ assert isinstance(r_A_list, FixedSizeListRepr)
+ r_B_list = rtyper.getrepr(s_B_list)
+ assert isinstance(r_B_list, FixedSizeListRepr)
+
+ assert r_A_list.lowleveltype == r_B_list.lowleveltype
+
+def test_type_erase_var_size():
+ class A(object):
+ pass
+ class B(object):
+ pass
+
+ def f():
+ la = [A()]
+ lb = [B()]
+ la.append(None)
+ lb.append(None)
+ return la, lb
+
+ t = TranslationContext()
+ s = t.buildannotator().build_types(f, [])
+ rtyper = t.buildrtyper()
+ rtyper.specialize()
+
+ s_A_list = s.items[0]
+ s_B_list = s.items[1]
+
+ r_A_list = rtyper.getrepr(s_A_list)
+ assert isinstance(r_A_list, ListRepr)
+ r_B_list = rtyper.getrepr(s_B_list)
+ assert isinstance(r_B_list, ListRepr)
+
+ assert r_A_list.lowleveltype == r_B_list.lowleveltype
More information about the Pypy-commit
mailing list