[pypy-svn] r33380 - in pypy/branch/even-more-config3/pypy/translator: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Oct 17 17:06:51 CEST 2006
Author: cfbolz
Date: Tue Oct 17 17:06:50 2006
New Revision: 33380
Modified:
pypy/branch/even-more-config3/pypy/translator/interactive.py
pypy/branch/even-more-config3/pypy/translator/test/test_interactive.py
Log:
(pedronis, cfbolz): fix interactive to work with configuration (which made a
lot of things simpler, actually).
Modified: pypy/branch/even-more-config3/pypy/translator/interactive.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/interactive.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/interactive.py Tue Oct 17 17:06:50 2006
@@ -6,10 +6,10 @@
from pypy.config.config import Config
from pypy.config.pypyoption import pypy_optiondescription
-DEFAULT_OPTIONS = driver.DEFAULT_OPTIONS.copy()
-DEFAULT_OPTIONS.update({
- 'backend': None,
-})
+DEFAULTS = {
+ 'translation.backend': None,
+ 'translation.type_system': None,
+}
class Translation(object):
@@ -20,10 +20,9 @@
graph = self.context.buildflowgraph(entry_point)
self.context._prebuilt_graphs[entry_point] = graph
- self.config = Config(pypy_optiondescription)
+ self.driver = driver.TranslationDriver(overrides=DEFAULTS)
+ self.config = self.driver.config
- self.driver = driver.TranslationDriver(config=self.config)
-
# hook into driver events
driver_own_event = self.driver._event
def _event(kind, goal, func):
@@ -32,27 +31,8 @@
self.driver._event = _event
self.driver_setup = False
- self.frozen_options = {}
-
self.update_options(argtypes, kwds)
- GOAL_USES_OPTS = {
- 'annotate': ['debug'],
- 'rtype_lltype': ['insist'],
- 'rtype_ootype': ['insist'],
- 'backendopt_lltype': ['raisingop2direct_call', 'merge_if_blocks'],
- 'stackcheckinsertion_lltype': [],
- 'database_c': ['gc', 'stackless'],
- 'source_llvm': [],
- 'source_js': [],
- 'source_c': [],
- 'compile_c': [],
- 'compile_llvm': [],
- 'source_cl': [],
- 'source_cli': [],
- 'compile_cli': [],
- }
-
def view(self):
self.context.view()
@@ -64,9 +44,8 @@
#print goal
self.ensure_setup()
elif kind == 'post':
- used_opts = dict.fromkeys(self.GOAL_USES_OPTS[goal], True)
- self.frozen_options.update(used_opts)
-
+ pass
+
def ensure_setup(self, argtypes=None, policy=None, standalone=False):
if not self.driver_setup:
if standalone:
@@ -92,59 +71,31 @@
if argtypes or kwds.get('policy') or kwds.get('standalone'):
self.ensure_setup(argtypes, kwds.get('policy'),
kwds.get('standalone'))
- for optname, value in kwds.iteritems():
- if optname in ('policy', 'standalone'):
- continue
- if optname in self.frozen_options:
- if self.get_option(optname) != value:
- raise Exception("inconsistent option supplied: %s" %
- optname)
- else:
- try:
- self.get_option(optname)
- except AttributeError:
- raise TypeError('driver has no option %r' % (optname,))
- self.set_option(optname, value)
- self.frozen_options[optname] = True
-
- def get_option(self, name):
- # convenience function to look through the translation and
- # translation.backendopt namespaces of the config object
- try:
- return getattr(self.config.translation, name)
- except AttributeError:
- return getattr(self.config.translation.backendopt, name)
-
- def set_option(self, name, value):
- try:
- setattr(self.config.translation, name, value)
- except AttributeError:
- setattr(self.config.translation.backendopt, name, value)
+ kwds.pop('policy', None)
+ kwds.pop('standalone', None)
+ self.config.translation.set(**kwds)
def ensure_opt(self, name, value=None, fallback=None):
if value is not None:
self.update_options(None, {name: value})
- elif fallback is not None and name not in self.frozen_options:
+ return value
+ val = getattr(self.config.translation, name, None)
+ if fallback is not None and val is None:
self.update_options(None, {name: fallback})
- val = self.get_option(name)
- if val is None:
- raise Exception(
- "the %r option should have been specified at this point" %name)
- return val
+ return fallback
+ if val is not None:
+ return val
+ raise Exception(
+ "the %r option should have been specified at this point" %name)
def ensure_type_system(self, type_system=None):
- if type_system is None:
- backend = self.config.translation.backend
- # YYY the next two lines are unreachable now?
- if backend is not None:
- type_system = driver.backend_to_typesystem(backend)
+ if self.config.translation.backend is not None:
+ return self.ensure_opt('type_system')
return self.ensure_opt('type_system', type_system, 'lltype')
def ensure_backend(self, backend=None):
backend = self.ensure_opt('backend', backend)
self.ensure_type_system()
- if backend == 'llvm':
- self.update_options(None, {'gc': 'boehm'})
return backend
# disable some goals (steps)
Modified: pypy/branch/even-more-config3/pypy/translator/test/test_interactive.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/test/test_interactive.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/test/test_interactive.py Tue Oct 17 17:06:50 2006
@@ -41,10 +41,6 @@
assert 'rtype_lltype' in t.driver.done
- t = Translation(f, [int, int])
- t.annotate()
- py.test.raises(Exception, "t.rtype([int, int],debug=False)")
-
def test_simple_backendopt():
def f(x, y):
return x,y
More information about the Pypy-commit
mailing list