[pypy-svn] r25343 - pypy/dist/pypy/rpython/ootypesystem
nik at codespeak.net
nik at codespeak.net
Wed Apr 5 11:33:26 CEST 2006
Author: nik
Date: Wed Apr 5 11:33:25 2006
New Revision: 25343
Added:
pypy/dist/pypy/rpython/ootypesystem/riterable.py (contents, props changed)
Modified:
pypy/dist/pypy/rpython/ootypesystem/rlist.py
pypy/dist/pypy/rpython/ootypesystem/rtuple.py
Log:
generalize iterator type construction for tuples and lists in ootypes.
Added: pypy/dist/pypy/rpython/ootypesystem/riterable.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/ootypesystem/riterable.py Wed Apr 5 11:33:25 2006
@@ -0,0 +1,13 @@
+from pypy.rpython.ootypesystem import ootype
+
+_iter_types = {}
+
+def iterator_type(r_iterable):
+ key = r_iterable.lowleveltype
+ if _iter_types.has_key(key):
+ return _iter_types[key]
+ else:
+ ITER = ootype.Instance("Iterator", ootype.ROOT,
+ {"iterable": key, "index": ootype.Signed})
+ _iter_types[key] = ITER
+ return ITER
Modified: pypy/dist/pypy/rpython/ootypesystem/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rlist.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rlist.py Wed Apr 5 11:33:25 2006
@@ -4,6 +4,7 @@
from pypy.rpython.rmodel import Repr, IntegerRepr
from pypy.rpython.rmodel import inputconst, externalvsinternal
from pypy.rpython.ootypesystem import ootype
+from pypy.rpython.ootypesystem.riterable import iterator_type
class BaseListRepr(AbstractListRepr):
@@ -83,34 +84,22 @@
#
# Iteration.
-_list_iter_types = {}
-
-def list_iter_type(r_list):
- key = r_list.lowleveltype
- if _list_iter_types.has_key(key):
- return _list_iter_types[key]
- else:
- INST = ootype.Instance("ListIter", ootype.ROOT,
- {"list": r_list.lowleveltype, "index": ootype.Signed})
- _list_iter_types[key] = INST
- return INST
-
class ListIteratorRepr(AbstractListIteratorRepr):
def __init__(self, r_list):
self.r_list = r_list
- self.lowleveltype = list_iter_type(r_list)
+ self.lowleveltype = iterator_type(r_list)
self.ll_listiter = ll_listiter
self.ll_listnext = ll_listnext
def ll_listiter(ITER, lst):
iter = ootype.new(ITER)
- iter.list = lst
+ iter.iterable = lst
iter.index = 0
return iter
def ll_listnext(iter):
- l = iter.list
+ l = iter.iterable
index = iter.index
if index >= l.length():
raise StopIteration
Modified: pypy/dist/pypy/rpython/ootypesystem/rtuple.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rtuple.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rtuple.py Wed Apr 5 11:33:25 2006
@@ -1,5 +1,6 @@
from pypy.rpython.rmodel import inputconst
from pypy.rpython.rtuple import AbstractTupleRepr, AbstractTupleIteratorRepr
+from pypy.rpython.ootypesystem.riterable import iterator_type
from pypy.rpython.ootypesystem import ootype
@@ -55,23 +56,11 @@
#
# Iteration.
-_tuple_iter_types = {}
-
-def tuple_iter_type(r_tuple):
- key = r_tuple.lowleveltype
- if _tuple_iter_types.has_key(key):
- return _tuple_iter_types[key]
- else:
- INST = ootype.Instance("TupleIter", ootype.ROOT,
- {"tuple": r_tuple.lowleveltype})
- _tuple_iter_types[key] = INST
- return INST
-
class Length1TupleIteratorRepr(AbstractTupleIteratorRepr):
def __init__(self, r_tuple):
self.r_tuple = r_tuple
- self.lowleveltype = tuple_iter_type(r_tuple)
+ self.lowleveltype = iterator_type(r_tuple)
self.ll_tupleiter = ll_tupleiter
self.ll_tuplenext = ll_tuplenext
@@ -79,14 +68,14 @@
def ll_tupleiter(ITERINST, tuple):
iter = ootype.new(ITERINST)
- iter.tuple = tuple
+ iter.iterable = tuple
return iter
def ll_tuplenext(iter):
# for iterating over length 1 tuples only!
- t = iter.tuple
+ t = iter.iterable
if t:
- iter.tuple = ootype.null(ootype.typeOf(t))
+ iter.iterable = ootype.null(ootype.typeOf(t))
return t.item0
else:
raise StopIteration
More information about the Pypy-commit
mailing list