[Jython-checkins] jython (merge default -> default): merge

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


http://hg.python.org/jython/rev/2584e1ab76c0
changeset:   6349:2584e1ab76c0
parent:      6348:e3e82ea6bc53
parent:      6346:9e9f72d78bd6
user:        Shashank Bharadwaj <shanka.mns at gmail.com>
date:        Tue Mar 13 16:08:11 2012 -0700
summary:
  merge

files:
  src/org/python/compiler/CodeCompiler.java |  15 ++++++++--
  src/org/python/core/Options.java          |   4 ++
  2 files changed, 16 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);
diff --git a/src/org/python/core/Options.java b/src/org/python/core/Options.java
--- a/src/org/python/core/Options.java
+++ b/src/org/python/core/Options.java
@@ -85,6 +85,10 @@
     //XXX: place holder
     public static int bytes_warning = 0;
 
+    // Corresponds to -O (Python bytecode optimization), -OO (remove docstrings)
+    // flags in CPython; it's not clear how Jython should expose its optimization,
+    // but this is user visible as of 2.7.
+    public static int optimize = 0;
 
     /**
      * Enable division warning. The value maps to the registry values of

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


More information about the Jython-checkins mailing list