[pypy-svn] r50451 - in pypy/branch/astcompilertests/pypy/interpreter/astcompiler: . test

arigo at codespeak.net arigo at codespeak.net
Tue Jan 8 22:45:44 CET 2008


Author: arigo
Date: Tue Jan  8 22:45:44 2008
New Revision: 50451

Modified:
   pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py
   pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_compiler.py
Log:
Test and fix - just reordering a few lines of code.

Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py	(original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py	Tue Jan  8 22:45:44 2008
@@ -1375,7 +1375,10 @@
         self.emit('PRINT_EXPR')
         
 class AbstractFunctionCode(CodeGenerator):
-    def __init__(self, space, func, isLambda, mod):
+    def __init__(self, space, scope, func, isLambda, mod):
+        assert scope is not None
+        self.scope = scope
+        self.localsfullyknown = self.scope.locals_fully_known()
         self.module = mod
         if isLambda:
             name = "<lambda>"
@@ -1414,6 +1417,9 @@
         CodeGenerator.__init__(self, space, graph)
         self.optimized = 1
 
+        self.graph.setFreeVars(self.scope.get_free_vars_in_scope())
+        self.graph.setCellVars(self.scope.get_cell_vars())
+
         if not isLambda:
             self.setDocstring(func.w_doc)
 
@@ -1459,13 +1465,8 @@
 class FunctionCodeGenerator(AbstractFunctionCode):
 
     def __init__(self, space, func, isLambda, mod):
-        assert func.scope is not None
-        self.scope = func.scope
-        self.localsfullyknown = self.scope.locals_fully_known()
-        AbstractFunctionCode.__init__(self, space, func, isLambda, mod)
-        
-        self.graph.setFreeVars(self.scope.get_free_vars_in_scope())
-        self.graph.setCellVars(self.scope.get_cell_vars())
+        AbstractFunctionCode.__init__(self, space, func.scope,
+                                      func, isLambda, mod)
         if self.scope.generator:
             self.graph.setFlag(CO_GENERATOR)
             if self.scope.return_with_arg is not None:
@@ -1476,12 +1477,7 @@
 class GenExprCodeGenerator(AbstractFunctionCode):
 
     def __init__(self, space, gexp, mod):
-        assert gexp.scope is not None
-        self.scope = gexp.scope
-        self.localsfullyknown = self.scope.locals_fully_known()
-        AbstractFunctionCode.__init__(self, space, gexp, 1, mod)
-        self.graph.setFreeVars(self.scope.get_free_vars_in_scope())
-        self.graph.setCellVars(self.scope.get_cell_vars())
+        AbstractFunctionCode.__init__(self, space, gexp.scope, gexp, 1, mod)
         self.graph.setFlag(CO_GENERATOR)
 
 class AbstractClassCode(CodeGenerator):

Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_compiler.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_compiler.py	(original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_compiler.py	Tue Jan  8 22:45:44 2008
@@ -393,6 +393,16 @@
         yield self.st, decl, 'A,A1,A2,B2,C,C1,C2,D1,E,G,G1,G2,N1', \
                              (6,6 ,4 ,1 ,5,5 ,5 ,3 ,8,2,2 ,2 ,7 )
 
+        decl = py.code.Source("""
+            def f((a, b)):
+                def g((c, d)):
+                    return (a, b, c, d)
+                return g
+            x = f((1, 2))((3, 4))
+        """)
+        decl = str(decl) + "\n"
+        yield self.st, decl, 'x', (1, 2, 3, 4)
+
     def test_try_except_finally(self):
         yield self.simple_test, """
             try:


More information about the pypy-svn mailing list