[pypy-svn] r34605 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Tue Nov 14 17:46:48 CET 2006
Author: antocuni
Date: Tue Nov 14 17:46:47 2006
New Revision: 34605
Modified:
pypy/dist/pypy/translator/cli/cts.py
pypy/dist/pypy/translator/cli/dotnet.py
pypy/dist/pypy/translator/cli/function.py
pypy/dist/pypy/translator/cli/test/test_dotnet.py
Log:
Added the possibility to inspect the native exception objects.
Modified: pypy/dist/pypy/translator/cli/cts.py
==============================================================================
--- pypy/dist/pypy/translator/cli/cts.py (original)
+++ pypy/dist/pypy/translator/cli/cts.py Tue Nov 14 17:46:47 2006
@@ -147,9 +147,9 @@
elif isinstance(t, lltype.Ptr) and isinstance(t.TO, lltype.OpaqueType):
return self.__class('[mscorlib]System.Object', include_class)
elif isinstance(t, ootype.Instance):
- native_class = t._hints.get('native_class', None)
- if native_class:
- return self.__class(native_class, include_class)
+ NATIVE_INSTANCE = t._hints.get('NATIVE_INSTANCE', None)
+ if NATIVE_INSTANCE:
+ return self.__class(NATIVE_INSTANCE._name, include_class)
else:
name = self.db.pending_class(t)
return self.__class(name, include_class)
Modified: pypy/dist/pypy/translator/cli/dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/dotnet.py (original)
+++ pypy/dist/pypy/translator/cli/dotnet.py Tue Nov 14 17:46:47 2006
@@ -1,7 +1,7 @@
import types
from pypy.annotation.pairtype import pair, pairtype
-from pypy.annotation.model import SomeObject, SomeOOInstance, SomeInteger, s_None,\
+from pypy.annotation.model import SomeObject, SomeInstance, SomeOOInstance, SomeInteger, s_None,\
s_ImpossibleValue, lltype_to_annotation, annotation_to_lltype, SomeChar, SomeString
from pypy.rpython.error import TyperError
from pypy.rpython.extregistry import ExtRegistryEntry
@@ -305,13 +305,13 @@
-native_exc = {}
+native_exc_cache = {}
def NativeException(cliClass):
try:
- return native_exc[cliClass._name]
+ return native_exc_cache[cliClass._name]
except KeyError:
res = _create_NativeException(cliClass)
- native_exc[cliClass._name] = res
+ native_exc_cache[cliClass._name] = res
return res
def _create_NativeException(cliClass):
@@ -324,5 +324,22 @@
else:
# we are not using pythonnet -- create a fake class
res = types.ClassType(TYPE._classname, (Exception,), {})
- res._rpython_hints = {'native_class': cliClass._name}
+ res._rpython_hints = {'NATIVE_INSTANCE': TYPE}
return res
+
+def native_exc(exc):
+ return exc
+
+class Entry(ExtRegistryEntry):
+ _about_ = native_exc
+
+ def compute_result_annotation(self, exc_s):
+ assert isinstance(exc_s, SomeInstance)
+ cls = exc_s.classdef.classdesc.pyobj
+ assert issubclass(cls, Exception)
+ NATIVE_INSTANCE = cls._rpython_hints['NATIVE_INSTANCE']
+ return SomeOOInstance(NATIVE_INSTANCE)
+
+ def specialize_call(self, hop):
+ v_obj, = hop.inputargs(*hop.args_r)
+ return hop.genop('same_as', [v_obj], hop.r_result.lowleveltype)
Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py (original)
+++ pypy/dist/pypy/translator/cli/function.py Tue Nov 14 17:46:47 2006
@@ -28,8 +28,8 @@
def record_ll_meta_exc(self, ll_meta_exc):
# record the type only if it doesn't belong to a native_class
ll_exc = ll_meta_exc._inst.class_._INSTANCE
- native_class = ll_exc._hints.get('native_class', None)
- if native_class is None:
+ NATIVE_INSTANCE = ll_exc._hints.get('NATIVE_INSTANCE', None)
+ if NATIVE_INSTANCE is None:
OOFunction.record_ll_meta_exc(self, ll_meta_exc)
def begin_try(self):
Modified: pypy/dist/pypy/translator/cli/test/test_dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_dotnet.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_dotnet.py Tue Nov 14 17:46:47 2006
@@ -6,7 +6,8 @@
ROOT, overload, Instance, new
from pypy.translator.cli.test.runtest import CliTest
from pypy.translator.cli.dotnet import SomeCliClass, SomeCliStaticMethod,\
- NativeInstance, CLR, box, unbox, OverloadingResolver, NativeException
+ NativeInstance, CLR, box, unbox, OverloadingResolver, NativeException,\
+ native_exc
System = CLR.System
Math = CLR.System.Math
@@ -221,6 +222,18 @@
return True
assert self.interpret(fn, []) == True
+ def test_native_exception_object(self):
+ SystemException = NativeException(CLR.System.Exception)
+ def fn():
+ x = ArrayList()
+ try:
+ x.get_Item(0)
+ return "Impossible!"
+ except SystemException, e:
+ ex = native_exc(e)
+ return ex.get_Message()
+ res = self.ll_to_string(self.interpret(fn, []))
+ assert res.startswith("Index is less than 0")
class TestPythonnet(TestDotnetRtyping):
# don't interpreter functions but execute them directly through pythonnet
More information about the Pypy-commit
mailing list