[pypy-svn] r15508 - in pypy/dist/pypy/translator/llvm2: . module test

ericvrp at codespeak.net ericvrp at codespeak.net
Tue Aug 2 15:02:06 CEST 2005


Author: ericvrp
Date: Tue Aug  2 15:02:05 2005
New Revision: 15508

Modified:
   pypy/dist/pypy/translator/llvm2/funcnode.py
   pypy/dist/pypy/translator/llvm2/module/extfunction.py
   pypy/dist/pypy/translator/llvm2/opwriter.py
   pypy/dist/pypy/translator/llvm2/test/test_exception.py
Log:
- enabled more passing tests
- finally use correct type for exc_type and exc_value globals
- remove call to issubclass for "except: cases



Modified: pypy/dist/pypy/translator/llvm2/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/funcnode.py	(original)
+++ pypy/dist/pypy/translator/llvm2/funcnode.py	Tue Aug  2 15:02:05 2005
@@ -133,6 +133,9 @@
 
     def write_block_branches(self, codewriter, block):
         #assert len(block.exits) <= 2    #more exits are possible (esp. in combination with exceptions)
+        if block.exitswitch == Constant(last_exception):
+            #codewriter.comment('FuncNode(ConstantLLVMNode) *last_exception* write_block_branches @%s@' % str(block.exits))
+            return
         if len(block.exits) == 1:
             codewriter.br_uncond(self.block_to_name[block.exits[0].target])
         elif len(block.exits) == 2:
@@ -201,13 +204,8 @@
             inputargs = self.db.repr_arg_multi(block.inputargs)
             inputargtypes = self.db.repr_arg_type_multi(block.inputargs)
 
-            tmptype, tmpvar = 'sbyte*', self.db.repr_tmpvar()
-            codewriter.cast(tmpvar, inputargtypes[0], inputargs[0], tmptype)
-            codewriter.store(tmptype, tmpvar, '%last_exception_type')
-
-            tmptype, tmpvar = 'sbyte*', self.db.repr_tmpvar()
-            codewriter.cast(tmpvar, inputargtypes[1], inputargs[1], tmptype)
-            codewriter.store(tmptype, tmpvar, '%last_exception_value')
+            codewriter.store(inputargtypes[0], inputargs[0], '%last_exception_type')
+            codewriter.store(inputargtypes[1], inputargs[1], '%last_exception_value')
         else:
             codewriter.comment('reraise last exception')
             #Reraising last_exception.

Modified: pypy/dist/pypy/translator/llvm2/module/extfunction.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/extfunction.py	(original)
+++ pypy/dist/pypy/translator/llvm2/module/extfunction.py	Tue Aug  2 15:02:05 2005
@@ -6,10 +6,8 @@
 %structtype.rpy_string = type {int, {int, [0 x sbyte]}}
 
 ;exception handling globals
-%last_exception_type  = global sbyte* null
-%last_exception_value = global sbyte* null
-;%last_exception_type  = global %structtype.object_vtable* null
-;%last_exception_value = global %structtype.object* null
+%last_exception_type  = global %structtype.object_vtable* null
+%last_exception_value = global %structtype.object* null
 """
 
 gc_boehm = """declare sbyte* %GC_malloc(uint)

Modified: pypy/dist/pypy/translator/llvm2/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm2/opwriter.py	Tue Aug  2 15:02:05 2005
@@ -262,19 +262,15 @@
                                     e.lltype_of_exception_type.TO.__name__
                                     + '*')
 
-        tmptype1, tmpvar1 = 'sbyte*', self.db.repr_tmpvar()
-        tmptype2, tmpvar2 = lltype_of_exception_type, self.db.repr_tmpvar()
-
         self.codewriter.label(exc_label)
-        self.codewriter.load(tmpvar1, tmptype1, '%last_exception_type')
-        self.codewriter.cast(tmpvar2, tmptype1, tmpvar1, tmptype2)
-        self.codewriter.newline()
 
-        exc_found_labels = []
+        exc_found_labels, last_exception_type = [], None
         for link in self.block.exits[1:]:
             assert issubclass(link.exitcase, Exception)
 
             etype = self.db.obj2node[link.llexitcase._obj]
+            current_exception_type = etype.get_ref()
+            #self.codewriter.comment('etype=%s, current_exception_type=%s' % (str(etype.ref), str(current_exception_type)))
 
             target          = self.node.block_to_name[link.target]
             exc_found_label = block_label + '_exception_found_branchto_' + target
@@ -282,18 +278,26 @@
 
             not_this_exception_label = block_label + '_not_exception_' + etype.ref[1:]
 
-            ll_issubclass_cond = self.db.repr_tmpvar()
-            self.codewriter.call(ll_issubclass_cond,
-                                 'bool',
-                                 ll_exception_match,
-                                 [etype.get_ref(), tmpvar2],
-                                 [lltype_of_exception_type, lltype_of_exception_type])
-            self.codewriter.br(ll_issubclass_cond, not_this_exception_label, exc_found_label)
+            if current_exception_type.find('getelementptr') == -1:  #XXX catch all (except:)
+                self.codewriter.br_uncond(exc_found_label)
+            else:
+                if not last_exception_type:
+                    last_exception_type = self.db.repr_tmpvar()
+                    self.codewriter.load(last_exception_type, lltype_of_exception_type, '%last_exception_type')
+                    #self.codewriter.newline()
+                ll_issubclass_cond = self.db.repr_tmpvar()
+                self.codewriter.call(ll_issubclass_cond,
+                                     'bool',
+                                     ll_exception_match,
+                                     [last_exception_type, current_exception_type],
+                                     [lltype_of_exception_type, lltype_of_exception_type])
+                self.codewriter.br(ll_issubclass_cond, not_this_exception_label, exc_found_label)
+
             self.codewriter.label(not_this_exception_label)
 
-        self.codewriter.comment('this code should never be reached!')
+        self.codewriter.comment('reraise when exception is not caught')
         self.codewriter.unwind()
-        #self.codewriter.br_uncond(none_label)
+
         for label, target in exc_found_labels:
             self.codewriter.label(label)
             self.codewriter.br_uncond(target)

Modified: pypy/dist/pypy/translator/llvm2/test/test_exception.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_exception.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_exception.py	Tue Aug  2 15:02:05 2005
@@ -11,6 +11,8 @@
         self.n = n
 
 def getitem(l, i):  #LookupError, KeyError
+    if not isinstance(i, int):
+        raise LookupError
     if i < 0:
         i = len(l) - i
     if i>= len(l):
@@ -18,7 +20,6 @@
     return l[i]
 
 def test_simple1():
-    #py.test.skip("not working yet")
     def raise_(i):
         if i:
             raise TestException()
@@ -37,8 +38,6 @@
     assert f(1) == fn(1)
 
 def test_simple2():
-    #py.test.skip("not working yet, lst[n] raises no exceptions")
-    py.test.skip('failing')
     def fn(n):
         lst = range(10)
         try:
@@ -52,7 +51,6 @@
     assert f(10) == fn(10)
 
 def test_simple3():
-    #py.test.skip("not working yet")
     def raise_(i):
         if i == 0:
             raise TestException()
@@ -79,8 +77,6 @@
     assert f(2) == fn(2)
 
 def test_pass_exc():
-    #py.test.skip("not working yet, lst[n] raises no exceptions")
-    py.test.skip('failing')
     def fn(n):
         lst = range(10)
         try:
@@ -93,20 +89,19 @@
     assert f( 0) == fn( 0)
     assert f(10) == fn(10)
 
-def test_divzero():
-    py.test.skip("not working yet")
-    def fn(n):
-        try:
-            n/0
-        except:
-            return 2
-        return 4
-    f = compile_function(fn, [int])
-    assert f(0) == fn(0)
+#def test_divzero():
+#    py.test.skip("divzero not working yet")
+#    def fn(n):
+#        try:
+#            n/0
+#        except:
+#            return 2
+#        return 4
+#    f = compile_function(fn, [int])
+#    assert f(0) == fn(0)
     
 def test_reraise1():
-    #py.test.skip("not working yet, lst[n] raises no exceptions")
-    py.test.skip('failing')
+    py.test.skip("failing") #uncaught exception causes exit!
     def fn(n):
         lst = range(10)
         try:
@@ -120,8 +115,7 @@
     assert f(10) == fn(10)
 
 def test_reraise2():
-    #py.test.skip("not working yet, lst[n] raises no exceptions")
-    py.test.skip('failing')
+    py.test.skip("failing")  #uncaught exception causes exit!
     def fn(n):
         lst = range(10)
         try:
@@ -135,7 +129,6 @@
     assert f(10) == fn(10)
 
 def test_simple_exception():
-    #py.test.skip("not working yet, lst[n] raises no exceptions")
     def fn(n):
         lst = range(10)
         try:
@@ -150,8 +143,7 @@
         assert f(i) == fn(i)
 
 def test_two_exceptions():
-    #py.test.skip("not working yet, lst[n] raises no exceptions")
-    py.test.skip('failing')
+    py.test.skip("failing")
     def fn(n):
         lst = range(10)
         try:
@@ -168,8 +160,6 @@
         assert f(i) == fn(i)
 
 def test_catch_base_exception():
-    py.test.skip('aborted')    
-    #py.test.skip("not working yet, lst[n] raises no exceptions")
     def fn(n):
         lst = range(10)
         try:
@@ -183,9 +173,8 @@
     for i in range(10, 20):
         assert f(i) == fn(i)
 
-
 def test_catches():
-    py.test.skip("not working yet")
+    py.test.skip("failing") #"except: exception, value" not implemented yet
     def raises(i):
         if i == 3:
             raise MyException, 12
@@ -209,7 +198,6 @@
     assert f(13) == fn(13)
 
 def test_try_raise_choose():
-    py.test.skip("not working yet")
     f = compile_function(try_raise_choose, [int])
     for i in [-1, 0, 1, 2]:
         assert f(i) == i



More information about the Pypy-commit mailing list