[pypy-svn] r35266 - in pypy/dist/pypy: config config/test interpreter tool tool/build translator translator/c translator/c/test translator/cli translator/goal translator/js translator/llvm translator/oosupport translator/test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Dec 4 20:12:31 CET 2006


Author: cfbolz
Date: Mon Dec  4 20:12:22 2006
New Revision: 35266

Added:
   pypy/dist/pypy/config/translationoption.py
Modified:
   pypy/dist/pypy/config/pypyoption.py
   pypy/dist/pypy/config/test/test_pypyoption.py
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/tool/build/config.py
   pypy/dist/pypy/tool/option.py
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/c/test/test_boehm.py
   pypy/dist/pypy/translator/c/test/test_newgc.py
   pypy/dist/pypy/translator/c/test/test_stackless.py
   pypy/dist/pypy/translator/c/test/test_typed.py
   pypy/dist/pypy/translator/cli/gencli.py
   pypy/dist/pypy/translator/driver.py
   pypy/dist/pypy/translator/goal/targetpypystandalone.py
   pypy/dist/pypy/translator/goal/translate.py
   pypy/dist/pypy/translator/interactive.py
   pypy/dist/pypy/translator/js/main.py
   pypy/dist/pypy/translator/llvm/genllvm.py
   pypy/dist/pypy/translator/oosupport/genoo.py
   pypy/dist/pypy/translator/test/test_driver.py
   pypy/dist/pypy/translator/translator.py
Log:
steps into the direction of separating the translation from the pypy options.
Some messes involved.


Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py	(original)
+++ pypy/dist/pypy/config/pypyoption.py	Mon Dec  4 20:12:22 2006
@@ -18,220 +18,112 @@
     module_dependencies['rctime'] = [("objspace.usemodules.select", True),]
 
                               
-pypy_optiondescription = OptionDescription("pypy", "All PyPy Options", [
-    OptionDescription("objspace", "Object Space Option", [
-        ChoiceOption("name", "Object Space name",
-                     ["std", "flow", "logic", "thunk", "cpy", "dump", "sand"],
-                     "std",
-                     requires = {
-                         "logic": [("objspace.geninterp", False),
-                                   ("objspace.usemodules._stackless", True)],
-                     },
-                     cmdline='--objspace -o'),
-
-        ChoiceOption("parser", "parser",
-                     ["pypy", "cpython"], "pypy",
-                     cmdline='--parser'),
-
-        ChoiceOption("compiler", "compiler",
-                     ["cpython", "ast"], "ast",
-                     cmdline='--compiler'),
+pypy_optiondescription = OptionDescription("objspace", "Object Space Option", [
+    ChoiceOption("name", "Object Space name",
+                 ["std", "flow", "logic", "thunk", "cpy", "dump"], "std",
+                 requires = {
+                     "thunk": [("objspace.geninterp", False)],
+                     "logic": [("objspace.geninterp", False),
+                               ("objspace.usemodules._stackless", True)],
+                 },
+                 cmdline='--objspace -o'),
+
+    ChoiceOption("parser", "parser",
+                 ["pypy", "cpython"], "pypy",
+                 cmdline='--parser'),
+
+    ChoiceOption("compiler", "compiler",
+                 ["cpython", "ast"], "ast",
+                 cmdline='--compiler'),
+
+    BoolOption("nofaking", "disallow faking in the object space",
+               default=False,
+               requires=[
+                   ("objspace.usemodules.posix", True),
+                   ("objspace.usemodules.time", True),
+                   ("objspace.usemodules.errno", True)],
+               cmdline='--nofaking'),
+
+    OptionDescription("usemodules", "Which Modules should be used", [
+        BoolOption(modname, "use module %s" % (modname, ),
+                   default=modname in default_modules,
+                   cmdline="--withmod-%s" % (modname, ),
+                   requires= module_dependencies.get(modname, []))
+        for modname in all_modules]),
+
+    BoolOption("geninterp", "specify whether geninterp should be used",
+               default=True),
+
+    BoolOption("logbytecodes",
+               "keep track of bytecode usage",
+               default=False),
+
+    BoolOption("usepycfiles", "Write and read pyc files when importing",
+               default=True),
+   
+    OptionDescription("std", "Standard Object Space Options", [
+        BoolOption("withtproxy", "support transparent proxies",
+                   default=False, cmdline='--with-transparent-proxy'),
 
-        BoolOption("nofaking", "disallow faking in the object space",
+        BoolOption("withsmallint", "use tagged integers",
+                   default=False),
+
+        BoolOption("withprebuiltint", "prebuilt commonly used int objects",
                    default=False,
-                   requires=[
-                       ("objspace.usemodules.posix", True),
-                       ("objspace.usemodules.time", True),
-                       ("objspace.usemodules.errno", True)],
-                   cmdline='--nofaking'),
-
-        OptionDescription("usemodules", "Which Modules should be used", [
-            BoolOption(modname, "use module %s" % (modname, ),
-                       default=modname in default_modules,
-                       cmdline="--withmod-%s" % (modname, ),
-                       requires= module_dependencies.get(modname, []))
-            for modname in all_modules]),
+                   requires=[("objspace.std.withsmallint", False)]),
+
+        IntOption("prebuiltintfrom", "lowest integer which is prebuilt",
+                  default=-5, cmdline="--prebuiltinfrom"),
+
+        IntOption("prebuiltintto", "highest integer which is prebuilt",
+                  default=100, cmdline="--prebuiltintto"),
 
-        BoolOption("geninterp", "specify whether geninterp should be used",
-                   default=True),
+        BoolOption("withstrjoin", "use strings optimized for addition",
+                   default=False),
+
+        BoolOption("withstrslice", "use strings optimized for slicing",
+                   default=False),
 
-        BoolOption("logbytecodes",
-                   "keep track of bytecode usage",
+        BoolOption("withstrdict",
+                   "use dictionaries optimized for string keys",
                    default=False),
 
-        BoolOption("usepycfiles", "Write and read pyc files when importing",
-                   default=True),
-       
-        OptionDescription("std", "Standard Object Space Options", [
-            BoolOption("withtproxy", "support transparent proxies",
-                       default=False, cmdline='--with-transparent-proxy'),
-
-            BoolOption("withsmallint", "use tagged integers",
-                       default=False),
-
-            BoolOption("withprebuiltint", "prebuilt commonly used int objects",
-                       default=False,
-                       requires=[("objspace.std.withsmallint", False)]),
-
-            IntOption("prebuiltintfrom", "lowest integer which is prebuilt",
-                      default=-5, cmdline="--prebuiltinfrom"),
-
-            IntOption("prebuiltintto", "highest integer which is prebuilt",
-                      default=100, cmdline="--prebuiltintto"),
-
-            BoolOption("withstrjoin", "use strings optimized for addition",
-                       default=False),
-
-            BoolOption("withstrslice", "use strings optimized for slicing",
-                       default=False),
-
-            BoolOption("withstrdict",
-                       "use dictionaries optimized for string keys",
-                       default=False),
-
-            BoolOption("withmultidict",
-                       "use dictionaries optimized for flexibility",
-                       default=False,
-                       requires=[("objspace.std.withstrdict", False)]),
-
-            BoolOption("withdictmeasurement",
-                       "create huge files with masses of information "
-                       "about dictionaries",
-                       default=False,
-                       requires=[("objspace.std.withmultidict", True)]),
-
-            BoolOption("withrangelist",
-                       "enable special range list implementation that does not "
-                       "actually create the full list until the resulting "
-                       "list is mutaged",
-                       default=False),
-
-            BoolOption("oldstyle",
-                       "specify whether the default metaclass should be classobj",
-                       default=False, cmdline="--oldstyle"),
-         ]),
-        BoolOption("lowmem", "Try to use little memory during translation",
-                   default=False, cmdline="--lowmem",
-                   requires=[("objspace.geninterp", False)]),
-
-
-    ]),
-
-    BoolOption("translating", "indicates whether we are translating currently",
-               default=False, cmdline=None),
-
-    OptionDescription("translation", "Translation Options", [
-        BoolOption("stackless", "compile stackless features in",
-                   default=False, cmdline="--stackless",
-                   requires=[("translation.type_system", "lltype")]),
-        ChoiceOption("type_system", "Type system to use when RTyping",
-                     ["lltype", "ootype"], cmdline=None),
-        ChoiceOption("backend", "Backend to use for code generation",
-                     ["c", "llvm", "cli", "js", "squeak", "cl"],
-                     requires={
-                         "c":      [("translation.type_system", "lltype")],
-                         "llvm":   [("translation.type_system", "lltype"),
-                                    ("translation.gc", "boehm"),
-                                    ("translation.backendopt.raisingop2direct_call", True)],
-                         "cli":    [("translation.type_system", "ootype")],
-                         "js":     [("translation.type_system", "ootype")],
-                         "squeak": [("translation.type_system", "ootype")],
-                         "cl":     [("translation.type_system", "ootype")],
-                         },
-                     cmdline="-b --backend"),
-        ChoiceOption("gc", "Garbage Collection Strategy",
-                     ["boehm", "ref", "framework", "none", "stacklessgc",
-                      "exact_boehm"],
-                      "boehm", requires={
-                         "stacklessgc": [("translation.stackless", True)]},
-                      cmdline="--gc"),
-        BoolOption("thread", "enable use of threading primitives",
-                   default=False, cmdline="--thread"),
-        BoolOption("verbose", "Print extra information", default=False),
-        BoolOption("debug", "Record extra annotation information",
-                   cmdline="-d --debug", default=False),
-        BoolOption("insist", "Try hard to go on RTyping", default=False,
-                   cmdline="--insist"),
-        BoolOption("countmallocs", "Count mallocs and frees", default=False,
-                   cmdline=None),
-
-        # misc
-        StrOption("cc", "Specify compiler", cmdline="--cc"),
-        StrOption("profopt", "Specify profile based optimization script",
-                  cmdline="--profopt"),
-        BoolOption("debug_transform", "Perform the debug transformation",
-                   default=False, cmdline="--debug-transform", negation=False),
-
-        BoolOption("instrument", "internal: turn instrumentation on",
-                   default=False, cmdline=None),
-
-        ArbitraryOption("instrumentctl", "internal",
-                   default=None),        
-
-        # portability options
-        BoolOption("vanilla",
-                   "Try to be as portable as possible, which is not much",
+        BoolOption("withmultidict",
+                   "use dictionaries optimized for flexibility",
                    default=False,
-                   cmdline="--vanilla",
-                   requires=[("translation.no__thread", True)]),
-        BoolOption("no__thread",
-                   "don't use __thread for implementing TLS",
-                   default=False, cmdline="--no__thread", negation=False),
-        StrOption("compilerflags", "Specify flags for the compiler", 
-                   cmdline="--cflags"),
-        StrOption("linkerflags", "Specify flags for the linker", 
-                   cmdline="--ldflags"),
-
-        # Flags of the TranslationContext:
-        BoolOption("simplifying", "Simplify flow graphs", default=True),
-        BoolOption("do_imports_immediately", "XXX", default=True,
-                   cmdline=None),
-        BoolOption("builtins_can_raise_exceptions", "XXX", default=False,
-                   cmdline=None),
-        BoolOption("list_comprehension_operations", "XXX", default=False,
-                   cmdline=None),
-        ChoiceOption("fork_before",
-                     "(UNIX) Create restartable checkpoint before step",
-                     ["annotate", "rtype", "backendopt", "database", "source"],
-                     default=None, cmdline="--fork-before"),
-
-        OptionDescription("backendopt", "Backend Optimization Options", [
-            BoolOption("print_statistics", "Print statistics while optimizing",
-                       default=False),
-            BoolOption("merge_if_blocks", "Merge if ... elif chains",
-                       cmdline="--if-block-merge", default=True),
-            BoolOption("raisingop2direct_call",
-                       "Transform exception raising operations",
-                       default=False, cmdline="--raisingop2direct_call"),
-            BoolOption("mallocs", "Remove mallocs", default=True),
-            BoolOption("constfold", "Constant propagation",
-                       default=True),
-            BoolOption("heap2stack", "Escape analysis and stack allocation",
-                       default=False,
-                       requires=[("translation.stackless", False)]),
-            BoolOption("clever_malloc_removal",
-                       "Remove mallocs in a clever way", default=False),
-            BoolOption("remove_asserts",
-                       "Kill 'raise AssertionError', which lets the C "
-                       "optimizer remove the asserts", default=False),
-            IntOption("inline_threshold", "Threshold when to inline functions",
-                      default=1, cmdline=None),
-            StrOption("profile_based_inline",
-                      "Use call count profiling to drive inlining"
-                      ", specify arguments",
-                      default=None, cmdline="--prof-based-inline"),
-        ]),
-
-        OptionDescription("cli", "GenCLI options", [
-            BoolOption("trace_calls", "Trace function calls", default=False,
-                       cmdline="--cli-trace-calls")
-        ]),
-    ]),
+                   requires=[("objspace.std.withstrdict", False)]),
+
+        BoolOption("withdictmeasurement",
+                   "create huge files with masses of information "
+                   "about dictionaries",
+                   default=False,
+                   requires=[("objspace.std.withmultidict", True)]),
+
+        BoolOption("withrangelist",
+                   "enable special range list implementation that does not "
+                   "actually create the full list until the resulting "
+                   "list is mutaged",
+                   default=False),
+
+        BoolOption("oldstyle",
+                   "specify whether the default metaclass should be classobj",
+                   default=False, cmdline="--oldstyle"),
+     ]),
+    BoolOption("lowmem", "Try to use little memory during translation",
+               default=False, cmdline="--lowmem",
+               requires=[("objspace.geninterp", False)]),
+
+
 ])
 
+def get_pypy_config(overrides=None, translating=False):
+    from pypy.config.translationoption import get_combined_translation_config
+    return get_combined_translation_config(
+            pypy_optiondescription, overrides=overrides,
+            translating=translating)
 
 if __name__ == '__main__':
-    config = Config(pypy_optiondescription)
+    config = get_pypy_config()
     print config.getpaths()
     parser = to_optparse(config) #, useoptions=["translation.*"])
     option, args = parser.parse_args()

Modified: pypy/dist/pypy/config/test/test_pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/test/test_pypyoption.py	(original)
+++ pypy/dist/pypy/config/test/test_pypyoption.py	Mon Dec  4 20:12:22 2006
@@ -1,26 +1,25 @@
 import py
-from pypy.config.pypyoption import pypy_optiondescription
-from pypy.config.config import Config
+from pypy.config.pypyoption import get_pypy_config
 
 def test_required():
-    conf = Config(pypy_optiondescription)
+    conf = get_pypy_config()
     assert not conf.translating
 
     assert conf.objspace.usemodules.gc
 
     conf.objspace.std.withsmallint = True
     assert not conf.objspace.std.withprebuiltint
-    conf = Config(pypy_optiondescription)
+    conf = get_pypy_config()
     conf.objspace.std.withprebuiltint = True
     py.test.raises(ValueError, "conf.objspace.std.withsmallint = True")
 
 def test_objspace_incopatibilities():
-    conf = Config(pypy_optiondescription)
+    conf = get_pypy_config()
     conf.objspace.name = "logic"
     assert not conf.objspace.geninterp
 
 def test_stacklessgc_required():
-    conf = Config(pypy_optiondescription)
+    conf = get_pypy_config()
     conf.translation.gc = "stacklessgc"
     assert conf.translation.stackless
     assert conf.translation.type_system == "lltype"

Added: pypy/dist/pypy/config/translationoption.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/config/translationoption.py	Mon Dec  4 20:12:22 2006
@@ -0,0 +1,145 @@
+import autopath
+import py, os
+from pypy.config.config import OptionDescription, BoolOption, IntOption, ArbitraryOption
+from pypy.config.config import ChoiceOption, StrOption, to_optparse, Config
+
+translation_optiondescription = OptionDescription(
+        "translation", "Translation Options", [
+    BoolOption("stackless", "compile stackless features in",
+               default=False, cmdline="--stackless",
+               requires=[("translation.type_system", "lltype")]),
+    ChoiceOption("type_system", "Type system to use when RTyping",
+                 ["lltype", "ootype"], cmdline=None),
+    ChoiceOption("backend", "Backend to use for code generation",
+                 ["c", "llvm", "cli", "js", "squeak", "cl"],
+                 requires={
+                     "c":      [("translation.type_system", "lltype")],
+                     "llvm":   [("translation.type_system", "lltype"),
+                                ("translation.gc", "boehm"),
+                                ("translation.backendopt.raisingop2direct_call", True)],
+                     "cli":    [("translation.type_system", "ootype")],
+                     "js":     [("translation.type_system", "ootype")],
+                     "squeak": [("translation.type_system", "ootype")],
+                     "cl":     [("translation.type_system", "ootype")],
+                     },
+                 cmdline="-b --backend"),
+    ChoiceOption("gc", "Garbage Collection Strategy",
+                 ["boehm", "ref", "framework", "none", "stacklessgc",
+                  "exact_boehm"],
+                  "boehm", requires={
+                     "stacklessgc": [("translation.stackless", True)]},
+                  cmdline="--gc"),
+    BoolOption("thread", "enable use of threading primitives",
+               default=False, cmdline="--thread"),
+    BoolOption("verbose", "Print extra information", default=False),
+    BoolOption("debug", "Record extra annotation information",
+               cmdline="-d --debug", default=False),
+    BoolOption("insist", "Try hard to go on RTyping", default=False,
+               cmdline="--insist"),
+    BoolOption("countmallocs", "Count mallocs and frees", default=False,
+               cmdline=None),
+
+    # misc
+    StrOption("cc", "Specify compiler", cmdline="--cc"),
+    StrOption("profopt", "Specify profile based optimization script",
+              cmdline="--profopt"),
+    BoolOption("debug_transform", "Perform the debug transformation",
+               default=False, cmdline="--debug-transform", negation=False),
+
+    BoolOption("instrument", "internal: turn instrumentation on",
+               default=False, cmdline=None),
+
+    ArbitraryOption("instrumentctl", "internal",
+               default=None),        
+
+    # portability options
+    BoolOption("vanilla",
+               "Try to be as portable as possible, which is not much",
+               default=False,
+               cmdline="--vanilla",
+               requires=[("translation.no__thread", True)]),
+    BoolOption("no__thread",
+               "don't use __thread for implementing TLS",
+               default=False, cmdline="--no__thread", negation=False),
+    StrOption("compilerflags", "Specify flags for the compiler", 
+               cmdline="--cflags"),
+    StrOption("linkerflags", "Specify flags for the linker",
+               cmdline="--ldflags"),
+
+    # Flags of the TranslationContext:
+    BoolOption("simplifying", "Simplify flow graphs", default=True),
+    BoolOption("do_imports_immediately", "XXX", default=True,
+               cmdline=None),
+    BoolOption("builtins_can_raise_exceptions", "XXX", default=False,
+               cmdline=None),
+    BoolOption("list_comprehension_operations", "XXX", default=False,
+               cmdline=None),
+    ChoiceOption("fork_before",
+                 "(UNIX) Create restartable checkpoint before step",
+                 ["annotate", "rtype", "backendopt", "database", "source"],
+                 default=None, cmdline="--fork-before"),
+
+    OptionDescription("backendopt", "Backend Optimization Options", [
+        BoolOption("print_statistics", "Print statistics while optimizing",
+                   default=False),
+        BoolOption("merge_if_blocks", "Merge if ... elif chains",
+                   cmdline="--if-block-merge", default=True),
+        BoolOption("raisingop2direct_call",
+                   "Transform exception raising operations",
+                   default=False, cmdline="--raisingop2direct_call"),
+        BoolOption("mallocs", "Remove mallocs", default=True),
+        BoolOption("constfold", "Constant propagation",
+                   default=True),
+        BoolOption("heap2stack", "Escape analysis and stack allocation",
+                   default=False,
+                   requires=[("translation.stackless", False)]),
+        BoolOption("clever_malloc_removal",
+                   "Remove mallocs in a clever way", default=False),
+        BoolOption("remove_asserts",
+                   "Kill 'raise AssertionError', which lets the C "
+                   "optimizer remove the asserts", default=False),
+        IntOption("inline_threshold", "Threshold when to inline functions",
+                  default=1, cmdline=None),
+        StrOption("profile_based_inline",
+                  "Use call count profiling to drive inlining"
+                  ", specify arguments",
+                  default=None, cmdline="--prof-based-inline"),
+    ]),
+
+    OptionDescription("cli", "GenCLI options", [
+        BoolOption("trace_calls", "Trace function calls", default=False,
+                   cmdline="--cli-trace-calls")
+    ]),
+])
+
+def get_combined_translation_config(other_optdescr=None,
+                                    existing_config=None,
+                                    overrides=None,
+                                    translating=False):
+    if overrides is None:
+        overrides = {}
+    d = BoolOption("translating",
+                   "indicates whether we are translating currently",
+                   default=False, cmdline=None)
+    if other_optdescr is None:
+        children = []
+        newname = ""
+    else:
+        children = [other_optdescr]
+        newname = other_optdescr._name
+    if existing_config is None:
+        children += [d, translation_optiondescription]
+    else:
+        children += [child for child in existing_config._cfgimpl_descr._children
+                         if child._name != newname]
+    descr = OptionDescription("pypy", "all options", children)
+    config = Config(descr, **overrides)
+    if translating:
+        config.translating = True
+    if existing_config is not None:
+        for child in existing_config._cfgimpl_descr._children:
+            if child._name == newname:
+                continue
+            value = getattr(existing_config, child._name)
+            config._cfgimpl_values[child._name] = value
+    return config

Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Mon Dec  4 20:12:22 2006
@@ -170,16 +170,15 @@
         # set recursion limit
         # sets all the internal descriptors
         if config is None:
-            from pypy.config.config import Config
-            from pypy.config.pypyoption import pypy_optiondescription
-            config = Config(pypy_optiondescription)
+            from pypy.config.pypyoption import get_pypy_config
+            config = get_pypy_config(translating=True)
         self.config = config
         self.interned_strings = {}
         self.pending_actions = []
         self.setoptions(**kw)
 
-        if self.config.objspace.logbytecodes:            
-            self.bytecodecounts = {}
+#        if self.config.objspace.logbytecodes:            
+#            self.bytecodecounts = {}
 
         self.initialize()
 

Modified: pypy/dist/pypy/tool/build/config.py
==============================================================================
--- pypy/dist/pypy/tool/build/config.py	(original)
+++ pypy/dist/pypy/tool/build/config.py	Mon Dec  4 20:12:22 2006
@@ -18,8 +18,8 @@
 
 # compile option config, used by client to parse info, by startcompile for 
 # cmdline args, defaults are taken from the optiondescription
-from pypy.config.pypyoption import pypy_optiondescription
-compile_config = Config(pypy_optiondescription)
+from pypy.config.pypyoption import get_pypy_config
+compile_config = get_pypy_config()
 compile_config.override({'translation.backend': 'c'})
 
 # settings for the server

Modified: pypy/dist/pypy/tool/option.py
==============================================================================
--- pypy/dist/pypy/tool/option.py	(original)
+++ pypy/dist/pypy/tool/option.py	Mon Dec  4 20:12:22 2006
@@ -2,7 +2,7 @@
 # XXX needs clean-up and reorganization.
 
 import os
-from pypy.config.pypyoption import pypy_optiondescription
+from pypy.config.pypyoption import get_pypy_config
 from pypy.config.config import Config, OptionDescription, to_optparse
 from py.compat import optparse
 make_option = optparse.make_option
@@ -24,7 +24,7 @@
 
  
 def get_standard_options():
-    config = Config(pypy_optiondescription)
+    config = get_pypy_config()
     parser = to_optparse(config, useoptions=["objspace.*"])
     parser.add_option(
         '-H', action="callback",
@@ -54,9 +54,7 @@
     # XXX this whole file should sooner or later go away and the cmd line
     # options be generated from the option description. it's especially messy
     # since we have to check whether the default was actually overwritten
-    from pypy.config.pypyoption import pypy_optiondescription
-    from pypy.config.config import Config
-    conf = Config(pypy_optiondescription)
+    conf = get_pypy_config()
     if kwds.get("objspace", None) is not None:
         conf.objspace.name = kwds["objspace"]
     if getattr(cmdlineopt, "objspace", None) is not None:

Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Mon Dec  4 20:12:22 2006
@@ -29,9 +29,8 @@
         self.originalentrypoint = entrypoint
         self.gcpolicy = gcpolicy
         if config is None:
-            from pypy.config.config import Config
-            from pypy.config.pypyoption import pypy_optiondescription
-            config = Config(pypy_optiondescription)
+            from pypy.config.pypyoption import get_pypy_config
+            config = get_pypy_config(translating=True)
         if gcpolicy is not None and gcpolicy.requires_stackless:
             config.translation.stackless = True
         self.config = config

Modified: pypy/dist/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_boehm.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_boehm.py	Mon Dec  4 20:12:22 2006
@@ -3,8 +3,6 @@
 from pypy.translator.tool.cbuild import check_boehm_presence
 from pypy.translator.c.genc import CExtModuleBuilder
 from pypy import conftest
-from pypy.config.config import Config
-from pypy.config.pypyoption import pypy_optiondescription
 
 def setup_module(mod):
     if not check_boehm_presence():
@@ -23,7 +21,8 @@
 
     def getcompiled(self, func, argstypelist = [],
                     annotatorpolicy=None):
-        config = Config(pypy_optiondescription)
+        from pypy.config.pypyoption import get_pypy_config
+        config = get_pypy_config(translating=True)
         config.translation.gc = self.gcpolicy
         config.translation.simplifying = True
         t = TranslationContext(config=config)

Modified: pypy/dist/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_newgc.py	Mon Dec  4 20:12:22 2006
@@ -9,12 +9,11 @@
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rlib.objectmodel import cast_weakgcaddress_to_object, cast_object_to_weakgcaddress
-from pypy.config.config import Config
-from pypy.config.pypyoption import pypy_optiondescription
 from pypy import conftest
 
 def compile_func(fn, inputtypes, t=None, gcpolicy="ref"):
-    config = Config(pypy_optiondescription)
+    from pypy.config.pypyoption import get_pypy_config
+    config = get_pypy_config(translating=True)
     config.translation.gc = gcpolicy
     if t is None:
         t = TranslationContext(config=config)

Modified: pypy/dist/pypy/translator/c/test/test_stackless.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_stackless.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_stackless.py	Mon Dec  4 20:12:22 2006
@@ -6,7 +6,6 @@
 from pypy.rlib.rstack import stack_unwind, stack_frames_depth, stack_too_big
 from pypy.rlib.rstack import yield_current_frame_to_caller
 from pypy.config.config import Config
-from pypy.config.pypyoption import pypy_optiondescription
 import os
 
 
@@ -33,7 +32,8 @@
             os.write(1, str(fn())+"\n")
             return 0
 
-        config = Config(pypy_optiondescription)
+        from pypy.config.pypyoption import get_pypy_config
+        config = get_pypy_config(translating=True)
         config.translation.gc = self.gcpolicy
         config.translation.stackless = True
         t = TranslationContext(config=config)

Modified: pypy/dist/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_typed.py	Mon Dec  4 20:12:22 2006
@@ -8,8 +8,6 @@
 from pypy.translator.test import snippet
 from pypy.translator.translator import TranslationContext
 from pypy.rlib.rarithmetic import r_uint, r_ulonglong, r_longlong, intmask
-from pypy.config.config import Config
-from pypy.config.pypyoption import pypy_optiondescription
 
 # XXX this tries to make compiling faster for full-scale testing
 from pypy.translator.tool import cbuild
@@ -19,7 +17,8 @@
 class CompilationTestCase:
 
     def annotatefunc(self, func, argtypes=None):
-        config = Config(pypy_optiondescription)
+        from pypy.config.pypyoption import get_pypy_config
+        config = get_pypy_config(translating=True)
         config.translation.gc = "ref"
         config.translation.simplifying = True
         t = TranslationContext(config=config)

Modified: pypy/dist/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/dist/pypy/translator/cli/gencli.py	(original)
+++ pypy/dist/pypy/translator/cli/gencli.py	Mon Dec  4 20:12:22 2006
@@ -4,7 +4,6 @@
 import py
 from py.compat import subprocess
 from pypy.config.config import Config
-from pypy.config.pypyoption import pypy_optiondescription
 from pypy.translator.oosupport.genoo import GenOO
 from pypy.translator.cli import conftest
 from pypy.translator.cli.ilgenerator import IlasmGenerator

Modified: pypy/dist/pypy/translator/driver.py
==============================================================================
--- pypy/dist/pypy/translator/driver.py	(original)
+++ pypy/dist/pypy/translator/driver.py	Mon Dec  4 20:12:22 2006
@@ -87,10 +87,8 @@
         self.log = log
 
         if config is None:
-            from pypy.config.config import Config
-            from pypy.config.pypyoption import pypy_optiondescription
-            config = Config(pypy_optiondescription,
-                            **DEFAULTS)
+            from pypy.config.pypyoption import get_pypy_config
+            config = get_pypy_config(DEFAULTS, translating=True)
         self.config = config
         if overrides is not None:
             self.config.override(overrides)

Modified: pypy/dist/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypystandalone.py	(original)
+++ pypy/dist/pypy/translator/goal/targetpypystandalone.py	Mon Dec  4 20:12:22 2006
@@ -13,7 +13,6 @@
 from pypy.interpreter import gateway
 from pypy.interpreter.error import OperationError
 from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
-from pypy.config.pypyoption import pypy_optiondescription
 from pypy.config.config import Config, to_optparse, make_dict, SUPPRESS_USAGE
 from pypy.tool.option import make_objspace
 
@@ -94,6 +93,10 @@
     def print_help(self, config):
         self.opt_parser(config).print_help()
 
+    def get_additional_config_options(self):
+        from pypy.config.pypyoption import pypy_optiondescription
+        return pypy_optiondescription
+
     def target(self, driver, args):
         driver.exe_name = 'pypy-%(backend)s'
 
@@ -150,7 +153,8 @@
         return entry_point, None, PyPyAnnotatorPolicy(single_space = space)
 
     def interface(self, ns):
-        for name in ['take_options', 'handle_config', 'print_help', 'target']:
+        for name in ['take_options', 'handle_config', 'print_help', 'target',
+                     'get_additional_config_options']:
             ns[name] = getattr(self, name)
 
 

Modified: pypy/dist/pypy/translator/goal/translate.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate.py	(original)
+++ pypy/dist/pypy/translator/goal/translate.py	Mon Dec  4 20:12:22 2006
@@ -11,7 +11,7 @@
 from pypy.config.config import to_optparse, OptionDescription, BoolOption, \
                                ArbitraryOption, StrOption, IntOption, Config, \
                                ChoiceOption, OptHelpFormatter
-from pypy.config.pypyoption import pypy_optiondescription
+from pypy.config.translationoption import get_combined_translation_config
 
 
 GOALS= [
@@ -106,8 +106,8 @@
 
     opt_parser.disable_interspersed_args()
 
-    config = Config(pypy_optiondescription,
-                    **OVERRIDES)
+    config = get_combined_translation_config(
+                overrides=OVERRIDES, translating=True)
     to_optparse(config, parser=opt_parser, useoptions=['translation.*'])
     translateconfig = Config(translate_optiondescr)
     to_optparse(translateconfig, parser=opt_parser)
@@ -149,6 +149,14 @@
     # based on the config
     if 'handle_config' in targetspec_dic:
         targetspec_dic['handle_config'](config)
+    # give the target the possibility to get its own configuration options
+    # into the config
+    if 'get_additional_config_options' in targetspec_dic:
+        optiondescr = targetspec_dic['get_additional_config_options']()
+        config = get_combined_translation_config(
+                optiondescr,
+                existing_config=config,
+                translating=True)
 
     if translateconfig.help:
         opt_parser.print_help()

Modified: pypy/dist/pypy/translator/interactive.py
==============================================================================
--- pypy/dist/pypy/translator/interactive.py	(original)
+++ pypy/dist/pypy/translator/interactive.py	Mon Dec  4 20:12:22 2006
@@ -3,8 +3,6 @@
 import autopath
 from pypy.translator.translator import TranslationContext
 from pypy.translator import driver
-from pypy.config.config import Config
-from pypy.config.pypyoption import pypy_optiondescription
 
 DEFAULTS = {
   'translation.backend': None,

Modified: pypy/dist/pypy/translator/js/main.py
==============================================================================
--- pypy/dist/pypy/translator/js/main.py	(original)
+++ pypy/dist/pypy/translator/js/main.py	Mon Dec  4 20:12:22 2006
@@ -127,9 +127,8 @@
     # XXX: Really do that
     #options = optparse.Values(defaults=DEFAULT_OPTIONS)
     #options.debug_transform = opts.debug_transform
-    from pypy.config.config import Config
-    from pypy.config.pypyoption import pypy_optiondescription
-    config = Config(pypy_optiondescription)
+    from pypy.config.pypyoption import get_pypy_config
+    config = get_pypy_config(translating=True)
     config.translation.debug_transform = opts.debug_transform
     driver = TranslationDriver(config=config)
     try:

Modified: pypy/dist/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/genllvm.py	Mon Dec  4 20:12:22 2006
@@ -40,9 +40,8 @@
         self.translator = translator
         
         if config is None:
-            from pypy.config.config import Config
-            from pypy.config.pypyoption import pypy_optiondescription
-            config = Config(pypy_optiondescription)
+            from pypy.config.pypyoption import get_pypy_config
+            config = get_pypy_config(translating=True)
         self.config = config
         self.stackless = stackless
 

Modified: pypy/dist/pypy/translator/oosupport/genoo.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/genoo.py	(original)
+++ pypy/dist/pypy/translator/oosupport/genoo.py	Mon Dec  4 20:12:22 2006
@@ -1,7 +1,5 @@
 """ basic oogenerator
 """
-from pypy.config.config import Config
-from pypy.config.pypyoption import pypy_optiondescription
 from pypy.translator.oosupport import constant as ooconst
 
 class GenOO(object):
@@ -30,7 +28,8 @@
         self.entrypoint = entrypoint
         self.db = self.Database(self)
         if config is None:
-            config = Config(pypy_optiondescription)
+            from pypy.config.pypyoption import get_pypy_config
+            config = get_pypy_config(translating=True)
         self.config = config
 
     def generate_source(self):

Modified: pypy/dist/pypy/translator/test/test_driver.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_driver.py	(original)
+++ pypy/dist/pypy/translator/test/test_driver.py	Mon Dec  4 20:12:22 2006
@@ -1,8 +1,6 @@
 import py
 
 from pypy.translator.driver import TranslationDriver
-from pypy.config.config import Config
-from pypy.config.pypyoption import pypy_optiondescription
 from py.compat import optparse
 
 def cmpl(l1, l2):

Modified: pypy/dist/pypy/translator/translator.py
==============================================================================
--- pypy/dist/pypy/translator/translator.py	(original)
+++ pypy/dist/pypy/translator/translator.py	Mon Dec  4 20:12:22 2006
@@ -11,6 +11,8 @@
 from pypy.objspace.flow import FlowObjSpace
 from pypy.tool.ansi_print import ansi_log
 from pypy.tool.sourcetools import nice_repr_for_func
+from pypy.config.pypyoption import pypy_optiondescription
+from pypy.config.translationoption import get_combined_translation_config
 import py
 log = py.log.Producer("flowgraph")
 py.log.setconsumer("flowgraph", ansi_log)
@@ -26,9 +28,8 @@
 
     def __init__(self, config=None, **flowing_flags):
         if config is None:
-            from pypy.config.config import Config
-            from pypy.config.pypyoption import pypy_optiondescription
-            config = Config(pypy_optiondescription)
+            from pypy.config.pypyoption import get_pypy_config
+            config = get_pypy_config(translating=True)
         # ZZZ should go away in the end
         for attr in ['verbose', 'simplifying', 'do_imports_immediately',
                      'builtins_can_raise_exceptions',
@@ -36,6 +37,7 @@
             if attr in flowing_flags:
                 setattr(config.translation, attr, flowing_flags[attr])
         self.config = config
+        self.create_flowspace_config()
         self.annotator = None
         self.rtyper = None
         self.exceptiontransformer = None
@@ -45,6 +47,17 @@
 
         self._implicitly_called_by_externals = []
 
+    def create_flowspace_config(self):
+        # XXX this is a hack: we create a new config, which is only used
+        # for the flow object space. The problem is that the flow obj space
+        # needs an objspace config, but the thing we are translating might not
+        # have one (or worse we are translating pypy and the flow space picks
+        # up strange options of the pypy we are translating). Therefore we need
+        # to construct this new config
+        self.flowconfig = get_combined_translation_config(
+                pypy_optiondescription, self.config, translating=True)
+        self.flowconfig.objspace.name = "flow"
+
     def buildflowgraph(self, func):
         """Get the flow graph for a function."""
         if not isinstance(func, types.FunctionType):
@@ -55,7 +68,7 @@
         else:
             if self.config.translation.verbose:
                 log.start(nice_repr_for_func(func))
-            space = FlowObjSpace(self.config)
+            space = FlowObjSpace(self.flowconfig)
             if self.annotator:
                 # ZZZ
                 self.annotator.policy._adjust_space_config(space)



More information about the Pypy-commit mailing list