[pypy-svn] r32756 - in pypy/branch/even-more-config/pypy: config objspace/flow objspace/flow/test translator

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Sep 30 00:36:18 CEST 2006


Author: cfbolz
Date: Sat Sep 30 00:36:09 2006
New Revision: 32756

Modified:
   pypy/branch/even-more-config/pypy/config/pypyoption.py
   pypy/branch/even-more-config/pypy/objspace/flow/flowcontext.py
   pypy/branch/even-more-config/pypy/objspace/flow/objspace.py
   pypy/branch/even-more-config/pypy/objspace/flow/specialcase.py
   pypy/branch/even-more-config/pypy/objspace/flow/test/test_objspace.py
   pypy/branch/even-more-config/pypy/translator/driver.py
   pypy/branch/even-more-config/pypy/translator/geninterplevel.py
   pypy/branch/even-more-config/pypy/translator/translator.py
Log:
start to use config objects in the TranslationContext and the flow object
space.


Modified: pypy/branch/even-more-config/pypy/config/pypyoption.py
==============================================================================
--- pypy/branch/even-more-config/pypy/config/pypyoption.py	(original)
+++ pypy/branch/even-more-config/pypy/config/pypyoption.py	Sat Sep 30 00:36:09 2006
@@ -122,7 +122,20 @@
         ChoiceOption("gc", "Garbage Collection Strategy",
                      ["boehm", "ref", "framework", "none", "stacklessgc"],
                       "boehm", requires={
-                         "stacklessgc": [("translation.stackless", True)]})
+                         "stacklessgc": [("translation.stackless", True)]}),
+
+        BoolOption("verbose", "Print extra information", default=False),
+
+        # Flags of the TranslationContext:
+        BoolOption("verbose", "Print extra information", default=False),
+        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),
+
     ])
 ])
 

Modified: pypy/branch/even-more-config/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/branch/even-more-config/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/branch/even-more-config/pypy/objspace/flow/flowcontext.py	Sat Sep 30 00:36:09 2006
@@ -281,7 +281,7 @@
 
             except OperationError, e:
                 #print "OE", e.w_type, e.w_value
-                if (self.space.do_imports_immediately and
+                if (self.space.config.translation.do_imports_immediately and
                     e.w_type is self.space.w_ImportError):
                     raise ImportError('import statement always raises %s' % (
                         e,))

Modified: pypy/branch/even-more-config/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/branch/even-more-config/pypy/objspace/flow/objspace.py	(original)
+++ pypy/branch/even-more-config/pypy/objspace/flow/objspace.py	Sat Sep 30 00:36:09 2006
@@ -34,9 +34,6 @@
     
     full_exceptions = False
 
-    builtins_can_raise_exceptions = False
-    do_imports_immediately = True
-
     def initialize(self):
         import __builtin__
         self.concrete_mode = 1
@@ -424,7 +421,7 @@
         exceptions = [Exception]   # *any* exception by default
         if isinstance(w_callable, Constant):
             c = w_callable.value
-            if not self.builtins_can_raise_exceptions:
+            if not self.config.translation.builtins_can_raise_exceptions:
                 if (isinstance(c, (types.BuiltinFunctionType,
                                    types.BuiltinMethodType,
                                    types.ClassType,

Modified: pypy/branch/even-more-config/pypy/objspace/flow/specialcase.py
==============================================================================
--- pypy/branch/even-more-config/pypy/objspace/flow/specialcase.py	(original)
+++ pypy/branch/even-more-config/pypy/objspace/flow/specialcase.py	Sat Sep 30 00:36:09 2006
@@ -11,7 +11,7 @@
         # import * in a function gives us the locals as Variable
         # we always forbid it as a SyntaxError
         raise SyntaxError, "RPython: import * is not allowed in functions"
-    if space.do_imports_immediately:
+    if space.config.translation.do_imports_immediately:
         name, glob, loc, frm = (space.unwrap(w_name), space.unwrap(w_glob),
                                 space.unwrap(w_loc), space.unwrap(w_frm))
         try:
@@ -36,7 +36,7 @@
         else:
             raise Exception, "should call %r with exactly %d arguments" % (
                 fn, Arity[opname])
-    if space.builtins_can_raise_exceptions:
+    if space.config.translation.builtins_can_raise_exceptions:
         # in this mode, avoid constant folding and raise an implicit Exception
         w_result = space.do_operation(opname, *args_w)
         space.handle_implicit_exceptions([Exception])

Modified: pypy/branch/even-more-config/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/branch/even-more-config/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/branch/even-more-config/pypy/objspace/flow/test/test_objspace.py	Sat Sep 30 00:36:09 2006
@@ -713,9 +713,9 @@
 
 
 class TestFlowObjSpaceDelay(Base):
-    def setup_class(cls): 
+    def setup_class(cls):
         cls.space = FlowObjSpace()
-        cls.space.do_imports_immediately = False
+        cls.space.config.translation.do_imports_immediately = False
 
     def test_import_something(self):
         def f():

Modified: pypy/branch/even-more-config/pypy/translator/driver.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/driver.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/driver.py	Sat Sep 30 00:36:09 2006
@@ -176,7 +176,7 @@
 
         if empty_translator:
             # set verbose flags
-            empty_translator.flags['verbose'] = True
+            empty_translator.config.translation.verbose = True
             translator = empty_translator
         else:
             translator = TranslationContext(verbose=True)

Modified: pypy/branch/even-more-config/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/geninterplevel.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/geninterplevel.py	Sat Sep 30 00:36:09 2006
@@ -64,13 +64,6 @@
      uniquemodulename, C_IDENTIFIER, NameManager
 
 
-# list of simplifcation passes needed by geninterp
-from pypy.translator.simplify import transform_ovfcheck, all_passes as needed_passes
-
-needed_passes = needed_passes[:]
-needed_passes.remove(transform_ovfcheck)
-
-
 import pypy # __path__
 import py.path
 from pypy.tool.ansi_print import ansi_log
@@ -1487,7 +1480,7 @@
                 sys.path.remove(libdir)
 
         entrypoint = dic
-        t = TranslationContext(verbose=False, simplifying=needed_passes,
+        t = TranslationContext(verbose=False, simplifying=True,
                                do_imports_immediately=do_imports_immediately,
                                builtins_can_raise_exceptions=True,
                                list_comprehension_operations=False)

Modified: pypy/branch/even-more-config/pypy/translator/translator.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/translator.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/translator.py	Sat Sep 30 00:36:09 2006
@@ -12,9 +12,9 @@
 from pypy.tool.ansi_print import ansi_log
 from pypy.tool.sourcetools import nice_repr_for_func
 import py
-log = py.log.Producer("flowgraph") 
-py.log.setconsumer("flowgraph", ansi_log) 
-
+log = py.log.Producer("flowgraph")
+py.log.setconsumer("flowgraph", ansi_log)
+ 
 class TranslationContext(object):
     FLOWING_FLAGS = {
         'verbose': False,
@@ -24,11 +24,18 @@
         'list_comprehension_operations': False,   # True, - not super-tested
         }
 
-    def __init__(self, **flowing_flags):
-        self.flags = self.FLOWING_FLAGS.copy()
-        self.flags.update(flowing_flags)
-        if len(self.flags) > len(self.FLOWING_FLAGS):
-            raise TypeError("unexpected keyword argument")
+    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)
+        # ZZZ should go away in the end
+        for attr in ['verbose', 'simplifying', 'do_imports_immediately',
+                     'builtins_can_raise_exceptions',
+                     'list_comprehension_operations']:
+            if attr in flowing_flags:
+                setattr(config.translation, attr, flowing_flags[attr])
+        self.config = config
         self.annotator = None
         self.rtyper = None
         self.exceptiontransformer = None
@@ -47,18 +54,18 @@
         if func in self._prebuilt_graphs:
             graph = self._prebuilt_graphs.pop(func)
         else:
-            if self.flags.get('verbose'):
+            if self.config.translation.verbose:
                 log.start(nice_repr_for_func(func))
-            space = FlowObjSpace()
-            space.__dict__.update(self.flags)   # xxx push flags there
+            space = FlowObjSpace(self.config)
             if self.annotator:
+                # ZZZ
                 self.annotator.policy._adjust_space_config(space)
             graph = space.build_flow(func)
-            if self.flags.get('simplifying'):
+            if self.config.translation.simplifying:
                 simplify.simplify_graph(graph)
-            if self.flags.get('list_comprehension_operations'):
+            if self.config.translation.list_comprehension_operations:
                 simplify.detect_list_comprehension(graph)
-            if self.flags.get('verbose'):
+            if self.config.translation.verbose:
                 log.done(func.__name__)
             self.graphs.append(graph)   # store the graph in our list
         return graph



More information about the Pypy-commit mailing list