From: <th...@us...> - 2008-10-17 20:46:49
|
Revision: 5456 http://jython.svn.sourceforge.net/jython/?rev=5456&view=rev Author: thobes Date: 2008-10-17 20:46:47 +0000 (Fri, 17 Oct 2008) Log Message: ----------- Improved the scope analysis for generator expressions. Also fixed a bug in my recent commit where the fix for yield as an expression accidentially reordered the value to be yielded on the stack. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java trunk/jython/src/org/python/compiler/ScopesCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-17 19:28:20 UTC (rev 5455) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-17 20:46:47 UTC (rev 5456) @@ -555,13 +555,16 @@ throw new ParseException("'yield' outside function", node); } + int stackState = saveStack(); + if (node.value != null) { visit(node.value); } else { getNone(); } + setLastI(++yield_count); - int stackState = saveStack(); + saveLocals(); code.areturn(); Modified: trunk/jython/src/org/python/compiler/ScopesCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/ScopesCompiler.java 2008-10-17 19:28:20 UTC (rev 5455) +++ trunk/jython/src/org/python/compiler/ScopesCompiler.java 2008-10-17 20:46:47 UTC (rev 5456) @@ -271,9 +271,9 @@ @Override public Object visitGeneratorExp(GeneratorExp node) throws Exception { // The first iterator is evaluated in the outer scope - /*if (node.generators != null && node.generators.length > 0) { + if (node.generators != null && node.generators.length > 0) { visit(node.generators[0].iter); - }*/ + } String bound_exp = "_(x)"; String tmp = "_(" + node.getLine() + "_" + node.getCharPositionInLine() + ")"; @@ -289,7 +289,7 @@ cur.generator = true; cur.yield_count++; // The reset of the iterators are evaluated in the inner scope - /*if (node.elt != null) { + if (node.elt != null) { visit(node.elt); } if (node.generators != null) { @@ -310,9 +310,6 @@ } } } - /*/ - traverse(node); - //*/ endScope(); return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |