[pypy-svn] r28877 - pypy/dist/pypy/translator/cli/test
antocuni at codespeak.net
antocuni at codespeak.net
Fri Jun 16 13:55:28 CEST 2006
Author: antocuni
Date: Fri Jun 16 13:55:13 2006
New Revision: 28877
Modified:
pypy/dist/pypy/translator/cli/test/runtest.py
Log:
- Force ValueError to be rendered instead of KeyError
- Cache compiled functions: don't recompile when trying to interpret
the last function again.
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 Fri Jun 16 13:55:13 2006
@@ -136,17 +136,17 @@
ann.build_types(func, annotation)
# quick hack: force exceptions.Exception to be rendered
- def raiseKeyError():
- raise KeyError
- ann.build_types(raiseKeyError, [])
+ def raiseValueError():
+ raise ValueError
+ ann.build_types(raiseValueError, [])
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 graph.name == 'raiseValueError':
+ raiseValueError_graph = graph
if getoption('view'):
t.view()
@@ -157,7 +157,7 @@
tmpdir = udir
return GenCli(tmpdir, t, TestEntryPoint(main_graph, True),
- pending_graphs=[raiseKeyError_graph])
+ pending_graphs=[raiseValueError_graph])
class CliFunctionWrapper(object):
def __init__(self, exe_name):
@@ -210,9 +210,23 @@
return 'ExceptionWrapper(%s)' % repr(self.class_name)
class CliTest(BaseRtypingTest, OORtypeMixin):
- def interpret(self, fn, args):
+ def __init__(self):
+ self._func = None
+ self._ann = None
+ self._cli_func = None
+
+ def _compile(self, fn, args):
ann = [lltype_to_annotation(typeOf(x)) for x in args]
- f = compile_function(fn, ann)
+ if self._func is fn and self._ann == ann:
+ return self._cli_func
+ else:
+ self._func = fn
+ self._ann = ann
+ self._cli_func = compile_function(fn, ann)
+ return self._cli_func
+
+ def interpret(self, fn, args):
+ f = self._compile(fn, args)
res = f(*args)
if isinstance(res, ExceptionWrapper):
raise res
More information about the Pypy-commit
mailing list