[pypy-svn] r8550 - in pypy/dist/pypy: annotation translator translator/test
mwh at codespeak.net
mwh at codespeak.net
Tue Jan 25 12:31:20 CET 2005
Author: mwh
Date: Tue Jan 25 12:31:20 2005
New Revision: 8550
Modified:
pypy/dist/pypy/annotation/model.py
pypy/dist/pypy/translator/annrpython.py
pypy/dist/pypy/translator/test/snippet.py
pypy/dist/pypy/translator/test/test_annrpython.py
Log:
Begin annotation of slices:
- add SomeSlice class
- create them from newslice operations
- test (bit icky, please rewrite if you know a better way!)
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Tue Jan 25 12:31:20 2005
@@ -129,6 +129,14 @@
self.s_item = s_item # general enough for any element
+class SomeSlice(SomeObject):
+ knowntype = slice
+ def __init__(self, start, stop, step):
+ self.start = start
+ self.stop = stop
+ self.step = step
+
+
class SomeTuple(SomeObject):
"Stands for a tuple of known length."
knowntype = tuple
Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py (original)
+++ pypy/dist/pypy/translator/annrpython.py Tue Jan 25 12:31:20 2005
@@ -378,6 +378,9 @@
factory = self.bookkeeper.getfactory(DictFactory)
return factory.create()
+ def consider_op_newslice(self, start, stop, step):
+ return annmodel.SomeSlice(start, stop, step)
+
class CannotSimplify(Exception):
pass
Modified: pypy/dist/pypy/translator/test/snippet.py
==============================================================================
--- pypy/dist/pypy/translator/test/snippet.py (original)
+++ pypy/dist/pypy/translator/test/snippet.py Tue Jan 25 12:31:20 2005
@@ -655,3 +655,6 @@
return x
else:
return apbc
+
+def simple_slice(x):
+ return x[:10]
Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py (original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py Tue Jan 25 12:31:20 2005
@@ -381,6 +381,17 @@
s_meth = s_example.getattr(iv(methname))
assert isinstance(s_constmeth, annmodel.SomeBuiltin)
+ def test_simple_slicing0(self):
+ a = RPythonAnnotator()
+ s = a.build_types(snippet.simple_slice, [list])
+ g = a.translator.getflowgraph(snippet.simple_slice)
+ for thing in flatten(g):
+ if isinstance(thing, Block):
+ for op in thing.operations:
+ if op.opname == "newslice":
+ assert isinstance(a.binding(op.result),
+ annmodel.SomeSlice)
+
def g(n):
return [0,1,2,n]
More information about the Pypy-commit
mailing list