[pypy-svn] r56607 - in pypy/branch/2.5-features/pypy/interpreter: astcompiler pyparser test

bgola at codespeak.net bgola at codespeak.net
Thu Jul 17 00:09:10 CEST 2008


Author: bgola
Date: Thu Jul 17 00:09:08 2008
New Revision: 56607

Modified:
   pypy/branch/2.5-features/pypy/interpreter/astcompiler/pycodegen.py
   pypy/branch/2.5-features/pypy/interpreter/pyparser/astbuilder.py
   pypy/branch/2.5-features/pypy/interpreter/test/test_compiler.py
Log:
fixing some tests under interpreter/test/

Modified: pypy/branch/2.5-features/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/astcompiler/pycodegen.py	(original)
+++ pypy/branch/2.5-features/pypy/interpreter/astcompiler/pycodegen.py	Thu Jul 17 00:09:08 2008
@@ -333,18 +333,21 @@
         self.set_lineno(node)
         for default in node.defaults:
             default.accept( self )
+        self._makeClosure(gen, len(node.defaults))
+        for i in range(ndecorators):
+            self.emitop_int('CALL_FUNCTION', 1)
+
+    def _makeClosure(self, gen, args):
         frees = gen.scope.get_free_vars_in_parent()
         if frees:
             for name in frees:
                 self.emitop('LOAD_CLOSURE', name)
+            self.emitop_int('BUILD_TUPLE', len(frees))
             self.emitop_code('LOAD_CONST', gen)
-            self.emitop_int('MAKE_CLOSURE', len(node.defaults))
+            self.emitop_int('MAKE_CLOSURE', args)
         else:
             self.emitop_code('LOAD_CONST', gen)
-            self.emitop_int('MAKE_FUNCTION', len(node.defaults))
-
-        for i in range(ndecorators):
-            self.emitop_int('CALL_FUNCTION', 1)
+            self.emitop_int('MAKE_FUNCTION', args)
 
     def visitClass(self, node):
         gen = ClassCodeGenerator(self.space, node,
@@ -356,15 +359,7 @@
         for base in node.bases:
             base.accept( self )
         self.emitop_int('BUILD_TUPLE', len(node.bases))
-        frees = gen.scope.get_free_vars_in_parent()
-        if frees:
-            for name in frees:
-                self.emitop('LOAD_CLOSURE', name)
-            self.emitop_code('LOAD_CONST', gen)
-            self.emitop_int('MAKE_CLOSURE', 0)
-        else:
-            self.emitop_code('LOAD_CONST', gen)
-            self.emitop_int('MAKE_FUNCTION', 0)
+        self._makeClosure(gen, 0)
         self.emitop_int('CALL_FUNCTION', 0)
         self.emit('BUILD_CLASS')
         self.storeName(node.name, node.lineno)
@@ -658,16 +653,7 @@
         inner.accept( gen )
         gen.finish()
         self.set_lineno(node)
-        frees = gen.scope.get_free_vars_in_parent()
-        if frees:
-            for name in frees:
-                self.emitop('LOAD_CLOSURE', name)
-            self.emitop_code('LOAD_CONST', gen)
-            self.emitop_int('MAKE_CLOSURE', 0)
-        else:
-            self.emitop_code('LOAD_CONST', gen)
-            self.emitop_int('MAKE_FUNCTION', 0)
-
+        self._makeClosure(gen, 0)
         # precomputation of outmost iterable
         qual0 = inner.quals[0]
         assert isinstance(qual0, ast.GenExprFor)
@@ -1167,10 +1153,11 @@
         self.emit('RETURN_VALUE')
 
     def visitYield(self, node):
-        if len(self.setups):
-            kind, block = self.setups[-1]
-            if kind  == TRY_FINALLY:
-                raise SyntaxError("'yield' not allowed in a 'try' block "
+        if self.space.config.objspace.pyversion < '2.5':
+            if len(self.setups):
+                kind, block = self.setups[-1]
+                if kind  == TRY_FINALLY:
+                    raise SyntaxError("'yield' not allowed in a 'try' block "
                                   "with a 'finally' clause",
                                   node.lineno)
         self.set_lineno(node)

Modified: pypy/branch/2.5-features/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/pyparser/astbuilder.py	(original)
+++ pypy/branch/2.5-features/pypy/interpreter/pyparser/astbuilder.py	Thu Jul 17 00:09:08 2008
@@ -837,7 +837,7 @@
     """
     import_from: 'from' dotted_name 'import' ('*' | '(' import_as_names [','] ')' | import_as_names)
 
-    import_as_names: import_as_name (',' import_as_name)*
+    import_as_names: import_as_name (',' import_as_name)* [',']
     import_as_name: NAME [NAME NAME]
     """
     atoms = get_atoms(builder, nb)
@@ -855,6 +855,10 @@
             tokens = slicecut( atoms, index+1, -1 )
         else:
             tokens = atoms[index:]
+            if tokens[-1].name == builder.parser.tokens['COMMA']:
+                raise SyntaxError, "trailing comma not allowed without" \
+                        "surrounding parentheses"
+
         index = 0
         l = len(tokens)
         names = []

Modified: pypy/branch/2.5-features/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/test/test_compiler.py	(original)
+++ pypy/branch/2.5-features/pypy/interpreter/test/test_compiler.py	Thu Jul 17 00:09:08 2008
@@ -582,10 +582,6 @@
         assert space.float_w(w_result) == 0
 
 
-class TestECCompiler(BaseTestCompiler):
-    def setup_method(self, method):
-        self.compiler = self.space.getexecutioncontext().compiler
-
 class TestPyCCompiler(BaseTestCompiler):
     def setup_method(self, method):
         self.compiler = CPythonCompiler(self.space)
@@ -600,16 +596,15 @@
         def skip_on_2_4(self):
             py.test.skip("syntax not supported by the CPython 2.4 compiler")
         test_continue_in_nested_finally = skip_on_2_4
+    elif sys.version_info > (2, 4):
+        def skip_on_2_5(self):
+            py.test.skip("syntax changed in CPython 2.5 compiler")
+        test_yield_in_finally = skip_on_2_5
+            
 
-
-class TestPythonAstCompiler(BaseTestCompiler):
+class TestPythonAstCompiler_25_grammar(BaseTestCompiler):
     def setup_method(self, method):
-        self.compiler = PythonAstCompiler(self.space, "2.4")
-
-
-class TestPythonAstCompiler_25_grammar:
-    def setup_method(self, method):
-        self.compiler = PythonAstCompiler(self.space, "2.5a")
+        self.compiler = PythonAstCompiler(self.space, "2.5")
 
     def test_from_future_import(self):
         source = """from __future__ import with_statement
@@ -626,6 +621,22 @@
         assert isinstance(code, PyCode)
         assert code.co_filename == '<filename2>'
 
+    def test_yield_in_finally(self): # behavior changed in 2.5
+        code ='def f():\n try:\n  yield 19\n finally:\n  pass\n'
+        self.compiler.compile(code, '', 'single', 0)
+
+
+class TestECCompiler(BaseTestCompiler):
+    def setup_method(self, method):
+        self.space.config.objspace.pyversion = "2.4"
+        self.compiler = self.space.getexecutioncontext().compiler
+
+
+class TestPythonAstCompiler(BaseTestCompiler):
+    def setup_method(self, method):
+        self.space.config.objspace.pyversion = "2.4"
+        self.compiler = PythonAstCompiler(self.space, "2.4")
+
 
 class AppTestOptimizer:
     def test_constant_fold_add(self):



More information about the Pypy-commit mailing list