[pypy-svn] r51926 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Thu Feb 28 18:39:17 CET 2008
Author: antocuni
Date: Thu Feb 28 18:39:16 2008
New Revision: 51926
Modified:
pypy/dist/pypy/translator/cli/dotnet.py
pypy/dist/pypy/translator/cli/test/test_dotnet.py
Log:
add a way to store instances of System.Type as PBCs. It is a bit
convoluted because it converts them into values of type ootype.Class,
then it does a cast at runtime via box/clidowncast, but it's the best
we can do until we refactor the way .NET is accessed within RPython.
Modified: pypy/dist/pypy/translator/cli/dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/dotnet.py (original)
+++ pypy/dist/pypy/translator/cli/dotnet.py Thu Feb 28 18:39:16 2008
@@ -360,6 +360,11 @@
return CLR.System.Char(x)
else:
return CLR.System.String(x)
+ elif isinstance(x, ootype._class):
+ name = '%s.%s' % (x._INSTANCE._namespace, x._INSTANCE._classname)
+ t = CLR.System.Type.GetType(name)
+ assert t is not None
+ return t
elif isinstance(x, PythonNet.System.Object):
return x
elif x is None:
@@ -555,6 +560,12 @@
TYPE = cliClass._INSTANCE
return PythonNet.System.Type.GetType(TYPE._assembly_qualified_name)
+
+def classof(cliClass):
+ assert isinstance(cliClass, CliClass)
+ TYPE = cliClass._INSTANCE
+ return ootype._class(TYPE)
+
class Entry(ExtRegistryEntry):
_about_ = typeof
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 Thu Feb 28 18:39:16 2008
@@ -8,7 +8,7 @@
from pypy.translator.cli.dotnet import SomeCliClass, SomeCliStaticMethod,\
NativeInstance, CLR, box, unbox, OverloadingResolver, NativeException,\
native_exc, new_array, init_array, typeof, eventhandler, clidowncast,\
- fieldinfo_for_const
+ fieldinfo_for_const, classof
System = CLR.System
ArrayList = CLR.System.Collections.ArrayList
@@ -604,6 +604,14 @@
res = self.interpret(fn, [])
assert res == 42
+ def test_classof(self):
+ int32_class = classof(System.Int32)
+ def fn():
+ int32_obj = box(int32_class)
+ int32_type = clidowncast(int32_obj, System.Type)
+ return int32_type.get_Name()
+ assert self.interpret(fn, []) == 'Int32'
+
class TestPythonnet(TestDotnetRtyping):
# don't interpreter functions but execute them directly through pythonnet
def interpret(self, f, args, backendopt='ignored'):
More information about the pypy-svn
mailing list