[pypy-svn] r23872 - in pypy/dist/pypy/rpython: . lltypesystem ootypesystem test

nik at codespeak.net nik at codespeak.net
Wed Mar 1 23:56:32 CET 2006


Author: nik
Date: Wed Mar  1 23:56:23 2006
New Revision: 23872

Added:
   pypy/dist/pypy/rpython/exceptiondata.py
      - copied, changed from r23857, pypy/dist/pypy/rpython/lltypesystem/exceptiondata.py
   pypy/dist/pypy/rpython/ootypesystem/exceptiondata.py
      - copied, changed from r23857, pypy/dist/pypy/rpython/lltypesystem/exceptiondata.py
Modified:
   pypy/dist/pypy/rpython/lltypesystem/exceptiondata.py
   pypy/dist/pypy/rpython/ootypesystem/rclass.py
   pypy/dist/pypy/rpython/rtyper.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
   pypy/dist/pypy/rpython/typesystem.py
Log:
(pedronis, nik)
made an rpbc test working for ootype that was (accidentally) using
exceptions. factored out an abstract ExceptionData class to share
between the two type systems. ExceptionData of ootypesystem will
need more work once we get to explicit exception tests.


Modified: pypy/dist/pypy/rpython/lltypesystem/exceptiondata.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/exceptiondata.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/exceptiondata.py	Wed Mar  1 23:56:23 2006
@@ -4,25 +4,12 @@
 from pypy.rpython.lltypesystem.lltype import \
      Array, malloc, Ptr, PyObject, pyobjectptr, \
      FuncType, functionptr, Signed
+from pypy.rpython.exceptiondata import AbstractExceptionData
 from pypy.rpython.extfunctable import standardexceptions
 from pypy.annotation.classdef import FORCE_ATTRIBUTES_INTO_CLASSES
 
-class ExceptionData:
+class ExceptionData(AbstractExceptionData):
     """Public information for the code generators to help with exceptions."""
-    standardexceptions = standardexceptions
-
-    def __init__(self, rtyper):
-        self.make_standard_exceptions(rtyper)
-        # (NB. rclass identifies 'Exception' and 'object')
-        r_type = rclass.getclassrepr(rtyper, None)
-        r_instance = rclass.getinstancerepr(rtyper, None)
-        r_type.setup()
-        r_instance.setup()
-        self.r_exception_type  = r_type
-        self.r_exception_value = r_instance
-        self.lltype_of_exception_type  = r_type.lowleveltype
-        self.lltype_of_exception_value = r_instance.lowleveltype
-
 
     def make_helpers(self, rtyper):
         # create helper functionptrs
@@ -31,14 +18,6 @@
         self.fn_pyexcclass2exc   = self.make_pyexcclass2exc(rtyper)
         self.fn_raise_OSError    = self.make_raise_OSError(rtyper)
 
-
-    def make_standard_exceptions(self, rtyper):
-        bk = rtyper.annotator.bookkeeper
-        for cls in self.standardexceptions:
-            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)

Modified: pypy/dist/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rclass.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rclass.py	Wed Mar  1 23:56:23 2006
@@ -218,8 +218,10 @@
                 self.classdef.classdesc.find_source_for("__init__") is not None:
             s_init = self.classdef.classdesc.s_get_value(self.classdef,
                     '__init__')
-            mangled = mangle("__init__")
-            allmethods[mangled] = "__init__", s_init
+            if isinstance(s_init, annmodel.SomePBC):
+                mangled = mangle("__init__")
+                allmethods[mangled] = "__init__", s_init
+            # else: it's the __init__ of a builtin exception
             
         #
         # hash() support

Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py	(original)
+++ pypy/dist/pypy/rpython/rtyper.py	Wed Mar  1 23:56:23 2006
@@ -66,12 +66,7 @@
         for s_primitive, lltype in annmodel.annotation_to_ll_map:
             r = self.getrepr(s_primitive)
             self.primitive_to_repr[r.lowleveltype] = r
-        if type_system == "lltype":
-            from pypy.rpython.lltypesystem.exceptiondata import ExceptionData
-
-            self.exceptiondata = ExceptionData(self)
-        else:
-            self.exceptiondata = None
+        self.exceptiondata = self.type_system.exceptiondata.ExceptionData(self)
 
         try:
             self.seed = int(os.getenv('RTYPERSEED'))

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Wed Mar  1 23:56:23 2006
@@ -805,31 +805,31 @@
         res = interpret(f, [3, 0], type_system=self.ts)
         assert res == 5
 
-def test_various_patterns_but_one_signature_method():
-    class A:
-        def meth(self, a, b=0):
-            raise NotImplementedError
-    class B(A):
-        def meth(self, a, b=0):
-            return a+b
+    def test_various_patterns_but_one_signature_method(self):
+        class A:
+            def meth(self, a, b=0):
+                raise NotImplementedError
+        class B(A):
+            def meth(self, a, b=0):
+                return a+b
+            
+        class C(A):
+            def meth(self, a, b=0):
+                return a*b
+        def f(i):
+            if i == 0:
+                x = B()
+            else:
+                x = C()
+            r1 = x.meth(1)
+            r2 = x.meth(3, 2)
+            r3 = x.meth(7, b=11)
+            return r1+r2+r3
+        res = interpret(f, [0], type_system=self.ts)
+        assert res == 1+3+2+7+11
+        res = interpret(f, [1], type_system=self.ts)
+        assert res == 3*2+11*7
         
-    class C(A):
-        def meth(self, a, b=0):
-            return a*b
-    def f(i):
-        if i == 0:
-            x = B()
-        else:
-            x = C()
-        r1 = x.meth(1)
-        r2 = x.meth(3, 2)
-        r3 = x.meth(7, b=11)
-        return r1+r2+r3
-    res = interpret(f, [0])
-    assert res == 1+3+2+7+11
-    res = interpret(f, [1])
-    assert res == 3*2+11*7
-    
 
 def test_multiple_ll_one_hl_op():
     class E(Exception):

Modified: pypy/dist/pypy/rpython/typesystem.py
==============================================================================
--- pypy/dist/pypy/rpython/typesystem.py	(original)
+++ pypy/dist/pypy/rpython/typesystem.py	Wed Mar  1 23:56:23 2006
@@ -18,7 +18,7 @@
                                   None, None, ['__doc__'])
             except ImportError:
                 return None
-        if name in ('rclass', 'rpbc', 'rbuiltin'):
+        if name in ('rclass', 'rpbc', 'rbuiltin', 'exceptiondata'):
             mod = load(name)
             if mod is not None:
                 setattr(self, name, mod)



More information about the Pypy-commit mailing list