[pypy-svn] r25298 - in pypy/dist/pypy/rpython: . test

nik at codespeak.net nik at codespeak.net
Tue Apr 4 16:36:41 CEST 2006


Author: nik
Date: Tue Apr  4 16:36:39 2006
New Revision: 25298

Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/test/test_llinterp.py
Log:
(pedronis, nik)
exceptions that escape out of the llinterpreter were only working
with the lltypesystem. generalize this for ootypesystem.


Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Tue Apr  4 16:36:39 2006
@@ -23,7 +23,14 @@
             extra = extra.replace('\n', '\n | ') + '\n `------'
         else:
             extra = ''
-        return '<LLException %r%s>' % (''.join(etype.name).rstrip('\x00'), extra)
+        return '<LLException %r%s>' % (type_name(etype), extra)
+
+def type_name(etype):
+    if isinstance(lltype.typeOf(etype), lltype.Ptr):
+        return ''.join(etype.name).rstrip('\x00')
+    else:
+        # ootype!
+        return etype.class_._INSTANCE._name.split(".")[-1] 
 
 class LLInterpreter(object):
     """ low level interpreter working with concrete values. """
@@ -94,14 +101,19 @@
         assert isinstance(exc, LLException)
         import exceptions
         klass, inst = exc.args[0], exc.args[1]
-        # indirect way to invoke fn_pyexcclass2exc, for memory/test/test_llinterpsim
-        f = self.typer.getexceptiondata().fn_pyexcclass2exc
-        obj = self.typer.type_system.deref(f)
-        ll_pyexcclass2exc_graph = obj.graph
-        for cls in exceptions.__dict__.values():
-            if type(cls) is type(Exception):
-                if self.eval_graph(ll_pyexcclass2exc_graph, [lltype.pyobjectptr(cls)]).typeptr == klass:
-                    return cls
+        exdata = self.typer.getexceptiondata()
+        frame = LLFrame(None, [], self)
+        old_active_frame = self.active_frame
+        try:
+            for cls in exceptions.__dict__.values():
+                if type(cls) is type(Exception):
+                    evalue = frame.op_direct_call(exdata.fn_pyexcclass2exc,
+                            lltype.pyobjectptr(cls))
+                    etype = frame.op_direct_call(exdata.fn_type_of_exc_inst, evalue)
+                    if etype == klass:
+                        return cls
+        finally:
+            self.active_frame = old_active_frame
         raise ValueError, "couldn't match exception"
 
 
@@ -126,7 +138,7 @@
 
 class LLFrame(object):
     def __init__(self, graph, args, llinterpreter, f_back=None):
-        assert isinstance(graph, FunctionGraph)
+        assert not graph or isinstance(graph, FunctionGraph)
         self.graph = graph
         self.args = args
         self.llinterpreter = llinterpreter

Modified: pypy/dist/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llinterp.py	(original)
+++ pypy/dist/pypy/rpython/test/test_llinterp.py	Tue Apr  4 16:36:39 2006
@@ -128,6 +128,8 @@
     assert res == 41
     interpret_raises(IndexError, raise_exception, [42])
     interpret_raises(ValueError, raise_exception, [43])
+    interpret_raises(IndexError, raise_exception, [42], type_system="ootype")
+    interpret_raises(ValueError, raise_exception, [43], type_system="ootype")
 
 def test_call_raise():
     res = interpret(call_raise, [41])



More information about the Pypy-commit mailing list