[pypy-svn] r26496 - in pypy/dist/pypy/rpython/ootypesystem: . test
nik at codespeak.net
nik at codespeak.net
Fri Apr 28 09:28:30 CEST 2006
Author: nik
Date: Fri Apr 28 09:28:26 2006
New Revision: 26496
Modified:
pypy/dist/pypy/rpython/ootypesystem/exceptiondata.py
pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py
Log:
(sanxiyn, dialtone, samuele, nik)
added a helper to exceptiondata to check if an Instance is derived from
Exception. the interesting part of this was writing a test for it. ;)
Modified: pypy/dist/pypy/rpython/ootypesystem/exceptiondata.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/exceptiondata.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/exceptiondata.py Fri Apr 28 09:28:26 2006
@@ -8,6 +8,18 @@
class ExceptionData(AbstractExceptionData):
"""Public information for the code generators to help with exceptions."""
+ def __init__(self, rtyper):
+ AbstractExceptionData.__init__(self, rtyper)
+ self._compute_exception_instance(rtyper)
+
+ def _compute_exception_instance(self, rtyper):
+ excdef = rtyper.annotator.bookkeeper.getuniqueclassdef(Exception)
+ excrepr = rclass.getinstancerepr(rtyper, excdef)
+ self._EXCEPTION_INST = excrepr.lowleveltype
+
+ def is_exception_instance(self, INSTANCE):
+ return ootype.isSubclass(INSTANCE, self._EXCEPTION_INST)
+
def make_helpers(self, rtyper):
self.fn_exception_match = self.make_exception_matcher(rtyper)
self.fn_pyexcclass2exc = self.make_pyexcclass2exc(rtyper)
Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py Fri Apr 28 09:28:26 2006
@@ -172,4 +172,18 @@
res = interpret(oof, [], type_system='ootype')
+def test_is_exception_instance():
+ def f():
+ return NameError()
+
+ t = TranslationContext()
+ t.buildannotator().build_types(f, [])
+ if conftest.option.view:
+ t.view()
+ rtyper = t.buildrtyper(type_system="ootype")
+ rtyper.specialize()
+ graph = graphof(t, f)
+
+ INST = graph.getreturnvar().concretetype
+ assert rtyper.exceptiondata.is_exception_instance(INST)
More information about the Pypy-commit
mailing list