[pypy-svn] r33375 - in pypy/branch/even-more-config3/pypy/translator: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Oct 17 15:50:13 CEST 2006


Author: cfbolz
Date: Tue Oct 17 15:50:12 2006
New Revision: 33375

Modified:
   pypy/branch/even-more-config3/pypy/translator/driver.py
   pypy/branch/even-more-config3/pypy/translator/test/test_driver.py
Log:
(pedronis, cfbolz): remove the options attribute of the driver and its last
uses. Change the signature of the constructor to make it possible to override
defaults and also set options during the construction.


Modified: pypy/branch/even-more-config3/pypy/translator/driver.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/driver.py	(original)
+++ pypy/branch/even-more-config3/pypy/translator/driver.py	Tue Oct 17 15:50:12 2006
@@ -14,26 +14,24 @@
 py.log.setconsumer("translation", ansi_log)
 
 
-DEFAULT_OPTIONS = {
-  'gc': 'ref',
-  'cc': None,
-  'profopt': None,
-
-  'thread': False, # influences GC policy
-
-  'stackless': False,
-  'debug': True,
-  'insist': False,
-  'backend': 'c',
-  'type_system': None,
-  'lowmem': False,
-  'fork_before': None,
-  'raisingop2direct_call' : False,
-  'merge_if_blocks': True,
-  'debug_transform' : False,
+DEFAULTS = {
+  'translation.gc': 'ref',
+  'translation.cc': None,
+  'translation.profopt': None,
+
+  'translation.thread': False, # influences GC policy
+
+  'translation.stackless': False,
+  'translation.debug': True,
+  'translation.insist': False,
+  'translation.backend': 'c',
+  'translation.lowmem': False,
+  'translation.goals.fork_before': None,
+  'translation.backendopt.raisingop2direct_call' : False,
+  'translation.backendopt.merge_if_blocks': True,
+  'translation.debug_transform' : False,
 }
 
-_default_options = optparse.Values(defaults=DEFAULT_OPTIONS)
 
 def taskdef(taskfunc, deps, title, new_state=None, expected_states=[], idemp=False):
     taskfunc.task_deps = deps
@@ -56,9 +54,9 @@
 
 class TranslationDriver(SimpleTaskEngine):
 
-    def __init__(self, options=None, default_goal=None, disable=[],
+    def __init__(self, setopts=None, default_goal=None, disable=[],
                  exe_name=None, extmod_name=None,
-                 config=None):
+                 config=None, overrides=None):
         SimpleTaskEngine.__init__(self)
 
         self.log = log
@@ -66,33 +64,15 @@
         if config is None:
             from pypy.config.config import Config
             from pypy.config.pypyoption import pypy_optiondescription
-            config = Config(pypy_optiondescription)
+            config = Config(pypy_optiondescription,
+                            **DEFAULTS)
         self.config = config
+        if overrides is not None:
+            self.config.override(overrides)
 
-        # YYY the option argument should disappear
-        if options is None:
-            options = _default_options
-        else:
-            # move options over to config
-
-            # YYY debug
-            # YYY fork_before
-            # YYY debug_transform
-            tconf = config.translation
-            tconf.gc = options.gc
-            tconf.thread = options.thread
-            tconf.stackless = options.stackless
-            tconf.backend = options.backend
-            tconf.type_system = options.type_system
-            tconf.insist = options.insist
-            tconf.lowmem = options.lowmem
-            tconf.backendopt.merge_if_blocks = options.merge_if_blocks
-            tconf.backendopt.raisingop2direct_call = (
-                    options.raisingop2direct_call)
-
-
-        self.options = options
-
+        if setopts is not None:
+            self.config.set(**setopts)
+        
         self.exe_name = exe_name
         self.extmod_name = extmod_name
 
@@ -142,22 +122,14 @@
                             expose_task(explicit_task)
                     else:
                         expose_task(explicit_task)
+    
+    def get_info(self): # XXX more?
+        d = {'backend': self.config.translation.backend}
+        return d
 
     def get_backend_and_type_system(self):
-        type_system = None
-        backend = None
-        if self.config.translation.type_system:
-            type_system = self.config.translation.type_system
-        if self.config.translation.backend:
-            backend = self.config.translation.backend
-            ts = backend_to_typesystem(backend)
-            if type_system:
-                # YYY should be dead code
-                if ts != type_system:
-                    raise ValueError, ("incosistent type-system and backend:"
-                                       " %s and %s" % (type_system, backend))
-            else:
-                type_system = ts
+        type_system = self.config.translation.type_system
+        backend = self.config.translation.backend
         return backend, type_system
 
     def backend_select_goals(self, goals):
@@ -239,7 +211,7 @@
         
         s = annotator.build_types(self.entry_point, self.inputtypes)
         
-        if self.options.debug_transform:
+        if self.config.translation.debug_transform:
             from pypy.translator.transformer.debug import DebugTransformer
             dt = DebugTransformer(translator)
             dt.transform_all()
@@ -305,7 +277,6 @@
 
     def task_backendopt_ootype(self):
         from pypy.translator.backendopt.all import backend_optimizations
-        opt = self.options
         backend_optimizations(self.translator,
                               raisingop2direct_call_all=False,
                               inline_threshold=0,
@@ -369,7 +340,8 @@
         if self.exe_name is not None:
             import shutil
             exename = mkexename(self.c_entryp)
-            newexename = self.exe_name % self.options.__dict__
+            info = {'backend': self.config.translation.backend}
+            newexename = self.exe_name % self.get_info()
             if '/' not in newexename and '\\' not in newexename:
                 newexename = './' + newexename
             newexename = mkexename(newexename)
@@ -445,7 +417,7 @@
     def task_compile_llvm(self):
         gen = self.llvmgen
         if self.standalone:
-            exe_name = (self.exe_name or 'testing') % self.options.__dict__
+            exe_name = (self.exe_name or 'testing') % self.get_info()
             self.c_entryp = gen.compile_llvm_source(exe_name=exe_name)
             self.create_exe()
         else:
@@ -502,7 +474,7 @@
         from pypy.translator.js.js import JS
         self.gen = JS(self.translator, functions=[self.entry_point],
                       stackless=self.config.translation.stackless,
-                      use_debug=self.options.debug_transform)
+                      use_debug=self.config.translation.debug_transform)
         filename = self.gen.write_source()
         self.log.info("Wrote %s" % (filename,))
     task_source_js = taskdef(task_source_js, 
@@ -603,7 +575,7 @@
     # checkpointing support
     def _event(self, kind, goal, func):
         if kind == 'pre':
-            fork_before = self.options.fork_before
+            fork_before = self.config.translation.goals.fork_before
             if fork_before:
                 fork_before, = self.backend_select_goals([fork_before])
                 if not fork_before in self.done and fork_before == goal:

Modified: pypy/branch/even-more-config3/pypy/translator/test/test_driver.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/test/test_driver.py	(original)
+++ pypy/branch/even-more-config3/pypy/translator/test/test_driver.py	Tue Oct 17 15:50:12 2006
@@ -1,6 +1,6 @@
 import py
 
-from pypy.translator.driver import TranslationDriver, DEFAULT_OPTIONS
+from pypy.translator.driver import TranslationDriver
 from pypy.config.config import Config
 from pypy.config.pypyoption import pypy_optiondescription
 from py.compat import optparse
@@ -13,8 +13,7 @@
     return l1 == l2
 
 def test_ctr():
-    config = Config(pypy_optiondescription, **{"translation.backend": "c"})
-    td = TranslationDriver(config=config)
+    td = TranslationDriver()
 
     assert cmpl(td.exposed,
                 ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source', 'compile', 'run'])
@@ -27,8 +26,7 @@
     assert td.backend_select_goals(['backendopt_lltype']) == [
         'backendopt_lltype']
 
-    config = Config(pypy_optiondescription)
-    td = TranslationDriver(config=config)
+    td = TranslationDriver({'backend': None, 'type_system': None})
 
     assert td.backend_select_goals(['compile_c']) == ['compile_c']
     py.test.raises(Exception, td.backend_select_goals, ['compile'])
@@ -48,9 +46,7 @@
                  'compile_llvm', 'compile_js', 'run_cl', 'run_squeak',
                  'run_llvm', 'run_c', 'run_js', 'run_cli'])
 
-    config = Config(pypy_optiondescription,
-                    **{"translation.type_system": "lltype"})
-    td = TranslationDriver(config=config)
+    td = TranslationDriver({'backend': None, 'type_system': 'lltype'})
 
     assert td.backend_select_goals(['compile_c']) == ['compile_c']
     py.test.raises(Exception, td.backend_select_goals, ['compile'])



More information about the Pypy-commit mailing list