Commits

holger krekel committed d7cf399

make our applevel-loaded _stablecompiler issue
SyntaxWarnings/raise SyntaxErrors on too late
global statements. Makes test_global.py
pass (but you need to erase lib/_sre.py i think
because using the app-level _sre really takes
forever).

added the possibility to specify the compiler
for running compliance tests.

Comments (0)

Files changed (2)

lib-python/conftest.py

     """ Regression Test Declaration.""" 
     def __init__(self, basename, enabled=False, dumbtest=False,
                                  oldstyle=False, core=False, uselibfile=False,
+                                 compiler=None, 
                                  usemodules = ''): 
         self.basename = basename 
         self.enabled = enabled 
         self._oldstyle = oldstyle 
         self._uselibfile = uselibfile
         self._usemodules = usemodules.split()
+        self.compiler = compiler 
         self.core = core
 
     def oldstyle(self): 
 
     RegrTest('test_gl.py', enabled=False, dumbtest=1),
     RegrTest('test_glob.py', enabled=True, core=True),
-    RegrTest('test_global.py', enabled=True, core=True),
+    RegrTest('test_global.py', enabled=True, core=True, compiler='_stable'),
         # this fails because it relies on the warnings module 
         # turning a warning into an exception, but PyPy's
         # interplevel doesn't call into the app-level warnings
             pypy_options.append('--oldstyle') 
         if regrtest.uselibfile: 
             pypy_options.append('--uselibfile')
+        if regrtest.compiler:
+            pypy_options.append('--compiler=%s' % regrtest.compiler)
         pypy_options.extend(
             ['--usemodules=%s' % mod for mod in regrtest.usemodules])
         sopt = " ".join(pypy_options) 

pypy/lib/_stablecompiler/symbols.py

                    SC_UNKNOWN, SC_DEFAULT
 from misc import mangle
 import types
-
+import warnings
 
 import sys
 
 MANGLE_LEN = 256
 
+def issue_warning(msg, filename, lineno): 
+    try:
+        warnings.warn_explicit(msg, SyntaxWarning, filename, lineno)
+    except SyntaxWarning:
+        err = SyntaxError(msg)
+        err.filename = filename
+        err.lineno = lineno
+        raise err 
+
 class Scope:
     localsfullyknown = True
     # XXX how much information do I need about each name?
 
     def visitGlobal(self, node, scope):
         for name in node.names:
+            namescope = scope.check_name(name)
+            if namescope == SC_LOCAL:
+                issue_warning("name '%s' is assigned to before "
+                              "global declaration" %(name,),
+                              node.filename, node.lineno) 
+            elif namescope != SC_GLOBAL and name in scope.uses:
+                issue_warning("name '%s' is used prior "
+                              "to global declaration" %(name,), 
+                              node.filename, node.lineno)
             scope.add_global(name)
 
     def visitAssign(self, node, scope):