[pypy-svn] r45109 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Sun Jul 15 21:02:56 CEST 2007
Author: antocuni
Date: Sun Jul 15 21:02:54 2007
New Revision: 45109
Modified:
pypy/dist/pypy/translator/cli/carbonpython.py
pypy/dist/pypy/translator/cli/entrypoint.py
pypy/dist/pypy/translator/cli/gencli.py
pypy/dist/pypy/translator/cli/ilgenerator.py
pypy/dist/pypy/translator/cli/rte.py
pypy/dist/pypy/translator/cli/test/test_carbonpython.py
Log:
the result of my travel from vilnius: tweak gencli until it generates
.netmodules instead of .dll
Modified: pypy/dist/pypy/translator/cli/carbonpython.py
==============================================================================
--- pypy/dist/pypy/translator/cli/carbonpython.py (original)
+++ pypy/dist/pypy/translator/cli/carbonpython.py Sun Jul 15 21:02:54 2007
@@ -15,12 +15,14 @@
from pypy.translator.cli.entrypoint import DllEntryPoint
class DllDef:
- def __init__(self, name, namespace, functions=[]):
+ def __init__(self, name, namespace, functions=[], dontmangle=True, isnetmodule=False):
self.name = name
self.namespace = namespace
self.functions = functions # [(function, annotation), ...]
+ self.isnetmodule = isnetmodule
self.driver = TranslationDriver()
- self.driver.config.translation.ootype.mangle = False
+ if dontmangle:
+ self.driver.config.translation.ootype.mangle = False
self.driver.setup_library(self)
def add_function(self, func, inputtypes):
@@ -28,13 +30,14 @@
def get_entrypoint(self, bk):
graphs = [bk.getdesc(f).cachedgraph(None) for f, _ in self.functions]
- return DllEntryPoint(self.name, graphs)
+ return DllEntryPoint(self.name, graphs, self.isnetmodule)
def compile(self):
# add all functions to the appropriate namespace
- for func, _ in self.functions:
- if not hasattr(func, '_namespace_'):
- func._namespace_ = self.namespace
+ if self.namespace:
+ for func, _ in self.functions:
+ if not hasattr(func, '_namespace_'):
+ func._namespace_ = self.namespace
self.driver.proceed(['compile_cli'])
class export(object):
Modified: pypy/dist/pypy/translator/cli/entrypoint.py
==============================================================================
--- pypy/dist/pypy/translator/cli/entrypoint.py (original)
+++ pypy/dist/pypy/translator/cli/entrypoint.py Sun Jul 15 21:02:54 2007
@@ -15,6 +15,8 @@
return TestEntryPoint(graph)
class BaseEntryPoint(Node):
+ isnetmodule = False
+
def set_db(self, db):
self.db = db
self.cts = CTS(db)
@@ -25,6 +27,7 @@
def output_filename(self, il_filename):
return il_filename.replace('.il', '.exe')
+
class StandaloneEntryPoint(BaseEntryPoint):
"""
This class produces a 'main' method that converts the argv in a
@@ -67,18 +70,22 @@
self.db.pending_function(self.graph)
class DllEntryPoint(BaseEntryPoint):
- def __init__(self, name, graphs):
+ def __init__(self, name, graphs, isnetmodule=False):
self.name = name
self.graphs = graphs
+ self.isnetmodule = isnetmodule
def get_name(self):
return self.name
def ilasm_flags(self):
- return ['/dll']
+ return BaseEntryPoint.ilasm_flags(self) + ['/dll']
def output_filename(self, il_filename):
- return il_filename.replace('.il', '.dll')
+ ext = '.dll'
+ if self.isnetmodule:
+ ext = '.netmodule'
+ return il_filename.replace('.il', ext)
def render(self, ilasm):
for graph in self.graphs:
Modified: pypy/dist/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/dist/pypy/translator/cli/gencli.py (original)
+++ pypy/dist/pypy/translator/cli/gencli.py Sun Jul 15 21:02:54 2007
@@ -76,7 +76,8 @@
if USE_STACKOPT:
return StackOptGenerator(out, self.assembly_name, self.config)
else:
- return IlasmGenerator(out, self.assembly_name, self.config)
+ isnetmodule = self.entrypoint.isnetmodule
+ return IlasmGenerator(out, self.assembly_name, self.config, isnetmodule)
def build_exe(self):
if getoption('source'):
@@ -87,13 +88,15 @@
ilasm = SDK.ilasm()
tmpfile = self.tmpfile.strpath
- self._exec_helper(ilasm, [tmpfile]+self.entrypoint.ilasm_flags(),
+ self.outfile = self.entrypoint.output_filename(tmpfile)
+ argv = [tmpfile,'/output:' + self.outfile] + self.entrypoint.ilasm_flags()
+ self._exec_helper(ilasm, argv,
'ilasm failed to assemble (%s):\n%s\n%s',
timeout = 900)
# Mono's ilasm occasionally deadlocks. We set a timer to avoid
# blocking automated test runs forever.
- self.outfile = self.entrypoint.output_filename(tmpfile)
+
if getoption('verify'):
peverify = SDK.peverify()
self._exec_helper(peverify, [outfile], 'peverify failed to verify (%s):\n%s\n%s')
Modified: pypy/dist/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/dist/pypy/translator/cli/ilgenerator.py (original)
+++ pypy/dist/pypy/translator/cli/ilgenerator.py Sun Jul 15 21:02:54 2007
@@ -46,15 +46,18 @@
class IlasmGenerator(object):
"""
- Generate IL code by writing to a file and compiling it with ilasm
+ Generate IL code by writing to a file and compiling it with ilasm.
"""
- def __init__(self, outfile, name, config):
+ def __init__(self, outfile, name, config, isnetmodule=False):
self.out = outfile
self.config = config
self.code = CodeGenerator(self.out)
self.code.writeline('.assembly extern mscorlib {}')
self.code.writeline('.assembly extern pypylib {}')
- self.code.writeline('.assembly %s {}' % name)
+ if isnetmodule:
+ self.code.writeline('.module %s.netmodule' % name)
+ else:
+ self.code.writeline('.assembly %s {}' % name)
self.code.writeline('.field static object last_exception') # XXX
def close(self):
Modified: pypy/dist/pypy/translator/cli/rte.py
==============================================================================
--- pypy/dist/pypy/translator/cli/rte.py (original)
+++ pypy/dist/pypy/translator/cli/rte.py Sun Jul 15 21:02:54 2007
@@ -82,6 +82,13 @@
FLAGS = ['/t:library', '/unsafe', '/r:main.exe']
DEPENDENCIES = [MainStub]
+class RPythonNetModule(Target):
+ SOURCES = []
+ OUTPUT = 'rpython.netmodule'
+
+ def compile(cls, sources, out):
+ pass
+
class Query(Target):
SOURCES = ['query.cs']
OUTPUT = 'query.exe'
Modified: pypy/dist/pypy/translator/cli/test/test_carbonpython.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_carbonpython.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_carbonpython.py Sun Jul 15 21:02:54 2007
@@ -18,14 +18,12 @@
class TestCarbonPython(CliTest):
- def _csharp(self, reference, source):
+ def _csharp(self, source, references=[], netmodules=[]):
tmpfile = udir.udir.join('tmp.cs')
tmpfile.write(TEMPLATE % source)
- if reference is None:
- flags = []
- else:
- flags = ['/r:%s' % reference]
-
+ flags = ['/r:%s' % ref for ref in references]
+ flags += ['/addmodule:%s' % mod for mod in netmodules]
+
class MyTarget(Target):
SOURCES = [str(tmpfile)]
FLAGS = flags
@@ -36,7 +34,7 @@
return func()
def test_compilation(self):
- res = self._csharp(None, 'Console.WriteLine(42);')
+ res = self._csharp('Console.WriteLine(42);')
assert res == 42
def test_func_namespace(self):
@@ -57,7 +55,7 @@
dll = DllDef('test', 'Test', [(foo, [int]),
(bar, [int])])
dll.compile()
- res = self._csharp('test', 'Console.WriteLine("{0}, {1}", Test.foo(42), Test.bar(42));')
+ res = self._csharp('Console.WriteLine("{0}, {1}", Test.foo(42), Test.bar(42));', ['test'])
assert res == (43, 84)
def test_export(self):
@@ -119,11 +117,11 @@
entrypoints = collect_entrypoints({'MyClass': MyClass})
dll = DllDef('test', 'Test', entrypoints)
dll.compile()
- res = self._csharp('test', """
+ res = self._csharp("""
Test.MyClass obj = new Test.MyClass();
obj.__init__(39);
Console.WriteLine(obj.add(1, 2));
- """)
+ """, ['test'])
assert res == 42
def test_export_cliclass(self):
@@ -136,27 +134,36 @@
entrypoints = collect_entrypoints({'getitem': getitem})
dll = DllDef('test', 'Test', entrypoints)
dll.compile()
- res = self._csharp('test', """
+ res = self._csharp("""
ArrayList obj = new ArrayList();
obj.Add(42);
Console.WriteLine(Test.getitem(obj, 0));
- """)
+ """, ['test'])
assert res == 42
def test_compile_dll(self):
cwd, _ = os.path.split(__file__)
mylib_py = os.path.join(cwd, 'mylib.py')
compile_dll(mylib_py, copy_dll=False)
- res = self._csharp('mylib', """
+ res = self._csharp("""
Console.WriteLine(mylib.sum(20, 22));
- """)
+ """, ['mylib'])
assert res == 42
def test_compile_dll_alternative_name(self):
cwd, _ = os.path.split(__file__)
mylib_py = os.path.join(cwd, 'mylib.py')
compile_dll(mylib_py, 'mylibxxx.dll', copy_dll=False)
- res = self._csharp('mylibxxx', """
+ res = self._csharp("""
Console.WriteLine(mylibxxx.sum(20, 22));
- """)
+ """, ['mylibxxx'])
assert res == 42
+
+ def test_compile_netmodule(self):
+ def foo(x):
+ return x+1
+ dll = DllDef('mymodule', 'Test', [(foo, [int])], isnetmodule=True)
+ dll.compile()
+ res = self._csharp('Console.WriteLine("{0}", Test.foo(41));',
+ netmodules = ['mymodule'])
+
More information about the pypy-svn
mailing list