[pypy-svn] r50935 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Wed Jan 23 17:30:27 CET 2008
Author: antocuni
Date: Wed Jan 23 17:30:27 2008
New Revision: 50935
Modified:
pypy/dist/pypy/translator/cli/query.py
pypy/dist/pypy/translator/cli/test/test_dotnet.py
Log:
add support to access classes defined in pypylib from rpython
Modified: pypy/dist/pypy/translator/cli/query.py
==============================================================================
--- pypy/dist/pypy/translator/cli/query.py (original)
+++ pypy/dist/pypy/translator/cli/query.py Wed Jan 23 17:30:27 2008
@@ -13,10 +13,30 @@
Types = {} # TypeName -> ClassDesc
Namespaces = set()
mscorlib = 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
+pypylib = 'pypylib, Version=0.0.0.0, Culture=neutral'
#_______________________________________________________________________________
# This is the public interface of query.py
+def get_cli_class(name):
+ desc = get_class_desc(name)
+ return desc.get_cliclass()
+
+#_______________________________________________________________________________
+
+def load_pypylib():
+ from pypy.translator.cli.rte import get_pypy_dll
+ dll = get_pypy_dll()
+ try:
+ import clr
+ from System.Reflection import Assembly
+ except ImportError:
+ pass
+ else:
+ Assembly.LoadFrom(dll)
+ clr.AddReference(pypylib)
+ load_assembly(pypylib)
+
def load_assembly(name):
if name in Assemblies:
return
@@ -41,13 +61,6 @@
Types.update(types)
-def get_cli_class(name):
- desc = get_class_desc(name)
- return desc.get_cliclass()
-
-#_______________________________________________________________________________
-
-
def get_cachedir():
import pypy
_cache = py.path.local(pypy.__file__).new(basename='_cache').ensure(dir=1)
@@ -128,13 +141,18 @@
if self._cliclass is not None:
return self._cliclass
-
- assert self.Assembly.startswith('mscorlib') # TODO: support external assemblies
+
+ if self.Assembly == mscorlib:
+ assembly = '[mscorlib]'
+ elif self.Assembly == pypylib:
+ assembly = '[pypylib]'
+ else:
+ assert False, 'TODO: support external assemblies'
namespace, name = self.FullName.rsplit('.', 1)
# construct OOTYPE and CliClass
# no superclass for now, will add it later
- TYPE = NativeInstance('[mscorlib]', namespace, name, None, {}, {})
+ TYPE = NativeInstance(assembly, namespace, name, None, {}, {})
TYPE._is_value_type = self.IsValueType
Class = CliClass(TYPE, {}, {})
self._cliclass = Class
@@ -194,6 +212,7 @@
assert self._name is None, '_buildtree can be called only on top-level CLR, not on namespaces'
from pypy.translator.cli.support import getattr_ex
load_assembly(mscorlib)
+ load_pypylib()
for fullname in sorted(list(Namespaces)):
if '.' in fullname:
parent, name = fullname.rsplit('.', 1)
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 Wed Jan 23 17:30:27 2008
@@ -440,6 +440,12 @@
res = self.interpret(fn, [])
assert self.ll_to_string(res) == 'add'
+ def test_pypylib(self):
+ def fn():
+ return CLR.pypy.runtime.Utils.OOString(42, -1)
+ res = self.interpret(fn, [])
+ assert self.ll_to_string(res) == '42'
+
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