From: Samuele P. <ped...@us...> - 2001-05-15 18:53:38
|
Update of /cvsroot/jython/jython/org/python/compiler In directory usw-pr-cvs1:/tmp/cvs-serv2169/compiler Modified Files: CodeCompiler.java Module.java ScopeInfo.java ScopesCompiler.java Added Files: CompilationContext.java Log Message: - fixed bug #415963 UnboundLocalError not raised on delete . - fixed bug related to free+bound vars in class scope . - incresead CPython compatibility: * code supports co_nlocals, co_flags have CO_OPTIMIZED set when meaningful * def f(): locals()['a']=1 print a now raises a NameError (like in CPython) * co_varnames == () and co_nlocals = 0 for classdef code ! Py.newCode and related funcs signatures have been changed - PyFrame.getf_locals() now deals with cell and free vars and handles the classdef case - compiler tiny mods for use by jythonc nested scopes support --- NEW FILE --- package org.python.compiler; import org.python.parser.SimpleNode; public interface CompilationContext { public Future getFutures(); public void error(String msg,boolean err,SimpleNode node) throws Exception; public String getFilename(); } Index: CodeCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/CodeCompiler.java,v retrieving revision 2.13 retrieving revision 2.14 diff -C2 -r2.13 -r2.14 *** CodeCompiler.java 2001/03/10 02:13:48 2.13 --- CodeCompiler.java 2001/05/15 18:53:34 2.14 *************** *** 12,16 **** import java.util.Vector; ! public class CodeCompiler extends Visitor { public static final Object Exit=new Integer(1); --- 12,16 ---- import java.util.Vector; ! public class CodeCompiler extends Visitor implements CompilationContext { public static final Object Exit=new Integer(1); *************** *** 39,42 **** --- 39,46 ---- public ScopeInfo my_scope; + public Future getFutures() { return futures; } + public String getFilename() { return module.sfilename; } + + boolean optimizeGlobals = true; public Vector names; *************** *** 200,204 **** tbl = scope.tbl; ! optimizeGlobals = !scope.exec&&!scope.from_import_star; mode = GET; --- 204,208 ---- tbl = scope.tbl; ! optimizeGlobals = fast_locals&&!scope.exec&&!scope.from_import_star; mode = GET; *************** *** 2270,2274 **** if (!my_scope.nested_scopes) flags &= ~ScopeInfo.FREE; if ((flags&ScopeInfo.GLOBAL) !=0 || ! optimizeGlobals&&fast_locals&&(flags&(ScopeInfo.BOUND|ScopeInfo.CELL|ScopeInfo.FREE))==0) { code.ldc(name); if (mrefs.getglobal == 0) { --- 2274,2278 ---- if (!my_scope.nested_scopes) flags &= ~ScopeInfo.FREE; if ((flags&ScopeInfo.GLOBAL) !=0 || ! optimizeGlobals&&(flags&(ScopeInfo.BOUND|ScopeInfo.CELL|ScopeInfo.FREE))==0) { code.ldc(name); if (mrefs.getglobal == 0) { *************** *** 2302,2306 **** } } ! if ((flags&ScopeInfo.FREE) != 0) { code.iconst(syminf.env_index); if (mrefs.getderef == 0) { --- 2306,2310 ---- } } ! if ((flags&ScopeInfo.FREE) != 0 && (flags&ScopeInfo.BOUND) == 0) { code.iconst(syminf.env_index); if (mrefs.getderef == 0) { *************** *** 2419,2421 **** --- 2423,2426 ---- return null; } + } Index: Module.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Module.java,v retrieving revision 2.5 retrieving revision 2.6 diff -C2 -r2.5 -r2.6 *** Module.java 2001/03/13 20:19:10 2.5 --- Module.java 2001/05/15 18:53:34 2.6 *************** *** 198,201 **** --- 198,203 ---- public String[] freevars; public int xxx_npurecell; + + public int moreflags; public PyCodeConstant() { ; *************** *** 211,215 **** //Make all names ! CodeCompiler.makeStrings(c, names, names.length); c.ldc(((PyStringConstant)module.filename).value); --- 213,221 ---- //Make all names ! if (names != null) { ! CodeCompiler.makeStrings(c, names, names.length); ! } else { // classdef ! CodeCompiler.makeStrings(c, null, 0); ! } c.ldc(((PyStringConstant)module.filename).value); *************** *** 233,240 **** c.iconst(xxx_npurecell); int mref_newCode = c.pool.Methodref( "org/python/core/Py", "newCode", ! "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;I)Lorg/python/core/PyCode;"); c.invokestatic(mref_newCode); --- 239,248 ---- c.iconst(xxx_npurecell); + c.iconst(moreflags); + int mref_newCode = c.pool.Methodref( "org/python/core/Py", "newCode", ! "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); c.invokestatic(mref_newCode); *************** *** 413,417 **** compiler.parse(tree, c, fast_locals, className, classBody, scope); ! code.names = toNameAr(compiler.names,false); if (scope != null) { --- 421,426 ---- compiler.parse(tree, c, fast_locals, className, classBody, scope); ! // !classdef only ! if (!classBody) code.names = toNameAr(compiler.names,false); if (scope != null) { *************** *** 419,422 **** --- 428,434 ---- code.freevars = toNameAr(scope.freevars,true); code.xxx_npurecell = scope.xxx_npurecell; + if (compiler.optimizeGlobals) { + code.moreflags |= org.python.core.PyTableCode.CO_OPTIMIZED; + } } Index: ScopeInfo.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopeInfo.java,v retrieving revision 2.2 retrieving revision 2.3 diff -C2 -r2.2 -r2.3 *** ScopeInfo.java 2001/03/11 16:29:31 2.2 --- ScopeInfo.java 2001/05/15 18:53:34 2.3 *************** *** 110,114 **** public int cell; ! public void cook(ScopeInfo up,CodeCompiler ctxt) throws Exception { if (up == null) return; // top level => nop --- 110,114 ---- public int cell; ! public void cook(ScopeInfo up,CompilationContext ctxt) throws Exception { if (up == null) return; // top level => nop *************** *** 176,180 **** } ! private void dynastuff_trouble(boolean inner_free,CodeCompiler ctxt) throws Exception { String illegal; if (unqual_exec && from_import_star) --- 176,180 ---- } ! private void dynastuff_trouble(boolean inner_free,CompilationContext ctxt) throws Exception { String illegal; if (unqual_exec && from_import_star) Index: ScopesCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopesCompiler.java,v retrieving revision 2.2 retrieving revision 2.3 diff -C2 -r2.2 -r2.3 *** ScopesCompiler.java 2001/03/10 02:13:48 2.2 --- ScopesCompiler.java 2001/05/15 18:53:34 2.3 *************** *** 8,12 **** public class ScopesCompiler extends Visitor implements ScopeConstants { ! private CodeCompiler code_compiler; private boolean nested_scopes = false; --- 8,12 ---- public class ScopesCompiler extends Visitor implements ScopeConstants { ! private CompilationContext code_compiler; private boolean nested_scopes = false; *************** *** 24,28 **** private int func_level = 0; ! public ScopesCompiler(CodeCompiler code_compiler) { // ?? polish this.code_compiler = code_compiler; scopes = new Stack(); --- 24,28 ---- private int func_level = 0; ! public ScopesCompiler(CompilationContext code_compiler) { // ?? polish this.code_compiler = code_compiler; scopes = new Stack(); *************** *** 30,34 **** String nested_scopes_opt = org.python.core.PySystemState.registry.getProperty("python.xfutures.nested_scopes"); if (nested_scopes_opt != null && nested_scopes_opt.equals("on")) nested_scopes = true; else ! nested_scopes = code_compiler.futures.areNestedScopesOn(); // System.err.println("nested-scopes: "+nested_scopes); } --- 30,34 ---- String nested_scopes_opt = org.python.core.PySystemState.registry.getProperty("python.xfutures.nested_scopes"); if (nested_scopes_opt != null && nested_scopes_opt.equals("on")) nested_scopes = true; else ! nested_scopes = code_compiler.getFutures().areNestedScopesOn(); // System.err.println("nested-scopes: "+nested_scopes); } *************** *** 72,76 **** --- 72,80 ---- public void parse(SimpleNode node) throws Exception { + try { node.visit(this); + } catch(Throwable t) { + throw org.python.core.parser.fixParseError(null,t,code_compiler.getFilename()); + } } |