From: <zy...@us...> - 2008-08-09 05:36:19
|
Revision: 5114 http://jython.svn.sourceforge.net/jython/?rev=5114&view=rev Author: zyasoft Date: 2008-08-09 05:36:17 +0000 (Sat, 09 Aug 2008) Log Message: ----------- Reordered code to test for raising exceptions thrown into a generator, fixing test cases in test_contextlib, test_generators, and test_with. Modified Paths: -------------- branches/asm/src/org/python/compiler/ClassFile.java branches/asm/src/org/python/compiler/CodeCompiler.java branches/asm/src/org/python/compiler/Module.java Modified: branches/asm/src/org/python/compiler/ClassFile.java =================================================================== --- branches/asm/src/org/python/compiler/ClassFile.java 2008-08-09 00:37:11 UTC (rev 5113) +++ branches/asm/src/org/python/compiler/ClassFile.java 2008-08-09 05:36:17 UTC (rev 5114) @@ -48,9 +48,7 @@ this.interfaces = new String[0]; this.access = access; - //XXX: can we do better than ASM for computing MAXS? cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); - methodVisitors = Collections.synchronizedList(new ArrayList()); fieldVisitors = Collections.synchronizedList(new ArrayList()); } Modified: branches/asm/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-09 00:37:11 UTC (rev 5113) +++ branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-09 05:36:17 UTC (rev 5114) @@ -552,7 +552,15 @@ throw new ParseException("'yield' outside function", node); } - saveLocals(); + loadFrame(); + code.invokevirtual("org/python/core/PyFrame", "getGeneratorInput", "()" + $obj); + code.dup(); + code.instanceof_("org/python/core/PyException"); + Label done = new Label(); + code.ifeq(done); + code.checkcast("java/lang/Throwable"); + code.athrow(); + code.label(done); if (node.value != null) { visit(node.value); @@ -560,6 +568,7 @@ getNone(); } setLastI(++yield_count); + saveLocals(); code.areturn(); Label restart = new Label(); @@ -568,10 +577,10 @@ restoreLocals(); loadFrame(); - code.invokevirtual("org/python/core/PyFrame", "getGeneratorInput", "()" + $obj); + code.invokevirtual("org/python/core/PyFrame", "checkGeneratorInput", "()" + $obj); code.dup(); code.instanceof_("org/python/core/PyException"); - Label done = new Label(); + done = new Label(); code.ifeq(done); code.checkcast("java/lang/Throwable"); code.athrow(); Modified: branches/asm/src/org/python/compiler/Module.java =================================================================== --- branches/asm/src/org/python/compiler/Module.java 2008-08-09 00:37:11 UTC (rev 5113) +++ branches/asm/src/org/python/compiler/Module.java 2008-08-09 05:36:17 UTC (rev 5114) @@ -437,19 +437,7 @@ if (scope.generator) { c.label(genswitch); - // throw any exception that was sent into this generator c.aload(1); - c.invokevirtual("org/python/core/PyFrame", "checkGeneratorInput", "()" + $obj); - c.dup(); - c.instanceof_("org/python/core/PyException"); - Label done = new Label(); - c.ifeq(done); - c.checkcast("java/lang/Throwable"); - c.athrow(); - c.label(done); - - c.pop(); - c.aload(1); c.getfield("org/python/core/PyFrame", "f_lasti", "I"); Label[] yields = new Label[compiler.yields.size()+1]; @@ -458,7 +446,6 @@ yields[i] = (Label) compiler.yields.elementAt(i-1); } c.tableswitch(0, yields.length - 1, start, yields); - // XXX: Generate an error } // !classdef only This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-10 15:31:57
|
Revision: 5131 http://jython.svn.sourceforge.net/jython/?rev=5131&view=rev Author: fwierzbicki Date: 2008-08-10 15:31:52 +0000 (Sun, 10 Aug 2008) Log Message: ----------- Choose a name for the bound parameter to generator expressions that can't collide with a real NAME. Arbitrarily picked _(x) just because it looks a bit like the names of the gen expressions themselves. Modified Paths: -------------- branches/asm/src/org/python/compiler/CodeCompiler.java branches/asm/src/org/python/compiler/ScopesCompiler.java Modified: branches/asm/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-10 15:03:21 UTC (rev 5130) +++ branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-10 15:31:52 UTC (rev 5131) @@ -1964,7 +1964,7 @@ } public Object visitGeneratorExp(GeneratorExp node) throws Exception { - String bound_exp = "x"; + String bound_exp = "_(x)"; String tmp_append ="_(" + node.getLine() + "_" + node.getCharPositionInLine() + ")"; setline(node); Modified: branches/asm/src/org/python/compiler/ScopesCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/ScopesCompiler.java 2008-08-10 15:03:21 UTC (rev 5130) +++ branches/asm/src/org/python/compiler/ScopesCompiler.java 2008-08-10 15:31:52 UTC (rev 5131) @@ -250,7 +250,7 @@ } public Object visitGeneratorExp(GeneratorExp node) throws Exception { - String bound_exp = "x"; + String bound_exp = "_(x)"; String tmp ="_(" + node.getLine() + "_" + node.getCharPositionInLine() + ")"; def(tmp); ArgListCompiler ac = new ArgListCompiler(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-08-11 02:56:55
|
Revision: 5141 http://jython.svn.sourceforge.net/jython/?rev=5141&view=rev Author: zyasoft Date: 2008-08-11 02:56:53 +0000 (Mon, 11 Aug 2008) Log Message: ----------- from X import * now raises the appropriate syntax errors (for nested scopes) or warning (otherwise). Modified Paths: -------------- branches/asm/src/org/python/compiler/CodeCompiler.java branches/asm/src/org/python/compiler/ScopeInfo.java Modified: branches/asm/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-11 00:32:24 UTC (rev 5140) +++ branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-11 02:56:53 UTC (rev 5141) @@ -768,6 +768,23 @@ code.ldc(node.module); //Note: parser does not allow node.names.length == 0 if (node.names.length == 1 && node.names[0].name.equals("*")) { + if (my_scope.func_level > 0) { + module.error("import * only allowed at module level", false, node); + + if (my_scope.contains_ns_free_vars) { + module.error("import * is not allowed in function '" + + my_scope.scope_name + + "' because it contains a nested function with free variables", + true, node); + } + } + if (my_scope.func_level > 1) { + module.error("import * is not allowed in function '" + + my_scope.scope_name + + "' because it is a nested function", + true, node); + } + loadFrame(); code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); } else { Modified: branches/asm/src/org/python/compiler/ScopeInfo.java =================================================================== --- branches/asm/src/org/python/compiler/ScopeInfo.java 2008-08-11 00:32:24 UTC (rev 5140) +++ branches/asm/src/org/python/compiler/ScopeInfo.java 2008-08-11 02:56:53 UTC (rev 5141) @@ -52,6 +52,7 @@ public boolean unqual_exec; public boolean exec; public boolean from_import_star; + public boolean contains_ns_free_vars; public boolean generator; public int yield_count; public int max_with_count; @@ -179,6 +180,12 @@ names.addElement(purecells.elementAt(i)); } } + + if (some_free && nested) { + up.contains_ns_free_vars = true; + } + // XXX - this doesn't catch all cases - may depend subtly + // on how visiting NOW works with antlr compared to javacc if ((unqual_exec || from_import_star)) { if(some_inner_free) dynastuff_trouble(true, ctxt); else if(func_level > 1 && some_free) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |