[pypy-svn] r69130 - in pypy/trunk/pypy/translator: cli cli/test oosupport
antocuni at codespeak.net
antocuni at codespeak.net
Tue Nov 10 18:57:26 CET 2009
Author: antocuni
Date: Tue Nov 10 18:57:25 2009
New Revision: 69130
Modified:
pypy/trunk/pypy/translator/cli/function.py
pypy/trunk/pypy/translator/cli/test/test_dotnet.py
pypy/trunk/pypy/translator/oosupport/function.py
Log:
ugly workaround to make the exceptiontranformer work with .NET valuetypes
Modified: pypy/trunk/pypy/translator/cli/function.py
==============================================================================
--- pypy/trunk/pypy/translator/cli/function.py (original)
+++ pypy/trunk/pypy/translator/cli/function.py Tue Nov 10 18:57:25 2009
@@ -139,6 +139,21 @@
self.store(link.last_exc_value)
self._setup_link(link)
+ def _dont_store(self, to_load, to_store):
+ # ugly workaround to make the exceptiontransformer work with
+ # valuetypes: when exceptiontransforming a function whose result is a
+ # .NET valuetype, it tries to store a null into the return variable.
+ # Since it is not possible to store a null into a valuetype, and that
+ # in that case the value is not used anyway, we simply ignore it.
+ from pypy.translator.cli.dotnet import NativeInstance
+ if isinstance(to_load, flowmodel.Constant):
+ value = to_load.value
+ is_null = not value
+ T = ootype.typeOf(to_load.value)
+ if isinstance(T, NativeInstance) and T._is_value_type and is_null:
+ return True
+ return OOFunction._dont_store(self, to_load, to_store)
+
def render_numeric_switch(self, block):
if block.exitswitch.concretetype in (ootype.SignedLongLong, ootype.UnsignedLongLong):
# TODO: it could be faster to check is the values fit in
Modified: pypy/trunk/pypy/translator/cli/test/test_dotnet.py
==============================================================================
--- pypy/trunk/pypy/translator/cli/test/test_dotnet.py (original)
+++ pypy/trunk/pypy/translator/cli/test/test_dotnet.py Tue Nov 10 18:57:25 2009
@@ -632,6 +632,20 @@
return d[OpCodes.Add]
assert self.interpret(fn, []) == 42
+ def test_valuetype_exceptiontransform(self):
+ def foo(x):
+ if x:
+ return OpCodes.Add
+ raise ValueError
+ def fn(x):
+ try:
+ foo(x)
+ return False
+ except ValueError:
+ return True
+ res = self.interpret(fn, [0], exctrans=True)
+ assert res
+
def test_classof(self):
int32_class = classof(System.Int32)
def fn():
@@ -694,7 +708,7 @@
class TestPythonnet(TestDotnetRtyping):
# don't interpreter functions but execute them directly through pythonnet
- def interpret(self, f, args, backendopt='ignored'):
+ def interpret(self, f, args, backendopt='ignored', exctrans='ignored'):
return f(*args)
def _skip_pythonnet(self, msg):
Modified: pypy/trunk/pypy/translator/oosupport/function.py
==============================================================================
--- pypy/trunk/pypy/translator/oosupport/function.py (original)
+++ pypy/trunk/pypy/translator/oosupport/function.py Tue Nov 10 18:57:25 2009
@@ -321,6 +321,9 @@
self._setup_link(link)
self.generator.branch_unconditionally(target_label)
+ def _dont_store(self, to_load, to_store):
+ return False
+
def _setup_link(self, link):
target = link.target
linkvars = []
@@ -329,6 +332,8 @@
continue
if to_load.concretetype is ootype.Void:
continue
+ if self._dont_store(to_load, to_store):
+ continue
linkvars.append((to_load, to_store))
# after SSI_to_SSA it can happen to have to_load = [a, b] and
More information about the Pypy-commit
mailing list