From: Finn B. <bc...@us...> - 2001-11-27 13:51:41
|
Update of /cvsroot/jython/jython/org/python/compiler In directory usw-pr-cvs1:/tmp/cvs-serv9040/compiler Modified Files: AdapterMaker.java ArgListCompiler.java ClassFile.java Code.java CodeCompiler.java CompilationContext.java ConstantPool.java Future.java JavaMaker.java Label.java Module.java ProxyMaker.java ScopeConstants.java ScopeInfo.java SymInfo.java Log Message: Whitespace normalization. Index: AdapterMaker.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/AdapterMaker.java,v retrieving revision 2.5 retrieving revision 2.6 diff -C2 -d -r2.5 -r2.6 *** AdapterMaker.java 2001/10/28 17:13:41 2.5 --- AdapterMaker.java 2001/11/27 13:51:37 2.6 *************** *** 46,50 **** } } ! public void addMethod(Method method, int access) throws Exception { Class[] parameters = method.getParameterTypes(); --- 46,50 ---- } } ! public void addMethod(Method method, int access) throws Exception { Class[] parameters = method.getParameterTypes(); Index: ArgListCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ArgListCompiler.java,v retrieving revision 2.6 retrieving revision 2.7 diff -C2 -d -r2.6 -r2.7 *** ArgListCompiler.java 2001/10/28 17:13:41 2.6 --- ArgListCompiler.java 2001/11/27 13:51:37 2.7 *************** *** 67,71 **** } names.addElement(name); ! //Handle tuple arguments properly if (node.getChild(0).id == PythonGrammarTreeConstants.JJTFPLIST) { --- 67,71 ---- } names.addElement(name); ! //Handle tuple arguments properly if (node.getChild(0).id == PythonGrammarTreeConstants.JJTFPLIST) { Index: ClassFile.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ClassFile.java,v retrieving revision 2.5 retrieving revision 2.6 diff -C2 -d -r2.5 -r2.6 *** ClassFile.java 2001/10/28 17:13:41 2.5 --- ClassFile.java 2001/11/27 13:51:37 2.6 *************** *** 58,62 **** return new String(c); } ! public ClassFile(String name) { this(name, "java/lang/Object", SYNCHRONIZED | PUBLIC); --- 58,62 ---- return new String(c); } ! public ClassFile(String name) { this(name, "java/lang/Object", SYNCHRONIZED | PUBLIC); *************** *** 119,123 **** } } ! public void addAttribute(Attribute attr) throws IOException { attributes.addElement(attr); --- 119,123 ---- } } ! public void addAttribute(Attribute attr) throws IOException { attributes.addElement(attr); *************** *** 127,131 **** //Write Header int thisclass = pool.Class(name); ! int superclass = pool.Class(this.superclass); stream.writeInt(0xcafebabe); --- 127,131 ---- //Write Header int thisclass = pool.Class(name); ! int superclass = pool.Class(this.superclass); stream.writeInt(0xcafebabe); *************** *** 150,154 **** int n = attributes.size(); stream.writeShort(n); ! for (int i=0; i<n; i++) { ((Attribute)attributes.elementAt(i)).write(stream); --- 150,154 ---- int n = attributes.size(); stream.writeShort(n); ! for (int i=0; i<n; i++) { ((Attribute)attributes.elementAt(i)).write(stream); Index: Code.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Code.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -d -r2.4 -r2.5 *** Code.java 2001/10/28 17:13:42 2.4 --- Code.java 2001/11/27 13:51:37 2.5 *************** *** 6,10 **** import java.util.Vector; ! class ExceptionLabel { public Label start, end, handler; --- 6,10 ---- import java.util.Vector; ! class ExceptionLabel { public Label start, end, handler; *************** *** 20,24 **** ! public class Code extends Attribute { ConstantPool pool; --- 20,24 ---- ! public class Code extends Attribute { ConstantPool pool; Index: CodeCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/CodeCompiler.java,v retrieving revision 2.21 retrieving revision 2.22 diff -C2 -d -r2.21 -r2.22 *** CodeCompiler.java 2001/10/28 17:13:42 2.21 --- CodeCompiler.java 2001/11/27 13:51:37 2.22 *************** *** 35,47 **** public boolean fast_locals, print_results; ! public Future futures; public Hashtable tbl; public ScopeInfo my_scope; ! public Future getFutures() { return futures; } public String getFilename() { return module.sfilename; } ! boolean optimizeGlobals = true; public Vector names; --- 35,47 ---- public boolean fast_locals, print_results; ! public Future futures; public Hashtable tbl; public ScopeInfo my_scope; ! public Future getFutures() { return futures; } public String getFilename() { return module.sfilename; } ! boolean optimizeGlobals = true; public Vector names; *************** *** 202,206 **** scope = node.scope; } ! my_scope = scope; names = scope.names; --- 202,206 ---- scope = node.scope; } ! my_scope = scope; names = scope.names; *************** *** 251,255 **** if (suite.getNumChildren() > 0 && suite.getChild(0).id == PythonGrammarTreeConstants.JJTEXPR_STMT && ! suite.getChild(0).getChild(0).id == PythonGrammarTreeConstants.JJTSTRING) { loadFrame(); --- 251,255 ---- if (suite.getNumChildren() > 0 && suite.getChild(0).id == PythonGrammarTreeConstants.JJTEXPR_STMT && ! suite.getChild(0).getChild(0).id == PythonGrammarTreeConstants.JJTSTRING) { loadFrame(); *************** *** 322,326 **** int getclosure; ! public boolean makeClosure(Vector freenames) throws Exception { if (freenames == null) return false; --- 322,326 ---- int getclosure; ! public boolean makeClosure(Vector freenames) throws Exception { if (freenames == null) return false; *************** *** 333,337 **** "(I)Lorg/python/core/PyObject;"); } ! int tmp = code.getLocal(); code.iconst(n); --- 333,337 ---- "(I)Lorg/python/core/PyObject;"); } ! int tmp = code.getLocal(); code.iconst(n); *************** *** 347,359 **** code.aastore(); } ! code.aload(tmp); code.freeLocal(tmp); ! return true; } ! ! ! int f_globals, PyFunction_init, PyFunction_closure_init; --- 347,359 ---- code.aastore(); } ! code.aload(tmp); code.freeLocal(tmp); ! return true; } ! ! ! int f_globals, PyFunction_init, PyFunction_closure_init; *************** *** 381,385 **** makeArray(node.scope.ac.getDefaults()); ! node.scope.setup_closure(my_scope); node.scope.dump(); --- 381,385 ---- makeArray(node.scope.ac.getDefaults()); ! node.scope.setup_closure(my_scope); node.scope.dump(); *************** *** 388,392 **** Vector freenames = node.scope.freevars; node.scope = null; // release scope info ! getDocString(suite); --- 388,392 ---- Vector freenames = node.scope.freevars; node.scope = null; // release scope info ! getDocString(suite); *************** *** 417,421 **** setline(node); int n = node.getNumChildren(); ! if (n == 1 && node.getChild(0).id >= PythonGrammarTreeConstants.JJTAUG_PLUS && node.getChild(0).id <= PythonGrammarTreeConstants.JJTAUG_POWER) { --- 417,421 ---- setline(node); int n = node.getNumChildren(); ! if (n == 1 && node.getChild(0).id >= PythonGrammarTreeConstants.JJTAUG_PLUS && node.getChild(0).id <= PythonGrammarTreeConstants.JJTAUG_POWER) { *************** *** 557,561 **** throw new ParseException("'break' outside loop", node); } ! Object obj = breakLabels.peek(); if (obj == DoFinally) { --- 557,561 ---- throw new ParseException("'break' outside loop", node); } ! Object obj = breakLabels.peek(); if (obj == DoFinally) { *************** *** 575,579 **** throw new ParseException("'continue' not properly in loop", node); } ! Object obj = continueLabels.peek(); if (obj == DoFinally) { --- 575,579 ---- throw new ParseException("'continue' not properly in loop", node); } ! Object obj = continueLabels.peek(); if (obj == DoFinally) { *************** *** 591,595 **** return return_stmt(node, false); } ! public Object return_stmt(SimpleNode node, boolean inEval) throws Exception --- 591,595 ---- return return_stmt(node, false); } ! public Object return_stmt(SimpleNode node, boolean inEval) throws Exception *************** *** 690,694 **** code.invokestatic(mrefs.importOne); } ! set(asnameNode); --- 690,694 ---- code.invokestatic(mrefs.importOne); } ! set(asnameNode); *************** *** 713,717 **** if (cnode.id == PythonGrammarTreeConstants.JJTIMPORT_AS_NAME) { names[i] = (String)cnode.getChild(0).getInfo(); ! asnameNodes[i] = cnode.getChild(1); } else { names[i] = (String)cnode.getInfo(); --- 713,717 ---- if (cnode.id == PythonGrammarTreeConstants.JJTIMPORT_AS_NAME) { names[i] = (String)cnode.getChild(0).getInfo(); ! asnameNodes[i] = cnode.getChild(1); } else { names[i] = (String)cnode.getInfo(); *************** *** 795,803 **** setline(node); Label end_of_assert = code.getLabel(); ! /* First do an if __debug__: */ loadFrame(); emitGetGlobal("__debug__"); ! if (mrefs.nonzero == 0) { mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject", --- 795,803 ---- setline(node); Label end_of_assert = code.getLabel(); ! /* First do an if __debug__: */ loadFrame(); emitGetGlobal("__debug__"); ! if (mrefs.nonzero == 0) { mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject", *************** *** 807,811 **** code.ifeq(end_of_assert); ! /* Now do the body of the assert */ node.getChild(0).visit(this); --- 807,811 ---- code.ifeq(end_of_assert); ! /* Now do the body of the assert */ node.getChild(0).visit(this); *************** *** 826,833 **** code.invokestatic(mrefs.assert1); } ! /* And finally set the label for the end of it all */ end_of_assert.setPosition(); ! return null; } --- 826,833 ---- code.invokestatic(mrefs.assert1); } ! /* And finally set the label for the end of it all */ end_of_assert.setPosition(); ! return null; } *************** *** 1106,1120 **** int retLocal = code.getLocal(); code.astore(retLocal); ! // Trick the JVM verifier into thinking this code might not be executed code.iconst(1); code.ifeq(skipSuite); ! // The actual finally suite is always executed (since 1 != 0) ret = finallySuite.visit(this); ! // Fake jump to here to pretend this could always happen skipSuite.setPosition(); ! code.ret(retLocal); finallyEnd.setPosition(); --- 1106,1120 ---- int retLocal = code.getLocal(); code.astore(retLocal); ! // Trick the JVM verifier into thinking this code might not be executed code.iconst(1); code.ifeq(skipSuite); ! // The actual finally suite is always executed (since 1 != 0) ret = finallySuite.visit(this); ! // Fake jump to here to pretend this could always happen skipSuite.setPosition(); ! code.ret(retLocal); finallyEnd.setPosition(); *************** *** 1514,1520 **** inst.visit(this); code.ldc(name); ! //System.out.println("invoke: "+name+": "+values.length); ! switch (values.length) { case 0: --- 1514,1520 ---- inst.visit(this); code.ldc(name); ! //System.out.println("invoke: "+name+": "+values.length); ! switch (values.length) { case 0: *************** *** 1544,1548 **** values[1].visit(this); code.invokevirtual(mrefs.invokea2); ! break; default: makeArray(values); --- 1544,1548 ---- values[1].visit(this); code.invokevirtual(mrefs.invokea2); ! break; default: makeArray(values); *************** *** 1557,1561 **** return null; ! } --- 1557,1561 ---- return null; ! } *************** *** 1612,1616 **** values = new SimpleNode[0]; } ! // Detect a method invocation with no keywords if (nKeywords == 0 && starargs == null && kwargs == null && --- 1612,1616 ---- values = new SimpleNode[0]; } ! // Detect a method invocation with no keywords if (nKeywords == 0 && starargs == null && kwargs == null && *************** *** 1619,1623 **** return Invoke(callee.getChild(0), callee.getChild(1), values); } ! callee.visit(this); --- 1619,1623 ---- return Invoke(callee.getChild(0), callee.getChild(1), values); } ! callee.visit(this); *************** *** 1680,1684 **** values[1].visit(this); code.invokevirtual(mrefs.calla2); ! break; case 3: if (mrefs.calla3 == 0) { --- 1680,1684 ---- values[1].visit(this); code.invokevirtual(mrefs.calla2); ! break; case 3: if (mrefs.calla3 == 0) { *************** *** 1782,1786 **** } return null; ! } --- 1782,1786 ---- } return null; ! } *************** *** 1797,1801 **** } else { int old_mode = mode; ! mode = GET; seq.visit(this); index.visit(this); --- 1797,1801 ---- } else { int old_mode = mode; ! mode = GET; seq.visit(this); index.visit(this); *************** *** 1857,1861 **** } } ! switch(mode) { case DEL: --- 1857,1861 ---- } } ! switch(mode) { case DEL: *************** *** 1896,1900 **** n -= 1; } ! if (mrefs.unpackSequence == 0) { mrefs.unpackSequence = code.pool.Methodref( --- 1896,1900 ---- n -= 1; } ! if (mrefs.unpackSequence == 0) { mrefs.unpackSequence = code.pool.Methodref( *************** *** 1911,1915 **** code.iconst(n); code.invokestatic(mrefs.unpackSequence); ! int tmp = code.getLocal(); code.astore(tmp); --- 1911,1915 ---- code.iconst(n); code.invokestatic(mrefs.unpackSequence); ! int tmp = code.getLocal(); code.astore(tmp); *************** *** 2037,2041 **** public Object list_iter(SimpleNode node) throws Exception { if (node.getNumChildren() == 0) { ! int tmp_append = ((Integer) listComprehensionAppends.peek()).intValue(); SimpleNode exprNode = (SimpleNode) listComprehensionExprs.peek(); --- 2037,2041 ---- public Object list_iter(SimpleNode node) throws Exception { if (node.getNumChildren() == 0) { ! int tmp_append = ((Integer) listComprehensionAppends.peek()).intValue(); SimpleNode exprNode = (SimpleNode) listComprehensionExprs.peek(); *************** *** 2109,2114 **** makeArray(node.scope.ac.getDefaults()); ! ! node.scope.setup_closure(my_scope); node.scope.dump(); module.PyCode(retSuite, name, true, className, --- 2109,2114 ---- makeArray(node.scope.ac.getDefaults()); ! ! node.scope.setup_closure(my_scope); node.scope.dump(); module.PyCode(retSuite, name, true, className, *************** *** 2132,2136 **** code.invokespecial(mrefs.PyFunction_closure_init1); } ! return null; } --- 2132,2136 ---- code.invokespecial(mrefs.PyFunction_closure_init1); } ! return null; } *************** *** 2220,2226 **** "(Ljava/lang/String;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;[Lorg/python/core/PyObject;)Lorg/python/core/PyObject;"); } ! code.invokestatic(mrefs.makeClass_closure); } ! //Assign this new class to the given name set(node.getChild(0)); --- 2220,2226 ---- "(Ljava/lang/String;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;[Lorg/python/core/PyObject;)Lorg/python/core/PyObject;"); } ! code.invokestatic(mrefs.makeClass_closure); } ! //Assign this new class to the given name set(node.getChild(0)); *************** *** 2273,2277 **** code.invokevirtual(mrefs.getglobal); } ! public Object Name(SimpleNode node) throws Exception { String name; --- 2273,2277 ---- code.invokevirtual(mrefs.getglobal); } ! public Object Name(SimpleNode node) throws Exception { String name; *************** *** 2281,2291 **** name = getName(node); ! if (mode == AUGGET) mode = GET; ! else if (mode == AUGSET) mode = SET; SymInfo syminf = (SymInfo)tbl.get(name); ! switch (mode) { case GET: --- 2281,2291 ---- name = getName(node); ! if (mode == AUGGET) mode = GET; ! else if (mode == AUGSET) mode = SET; SymInfo syminf = (SymInfo)tbl.get(name); ! switch (mode) { case GET: *************** *** 2294,2298 **** int flags = syminf.flags; if (!my_scope.nested_scopes) flags &= ~ScopeInfo.FREE; ! if ((flags&ScopeInfo.GLOBAL) !=0 || optimizeGlobals&&(flags&(ScopeInfo.BOUND|ScopeInfo.CELL|ScopeInfo.FREE))==0) { emitGetGlobal(name); --- 2294,2298 ---- int flags = syminf.flags; if (!my_scope.nested_scopes) flags &= ~ScopeInfo.FREE; ! if ((flags&ScopeInfo.GLOBAL) !=0 || optimizeGlobals&&(flags&(ScopeInfo.BOUND|ScopeInfo.CELL|ScopeInfo.FREE))==0) { emitGetGlobal(name); Index: CompilationContext.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/CompilationContext.java,v retrieving revision 2.1 retrieving revision 2.2 diff -C2 -d -r2.1 -r2.2 *** CompilationContext.java 2001/05/15 18:53:34 2.1 --- CompilationContext.java 2001/11/27 13:51:37 2.2 *************** *** 1,3 **** ! package org.python.compiler; --- 1,3 ---- ! package org.python.compiler; *************** *** 5,13 **** public interface CompilationContext { ! ! public Future getFutures(); public void error(String msg,boolean err,SimpleNode node) throws Exception; ! public String getFilename(); ! } \ No newline at end of file --- 5,13 ---- public interface CompilationContext { ! ! public Future getFutures(); public void error(String msg,boolean err,SimpleNode node) throws Exception; ! public String getFilename(); ! } Index: ConstantPool.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ConstantPool.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -d -r2.4 -r2.5 *** ConstantPool.java 2001/10/28 17:13:42 2.4 --- ConstantPool.java 2001/11/27 13:51:37 2.5 *************** *** 79,83 **** sizes[index+1] = slots; index += slots; ! } //System.out.print("Constant: "); //for(int j=0; j<data.length; j++) --- 79,83 ---- sizes[index+1] = slots; index += slots; ! } //System.out.print("Constant: "); //for(int j=0; j<data.length; j++) *************** *** 90,94 **** tdata.writeByte(1); tdata.writeUTF(s); ! return addConstant(1); } --- 90,94 ---- tdata.writeByte(1); tdata.writeUTF(s); ! return addConstant(1); } *************** *** 97,101 **** tdata.writeByte(7); tdata.writeShort(c); ! return addConstant(1); } --- 97,101 ---- tdata.writeByte(7); tdata.writeShort(c); ! return addConstant(1); } *************** *** 171,175 **** sizes[index] = sigSize(type, true); //System.out.println("method: "+c+", "+name+", "+type+": "+index); ! return index; } --- 171,175 ---- sizes[index] = sigSize(type, true); //System.out.println("method: "+c+", "+name+", "+type+": "+index); ! return index; } *************** *** 185,196 **** int index = addConstant(1); sizes[index] = sigSize(type, true); ! return index; } public int String(String s) throws IOException { ! int i = UTF8(s); tdata.writeByte(8); tdata.writeShort(i); ! return addConstant(1); } --- 185,196 ---- int index = addConstant(1); sizes[index] = sigSize(type, true); ! return index; } public int String(String s) throws IOException { ! int i = UTF8(s); tdata.writeByte(8); tdata.writeShort(i); ! return addConstant(1); } *************** *** 198,202 **** tdata.writeByte(3); tdata.writeInt(i); ! return addConstant(1); } --- 198,202 ---- tdata.writeByte(3); tdata.writeInt(i); ! return addConstant(1); } *************** *** 204,208 **** tdata.writeByte(4); tdata.writeFloat(f); ! return addConstant(1); } --- 204,208 ---- tdata.writeByte(4); tdata.writeFloat(f); ! return addConstant(1); } *************** *** 210,214 **** tdata.writeByte(5); tdata.writeLong(l); ! return addConstant(2); } --- 210,214 ---- tdata.writeByte(5); tdata.writeLong(l); ! return addConstant(2); } *************** *** 216,220 **** tdata.writeByte(6); tdata.writeDouble(d); ! return addConstant(2); } --- 216,220 ---- tdata.writeByte(6); tdata.writeDouble(d); ! return addConstant(2); } *************** *** 226,230 **** tdata.writeShort(n); tdata.writeShort(t); ! return addConstant(1); } --- 226,230 ---- tdata.writeShort(n); tdata.writeShort(t); ! return addConstant(1); } Index: Future.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Future.java,v retrieving revision 2.3 retrieving revision 2.4 diff -C2 -d -r2.3 -r2.4 *** Future.java 2001/05/27 18:49:15 2.3 --- Future.java 2001/11/27 13:51:37 2.4 *************** *** 10,21 **** private static final String FUTURE = "__future__"; ! private boolean check(SimpleNode cand) throws Exception { SimpleNode dotted_name = cand.getChild(0); ! if (dotted_name.getNumChildren() != 1 || !((String)dotted_name.getChild(0).getInfo()).equals(FUTURE)) return false; int n = cand.getNumChildren(); if (n == 1) { ! throw new ParseException("future statement does not support import *",cand); } for (int i = 1; i < n; i++) { --- 10,21 ---- private static final String FUTURE = "__future__"; ! private boolean check(SimpleNode cand) throws Exception { SimpleNode dotted_name = cand.getChild(0); ! if (dotted_name.getNumChildren() != 1 || !((String)dotted_name.getChild(0).getInfo()).equals(FUTURE)) return false; int n = cand.getNumChildren(); if (n == 1) { ! throw new ParseException("future statement does not support import *",cand); } for (int i = 1; i < n; i++) { *************** *** 30,34 **** feature = (String)imp.getChild(0).getInfo(); break; ! } // *known* features if (feature.equals("nested_scopes")) { --- 30,34 ---- feature = (String)imp.getChild(0).getInfo(); break; ! } // *known* features if (feature.equals("nested_scopes")) { *************** *** 37,59 **** } throw new ParseException("future feature "+feature+" is not defined",cand); ! } return true; } ! public void preprocessFutures(SimpleNode node,org.python.core.CompilerFlags cflags) throws Exception { if (cflags != null) { nested_scopes = cflags.nested_scopes; } ! ! if ( node.id != PythonGrammarTreeConstants.JJTFILE_INPUT && node.id != PythonGrammarTreeConstants.JJTSINGLE_INPUT) return; int n = node.getNumChildren(); if (n == 0) return; ! int beg = 0; if (node.id == PythonGrammarTreeConstants.JJTFILE_INPUT && node.getChild(0).id == PythonGrammarTreeConstants.JJTEXPR_STMT && node.getChild(0).getChild(0).id == PythonGrammarTreeConstants.JJTSTRING) beg++; ! for (int i = beg; i < n; i++) { SimpleNode stmt = node.getChild(i); --- 37,59 ---- } throw new ParseException("future feature "+feature+" is not defined",cand); ! } return true; } ! public void preprocessFutures(SimpleNode node,org.python.core.CompilerFlags cflags) throws Exception { if (cflags != null) { nested_scopes = cflags.nested_scopes; } ! ! if ( node.id != PythonGrammarTreeConstants.JJTFILE_INPUT && node.id != PythonGrammarTreeConstants.JJTSINGLE_INPUT) return; int n = node.getNumChildren(); if (n == 0) return; ! int beg = 0; if (node.id == PythonGrammarTreeConstants.JJTFILE_INPUT && node.getChild(0).id == PythonGrammarTreeConstants.JJTEXPR_STMT && node.getChild(0).getChild(0).id == PythonGrammarTreeConstants.JJTSTRING) beg++; ! for (int i = beg; i < n; i++) { SimpleNode stmt = node.getChild(i); *************** *** 62,72 **** if (!check(stmt)) break; } ! if (cflags != null) { cflags.nested_scopes = cflags.nested_scopes || nested_scopes; } } - public static void checkFromFuture(SimpleNode node) throws Exception { if (node.from_future_checked) return; --- 62,72 ---- if (!check(stmt)) break; } ! if (cflags != null) { cflags.nested_scopes = cflags.nested_scopes || nested_scopes; } } + public static void checkFromFuture(SimpleNode node) throws Exception { if (node.from_future_checked) return; *************** *** 75,81 **** throw new ParseException("from __future__ imports must occur at the beginning of the file",node); } ! node.from_future_checked = true; } ! public boolean areNestedScopesOn() { return nested_scopes; --- 75,81 ---- throw new ParseException("from __future__ imports must occur at the beginning of the file",node); } ! node.from_future_checked = true; } ! public boolean areNestedScopesOn() { return nested_scopes; Index: JavaMaker.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/JavaMaker.java,v retrieving revision 2.13 retrieving revision 2.14 diff -C2 -d -r2.13 -r2.14 *** JavaMaker.java 2001/11/21 11:22:45 2.13 --- JavaMaker.java 2001/11/27 13:51:37 2.14 *************** *** 16,20 **** PyObject methods; public boolean frozen, main; ! public JavaMaker(Class superclass, Class[] interfaces, String pythonClass, String pythonModule, String myClass, --- 16,20 ---- PyObject methods; public boolean frozen, main; ! public JavaMaker(Class superclass, Class[] interfaces, String pythonClass, String pythonModule, String myClass, *************** *** 24,28 **** null, null, methods, false, false); } ! public JavaMaker(Class superclass, Class[] interfaces, String pythonClass, String pythonModule, String myClass, --- 24,28 ---- null, null, methods, false, false); } ! public JavaMaker(Class superclass, Class[] interfaces, String pythonClass, String pythonModule, String myClass, *************** *** 121,126 **** } else if (methods.__finditem__(method.getName().intern()) != null) { super.addMethod(method, access); ! } else if (Modifier.isProtected(method.getModifiers())) { ! addSuperMethod(method, access); } } --- 121,126 ---- } else if (methods.__finditem__(method.getName().intern()) != null) { super.addMethod(method, access); ! } else if (Modifier.isProtected(method.getModifiers())) { ! addSuperMethod(method, access); } } *************** *** 138,142 **** */ ! public void addMain() throws Exception { Code code = classfile.addMethod("main", "([Ljava/lang/String;)V", --- 138,142 ---- */ ! public void addMain() throws Exception { Code code = classfile.addMethod("main", "([Ljava/lang/String;)V", Index: Label.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Label.java,v retrieving revision 2.2 retrieving revision 2.3 diff -C2 -d -r2.2 -r2.3 *** Label.java 2001/10/28 17:13:42 2.2 --- Label.java 2001/11/27 13:51:37 2.3 *************** *** 12,16 **** Code code; int stack; ! public Label(Code code) { this.code = code; --- 12,16 ---- Code code; int stack; ! public Label(Code code) { this.code = code; *************** *** 64,68 **** return position; } ! public void setPosition() { position = code.size(); --- 64,68 ---- return position; } ! public void setPosition() { position = code.size(); Index: Module.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Module.java,v retrieving revision 2.8 retrieving revision 2.9 diff -C2 -d -r2.8 -r2.9 *** Module.java 2001/10/28 17:13:42 2.8 --- Module.java 2001/11/27 13:51:37 2.9 *************** *** 7,11 **** import org.python.parser.*; ! class PyIntegerConstant extends Constant { int value; --- 7,11 ---- import org.python.parser.*; ! class PyIntegerConstant extends Constant { int value; *************** *** 193,202 **** public boolean arglist, keywordlist; String fname; ! // for nested scopes public String[] cellvars; public String[] freevars; public int jy_npurecell; ! public int moreflags; --- 193,202 ---- public boolean arglist, keywordlist; String fname; ! // for nested scopes public String[] cellvars; public String[] freevars; public int jy_npurecell; ! public int moreflags; *************** *** 233,244 **** c.iconst(id); ! if (cellvars != null) CodeCompiler.makeStrings(c, cellvars, cellvars.length); else c.aconst_null(); if (freevars != null) CodeCompiler.makeStrings(c, freevars, freevars.length); else c.aconst_null(); c.iconst(jy_npurecell); ! c.iconst(moreflags); ! int mref_newCode = c.pool.Methodref( "org/python/core/Py", --- 233,244 ---- c.iconst(id); ! if (cellvars != null) CodeCompiler.makeStrings(c, cellvars, cellvars.length); else c.aconst_null(); if (freevars != null) CodeCompiler.makeStrings(c, freevars, freevars.length); else c.aconst_null(); c.iconst(jy_npurecell); ! c.iconst(moreflags); ! int mref_newCode = c.pool.Methodref( "org/python/core/Py", *************** *** 332,336 **** return PyCode(tree, name, ac, fast_locals, class_body, printResults, 0); }*/ ! Vector codes; private boolean isJavaIdentifier(String s) { --- 332,336 ---- return PyCode(tree, name, ac, fast_locals, class_body, printResults, 0); }*/ ! Vector codes; private boolean isJavaIdentifier(String s) { *************** *** 340,344 **** if (!Character.isJavaIdentifierStart(chars[0])) return false; ! for(int i=1; i<chars.length; i++) { if (!Character.isJavaIdentifierPart(chars[i])) --- 340,344 ---- if (!Character.isJavaIdentifierStart(chars[0])) return false; ! for(int i=1; i<chars.length; i++) { if (!Character.isJavaIdentifierPart(chars[i])) *************** *** 349,353 **** private static final String[] emptyStringAr = new String[0]; ! private String[] toNameAr(Vector names,boolean nullok) { int sz = names.size(); --- 349,353 ---- private static final String[] emptyStringAr = new String[0]; ! private String[] toNameAr(Vector names,boolean nullok) { int sz = names.size(); *************** *** 357,362 **** return nameArray; } ! ! private int to_cell; --- 357,362 ---- return nameArray; } ! ! private int to_cell; *************** *** 370,377 **** } ! public PyCodeConstant PyCode(SimpleNode tree, String name, boolean fast_locals, String className, ! boolean classBody, boolean printResults, int firstlineno, ScopeInfo scope,org.python.core.CompilerFlags cflags) throws Exception --- 370,377 ---- } ! public PyCodeConstant PyCode(SimpleNode tree, String name, boolean fast_locals, String className, ! boolean classBody, boolean printResults, int firstlineno, ScopeInfo scope,org.python.core.CompilerFlags cflags) throws Exception *************** *** 379,383 **** PyCodeConstant code = new PyCodeConstant(); ArgListCompiler ac = (scope != null)?scope.ac:null; ! if (ac != null) { code.arglist = ac.arglist; --- 379,383 ---- PyCodeConstant code = new PyCodeConstant(); ArgListCompiler ac = (scope != null)?scope.ac:null; ! if (ac != null) { code.arglist = ac.arglist; *************** *** 385,389 **** code.argcount = ac.names.size(); } ! code.co_name = name; code.co_firstlineno = firstlineno; --- 385,389 ---- code.argcount = ac.names.size(); } ! code.co_name = name; code.co_firstlineno = firstlineno; *************** *** 410,414 **** tree = ac.init_code; } ! if (scope != null) { int nparamcell = scope.jy_paramcells.size(); --- 410,414 ---- tree = ac.init_code; } ! if (scope != null) { int nparamcell = scope.jy_paramcells.size(); *************** *** 433,437 **** // !classdef only if (!classBody) code.names = toNameAr(compiler.names,false); ! if (scope != null) { code.cellvars = toNameAr(scope.cellvars,true); --- 433,437 ---- // !classdef only if (!classBody) code.names = toNameAr(compiler.names,false); ! if (scope != null) { code.cellvars = toNameAr(scope.cellvars,true); *************** *** 446,450 **** code.moreflags |= org.python.core.PyTableCode.CO_NESTED; } ! code.module = this; code.name = code.fname; --- 446,450 ---- code.moreflags |= org.python.core.PyTableCode.CO_NESTED; } ! code.module = this; code.name = code.fname; Index: ProxyMaker.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ProxyMaker.java,v retrieving revision 2.14 retrieving revision 2.15 diff -C2 -d -r2.14 -r2.15 *** ProxyMaker.java 2001/10/28 17:13:42 2.14 --- ProxyMaker.java 2001/11/27 13:51:37 2.15 *************** *** 55,59 **** public boolean isAdapter=false; ! // Ctor used by makeProxy and AdapterMaker. public ProxyMaker(String classname, Class superclass) { this.myClass = "org.python.proxies."+classname; --- 55,59 ---- public boolean isAdapter=false; ! // Ctor used by makeProxy and AdapterMaker. public ProxyMaker(String classname, Class superclass) { this.myClass = "org.python.proxies."+classname; *************** *** 236,240 **** } ! public void doJavaCall(Code code, String name, String type, String jcallName) throws Exception --- 236,240 ---- } ! public void doJavaCall(Code code, String name, String type, String jcallName) throws Exception *************** *** 243,251 **** "org/python/core/PyObject", jcallName, "([Ljava/lang/Object;)Lorg/python/core/PyObject;"); ! int py2j = code.pool.Methodref( "org/python/core/Py", "py2"+name, "(Lorg/python/core/PyObject;)"+type); ! code.invokevirtual(jcall); code.invokestatic(py2j); --- 243,251 ---- "org/python/core/PyObject", jcallName, "([Ljava/lang/Object;)Lorg/python/core/PyObject;"); ! int py2j = code.pool.Methodref( "org/python/core/Py", "py2"+name, "(Lorg/python/core/PyObject;)"+type); ! code.invokevirtual(jcall); code.invokestatic(py2j); *************** *** 387,392 **** Label forname_exch_start = code.getLabel(); Label forname_exch_end = code.getLabel(); ! forname_start.setPosition(); ! */ int forname = code.pool.Methodref( "java/lang/Class","forName", --- 387,392 ---- Label forname_exch_start = code.getLabel(); Label forname_exch_end = code.getLabel(); ! forname_start.setPosition(); ! */ int forname = code.pool.Methodref( "java/lang/Class","forName", *************** *** 403,409 **** code.dup(); forname_exch_end.setPosition(); ! code.addExceptionHandler(forname_start,forname_end,forname_exch_start,code.pool.Class("java/lang/ClassNotFoundException")); ! */ int tojava = code.pool.Methodref( "org/python/core/Py", "tojava", --- 403,409 ---- code.dup(); forname_exch_end.setPosition(); ! code.addExceptionHandler(forname_start,forname_end,forname_exch_start,code.pool.Class("java/lang/ClassNotFoundException")); ! */ int tojava = code.pool.Methodref( "org/python/core/Py", "tojava", *************** *** 451,460 **** code.aload(instLocal); code.aload(excLocal); ! int jthrow = code.pool.Methodref( "org/python/core/PyObject", "_jthrow", "(Ljava/lang/Throwable;)V"); code.invokevirtual(jthrow); ! code.addExceptionHandler(start, end, handlerStart, code.pool.Class("java/lang/Throwable")); --- 451,460 ---- code.aload(instLocal); code.aload(excLocal); ! int jthrow = code.pool.Methodref( "org/python/core/PyObject", "_jthrow", "(Ljava/lang/Throwable;)V"); code.invokevirtual(jthrow); ! code.addExceptionHandler(start, end, handlerStart, code.pool.Class("java/lang/Throwable")); *************** *** 466,474 **** } ! public void addMethod(Method method, int access) throws Exception { boolean isAbstract = false; ! if (Modifier.isAbstract(access)) { access = access & ~Modifier.ABSTRACT; isAbstract = true; --- 466,474 ---- } ! public void addMethod(Method method, int access) throws Exception { boolean isAbstract = false; ! if (Modifier.isAbstract(access)) { access = access & ~Modifier.ABSTRACT; isAbstract = true; *************** *** 514,518 **** callPython.setPosition(); code.aload(tmp); ! callMethod(code, name, parameters, ret, method.getExceptionTypes()); --- 514,518 ---- callPython.setPosition(); code.aload(tmp); ! callMethod(code, name, parameters, ret, method.getExceptionTypes()); *************** *** 572,585 **** continue; } ! if (Modifier.isNative(access)) { access = access & ~Modifier.NATIVE; } ! if (Modifier.isProtected(access)) { access = (access & ~Modifier.PROTECTED) | Modifier.PUBLIC; if (Modifier.isFinal(access)) { addSuperMethod(methods[i], access); ! continue; } } --- 572,585 ---- continue; } ! if (Modifier.isNative(access)) { access = access & ~Modifier.NATIVE; } ! if (Modifier.isProtected(access)) { access = (access & ~Modifier.PROTECTED) | Modifier.PUBLIC; if (Modifier.isFinal(access)) { addSuperMethod(methods[i], access); ! continue; } } *************** *** 644,654 **** String sig = makeSignature(parameters, ret); String superclass = mapClass(method.getDeclaringClass()); ! String superName = method.getName(); String methodName = superName; if (Modifier.isFinal(access)) { ! methodName = "super__"+superName; access &= ~Modifier.FINAL; ! } ! addSuperMethod(methodName, superName, superclass, parameters, ret, sig, access); } --- 644,654 ---- String sig = makeSignature(parameters, ret); String superclass = mapClass(method.getDeclaringClass()); ! String superName = method.getName(); String methodName = superName; if (Modifier.isFinal(access)) { ! methodName = "super__"+superName; access &= ~Modifier.FINAL; ! } ! addSuperMethod(methodName, superName, superclass, parameters, ret, sig, access); } *************** *** 702,706 **** code.getfield(field); code.areturn(); ! // implement PyProxy interface classfile.addField("__systemState", --- 702,706 ---- code.getfield(field); code.areturn(); ! // implement PyProxy interface classfile.addField("__systemState", Index: ScopeConstants.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopeConstants.java,v retrieving revision 2.2 retrieving revision 2.3 diff -C2 -d -r2.2 -r2.3 *** ScopeConstants.java 2001/03/11 16:29:31 2.2 --- ScopeConstants.java 2001/11/27 13:51:37 2.3 *************** *** 2,6 **** public interface ScopeConstants { ! public final static int BOUND = 1; public final static int NGLOBAL = 2; // func scope expl global --- 2,6 ---- public interface ScopeConstants { ! public final static int BOUND = 1; public final static int NGLOBAL = 2; // func scope expl global *************** *** 11,15 **** public final static int CLASS_GLOBAL = 64; // class scope expl global public final static int GLOBAL = NGLOBAL|CLASS_GLOBAL; // all global ! public final static int TOPSCOPE = 0; public final static int FUNCSCOPE = 1; --- 11,15 ---- public final static int CLASS_GLOBAL = 64; // class scope expl global public final static int GLOBAL = NGLOBAL|CLASS_GLOBAL; // all global ! public final static int TOPSCOPE = 0; public final static int FUNCSCOPE = 1; Index: ScopeInfo.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopeInfo.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -d -r2.4 -r2.5 *** ScopeInfo.java 2001/05/27 18:49:15 2.4 --- ScopeInfo.java 2001/11/27 13:51:37 2.5 *************** *** 23,27 **** System.err.print(name); if ((flags&BOUND) != 0) System.err.print('='); ! if ((flags&NGLOBAL) != 0) System.err.print('G'); else // func scope global (affect nested scopes) if ((flags&CLASS_GLOBAL) != 0) System.err.print('g'); // vs. class scope global if ((flags&PARAM) != 0) System.err.print('P'); else --- 23,27 ---- System.err.print(name); if ((flags&BOUND) != 0) System.err.print('='); ! if ((flags&NGLOBAL) != 0) System.err.print('G'); else // func scope global (affect nested scopes) if ((flags&CLASS_GLOBAL) != 0) System.err.print('g'); // vs. class scope global if ((flags&PARAM) != 0) System.err.print('P'); else *************** *** 31,37 **** System.err.print(" "); } ! System.err.println(); } ! public ScopeInfo(String name,SimpleNode node,int level,int kind,int func_level,ArgListCompiler ac,boolean nested_scopes) { scope_name = name; --- 31,37 ---- System.err.print(" "); } ! System.err.println(); } ! public ScopeInfo(String name,SimpleNode node,int level,int kind,int func_level,ArgListCompiler ac,boolean nested_scopes) { scope_name = name; *************** *** 43,59 **** this.nested_scopes = nested_scopes; } ! public int kind; public boolean nested_scopes; ! public boolean unqual_exec; public boolean exec; public boolean from_import_star; ! public ArgListCompiler ac; ! public Hashtable tbl = new Hashtable(); public Vector names = new Vector(); ! public int addGlobal(String name) { int global = kind==CLASSSCOPE?CLASS_GLOBAL:NGLOBAL; // global kind = func vs. class --- 43,59 ---- this.nested_scopes = nested_scopes; } ! public int kind; public boolean nested_scopes; ! public boolean unqual_exec; public boolean exec; public boolean from_import_star; ! public ArgListCompiler ac; ! public Hashtable tbl = new Hashtable(); public Vector names = new Vector(); ! public int addGlobal(String name) { int global = kind==CLASSSCOPE?CLASS_GLOBAL:NGLOBAL; // global kind = func vs. class *************** *** 67,78 **** return prev; } ! public int local = 0; ! public void addParam(String name) { tbl.put(name, new SymInfo(PARAM|BOUND,local++)); names.addElement(name); } ! public void markFromParam() { for (Enumeration e=tbl.elements(); e.hasMoreElements(); ) { --- 67,78 ---- return prev; } ! public int local = 0; ! public void addParam(String name) { tbl.put(name, new SymInfo(PARAM|BOUND,local++)); names.addElement(name); } ! public void markFromParam() { for (Enumeration e=tbl.elements(); e.hasMoreElements(); ) { *************** *** 81,85 **** } } ! public void addBound(String name) { SymInfo info = (SymInfo)tbl.get(name); --- 81,85 ---- } } ! public void addBound(String name) { SymInfo info = (SymInfo)tbl.get(name); *************** *** 90,94 **** info.flags |= BOUND; } ! public void addUsed(String name) { if (tbl.get(name) == null) { --- 90,94 ---- info.flags |= BOUND; } ! public void addUsed(String name) { if (tbl.get(name) == null) { *************** *** 99,116 **** private final static Object PRESENT = new Object(); ! public Hashtable inner_free = new Hashtable(); ! public Vector cellvars = new Vector(); ! public Vector jy_paramcells = new Vector(); ! public int jy_npurecell; ! public int cell; ! public void cook(ScopeInfo up,CompilationContext ctxt) throws Exception { if (up == null) return; // top level => nop ! boolean nested_scopes = this.nested_scopes; boolean func = kind == FUNCSCOPE; --- 99,116 ---- private final static Object PRESENT = new Object(); ! public Hashtable inner_free = new Hashtable(); ! public Vector cellvars = new Vector(); ! public Vector jy_paramcells = new Vector(); ! public int jy_npurecell; ! public int cell; ! public void cook(ScopeInfo up,CompilationContext ctxt) throws Exception { if (up == null) return; // top level => nop ! boolean nested_scopes = this.nested_scopes; boolean func = kind == FUNCSCOPE; *************** *** 118,122 **** cell = 0; boolean some_inner_free = inner_free.size() > 0; ! for (Enumeration e = inner_free.keys(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); --- 118,122 ---- cell = 0; boolean some_inner_free = inner_free.size() > 0; ! for (Enumeration e = inner_free.keys(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); *************** *** 131,135 **** if (nested_scopes) { info.flags |= CELL; ! if ((info.flags&PARAM) != 0) jy_paramcells.addElement(name); cellvars.addElement(name); info.env_index = cell++; --- 131,135 ---- if (nested_scopes) { info.flags |= CELL; ! if ((info.flags&PARAM) != 0) jy_paramcells.addElement(name); cellvars.addElement(name); info.env_index = cell++; *************** *** 144,148 **** } boolean some_free = false; ! boolean nested = up.kind != TOPSCOPE; for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { --- 144,148 ---- } boolean some_free = false; ! boolean nested = up.kind != TOPSCOPE; for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { *************** *** 173,177 **** else if(func_level > 1 && some_free) dynastuff_trouble(false, ctxt); } ! } --- 173,177 ---- else if(func_level > 1 && some_free) dynastuff_trouble(false, ctxt); } ! } *************** *** 190,194 **** ctxt.error(illegal + why ,nested_scopes,scope_node); } ! public Vector freevars = new Vector(); --- 190,194 ---- ctxt.error(illegal + why ,nested_scopes,scope_node); } ! public Vector freevars = new Vector(); *************** *** 214,224 **** info.flags = NGLOBAL|BOUND; continue; ! } } info.flags &= ~FREE; } } ! } ! } --- 214,224 ---- info.flags = NGLOBAL|BOUND; continue; ! } } info.flags &= ~FREE; } } ! } ! } Index: SymInfo.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/SymInfo.java,v retrieving revision 2.1 retrieving revision 2.2 diff -C2 -d -r2.1 -r2.2 *** SymInfo.java 2001/03/08 23:43:51 2.1 --- SymInfo.java 2001/11/27 13:51:37 2.2 *************** *** 1,3 **** ! package org.python.compiler; --- 1,3 ---- ! package org.python.compiler; *************** *** 7,19 **** this.flags = flags; } ! public SymInfo(int flags,int locals_index) { this.flags = flags; this.locals_index = locals_index; } ! public int flags; public int locals_index; public int env_index; ! } --- 7,19 ---- this.flags = flags; } ! public SymInfo(int flags,int locals_index) { this.flags = flags; this.locals_index = locals_index; } ! public int flags; public int locals_index; public int env_index; ! } |