[Jython-checkins] jython: Mark the synthetic return node used by lambda. This allows this node

frank.wierzbicki jython-checkins at python.org
Wed Mar 14 04:09:32 CET 2012


http://hg.python.org/jython/rev/a7d12eca6887
changeset:   6344:a7d12eca6887
parent:      6341:1bde50fae0be
user:        Jim Baker <jbaker at zyasoft.com>
date:        Tue Mar 13 15:08:50 2012 -0700
summary:
  Mark the synthetic return node used by lambda. This allows this node
to be ignored in the case of an expression returning within a
generator introduced by a yield. Normal usage of return within a
lambda is still caught by the parser.

files:
  src/org/python/compiler/CodeCompiler.java |  15 ++++++++--
  1 files changed, 12 insertions(+), 3 deletions(-)


diff --git a/src/org/python/compiler/CodeCompiler.java b/src/org/python/compiler/CodeCompiler.java
--- a/src/org/python/compiler/CodeCompiler.java
+++ b/src/org/python/compiler/CodeCompiler.java
@@ -846,7 +846,7 @@
         }
         int tmp = 0;
         if (node.getInternalValue() != null) {
-            if (my_scope.generator) {
+            if (my_scope.generator && !(node instanceof LambdaSyntheticReturn)) {
                 throw new ParseException("'return' with argument " +
                         "inside generator", node);
             }
@@ -2255,13 +2255,22 @@
         return null;
     }
 
+
+    // a marker class to distinguish this usage; future generator rewriting may likely
+    // want to remove this support
+    private class LambdaSyntheticReturn extends Return {
+        private LambdaSyntheticReturn(PythonTree tree, expr value) {
+            super(tree, value);
+        }
+    }
+    
     @Override
     public Object visitLambda(Lambda node) throws Exception {
         String name = "<lambda>";
 
-        //Add a return node onto the outside of suite;
+        //Add a synthetic return node onto the outside of suite;
         java.util.List<stmt> bod = new ArrayList<stmt>();
-        bod.add(new Return(node, node.getInternalBody()));
+        bod.add(new LambdaSyntheticReturn(node, node.getInternalBody()));
         mod retSuite = new Suite(node, bod);
 
         setline(node);

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list