]> granicus.if.org Git - python/commitdiff
Issue #999042: The Python compiler now handles explict global statements
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>
Sat, 7 Feb 2009 00:54:41 +0000 (00:54 +0000)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>
Sat, 7 Feb 2009 00:54:41 +0000 (00:54 +0000)
correctly (should be assigned using STORE_GLOBAL opcode).  This was done by
having the system table differentiate between explict and implicit globals.

Lib/compiler/consts.py
Lib/compiler/pycodegen.py
Lib/compiler/symbols.py
Misc/NEWS

index dd42793aa9d478c82d1ce83b25377fdf3455ce71..022f6daa4c70b43803775a0103c7341883478a74 100644 (file)
@@ -4,10 +4,11 @@ OP_DELETE = 'OP_DELETE'
 OP_APPLY = 'OP_APPLY'
 
 SC_LOCAL = 1
-SC_GLOBAL = 2
-SC_FREE = 3
-SC_CELL = 4
-SC_UNKNOWN = 5
+SC_GLOBAL_IMPLICIT = 2
+SC_GLOBAL_EXPLICT = 3
+SC_FREE = 4
+SC_CELL = 5
+SC_UNKNOWN = 6
 
 CO_OPTIMIZED = 0x0001
 CO_NEWLOCALS = 0x0002
index e7ce1a9ddb176767a8810612283cc49a1feb9266..6d5a41c411501080fbaae8774b515fd7f8408fb2 100644 (file)
@@ -7,7 +7,8 @@ from cStringIO import StringIO
 
 from compiler import ast, parse, walk, syntax
 from compiler import pyassem, misc, future, symbols
-from compiler.consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL
+from compiler.consts import SC_LOCAL, SC_GLOBAL_IMPLICIT, SC_GLOBAL_EXPLICT, \
+     SC_FREE, SC_CELL
 from compiler.consts import (CO_VARARGS, CO_VARKEYWORDS, CO_NEWLOCALS,
      CO_NESTED, CO_GENERATOR, CO_FUTURE_DIVISION,
      CO_FUTURE_ABSIMPORT, CO_FUTURE_WITH_STATEMENT, CO_FUTURE_PRINT_FUNCTION)
@@ -282,7 +283,9 @@ class CodeGenerator:
                 self.emit(prefix + '_NAME', name)
             else:
                 self.emit(prefix + '_FAST', name)
-        elif scope == SC_GLOBAL:
+        elif scope == SC_GLOBAL_EXPLICT:
+            self.emit(prefix + '_GLOBAL', name)
+        elif scope == SC_GLOBAL_IMPLICIT:
             if not self.optimized:
                 self.emit(prefix + '_NAME', name)
             else:
index 0e660ae7da1250f7800322e90de0a4ea65281adb..0bbdc7122d89bdb48d900b133676c822b1f328ae 100644 (file)
@@ -1,7 +1,8 @@
 """Module symbol-table generator"""
 
 from compiler import ast
-from compiler.consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL, SC_UNKNOWN
+from compiler.consts import SC_LOCAL, SC_GLOBAL_IMPLICIT, SC_GLOBAL_EXPLICT, \
+    SC_FREE, SC_CELL, SC_UNKNOWN
 from compiler.misc import mangle
 import types
 
@@ -89,7 +90,7 @@ class Scope:
         The scope of a name could be LOCAL, GLOBAL, FREE, or CELL.
         """
         if name in self.globals:
-            return SC_GLOBAL
+            return SC_GLOBAL_EXPLICT
         if name in self.cells:
             return SC_CELL
         if name in self.defs:
@@ -99,7 +100,7 @@ class Scope:
         if self.nested:
             return SC_UNKNOWN
         else:
-            return SC_GLOBAL
+            return SC_GLOBAL_IMPLICIT
 
     def get_free_vars(self):
         if not self.nested:
@@ -152,7 +153,7 @@ class Scope:
                 if sc == SC_UNKNOWN or sc == SC_FREE \
                    or isinstance(self, ClassScope):
                     self.frees[name] = 1
-                elif sc == SC_GLOBAL:
+                elif sc == SC_GLOBAL_IMPLICIT:
                     child_globals.append(name)
                 elif isinstance(self, FunctionScope) and sc == SC_LOCAL:
                     self.cells[name] = 1
index 96256f523ea81df00ee886a1fc0915bdd4af33d5..8d33ee82d6091efceb603e85c016ab2cd4372423 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -410,6 +410,9 @@ Library
   protocol numbers are supplied outside the allowed 0-65536 range on bind()
   and getservbyport().
 
+- Issue #999042: The Python compiler now handles explict global statements
+  correctly (should be assigned using STORE_GLOBAL opcode).
+
 Tools/Demos
 -----------