From: Finn B. <bc...@us...> - 2001-11-27 19:07:24
|
Update of /cvsroot/jython/jython/org/python/compiler In directory usw-pr-cvs1:/tmp/cvs-serv31804/compiler Modified Files: ArgListCompiler.java Code.java CodeCompiler.java CompilationContext.java Future.java JavaMaker.java Label.java Module.java ProxyMaker.java ScopeInfo.java ScopesCompiler.java Log Message: Long line normalization. Index: ArgListCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ArgListCompiler.java,v retrieving revision 2.7 retrieving revision 2.8 diff -C2 -d -r2.7 -r2.8 *** ArgListCompiler.java 2001/11/27 13:51:37 2.7 --- ArgListCompiler.java 2001/11/27 19:07:21 2.8 *************** *** 9,12 **** --- 9,13 ---- public class ArgListCompiler extends org.python.parser.Visitor + implements PythonGrammarTreeConstants { public boolean arglist, keywordlist; *************** *** 19,23 **** defaults = new Vector(); names = new Vector(); ! init_code = new SimpleNode(PythonGrammarTreeConstants.JJTSUITE); } --- 20,24 ---- defaults = new Vector(); names = new Vector(); ! init_code = new SimpleNode(JJTSUITE); } *************** *** 69,79 **** //Handle tuple arguments properly ! if (node.getChild(0).id == PythonGrammarTreeConstants.JJTFPLIST) { ! SimpleNode expr = new SimpleNode( ! PythonGrammarTreeConstants.JJTEXPR_STMT); // Set the right line number for this expr expr.beginLine = node.beginLine; expr.jjtAddChild(node.getChild(0), 0); ! SimpleNode nm = new SimpleNode(PythonGrammarTreeConstants.JJTNAME); nm.setInfo(name); expr.jjtAddChild(nm, 1); --- 70,79 ---- //Handle tuple arguments properly ! if (node.getChild(0).id == JJTFPLIST) { ! SimpleNode expr = new SimpleNode(JJTEXPR_STMT); // Set the right line number for this expr expr.beginLine = node.beginLine; expr.jjtAddChild(node.getChild(0), 0); ! SimpleNode nm = new SimpleNode(JJTNAME); nm.setInfo(name); expr.jjtAddChild(nm, 1); Index: Code.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Code.java,v retrieving revision 2.5 retrieving revision 2.6 diff -C2 -d -r2.5 -r2.6 *** Code.java 2001/11/27 13:51:37 2.5 --- Code.java 2001/11/27 19:07:21 2.6 *************** *** 149,153 **** } if (linenumbers != null) ! ClassFile.writeAttributes(stream, new Attribute[] { linenumbers }); else ClassFile.writeAttributes(stream, new Attribute[0]); --- 149,154 ---- } if (linenumbers != null) ! ClassFile.writeAttributes(stream, ! new Attribute[] { linenumbers }); else ClassFile.writeAttributes(stream, new Attribute[0]); *************** *** 284,288 **** } ! public void getfield(String c, String name, String type) throws IOException { getfield(pool.Fieldref(c, name, type)); } --- 285,291 ---- } ! public void getfield(String c, String name, String type) ! throws IOException ! { getfield(pool.Fieldref(c, name, type)); } *************** *** 294,298 **** } ! public void getstatic(String c, String name, String type) throws IOException { getstatic(pool.Fieldref(c, name, type)); } --- 297,303 ---- } ! public void getstatic(String c, String name, String type) ! throws IOException ! { getstatic(pool.Fieldref(c, name, type)); } Index: CodeCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/CodeCompiler.java,v retrieving revision 2.22 retrieving revision 2.23 diff -C2 -d -r2.22 -r2.23 *** CodeCompiler.java 2001/11/27 13:51:37 2.22 --- CodeCompiler.java 2001/11/27 19:07:21 2.23 *************** *** 13,18 **** import java.util.Vector; ! public class CodeCompiler extends Visitor implements CompilationContext { public static final Object Exit=new Integer(1); public static final Object NoExit=null; --- 13,20 ---- import java.util.Vector; ! public class CodeCompiler extends Visitor [...1446 lines suppressed...] --- 2411,2415 ---- mrefs.dellocal1 = code.pool.Methodref( "org/python/core/PyFrame", "dellocal", ! "(" + $str + ")V"); } code.invokevirtual(mrefs.dellocal1); *************** *** 2412,2416 **** } if ((syminf.flags&ScopeInfo.CELL) != 0) { ! error("can not delete variable '"+name+"' referenced in nested scope",true,node); } code.iconst(syminf.locals_index); --- 2419,2424 ---- } if ((syminf.flags&ScopeInfo.CELL) != 0) { ! error("can not delete variable '"+name+ ! "' referenced in nested scope",true,node); } code.iconst(syminf.locals_index); Index: CompilationContext.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/CompilationContext.java,v retrieving revision 2.2 retrieving revision 2.3 diff -C2 -d -r2.2 -r2.3 *** CompilationContext.java 2001/11/27 13:51:37 2.2 --- CompilationContext.java 2001/11/27 19:07:21 2.3 *************** *** 7,11 **** public Future getFutures(); ! public void error(String msg,boolean err,SimpleNode node) throws Exception; public String getFilename(); --- 7,12 ---- public Future getFutures(); ! public void error(String msg,boolean err,SimpleNode node) ! throws Exception; public String getFilename(); Index: Future.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Future.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -d -r2.4 -r2.5 *** Future.java 2001/11/27 13:51:37 2.4 --- Future.java 2001/11/27 19:07:21 2.5 *************** *** 5,9 **** import org.python.parser.*; ! public class Future extends Object { private boolean nested_scopes; --- 5,9 ---- import org.python.parser.*; ! public class Future extends Object implements PythonGrammarTreeConstants { private boolean nested_scopes; *************** *** 14,21 **** 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++) { --- 14,23 ---- 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++) { *************** *** 24,31 **** switch(imp.id) { default: ! case PythonGrammarTreeConstants.JJTNAME: feature = (String)imp.getInfo(); break; ! case PythonGrammarTreeConstants.JJTIMPORT_AS_NAME: feature = (String)imp.getChild(0).getInfo(); break; --- 26,33 ---- switch(imp.id) { default: ! case JJTNAME: feature = (String)imp.getInfo(); break; ! case JJTIMPORT_AS_NAME: feature = (String)imp.getChild(0).getInfo(); break; *************** *** 36,62 **** continue; } ! 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); ! if (stmt.id != PythonGrammarTreeConstants.JJTIMPORTFROM) break; stmt.from_future_checked = true; if (!check(stmt)) break; --- 38,68 ---- continue; } ! 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 != JJTFILE_INPUT && node.id != JJTSINGLE_INPUT) ! return; int n = node.getNumChildren(); if (n == 0) return; int beg = 0; ! if (node.id == JJTFILE_INPUT && ! node.getChild(0).id == JJTEXPR_STMT && ! node.getChild(0).getChild(0).id == JJTSTRING) beg++; for (int i = beg; i < n; i++) { SimpleNode stmt = node.getChild(i); ! if (stmt.id != JJTIMPORTFROM) break; stmt.from_future_checked = true; if (!check(stmt)) break; *************** *** 72,77 **** if (node.from_future_checked) return; SimpleNode dotted_name = node.getChild(0); ! if (dotted_name.getNumChildren() == 1 && ((String)dotted_name.getChild(0).getInfo()).equals(FUTURE)) { ! throw new ParseException("from __future__ imports must occur at the beginning of the file",node); } node.from_future_checked = true; --- 78,85 ---- if (node.from_future_checked) return; SimpleNode dotted_name = node.getChild(0); ! if (dotted_name.getNumChildren() == 1 && ! ((String)dotted_name.getChild(0).getInfo()).equals(FUTURE)) { ! throw new ParseException("from __future__ imports must occur " + ! "at the beginning of the file",node); } node.from_future_checked = true; Index: JavaMaker.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/JavaMaker.java,v retrieving revision 2.14 retrieving revision 2.15 diff -C2 -d -r2.14 -r2.15 *** JavaMaker.java 2001/11/27 13:51:37 2.14 --- JavaMaker.java 2001/11/27 19:07:21 2.15 *************** *** 8,12 **** import org.python.core.PyProxy; ! public class JavaMaker extends ProxyMaker { public String pythonClass, pythonModule; --- 8,12 ---- import org.python.core.PyProxy; ! public class JavaMaker extends ProxyMaker implements ClassConstants { public String pythonClass, pythonModule; *************** *** 84,88 **** // _initProxy method ! Code code = classfile.addMethod("__initProxy__", "([Ljava/lang/Object;)V", Modifier.PUBLIC); code.aload(0); --- 84,89 ---- // _initProxy method ! Code code = classfile.addMethod("__initProxy__", ! "([Ljava/lang/Object;)V", Modifier.PUBLIC); code.aload(0); *************** *** 99,103 **** int initProxy = code.pool.Methodref( "org/python/core/Py", "initProxy", ! "(Lorg/python/core/PyProxy;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/String;Z)V"); code.invokestatic(initProxy); code.return_(); --- 100,105 ---- int initProxy = code.pool.Methodref( "org/python/core/Py", "initProxy", ! "(" + $pyProxy + $str + $str + $objArr + ! $strArr + $strArr + "Z)V"); code.invokestatic(initProxy); code.return_(); *************** *** 114,118 **** public void addMethod(Method method, int access) throws Exception { ! // System.out.println("add: "+method.getName()+", "+methods.containsKey(method.getName())); // Check to see if it's an abstract method if (Modifier.isAbstract(access)) { --- 116,121 ---- public void addMethod(Method method, int access) throws Exception { ! //System.out.println("add: "+method.getName()+", "+ ! // methods.containsKey(method.getName())); // Check to see if it's an abstract method if (Modifier.isAbstract(access)) { *************** *** 133,137 **** { if (!PyProxy.class.isAssignableFrom(this.superclass)) { ! super.addSuperMethod(methodName,superName,superclass,parameters,ret,sig,access); } } --- 136,141 ---- { if (!PyProxy.class.isAssignableFrom(this.superclass)) { ! super.addSuperMethod(methodName,superName,superclass,parameters, ! ret,sig,access); } } *************** *** 140,150 **** public void addMain() throws Exception { ! Code code = classfile.addMethod("main", "([Ljava/lang/String;)V", ClassFile.PUBLIC | ClassFile.STATIC); // Load the class of the Python module to run int forname = code.pool.Methodref( ! "java/lang/Class","forName", ! "(Ljava/lang/String;)Ljava/lang/Class;"); code.ldc(pythonModule); code.invokestatic(forname); --- 144,153 ---- public void addMain() throws Exception { ! Code code = classfile.addMethod("main", "(" + $str + ")V", ClassFile.PUBLIC | ClassFile.STATIC); // Load the class of the Python module to run int forname = code.pool.Methodref( ! "java/lang/Class","forName", "(" + $str + ")" + $clss); code.ldc(pythonModule); code.invokestatic(forname); *************** *** 158,162 **** int runMain = code.pool.Methodref( "org/python/core/Py", "runMain", ! "(Ljava/lang/Class;[Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;Z)V"); code.invokestatic(runMain); code.return_(); --- 161,165 ---- int runMain = code.pool.Methodref( "org/python/core/Py", "runMain", ! "(" + $clss + $strArr + $strArr + $strArr + "Z)V"); code.invokestatic(runMain); code.return_(); Index: Label.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Label.java,v retrieving revision 2.3 retrieving revision 2.4 diff -C2 -d -r2.3 -r2.4 *** Label.java 2001/11/27 13:51:37 2.3 --- Label.java 2001/11/27 19:07:21 2.4 *************** *** 31,35 **** for (int i=0; i<noffsets; i++) { ! //System.out.println("o: "+offsets[i]+", "+position+", "+positions[i]); int off = position-offsets[i]; int p = positions[i]; --- 31,36 ---- for (int i=0; i<noffsets; i++) { ! //System.out.println("o: "+offsets[i]+", "+position+", "+ ! // positions[i]); int off = position-offsets[i]; int p = positions[i]; Index: Module.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Module.java,v retrieving revision 2.9 retrieving revision 2.10 diff -C2 -d -r2.9 -r2.10 *** Module.java 2001/11/27 13:51:37 2.9 --- Module.java 2001/11/27 19:07:21 2.10 *************** *** 7,11 **** import org.python.parser.*; ! class PyIntegerConstant extends Constant { int value; --- 7,11 ---- import org.python.parser.*; ! class PyIntegerConstant extends Constant implements ClassConstants { int value; *************** *** 16,33 **** public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, ! "Lorg/python/core/PyInteger;"); } public void put(Code c) throws IOException { ! module.classfile.addField(name, "Lorg/python/core/PyInteger;", access); c.iconst(value); int mref_newInteger = c.pool.Methodref( "org/python/core/Py", "newInteger", ! "(I)Lorg/python/core/PyInteger;"); c.invokestatic(mref_newInteger); ! c.putstatic(module.classfile.name, name, ! "Lorg/python/core/PyInteger;"); } --- 16,31 ---- public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, $pyInteger); } public void put(Code c) throws IOException { ! module.classfile.addField(name, $pyInteger, access); c.iconst(value); int mref_newInteger = c.pool.Methodref( "org/python/core/Py", "newInteger", ! "(I)" + $pyInteger); c.invokestatic(mref_newInteger); ! c.putstatic(module.classfile.name, name, $pyInteger); } *************** *** 44,48 **** } ! class PyFloatConstant extends Constant { double value; --- 42,46 ---- } ! class PyFloatConstant extends Constant implements ClassConstants { double value; *************** *** 53,67 **** public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, "Lorg/python/core/PyFloat;"); } public void put(Code c) throws IOException { ! module.classfile.addField(name, "Lorg/python/core/PyFloat;", access); c.ldc(c.pool.Double(value)); int mref_newFloat = c.pool.Methodref("org/python/core/Py", "newFloat", ! "(D)Lorg/python/core/PyFloat;"); c.invokestatic(mref_newFloat); ! c.putstatic(module.classfile.name, name, "Lorg/python/core/PyFloat;"); } --- 51,65 ---- public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, $pyFloat); } public void put(Code c) throws IOException { ! module.classfile.addField(name, $pyFloat, access); c.ldc(c.pool.Double(value)); int mref_newFloat = c.pool.Methodref("org/python/core/Py", "newFloat", ! "(D)" + $pyFloat); c.invokestatic(mref_newFloat); ! c.putstatic(module.classfile.name, name, $pyFloat); } *************** *** 78,82 **** } ! class PyComplexConstant extends Constant { double value; --- 76,80 ---- } ! class PyComplexConstant extends Constant implements ClassConstants { double value; *************** *** 87,104 **** public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, ! "Lorg/python/core/PyComplex;"); } public void put(Code c) throws IOException { ! module.classfile.addField(name, "Lorg/python/core/PyComplex;", access); c.ldc(c.pool.Double(value)); int mref_newImaginary = c.pool.Methodref( "org/python/core/Py", "newImaginary", ! "(D)Lorg/python/core/PyComplex;"); c.invokestatic(mref_newImaginary); ! c.putstatic(module.classfile.name, name, ! "Lorg/python/core/PyComplex;"); } --- 85,100 ---- public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, $pyComplex); } public void put(Code c) throws IOException { ! module.classfile.addField(name, $pyComplex, access); c.ldc(c.pool.Double(value)); int mref_newImaginary = c.pool.Methodref( "org/python/core/Py", "newImaginary", ! "(D)" + $pyComplex); c.invokestatic(mref_newImaginary); ! c.putstatic(module.classfile.name, name, $pyComplex); } *************** *** 115,119 **** } ! class PyStringConstant extends Constant { String value; --- 111,115 ---- } ! class PyStringConstant extends Constant implements ClassConstants { String value; *************** *** 124,139 **** public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, "Lorg/python/core/PyString;"); } public void put(Code c) throws IOException { ! module.classfile.addField(name, "Lorg/python/core/PyString;", access); c.ldc(value); int mref_newString = c.pool.Methodref( "org/python/core/Py", "newString", ! "(Ljava/lang/String;)Lorg/python/core/PyString;"); c.invokestatic(mref_newString); ! c.putstatic(module.classfile.name, name, "Lorg/python/core/PyString;"); } --- 120,135 ---- public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, $pyStr); } public void put(Code c) throws IOException { ! module.classfile.addField(name, $pyStr, access); c.ldc(value); int mref_newString = c.pool.Methodref( "org/python/core/Py", "newString", ! "(" + $str + ")" + $pyStr); c.invokestatic(mref_newString); ! c.putstatic(module.classfile.name, name, $pyStr); } *************** *** 150,154 **** } ! class PyLongConstant extends Constant { String value; --- 146,150 ---- } ! class PyLongConstant extends Constant implements ClassConstants { String value; *************** *** 159,174 **** public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, "Lorg/python/core/PyLong;"); } public void put(Code c) throws IOException { ! module.classfile.addField(name, "Lorg/python/core/PyLong;", access); c.ldc(value); int mref_newLong = c.pool.Methodref( "org/python/core/Py", "newLong", ! "(Ljava/lang/String;)Lorg/python/core/PyLong;"); c.invokestatic(mref_newLong); ! c.putstatic(module.classfile.name, name, "Lorg/python/core/PyLong;"); } --- 155,170 ---- public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, $pyLong); } public void put(Code c) throws IOException { ! module.classfile.addField(name, $pyLong, access); c.ldc(value); int mref_newLong = c.pool.Methodref( "org/python/core/Py", "newLong", ! "(" + $str + ")" + $pyLong); c.invokestatic(mref_newLong); ! c.putstatic(module.classfile.name, name, $pyLong); } *************** *** 184,188 **** } ! class PyCodeConstant extends Constant { public String co_name; --- 180,184 ---- } ! class PyCodeConstant extends Constant implements ClassConstants { public String co_name; *************** *** 205,213 **** public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, "Lorg/python/core/PyCode;"); } public void put(Code c) throws IOException { ! module.classfile.addField(name, "Lorg/python/core/PyCode;", access); c.iconst(argcount); --- 201,209 ---- public void get(Code c) throws IOException { ! c.getstatic(module.classfile.name, name, $pyCode); } public void put(Code c) throws IOException { ! module.classfile.addField(name, $pyCode, access); c.iconst(argcount); *************** *** 234,239 **** 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); --- 230,241 ---- 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); *************** *** 244,256 **** "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); //c.aconst_null(); ! c.putstatic(module.classfile.name, name, "Lorg/python/core/PyCode;"); } } ! public class Module { ClassFile classfile; --- 246,259 ---- "org/python/core/Py", "newCode", ! "(I" + $strArr + $str + $str + "IZZ" + $pyFuncTbl + "I" + ! $strArr + $strArr + "II)" + $pyCode); c.invokestatic(mref_newCode); //c.aconst_null(); ! c.putstatic(module.classfile.name, name, $pyCode); } } ! public class Module implements ClassConstants { ClassFile classfile; *************** *** 323,327 **** int firstlineno) throws Exception { ! return PyCode(tree, name, ac, fast_locals, class_body, false, firstlineno); } public PyCodeConstant PyCode(SimpleNode tree, String name, --- 326,331 ---- int firstlineno) throws Exception { ! return PyCode(tree, name, ac, fast_locals, class_body, false, ! firstlineno); } public PyCodeConstant PyCode(SimpleNode tree, String name, *************** *** 367,371 **** throws Exception { ! return PyCode(tree,name,fast_locals,className,classBody,printResults,firstlineno,scope,null); } --- 371,376 ---- throws Exception { ! return PyCode(tree,name,fast_locals,className,classBody, ! printResults,firstlineno,scope,null); } *************** *** 374,378 **** boolean fast_locals, String className, boolean classBody, boolean printResults, ! int firstlineno, ScopeInfo scope,org.python.core.CompilerFlags cflags) throws Exception { --- 379,384 ---- boolean fast_locals, String className, boolean classBody, boolean printResults, ! int firstlineno, ScopeInfo scope, ! org.python.core.CompilerFlags cflags) throws Exception { *************** *** 400,404 **** Code c = classfile.addMethod( code.fname, ! "(Lorg/python/core/PyFrame;)Lorg/python/core/PyObject;", ClassFile.PUBLIC); --- 406,410 ---- Code c = classfile.addMethod( code.fname, ! "(" + $pyFrame + ")" + $pyObj, ClassFile.PUBLIC); *************** *** 415,419 **** if (nparamcell > 0) { if (to_cell == 0) { ! to_cell = classfile.pool.Methodref("org/python/core/PyFrame","to_cell","(II)V"); } Hashtable tbl = scope.tbl; --- 421,426 ---- if (nparamcell > 0) { if (to_cell == 0) { ! to_cell = classfile.pool.Methodref("org/python/core/PyFrame", ! "to_cell","(II)V"); } Hashtable tbl = scope.tbl; *************** *** 429,433 **** } ! compiler.parse(tree, c, fast_locals, className, classBody, scope,cflags); // !classdef only --- 436,441 ---- } ! compiler.parse(tree, c, fast_locals, className, classBody, ! scope,cflags); // !classdef only *************** *** 464,468 **** public void addRunnable() throws IOException { Code c = classfile.addMethod("getMain", ! "()Lorg/python/core/PyCode;", ClassFile.PUBLIC); mainCode.get(c); --- 472,476 ---- public void addRunnable() throws IOException { Code c = classfile.addMethod("getMain", ! "()" + $pyCode, ClassFile.PUBLIC); mainCode.get(c); *************** *** 471,475 **** public void addMain() throws IOException { ! Code c = classfile.addMethod("main", "([Ljava/lang/String;)V", ClassFile.PUBLIC | ClassFile.STATIC); --- 479,483 ---- public void addMain() throws IOException { ! Code c = classfile.addMethod("main", "(" + $str + ")V", ClassFile.PUBLIC | ClassFile.STATIC); *************** *** 483,487 **** "org/python/core/Py", "do_main", ! "(Lorg/python/core/PyRunnable;[Ljava/lang/String;)V")); c.return_(); } --- 491,495 ---- "org/python/core/Py", "do_main", ! "(" + $pyRunnable + $strArr + ")V")); c.return_(); } *************** *** 517,521 **** Code code = classfile.addMethod( "call_function", ! "(ILorg/python/core/PyFrame;)Lorg/python/core/PyObject;", ClassFile.PUBLIC); --- 525,529 ---- Code code = classfile.addMethod( "call_function", ! "(I" + $pyFrame + ")" + $pyObj, ClassFile.PUBLIC); *************** *** 537,541 **** classfile.name, ((PyCodeConstant)codes.elementAt(i)).fname, ! "(Lorg/python/core/PyFrame;)Lorg/python/core/PyObject;"); code.areturn(); } --- 545,549 ---- classfile.name, ((PyCodeConstant)codes.elementAt(i)).fname, ! "(" + $pyFrame + ")" + $pyObj); code.areturn(); } *************** *** 568,572 **** String name, String filename, boolean linenumbers, boolean printResults, ! boolean setFile,org.python.core.CompilerFlags cflags) throws Exception { --- 576,581 ---- String name, String filename, boolean linenumbers, boolean printResults, ! boolean setFile, ! org.python.core.CompilerFlags cflags) throws Exception { *************** *** 576,580 **** //Add __file__ for filename (if it exists?) ! Constant main = module.PyCode(node, "?",false, null, false, printResults, 0,null,cflags); module.mainCode = main; module.write(ostream); --- 585,590 ---- //Add __file__ for filename (if it exists?) ! Constant main = module.PyCode(node, "?", false, null, false, ! printResults, 0, null, cflags); module.mainCode = main; module.write(ostream); Index: ProxyMaker.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ProxyMaker.java,v retrieving revision 2.15 retrieving revision 2.16 diff -C2 -d -r2.15 -r2.16 *** ProxyMaker.java 2001/11/27 13:51:37 2.15 --- ProxyMaker.java 2001/11/27 19:07:21 2.16 *************** *** 10,14 **** import org.python.core.Py; ! public class ProxyMaker { public static final int tBoolean=0; --- 10,14 ---- import org.python.core.Py; ! public class ProxyMaker implements ClassConstants { public static final int tBoolean=0; *************** *** 242,250 **** int jcall = code.pool.Methodref( "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); --- 242,250 ---- int jcall = code.pool.Methodref( "org/python/core/PyObject", jcallName, ! "(" + $objArr + ")" + $pyObj); int py2j = code.pool.Methodref( "org/python/core/Py", "py2"+name, ! "(" + $pyObj + ")"+type); code.invokevirtual(jcall); *************** *** 256,261 **** if (parameters.length == 0) { int EmptyObjects = code.pool.Fieldref( ! "org/python/core/Py", "EmptyObjects", ! "[Lorg/python/core/PyObject;"); code.getstatic(EmptyObjects); } --- 256,260 ---- if (parameters.length == 0) { int EmptyObjects = code.pool.Fieldref( ! "org/python/core/Py", "EmptyObjects", $pyObjArr); code.getstatic(EmptyObjects); } *************** *** 282,286 **** int newInteger = code.pool.Methodref( "org/python/core/Py", ! "newInteger", "(I)Lorg/python/core/PyInteger;"); code.invokestatic(newInteger); break; --- 281,285 ---- int newInteger = code.pool.Methodref( "org/python/core/Py", ! "newInteger", "(I)" + $pyInteger); code.invokestatic(newInteger); break; *************** *** 291,295 **** int newInteger1 = code.pool.Methodref( "org/python/core/Py", ! "newInteger", "(J)Lorg/python/core/PyObject;"); code.invokestatic(newInteger1); break; --- 290,294 ---- int newInteger1 = code.pool.Methodref( "org/python/core/Py", ! "newInteger", "(J)" + $pyObj); code.invokestatic(newInteger1); break; *************** *** 300,304 **** int newFloat = code.pool.Methodref( "org/python/core/Py", ! "newFloat", "(F)Lorg/python/core/PyFloat;"); code.invokestatic(newFloat); break; --- 299,303 ---- int newFloat = code.pool.Methodref( "org/python/core/Py", ! "newFloat", "(F)" + $pyFloat); code.invokestatic(newFloat); break; *************** *** 309,313 **** int newFloat1 = code.pool.Methodref( "org/python/core/Py", ! "newFloat", "(D)Lorg/python/core/PyFloat;"); code.invokestatic(newFloat1); break; --- 308,312 ---- int newFloat1 = code.pool.Methodref( "org/python/core/Py", ! "newFloat", "(D)" + $pyFloat); code.invokestatic(newFloat1); break; *************** *** 317,321 **** int newString = code.pool.Methodref( "org/python/core/Py", ! "newString", "(C)Lorg/python/core/PyString;"); code.invokestatic(newString); break; --- 316,320 ---- int newString = code.pool.Methodref( "org/python/core/Py", ! "newString", "(C)" + $pyStr); code.invokestatic(newString); break; *************** *** 380,384 **** int jcall = code.pool.Methodref( "org/python/core/PyObject", jcallName, ! "([Ljava/lang/Object;)Lorg/python/core/PyObject;"); code.invokevirtual(jcall); /* catching exceptions is not vm mandatory --- 379,383 ---- int jcall = code.pool.Methodref( "org/python/core/PyObject", jcallName, ! "(" + $objArr + ")" + $pyObj); code.invokevirtual(jcall); /* catching exceptions is not vm mandatory *************** *** 391,395 **** int forname = code.pool.Methodref( "java/lang/Class","forName", ! "(Ljava/lang/String;)Ljava/lang/Class;"); code.ldc(ret.getName()); code.invokestatic(forname); --- 390,394 ---- int forname = code.pool.Methodref( "java/lang/Class","forName", ! "(" + $str + ")" + $clss); code.ldc(ret.getName()); code.invokestatic(forname); *************** *** 399,412 **** forname_exch_start.setPosition(); code.stack = 1; ! code.pop(); // never reached, but this code keeps the verifier happy code.aconst_null(); 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", ! "(Lorg/python/core/PyObject;Ljava/lang/Class;)Ljava/lang/Object;"); code.invokestatic(tojava); // I guess I need this checkcast to keep the verifier happy --- 398,414 ---- forname_exch_start.setPosition(); code.stack = 1; ! // never reached, but this code keeps the verifier happy ! code.pop(); code.aconst_null(); 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", ! "(" + $pyObj + $clss + ")" + $obj); code.invokestatic(tojava); // I guess I need this checkcast to keep the verifier happy *************** *** 454,458 **** int jthrow = code.pool.Methodref( "org/python/core/PyObject", "_jthrow", ! "(Ljava/lang/Throwable;)V"); code.invokevirtual(jthrow); --- 456,460 ---- int jthrow = code.pool.Methodref( "org/python/core/PyObject", "_jthrow", ! "(" + $throwable + ")V"); code.invokevirtual(jthrow); *************** *** 486,497 **** code.aload(0); - // int proxy = code.pool.Fieldref(classfile.name, "__proxy", "Lorg/python/core/PyInstance;"); - // code.getfield(proxy); - code.ldc(name); - // int nref = code.pool.Fieldref(classfile.name, name, "Lorg/python/core/PyString;"); - // code.getstatic(nref); - if (!isAbstract) { int tmp = code.getLocal(); --- 488,493 ---- *************** *** 499,503 **** "org/python/core/Py", "jfindattr", ! "(Lorg/python/core/PyProxy;Ljava/lang/String;)Lorg/python/core/PyObject;"); code.invokestatic(jfindattr); --- 495,499 ---- "org/python/core/Py", "jfindattr", ! "(" + $pyProxy + $str + ")" + $pyObj); code.invokestatic(jfindattr); *************** *** 525,529 **** "org/python/core/Py", "jgetattr", ! "(Lorg/python/core/PyProxy;Ljava/lang/String;)Lorg/python/core/PyObject;"); code.invokestatic(jgetattr); callMethod(code, name, parameters, ret, --- 521,525 ---- "org/python/core/Py", "jgetattr", ! "(" + $pyProxy + $str + ")" + $pyObj); code.invokestatic(jgetattr); callMethod(code, name, parameters, ret, *************** *** 534,538 **** "org/python/core/Py", "jfindattr", ! "(Lorg/python/core/PyProxy;Ljava/lang/String;)Lorg/python/core/PyObject;"); code.invokestatic(jfindattr); code.dup(); --- 530,534 ---- "org/python/core/Py", "jfindattr", ! "(" + $pyProxy + $str + ")" + $pyObj); code.invokestatic(jfindattr); code.dup(); *************** *** 662,668 **** /* rationale: JC java-class, P proxy-class subclassing JC in order to avoid infinite recursion P should define super__foo ! only if no class between P and JC in the hierarchy defines it yet; ! this means that the python class needing P is the first that ! redefines the JC method foo. */ try { --- 658,664 ---- /* rationale: JC java-class, P proxy-class subclassing JC in order to avoid infinite recursion P should define super__foo ! only if no class between P and JC in the hierarchy defines ! it yet; this means that the python class needing P is the ! first that redefines the JC method foo. */ try { *************** *** 735,739 **** classfile.addInterface(mapClass(org.python.core.ClassDictInit.class)); Code code = classfile.addMethod("classDictInit", ! "(Lorg/python/core/PyObject;)V", Modifier.PUBLIC | Modifier.STATIC); code.aload(0); --- 731,735 ---- classfile.addInterface(mapClass(org.python.core.ClassDictInit.class)); Code code = classfile.addMethod("classDictInit", ! "(" + $pyObj + ")V", Modifier.PUBLIC | Modifier.STATIC); code.aload(0); *************** *** 747,756 **** int j2py = code.pool.Methodref( "org/python/core/Py", "java2py", ! "(Ljava/lang/Object;)Lorg/python/core/PyObject;"); code.invokestatic(j2py); int setitem = code.pool.Methodref( "org/python/core/PyObject", "__setitem__", ! "(Ljava/lang/String;Lorg/python/core/PyObject;)V"); code.invokevirtual(setitem); code.return_(); --- 743,752 ---- int j2py = code.pool.Methodref( "org/python/core/Py", "java2py", ! "(" + $obj + ")" + $pyObj); code.invokestatic(j2py); int setitem = code.pool.Methodref( "org/python/core/PyObject", "__setitem__", ! "(" + $str + $pyObj + ")V"); code.invokevirtual(setitem); code.return_(); Index: ScopeInfo.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopeInfo.java,v retrieving revision 2.5 retrieving revision 2.6 diff -C2 -d -r2.5 -r2.6 *** ScopeInfo.java 2001/11/27 13:51:37 2.5 --- ScopeInfo.java 2001/11/27 19:07:21 2.6 *************** *** 14,20 **** public void dump() { // for debugging ! if (org.python.core.Options.verbose < org.python.core.Py.DEBUG) return; for(int i=0; i<level; i++) System.err.print(' '); ! System.err.print(((kind != CLASSSCOPE)?scope_name:"class "+scope_name)+": "); for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); --- 14,22 ---- public void dump() { // for debugging ! if (org.python.core.Options.verbose < org.python.core.Py.DEBUG) ! return; for(int i=0; i<level; i++) System.err.print(' '); ! System.err.print(((kind != CLASSSCOPE)?scope_name:"class "+ ! scope_name)+": "); for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); *************** *** 23,30 **** 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 ! if ((flags&FROM_PARAM) != 0) System.err.print('p'); if ((flags&CELL) != 0) System.err.print('!'); if ((flags&FREE) != 0) System.err.print(",f"); --- 25,34 ---- System.err.print(name); if ((flags&BOUND) != 0) System.err.print('='); ! // func scope global (affect nested scopes) ! // vs. class scope global ! if ((flags&NGLOBAL) != 0) System.err.print('G'); ! else if ((flags&CLASS_GLOBAL) != 0) System.err.print('g'); ! if ((flags&PARAM) != 0) System.err.print('P'); ! else if ((flags&FROM_PARAM) != 0) System.err.print('p'); if ((flags&CELL) != 0) System.err.print('!'); if ((flags&FREE) != 0) System.err.print(",f"); *************** *** 34,38 **** } ! public ScopeInfo(String name,SimpleNode node,int level,int kind,int func_level,ArgListCompiler ac,boolean nested_scopes) { scope_name = name; scope_node = node; --- 38,44 ---- } ! public ScopeInfo(String name, SimpleNode node, int level, int kind, ! int func_level, ArgListCompiler ac, ! boolean nested_scopes) { scope_name = name; scope_node = node; *************** *** 57,61 **** public int addGlobal(String name) { ! int global = kind==CLASSSCOPE?CLASS_GLOBAL:NGLOBAL; // global kind = func vs. class SymInfo info = (SymInfo)tbl.get(name); if (info == null) { --- 63,68 ---- public int addGlobal(String name) { ! // global kind = func vs. class ! int global = kind==CLASSSCOPE?CLASS_GLOBAL:NGLOBAL; SymInfo info = (SymInfo)tbl.get(name); if (info == null) { *************** *** 128,135 **** int flags = info.flags; if (func) { ! if ((flags&NGLOBAL) == 0 && (flags&BOUND) != 0) { // not func global and bound ? if (nested_scopes) { info.flags |= CELL; ! if ((info.flags&PARAM) != 0) jy_paramcells.addElement(name); cellvars.addElement(name); info.env_index = cell++; --- 135,144 ---- int flags = info.flags; if (func) { ! // not func global and bound ? ! if ((flags&NGLOBAL) == 0 && (flags&BOUND) != 0) { if (nested_scopes) { info.flags |= CELL; ! if ((info.flags&PARAM) != 0) ! jy_paramcells.addElement(name); cellvars.addElement(name); info.env_index = cell++; *************** *** 137,141 **** continue; } ! ctxt.error("local name '"+name+"' in '"+scope_name+"' shadows use as global in nested scopes",false,scope_node); } } else { --- 146,152 ---- continue; } ! ctxt.error("local name '"+name+"' in '"+scope_name+ ! "' shadows use as global in nested scopes", ! false, scope_node); } } else { *************** *** 171,192 **** if ((unqual_exec || from_import_star)) { if(some_inner_free) dynastuff_trouble(true, ctxt); ! else if(func_level > 1 && some_free) dynastuff_trouble(false, ctxt); } } ! private void dynastuff_trouble(boolean inner_free,CompilationContext ctxt) throws Exception { String illegal; if (unqual_exec && from_import_star) ! illegal = "function '"+scope_name+"' uses import * and bare exec, which are illegal"; else if (unqual_exec) ! illegal = "unqualified exec is not allowed in function '"+scope_name+"'"; ! else illegal = "import * is not allowed in function '"+scope_name+"'"; String why; if (inner_free) ! why = " because it contains a function with free variables"; else ! why = " because it contains free variables"; ! ctxt.error(illegal + why ,nested_scopes,scope_node); } --- 182,208 ---- if ((unqual_exec || from_import_star)) { if(some_inner_free) dynastuff_trouble(true, ctxt); ! else if(func_level > 1 && some_free) ! dynastuff_trouble(false, ctxt); } } ! private void dynastuff_trouble(boolean inner_free, ! CompilationContext ctxt) throws Exception { String illegal; if (unqual_exec && from_import_star) ! illegal = "function '"+scope_name+ ! "' uses import * and bare exec, which are illegal"; else if (unqual_exec) ! illegal = "unqualified exec is not allowed in function '"+ ! scope_name+"'"; ! else ! illegal = "import * is not allowed in function '"+scope_name+"'"; String why; if (inner_free) ! why = " because it contains a function with free variables"; else ! why = " because it contains free variables"; ! ctxt.error(illegal + why, nested_scopes, scope_node); } *************** *** 204,208 **** if ((flags&FREE) != 0) { SymInfo up_info = (SymInfo)up_tbl.get(name); ! if (up_info != null) { // ?? differs from CPython -- what is the intended behaviour? int up_flags = up_info.flags; if ((up_flags&(CELL|FREE)) != 0) { --- 220,225 ---- if ((flags&FREE) != 0) { SymInfo up_info = (SymInfo)up_tbl.get(name); ! // ?? differs from CPython -- what is the intended behaviour? ! if (up_info != null) { int up_flags = up_info.flags; if ((up_flags&(CELL|FREE)) != 0) { *************** *** 211,215 **** continue; } ! if (nested && (up_flags&NGLOBAL) != 0) { // ! func global affect nested scopes info.flags = NGLOBAL|BOUND; continue; --- 228,233 ---- continue; } ! // ! func global affect nested scopes ! if (nested && (up_flags&NGLOBAL) != 0) { info.flags = NGLOBAL|BOUND; continue; *************** *** 221,224 **** } - } --- 239,241 ---- Index: ScopesCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopesCompiler.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -d -r2.4 -r2.5 *** ScopesCompiler.java 2001/05/27 18:49:15 2.4 --- ScopesCompiler.java 2001/11/27 19:07:21 2.5 *************** *** 28,33 **** scopes = new Stack(); mode = GET; - /*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); --- 28,31 ---- *************** *** 54,63 **** } ! public void beginScope(String name,int kind,SimpleNode node,ArgListCompiler ac) { if (cur != null) { scopes.push(cur); } if (kind == FUNCSCOPE) func_level++; ! node.scope = cur = new ScopeInfo(name,node,level++,kind,func_level,ac,nested_scopes); } --- 52,64 ---- } ! public void beginScope(String name, int kind, SimpleNode node, ! ArgListCompiler ac) ! { if (cur != null) { scopes.push(cur); } if (kind == FUNCSCOPE) func_level++; ! node.scope = cur = new ScopeInfo(name, node, level++, kind, ! func_level, ac, nested_scopes); } *************** *** 75,79 **** node.visit(this); } catch(Throwable t) { ! throw org.python.core.parser.fixParseError(null,t,code_compiler.getFilename()); } } --- 76,81 ---- node.visit(this); } catch(Throwable t) { ! throw org.python.core.parser.fixParseError(null, t, ! code_compiler.getFilename()); } } *************** *** 154,158 **** node.getChild(i).visit(this); } ! if(node.getChild(n-1).id != PythonGrammarTreeConstants.JJTCOMMA) node.getChild(n-1).visit(this); } return null; --- 156,161 ---- node.getChild(i).visit(this); } ! if(node.getChild(n-1).id != PythonGrammarTreeConstants.JJTCOMMA) ! node.getChild(n-1).visit(this); } return null; *************** *** 238,246 **** int prev = cur.addGlobal(name); if (prev >= 0) { ! if ((prev&FROM_PARAM) != 0) code_compiler.error("name '"+name+"' is local and global",true,node); if ((prev&GLOBAL) != 0) continue; String what; if ((prev&BOUND) != 0) what = "assignment"; else what = "use"; ! code_compiler.error("name '"+name+"' declared global after "+what,false,node); } } --- 241,252 ---- int prev = cur.addGlobal(name); if (prev >= 0) { ! if ((prev&FROM_PARAM) != 0) ! code_compiler.error("name '"+name+"' is local and global", ! true,node); if ((prev&GLOBAL) != 0) continue; String what; if ((prev&BOUND) != 0) what = "assignment"; else what = "use"; ! code_compiler.error("name '"+name+"' declared global after "+ ! what,false,node); } } *************** *** 477,481 **** if (n > 0) { for (int i=0; i<n-1; i++) node.getChild(i).visit(this); ! if (node.getChild(n-1).id != PythonGrammarTreeConstants.JJTCOMMA) node.getChild(n-1).visit(this); } return null; --- 483,488 ---- if (n > 0) { for (int i=0; i<n-1; i++) node.getChild(i).visit(this); ! if (node.getChild(n-1).id != PythonGrammarTreeConstants.JJTCOMMA) ! node.getChild(n-1).visit(this); } return null; *************** *** 494,498 **** if (n > 0) { for (int i=0; i<n-1; i++) node.getChild(i).visit(this); ! if (node.getChild(n-1).id != PythonGrammarTreeConstants.JJTCOMMA) node.getChild(n-1).visit(this); } return null; --- 501,506 ---- if (n > 0) { for (int i=0; i<n-1; i++) node.getChild(i).visit(this); ! if (node.getChild(n-1).id != PythonGrammarTreeConstants.JJTCOMMA) ! node.getChild(n-1).visit(this); } return null; *************** *** 582,586 **** String name = (String)node.getInfo(); if ( mode != GET) { ! if (name.equals("__debug__")) code_compiler.error("can not assign to __debug__",false,node); cur.addBound(name); } --- 590,595 ---- String name = (String)node.getInfo(); if ( mode != GET) { ! if (name.equals("__debug__")) ! code_compiler.error("can not assign to __debug__",false,node); cur.addBound(name); } |