[pypy-svn] r15606 - in pypy/dist/pypy: interpreter/stablecompiler interpreter/test lib/_stablecompiler

arigo at codespeak.net arigo at codespeak.net
Thu Aug 4 12:20:04 CEST 2005


Author: arigo
Date: Thu Aug  4 12:20:03 2005
New Revision: 15606

Modified:
   pypy/dist/pypy/interpreter/stablecompiler/consts.py
   pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py
   pypy/dist/pypy/interpreter/stablecompiler/symbols.py
   pypy/dist/pypy/interpreter/test/test_exec.py
   pypy/dist/pypy/lib/_stablecompiler/consts.py
   pypy/dist/pypy/lib/_stablecompiler/pycodegen.py
   pypy/dist/pypy/lib/_stablecompiler/symbols.py
Log:
Porting mwh's fix for the 'compiler' package to the two copies of our
stablecompiler.  See new test case.


Modified: pypy/dist/pypy/interpreter/stablecompiler/consts.py
==============================================================================
--- pypy/dist/pypy/interpreter/stablecompiler/consts.py	(original)
+++ pypy/dist/pypy/interpreter/stablecompiler/consts.py	Thu Aug  4 12:20:03 2005
@@ -8,6 +8,7 @@
 SC_FREE = 3
 SC_CELL = 4
 SC_UNKNOWN = 5
+SC_REALLY_GLOBAL = 6
 
 CO_OPTIMIZED = 0x0001
 CO_NEWLOCALS = 0x0002

Modified: pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py	(original)
+++ pypy/dist/pypy/interpreter/stablecompiler/pycodegen.py	Thu Aug  4 12:20:03 2005
@@ -9,7 +9,7 @@
 from pypy.interpreter.stablecompiler import ast, parse, walk, syntax
 from pypy.interpreter.stablecompiler import pyassem, misc, future, symbols
 from pypy.interpreter.stablecompiler.consts import SC_LOCAL, SC_GLOBAL, \
-    SC_FREE, SC_CELL
+    SC_FREE, SC_CELL, SC_REALLY_GLOBAL
 from pypy.interpreter.stablecompiler.consts import CO_VARARGS, CO_VARKEYWORDS, \
     CO_NEWLOCALS, CO_NESTED, CO_GENERATOR, CO_GENERATOR_ALLOWED, CO_FUTURE_DIVISION
 from pypy.interpreter.stablecompiler.pyassem import TupleArg
@@ -286,6 +286,8 @@
                 self.emit(prefix + '_GLOBAL', name)
         elif scope == SC_FREE or scope == SC_CELL:
             self.emit(prefix + '_DEREF', name)
+        elif scope == SC_REALLY_GLOBAL:
+            self.emit(prefix +  '_GLOBAL', name)
         else:
             raise RuntimeError, "unsupported scope for var %s: %d" % \
                   (name, scope)

Modified: pypy/dist/pypy/interpreter/stablecompiler/symbols.py
==============================================================================
--- pypy/dist/pypy/interpreter/stablecompiler/symbols.py	(original)
+++ pypy/dist/pypy/interpreter/stablecompiler/symbols.py	Thu Aug  4 12:20:03 2005
@@ -2,7 +2,7 @@
 
 from pypy.interpreter.stablecompiler import ast
 from pypy.interpreter.stablecompiler.consts import SC_LOCAL, SC_GLOBAL, \
-    SC_FREE, SC_CELL, SC_UNKNOWN
+    SC_FREE, SC_CELL, SC_UNKNOWN, SC_REALLY_GLOBAL
 from pypy.interpreter.stablecompiler.misc import mangle
 import types
 
@@ -90,7 +90,7 @@
         The scope of a name could be LOCAL, GLOBAL, FREE, or CELL.
         """
         if self.globals.has_key(name):
-            return SC_GLOBAL
+            return SC_REALLY_GLOBAL
         if self.cells.has_key(name):
             return SC_CELL
         if self.defs.has_key(name):
@@ -155,7 +155,7 @@
                 if sc == SC_UNKNOWN or sc == SC_FREE \
                    or isinstance(self, ClassScope):
                     self.frees[name] = 1
-                elif sc == SC_GLOBAL:
+                elif sc == SC_GLOBAL or sc == SC_REALLY_GLOBAL:
                     child_globals.append(name)
                 elif isinstance(self, FunctionScope) and sc == SC_LOCAL:
                     self.cells[name] = 1

Modified: pypy/dist/pypy/interpreter/test/test_exec.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_exec.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_exec.py	Thu Aug  4 12:20:03 2005
@@ -74,3 +74,10 @@
         def f():
             exec 'raise TypeError' in {}
         raises(TypeError,f)
+
+    def test_global_stmt(self):
+        g = {}
+        l = {}
+        exec "global a; a=5" in g, l
+        assert l == {}
+        assert g['a'] == 5

Modified: pypy/dist/pypy/lib/_stablecompiler/consts.py
==============================================================================
--- pypy/dist/pypy/lib/_stablecompiler/consts.py	(original)
+++ pypy/dist/pypy/lib/_stablecompiler/consts.py	Thu Aug  4 12:20:03 2005
@@ -8,6 +8,7 @@
 SC_FREE = 3
 SC_CELL = 4
 SC_UNKNOWN = 5
+SC_REALLY_GLOBAL = 6
 
 CO_OPTIMIZED = 0x0001
 CO_NEWLOCALS = 0x0002

Modified: pypy/dist/pypy/lib/_stablecompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/lib/_stablecompiler/pycodegen.py	(original)
+++ pypy/dist/pypy/lib/_stablecompiler/pycodegen.py	Thu Aug  4 12:20:03 2005
@@ -10,7 +10,7 @@
 from transformer import parse
 from visitor import walk
 import pyassem, misc, future, symbols
-from consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL
+from consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL, SC_REALLY_GLOBAL
 from consts import CO_VARARGS, CO_VARKEYWORDS, \
     CO_NEWLOCALS, CO_NESTED, CO_GENERATOR, CO_GENERATOR_ALLOWED, CO_FUTURE_DIVISION
 from pyassem import TupleArg
@@ -287,6 +287,8 @@
                 self.emit(prefix + '_GLOBAL', name)
         elif scope == SC_FREE or scope == SC_CELL:
             self.emit(prefix + '_DEREF', name)
+        elif scope == SC_REALLY_GLOBAL:
+            self.emit(prefix +  '_GLOBAL', name)
         else:
             raise RuntimeError, "unsupported scope for var %s: %d" % \
                   (name, scope)

Modified: pypy/dist/pypy/lib/_stablecompiler/symbols.py
==============================================================================
--- pypy/dist/pypy/lib/_stablecompiler/symbols.py	(original)
+++ pypy/dist/pypy/lib/_stablecompiler/symbols.py	Thu Aug  4 12:20:03 2005
@@ -1,7 +1,8 @@
 """Module symbol-table generator"""
 
 import ast
-from consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL, SC_UNKNOWN
+from consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL, \
+     SC_UNKNOWN, SC_REALLY_GLOBAL
 from misc import mangle
 import types
 
@@ -89,7 +90,7 @@
         The scope of a name could be LOCAL, GLOBAL, FREE, or CELL.
         """
         if self.globals.has_key(name):
-            return SC_GLOBAL
+            return SC_REALLY_GLOBAL
         if self.cells.has_key(name):
             return SC_CELL
         if self.defs.has_key(name):
@@ -154,7 +155,7 @@
                 if sc == SC_UNKNOWN or sc == SC_FREE \
                    or isinstance(self, ClassScope):
                     self.frees[name] = 1
-                elif sc == SC_GLOBAL:
+                elif sc == SC_GLOBAL or sc == SC_REALLY_GLOBAL:
                     child_globals.append(name)
                 elif isinstance(self, FunctionScope) and sc == SC_LOCAL:
                     self.cells[name] = 1



More information about the Pypy-commit mailing list