[pypy-svn] r28822 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Thu Jun 15 16:24:37 CEST 2006
Author: antocuni
Date: Thu Jun 15 16:24:31 2006
New Revision: 28822
Modified:
pypy/dist/pypy/translator/cli/gencli.py
pypy/dist/pypy/translator/cli/test/runtest.py
Log:
- Split old compile_function into a compile_function function and a
CliFunctionWrapper class.
- Some bugfixes.
Modified: pypy/dist/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/dist/pypy/translator/cli/gencli.py (original)
+++ pypy/dist/pypy/translator/cli/gencli.py Thu Jun 15 16:24:31 2006
@@ -89,7 +89,6 @@
names.add(graph.name)
def build_exe(self):
- tmpfile = self.generate_source()
if getoption('source'):
return None
@@ -97,8 +96,9 @@
shutil.copy(pypy_dll, self.tmpdir.strpath)
ilasm = SDK.ilasm()
+ tmpfile = self.tmpfile.strpath
proc = subprocess.Popen([ilasm, tmpfile], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
retval = proc.wait()
- assert retval == 0, 'ilasm failed to assemble %s (%s):\n%s' % (self.graph.name, tmpfile, stdout)
+ assert retval == 0, 'ilasm failed to assemble (%s):\n%s' % (tmpfile, stdout)
return tmpfile.replace('.il', '.exe')
Modified: pypy/dist/pypy/translator/cli/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/runtest.py (original)
+++ pypy/dist/pypy/translator/cli/test/runtest.py Thu Jun 15 16:24:31 2006
@@ -113,52 +113,55 @@
assert False, 'Input type %s not supported' % arg_type
-class compile_function:
- def __init__(self, func, annotation=[], graph=None):
- self._func = func
- self._gen = self._build_gen(func, annotation, graph)
- self._exe = self._gen.build_exe()
-
- def _build_gen(self, func, annotation, graph=None):
- try:
- func = func.im_func
- except AttributeError:
- pass
- t = TranslationContext()
- if graph is not None:
- graph.func = func
- ann = t.buildannotator()
- inputcells = [ann.typeannotation(a) for a in annotation]
- ann.build_graph_types(graph, inputcells)
- t.graphs.insert(0, graph)
- else:
- ann = t.buildannotator()
- ann.build_types(func, annotation)
-
- # quick hack: force exceptions.Exception to be rendered
- def raiseKeyError():
- raise KeyError
- ann.build_types(raiseKeyError, [])
-
- t.buildrtyper(type_system="ootype").specialize()
- self.graph = t.graphs[0]
-
- # XXX: horrible hack :-(
- for graph in t.graphs:
- if graph.name == 'raiseKeyError':
- raiseKeyError_graph = graph
-
- if getoption('view'):
- t.view()
-
- if getoption('wd'):
- self.tmpdir = py.path.local('.')
- else:
- self.tmpdir = udir
-
- return GenCli(self.tmpdir, t, TestEntryPoint(self.graph, True),
- pending_graphs=[raiseKeyError_graph])
-
+def compile_function(func, annotation=[], graph=None):
+ gen = _build_gen(func, annotation, graph)
+ gen.generate_source()
+ exe_name = gen.build_exe()
+ return CliFunctionWrapper(exe_name)
+
+def _build_gen(func, annotation, graph=None):
+ try:
+ func = func.im_func
+ except AttributeError:
+ pass
+ t = TranslationContext()
+ if graph is not None:
+ graph.func = func
+ ann = t.buildannotator()
+ inputcells = [ann.typeannotation(a) for a in annotation]
+ ann.build_graph_types(graph, inputcells)
+ t.graphs.insert(0, graph)
+ else:
+ ann = t.buildannotator()
+ ann.build_types(func, annotation)
+
+ # quick hack: force exceptions.Exception to be rendered
+ def raiseKeyError():
+ raise KeyError
+ ann.build_types(raiseKeyError, [])
+
+ t.buildrtyper(type_system="ootype").specialize()
+ main_graph = t.graphs[0]
+
+ # XXX: horrible hack :-(
+ for graph in t.graphs:
+ if graph.name == 'raiseKeyError':
+ raiseKeyError_graph = graph
+
+ if getoption('view'):
+ t.view()
+
+ if getoption('wd'):
+ tmpdir = py.path.local('.')
+ else:
+ tmpdir = udir
+
+ return GenCli(tmpdir, t, TestEntryPoint(main_graph, True),
+ pending_graphs=[raiseKeyError_graph])
+
+class CliFunctionWrapper(object):
+ def __init__(self, exe_name):
+ self._exe = exe_name
def __call__(self, *args):
if self._exe is None:
More information about the Pypy-commit
mailing list