From: <th...@us...> - 2008-09-24 22:12:32
|
Revision: 5346 http://jython.svn.sourceforge.net/jython/?rev=5346&view=rev Author: thobes Date: 2008-09-24 22:12:23 +0000 (Wed, 24 Sep 2008) Log Message: ----------- Fixed the bug of the __exit__ method not being invoked on the outer context manager in the case of nested with statements. The problem was that the exception handlers were not properly sorted. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-09-24 21:05:39 UTC (rev 5345) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-09-24 22:12:23 UTC (rev 5346) @@ -2090,7 +2090,7 @@ // mgr = (EXPR) visit(node.context_expr); - int mgr_tmp = code.getLocal("org/python/core/PyObject"); + int mgr_tmp = code.getLocal("org/python/core/PyObject"); code.astore(mgr_tmp); // exit = mgr.__exit__ # Not calling it yet, so storing in the frame @@ -2113,7 +2113,10 @@ // exc = True # not necessary, since we don't exec finally if exception // try-catch block here - code.trycatch(label_body_start, label_body_end, label_catch, "java/lang/Throwable"); + //code.trycatch(label_body_start, label_body_end, label_catch, "java/lang/Throwable"); + ExceptionHandler handler = new ExceptionHandler(); + handler.exceptionStarts.addElement(label_body_start); + exceptionHandlers.push(handler); // VAR = value # Only if "as VAR" is present code.label(label_body_start); @@ -2124,8 +2127,10 @@ // BLOCK suite(node.body); + exceptionHandlers.pop(); code.goto_(label_finally); code.label(label_body_end); + handler.exceptionEnds.addElement(label_body_end); // CATCH code.label(label_catch); @@ -2162,6 +2167,8 @@ code.athrow(); code.freeLocal(ts_tmp); + + handler.addExceptionHandlers(label_catch); // FINALLY // ordinarily with a finally, we need to duplicate the code. that's not the case here This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2008-09-25 18:52:37
|
Revision: 5347 http://jython.svn.sourceforge.net/jython/?rev=5347&view=rev Author: thobes Date: 2008-09-25 18:52:30 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Fix of the bug with "def f(): lambda x=(yield): 1". The problem was that the order of instructions were such that there was elements on the stack before the yield-point that does not get restored. I also found another problem in that the types for local variables in CodeCompiler are not proper java types, this is in error in nearly all places, and needs to be fixed in a later commit. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-09-24 22:12:23 UTC (rev 5346) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-09-25 18:52:30 UTC (rev 5347) @@ -331,15 +331,17 @@ if (n == 0) { code.getstatic("org/python/core/Py", "EmptyObjects", $pyObjArr); } else { - int tmp = code.getLocal("[org/python/core/PyObject"); + int tmp = code.getLocal("[Lorg/python/core/PyObject;"); code.iconst(n); code.anewarray("org/python/core/PyObject"); code.astore(tmp); for(int i=0; i<n; i++) { + visit(nodes[i]); code.aload(tmp); + code.swap(); code.iconst(i); - visit(nodes[i]); + code.swap(); code.aastore(); } code.aload(tmp); @@ -1787,16 +1789,20 @@ setline(node); + ScopeInfo scope = module.getScopeInfo(node); + + makeArray(scope.ac.getDefaults()); + code.new_("org/python/core/PyFunction"); + + code.dup_x1(); + code.swap(); - code.dup(); loadFrame(); code.getfield("org/python/core/PyFrame", "f_globals", $pyObj); + + code.swap(); - ScopeInfo scope = module.getScopeInfo(node); - - makeArray(scope.ac.getDefaults()); - scope.setup_closure(); scope.dump(); module.PyCode(retSuite, name, true, className, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-10-11 20:54:55
|
Revision: 5373 http://jython.svn.sourceforge.net/jython/?rev=5373&view=rev Author: fwierzbicki Date: 2008-10-11 20:54:47 +0000 (Sat, 11 Oct 2008) Log Message: ----------- Throw a Python exception for two internal compiler errors that where just printing a less useful error message and going on to an NPE. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-11 06:42:35 UTC (rev 5372) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-11 20:54:47 UTC (rev 5373) @@ -1966,7 +1966,7 @@ code.invokevirtual("org/python/core/PyFrame", "setlocal", "(" + $str + $pyObj + ")V"); } else { if (syminf == null) { - System.err.println("internal compiler error: "+node); + throw new ParseException("internal compiler error", node); } if ((syminf.flags&ScopeInfo.CELL) != 0) { code.iconst(syminf.env_index); @@ -1991,7 +1991,7 @@ code.invokevirtual("org/python/core/PyFrame", "dellocal", "(" + $str + ")V"); } else { if (syminf == null) { - System.err.println("internal compiler error: "+node); + throw new ParseException("internal compiler error", node); } if ((syminf.flags&ScopeInfo.CELL) != 0) { module.error("can not delete variable '"+name+ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-10-12 20:10:17
|
Revision: 5380 http://jython.svn.sourceforge.net/jython/?rev=5380&view=rev Author: pjenvey Date: 2008-10-12 20:10:04 +0000 (Sun, 12 Oct 2008) Log Message: ----------- fix bad bytecode generated for: a[[b for b, c in d]] = e the store was losing track of the value (e) here because the list comp/tuple unpack combo overwrote where e's location was held Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-12 16:28:15 UTC (rev 5379) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-12 20:10:04 UTC (rev 5380) @@ -1604,6 +1604,7 @@ return Slice(node, (Slice) node.slice); } + int value = temporary; expr_contextType ctx = node.ctx; if (node.ctx == expr_contextType.AugStore && augmode == expr_contextType.Store) { restoreAugTmps(node, 2); @@ -1627,7 +1628,7 @@ return null; case Param: case Store: - code.aload(temporary); + code.aload(value); code.invokevirtual("org/python/core/PyObject", "__setitem__", "(" + $pyObj + $pyObj + ")V"); return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2008-10-17 19:28:23
|
Revision: 5455 http://jython.svn.sourceforge.net/jython/?rev=5455&view=rev Author: thobes Date: 2008-10-17 19:28:20 +0000 (Fri, 17 Oct 2008) Log Message: ----------- Removed some erronious code in visitYield. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-17 18:15:50 UTC (rev 5454) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-17 19:28:20 UTC (rev 5455) @@ -555,18 +555,6 @@ throw new ParseException("'yield' outside function", node); } - if (yield_count == 0) { - loadFrame(); - code.invokevirtual("org/python/core/PyFrame", "getGeneratorInput", "()" + $obj); - code.dup(); - code.instanceof_("org/python/core/PyException"); - Label done = new Label(); - code.ifeq(done); - code.checkcast("java/lang/Throwable"); - code.athrow(); - code.label(done); - } - if (node.value != null) { visit(node.value); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-10-19 00:01:26
|
Revision: 5463 http://jython.svn.sourceforge.net/jython/?rev=5463&view=rev Author: pjenvey Date: 2008-10-19 00:01:20 +0000 (Sun, 19 Oct 2008) Log Message: ----------- fix forgetting to free the var/starargs of Calls, which produced bad byte for: def gen(): if True: # or b(**c) a = b(*c) yield d Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-18 20:23:01 UTC (rev 5462) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-19 00:01:20 UTC (rev 5463) @@ -1589,6 +1589,8 @@ code.aload(argArray); code.aload(strArray); + code.freeLocal(argArray); + code.freeLocal(strArray); code.dup2_x2(); code.pop2(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-10-19 06:51:18
|
Revision: 5467 http://jython.svn.sourceforge.net/jython/?rev=5467&view=rev Author: pjenvey Date: 2008-10-19 06:51:07 +0000 (Sun, 19 Oct 2008) Log Message: ----------- fix visitCompare leaving the left side on the stack, causing a minor short term memory leak Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-19 05:17:07 UTC (rev 5466) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-19 06:51:07 UTC (rev 5467) @@ -1374,12 +1374,15 @@ code.swap(); visitCmpop(node.ops[n-1]); + code.aconst_null(); + code.astore(last); + code.freeLocal(last); + if (n > 1) { code.astore(result); code.label(end); code.aload(result); } - code.freeLocal(last); code.freeLocal(result); return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-10-19 20:52:03
|
Revision: 5469 http://jython.svn.sourceforge.net/jython/?rev=5469&view=rev Author: pjenvey Date: 2008-10-19 20:51:56 +0000 (Sun, 19 Oct 2008) Log Message: ----------- move the last visitCompare fix to after the end label so we also avoid the issue when a chained comparison fails fast Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-19 15:16:29 UTC (rev 5468) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-19 20:51:56 UTC (rev 5469) @@ -1374,15 +1374,15 @@ code.swap(); visitCmpop(node.ops[n-1]); - code.aconst_null(); - code.astore(last); - code.freeLocal(last); - if (n > 1) { code.astore(result); code.label(end); code.aload(result); } + + code.aconst_null(); + code.astore(last); + code.freeLocal(last); code.freeLocal(result); return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-10-21 21:25:28
|
Revision: 5500 http://jython.svn.sourceforge.net/jython/?rev=5500&view=rev Author: pjenvey Date: 2008-10-21 21:25:21 +0000 (Tue, 21 Oct 2008) Log Message: ----------- fix passing a null node to the ParseException for bare except clauses that aren't the last clause, and match the error message to CPython Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-21 20:02:03 UTC (rev 5499) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-21 21:25:21 UTC (rev 5500) @@ -1137,7 +1137,7 @@ } else { if (i != node.handlers.length-1) { throw new ParseException( - "bare except must be last except clause", handler.type); + "default 'except:' must be last", handler); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-09 22:26:01
|
Revision: 5725 http://jython.svn.sourceforge.net/jython/?rev=5725&view=rev Author: pjenvey Date: 2008-12-09 22:25:56 +0000 (Tue, 09 Dec 2008) Log Message: ----------- these are no longer used Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-12-09 21:56:51 UTC (rev 5724) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-12-09 22:25:56 UTC (rev 5725) @@ -633,17 +633,6 @@ } } - private boolean inFinallyBody() { - for (int i = 0; i < exceptionHandlers.size(); ++i) { - ExceptionHandler handler = - (ExceptionHandler)exceptionHandlers.elementAt(i); - if (handler.isFinallyHandler()) { - return true; - } - } - return false; - } - private void restoreLocals() throws Exception { endExceptionHandlers(); @@ -1490,7 +1479,6 @@ public static int makeStrings(Code c, Collection<String> names) throws IOException { - int n = 0; if (names != null) { c.iconst(names.size()); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-13 22:44:58
|
Revision: 5756 http://jython.svn.sourceforge.net/jython/?rev=5756&view=rev Author: fwierzbicki Date: 2008-12-13 22:44:55 +0000 (Sat, 13 Dec 2008) Log Message: ----------- uncomment call to setline which will now activate ASM code that will create a LineNumberTable in .class output. This will show line numbers in JVM generated stack traces. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-12-13 16:08:36 UTC (rev 5755) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-12-13 22:44:55 UTC (rev 5756) @@ -175,7 +175,7 @@ public void setline(int line) throws Exception { if (module.linenumbers) { - //FJW code.setline(line); + code.setline(line); loadFrame(); code.iconst(line); code.invokevirtual("org/python/core/PyFrame", "setline", "(I)V"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-07-20 09:41:47
|
Revision: 6550 http://jython.svn.sourceforge.net/jython/?rev=6550&view=rev Author: thobes Date: 2009-07-20 09:41:42 +0000 (Mon, 20 Jul 2009) Log Message: ----------- Fix for problem with compiling coroutines, yield was not allowed in the iterator expression of for-nodes. Example of failing code: def err(): for x in (yield): pass Fixed by deferring the allocation of the registers for storing the iter until after the iter expression is evaluated. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-07-20 04:13:32 UTC (rev 6549) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-07-20 09:41:42 UTC (rev 6550) @@ -1089,14 +1089,14 @@ Label start_loop = new Label(); Label next_loop = new Label(); - int iter_tmp = code.getLocal("org/python/core/PyObject"); - int expr_tmp = code.getLocal("org/python/core/PyObject"); - setline(node); //parse the list visit(node.getInternalIter()); + int iter_tmp = code.getLocal("org/python/core/PyObject"); + int expr_tmp = code.getLocal("org/python/core/PyObject"); + //set up the loop iterator code.invokevirtual("org/python/core/PyObject", "__iter__", "()Lorg/python/core/PyObject;"); code.astore(iter_tmp); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-07-21 20:55:58
|
Revision: 6555 http://jython.svn.sourceforge.net/jython/?rev=6555&view=rev Author: thobes Date: 2009-07-21 20:55:55 +0000 (Tue, 21 Jul 2009) Log Message: ----------- Fix for issue 1407. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-07-21 02:48:53 UTC (rev 6554) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-07-21 20:55:55 UTC (rev 6555) @@ -657,7 +657,7 @@ for (String signature : stack) { code.aload(array); // Stack: |- ... array - code.iconst(i); + code.iconst(i--); code.aaload(); // Stack: |- ... value code.checkcast(signature); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-07-21 21:54:02
|
Revision: 6556 http://jython.svn.sourceforge.net/jython/?rev=6556&view=rev Author: thobes Date: 2009-07-21 21:53:56 +0000 (Tue, 21 Jul 2009) Log Message: ----------- Fix for a problem I discovered with the thread state being stored on yield in generators. This could have lead to faulty behaviour if the next resumption of the generator is from another thread or memory leaks if the generator is kept around longer than the lifetime of the thread. This fix does not have ideal memory footprint, one slot in the stored stack content array is left empty (where the thread state should have been), but it works, such minor memory optimizations can be saved for later. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-07-21 20:55:55 UTC (rev 6555) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-07-21 21:53:56 UTC (rev 6556) @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.ListIterator; import java.util.Map; import java.util.Stack; import java.util.Vector; @@ -635,15 +636,23 @@ code.iconst(stack.size()); code.anewarray("java/lang/Object"); code.astore(array); - for (int i = 0; i < stack.size(); i++) { - code.aload(array); - // Stack: |- ... value array - code.swap(); - code.iconst(i); - code.swap(); - // Stack: |- ... array index value - code.aastore(); - // Stack: |- ... + ListIterator<String> content = stack.listIterator(stack.size()); + for (int i = 0; content.hasPrevious(); i++) { + String signature = content.previous(); + if ("org/python/core/ThreadState".equals(signature)) { + // Stack: ... threadstate + code.pop(); + // Stack: ... + } else { + code.aload(array); + // Stack: |- ... value array + code.swap(); + code.iconst(i++); + code.swap(); + // Stack: |- ... array index value + code.aastore(); + // Stack: |- ... + } } return array; } else { @@ -655,12 +664,16 @@ if (stack.size() > 0) { int i = stack.size() -1; for (String signature : stack) { - code.aload(array); - // Stack: |- ... array - code.iconst(i--); - code.aaload(); - // Stack: |- ... value - code.checkcast(signature); + if ("org/python/core/ThreadState".equals(signature)) { + loadThreadState(); + } else { + code.aload(array); + // Stack: |- ... array + code.iconst(i--); + code.aaload(); + // Stack: |- ... value + code.checkcast(signature); + } } code.freeLocal(array); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-03 00:09:39
|
Revision: 6827 http://jython.svn.sourceforge.net/jython/?rev=6827&view=rev Author: fwierzbicki Date: 2009-10-03 00:09:30 +0000 (Sat, 03 Oct 2009) Log Message: ----------- First nibble at using CodegenUtils. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-02 20:29:01 UTC (rev 6826) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-03 00:09:30 UTC (rev 6827) @@ -87,8 +87,8 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.commons.Method; +import static org.python.util.CodegenUtils.*; - public class CodeCompiler extends Visitor implements Opcodes, ClassConstants { public static final Object Exit=new Integer(1); @@ -153,7 +153,7 @@ } public void getNone() throws IOException { - code.getstatic("org/python/core/Py", "None", $pyObj); + code.getstatic("org/python/core/Py", "None", ci(PyObject.class)); } public void loadFrame() throws Exception { @@ -278,7 +278,7 @@ if (classBody) { loadFrame(); - code.invokevirtual("org/python/core/PyFrame", "getf_locals", "()" + $pyObj); + code.invokevirtual("org/python/core/PyFrame", "getf_locals", sig(PyObject.class)); code.areturn(); } else { if (exit == null) { @@ -415,7 +415,7 @@ code.new_("org/python/core/PyFunction"); code.dup(); loadFrame(); - code.getfield("org/python/core/PyFrame", "f_globals", $pyObj); + code.getfield("org/python/core/PyFrame", "f_globals", ci(PyObject.class)); code.aload(defaults); code.freeLocal(defaults); @@ -1975,7 +1975,7 @@ code.freeLocal(defaultsArray); loadFrame(); - code.getfield("org/python/core/PyFrame", "f_globals", $pyObj); + code.getfield("org/python/core/PyFrame", "f_globals", ci(PyObject.class)); code.swap(); @@ -2215,7 +2215,7 @@ code.new_("org/python/core/PyFunction"); code.dup(); loadFrame(); - code.getfield("org/python/core/PyFrame", "f_globals", $pyObj); + code.getfield("org/python/core/PyFrame", "f_globals", ci(PyObject.class)); ScopeInfo scope = module.getScopeInfo(node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-03 00:49:11
|
Revision: 6828 http://jython.svn.sourceforge.net/jython/?rev=6828&view=rev Author: fwierzbicki Date: 2009-10-03 00:48:54 +0000 (Sat, 03 Oct 2009) Log Message: ----------- Converted almost all "org/python/Foo" to p(Foo.class). There is one I'm not sure about as it looks like "[org/python/core/PyObject" which doesn't make sense to me -- I'd expect "[Lorg/python/core/PyObject;". Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-03 00:09:30 UTC (rev 6827) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-03 00:48:54 UTC (rev 6828) @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.ListIterator; import java.util.Map; @@ -75,13 +76,23 @@ import org.python.core.CompilerFlags; import org.python.core.ContextGuard; import org.python.core.ContextManager; +import org.python.core.imp; +import org.python.core.Py; import org.python.core.PyComplex; +import org.python.core.PyDictionary; +import org.python.core.PyException; import org.python.core.PyFloat; +import org.python.core.PyFrame; +import org.python.core.PyFunction; import org.python.core.PyInteger; +import org.python.core.PyList; import org.python.core.PyLong; import org.python.core.PyObject; +import org.python.core.PySlice; import org.python.core.PyString; +import org.python.core.PyTuple; import org.python.core.PyUnicode; +import org.python.core.ThreadState; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; @@ -153,7 +164,7 @@ } public void getNone() throws IOException { - code.getstatic("org/python/core/Py", "None", ci(PyObject.class)); + code.getstatic(p(Py.class), "None", ci(PyObject.class)); } public void loadFrame() throws Exception { @@ -167,15 +178,15 @@ public void setLastI(int idx) throws Exception { loadFrame(); code.iconst(idx); - code.putfield("org/python/core/PyFrame", "f_lasti", "I"); + code.putfield(p(PyFrame.class), "f_lasti", "I"); } private void loadf_back() throws Exception { - code.getfield("org/python/core/PyFrame", "f_back", $pyFrame); + code.getfield(p(PyFrame.class), "f_back", $pyFrame); } public int storeTop() throws Exception { - int tmp = code.getLocal("org/python/core/PyObject"); + int tmp = code.getLocal(p(PyObject.class)); code.astore(tmp); return tmp; } @@ -185,7 +196,7 @@ code.setline(line); loadFrame(); code.iconst(line); - code.invokevirtual("org/python/core/PyFrame", "setline", "(I)V"); + code.invokevirtual(p(PyFrame.class), "setline", "(I)V"); } } @@ -270,15 +281,15 @@ // this allows yield and with to happily co-exist loadFrame(); code.iconst(scope.max_with_count); - code.anewarray("org/python/core/PyObject"); - code.putfield("org/python/core/PyFrame", "f_exits", $pyObjArr); + code.anewarray(p(PyObject.class)); + code.putfield(p(PyFrame.class), "f_exits", $pyObjArr); } Object exit = visit(node); if (classBody) { loadFrame(); - code.invokevirtual("org/python/core/PyFrame", "getf_locals", sig(PyObject.class)); + code.invokevirtual(p(PyFrame.class), "getf_locals", sig(PyObject.class)); code.areturn(); } else { if (exit == null) { @@ -307,7 +318,7 @@ loadFrame(); code.ldc("__doc__"); visit(((Expr) suite.getInternalBody().get(0)).getInternalValue()); - code.invokevirtual("org/python/core/PyFrame", "setglobal", "(" +$str + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setglobal", "(" +$str + $pyObj + ")V"); } traverse(suite); return null; @@ -334,11 +345,11 @@ int array = code.getLocal("[Lorg/python/core/PyObject;"); if (n == 0) { - code.getstatic("org/python/core/Py", "EmptyObjects", $pyObjArr); + code.getstatic(p(Py.class), "EmptyObjects", $pyObjArr); code.astore(array); } else { code.iconst(n); - code.anewarray("org/python/core/PyObject"); + code.anewarray(p(PyObject.class)); code.astore(array); for(int i=0; i<n; i++) { @@ -357,7 +368,7 @@ public void freeArray(int array) { code.aload(array); code.aconst_null(); - code.invokestatic("java/util/Arrays", "fill", "(" + $objArr + $obj + ")V"); + code.invokestatic(p(Arrays.class), "fill", "(" + $objArr + $obj + ")V"); code.freeLocal(array); } @@ -378,7 +389,7 @@ int tmp = code.getLocal("[Lorg/python/core/PyObject;"); code.iconst(n); - code.anewarray("org/python/core/PyObject"); + code.anewarray(p(PyObject.class)); code.astore(tmp); Map<String, SymInfo> upTbl = scope.up.tbl; for(int i=0; i<n; i++) { @@ -390,7 +401,7 @@ } SymInfo symInfo = upTbl.get(scope.freevars.elementAt(i)); code.iconst(symInfo.env_index); - code.invokevirtual("org/python/core/PyFrame", "getclosure", "(I)" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getclosure", "(I)" + $pyObj); code.aastore(); } @@ -412,10 +423,10 @@ // with freeArray, unlike other usages of makeArray here int defaults = makeArray(scope.ac.getDefaults()); - code.new_("org/python/core/PyFunction"); + code.new_(p(PyFunction.class)); code.dup(); loadFrame(); - code.getfield("org/python/core/PyFrame", "f_globals", ci(PyObject.class)); + code.getfield(p(PyFrame.class), "f_globals", ci(PyObject.class)); code.aload(defaults); code.freeLocal(defaults); @@ -428,9 +439,9 @@ getDocString(node.getInternalBody()); if (!makeClosure(scope)) { - code.invokespecial("org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + ")V"); } else { - code.invokespecial( "org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); + code.invokespecial( p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); } applyDecorators(node.getInternalDecorator_list()); @@ -449,7 +460,7 @@ stackConsume(); loadThreadState(); code.aload(res); - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); code.astore(res); } code.aload(res); @@ -463,7 +474,7 @@ visit(node.getInternalValue()); if (print_results) { - code.invokestatic("org/python/core/Py", "printResult", "(" + $pyObj + ")V"); + code.invokestatic(p(Py.class), "printResult", "(" + $pyObj + ")V"); } else { code.pop(); } @@ -498,9 +509,9 @@ if (node.getInternalValues() == null || node.getInternalValues().size() == 0) { if (node.getInternalDest() != null) { code.aload(tmp); - code.invokestatic("org/python/core/Py", "printlnv", "(" + $pyObj + ")V"); + code.invokestatic(p(Py.class), "printlnv", "(" + $pyObj + ")V"); } else { - code.invokestatic("org/python/core/Py", "println", "()V"); + code.invokestatic(p(Py.class), "println", "()V"); } } else { for (int i = 0; i < node.getInternalValues().size(); i++) { @@ -508,16 +519,16 @@ code.aload(tmp); visit(node.getInternalValues().get(i)); if (node.getInternalNl() && i == node.getInternalValues().size() - 1) { - code.invokestatic("org/python/core/Py", "println", "(" + $pyObj + $pyObj + ")V"); + code.invokestatic(p(Py.class), "println", "(" + $pyObj + $pyObj + ")V"); } else { - code.invokestatic("org/python/core/Py", "printComma", "(" + $pyObj + $pyObj + ")V"); + code.invokestatic(p(Py.class), "printComma", "(" + $pyObj + $pyObj + ")V"); } } else { visit(node.getInternalValues().get(i)); if (node.getInternalNl() && i == node.getInternalValues().size() - 1) { - code.invokestatic("org/python/core/Py", "println", "(" + $pyObj + ")V"); + code.invokestatic(p(Py.class), "println", "(" + $pyObj + ")V"); } else { - code.invokestatic("org/python/core/Py", "printComma", "(" + $pyObj + ")V"); + code.invokestatic(p(Py.class), "printComma", "(" + $pyObj + ")V"); } } @@ -595,21 +606,21 @@ restoreStack(stackState); loadFrame(); - code.invokevirtual("org/python/core/PyFrame", "getGeneratorInput", "()" + $obj); + code.invokevirtual(p(PyFrame.class), "getGeneratorInput", "()" + $obj); code.dup(); - code.instanceof_("org/python/core/PyException"); + code.instanceof_(p(PyException.class)); Label done2 = new Label(); code.ifeq(done2); - code.checkcast("java/lang/Throwable"); + code.checkcast(p(Throwable.class)); code.athrow(); code.label(done2); - code.checkcast("org/python/core/PyObject"); + code.checkcast(p(PyObject.class)); return null; } private void stackProduce() { - stackProduce("org/python/core/PyObject"); + stackProduce(p(PyObject.class)); } private void stackProduce(String signature) { @@ -630,12 +641,12 @@ if (stack.size() > 0) { int array = code.getLocal("[Ljava/lang/Object;"); code.iconst(stack.size()); - code.anewarray("java/lang/Object"); + code.anewarray(p(Object.class)); code.astore(array); ListIterator<String> content = stack.listIterator(stack.size()); for (int i = 0; content.hasPrevious(); i++) { String signature = content.previous(); - if ("org/python/core/ThreadState".equals(signature)) { + if (p(ThreadState.class).equals(signature)) { // Stack: ... threadstate code.pop(); // Stack: ... @@ -660,7 +671,7 @@ if (stack.size() > 0) { int i = stack.size() -1; for (String signature : stack) { - if ("org/python/core/ThreadState".equals(signature)) { + if (p(ThreadState.class).equals(signature)) { loadThreadState(); } else { code.aload(array); @@ -681,7 +692,7 @@ Vector<String> v = code.getActiveLocals(); loadFrame(); - code.getfield("org/python/core/PyFrame", "f_savedlocals", "[Ljava/lang/Object;"); + code.getfield(p(PyFrame.class), "f_savedlocals", "[Ljava/lang/Object;"); int locals = code.getLocal("[Ljava/lang/Object;"); code.astore(locals); @@ -731,7 +742,7 @@ private void saveLocals() throws Exception { Vector<String> v = code.getActiveLocals(); code.iconst(v.size()); - code.anewarray("java/lang/Object"); + code.anewarray(p(Object.class)); int locals = code.getLocal("[Ljava/lang/Object;"); code.astore(locals); @@ -741,7 +752,7 @@ continue; code.aload(locals); code.iconst(i); - //code.checkcast(code.pool.Class("java/lang/Object")); + //code.checkcast(code.pool.Class(p(Object.class))); if (i == 2222) { code.aconst_null(); } else @@ -751,7 +762,7 @@ loadFrame(); code.aload(locals); - code.putfield("org/python/core/PyFrame", "f_savedlocals", "[Ljava/lang/Object;"); + code.putfield(p(PyFrame.class), "f_savedlocals", "[Ljava/lang/Object;"); code.freeLocal(locals); } @@ -795,16 +806,16 @@ if (node.getInternalInst() != null) { visit(node.getInternalInst()); stackProduce(); } if (node.getInternalTback() != null) { visit(node.getInternalTback()); stackProduce(); } if (node.getInternalType() == null) { - code.invokestatic("org/python/core/Py", "makeException", "()" + $pyExc); + code.invokestatic(p(Py.class), "makeException", "()" + $pyExc); } else if (node.getInternalInst() == null) { stackConsume(); - code.invokestatic("org/python/core/Py", "makeException", "(" + $pyObj + ")" + $pyExc); + code.invokestatic(p(Py.class), "makeException", "(" + $pyObj + ")" + $pyExc); } else if (node.getInternalTback() == null) { stackConsume(2); - code.invokestatic("org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); + code.invokestatic(p(Py.class), "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); } else { stackConsume(3); - code.invokestatic("org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyExc); + code.invokestatic(p(Py.class), "makeException", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyExc); } code.athrow(); return Exit; @@ -820,7 +831,7 @@ asname = a.getInternalAsname(); code.ldc(name); loadFrame(); - code.invokestatic("org/python/core/imp", "importOneAs", "(" + $str + $pyFrame + ")" + $pyObj); + code.invokestatic(p(imp.class), "importOneAs", "(" + $str + $pyFrame + ")" + $pyObj); } else { String name = a.getInternalName(); asname = name; @@ -828,7 +839,7 @@ asname = asname.substring(0, asname.indexOf('.')); code.ldc(name); loadFrame(); - code.invokestatic("org/python/core/imp", "importOne", "(" + $str + $pyFrame + ")" + $pyObj); + code.invokestatic(p(imp.class), "importOne", "(" + $str + $pyFrame + ")" + $pyObj); } set(new Name(a, asname, expr_contextType.Store)); } @@ -866,7 +877,7 @@ } loadFrame(); - code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); + code.invokestatic(p(imp.class), "importAll", "(" + $str + $pyFrame + ")V"); } else { java.util.List<String> fromNames = new ArrayList<String>();//[names.size()]; java.util.List<String> asnames = new ArrayList<String>();//[names.size()]; @@ -891,7 +902,7 @@ } else { code.iconst(node.getInternalLevel()); } - code.invokestatic("org/python/core/imp", "importFrom", "(" + $str + $strArr + $pyFrame + "I" + ")" + $pyObjArr); + code.invokestatic(p(imp.class), "importFrom", "(" + $str + $strArr + $pyFrame + "I" + ")" + $pyObjArr); int tmp = storeTop(); for (int i = 0; i < aliases.size(); i++) { code.aload(tmp); @@ -931,7 +942,7 @@ //do the real work here stackConsume(3); - code.invokestatic("org/python/core/Py", "exec", "(" + $pyObj + $pyObj + $pyObj + ")V"); + code.invokestatic(p(Py.class), "exec", "(" + $pyObj + $pyObj + $pyObj + ")V"); return null; } @@ -944,7 +955,7 @@ loadFrame(); emitGetGlobal("__debug__"); - code.invokevirtual("org/python/core/PyObject", "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); code.ifeq(end_of_assert); @@ -952,7 +963,7 @@ then the assertion succeeded, the message portion should not be processed. Otherwise, the message will be processed. */ visit(node.getInternalTest()); - code.invokevirtual("org/python/core/PyObject", "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); /* If evaluation is false, then branch to end of method */ code.ifne(end_of_assert); @@ -970,7 +981,7 @@ code.swap(); // The type is the first argument, but the message could be a yield - code.invokestatic("org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); + code.invokestatic(p(Py.class), "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); /* Raise assertion error. Only executes this logic if assertion failed */ @@ -989,7 +1000,7 @@ setline(node.getInternalTest()); visit(node.getInternalTest()); - code.invokevirtual("org/python/core/PyObject", "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); code.ifeq(end_of_suite); @@ -1026,7 +1037,7 @@ Label end_of_else = new Label(); visit(node.getInternalTest()); - code.invokevirtual("org/python/core/PyObject", "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); code.ifeq(end_of_else); visit(node.getInternalBody()); @@ -1074,7 +1085,7 @@ //Do test visit(node.getInternalTest()); - code.invokevirtual("org/python/core/PyObject", "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); code.ifne(start_loop); finishLoop(savebcf); @@ -1102,11 +1113,11 @@ //parse the list visit(node.getInternalIter()); - int iter_tmp = code.getLocal("org/python/core/PyObject"); - int expr_tmp = code.getLocal("org/python/core/PyObject"); + int iter_tmp = code.getLocal(p(PyObject.class)); + int expr_tmp = code.getLocal(p(PyObject.class)); //set up the loop iterator - code.invokevirtual("org/python/core/PyObject", "__iter__", "()Lorg/python/core/PyObject;"); + code.invokevirtual(p(PyObject.class), "__iter__", "()Lorg/python/core/PyObject;"); code.astore(iter_tmp); //do check at end of loop. Saves one opcode ;-) @@ -1125,7 +1136,7 @@ setline(node); //get the next element from the list code.aload(iter_tmp); - code.invokevirtual("org/python/core/PyObject", "__iternext__", "()" + $pyObj); + code.invokevirtual(p(PyObject.class), "__iternext__", "()" + $pyObj); code.astore(expr_tmp); code.aload(expr_tmp); @@ -1162,7 +1173,7 @@ code.aload(exc); //get specific exception visit(handler.getInternalType()); - code.invokevirtual("org/python/core/PyException", "match", "(" + $pyObj + ")Z"); + code.invokevirtual(p(PyException.class), "match", "(" + $pyObj + ")Z"); code.ifeq(end_of_self); } else { if (i != node.getInternalHandlers().size()-1) { @@ -1173,7 +1184,7 @@ if (handler.getInternalName() != null) { code.aload(exc); - code.getfield("org/python/core/PyException", "value", "Lorg/python/core/PyObject;"); + code.getfield(p(PyException.class), "value", "Lorg/python/core/PyObject;"); set(handler.getInternalName()); } @@ -1202,7 +1213,7 @@ // Do protected suite exceptionHandlers.push(inFinally); - int excLocal = code.getLocal("java/lang/Throwable"); + int excLocal = code.getLocal(p(Throwable.class)); code.aconst_null(); code.astore(excLocal); @@ -1229,11 +1240,11 @@ code.aload(excLocal); loadFrame(); - code.invokestatic("org/python/core/Py", "addTraceback", "(" + $throwable + $pyFrame + ")V"); + code.invokestatic(p(Py.class), "addTraceback", "(" + $throwable + $pyFrame + ")V"); inlineFinally(inFinally); code.aload(excLocal); - code.checkcast("java/lang/Throwable"); + code.checkcast(p(Throwable.class)); code.athrow(); code.label(finallyEnd); @@ -1310,9 +1321,9 @@ loadFrame(); - code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); + code.invokestatic(p(Py.class), "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); - int exc = code.getFinallyLocal("java/lang/Throwable"); + int exc = code.getFinallyLocal(p(Throwable.class)); code.astore(exc); if (node.getInternalOrelse() == null) { @@ -1355,7 +1366,7 @@ visit(node.getInternalValues().get(0)); for (int i = 1; i < node.getInternalValues().size(); i++) { code.dup(); - code.invokevirtual("org/python/core/PyObject", "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); switch (node.getInternalOp()) { case Or : code.ifne(end); @@ -1374,8 +1385,8 @@ @Override public Object visitCompare(Compare node) throws Exception { - int last = code.getLocal("org/python/core/PyObject"); - int result = code.getLocal("org/python/core/PyObject"); + int last = code.getLocal(p(PyObject.class)); + int result = code.getLocal(p(PyObject.class)); Label end = new Label(); visit(node.getInternalLeft()); @@ -1391,7 +1402,7 @@ visitCmpop(node.getInternalOps().get(i)); code.dup(); code.astore(result); - code.invokevirtual("org/python/core/PyObject", "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); code.ifeq(end); } @@ -1427,7 +1438,7 @@ case In: name = "_in"; break; case NotIn: name = "_notin"; break; } - code.invokevirtual("org/python/core/PyObject", name, "(" + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), name, "(" + $pyObj + ")" + $pyObj); } @Override @@ -1455,7 +1466,7 @@ if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) { name = "_truediv"; } - code.invokevirtual("org/python/core/PyObject", name, "(" + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), name, "(" + $pyObj + ")" + $pyObj); return null; } @@ -1469,7 +1480,7 @@ case UAdd: name = "__pos__"; break; case USub: name = "__neg__"; break; } - code.invokevirtual("org/python/core/PyObject", name, "()" + $pyObj); + code.invokevirtual(p(PyObject.class), name, "()" + $pyObj); return null; } @@ -1503,7 +1514,7 @@ if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) { name = "_itruediv"; } - code.invokevirtual("org/python/core/PyObject", name, "(" + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), name, "(" + $pyObj + ")" + $pyObj); code.freeLocal(target); temporary = storeTop(); @@ -1523,7 +1534,7 @@ } else { c.iconst_0(); } - c.anewarray("java/lang/String"); + c.anewarray(p(String.class)); int strings = c.getLocal("[Ljava/lang/String;"); c.astore(strings); if (names != null) { @@ -1545,31 +1556,31 @@ String name = getName(node.getInternalAttr()); visit(node.getInternalValue()); stackProduce(); code.ldc(name); - code.invokevirtual("org/python/core/PyObject", "__getattr__", "(" + $str + ")" + $pyObj); - loadThreadState(); stackProduce("org/python/core/ThreadState"); + code.invokevirtual(p(PyObject.class), "__getattr__", "(" + $str + ")" + $pyObj); + loadThreadState(); stackProduce(p(ThreadState.class)); switch (values.size()) { case 0: stackConsume(2); // target + ts - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + ")" + $pyObj); break; case 1: visit(values.get(0)); stackConsume(2); // target + ts - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); break; case 2: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackConsume(3); // target + ts + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); break; case 3: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackProduce(); visit(values.get(2)); stackConsume(4); // target + ts + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); break; case 4: visit(values.get(0)); stackProduce(); @@ -1577,14 +1588,14 @@ visit(values.get(2)); stackProduce(); visit(values.get(3)); stackConsume(5); // target + ts + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); break; default: int argArray = makeArray(values); code.aload(argArray); code.freeLocal(argArray); stackConsume(2); // target + ts - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj); break; } return null; @@ -1634,9 +1645,9 @@ stackConsume(3); // target + starargs + kwargs - code.invokevirtual("org/python/core/PyObject", "_callextra", "(" + $pyObjArr + $strArr + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "_callextra", "(" + $pyObjArr + $strArr + $pyObj + $pyObj + ")" + $pyObj); } else if (keys.size() > 0) { - loadThreadState(); stackProduce("org/python/core/ThreadState"); + loadThreadState(); stackProduce(p(ThreadState.class)); int argArray = makeArray(values); int strArray = makeStrings(code, keys); code.aload(argArray); @@ -1644,31 +1655,31 @@ code.freeLocal(argArray); code.freeLocal(strArray); stackConsume(2); // target + ts - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + $strArr + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObjArr + $strArr + ")" + $pyObj); } else { - loadThreadState(); stackProduce("org/python/core/ThreadState"); + loadThreadState(); stackProduce(p(ThreadState.class)); switch (values.size()) { case 0: stackConsume(2); // target + ts - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + ")" + $pyObj); break; case 1: visit(values.get(0)); stackConsume(2); // target + ts - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); break; case 2: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackConsume(3); // target + ts + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); break; case 3: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackProduce(); visit(values.get(2)); stackConsume(4); // target + ts + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); break; case 4: visit(values.get(0)); stackProduce(); @@ -1676,14 +1687,14 @@ visit(values.get(2)); stackProduce(); visit(values.get(3)); stackConsume(5); // target + ts + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); break; default: int argArray = makeArray(values); code.aload(argArray); code.freeLocal(argArray); stackConsume(2); // target + ts - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj);// freeArray(argArray); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj);// freeArray(argArray); break; } } @@ -1724,15 +1735,15 @@ switch (ctx) { case Del: - code.invokevirtual("org/python/core/PyObject", "__delslice__", "(" + $pyObj + $pyObj + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__delslice__", "(" + $pyObj + $pyObj + $pyObj + ")V"); return null; case Load: - code.invokevirtual("org/python/core/PyObject", "__getslice__", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__getslice__", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj); return null; case Param: case Store: code.aload(temporary); - code.invokevirtual("org/python/core/PyObject", "__setslice__", "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__setslice__", "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")V"); return null; } return null; @@ -1763,15 +1774,15 @@ switch (ctx) { case Del: - code.invokevirtual("org/python/core/PyObject", "__delitem__", "(" + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__delitem__", "(" + $pyObj + ")V"); return null; case Load: - code.invokevirtual("org/python/core/PyObject", "__getitem__", "(" + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__getitem__", "(" + $pyObj + ")" + $pyObj); return null; case Param: case Store: code.aload(value); - code.invokevirtual("org/python/core/PyObject", "__setitem__", "(" + $pyObj + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__setitem__", "(" + $pyObj + $pyObj + ")V"); return null; } return null; @@ -1786,10 +1797,10 @@ @Override public Object visitExtSlice(ExtSlice node) throws Exception { int dims = makeArray(node.getInternalDims()); - code.new_("org/python/core/PyTuple"); + code.new_(p(PyTuple.class)); code.dup(); code.aload(dims); - code.invokespecial("org/python/core/PyTuple", "<init>", "(" + $pyObjArr + ")V"); + code.invokespecial(p(PyTuple.class), "<init>", "(" + $pyObjArr + ")V"); freeArray(dims); return null; } @@ -1813,15 +1824,15 @@ switch (ctx) { case Del: - code.invokevirtual("org/python/core/PyObject", "__delattr__", "(" + $str + ")V"); + code.invokevirtual(p(PyObject.class), "__delattr__", "(" + $str + ")V"); return null; case Load: - code.invokevirtual("org/python/core/PyObject", "__getattr__", "(" + $str + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__getattr__", "(" + $str + ")" + $pyObj); return null; case Param: case Store: code.aload(temporary); - code.invokevirtual("org/python/core/PyObject", "__setattr__", "(" + $str + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__setattr__", "(" + $str + $pyObj + ")V"); return null; } return null; @@ -1830,7 +1841,7 @@ public Object seqSet(java.util.List<expr> nodes) throws Exception { code.aload(temporary); code.iconst(nodes.size()); - code.invokestatic("org/python/core/Py", "unpackSequence", "(" + $pyObj + "I)" + $pyObjArr); + code.invokestatic(p(Py.class), "unpackSequence", "(" + $pyObj + "I)" + $pyObjArr); int tmp = code.getLocal("[org/python/core/PyObject"); code.astore(tmp); @@ -1863,11 +1874,11 @@ int content = makeArray(node.getInternalElts()); - code.new_("org/python/core/PyTuple"); + code.new_(p(PyTuple.class)); code.dup(); code.aload(content); - code.invokespecial("org/python/core/PyTuple", "<init>", "(" + $pyObjArr + ")V"); + code.invokespecial(p(PyTuple.class), "<init>", "(" + $pyObjArr + ")V"); freeArray(content); return null; } @@ -1879,26 +1890,26 @@ int content = makeArray(node.getInternalElts()); - code.new_("org/python/core/PyList"); + code.new_(p(PyList.class)); code.dup(); code.aload(content); - code.invokespecial("org/python/core/PyList", "<init>", "(" + $pyObjArr + ")V"); + code.invokespecial(p(PyList.class), "<init>", "(" + $pyObjArr + ")V"); freeArray(content); return null; } @Override public Object visitListComp(ListComp node) throws Exception { - code.new_("org/python/core/PyList"); + code.new_(p(PyList.class)); code.dup(); - code.invokespecial("org/python/core/PyList", "<init>", "()V"); + code.invokespecial(p(PyList.class), "<init>", "()V"); code.dup(); code.ldc("append"); - code.invokevirtual("org/python/core/PyObject", "__getattr__", "(" + $str + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__getattr__", "(" + $str + ")" + $pyObj); String tmp_append ="_[" + node.getLine() + "_" + node.getCharPositionInLine() + "]"; @@ -1938,10 +1949,10 @@ } int content = makeArray(elts); - code.new_("org/python/core/PyDictionary"); + code.new_(p(PyDictionary.class)); code.dup(); code.aload(content); - code.invokespecial("org/python/core/PyDictionary", "<init>", "(" + $pyObjArr + ")V"); + code.invokespecial(p(PyDictionary.class), "<init>", "(" + $pyObjArr + ")V"); freeArray(content); return null; } @@ -1949,7 +1960,7 @@ @Override public Object visitRepr(Repr node) throws Exception { visit(node.getInternalValue()); - code.invokevirtual("org/python/core/PyObject", "__repr__", "()" + $pyStr); + code.invokevirtual(p(PyObject.class), "__repr__", "()" + $pyStr); return null; } @@ -1968,14 +1979,14 @@ int defaultsArray = makeArray(scope.ac.getDefaults()); - code.new_("org/python/core/PyFunction"); + code.new_(p(PyFunction.class)); code.dup(); code.aload(defaultsArray); code.freeLocal(defaultsArray); loadFrame(); - code.getfield("org/python/core/PyFrame", "f_globals", ci(PyObject.class)); + code.getfield(p(PyFrame.class), "f_globals", ci(PyObject.class)); code.swap(); @@ -1985,9 +1996,9 @@ false, false, node.getLine(), scope, cflags).get(code); if (!makeClosure(scope)) { - code.invokespecial("org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + ")V"); } else { - code.invokespecial("org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObjArr + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObjArr + ")V"); } return null; } @@ -1995,7 +2006,7 @@ @Override public Object visitEllipsis(Ellipsis node) throws Exception { - code.getstatic("org/python/core/Py", "Ellipsis", "Lorg/python/core/PyObject;"); + code.getstatic(p(Py.class), "Ellipsis", "Lorg/python/core/PyObject;"); return null; } @@ -2007,7 +2018,7 @@ int step = storeTop(); stackConsume(2); - code.new_("org/python/core/PySlice"); + code.new_(p(PySlice.class)); code.dup(); code.dup2_x2(); code.pop2(); @@ -2015,7 +2026,7 @@ code.aload(step); code.freeLocal(step); - code.invokespecial("org/python/core/PySlice", "<init>", "(" + $pyObj + $pyObj + $pyObj + ")V"); + code.invokespecial(p(PySlice.class), "<init>", "(" + $pyObj + $pyObj + $pyObj + ")V"); return null; } @@ -2044,9 +2055,9 @@ //Make class out of name, bases, and code if (!makeClosure(scope)) { - code.invokestatic("org/python/core/Py", "makeClass", "(" + $str + $pyObjArr + $pyCode + $pyObj + ")" + $pyObj); + code.invokestatic(p(Py.class), "makeClass", "(" + $str + $pyObjArr + $pyCode + $pyObj + ")" + $pyObj); } else { - code.invokestatic("org/python/core/Py", "makeClass", "(" + $str + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")" + $pyObj); + code.invokestatic(p(Py.class), "makeClass", "(" + $str + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")" + $pyObj); } applyDecorators(node.getInternalDecorator_list()); @@ -2087,7 +2098,7 @@ void emitGetGlobal(String name) throws Exception { code.ldc(name); - code.invokevirtual("org/python/core/PyFrame", "getglobal", "(" + $str + ")" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getglobal", "(" + $str + ")" + $pyObj); } @Override @@ -2119,26 +2130,26 @@ if (fast_locals) { if ((flags&ScopeInfo.CELL) != 0) { code.iconst(syminf.env_index); - code.invokevirtual("org/python/core/PyFrame", "getderef", "(I)" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getderef", "(I)" + $pyObj); return null; } if ((flags&ScopeInfo.BOUND) != 0) { code.iconst(syminf.locals_index); - code.invokevirtual("org/python/core/PyFrame", "getlocal", "(I)" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getlocal", "(I)" + $pyObj); return null; } } if ((flags&ScopeInfo.FREE) != 0 && (flags&ScopeInfo.BOUND) == 0) { code.iconst(syminf.env_index); - code.invokevirtual("org/python/core/PyFrame", "getderef", "(I)" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getderef", "(I)" + $pyObj); return null; } } code.ldc(name); - code.invokevirtual("org/python/core/PyFrame", "getname", "(" + $str + ")" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getname", "(" + $str + ")" + $pyObj); return null; case Param: @@ -2147,12 +2158,12 @@ if (syminf != null && (syminf.flags&ScopeInfo.GLOBAL) != 0) { code.ldc(name); code.aload(temporary); - code.invokevirtual("org/python/core/PyFrame", "setglobal", "(" + $str + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setglobal", "(" + $str + $pyObj + ")V"); } else { if (!fast_locals) { code.ldc(name); code.aload(temporary); - code.invokevirtual("org/python/core/PyFrame", "setlocal", "(" + $str + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setlocal", "(" + $str + $pyObj + ")V"); } else { if (syminf == null) { throw new ParseException("internal compiler error", node); @@ -2160,11 +2171,11 @@ if ((syminf.flags&ScopeInfo.CELL) != 0) { code.iconst(syminf.env_index); code.aload(temporary); - code.invokevirtual("org/python/core/PyFrame", "setderef", "(I" + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setderef", "(I" + $pyObj + ")V"); } else { code.iconst(syminf.locals_index); code.aload(temporary); - code.invokevirtual("org/python/core/PyFrame", "setlocal", "(I" + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setlocal", "(I" + $pyObj + ")V"); } } } @@ -2173,11 +2184,11 @@ loadFrame(); if (syminf != null && (syminf.flags&ScopeInfo.GLOBAL) != 0) { code.ldc(name); - code.invokevirtual("org/python/core/PyFrame", "delglobal", "(" + $str + ")V"); + code.invokevirtual(p(PyFrame.class), "delglobal", "(" + $str + ")V"); } else { if (!fast_locals) { code.ldc(name); - code.invokevirtual("org/python/core/PyFrame", "dellocal", "(" + $str + ")V"); + code.invokevirtual(p(PyFrame.class), "dellocal", "(" + $str + ")V"); } else { if (syminf == null) { throw new ParseException("internal compiler error", node); @@ -2187,7 +2198,7 @@ "' referenced in nested scope",true,node); } code.iconst(syminf.locals_index); - code.invokevirtual("org/python/core/PyFrame", "dellocal", "(I)V"); + code.invokevirtual(p(PyFrame.class), "dellocal", "(I)V"); } } return null; } @@ -2212,10 +2223,10 @@ setline(node); - code.new_("org/python/core/PyFunction"); + code.new_(p(PyFunction.class)); code.dup(); loadFrame(); - code.getfield("org/python/core/PyFrame", "f_globals", ci(PyObject.class)); + code.getfield(p(PyFrame.class), "f_globals", ci(PyObject.class)); ScopeInfo scope = module.getScopeInfo(node); @@ -2252,9 +2263,9 @@ code.aconst_null(); if (!makeClosure(scope)) { - code.invokespecial("org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + ")V"); } else { - code.invokespecial( "org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); + code.invokespecial( p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); } int genExp = storeTop(); @@ -2262,10 +2273,10 @@ code.aload(genExp); code.freeLocal(genExp); code.swap(); - code.invokevirtual("org/python/core/PyObject", "__iter__", "()Lorg/python/core/PyObject;"); + code.invokevirtual(p(PyObject.class), "__iter__", "()Lorg/python/core/PyObject;"); loadThreadState(); code.swap(); - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); freeArray(emptyArray); return null; @@ -2300,7 +2311,7 @@ // value = mgr.__enter__() loadThreadState(); code.invokeinterface(Type.getType(ContextManager.class).getInternalName(), __enter__.getName(), __enter__.getDescriptor()); - int value_tmp = code.getLocal("org/python/core/PyObject"); + int value_tmp = code.getLocal(p(PyObject.class)); code.astore(value_tmp); // exc = True # not necessary, since we don't exec finally if exception @@ -2358,7 +2369,7 @@ code.label(label_catch); loadFrame(); - code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); + code.invokestatic(p(Py.class), "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); code.aload(mgr_tmp); code.swap(); loadThreadState(); @@ -2371,8 +2382,8 @@ code.ifne(label_end); // raise // # The exception is swallowed if exit() returns true - code.invokestatic("org/python/core/Py", "makeException", "()Lorg/python/core/PyException;"); - code.checkcast("java/lang/Throwable"); + code.invokestatic(p(Py.class), "makeException", "()Lorg/python/core/PyException;"); + code.checkcast(p(Throwable.class)); code.athrow(); code.label(label_end); @@ -2435,7 +2446,7 @@ exceptionStarts.elementAt(i), exceptionEnds.elementAt(i), handlerStart, - "java/lang/Throwable"); + p(Throwable.class)); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-04 01:16:53
|
Revision: 6830 http://jython.svn.sourceforge.net/jython/?rev=6830&view=rev Author: fwierzbicki Date: 2009-10-04 01:16:45 +0000 (Sun, 04 Oct 2009) Log Message: ----------- Converted invokespecial and getfield to CodegenUtils. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-03 20:34:59 UTC (rev 6829) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-04 01:16:45 UTC (rev 6830) @@ -78,6 +78,7 @@ import org.python.core.ContextManager; import org.python.core.imp; import org.python.core.Py; +import org.python.core.PyCode; import org.python.core.PyComplex; import org.python.core.PyDictionary; import org.python.core.PyException; @@ -219,18 +220,18 @@ private void saveAugTmps(PythonTree node, int count) throws Exception { if (count >= 4) { - augtmp4 = code.getLocal("Lorg/python/core/PyObject;"); + augtmp4 = code.getLocal(ci(PyObject.class)); code.astore(augtmp4); } if (count >= 3) { - augtmp3 = code.getLocal("Lorg/python/core/PyObject;"); + augtmp3 = code.getLocal(ci(PyObject.class)); code.astore(augtmp3); } if (count >= 2) { - augtmp2 = code.getLocal("Lorg/python/core/PyObject;"); + augtmp2 = code.getLocal(ci(PyObject.class)); code.astore(augtmp2); } - augtmp1 = code.getLocal("Lorg/python/core/PyObject;"); + augtmp1 = code.getLocal(ci(PyObject.class)); code.astore(augtmp1); code.aload(augtmp1); @@ -439,9 +440,9 @@ getDocString(node.getInternalBody()); if (!makeClosure(scope)) { - code.invokespecial(p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject.class)); } else { - code.invokespecial( p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject.class, PyObject[].class)); } applyDecorators(node.getInternalDecorator_list()); @@ -1184,7 +1185,7 @@ if (handler.getInternalName() != null) { code.aload(exc); - code.getfield(p(PyException.class), "value", "Lorg/python/core/PyObject;"); + code.getfield(p(PyException.class), "value", ci(PyObject.class)); set(handler.getInternalName()); } @@ -1800,7 +1801,7 @@ code.new_(p(PyTuple.class)); code.dup(); code.aload(dims); - code.invokespecial(p(PyTuple.class), "<init>", "(" + $pyObjArr + ")V"); + code.invokespecial(p(PyTuple.class), "<init>", sig(Void.TYPE, PyObject[].class)); freeArray(dims); return null; } @@ -1878,7 +1879,7 @@ code.dup(); code.aload(content); - code.invokespecial(p(PyTuple.class), "<init>", "(" + $pyObjArr + ")V"); + code.invokespecial(p(PyTuple.class), "<init>", sig(Void.TYPE, PyObject[].class)); freeArray(content); return null; } @@ -1893,7 +1894,7 @@ code.new_(p(PyList.class)); code.dup(); code.aload(content); - code.invokespecial(p(PyList.class), "<init>", "(" + $pyObjArr + ")V"); + code.invokespecial(p(PyList.class), "<init>", sig(Void.TYPE, PyObject[].class)); freeArray(content); return null; } @@ -1903,7 +1904,7 @@ code.new_(p(PyList.class)); code.dup(); - code.invokespecial(p(PyList.class), "<init>", "()V"); + code.invokespecial(p(PyList.class), "<init>", sig(Void.TYPE)); code.dup(); @@ -1952,7 +1953,7 @@ code.new_(p(PyDictionary.class)); code.dup(); code.aload(content); - code.invokespecial(p(PyDictionary.class), "<init>", "(" + $pyObjArr + ")V"); + code.invokespecial(p(PyDictionary.class), "<init>", sig(Void.TYPE, PyObject[].class)); freeArray(content); return null; } @@ -1996,9 +1997,9 @@ false, false, node.getLine(), scope, cflags).get(code); if (!makeClosure(scope)) { - code.invokespecial(p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class)); } else { - code.invokespecial(p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObjArr + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject[].class)); } return null; } @@ -2006,7 +2007,7 @@ @Override public Object visitEllipsis(Ellipsis node) throws Exception { - code.getstatic(p(Py.class), "Ellipsis", "Lorg/python/core/PyObject;"); + code.getstatic(p(Py.class), "Ellipsis", ci(PyObject.class)); return null; } @@ -2026,7 +2027,7 @@ code.aload(step); code.freeLocal(step); - code.invokespecial(p(PySlice.class), "<init>", "(" + $pyObj + $pyObj + $pyObj + ")V"); + code.invokespecial(p(PySlice.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject.class, PyObject.class)); return null; } @@ -2263,9 +2264,9 @@ code.aconst_null(); if (!makeClosure(scope)) { - code.invokespecial(p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject.class)); } else { - code.invokespecial( p(PyFunction.class), "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject.class, PyObject[].class)); } int genExp = storeTop(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-04 03:14:43
|
Revision: 6831 http://jython.svn.sourceforge.net/jython/?rev=6831&view=rev Author: fwierzbicki Date: 2009-10-04 02:42:47 +0000 (Sun, 04 Oct 2009) Log Message: ----------- Fix all invokevirtual to use sig() -- fix some invokespecial lines that went over 100 chars as per coding conventions. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-04 01:16:45 UTC (rev 6830) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-04 02:42:47 UTC (rev 6831) @@ -197,7 +197,7 @@ code.setline(line); loadFrame(); code.iconst(line); - code.invokevirtual(p(PyFrame.class), "setline", "(I)V"); + code.invokevirtual(p(PyFrame.class), "setline", sig(Void.TYPE, Integer.TYPE)); } } @@ -319,7 +319,8 @@ loadFrame(); code.ldc("__doc__"); visit(((Expr) suite.getInternalBody().get(0)).getInternalValue()); - code.invokevirtual(p(PyFrame.class), "setglobal", "(" +$str + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setglobal", sig(Void.TYPE, String.class, + PyObject.class)); } traverse(suite); return null; @@ -402,7 +403,7 @@ } SymInfo symInfo = upTbl.get(scope.freevars.elementAt(i)); code.iconst(symInfo.env_index); - code.invokevirtual(p(PyFrame.class), "getclosure", "(I)" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getclosure", sig(PyObject.class, Integer.TYPE)); code.aastore(); } @@ -440,9 +441,11 @@ getDocString(node.getInternalBody()); if (!makeClosure(scope)) { - code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject.class)); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, + PyObject[].class, PyCode.class, PyObject.class)); } else { - code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject.class, PyObject[].class)); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, + PyObject[].class, PyCode.class, PyObject.class, PyObject[].class)); } applyDecorators(node.getInternalDecorator_list()); @@ -461,7 +464,8 @@ stackConsume(); loadThreadState(); code.aload(res); - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject.class)); code.astore(res); } code.aload(res); @@ -607,7 +611,7 @@ restoreStack(stackState); loadFrame(); - code.invokevirtual(p(PyFrame.class), "getGeneratorInput", "()" + $obj); + code.invokevirtual(p(PyFrame.class), "getGeneratorInput", sig(Object.class)); code.dup(); code.instanceof_(p(PyException.class)); Label done2 = new Label(); @@ -956,7 +960,7 @@ loadFrame(); emitGetGlobal("__debug__"); - code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", sig(Boolean.TYPE)); code.ifeq(end_of_assert); @@ -964,7 +968,7 @@ then the assertion succeeded, the message portion should not be processed. Otherwise, the message will be processed. */ visit(node.getInternalTest()); - code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", sig(Boolean.TYPE)); /* If evaluation is false, then branch to end of method */ code.ifne(end_of_assert); @@ -1001,7 +1005,7 @@ setline(node.getInternalTest()); visit(node.getInternalTest()); - code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", sig(Boolean.TYPE)); code.ifeq(end_of_suite); @@ -1038,7 +1042,7 @@ Label end_of_else = new Label(); visit(node.getInternalTest()); - code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", sig(Boolean.TYPE)); code.ifeq(end_of_else); visit(node.getInternalBody()); @@ -1086,7 +1090,7 @@ //Do test visit(node.getInternalTest()); - code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", sig(Boolean.TYPE)); code.ifne(start_loop); finishLoop(savebcf); @@ -1118,7 +1122,7 @@ int expr_tmp = code.getLocal(p(PyObject.class)); //set up the loop iterator - code.invokevirtual(p(PyObject.class), "__iter__", "()Lorg/python/core/PyObject;"); + code.invokevirtual(p(PyObject.class), "__iter__", sig(PyObject.class)); code.astore(iter_tmp); //do check at end of loop. Saves one opcode ;-) @@ -1137,7 +1141,7 @@ setline(node); //get the next element from the list code.aload(iter_tmp); - code.invokevirtual(p(PyObject.class), "__iternext__", "()" + $pyObj); + code.invokevirtual(p(PyObject.class), "__iternext__", sig(PyObject.class)); code.astore(expr_tmp); code.aload(expr_tmp); @@ -1174,7 +1178,8 @@ code.aload(exc); //get specific exception visit(handler.getInternalType()); - code.invokevirtual(p(PyException.class), "match", "(" + $pyObj + ")Z"); + code.invokevirtual(p(PyException.class), "match", sig(Boolean.TYPE, + PyObject.class)); code.ifeq(end_of_self); } else { if (i != node.getInternalHandlers().size()-1) { @@ -1367,7 +1372,7 @@ visit(node.getInternalValues().get(0)); for (int i = 1; i < node.getInternalValues().size(); i++) { code.dup(); - code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", sig(Boolean.TYPE)); switch (node.getInternalOp()) { case Or : code.ifne(end); @@ -1403,7 +1408,7 @@ visitCmpop(node.getInternalOps().get(i)); code.dup(); code.astore(result); - code.invokevirtual(p(PyObject.class), "__nonzero__", "()Z"); + code.invokevirtual(p(PyObject.class), "__nonzero__", sig(Boolean.TYPE)); code.ifeq(end); } @@ -1439,7 +1444,7 @@ case In: name = "_in"; break; case NotIn: name = "_notin"; break; } - code.invokevirtual(p(PyObject.class), name, "(" + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), name, sig(PyObject.class, PyObject.class)); } @Override @@ -1467,7 +1472,7 @@ if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) { name = "_truediv"; } - code.invokevirtual(p(PyObject.class), name, "(" + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), name, sig(PyObject.class, PyObject.class)); return null; } @@ -1481,7 +1486,7 @@ case UAdd: name = "__pos__"; break; case USub: name = "__neg__"; break; } - code.invokevirtual(p(PyObject.class), name, "()" + $pyObj); + code.invokevirtual(p(PyObject.class), name, sig(PyObject.class)); return null; } @@ -1515,7 +1520,7 @@ if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) { name = "_itruediv"; } - code.invokevirtual(p(PyObject.class), name, "(" + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), name, sig(PyObject.class, PyObject.class)); code.freeLocal(target); temporary = storeTop(); @@ -1557,31 +1562,34 @@ String name = getName(node.getInternalAttr()); visit(node.getInternalValue()); stackProduce(); code.ldc(name); - code.invokevirtual(p(PyObject.class), "__getattr__", "(" + $str + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__getattr__", sig(PyObject.class, String.class)); loadThreadState(); stackProduce(p(ThreadState.class)); switch (values.size()) { case 0: stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class)); break; case 1: visit(values.get(0)); stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, + PyObject.class)); break; case 2: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackConsume(3); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, + PyObject.class, PyObject.class)); break; case 3: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackProduce(); visit(values.get(2)); stackConsume(4); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, + PyObject.class, PyObject.class, PyObject.class)); break; case 4: visit(values.get(0)); stackProduce(); @@ -1589,14 +1597,16 @@ visit(values.get(2)); stackProduce(); visit(values.get(3)); stackConsume(5); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, + PyObject.class, PyObject.class, PyObject.class, PyObject.class)); break; default: int argArray = makeArray(values); code.aload(argArray); code.freeLocal(argArray); stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, + PyObject[].class)); break; } return null; @@ -1646,7 +1656,8 @@ stackConsume(3); // target + starargs + kwargs - code.invokevirtual(p(PyObject.class), "_callextra", "(" + $pyObjArr + $strArr + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "_callextra", sig(PyObject.class, + PyObject[].class, String[].class, PyObject.class, PyObject.class)); } else if (keys.size() > 0) { loadThreadState(); stackProduce(p(ThreadState.class)); int argArray = makeArray(values); @@ -1656,31 +1667,36 @@ code.freeLocal(argArray); code.freeLocal(strArray); stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObjArr + $strArr + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, + PyObject[].class, String[].class)); } else { loadThreadState(); stackProduce(p(ThreadState.class)); switch (values.size()) { case 0: stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class)); break; case 1: visit(values.get(0)); stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject.class)); break; case 2: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackConsume(3); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject.class, PyObject.class)); break; case 3: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackProduce(); visit(values.get(2)); stackConsume(4); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject.class, PyObject.class, PyObject.class)); break; case 4: visit(values.get(0)); stackProduce(); @@ -1688,14 +1704,17 @@ visit(values.get(2)); stackProduce(); visit(values.get(3)); stackConsume(5); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject.class, PyObject.class, PyObject.class, + PyObject.class)); break; default: int argArray = makeArray(values); code.aload(argArray); code.freeLocal(argArray); stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj);// freeArray(argArray); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject[].class)); break; } } @@ -1736,15 +1755,18 @@ switch (ctx) { case Del: - code.invokevirtual(p(PyObject.class), "__delslice__", "(" + $pyObj + $pyObj + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__delslice__", sig(Void.TYPE, PyObject.class, + PyObject.class, PyObject.class)); return null; case Load: - code.invokevirtual(p(PyObject.class), "__getslice__", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__getslice__", sig(PyObject.class, + PyObject.class, PyObject.class, PyObject.class)); return null; case Param: case Store: code.aload(temporary); - code.invokevirtual(p(PyObject.class), "__setslice__", "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__setslice__", sig(Void.TYPE, PyObject.class, + PyObject.class, PyObject.class, PyObject.class)); return null; } return null; @@ -1775,15 +1797,16 @@ switch (ctx) { case Del: - code.invokevirtual(p(PyObject.class), "__delitem__", "(" + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__delitem__", sig(Void.TYPE, PyObject.class)); return null; case Load: - code.invokevirtual(p(PyObject.class), "__getitem__", "(" + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__getitem__", sig(PyObject.class, PyObject.class)); return null; case Param: case Store: code.aload(value); - code.invokevirtual(p(PyObject.class), "__setitem__", "(" + $pyObj + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__setitem__", sig(Void.TYPE, PyObject.class, + PyObject.class)); return null; } return null; @@ -1825,15 +1848,16 @@ switch (ctx) { case Del: - code.invokevirtual(p(PyObject.class), "__delattr__", "(" + $str + ")V"); + code.invokevirtual(p(PyObject.class), "__delattr__", sig(Void.TYPE, String.class)); return null; case Load: - code.invokevirtual(p(PyObject.class), "__getattr__", "(" + $str + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__getattr__", sig(PyObject.class, String.class)); return null; case Param: case Store: code.aload(temporary); - code.invokevirtual(p(PyObject.class), "__setattr__", "(" + $str + $pyObj + ")V"); + code.invokevirtual(p(PyObject.class), "__setattr__", sig(Void.TYPE, String.class, + PyObject.class)); return null; } return null; @@ -1910,8 +1934,7 @@ code.ldc("append"); - code.invokevirtual(p(PyObject.class), "__getattr__", "(" + $str + ")" + $pyObj); - + code.invokevirtual(p(PyObject.class), "__getattr__", sig(PyObject.class, String.class)); String tmp_append ="_[" + node.getLine() + "_" + node.getCharPositionInLine() + "]"; set(new Name(node, tmp_append, expr_contextType.Store)); @@ -1961,7 +1984,7 @@ @Override public Object visitRepr(Repr node) throws Exception { visit(node.getInternalValue()); - code.invokevirtual(p(PyObject.class), "__repr__", "()" + $pyStr); + code.invokevirtual(p(PyObject.class), "__repr__", sig(PyString.class)); return null; } @@ -1997,9 +2020,11 @@ false, false, node.getLine(), scope, cflags).get(code); if (!makeClosure(scope)) { - code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class)); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, + PyObject[].class, PyCode.class)); } else { - code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject[].class)); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, + PyObject[].class, PyCode.class, PyObject[].class)); } return null; } @@ -2027,7 +2052,8 @@ code.aload(step); code.freeLocal(step); - code.invokespecial(p(PySlice.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject.class, PyObject.class)); + code.invokespecial(p(PySlice.class), "<init>", sig(Void.TYPE, PyObject.class, + PyObject.class, PyObject.class)); return null; } @@ -2099,7 +2125,7 @@ void emitGetGlobal(String name) throws Exception { code.ldc(name); - code.invokevirtual(p(PyFrame.class), "getglobal", "(" + $str + ")" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getglobal", sig(PyObject.class, String.class)); } @Override @@ -2131,26 +2157,27 @@ if (fast_locals) { if ((flags&ScopeInfo.CELL) != 0) { code.iconst(syminf.env_index); - code.invokevirtual(p(PyFrame.class), "getderef", "(I)" + $pyObj); - + code.invokevirtual(p(PyFrame.class), "getderef", sig(PyObject.class, + Integer.TYPE)); return null; } if ((flags&ScopeInfo.BOUND) != 0) { code.iconst(syminf.locals_index); - code.invokevirtual(p(PyFrame.class), "getlocal", "(I)" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getlocal", sig(PyObject.class, + Integer.TYPE)); return null; } } if ((flags&ScopeInfo.FREE) != 0 && (flags&ScopeInfo.BOUND) == 0) { code.iconst(syminf.env_index); - code.invokevirtual(p(PyFrame.class), "getderef", "(I)" + $pyObj); - + code.invokevirtual(p(PyFrame.class), "getderef", sig(PyObject.class, + Integer.TYPE)); return null; } } code.ldc(name); - code.invokevirtual(p(PyFrame.class), "getname", "(" + $str + ")" + $pyObj); + code.invokevirtual(p(PyFrame.class), "getname", sig(PyObject.class, String.class)); return null; case Param: @@ -2159,12 +2186,14 @@ if (syminf != null && (syminf.flags&ScopeInfo.GLOBAL) != 0) { code.ldc(name); code.aload(temporary); - code.invokevirtual(p(PyFrame.class), "setglobal", "(" + $str + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setglobal", sig(Void.TYPE, String.class, + PyObject.class)); } else { if (!fast_locals) { code.ldc(name); code.aload(temporary); - code.invokevirtual(p(PyFrame.class), "setlocal", "(" + $str + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setlocal", sig(Void.TYPE, String.class, + PyObject.class)); } else { if (syminf == null) { throw new ParseException("internal compiler error", node); @@ -2172,11 +2201,13 @@ if ((syminf.flags&ScopeInfo.CELL) != 0) { code.iconst(syminf.env_index); code.aload(temporary); - code.invokevirtual(p(PyFrame.class), "setderef", "(I" + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setderef", sig(Void.TYPE, + Integer.TYPE, PyObject.class)); } else { code.iconst(syminf.locals_index); code.aload(temporary); - code.invokevirtual(p(PyFrame.class), "setlocal", "(I" + $pyObj + ")V"); + code.invokevirtual(p(PyFrame.class), "setlocal", sig(Void.TYPE, + Integer.TYPE, PyObject.class)); } } } @@ -2185,11 +2216,11 @@ loadFrame(); if (syminf != null && (syminf.flags&ScopeInfo.GLOBAL) != 0) { code.ldc(name); - code.invokevirtual(p(PyFrame.class), "delglobal", "(" + $str + ")V"); + code.invokevirtual(p(PyFrame.class), "delglobal", sig(Void.TYPE, String.class)); } else { if (!fast_locals) { code.ldc(name); - code.invokevirtual(p(PyFrame.class), "dellocal", "(" + $str + ")V"); + code.invokevirtual(p(PyFrame.class), "dellocal", sig(Void.TYPE, String.class)); } else { if (syminf == null) { throw new ParseException("internal compiler error", node); @@ -2199,7 +2230,7 @@ "' referenced in nested scope",true,node); } code.iconst(syminf.locals_index); - code.invokevirtual(p(PyFrame.class), "dellocal", "(I)V"); + code.invokevirtual(p(PyFrame.class), "dellocal", sig(Void.TYPE, Integer.TYPE)); } } return null; } @@ -2264,9 +2295,11 @@ code.aconst_null(); if (!makeClosure(scope)) { - code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject.class)); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, + PyObject[].class, PyCode.class, PyObject.class)); } else { - code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, PyObject[].class, PyCode.class, PyObject.class, PyObject[].class)); + code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, + PyObject[].class, PyCode.class, PyObject.class, PyObject[].class)); } int genExp = storeTop(); @@ -2274,10 +2307,10 @@ code.aload(genExp); code.freeLocal(genExp); code.swap(); - code.invokevirtual(p(PyObject.class), "__iter__", "()Lorg/python/core/PyObject;"); + code.invokevirtual(p(PyObject.class), "__iter__", sig(PyObject.class)); loadThreadState(); code.swap(); - code.invokevirtual(p(PyObject.class), "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, PyObject.class)); freeArray(emptyArray); return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-04 14:11:05
|
Revision: 6832 http://jython.svn.sourceforge.net/jython/?rev=6832&view=rev Author: fwierzbicki Date: 2009-10-04 14:10:58 +0000 (Sun, 04 Oct 2009) Log Message: ----------- Use sig() for invokestatic calls. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-04 02:42:47 UTC (rev 6831) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-04 14:10:58 UTC (rev 6832) @@ -370,7 +370,7 @@ public void freeArray(int array) { code.aload(array); code.aconst_null(); - code.invokestatic(p(Arrays.class), "fill", "(" + $objArr + $obj + ")V"); + code.invokestatic(p(Arrays.class), "fill", sig(Void.TYPE, Object[].class, Object.class)); code.freeLocal(array); } @@ -479,7 +479,7 @@ visit(node.getInternalValue()); if (print_results) { - code.invokestatic(p(Py.class), "printResult", "(" + $pyObj + ")V"); + code.invokestatic(p(Py.class), "printResult", sig(Void.TYPE, PyObject.class)); } else { code.pop(); } @@ -514,9 +514,9 @@ if (node.getInternalValues() == null || node.getInternalValues().size() == 0) { if (node.getInternalDest() != null) { code.aload(tmp); - code.invokestatic(p(Py.class), "printlnv", "(" + $pyObj + ")V"); + code.invokestatic(p(Py.class), "printlnv", sig(Void.TYPE, PyObject.class)); } else { - code.invokestatic(p(Py.class), "println", "()V"); + code.invokestatic(p(Py.class), "println", sig(Void.TYPE)); } } else { for (int i = 0; i < node.getInternalValues().size(); i++) { @@ -524,16 +524,19 @@ code.aload(tmp); visit(node.getInternalValues().get(i)); if (node.getInternalNl() && i == node.getInternalValues().size() - 1) { - code.invokestatic(p(Py.class), "println", "(" + $pyObj + $pyObj + ")V"); + code.invokestatic(p(Py.class), "println", sig(Void.TYPE, PyObject.class, + PyObject.class)); } else { - code.invokestatic(p(Py.class), "printComma", "(" + $pyObj + $pyObj + ")V"); + code.invokestatic(p(Py.class), "printComma", sig(Void.TYPE, PyObject.class, + PyObject.class)); } } else { visit(node.getInternalValues().get(i)); if (node.getInternalNl() && i == node.getInternalValues().size() - 1) { - code.invokestatic(p(Py.class), "println", "(" + $pyObj + ")V"); + code.invokestatic(p(Py.class), "println", sig(Void.TYPE, PyObject.class)); } else { - code.invokestatic(p(Py.class), "printComma", "(" + $pyObj + ")V"); + code.invokestatic(p(Py.class), "printComma", sig(Void.TYPE, + PyObject.class)); } } @@ -811,16 +814,18 @@ if (node.getInternalInst() != null) { visit(node.getInternalInst()); stackProduce(); } if (node.getInternalTback() != null) { visit(node.getInternalTback()); stackProduce(); } if (node.getInternalType() == null) { - code.invokestatic(p(Py.class), "makeException", "()" + $pyExc); + code.invokestatic(p(Py.class), "makeException", sig(PyException.class)); } else if (node.getInternalInst() == null) { stackConsume(); - code.invokestatic(p(Py.class), "makeException", "(" + $pyObj + ")" + $pyExc); + code.invokestatic(p(Py.class), "makeException", sig(PyException.class, PyObject.class)); } else if (node.getInternalTback() == null) { stackConsume(2); - code.invokestatic(p(Py.class), "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); + code.invokestatic(p(Py.class), "makeException", sig(PyException.class, PyObject.class, + PyObject.class)); } else { stackConsume(3); - code.invokestatic(p(Py.class), "makeException", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyExc); + code.invokestatic(p(Py.class), "makeException", sig(PyException.class, PyObject.class, + PyObject.class, PyObject.class)); } code.athrow(); return Exit; @@ -836,7 +841,8 @@ asname = a.getInternalAsname(); code.ldc(name); loadFrame(); - code.invokestatic(p(imp.class), "importOneAs", "(" + $str + $pyFrame + ")" + $pyObj); + code.invokestatic(p(imp.class), "importOneAs", sig(PyObject.class, String.class, + PyFrame.class)); } else { String name = a.getInternalName(); asname = name; @@ -844,7 +850,8 @@ asname = asname.substring(0, asname.indexOf('.')); code.ldc(name); loadFrame(); - code.invokestatic(p(imp.class), "importOne", "(" + $str + $pyFrame + ")" + $pyObj); + code.invokestatic(p(imp.class), "importOne", sig(PyObject.class, String.class, + PyFrame.class)); } set(new Name(a, asname, expr_contextType.Store)); } @@ -882,7 +889,8 @@ } loadFrame(); - code.invokestatic(p(imp.class), "importAll", "(" + $str + $pyFrame + ")V"); + code.invokestatic(p(imp.class), "importAll", sig(Void.TYPE, String.class, + PyFrame.class)); } else { java.util.List<String> fromNames = new ArrayList<String>();//[names.size()]; java.util.List<String> asnames = new ArrayList<String>();//[names.size()]; @@ -907,7 +915,8 @@ } else { code.iconst(node.getInternalLevel()); } - code.invokestatic(p(imp.class), "importFrom", "(" + $str + $strArr + $pyFrame + "I" + ")" + $pyObjArr); + code.invokestatic(p(imp.class), "importFrom", sig(PyObject[].class, String.class, + String[].class, PyFrame.class, Integer.TYPE)); int tmp = storeTop(); for (int i = 0; i < aliases.size(); i++) { code.aload(tmp); @@ -947,7 +956,8 @@ //do the real work here stackConsume(3); - code.invokestatic(p(Py.class), "exec", "(" + $pyObj + $pyObj + $pyObj + ")V"); + code.invokestatic(p(Py.class), "exec", sig(Void.TYPE, PyObject.class, PyObject.class, + PyObject.class)); return null; } @@ -986,8 +996,8 @@ code.swap(); // The type is the first argument, but the message could be a yield - code.invokestatic(p(Py.class), "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); - + code.invokestatic(p(Py.class), "makeException", sig(PyException.class, PyObject.class, + PyObject.class)); /* Raise assertion error. Only executes this logic if assertion failed */ code.athrow(); @@ -1246,7 +1256,8 @@ code.aload(excLocal); loadFrame(); - code.invokestatic(p(Py.class), "addTraceback", "(" + $throwable + $pyFrame + ")V"); + code.invokestatic(p(Py.class), "addTraceback", sig(Void.TYPE, Throwable.class, + PyFrame.class)); inlineFinally(inFinally); code.aload(excLocal); @@ -1327,7 +1338,8 @@ loadFrame(); - code.invokestatic(p(Py.class), "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); + code.invokestatic(p(Py.class), "setException", sig(PyException.class, Throwable.class, + PyFrame.class)); int exc = code.getFinallyLocal(p(Throwable.class)); code.astore(exc); @@ -1866,7 +1878,8 @@ public Object seqSet(java.util.List<expr> nodes) throws Exception { code.aload(temporary); code.iconst(nodes.size()); - code.invokestatic(p(Py.class), "unpackSequence", "(" + $pyObj + "I)" + $pyObjArr); + code.invokestatic(p(Py.class), "unpackSequence", sig(PyObject[].class, PyObject.class, + Integer.TYPE)); int tmp = code.getLocal("[org/python/core/PyObject"); code.astore(tmp); @@ -2082,9 +2095,11 @@ //Make class out of name, bases, and code if (!makeClosure(scope)) { - code.invokestatic(p(Py.class), "makeClass", "(" + $str + $pyObjArr + $pyCode + $pyObj + ")" + $pyObj); + code.invokestatic(p(Py.class), "makeClass", sig(PyObject.class, String.class, + PyObject[].class, PyCode.class, PyObject.class)); } else { - code.invokestatic(p(Py.class), "makeClass", "(" + $str + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")" + $pyObj); + code.invokestatic(p(Py.class), "makeClass", sig(PyObject.class, String.class, + PyObject[].class, PyCode.class, PyObject.class, PyObject[].class)); } applyDecorators(node.getInternalDecorator_list()); @@ -2327,15 +2342,20 @@ final Label label_catch = new Label(); final Label label_end = new Label(); - final Method contextGuard_getManager = Method.getMethod("org.python.core.ContextManager getManager (org.python.core.PyObject)"); - final Method __enter__ = Method.getMethod("org.python.core.PyObject __enter__ (org.python.core.ThreadState)"); - final Method __exit__ = Method.getMethod("boolean __exit__ (org.python.core.ThreadState,org.python.core.PyException)"); + final Method contextGuard_getManager = Method.getMethod( + "org.python.core.ContextManager getManager (org.python.core.PyObject)"); + final Method __enter__ = Method.getMethod( + "org.python.core.PyObject __enter__ (org.python.core.ThreadState)"); + final Method __exit__ = Method.getMethod( + "boolean __exit__ (org.python.core.ThreadState,org.python.core.PyException)"); // mgr = (EXPR) visit(node.getInternalContext_expr()); - // wrap the manager with the ContextGuard (or get it directly if it supports the ContextManager interface) - code.invokestatic(Type.getType(ContextGuard.class).getInternalName(), contextGuard_getManager.getName(), contextGuard_getManager.getDescriptor()); + // wrap the manager with the ContextGuard (or get it directly if it + // supports the ContextManager interface) + code.invokestatic(Type.getType(ContextGuard.class).getInternalName(), + contextGuard_getManager.getName(), contextGuard_getManager.getDescriptor()); code.dup(); @@ -2344,7 +2364,8 @@ // value = mgr.__enter__() loadThreadState(); - code.invokeinterface(Type.getType(ContextManager.class).getInternalName(), __enter__.getName(), __enter__.getDescriptor()); + code.invokeinterface(Type.getType(ContextManager.class).getInternalName(), + __enter__.getName(), __enter__.getDescriptor()); int value_tmp = code.getLocal(p(PyObject.class)); code.astore(value_tmp); @@ -2403,12 +2424,14 @@ code.label(label_catch); loadFrame(); - code.invokestatic(p(Py.class), "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); + code.invokestatic(p(Py.class), "setException", sig(PyException.class, Throwable.class, + PyFrame.class)); code.aload(mgr_tmp); code.swap(); loadThreadState(); code.swap(); - code.invokeinterface(Type.getType(ContextManager.class).getInternalName(), __exit__.getName(), __exit__.getDescriptor()); + code.invokeinterface(Type.getType(ContextManager.class).getInternalName(), + __exit__.getName(), __exit__.getDescriptor()); // # The exceptional case is handled here // exc = False # implicit @@ -2416,7 +2439,7 @@ code.ifne(label_end); // raise // # The exception is swallowed if exit() returns true - code.invokestatic(p(Py.class), "makeException", "()Lorg/python/core/PyException;"); + code.invokestatic(p(Py.class), "makeException", sig(PyException.class)); code.checkcast(p(Throwable.class)); code.athrow(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-04 14:39:46
|
Revision: 6833 http://jython.svn.sourceforge.net/jython/?rev=6833&view=rev Author: fwierzbicki Date: 2009-10-04 14:39:40 +0000 (Sun, 04 Oct 2009) Log Message: ----------- Finish up CodeCompiler conversion to CodegenUtils. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-04 14:10:58 UTC (rev 6832) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-04 14:39:40 UTC (rev 6833) @@ -183,7 +183,7 @@ } private void loadf_back() throws Exception { - code.getfield(p(PyFrame.class), "f_back", $pyFrame); + code.getfield(p(PyFrame.class), "f_back", ci(PyFrame.class)); } public int storeTop() throws Exception { @@ -283,7 +283,7 @@ loadFrame(); code.iconst(scope.max_with_count); code.anewarray(p(PyObject.class)); - code.putfield(p(PyFrame.class), "f_exits", $pyObjArr); + code.putfield(p(PyFrame.class), "f_exits", ci(PyObject[].class)); } Object exit = visit(node); @@ -345,9 +345,9 @@ else n = nodes.size(); - int array = code.getLocal("[Lorg/python/core/PyObject;"); + int array = code.getLocal(ci(PyObject[].class)); if (n == 0) { - code.getstatic(p(Py.class), "EmptyObjects", $pyObjArr); + code.getstatic(p(Py.class), "EmptyObjects", ci(PyObject[].class)); code.astore(array); } else { code.iconst(n); @@ -389,7 +389,7 @@ int n = scope.freevars.size(); if (n == 0) return false; - int tmp = code.getLocal("[Lorg/python/core/PyObject;"); + int tmp = code.getLocal(ci(PyObject[].class)); code.iconst(n); code.anewarray(p(PyObject.class)); code.astore(tmp); @@ -647,7 +647,7 @@ private int saveStack() throws Exception { if (stack.size() > 0) { - int array = code.getLocal("[Ljava/lang/Object;"); + int array = code.getLocal(ci(Object[].class)); code.iconst(stack.size()); code.anewarray(p(Object.class)); code.astore(array); @@ -700,9 +700,9 @@ Vector<String> v = code.getActiveLocals(); loadFrame(); - code.getfield(p(PyFrame.class), "f_savedlocals", "[Ljava/lang/Object;"); + code.getfield(p(PyFrame.class), "f_savedlocals", ci(Object[].class)); - int locals = code.getLocal("[Ljava/lang/Object;"); + int locals = code.getLocal(ci(Object[].class)); code.astore(locals); for (int i = 0; i < v.size(); i++) { @@ -751,7 +751,7 @@ Vector<String> v = code.getActiveLocals(); code.iconst(v.size()); code.anewarray(p(Object.class)); - int locals = code.getLocal("[Ljava/lang/Object;"); + int locals = code.getLocal(ci(Object[].class)); code.astore(locals); for (int i = 0; i < v.size(); i++) { @@ -770,7 +770,7 @@ loadFrame(); code.aload(locals); - code.putfield(p(PyFrame.class), "f_savedlocals", "[Ljava/lang/Object;"); + code.putfield(p(PyFrame.class), "f_savedlocals", ci(Object[].class)); code.freeLocal(locals); } @@ -1553,7 +1553,7 @@ c.iconst_0(); } c.anewarray(p(String.class)); - int strings = c.getLocal("[Ljava/lang/String;"); + int strings = c.getLocal(ci(String[].class)); c.astore(strings); if (names != null) { int i = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-08 03:30:28
|
Revision: 6848 http://jython.svn.sourceforge.net/jython/?rev=6848&view=rev Author: fwierzbicki Date: 2009-10-08 03:30:17 +0000 (Thu, 08 Oct 2009) Log Message: ----------- Coding standards / Cleanup. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-08 02:33:20 UTC (rev 6847) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-08 03:30:17 UTC (rev 6848) @@ -1,5 +1,4 @@ // Copyright (c) Corporation for National Research Initiatives - package org.python.compiler; import java.io.IOException; @@ -103,37 +102,30 @@ public class CodeCompiler extends Visitor implements Opcodes, ClassConstants { - static final Object Exit=new Integer(1); - static final Object NoExit=null; - - static final int GET=0; - static final int SET=1; - static final int DEL=2; - static final int AUGGET=3; - static final int AUGSET=4; - + static final Object Exit = new Integer(1); + static final Object NoExit = null; + static final int GET = 0; + static final int SET = 1; + static final int DEL = 2; + static final int AUGGET = 3; + static final int AUGSET = 4; Module module; ClassWriter cw; Code code; CodeCompiler mrefs; CompilerFlags cflags; - int temporary; expr_contextType augmode; int augtmp1; int augtmp2; int augtmp3; int augtmp4; - boolean fast_locals, print_results; - Map<String, SymInfo> tbl; ScopeInfo my_scope; - boolean optimizeGlobals = true; Vector<String> names; String className; - Stack<Label> continueLabels, breakLabels; Stack<ExceptionHandler> exceptionHandlers; Vector<Label> yields = new Vector<Label>(); @@ -147,9 +139,7 @@ * finally's all the exceptionHandlers are executed. */ public int bcfLevel = 0; - int yield_count = 0; - private Stack<String> stack = new Stack<String>(); public CodeCompiler(Module module, boolean print_results) { @@ -181,7 +171,7 @@ code.iconst(idx); code.putfield(p(PyFrame.class), "f_lasti", "I"); } - + private void loadf_back() throws Exception { code.getfield(p(PyFrame.class), "f_back", ci(PyFrame.class)); } @@ -235,40 +225,45 @@ code.astore(augtmp1); code.aload(augtmp1); - if (count >= 2) + if (count >= 2) { code.aload(augtmp2); - if (count >= 3) + } + if (count >= 3) { code.aload(augtmp3); - if (count >= 4) + } + if (count >= 4) { code.aload(augtmp4); + } } private void restoreAugTmps(PythonTree node, int count) throws Exception { - code.aload(augtmp1); - code.freeLocal(augtmp1); - if (count == 1) - return; - code.aload(augtmp2); - code.freeLocal(augtmp2); - if (count == 2) - return; - code.aload(augtmp3); - code.freeLocal(augtmp3); - if (count == 3) - return; - code.aload(augtmp4); - code.freeLocal(augtmp4); + code.aload(augtmp1); + code.freeLocal(augtmp1); + if (count == 1) { + return; + } + code.aload(augtmp2); + code.freeLocal(augtmp2); + if (count == 2) { + return; + } + code.aload(augtmp3); + code.freeLocal(augtmp3); + if (count == 3) { + return; + } + code.aload(augtmp4); + code.freeLocal(augtmp4); } static boolean checkOptimizeGlobals(boolean fast_locals, ScopeInfo scope) { - return fast_locals&&!scope.exec&&!scope.from_import_star; + return fast_locals && !scope.exec && !scope.from_import_star; } public void parse(mod node, Code code, - boolean fast_locals, String className, - boolean classBody, ScopeInfo scope, CompilerFlags cflags) - throws Exception - { + boolean fast_locals, String className, + boolean classBody, ScopeInfo scope, CompilerFlags cflags) + throws Exception { this.fast_locals = fast_locals; this.className = className; this.code = code; @@ -279,7 +274,7 @@ tbl = scope.tbl; optimizeGlobals = checkOptimizeGlobals(fast_locals, scope); - + if (scope.max_with_count > 0) { // allocate for all the with-exits we will have in the frame; // this allows yield and with to happily co-exist @@ -313,17 +308,15 @@ @Override public Object visitModule(org.python.antlr.ast.Module suite) - throws Exception - { + throws Exception { if (suite.getInternalBody().size() > 0 && - suite.getInternalBody().get(0) instanceof Expr && - ((Expr) suite.getInternalBody().get(0)).getInternalValue() instanceof Str) - { + suite.getInternalBody().get(0) instanceof Expr && + ((Expr) suite.getInternalBody().get(0)).getInternalValue() instanceof Str) { loadFrame(); code.ldc("__doc__"); visit(((Expr) suite.getInternalBody().get(0)).getInternalValue()); code.invokevirtual(p(PyFrame.class), "setglobal", sig(Void.TYPE, String.class, - PyObject.class)); + PyObject.class)); } traverse(suite); return null; @@ -333,9 +326,9 @@ public Object visitExpression(Expression node) throws Exception { if (my_scope.generator && node.getInternalBody() != null) { module.error("'return' with argument inside generator", - true, node); + true, node); } - return visitReturn(new Return(node,node.getInternalBody()), true); + return visitReturn(new Return(node, node.getInternalBody()), true); } public int makeArray(java.util.List<? extends PythonTree> nodes) throws Exception { @@ -343,10 +336,11 @@ // the caller is responsible for freeing. int n; - if (nodes == null) + if (nodes == null) { n = 0; - else + } else { n = nodes.size(); + } int array = code.getLocal(ci(PyObject[].class)); if (n == 0) { @@ -357,7 +351,7 @@ code.anewarray(p(PyObject.class)); code.astore(array); - for(int i=0; i<n; i++) { + for (int i = 0; i < n; i++) { visit(nodes.get(i)); code.aload(array); code.swap(); @@ -379,8 +373,7 @@ public void getDocString(java.util.List<stmt> suite) throws Exception { if (suite.size() > 0 && suite.get(0) instanceof Expr && - ((Expr) suite.get(0)).getInternalValue() instanceof Str) - { + ((Expr) suite.get(0)).getInternalValue() instanceof Str) { visit(((Expr) suite.get(0)).getInternalValue()); } else { code.aconst_null(); @@ -388,20 +381,24 @@ } public boolean makeClosure(ScopeInfo scope) throws Exception { - if (scope == null || scope.freevars == null) return false; + if (scope == null || scope.freevars == null) { + return false; + } int n = scope.freevars.size(); - if (n == 0) return false; + if (n == 0) { + return false; + } int tmp = code.getLocal(ci(PyObject[].class)); code.iconst(n); code.anewarray(p(PyObject.class)); code.astore(tmp); Map<String, SymInfo> upTbl = scope.up.tbl; - for(int i=0; i<n; i++) { + for (int i = 0; i < n; i++) { code.aload(tmp); code.iconst(i); loadFrame(); - for(int j = 1; j < scope.distance; j++) { + for (int j = 1; j < scope.distance; j++) { loadf_back(); } SymInfo symInfo = upTbl.get(scope.freevars.elementAt(i)); @@ -437,23 +434,23 @@ scope.setup_closure(); scope.dump(); - module.codeConstant(new Suite(node,node.getInternalBody()), name, true, - className, false, false, - node.getLine(), scope, cflags).get(code); + module.codeConstant(new Suite(node, node.getInternalBody()), name, true, + className, false, false, + node.getLine(), scope, cflags).get(code); getDocString(node.getInternalBody()); if (!makeClosure(scope)) { code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, - PyObject[].class, PyCode.class, PyObject.class)); + PyObject[].class, PyCode.class, PyObject.class)); } else { code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, - PyObject[].class, PyCode.class, PyObject.class, PyObject[].class)); + PyObject[].class, PyCode.class, PyObject.class, PyObject[].class)); } - + applyDecorators(node.getInternalDecorator_list()); - set(new Name(node,node.getInternalName(), expr_contextType.Store)); + set(new Name(node, node.getInternalName(), expr_contextType.Store)); return null; } @@ -461,14 +458,15 @@ if (decorators != null && !decorators.isEmpty()) { int res = storeTop(); for (expr decorator : decorators) { - visit(decorator); stackProduce(); + visit(decorator); + stackProduce(); } for (int i = decorators.size(); i > 0; i--) { stackConsume(); loadThreadState(); code.aload(res); code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, - ThreadState.class, PyObject.class)); + ThreadState.class, PyObject.class)); code.astore(res); } code.aload(res); @@ -490,7 +488,7 @@ } @Override - public Object visitAssign(Assign node) throws Exception { + public Object visitAssign(Assign node) throws Exception { setline(node); visit(node.getInternalValue()); if (node.getInternalTargets().size() == 1) { @@ -528,10 +526,10 @@ visit(node.getInternalValues().get(i)); if (node.getInternalNl() && i == node.getInternalValues().size() - 1) { code.invokestatic(p(Py.class), "println", sig(Void.TYPE, PyObject.class, - PyObject.class)); + PyObject.class)); } else { - code.invokestatic(p(Py.class), "printComma", sig(Void.TYPE, PyObject.class, - PyObject.class)); + code.invokestatic(p(Py.class), "printComma", sig(Void.TYPE, PyObject.class, + PyObject.class)); } } else { visit(node.getInternalValues().get(i)); @@ -539,7 +537,7 @@ code.invokestatic(p(Py.class), "println", sig(Void.TYPE, PyObject.class)); } else { code.invokestatic(p(Py.class), "printComma", sig(Void.TYPE, - PyObject.class)); + PyObject.class)); } } @@ -598,15 +596,15 @@ } int stackState = saveStack(); - + if (node.getInternalValue() != null) { visit(node.getInternalValue()); } else { getNone(); } - + setLastI(++yield_count); - + saveLocals(); code.areturn(); @@ -615,7 +613,7 @@ code.label(restart); restoreLocals(); restoreStack(stackState); - + loadFrame(); code.invokevirtual(p(PyFrame.class), "getGeneratorInput", sig(Object.class)); code.dup(); @@ -626,14 +624,14 @@ code.athrow(); code.label(done2); code.checkcast(p(PyObject.class)); - + return null; } - + private void stackProduce() { stackProduce(p(PyObject.class)); } - + private void stackProduce(String signature) { stack.push(signature); } @@ -641,7 +639,7 @@ private void stackConsume() { stackConsume(1); } - + private void stackConsume(int numItems) { for (int i = 0; i < numItems; i++) { stack.pop(); @@ -680,7 +678,7 @@ private void restoreStack(int array) throws Exception { if (stack.size() > 0) { - int i = stack.size() -1; + int i = stack.size() - 1; for (String signature : stack) { if (p(ThreadState.class).equals(signature)) { loadThreadState(); @@ -699,7 +697,7 @@ private void restoreLocals() throws Exception { endExceptionHandlers(); - + Vector<String> v = code.getActiveLocals(); loadFrame(); @@ -710,8 +708,9 @@ for (int i = 0; i < v.size(); i++) { String type = v.elementAt(i); - if (type == null) + if (type == null) { continue; + } code.aload(locals); code.iconst(i); code.aaload(); @@ -730,8 +729,7 @@ * variables without the verifier thinking we might jump out of our * handling with an exception. */ - private void endExceptionHandlers() - { + private void endExceptionHandlers() { Label end = new Label(); code.label(end); for (int i = 0; i < exceptionHandlers.size(); ++i) { @@ -740,8 +738,7 @@ } } - private void restartExceptionHandlers() - { + private void restartExceptionHandlers() { Label start = new Label(); code.label(start); for (int i = 0; i < exceptionHandlers.size(); ++i) { @@ -759,15 +756,17 @@ for (int i = 0; i < v.size(); i++) { String type = v.elementAt(i); - if (type == null) + if (type == null) { continue; + } code.aload(locals); code.iconst(i); //code.checkcast(code.pool.Class(p(Object.class))); if (i == 2222) { code.aconst_null(); - } else + } else { code.aload(i); + } code.aastore(); } @@ -777,7 +776,6 @@ code.freeLocal(locals); } - @Override public Object visitReturn(Return node) throws Exception { return visitReturn(node, false); @@ -790,9 +788,10 @@ } int tmp = 0; if (node.getInternalValue() != null) { - if (my_scope.generator) + if (my_scope.generator) { throw new ParseException("'return' with argument " + - "inside generator", node); + "inside generator", node); + } visit(node.getInternalValue()); tmp = code.getReturnLocal(); code.astore(tmp); @@ -813,9 +812,18 @@ @Override public Object visitRaise(Raise node) throws Exception { setline(node); - if (node.getInternalType() != null) { visit(node.getInternalType()); stackProduce(); } - if (node.getInternalInst() != null) { visit(node.getInternalInst()); stackProduce(); } - if (node.getInternalTback() != null) { visit(node.getInternalTback()); stackProduce(); } + if (node.getInternalType() != null) { + visit(node.getInternalType()); + stackProduce(); + } + if (node.getInternalInst() != null) { + visit(node.getInternalInst()); + stackProduce(); + } + if (node.getInternalTback() != null) { + visit(node.getInternalTback()); + stackProduce(); + } if (node.getInternalType() == null) { code.invokestatic(p(Py.class), "makeException", sig(PyException.class)); } else if (node.getInternalInst() == null) { @@ -824,11 +832,11 @@ } else if (node.getInternalTback() == null) { stackConsume(2); code.invokestatic(p(Py.class), "makeException", sig(PyException.class, PyObject.class, - PyObject.class)); + PyObject.class)); } else { stackConsume(3); code.invokestatic(p(Py.class), "makeException", sig(PyException.class, PyObject.class, - PyObject.class, PyObject.class)); + PyObject.class, PyObject.class)); } code.athrow(); return Exit; @@ -845,23 +853,23 @@ code.ldc(name); loadFrame(); code.invokestatic(p(imp.class), "importOneAs", sig(PyObject.class, String.class, - PyFrame.class)); + PyFrame.class)); } else { String name = a.getInternalName(); asname = name; - if (asname.indexOf('.') > 0) + if (asname.indexOf('.') > 0) { asname = asname.substring(0, asname.indexOf('.')); + } code.ldc(name); loadFrame(); code.invokestatic(p(imp.class), "importOne", sig(PyObject.class, String.class, - PyFrame.class)); + PyFrame.class)); } set(new Name(a, asname, expr_contextType.Store)); } return null; } - @Override public Object visitImportFrom(ImportFrom node) throws Exception { Future.checkFromFuture(node); // future stmt support @@ -890,18 +898,19 @@ "' because it is a nested function", true, node); } - + loadFrame(); code.invokestatic(p(imp.class), "importAll", sig(Void.TYPE, String.class, - PyFrame.class)); + PyFrame.class)); } else { java.util.List<String> fromNames = new ArrayList<String>();//[names.size()]; java.util.List<String> asnames = new ArrayList<String>();//[names.size()]; for (int i = 0; i < aliases.size(); i++) { fromNames.add(aliases.get(i).getInternalName()); asnames.add(aliases.get(i).getInternalAsname()); - if (asnames.get(i) == null) + if (asnames.get(i) == null) { asnames.set(i, fromNames.get(i)); + } } int strArray = makeStrings(code, fromNames); code.aload(strArray); @@ -919,7 +928,7 @@ code.iconst(node.getInternalLevel()); } code.invokestatic(p(imp.class), "importFrom", sig(PyObject[].class, String.class, - String[].class, PyFrame.class, Integer.TYPE)); + String[].class, PyFrame.class, Integer.TYPE)); int tmp = storeTop(); for (int i = 0; i < aliases.size(); i++) { code.aload(tmp); @@ -960,7 +969,7 @@ //do the real work here stackConsume(3); code.invokestatic(p(Py.class), "exec", sig(Void.TYPE, PyObject.class, PyObject.class, - PyObject.class)); + PyObject.class)); return null; } @@ -968,7 +977,7 @@ public Object visitAssert(Assert node) throws Exception { setline(node); Label end_of_assert = new Label(); - + /* First do an if __debug__: */ loadFrame(); emitGetGlobal("__debug__"); @@ -978,8 +987,8 @@ code.ifeq(end_of_assert); /* Now do the body of the assert. If PyObject.__nonzero__ is true, - then the assertion succeeded, the message portion should not be - processed. Otherwise, the message will be processed. */ + then the assertion succeeded, the message portion should not be + processed. Otherwise, the message will be processed. */ visit(node.getInternalTest()); code.invokevirtual(p(PyObject.class), "__nonzero__", sig(Boolean.TYPE)); @@ -987,24 +996,23 @@ code.ifne(end_of_assert); /* Visit the message part of the assertion, or pass Py.None */ - if( node.getInternalMsg() != null ) { - visit(node.getInternalMsg()); + if (node.getInternalMsg() != null) { + visit(node.getInternalMsg()); } else { - getNone(); + getNone(); } - + /* Push exception type onto stack(AssertionError) */ loadFrame(); emitGetGlobal("AssertionError"); - + code.swap(); // The type is the first argument, but the message could be a yield - + code.invokestatic(p(Py.class), "makeException", sig(PyException.class, PyObject.class, - PyObject.class)); - /* Raise assertion error. Only executes this logic if assertion - failed */ + PyObject.class)); + /* Raise assertion error. Only executes this logic if assertion failed */ code.athrow(); - + /* And finally set the label for the end of it all */ code.label(end_of_assert); @@ -1012,8 +1020,7 @@ } public Object doTest(Label end_of_if, If node, int index) - throws Exception - { + throws Exception { Label end_of_suite = new Label(); setline(node.getInternalTest()); @@ -1024,8 +1031,9 @@ Object exit = suite(node.getInternalBody()); - if (end_of_if != null && exit == null) + if (end_of_if != null && exit == null) { code.goto_(end_of_if); + } code.label(end_of_suite); @@ -1039,12 +1047,14 @@ @Override public Object visitIf(If node) throws Exception { Label end_of_if = null; - if (node.getInternalOrelse() != null) + if (node.getInternalOrelse() != null) { end_of_if = new Label(); + } Object exit = doTest(end_of_if, node, 0); - if (end_of_if != null) + if (end_of_if != null) { code.label(end_of_if); + } return exit; } @@ -1083,7 +1093,6 @@ bcfLevel = savebcf; } - @Override public Object visitWhile(While node) throws Exception { int savebcf = beginLoop(); @@ -1178,11 +1187,10 @@ } public void exceptionTest(int exc, Label end_of_exceptions, - TryExcept node, int index) - throws Exception - { + TryExcept node, int index) + throws Exception { for (int i = 0; i < node.getInternalHandlers().size(); i++) { - ExceptHandler handler = (ExceptHandler)node.getInternalHandlers().get(i); + ExceptHandler handler = (ExceptHandler) node.getInternalHandlers().get(i); //setline(name); Label end_of_self = new Label(); @@ -1192,12 +1200,12 @@ //get specific exception visit(handler.getInternalType()); code.invokevirtual(p(PyException.class), "match", sig(Boolean.TYPE, - PyObject.class)); + PyObject.class)); code.ifeq(end_of_self); } else { - if (i != node.getInternalHandlers().size()-1) { + if (i != node.getInternalHandlers().size() - 1) { throw new ParseException( - "default 'except:' must be last", handler); + "default 'except:' must be last", handler); } } @@ -1216,10 +1224,8 @@ code.athrow(); } - @Override - public Object visitTryFinally(TryFinally node) throws Exception - { + public Object visitTryFinally(TryFinally node) throws Exception { Label start = new Label(); Label end = new Label(); Label handlerStart = new Label(); @@ -1259,8 +1265,8 @@ code.aload(excLocal); loadFrame(); - code.invokestatic(p(Py.class), "addTraceback", sig(Void.TYPE, Throwable.class, - PyFrame.class)); + code.invokestatic(p(Py.class), "addTraceback", + sig(Void.TYPE, Throwable.class, PyFrame.class)); inlineFinally(inFinally); code.aload(excLocal); @@ -1284,19 +1290,19 @@ code.label(end); handler.exceptionEnds.addElement(end); // also exiting the try: portion of this particular finally - } + } if (handler.isFinallyHandler()) { handler.finalBody(this); } } - + private void reenterProtectedBody(ExceptionHandler handler) throws Exception { // restart exception coverage Label restart = new Label(); code.label(restart); handler.exceptionStarts.addElement(restart); } - + /** * Inline the finally handling code for levels down to the levelth parent * (0 means all). This takes care to avoid having more nested finallys @@ -1314,9 +1320,9 @@ ExceptionHandler handler = poppedHandlers.pop(); reenterProtectedBody(handler); exceptionHandlers.push(handler); - } - } - + } + } + @Override public Object visitTryExcept(TryExcept node) throws Exception { Label start = new Label(); @@ -1334,15 +1340,16 @@ code.label(end); handler.exceptionEnds.addElement(end); - if (exit == null) + if (exit == null) { code.goto_(handler_end); + } code.label(handler_start); loadFrame(); code.invokestatic(p(Py.class), "setException", sig(PyException.class, Throwable.class, - PyFrame.class)); + PyFrame.class)); int exc = code.getFinallyLocal(p(Throwable.class)); code.astore(exc); @@ -1373,10 +1380,11 @@ } public Object suite(java.util.List<stmt> stmts) throws Exception { - for(stmt s: stmts) { + for (stmt s : stmts) { Object exit = visit(s); - if (exit != null) + if (exit != null) { return Exit; + } } return null; } @@ -1389,12 +1397,12 @@ code.dup(); code.invokevirtual(p(PyObject.class), "__nonzero__", sig(Boolean.TYPE)); switch (node.getInternalOp()) { - case Or : - code.ifne(end); - break; - case And : - code.ifeq(end); - break; + case Or: + code.ifne(end); + break; + case And: + code.ifeq(end); + break; } code.pop(); visit(node.getInternalValues().get(i)); @@ -1403,7 +1411,6 @@ return null; } - @Override public Object visitCompare(Compare node) throws Exception { int last = code.getLocal(p(PyObject.class)); @@ -1414,7 +1421,7 @@ code.astore(last); int n = node.getInternalOps().size(); - for(int i = 0; i < n - 1; i++) { + for (int i = 0; i < n - 1; i++) { visit(node.getInternalComparators().get(i)); code.aload(last); code.swap(); @@ -1427,10 +1434,10 @@ code.ifeq(end); } - visit(node.getInternalComparators().get(n-1)); + visit(node.getInternalComparators().get(n - 1)); code.aload(last); code.swap(); - visitCmpop(node.getInternalOps().get(n-1)); + visitCmpop(node.getInternalOps().get(n - 1)); if (n > 1) { code.astore(result); @@ -1448,16 +1455,36 @@ public void visitCmpop(cmpopType op) throws Exception { String name = null; switch (op) { - case Eq: name = "_eq"; break; - case NotEq: name = "_ne"; break; - case Lt: name = "_lt"; break; - case LtE: name = "_le"; break; - case Gt: name = "_gt"; break; - case GtE: name = "_ge"; break; - case Is: name = "_is"; break; - case IsNot: name = "_isnot"; break; - case In: name = "_in"; break; - case NotIn: name = "_notin"; break; + case Eq: + name = "_eq"; + break; + case NotEq: + name = "_ne"; + break; + case Lt: + name = "_lt"; + break; + case LtE: + name = "_le"; + break; + case Gt: + name = "_gt"; + break; + case GtE: + name = "_ge"; + break; + case Is: + name = "_is"; + break; + case IsNot: + name = "_isnot"; + break; + case In: + name = "_in"; + break; + case NotIn: + name = "_notin"; + break; } code.invokevirtual(p(PyObject.class), name, sig(PyObject.class, PyObject.class)); } @@ -1470,18 +1497,42 @@ stackConsume(); String name = null; switch (node.getInternalOp()) { - case Add: name = "_add"; break; - case Sub: name = "_sub"; break; - case Mult: name = "_mul"; break; - case Div: name = "_div"; break; - case Mod: name = "_mod"; break; - case Pow: name = "_pow"; break; - case LShift: name = "_lshift"; break; - case RShift: name = "_rshift"; break; - case BitOr: name = "_or"; break; - case BitXor: name = "_xor"; break; - case BitAnd: name = "_and"; break; - case FloorDiv: name = "_floordiv"; break; + case Add: + name = "_add"; + break; + case Sub: + name = "_sub"; + break; + case Mult: + name = "_mul"; + break; + case Div: + name = "_div"; + break; + case Mod: + name = "_mod"; + break; + case Pow: + name = "_pow"; + break; + case LShift: + name = "_lshift"; + break; + case RShift: + name = "_rshift"; + break; + case BitOr: + name = "_or"; + break; + case BitXor: + name = "_xor"; + break; + case BitAnd: + name = "_and"; + break; + case FloorDiv: + name = "_floordiv"; + break; } if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) { @@ -1490,16 +1541,24 @@ code.invokevirtual(p(PyObject.class), name, sig(PyObject.class, PyObject.class)); return null; } - + @Override public Object visitUnaryOp(UnaryOp node) throws Exception { visit(node.getInternalOperand()); String name = null; switch (node.getInternalOp()) { - case Invert: name = "__invert__"; break; - case Not: name = "__not__"; break; - case UAdd: name = "__pos__"; break; - case USub: name = "__neg__"; break; + case Invert: + name = "__invert__"; + break; + case Not: + name = "__not__"; + break; + case UAdd: + name = "__pos__"; + break; + case USub: + name = "__neg__"; + break; } code.invokevirtual(p(PyObject.class), name, sig(PyObject.class)); return null; @@ -1519,18 +1578,42 @@ code.swap(); String name = null; switch (node.getInternalOp()) { - case Add: name = "_iadd"; break; - case Sub: name = "_isub"; break; - case Mult: name = "_imul"; break; - case Div: name = "_idiv"; break; - case Mod: name = "_imod"; break; - case Pow: name = "_ipow"; break; - case LShift: name = "_ilshift"; break; - case RShift: name = "_irshift"; break; - case BitOr: name = "_ior"; break; - case BitXor: name = "_ixor"; break; - case BitAnd: name = "_iand"; break; - case FloorDiv: name = "_ifloordiv"; break; + case Add: + name = "_iadd"; + break; + case Sub: + name = "_isub"; + break; + case Mult: + name = "_imul"; + break; + case Div: + name = "_idiv"; + break; + case Mod: + name = "_imod"; + break; + case Pow: + name = "_ipow"; + break; + case LShift: + name = "_ilshift"; + break; + case RShift: + name = "_irshift"; + break; + case BitOr: + name = "_ior"; + break; + case BitXor: + name = "_ixor"; + break; + case BitAnd: + name = "_iand"; + break; + case FloorDiv: + name = "_ifloordiv"; + break; } if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) { name = "_itruediv"; @@ -1546,10 +1629,8 @@ return null; } - public static int makeStrings(Code c, Collection<String> names) - throws IOException - { + throws IOException { if (names != null) { c.iconst(names.size()); } else { @@ -1570,68 +1651,76 @@ } return strings; } - + public Object invokeNoKeywords(Attribute node, java.util.List<expr> values) - throws Exception - { + throws Exception { String name = getName(node.getInternalAttr()); - visit(node.getInternalValue()); stackProduce(); + visit(node.getInternalValue()); + stackProduce(); code.ldc(name); code.invokevirtual(p(PyObject.class), "__getattr__", sig(PyObject.class, String.class)); - loadThreadState(); stackProduce(p(ThreadState.class)); + loadThreadState(); + stackProduce(p(ThreadState.class)); switch (values.size()) { - case 0: - stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class)); - break; - case 1: - visit(values.get(0)); - stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, + case 0: + stackConsume(2); // target + ts + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class)); + break; + case 1: + visit(values.get(0)); + stackConsume(2); // target + ts + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject.class)); + break; + case 2: + visit(values.get(0)); + stackProduce(); + visit(values.get(1)); + stackConsume(3); // target + ts + arguments + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject.class, PyObject.class)); + break; + case 3: + visit(values.get(0)); + stackProduce(); + visit(values.get(1)); + stackProduce(); + visit(values.get(2)); + stackConsume(4); // target + ts + arguments + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject.class, PyObject.class, PyObject.class)); + break; + case 4: + visit(values.get(0)); + stackProduce(); + visit(values.get(1)); + stackProduce(); + visit(values.get(2)); + stackProduce(); + visit(values.get(3)); + stackConsume(5); // target + ts + arguments + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject.class, PyObject.class, PyObject.class, PyObject.class)); - break; - case 2: - visit(values.get(0)); stackProduce(); - visit(values.get(1)); - stackConsume(3); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, - PyObject.class, PyObject.class)); - break; - case 3: - visit(values.get(0)); stackProduce(); - visit(values.get(1)); stackProduce(); - visit(values.get(2)); - stackConsume(4); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, - PyObject.class, PyObject.class, PyObject.class)); - break; - case 4: - visit(values.get(0)); stackProduce(); - visit(values.get(1)); stackProduce(); - visit(values.get(2)); stackProduce(); - visit(values.get(3)); - stackConsume(5); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, - PyObject.class, PyObject.class, PyObject.class, PyObject.class)); - break; - default: - int argArray = makeArray(values); - code.aload(argArray); - code.freeLocal(argArray); - stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, - PyObject[].class)); - break; + break; + default: + int argArray = makeArray(values); + code.aload(argArray); + code.freeLocal(argArray); + stackConsume(2); // target + ts + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + ThreadState.class, PyObject[].class)); + break; } return null; } - @Override public Object visitCall(Call node) throws Exception { - java.util.List<String> keys = new ArrayList<String>();//[node.keywords.size()]; - java.util.List<expr> values = new ArrayList<expr>();//[node.args.size() + keys.size()]; + java.util.List<String> keys = new ArrayList<String>(); + java.util.List<expr> values = new ArrayList<expr>(); for (int i = 0; i < node.getInternalArgs().size(); i++) { values.add(node.getInternalArgs().get(i)); } @@ -1640,41 +1729,45 @@ values.add(node.getInternalKeywords().get(i).getInternalValue()); } - if ((node.getInternalKeywords() == null || node.getInternalKeywords().size() == 0)&& node.getInternalStarargs() == null && - node.getInternalKwargs() == null && node.getInternalFunc() instanceof Attribute) - { + if ((node.getInternalKeywords() == null || node.getInternalKeywords().size() == 0) && + node.getInternalStarargs() == null && node.getInternalKwargs() == null && + node.getInternalFunc() instanceof Attribute) { return invokeNoKeywords((Attribute) node.getInternalFunc(), values); } - visit(node.getInternalFunc()); stackProduce(); + visit(node.getInternalFunc()); + stackProduce(); if (node.getInternalStarargs() != null || node.getInternalKwargs() != null) { int argArray = makeArray(values); int strArray = makeStrings(code, keys); - if (node.getInternalStarargs() == null) + if (node.getInternalStarargs() == null) { code.aconst_null(); - else + } else { visit(node.getInternalStarargs()); + } stackProduce(); - if (node.getInternalKwargs() == null) + if (node.getInternalKwargs() == null) { code.aconst_null(); - else + } else { visit(node.getInternalKwargs()); + } stackProduce(); - + code.aload(argArray); code.aload(strArray); code.freeLocal(argArray); code.freeLocal(strArray); code.dup2_x2(); code.pop2(); - + stackConsume(3); // target + starargs + kwargs code.invokevirtual(p(PyObject.class), "_callextra", sig(PyObject.class, - PyObject[].class, String[].class, PyObject.class, PyObject.class)); + PyObject[].class, String[].class, PyObject.class, PyObject.class)); } else if (keys.size() > 0) { - loadThreadState(); stackProduce(p(ThreadState.class)); + loadThreadState(); + stackProduce(p(ThreadState.class)); int argArray = makeArray(values); int strArray = makeStrings(code, keys); code.aload(argArray); @@ -1683,60 +1776,66 @@ code.freeLocal(strArray); stackConsume(2); // target + ts code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, - PyObject[].class, String[].class)); + PyObject[].class, String[].class)); } else { - loadThreadState(); stackProduce(p(ThreadState.class)); + loadThreadState(); + stackProduce(p(ThreadState.class)); switch (values.size()) { - case 0: - stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + case 0: + stackConsume(2); // target + ts + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class)); - break; - case 1: - visit(values.get(0)); - stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + break; + case 1: + visit(values.get(0)); + stackConsume(2); // target + ts + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, PyObject.class)); - break; - case 2: - visit(values.get(0)); stackProduce(); - visit(values.get(1)); - stackConsume(3); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + break; + case 2: + visit(values.get(0)); + stackProduce(); + visit(values.get(1)); + stackConsume(3); // target + ts + arguments + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, PyObject.class, PyObject.class)); - break; - case 3: - visit(values.get(0)); stackProduce(); - visit(values.get(1)); stackProduce(); - visit(values.get(2)); - stackConsume(4); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + break; + case 3: + visit(values.get(0)); + stackProduce(); + visit(values.get(1)); + stackProduce(); + visit(values.get(2)); + stackConsume(4); // target + ts + arguments + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, PyObject.class, PyObject.class, PyObject.class)); - break; - case 4: - visit(values.get(0)); stackProduce(); - visit(values.get(1)); stackProduce(); - visit(values.get(2)); stackProduce(); - visit(values.get(3)); - stackConsume(5); // target + ts + arguments - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + break; + case 4: + visit(values.get(0)); + stackProduce(); + visit(values.get(1)); + stackProduce(); + visit(values.get(2)); + stackProduce(); + visit(values.get(3)); + stackConsume(5); // target + ts + arguments + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, PyObject.class, PyObject.class, PyObject.class, PyObject.class)); - break; - default: - int argArray = makeArray(values); - code.aload(argArray); - code.freeLocal(argArray); - stackConsume(2); // target + ts - code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, + break; + default: + int argArray = makeArray(values); + code.aload(argArray); + code.freeLocal(argArray); + stackConsume(2); // target + ts + code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, PyObject[].class)); - break; + break; } } return null; } - public Object Slice(Subscript node, Slice slice) throws Exception { expr_contextType ctx = node.getInternalCtx(); if (ctx == expr_contextType.AugStore && augmode == expr_contextType.Store) { @@ -1745,23 +1844,27 @@ } else { visit(node.getInternalValue()); stackProduce(); - if (slice.getInternalLower() != null) + if (slice.getInternalLower() != null) { visit(slice.getInternalLower()); - else + } else { code.aconst_null(); + } stackProduce(); - if (slice.getInternalUpper() != null) + if (slice.getInternalUpper() != null) { visit(slice.getInternalUpper()); - else + } else { code.aconst_null(); + } stackProduce(); - if (slice.getInternalStep() != null) + if (slice.getInternalStep() != null) { visit(slice.getInternalStep()); - else + } else { code.aconst_null(); + } stackProduce(); - if (node.getInternalCtx() == expr_contextType.AugStore && augmode == expr_contextType.Load) { + if (node.getInternalCtx() == expr_contextType.AugStore && + augmode == expr_contextType.Load) { saveAugTmps(node, 4); ctx = expr_contextType.Load; } @@ -1769,20 +1872,20 @@ } switch (ctx) { - case Del: - code.invokevirtual(p(PyObject.class), "__delslice__", sig(Void.TYPE, PyObject.class, + case Del: + code.invokevirtual(p(PyObject.class), "__delslice__", sig(Void.TYPE, PyObject.class, PyObject.class, PyObject.class)); - return null; - case Load: - code.invokevirtual(p(PyObject.class), "__getslice__", sig(PyObject.class, + return null; + case Load: + code.invokevirtual(p(PyObject.class), "__getslice__", sig(PyObject.class, PyObject.class, PyObject.class, PyObject.class)); - return null; - case Param: - case Store: - code.aload(temporary); - code.invokevirtual(p(PyObject.class), "__setslice__", sig(Void.TYPE, PyObject.class, + return null; + case Param: + case Store: + code.aload(temporary); + code.invokevirtual(p(PyObject.class), "__setslice__", sig(Void.TYPE, PyObject.class, PyObject.class, PyObject.class, PyObject.class)); - return null; + return null; } return null; @@ -1796,33 +1899,38 @@ int value = temporary; expr_contextType ctx = node.getInternalCtx(); - if (node.getInternalCtx() == expr_contextType.AugStore && augmode == expr_contextType.Store) { + if (node.getInternalCtx() == expr_contextType.AugStore && + augmode == expr_contextType.Store) { restoreAugTmps(node, 2); ctx = expr_contextType.Store; } else { - visit(node.getInternalValue()); stackProduce(); + visit(node.getInternalValue()); + stackProduce(); visit(node.getInternalSlice()); stackConsume(); - if (node.getInternalCtx() == expr_contextType.AugStore && augmode == expr_contextType.Load) { + if (node.getInternalCtx() == expr_contextType.AugStore && + augmode == expr_contextType.Load) { saveAugTmps(node, 2); ctx = expr_contextType.Load; } } switch (ctx) { - case Del: - code.invokevirtual(p(PyObject.class), "__delitem__", sig(Void.TYPE, PyObject.class)); - return null; - case Load: - code.invokevirtual(p(PyObject.class), "__getitem__", sig(PyObject.class, PyObject.class)); - return null; - case Param: - case Store: - code.aload(value); - code.invokevirtual(p(PyObject.class), "__setitem__", sig(Void.TYPE, PyObject.class, - PyObject.class)); - return null; + case Del: + code.invokevirtual(p(PyObject.class), "__delitem__", + sig(Void.TYPE, PyObject.class)); + return null; + case Load: + code.invokevirtual(p(PyObject.class), "__getitem__", + sig(PyObject.class, PyObject.class)); + return null; + case Param: + case Store: + code.aload(value); + code.invokevirtual(p(PyObject.class), "__setitem__", + sig(Void.TYPE, PyObject.class, PyObject.class)); + return null; } return null; } @@ -1848,32 +1956,35 @@ public Object visitAttribute(Attribute node) throws Exception { expr_contextType ctx = node.getInternalCtx(); - if (node.getInternalCtx() == expr_contextType.AugStore && augmode == expr_contextType.Store) { + if (node.getInternalCtx() == expr_contextType.AugStore && + augmode == expr_contextType.Store) { restoreAugTmps(node, 2); ctx = expr_contextType.Store; } else { visit(node.getInternalValue()); code.ldc(getName(node.getInternalAttr())); - if (node.getInternalCtx() == expr_contextType.AugStore && augmode == expr_contextType.Load) { + if (node.getInternalCtx() == expr_contextType.AugStore && + augmode == expr_contextType.Load) { saveAugTmps(node, 2); ctx = expr_contextType.Load; } } switch (ctx) { - case Del: - code.invokevirtual(p(PyObject.class), "__delattr__", sig(Void.TYPE, String.class)); - return null; - case Load: - code.invokevirtual(p(PyObject.class), "__getattr__", sig(PyObject.class, String.class)); - return null; - case Param: - case Store: - code.aload(temporary); - code.invokevirtual(p(PyObject.class), "__setattr__", sig(Void.TYPE, String.class, - PyObject.class)); - return null; + case Del: + code.invokevirtual(p(PyObject.class), "__delattr__", sig(Void.TYPE, String.class)); + return null; + case Load: + code.invokevirtual(p(PyObject.class), "__getattr__", + sig(PyObject.class, String.class)); + return null; + case Param: + case Store: + code.aload(temporary); + code.invokevirtual(p(PyObject.class), "__setattr__", + sig(Void.TYPE, String.class, PyObject.class)); + return null; } return null; } @@ -1881,8 +1992,8 @@ public Object seqSet(java.util.List<expr> nodes) throws Exception { code.aload(temporary); code.iconst(nodes.size()); - code.invokestatic(p(Py.class), "unpackSequence", sig(PyObject[].class, PyObject.class, - Integer.TYPE)); + code.invokestatic(p(Py.class), "unpackSequence", + sig(PyObject[].class, PyObject.class, Integer.TYPE)); int tmp = code.getLocal("[org/python/core/PyObject"); code.astore(tmp); @@ -1899,7 +2010,7 @@ } public Object seqDel(java.util.List<expr> nodes) throws Exception { - for (expr e: nodes) { + for (expr e : nodes) { visit(e); } return null; @@ -1907,12 +2018,13 @@ @Override public Object visitTuple(Tuple node) throws Exception { - /* if (mode ==AUGSET) - throw new ParseException( - "augmented assign to tuple not possible", node); */ - if (node.getInternalCtx() == expr_contextType.Store) return seqSet(node.getInternalElts()); - if (node.getInternalCtx() == expr_contextType.Del) return seqDel(node.getInternalElts()); - + if (node.getInternalCtx() == expr_contextType.Store) { + return seqSet(node.getInternalElts()); + } + if (node.getInternalCtx() == expr_contextType.Del) { + return seqDel(node.getInternalElts()); + } + int content = makeArray(node.getInternalElts()); code.new_(p(PyTuple.class)); @@ -1926,9 +2038,13 @@ @Override public Object visitList(List node) throws Exception { - if (node.getInternalCtx() == expr_contextType.Store) return seqSet(node.getInternalElts()); - if (node.getInternalCtx() == expr_contextType.Del) return seqDel(node.getInternalElts()); - + if (node.getInternalCtx() == expr_contextType.Store) { + return seqSet(node.getInternalElts()); + } + if (node.getInternalCtx() == expr_contextType.Del) { + return seqDel(node.getInternalElts()); + } + int content = makeArray(node.getInternalElts()); code.new_(p(PyList.class)); @@ -1951,26 +2067,28 @@ code.ldc("append"); code.invokevirtual(p(PyObject.class), "__getattr__", sig(PyObject.class, String.class)); - String tmp_append ="_[" + node.getLine() + "_" + node.getCharPositionInLine() + "]"; + String tmp_append = "_[" + node.getLine() + "_" + node.getCharPositionInLine() + "]"; set(new Name(node, tmp_append, expr_contextType.Store)); java.util.List<expr> args = new ArrayList<expr>(); args.add(node.getInternalElt()); - stmt n = new Expr(node, new Call(node, new Name(node, tmp_append, expr_contextType.Load), - args, - new ArrayList<keyword>(), null, null)); + stmt n = new Expr(node, new Call(node, new Name(node, tmp_append, expr_contextType.Load), + args, + new ArrayList<keyword>(), null, null)); for (int i = node.getInternalGenerators().size() - 1; i >= 0; i--) { comprehension lc = node.getInternalGenerators().get(i); for (int j = lc.getInternalIfs().size() - 1; j >= 0; j--) { java.util.List<stmt> body = new ArrayList<stmt>(); body.add(n); - n = new If(lc.getInternalIfs().get(j), lc.getInternalIfs().get(j), body, new ArrayList<stmt>()); + n = new If(lc.getInternalIfs().get(j), lc.getInternalIfs().get(j), body, + new ArrayList<stmt>()); } java.util.List<stmt> body = new ArrayList<stmt>(); body.add(n); - n = new For(lc,lc.getInternalTarget(), lc.getInternalIter(), body, new ArrayList<stmt>()); + n = new For(lc, lc.getInternalTarget(), lc.getInternalIter(), body, + new ArrayList<stmt>()); } visit(n); java.util.List<expr> targets = new ArrayList<expr>(); @@ -1988,7 +2106,7 @@ elts.add(node.getInternalValues().get(i)); } int content = makeArray(elts); - + code.new_(p(PyDictionary.class)); code.dup(); code.aload(content); @@ -2010,7 +2128,7 @@ //Add a return node onto the outside of suite; java.util.List<stmt> bod = new ArrayList<stmt>(); - bod.add(new Return(node,node.getInternalBody())); + bod.add(new Return(node, node.getInternalBody())); mod retSuite = new Suite(node, bod); setline(node); @@ -2020,32 +2138,31 @@ int defaultsArray = makeArray(scope.ac.getDefaults()); code.new_(p(PyFunction.class)); - + code.dup(); code.aload(defaultsArray); code.freeLocal(defaultsArray); loadFrame(); code.getfield(p(PyFrame.class), "f_globals", ci(PyObject.class)); - + code.swap(); scope.setup_closure(); scope.dump(); module.codeConstant(retSuite, name, true, className, - false, false, node.getLine(), scope, cflags).get(code); + false, false, node.getLine(), scope, cflags).get(code); if (!makeClosure(scope)) { code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, - PyObject[].class, PyCode.class)); + PyObject[].class, PyCode.class)); } else { code.invokespecial(p(PyFunction.class), "<init>", sig(Void.TYPE, PyObject.class, - PyObject[].class, Py... [truncated message content] |
From: <fwi...@us...> - 2009-10-09 18:32:41
|
Revision: 6850 http://jython.svn.sourceforge.net/jython/?rev=6850&view=rev Author: fwierzbicki Date: 2009-10-09 18:32:33 +0000 (Fri, 09 Oct 2009) Log Message: ----------- Make all of the fields in CodeCompiler private except "yields". I plan to make "yields" private as well, but that's going to take some surgery on Module. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-09 03:17:04 UTC (rev 6849) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-09 18:32:33 UTC (rev 6850) @@ -102,32 +102,34 @@ public class CodeCompiler extends Visitor implements Opcodes, ClassConstants { - static final Object Exit = new Integer(1); - static final Object NoExit = null; - static final int GET = 0; - static final int SET = 1; - static final int DEL = 2; - static final int AUGGET = 3; - static final int AUGSET = 4; - Module module; - ClassWriter cw; - Code code; - CodeCompiler mrefs; - CompilerFlags cflags; - int temporary; - expr_contextType augmode; - int augtmp1; - int augtmp2; - int augtmp3; - int augtmp4; - boolean fast_locals, print_results; - Map<String, SymInfo> tbl; - ScopeInfo my_scope; - boolean optimizeGlobals = true; - Vector<String> names; - String className; - Stack<Label> continueLabels, breakLabels; - Stack<ExceptionHandler> exceptionHandlers; + private static final Object Exit = new Integer(1); + private static final Object NoExit = null; + private static final int GET = 0; + private static final int SET = 1; + private static final int DEL = 2; + private static final int AUGGET = 3; + private static final int AUGSET = 4; + private Module module; + private ClassWriter cw; + private Code code; + private CodeCompiler mrefs; + private CompilerFlags cflags; + private int temporary; + private expr_contextType augmode; + private int augtmp1; + private int augtmp2; + private int augtmp3; + private int augtmp4; + private boolean fast_locals, print_results; + private Map<String, SymInfo> tbl; + private ScopeInfo my_scope; + private boolean optimizeGlobals = true; + private Vector<String> names; + private String className; + private Stack<Label> continueLabels, breakLabels; + private Stack<ExceptionHandler> exceptionHandlers; + + //Module uses this, otherwise I'd make it private. Vector<Label> yields = new Vector<Label>(); /* @@ -138,8 +140,8 @@ * PyCode, in other words: each 'function'. When returning through * finally's all the exceptionHandlers are executed. */ - public int bcfLevel = 0; - int yield_count = 0; + private int bcfLevel = 0; + private int yield_count = 0; private Stack<String> stack = new Stack<String>(); public CodeCompiler(Module module, boolean print_results) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-26 19:34:53
|
Revision: 6905 http://jython.svn.sourceforge.net/jython/?rev=6905&view=rev Author: fwierzbicki Date: 2009-10-26 19:34:45 +0000 (Mon, 26 Oct 2009) Log Message: ----------- Remove unused imports and fields. Reduce visibility of parse and makeStrings. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-26 06:38:28 UTC (rev 6904) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-26 19:34:45 UTC (rev 6905) @@ -93,7 +93,6 @@ import org.python.core.PyTuple; import org.python.core.PyUnicode; import org.python.core.ThreadState; -import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; @@ -104,15 +103,8 @@ private static final Object Exit = new Integer(1); private static final Object NoExit = null; - private static final int GET = 0; - private static final int SET = 1; - private static final int DEL = 2; - private static final int AUGGET = 3; - private static final int AUGSET = 4; private Module module; - private ClassWriter cw; private Code code; - private CodeCompiler mrefs; private CompilerFlags cflags; private int temporary; private expr_contextType augmode; @@ -148,9 +140,6 @@ this.module = module; this.print_results = print_results; - mrefs = this; - cw = module.classfile.cw; - continueLabels = new Stack<Label>(); breakLabels = new Stack<Label>(); exceptionHandlers = new Stack<ExceptionHandler>(); @@ -262,7 +251,7 @@ return fast_locals && !scope.exec && !scope.from_import_star; } - public void parse(mod node, Code code, + void parse(mod node, Code code, boolean fast_locals, String className, boolean classBody, ScopeInfo scope, CompilerFlags cflags) throws Exception { @@ -1631,7 +1620,7 @@ return null; } - public static int makeStrings(Code c, Collection<String> names) + static int makeStrings(Code c, Collection<String> names) throws IOException { if (names != null) { c.iconst(names.size()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-26 19:51:18
|
Revision: 6906 http://jython.svn.sourceforge.net/jython/?rev=6906&view=rev Author: fwierzbicki Date: 2009-10-26 19:51:10 +0000 (Mon, 26 Oct 2009) Log Message: ----------- Remove another unused variable. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-26 19:34:45 UTC (rev 6905) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-26 19:51:10 UTC (rev 6906) @@ -116,7 +116,6 @@ private Map<String, SymInfo> tbl; private ScopeInfo my_scope; private boolean optimizeGlobals = true; - private Vector<String> names; private String className; private Stack<Label> continueLabels, breakLabels; private Stack<ExceptionHandler> exceptionHandlers; @@ -261,7 +260,6 @@ this.cflags = cflags; my_scope = scope; - names = scope.names; tbl = scope.tbl; optimizeGlobals = checkOptimizeGlobals(fast_locals, scope); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-27 03:38:53
|
Revision: 6914 http://jython.svn.sourceforge.net/jython/?rev=6914&view=rev Author: fwierzbicki Date: 2009-10-27 03:38:41 +0000 (Tue, 27 Oct 2009) Log Message: ----------- refactor scope param use in parse method. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-27 03:11:20 UTC (rev 6913) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-27 03:38:41 UTC (rev 6914) @@ -258,6 +258,8 @@ this.className = className; this.code = code; this.cflags = cflags; + this.my_scope = scope; + this.tbl = scope.tbl; //BEGIN preparse if (classBody) { @@ -273,16 +275,15 @@ } Label genswitch = new Label(); - if (scope.generator) { + if (my_scope.generator) { code.goto_(genswitch); } Label start = new Label(); code.label(start); - int nparamcell = scope.jy_paramcells.size(); + int nparamcell = my_scope.jy_paramcells.size(); if (nparamcell > 0) { - Map<String, SymInfo> tbl = scope.tbl; - java.util.List<String> paramcells = scope.jy_paramcells; + java.util.List<String> paramcells = my_scope.jy_paramcells; for (int i = 0; i < nparamcell; i++) { code.aload(1); SymInfo syminf = tbl.get(paramcells.get(i)); @@ -294,16 +295,13 @@ } //END preparse - my_scope = scope; + optimizeGlobals = checkOptimizeGlobals(fast_locals, my_scope); - tbl = scope.tbl; - optimizeGlobals = checkOptimizeGlobals(fast_locals, scope); - - if (scope.max_with_count > 0) { + if (my_scope.max_with_count > 0) { // allocate for all the with-exits we will have in the frame; // this allows yield and with to happily co-exist loadFrame(); - code.iconst(scope.max_with_count); + code.iconst(my_scope.max_with_count); code.anewarray(p(PyObject.class)); code.putfield(p(PyFrame.class), "f_exits", ci(PyObject[].class)); } @@ -326,7 +324,7 @@ //BEGIN postparse // similar to visitResume code in pyasm.py - if (scope.generator) { + if (my_scope.generator) { code.label(genswitch); code.aload(1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |