[pypy-svn] r25672 - pypy/dist/pypy/rpython/ootypesystem
antocuni at codespeak.net
antocuni at codespeak.net
Mon Apr 10 18:44:25 CEST 2006
Author: antocuni
Date: Mon Apr 10 18:44:17 2006
New Revision: 25672
Modified:
pypy/dist/pypy/rpython/ootypesystem/ootype.py
Log:
Added ootype.List._GENERIC_METHODS attribute. It contains the same
information as the former _METHODS, with the difference that the
ITEMTYPE is explicitly marked by a placeholder. This way backends can
know which arguments are parametized on ITEMTYPE and which have fixed
type. The _METHODS attribute is automatically computed from
_GENERIC_METHODS.
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 10 18:44:17 2006
@@ -182,21 +182,36 @@
class List(OOType):
+ ITEMTYPE_T = object() # placeholder, see below
def __init__(self, ITEMTYPE):
self._ITEMTYPE = ITEMTYPE
self._null = _null_list(self)
- # This defines the abstract list interface that backends will have
- # to map to their native list implementations.
- self._METHODS = frozendict({
+ # This defines the abstract list interface that backends will
+ # have to map to their native list implementations.
+ # 'ITEMTYPE_T' is used as a placeholder for indicating
+ # arguments that should have ITEMTYPE type.
+
+ generic_types = {self.ITEMTYPE_T: ITEMTYPE}
+ self._GENERIC_METHODS = frozendict({
# "name": Meth([ARGUMENT1_TYPE, ARGUMENT2_TYPE, ...], RESULT_TYPE)
"length": Meth([], Signed),
- "append": Meth([ITEMTYPE], Void),
- "getitem": Meth([Signed], ITEMTYPE),
- "setitem": Meth([Signed, ITEMTYPE], Void),
+ "append": Meth([self.ITEMTYPE_T], Void),
+ "getitem": Meth([Signed], self.ITEMTYPE_T),
+ "setitem": Meth([Signed, self.ITEMTYPE_T], Void),
})
+ self._setup_methods(generic_types)
+
+ def _setup_methods(self, generic_types):
+ methods = {}
+ for name, meth in self._GENERIC_METHODS.iteritems():
+ args = [generic_types.get(arg, arg) for arg in meth.ARGS]
+ result = generic_types.get(meth.RESULT, meth.RESULT)
+ methods[name] = Meth(args, result)
+ self._METHODS = frozendict(methods)
+
# NB: We are expecting Lists of the same ITEMTYPE to compare/hash
# equal. We don't redefine __eq__/__hash__ since the implementations
# from LowLevelType work fine, especially in the face of recursive
@@ -612,3 +627,6 @@
ROOT = Instance('Root', None, _is_root=True)
+
+print List(Signed)._METHODS
+
More information about the Pypy-commit
mailing list