Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r48330:8e974d408b19
Date: 2011-10-22 00:24 +0200
http://bitbucket.org/pypy/pypy/changeset/8e974d408b19/

Log:    astcompiler: remove special code for the exec statement

diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -221,7 +221,7 @@
                                   "nested scopes: '%s'" % (identifier,))
             container = self.cell_vars
         elif scope == symtable.SCOPE_GLOBAL_IMPLICIT:
-            if self.scope.locals_fully_known:
+            if self.scope.optimized:
                 op = name_ops_global(ctx)
         elif scope == symtable.SCOPE_GLOBAL_EXPLICIT:
             op = name_ops_global(ctx)
@@ -1125,7 +1125,7 @@
         scope = self.scope
         assert isinstance(scope, symtable.FunctionScope)
         flags = 0
-        if scope.locals_fully_known:
+        if scope.optimized:
             flags |= consts.CO_OPTIMIZED
         if scope.nested:
             flags |= consts.CO_NESTED
diff --git a/pypy/interpreter/astcompiler/symtable.py 
b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -32,14 +32,13 @@
         self.col_offset = col_offset
         self.parent = None
         self.name = name
-        self.locals_fully_known = False
+        self.optimized = False
         self.symbols = None
         self.roles = {}
         self.varnames = []
         self.children = []
         self.free_vars = []
         self.temp_name_counter = 1
-        self.has_exec = False
         self.has_free = False
         self.child_has_free = False
         self.nested = False
@@ -85,10 +84,6 @@
         raise SyntaxError("return outside function", ret.lineno,
                           ret.col_offset)
 
-    def note_exec(self, exc):
-        """Called when an exec statement is found."""
-        self.has_exec = True
-
     def note_import_star(self, imp):
         """Called when a star import is found."""
         return False
@@ -230,7 +225,6 @@
         self.optimized = True
         self.return_with_value = False
         self.import_star = None
-        self.bare_exec = None
 
     def note_symbol(self, identifier, role):
         # Special-case super: it counts as a use of __class__
@@ -252,12 +246,6 @@
             self.return_with_value = True
             self.ret = ret
 
-    def note_exec(self, exc):
-        Scope.note_exec(self, exc)
-        if not exc.globals:
-            self.optimized = False
-            self.bare_exec = exc
-
     def note_import_star(self, imp):
         self.optimized = False
         self.import_star = imp
@@ -293,20 +281,11 @@
             name = self.name
             if self.import_star:
                 node = self.import_star
-                if self.bare_exec:
-                    err = "function '%s' uses import * and bare exec, " \
-                        "which are illegal because it %s" % (name, trailer)
-                else:
-                    err = "import * is not allowed in function '%s' because " \
-                        "it %s" % (name, trailer)
-            elif self.bare_exec:
-                node = self.bare_exec
-                err = "unqualified exec is not allowed in function '%s' " \
-                    "because it %s" % (name, trailer)
+                err = "import * is not allowed in function '%s' because " \
+                    "it %s" % (name, trailer)
             else:
                 raise AssertionError("unknown reason for unoptimization")
             raise SyntaxError(err, node.lineno, node.col_offset)
-        self.locals_fully_known = self.optimized and not self.has_exec
 
 
 class ClassScope(Scope):
@@ -438,10 +417,6 @@
     def visit_alias(self, alias):
         self._visit_alias(alias)
 
-    def visit_Exec(self, exc):
-        self.scope.note_exec(exc)
-        ast.GenericASTVisitor.visit_Exec(self, exc)
-
     def visit_Yield(self, yie):
         self.scope.note_yield(yie)
         ast.GenericASTVisitor.visit_Yield(self, yie)
diff --git a/pypy/interpreter/astcompiler/test/test_symtable.py 
b/pypy/interpreter/astcompiler/test/test_symtable.py
--- a/pypy/interpreter/astcompiler/test/test_symtable.py
+++ b/pypy/interpreter/astcompiler/test/test_symtable.py
@@ -54,12 +54,12 @@
     def test_toplevel(self):
         scp = self.mod_scope("x = 4")
         assert scp.lookup("x") == symtable.SCOPE_LOCAL
-        assert not scp.locals_fully_known
+        assert not scp.optimized
         scp = self.mod_scope("x = 4", "single")
-        assert not scp.locals_fully_known
+        assert not scp.optimized
         assert scp.lookup("x") == symtable.SCOPE_LOCAL
         scp = self.mod_scope("x*4*6", "eval")
-        assert not scp.locals_fully_known
+        assert not scp.optimized
         assert scp.lookup("x") == symtable.SCOPE_GLOBAL_IMPLICIT
 
     def test_duplicate_argument(self):
@@ -278,12 +278,8 @@
 
     def test_unoptimization_with_nested_scopes(self):
         table = (
-            ("from x import *; exec 'hi'", "function 'f' uses import * " \
-                 "and bare exec, which are illegal because it"),
             ("from x import *", "import * is not allowed in function 'f' " \
                  "because it"),
-            ("exec 'hi'", "unqualified exec is not allowed in function 'f' " \
-                 "because it")
          )
         for line, error in table:
             input = """def n():
@@ -320,20 +316,6 @@
         assert     "import * only allowed at module level" in err1
         assert not "import * only allowed at module level" in err2
 
-    def test_exec(self):
-        self.mod_scope("exec 'hi'")
-        scp = self.func_scope("def f(): exec 'hi'")
-        assert not scp.optimized
-        assert not scp.locals_fully_known
-        assert isinstance(scp.bare_exec, ast.Exec)
-        assert scp.has_exec
-        for line in ("exec 'hi' in g", "exec 'hi' in g, h"):
-            scp = self.func_scope("def f(): " + line)
-            assert scp.optimized
-            assert not scp.locals_fully_known
-            assert scp.bare_exec is None
-            assert scp.has_exec
-
     def test_yield(self):
         scp = self.func_scope("def f(): yield x")
         assert scp.is_generator
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to