From: <cg...@us...> - 2009-08-22 20:23:34
|
Revision: 6706 http://jython.svn.sourceforge.net/jython/?rev=6706&view=rev Author: cgroves Date: 2009-08-22 20:23:25 +0000 (Sat, 22 Aug 2009) Log Message: ----------- Cleanup Modified Paths: -------------- branches/customizable-proxymaker/src/org/python/compiler/CodeCompiler.java branches/customizable-proxymaker/src/org/python/util/jython.java Modified: branches/customizable-proxymaker/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/customizable-proxymaker/src/org/python/compiler/CodeCompiler.java 2009-08-22 10:50:40 UTC (rev 6705) +++ branches/customizable-proxymaker/src/org/python/compiler/CodeCompiler.java 2009-08-22 20:23:25 UTC (rev 6706) @@ -137,7 +137,7 @@ public int bcfLevel = 0; int yield_count = 0; - + private Stack<String> stack = new Stack<String>(); public CodeCompiler(Module module, boolean print_results) { @@ -169,7 +169,7 @@ code.iconst(idx); code.putfield("org/python/core/PyFrame", "f_lasti", "I"); } - + private void loadf_back() throws Exception { code.getfield("org/python/core/PyFrame", "f_back", $pyFrame); } @@ -264,7 +264,7 @@ tbl = scope.tbl; optimizeGlobals = fast_locals&&!scope.exec&&!scope.from_import_star; - + 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 @@ -432,7 +432,7 @@ } else { code.invokespecial( "org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); } - + applyDecorators(node.getInternalDecorator_list()); set(new Name(node,node.getInternalName(), expr_contextType.Store)); @@ -576,15 +576,15 @@ } int stackState = saveStack(); - + if (node.getInternalValue() != null) { visit(node.getInternalValue()); } else { getNone(); } - + setLastI(++yield_count); - + saveLocals(); code.areturn(); @@ -593,7 +593,7 @@ code.label(restart); restoreLocals(); restoreStack(stackState); - + loadFrame(); code.invokevirtual("org/python/core/PyFrame", "getGeneratorInput", "()" + $obj); code.dup(); @@ -604,14 +604,14 @@ code.athrow(); code.label(done2); code.checkcast("org/python/core/PyObject"); - + return null; } - + private void stackProduce() { stackProduce("org/python/core/PyObject"); } - + private void stackProduce(String signature) { stack.push(signature); } @@ -619,7 +619,7 @@ private void stackConsume() { stackConsume(1); } - + private void stackConsume(int numItems) { for (int i = 0; i < numItems; i++) { stack.pop(); @@ -677,7 +677,7 @@ private void restoreLocals() throws Exception { endExceptionHandlers(); - + Vector<String> v = code.getActiveLocals(); loadFrame(); @@ -704,7 +704,7 @@ /** * Close all the open exception handler ranges. This should be paired * with restartExceptionHandlers to delimit internal code that - * shouldn't be handled by user handlers. This allows us to set + * shouldn't be handled by user handlers. This allows us to set * variables without the verifier thinking we might jump out of our * handling with an exception. */ @@ -864,7 +864,7 @@ "' because it is a nested function", true, node); } - + loadFrame(); code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); } else { @@ -939,7 +939,7 @@ public Object visitAssert(Assert node) throws Exception { setline(node); Label end_of_assert = new Label(); - + /* First do an if __debug__: */ loadFrame(); emitGetGlobal("__debug__"); @@ -961,20 +961,20 @@ if( node.getInternalMsg() != null ) { visit(node.getInternalMsg()); } else { - getNone(); + getNone(); } - + /* Push exception type onto stack(Py.AssertionError) */ code.getstatic("org/python/core/Py", "AssertionError", "Lorg/python/core/PyObject;"); - + 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); - + /* 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); @@ -1185,7 +1185,7 @@ code.athrow(); } - + @Override public Object visitTryFinally(TryFinally node) throws Exception { @@ -1257,14 +1257,14 @@ 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 @@ -1284,7 +1284,7 @@ exceptionHandlers.push(handler); } } - + @Override public Object visitTryExcept(TryExcept node) throws Exception { Label start = new Label(); @@ -1356,10 +1356,10 @@ code.dup(); code.invokevirtual("org/python/core/PyObject", "__nonzero__", "()Z"); switch (node.getInternalOp()) { - case Or : + case Or : code.ifne(end); break; - case And : + case And : code.ifeq(end); break; } @@ -1457,7 +1457,7 @@ code.invokevirtual("org/python/core/PyObject", name, "(" + $pyObj + ")" + $pyObj); return null; } - + @Override public Object visitUnaryOp(UnaryOp node) throws Exception { visit(node.getInternalOperand()); @@ -1513,10 +1513,7 @@ return null; } - - public static int makeStrings(Code c, Collection<String> names) - throws IOException - { + public static int makeStrings(Code c, Collection<String> names) { if (names != null) { c.iconst(names.size()); } else { @@ -1537,7 +1534,7 @@ } return strings; } - + public Object invokeNoKeywords(Attribute node, java.util.List<expr> values) throws Exception { @@ -1623,14 +1620,14 @@ 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("org/python/core/PyObject", "_callextra", "(" + $pyObjArr + $strArr + $pyObj + $pyObj + ")" + $pyObj); @@ -1859,7 +1856,7 @@ "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()); - + int content = makeArray(node.getInternalElts()); code.new_("org/python/core/PyTuple"); @@ -1875,7 +1872,7 @@ 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()); - + int content = makeArray(node.getInternalElts()); code.new_("org/python/core/PyList"); @@ -1905,7 +1902,7 @@ 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), + stmt n = new Expr(node, new Call(node, new Name(node, tmp_append, expr_contextType.Load), args, new ArrayList<keyword>(), null, null)); @@ -1936,7 +1933,7 @@ elts.add(node.getInternalValues().get(i)); } int content = makeArray(elts); - + code.new_("org/python/core/PyDictionary"); code.dup(); code.aload(content); @@ -1968,14 +1965,14 @@ int defaultsArray = makeArray(scope.ac.getDefaults()); code.new_("org/python/core/PyFunction"); - + code.dup(); code.aload(defaultsArray); code.freeLocal(defaultsArray); loadFrame(); code.getfield("org/python/core/PyFrame", "f_globals", $pyObj); - + code.swap(); scope.setup_closure(); @@ -2005,15 +2002,15 @@ if (node.getInternalStep() == null) getNone(); else visit(node.getInternalStep()); int step = storeTop(); stackConsume(2); - + code.new_("org/python/core/PySlice"); code.dup(); code.dup2_x2(); code.pop2(); - + code.aload(step); code.freeLocal(step); - + code.invokespecial("org/python/core/PySlice", "<init>", "(" + $pyObj + $pyObj + $pyObj + ")V"); return null; } @@ -2027,7 +2024,7 @@ //Get class name String name = getName(node.getInternalName()); code.ldc(name); - + code.aload(baseArray); ScopeInfo scope = module.getScopeInfo(node); @@ -2047,7 +2044,7 @@ } else { code.invokestatic("org/python/core/Py", "makeClass", "(" + $str + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")" + $pyObj); } - + applyDecorators(node.getInternalDecorator_list()); //Assign this new class to the given name @@ -2102,7 +2099,7 @@ expr_contextType ctx = node.getInternalCtx(); if (ctx == expr_contextType.AugStore) { ctx = augmode; - } + } switch (ctx) { case Load: @@ -2291,8 +2288,8 @@ // 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(); - + final int mgr_tmp = code.getLocal(Type.getType(ContextManager.class).getInternalName()); code.astore(mgr_tmp); @@ -2336,7 +2333,7 @@ set(node.getInternalOptional_vars(), value_tmp); } code.freeLocal(value_tmp); - + // BLOCK + FINALLY if non-local-goto Object blockResult = suite(node.getInternalBody()); normalExit.bodyDone = true; @@ -2380,7 +2377,7 @@ handler.addExceptionHandlers(label_catch); return null; } - + @Override protected Object unhandled_node(PythonTree node) throws Exception { throw new Exception("Unhandled node " + node); @@ -2390,7 +2387,7 @@ * Data about a given exception range whether a try:finally: or a * try:except:. The finally needs to inline the finally block for * each exit of the try: section, so we carry around that data for it. - * + * * Both of these need to stop exception coverage of an area that is either * the inlined fin ally of a parent try:finally: or the reentry block after * a yield. Thus we keep around a set of exception ranges that the Modified: branches/customizable-proxymaker/src/org/python/util/jython.java =================================================================== --- branches/customizable-proxymaker/src/org/python/util/jython.java 2009-08-22 10:50:40 UTC (rev 6705) +++ branches/customizable-proxymaker/src/org/python/util/jython.java 2009-08-22 20:23:25 UTC (rev 6706) @@ -71,16 +71,17 @@ public static boolean shouldRestart; /** - * Runs a JAR file, by executing the code found in the file __run__.py, - * which should be in the root of the JAR archive. - * - * Note that the __name__ is set to the base name of the JAR file and not - * to "__main__" (for historic reasons). - * - * This method do NOT handle exceptions. the caller SHOULD handle any - * (Py)Exceptions thrown by the code. - * - * @param filename The path to the filename to run. + * Runs a JAR file, by executing the code found in the file __run__.py, which should be in the + * root of the JAR archive. + * + * Note that the __name__ is set to the base name of the JAR file and not to "__main__" (for + * historical reasons). + * + * This method does NOT catch exceptions. The caller SHOULD handle any (Py)Exceptions thrown by + * the code. + * + * @param filename + * The path to the filename to run. */ public static void runJar(String filename) { // TBD: this is kind of gross because a local called `zipfile' just magically @@ -217,7 +218,7 @@ runJar(opts.filename); } catch (Throwable t) { Py.printException(t); - System.exit(-1); + System.exit(-1); } } else if (opts.filename.equals("-")) { try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |