[pypy-svn] r16428 - in pypy/dist/pypy: fakecompiler interpreter interpreter/stablecompiler lib/_stablecompiler

ludal at codespeak.net ludal at codespeak.net
Wed Aug 24 20:41:47 CEST 2005


Author: ludal
Date: Wed Aug 24 20:41:44 2005
New Revision: 16428

Modified:
   pypy/dist/pypy/fakecompiler/fakecompiler.py
   pypy/dist/pypy/interpreter/pycompiler.py
   pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py
   pypy/dist/pypy/lib/_stablecompiler/apphook.py
   pypy/dist/pypy/lib/_stablecompiler/pycodegen.py
Log:
(ludal,arigo)
+ pass along the __future__ flags to the compiler(s)


Modified: pypy/dist/pypy/fakecompiler/fakecompiler.py
==============================================================================
--- pypy/dist/pypy/fakecompiler/fakecompiler.py	(original)
+++ pypy/dist/pypy/fakecompiler/fakecompiler.py	Wed Aug 24 20:41:44 2005
@@ -2,11 +2,12 @@
 
 DUMPFILE = 'this_is_the_marshal_file'
 
-def reallycompile(tuples, filename, mode):
+def reallycompile(tuples, filename, mode, flag_names):
+    # XXX : use the flags if possible
     return parser.compileast(parser.tuple2ast(tuples), filename)
 
 if __name__ == '__main__':
-    tuples, filename, mode, done = marshal.load(file(DUMPFILE, "rb"))
-    code = reallycompile(tuples, filename, mode)
+    tuples, filename, mode, done, flag_names = marshal.load(file(DUMPFILE, "rb"))
+    code = reallycompile(tuples, filename, mode, flag_names)
     done = True
-    marshal.dump( (code, filename, mode, done), file(DUMPFILE, "wb"), 1)
+    marshal.dump( (code, filename, mode, done ), file(DUMPFILE, "wb"), 1)

Modified: pypy/dist/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycompiler.py	(original)
+++ pypy/dist/pypy/interpreter/pycompiler.py	Wed Aug 24 20:41:44 2005
@@ -87,6 +87,13 @@
     compiler_flags |= flag
     compiler_features[fname] = flag
 
+def get_flag_names( flag ):
+    flag_names = []
+    for name, value in compiler_features.items():
+        if flag & value:
+            flag_names.append( name )
+    return flag_names
+
 
 class CPythonCompiler(AbstractCompiler):
     """Faked implementation of a compiler, using the underlying compile()."""
@@ -189,9 +196,9 @@
         except ParseError, e:
             raise OperationError(space.w_SyntaxError,
                                  e.wrap_info(space, filename))
-        return self.compile_parse_result(parse_result, filename, mode)
+        return self.compile_parse_result(parse_result, filename, mode, flags)
 
-    def compile_parse_result(self, parse_result, filename, mode):
+    def compile_parse_result(self, parse_result, filename, mode, flags):
         """NOT_RPYTHON"""
         from pyparser.pythonutil import parse_result_to_nested_tuples
         # the result of this conversion has no useful type in RPython
@@ -209,12 +216,13 @@
             transformer = Transformer()
             tree = transformer.compile_node(tuples)
             stablecompiler.misc.set_filename(filename, tree)
+            flag_names = get_flag_names( flags )
             if mode == 'exec':
-                codegenerator = ModuleCodeGenerator(tree)
+                codegenerator = ModuleCodeGenerator(tree, flag_names)
             elif mode == 'single':
-                codegenerator = InteractiveCodeGenerator(tree)
+                codegenerator = InteractiveCodeGenerator(tree, flag_names)
             else: # mode == 'eval':
-                codegenerator = ExpressionCodeGenerator(tree)
+                codegenerator = ExpressionCodeGenerator(tree, flag_names)
             c = codegenerator.getCode()
         except SyntaxError, e:
             w_synerr = space.newtuple([space.wrap(e.msg),
@@ -272,7 +280,7 @@
         else:
             return self.w_compileapp
 
-    def compile_parse_result(self, parse_result, filename, mode):
+    def compile_parse_result(self, parse_result, filename, mode, flags):
         space = self.space
         if space.options.translating and not we_are_translated():
             # to avoid to spend too much time in the app-level compiler
@@ -280,8 +288,10 @@
             # doesn't see this because it thinks that we_are_translated()
             # returns True.
             return PythonCompiler.compile_parse_result(self, parse_result,
-                                                       filename, mode)
+                                                       filename, mode, flags)
         source_encoding, stack_element = parse_result
+        flag_names = get_flag_names( flags )
+        w_flag_names = space.newlist( [ space.wrap(n) for n in flag_names ] )
         w_nested_tuples = stack_element.as_w_tuple(space, lineno=True)
         if source_encoding is not None:
             from pypy.interpreter.pyparser import pysymbol
@@ -293,7 +303,8 @@
         w_code = space.call_function(self._get_compiler(mode),
                                      w_nested_tuples,
                                      space.wrap(filename),
-                                     space.wrap(mode))
+                                     space.wrap(mode),
+                                     w_flag_names)
         code = space.interpclass_w(w_code)
         from pypy.interpreter.pycode import PyCode
         if not isinstance(code, PyCode):
@@ -321,9 +332,9 @@
         except ParseError, e:
             raise OperationError(space.w_SyntaxError,
                                  e.wrap_info(space, filename))
-        return self.compile_parse_result(ast_tree, filename, mode)
+        return self.compile_parse_result(ast_tree, filename, mode, flags)
 
-    def compile_parse_result(self, ast_tree, filename, mode):
+    def compile_parse_result(self, ast_tree, filename, mode, flags):
         """NOT_RPYTHON"""
         # __________
         # XXX this uses the non-annotatable astcompiler at interp-level
@@ -334,12 +345,13 @@
         space = self.space
         try:
             astcompiler.misc.set_filename(filename, ast_tree)
+            flag_names = get_flag_names( flags )
             if mode == 'exec':
-                codegenerator = ModuleCodeGenerator(ast_tree)
+                codegenerator = ModuleCodeGenerator(ast_tree, flag_names)
             elif mode == 'single':
-                codegenerator = InteractiveCodeGenerator(ast_tree)
+                codegenerator = InteractiveCodeGenerator(ast_tree, flag_names)
             else: # mode == 'eval':
-                codegenerator = ExpressionCodeGenerator(ast_tree)
+                codegenerator = ExpressionCodeGenerator(ast_tree, flag_names)
             c = codegenerator.getCode()
         except SyntaxError, e:
             w_synerr = space.newtuple([space.wrap(e.msg),
@@ -355,22 +367,7 @@
             raise OperationError(space.w_TypeError,space.wrap(str(e)))
         # __________ end of XXX above
         from pypy.interpreter.pycode import PyCode
-        code = PyCode(space)        
-        code._code_new( c[0],
-                        c[1],
-                        c[2],
-                        c[3],
-                        c[4],
-                        c[5],
-                        c[6],
-                        c[7],
-                        c[8],
-                        c[9],
-                        c[10],
-                        c[11],
-                        c[12],
-                        c[13],
-                        )
+        code = PyCode(space)._from_code(c)
         return code
     #compile_parse_result._annspecialcase_ = 'override:cpy_stablecompiler'
 

Modified: pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py	(original)
+++ pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py	Wed Aug 24 20:41:44 2005
@@ -1222,9 +1222,12 @@
 
     scopes = None
 
-    def __init__(self, tree):
+    def __init__(self, tree, futures = []):
         self.graph = pyassem.PyFlowGraph("<module>", tree.filename)
         self.futures = future.find_futures(tree)
+        for f in futures:
+            if f not in self.futures:
+                self.futures.append(f)
         self.__super_init()
         walk(tree, self)
 
@@ -1235,10 +1238,10 @@
     __super_init = CodeGenerator.__init__
 
     scopes = None
-    futures = ()
 
-    def __init__(self, tree):
+    def __init__(self, tree, futures=[]):
         self.graph = pyassem.PyFlowGraph("<expression>", tree.filename)
+        self.futures = futures[:]
         self.__super_init()
         walk(tree, self)
 
@@ -1250,10 +1253,13 @@
     __super_init = CodeGenerator.__init__
 
     scopes = None
-    futures = ()
 
-    def __init__(self, tree):
+    def __init__(self, tree, futures=[]):
         self.graph = pyassem.PyFlowGraph("<interactive>", tree.filename)
+        self.futures = future.find_futures(tree)
+        for f in futures:
+            if f not in self.futures:
+                self.futures.append(f)
         self.__super_init()
         self.set_lineno(tree)
         walk(tree, self)

Modified: pypy/dist/pypy/lib/_stablecompiler/apphook.py
==============================================================================
--- pypy/dist/pypy/lib/_stablecompiler/apphook.py	(original)
+++ pypy/dist/pypy/lib/_stablecompiler/apphook.py	Wed Aug 24 20:41:44 2005
@@ -9,16 +9,16 @@
 from _stablecompiler.pycodegen import ExpressionCodeGenerator
 from _stablecompiler.transformer import Transformer
 
-def applevelcompile(tuples, filename, mode):
+def applevelcompile(tuples, filename, mode, flag_names ):
     transformer = Transformer()
     tree = transformer.compile_node(tuples)
     set_filename(filename, tree)
     if mode == 'exec':
-        codegenerator = ModuleCodeGenerator(tree)
+        codegenerator = ModuleCodeGenerator(tree, flag_names)
     elif mode == 'single':
-        codegenerator = InteractiveCodeGenerator(tree)
+        codegenerator = InteractiveCodeGenerator(tree, flag_names)
     else: # mode == 'eval':
-        codegenerator = ExpressionCodeGenerator(tree)
+        codegenerator = ExpressionCodeGenerator(tree, flag_names)
     return codegenerator.getCode()
 
 # temporary fake stuff, to allow to use the translated
@@ -26,10 +26,10 @@
 
 DUMPFILE = 'this_is_the_marshal_file'
 
-def fakeapplevelcompile(tuples, filename, mode):
+def fakeapplevelcompile(tuples, filename, mode, flag_names):
     import os, marshal
     done = False
-    data = marshal.dumps( (tuples, filename, mode, done) )
+    data = marshal.dumps( (tuples, filename, mode, done, flag_names) )
     f = file(DUMPFILE, "wb")
     f.write(data)
     f.close()

Modified: pypy/dist/pypy/lib/_stablecompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/lib/_stablecompiler/pycodegen.py	(original)
+++ pypy/dist/pypy/lib/_stablecompiler/pycodegen.py	Wed Aug 24 20:41:44 2005
@@ -1221,9 +1221,12 @@
 
     scopes = None
 
-    def __init__(self, tree):
+    def __init__(self, tree, futures = []):
         self.graph = pyassem.PyFlowGraph("<module>", tree.filename)
         self.futures = future.find_futures(tree)
+        for f in futures:
+            if f not in self.futures:
+                self.futures.append(f)
         self.__super_init()
         walk(tree, self)
 
@@ -1234,10 +1237,10 @@
     __super_init = CodeGenerator.__init__
 
     scopes = None
-    futures = ()
 
-    def __init__(self, tree):
+    def __init__(self, tree, futures=[]):
         self.graph = pyassem.PyFlowGraph("<expression>", tree.filename)
+        self.futures = futures[:]
         self.__super_init()
         walk(tree, self)
 
@@ -1249,10 +1252,13 @@
     __super_init = CodeGenerator.__init__
 
     scopes = None
-    futures = ()
 
-    def __init__(self, tree):
+    def __init__(self, tree, futures=[]):
         self.graph = pyassem.PyFlowGraph("<interactive>", tree.filename)
+        self.futures = future.find_futures(tree)
+        for f in futures:
+            if f not in self.futures:
+                self.futures.append(f)
         self.__super_init()
         self.set_lineno(tree)
         walk(tree, self)



More information about the Pypy-commit mailing list