[pypy-svn] r20298 - in pypy/branch/somepbc-refactoring/pypy/rpython: . lltypesystem test

pedronis at codespeak.net pedronis at codespeak.net
Sun Nov 27 02:13:50 CET 2005


Author: pedronis
Date: Sun Nov 27 02:13:49 2005
New Revision: 20298

Modified:
   pypy/branch/somepbc-refactoring/pypy/rpython/llinterp.py
   pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/exceptiondata.py
   pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py
   pypy/branch/somepbc-refactoring/pypy/rpython/test/test_exception.py
   pypy/branch/somepbc-refactoring/pypy/rpython/typesystem.py
Log:
started reenabling exception support in rtyper and llinterp.

added logic to getcallable such that a _callable is attached to function pointer as expected and
so that suggested_primitive helpers are run by llinterp direclty avoid infinite recursion.



Modified: pypy/branch/somepbc-refactoring/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/llinterp.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/llinterp.py	Sun Nov 27 02:13:49 2005
@@ -195,8 +195,8 @@
                 cls, inst = e.args
                 for link in block.exits[1:]:
                     assert issubclass(link.exitcase, Exception)
-                    if self.llinterpreter.eval_function(
-                        exdata.ll_exception_match, [cls, link.llexitcase]):
+                    if self.llinterpreter.eval_graph(
+                        exdata.ll_exception_match_graph, [cls, link.llexitcase]):
                         self.setifvar(link.last_exception, cls)
                         self.setifvar(link.last_exc_value, inst)
                         break

Modified: pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/exceptiondata.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/exceptiondata.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/exceptiondata.py	Sun Nov 27 02:13:49 2005
@@ -26,51 +26,54 @@
 
     def make_helpers(self, rtyper):
         # create helper functions
-        self.ll_exception_match  = self.make_exception_matcher(rtyper)
-        self.ll_type_of_exc_inst = self.make_type_of_exc_inst(rtyper)
-        self.ll_pyexcclass2exc   = self.make_pyexcclass2exc(rtyper)
-        self.ll_raise_OSError    = self.make_raise_OSError(rtyper)
+        self.ll_exception_match_graph  = self.make_exception_matcher(rtyper)
+        self.ll_type_of_exc_inst_graph = self.make_type_of_exc_inst(rtyper)
+        self.ll_pyexcclass2exc_graph   = self.make_pyexcclass2exc(rtyper)
+        self.ll_raise_OSError_graph    = self.make_raise_OSError(rtyper)
 
 
     def make_standard_exceptions(self, rtyper):
         bk = rtyper.annotator.bookkeeper
         for cls in self.standardexceptions:
-            classdef = bk.getclassdef(cls)
+            classdef = bk.getuniqueclassdef(cls)
             rclass.getclassrepr(rtyper, classdef).setup()
 
 
     def make_exception_matcher(self, rtyper):
         # ll_exception_matcher(real_exception_vtable, match_exception_vtable)
         s_typeptr = annmodel.SomePtr(self.lltype_of_exception_type)
-        dontcare, spec_function = annotate_lowlevel_helper(
+        helper_graph = annotate_lowlevel_helper(
             rtyper.annotator, rclass.ll_issubclass, [s_typeptr, s_typeptr])
-        return spec_function
+        return helper_graph
 
 
     def make_raise_OSError(self, rtyper):
         # ll_raise_OSError(errno)
         def ll_raise_OSError(errno):
             raise OSError(errno, None)
-        dontcare, spec_function = annotate_lowlevel_helper(
+        helper_graph = annotate_lowlevel_helper(
             rtyper.annotator, ll_raise_OSError, [annmodel.SomeInteger()])
-        return spec_function
+        return helper_graph
 
 
     def make_type_of_exc_inst(self, rtyper):
         # ll_type_of_exc_inst(exception_instance) -> exception_vtable
         s_excinst = annmodel.SomePtr(self.lltype_of_exception_value)
-        dontcare, spec_function = annotate_lowlevel_helper(
+        helper_graph = annotate_lowlevel_helper(
             rtyper.annotator, rclass.ll_type, [s_excinst])
-        return spec_function
+        return helper_graph
 
 
     def make_pyexcclass2exc(self, rtyper):
         # ll_pyexcclass2exc(python_exception_class) -> exception_instance
         table = {}
+        Exception_def = rtyper.annotator.bookkeeper.getuniqueclassdef(Exception)
         for clsdef in rtyper.class_reprs:
-            if (clsdef and clsdef.cls is not Exception
-                and issubclass(clsdef.cls, Exception)):
-                cls = clsdef.cls
+            if (clsdef and clsdef is not Exception_def
+                and clsdef.issubclass(Exception_def)):
+                if not hasattr(clsdef.classdesc, 'pyobj'):
+                    continue
+                cls = clsdef.classdesc.pyobj
                 if cls in self.standardexceptions and cls not in FORCE_ATTRIBUTES_INTO_CLASSES:
                     is_standard = True
                     assert not clsdef.attrs, (
@@ -136,6 +139,6 @@
             return default_excinst
 
         s_pyobj = annmodel.SomePtr(Ptr(PyObject))
-        dontcare, spec_function = annotate_lowlevel_helper(
+        helper_graph = annotate_lowlevel_helper(
             rtyper.annotator, ll_pyexcclass2exc, [s_pyobj])
-        return spec_function
+        return helper_graph

Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py	Sun Nov 27 02:13:49 2005
@@ -64,7 +64,7 @@
         for s_primitive, lltype in annmodel.annotation_to_ll_map:
             r = self.getrepr(s_primitive)
             self.primitive_to_repr[r.lowleveltype] = r
-        if 0:  # XXX for now XXX type_system == "lltype":
+        if type_system == "lltype":
             from pypy.rpython.lltypesystem.exceptiondata import ExceptionData
 
             self.exceptiondata = ExceptionData(self)

Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_exception.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_exception.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_exception.py	Sun Nov 27 02:13:49 2005
@@ -36,20 +36,23 @@
     t = Translator(f)
     a = t.annotate([int])
     t.specialize()
-    data = t.rtyper.getexceptiondata()
+    excdata = t.rtyper.getexceptiondata()
+    ll_pyexcclass2exc = excdata.ll_pyexcclass2exc_graph.func # original callable version
+    getcdef = a.bookkeeper.getuniqueclassdef
+
     #t.view()
-    ovferr_inst = data.ll_pyexcclass2exc(pyobjectptr(OverflowError))
-    classdef = a.bookkeeper.getclassdef(OverflowError)
+    ovferr_inst = ll_pyexcclass2exc(pyobjectptr(OverflowError))
+    classdef = getcdef(OverflowError)
     assert ovferr_inst.typeptr == t.rtyper.class_reprs[classdef].getvtable()
 
-    taberr_inst = data.ll_pyexcclass2exc(pyobjectptr(TabError))
-    classdef = a.bookkeeper.getclassdef(StandardError) # most precise class seen
+    taberr_inst = ll_pyexcclass2exc(pyobjectptr(TabError))
+    classdef = getcdef(StandardError) # most precise class seen
     assert taberr_inst.typeptr == t.rtyper.class_reprs[classdef].getvtable()
 
-    myerr_inst = data.ll_pyexcclass2exc(pyobjectptr(MyException))
+    myerr_inst = ll_pyexcclass2exc(pyobjectptr(MyException))
     assert myerr_inst.typeptr == t.rtyper.class_reprs[None].getvtable()
 
-    strgerr_inst = data.ll_pyexcclass2exc(pyobjectptr(MyStrangeException))
+    strgerr_inst = ll_pyexcclass2exc(pyobjectptr(MyStrangeException))
     assert strgerr_inst.typeptr == t.rtyper.class_reprs[None].getvtable()
 
 

Modified: pypy/branch/somepbc-refactoring/pypy/rpython/typesystem.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/typesystem.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/typesystem.py	Sun Nov 27 02:13:49 2005
@@ -44,7 +44,10 @@
         typ, constr = self.callable_trait
         
         FT = typ(llinputs, lloutput)
-        return constr(FT, graph.name, graph = graph)
+        if hasattr(graph, 'func') and callable(graph.func):
+            return constr(FT, graph.name, graph = graph, _callable = graph.func)
+        else:
+            return constr(FT, graph.name, graph = graph)
 
     def getconcretetype(self, v):
         """Helper called by getcallable() to get the conrete type of a variable



More information about the Pypy-commit mailing list