From: Finn B. <bc...@us...> - 2000-12-06 20:55:34
|
Update of /cvsroot/jython/jython/org/python/compiler In directory slayer.i.sourceforge.net:/tmp/cvs-serv1023 Modified Files: LocalsCompiler.java CodeCompiler.java Log Message: Fixed bug 122834 by detecting when ImportAll or ExecStmt are used in a function. Such use will disable the fast getglobal() call and use the slower getname() instead. Index: LocalsCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/LocalsCompiler.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -r2.4 -r2.5 *** LocalsCompiler.java 2000/10/13 20:00:25 2.4 --- LocalsCompiler.java 2000/12/06 20:55:30 2.5 *************** *** 14,17 **** --- 14,18 ---- static final int SET = 1; static final int DEL = 2; + boolean optimizeGlobals = true; public LocalsCompiler() { *************** *** 128,131 **** --- 129,138 ---- public Object ImportFrom(SimpleNode node) throws Exception { int n = node.getNumChildren(); + if (n == 1) { + // ImportAll + optimizeGlobals = false; + return null; + } + for (int i=1; i<n; i++) { SimpleNode cnode = node.getChild(i); *************** *** 151,154 **** --- 158,162 ---- public Object exec_stmt(SimpleNode node) throws Exception { //Disable locals somehow here? + optimizeGlobals = false; return null; } Index: CodeCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/CodeCompiler.java,v retrieving revision 2.7 retrieving revision 2.8 diff -C2 -r2.7 -r2.8 *** CodeCompiler.java 2000/10/18 13:01:11 2.7 --- CodeCompiler.java 2000/12/06 20:55:30 2.8 *************** *** 33,36 **** --- 33,37 ---- public Hashtable locals; public Hashtable globals; + boolean optimizeGlobals = true; public Vector names; public String className; *************** *** 179,182 **** --- 180,184 ---- locals = lc.locals; globals = lc.globals; + optimizeGlobals = lc.optimizeGlobals; mode = GET; *************** *** 2163,2180 **** case GET: loadFrame(); ! Integer i=null; ! if (fast_locals) ! i = (Integer)locals.get(name); ! ! if (!fast_locals || i != null) { ! if (i == null) { code.ldc(name); ! if (mrefs.getlocal1 == 0) { ! mrefs.getlocal1 = code.pool.Methodref( ! "org/python/core/PyFrame", "getname", "(Ljava/lang/String;)Lorg/python/core/PyObject;"); } ! code.invokevirtual(mrefs.getlocal1); ! } else { code.iconst(i.intValue()); if (mrefs.getlocal2 == 0) { --- 2165,2181 ---- case GET: loadFrame(); ! if (fast_locals) { ! Integer i = (Integer)locals.get(name); ! if (i == null && optimizeGlobals) { code.ldc(name); ! if (mrefs.getglobal == 0) { ! mrefs.getglobal = code.pool.Methodref( ! "org/python/core/PyFrame", "getglobal", "(Ljava/lang/String;)Lorg/python/core/PyObject;"); } ! code.invokevirtual(mrefs.getglobal); ! return null; ! } ! if (i != null) { code.iconst(i.intValue()); if (mrefs.getlocal2 == 0) { *************** *** 2184,2198 **** } code.invokevirtual(mrefs.getlocal2); } - } else { - code.ldc(name); - if (mrefs.getglobal == 0) { - mrefs.getglobal = code.pool.Methodref( - "org/python/core/PyFrame", "getglobal", - "(Ljava/lang/String;)Lorg/python/core/PyObject;"); - } - code.invokevirtual(mrefs.getglobal); } return null; case SET: loadFrame(); --- 2185,2200 ---- } code.invokevirtual(mrefs.getlocal2); + return null; } } + code.ldc(name); + if (mrefs.getlocal1 == 0) { + mrefs.getlocal1 = code.pool.Methodref( + "org/python/core/PyFrame", "getname", + "(Ljava/lang/String;)Lorg/python/core/PyObject;"); + } + code.invokevirtual(mrefs.getlocal1); return null; + case SET: loadFrame(); *************** *** 2217,2221 **** code.invokevirtual(mrefs.setlocal1); } else { ! i = (Integer)locals.get(name); if (i == null) { System.err.println("internal compiler error: "+node); --- 2219,2223 ---- code.invokevirtual(mrefs.setlocal1); } else { ! Integer i = (Integer)locals.get(name); if (i == null) { System.err.println("internal compiler error: "+node); *************** *** 2252,2256 **** code.invokevirtual(mrefs.dellocal1); } else { ! i = (Integer)locals.get(name); code.iconst(i.intValue()); if (mrefs.dellocal2 == 0) { --- 2254,2258 ---- code.invokevirtual(mrefs.dellocal1); } else { ! Integer i = (Integer)locals.get(name); code.iconst(i.intValue()); if (mrefs.dellocal2 == 0) { |