[pypy-svn] r9742 - in pypy/dist/pypy: annotation translator/test

pedronis at codespeak.net pedronis at codespeak.net
Fri Mar 11 18:01:06 CET 2005


Author: pedronis
Date: Fri Mar 11 18:01:06 2005
New Revision: 9742

Modified:
   pypy/dist/pypy/annotation/unaryop.py
   pypy/dist/pypy/translator/test/snippet.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
- some more tests involving exception handling code annotation

- annotation for type op to pass all of them




Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Fri Mar 11 18:01:06 2005
@@ -22,13 +22,28 @@
 
 UNARY_OPERATIONS = set(['len', 'is_true', 'getattr', 'setattr',
                         'simple_call', 'call_args',
-                        'iter', 'next', 'invert'])
+                        'iter', 'next', 'invert', 'type'])
 
 for opname in UNARY_OPERATIONS:
     missing_operation(SomeObject, opname)
 
 
 class __extend__(SomeObject):
+
+    def type(obj):
+        if obj.is_constant():
+            r = immutablevalue(obj.knowntype)
+        else:
+            r = SomeObject()
+        bk = getbookkeeper()
+        fn, block, i = bk.position_key
+        annotator = bk.annotator
+        op = block.operations[i]
+        assert op.opname == "type" 
+        assert len(op.args) == 1
+        assert annotator.binding(op.args[0]) == obj
+        r.is_type_of = [op.args[0]]
+        return r
     
     def len(obj):
         return SomeInteger(nonneg=True)

Modified: pypy/dist/pypy/translator/test/snippet.py
==============================================================================
--- pypy/dist/pypy/translator/test/snippet.py	(original)
+++ pypy/dist/pypy/translator/test/snippet.py	Fri Mar 11 18:01:06 2005
@@ -721,6 +721,40 @@
     except Exc, e:
         return e
     return Exc()
+
+
+def witness(x):
+    pass
+
+def exception_deduction_with_raise1(x):
+    try:
+        exception_deduction0(2)
+        if x:
+            raise Exc()
+    except Exc, e:
+        witness(e)
+        return e
+    return Exc()
+
+def exception_deduction_with_raise2(x):
+    try:
+        exception_deduction0(2)
+        if x:
+            raise Exc
+    except Exc, e:
+        witness(e)
+        return e
+    return Exc()
+
+def exception_deduction_with_raise3(x):
+    try:
+        exception_deduction0(2)
+        if x:
+            raise Exc, Exc()
+    except Exc, e:
+        witness(e)
+        return e
+    return Exc()
     
 def slice_union(x):
     if x:

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	Fri Mar 11 18:01:06 2005
@@ -575,6 +575,26 @@
         assert s.items[0].knowntype == int
         assert s.items[1].knowntype == str
 
+    def test_exception_deduction_with_raise1(self):
+        a = RPythonAnnotator()
+        s = a.build_types(snippet.exception_deduction_with_raise1, [bool])
+        assert isinstance(s, annmodel.SomeInstance)
+        assert s.knowntype is snippet.Exc
+
+
+    def test_exception_deduction_with_raise2(self):
+        a = RPythonAnnotator()
+        s = a.build_types(snippet.exception_deduction_with_raise2, [bool])
+        assert isinstance(s, annmodel.SomeInstance)
+        assert s.knowntype is snippet.Exc
+
+    def test_exception_deduction_with_raise3(self):
+        a = RPythonAnnotator()
+        s = a.build_types(snippet.exception_deduction_with_raise3, [bool])
+        assert isinstance(s, annmodel.SomeInstance)
+        assert s.knowntype is snippet.Exc
+
+
 def g(n):
     return [0,1,2,n]
 



More information about the Pypy-commit mailing list