From: <zy...@us...> - 2009-01-26 01:19:16
|
Revision: 5980 http://jython.svn.sourceforge.net/jython/?rev=5980&view=rev Author: zyasoft Date: 2009-01-26 01:19:12 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Properly handles *args, **kwargs for the receiver function. func_code can now be set to a PyBytecode (or other extender of PyBaseCode). Turned off debugging by default for PyBytecode objects. Modified Paths: -------------- branches/pbcvm/src/org/python/core/PyBytecode.java branches/pbcvm/src/org/python/core/PyFunction.java Modified: branches/pbcvm/src/org/python/core/PyBytecode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-26 00:33:21 UTC (rev 5979) +++ branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-26 01:19:12 UTC (rev 5980) @@ -18,7 +18,9 @@ return opname; } + private boolean debug = false; public PyObject _debug(int maxCount) { + debug = maxCount > 0; this.maxCount = maxCount; return Py.None; } @@ -66,6 +68,8 @@ // co_argcount -= 1; // co_flags |= CO_VARKEYWORDS; // } + varargs = (flags & CO_VARARGS) != 0; + varkwargs = (flags & CO_VARKEYWORDS) != 0; co_flags |= flags; co_stacksize = stacksize; @@ -206,12 +210,14 @@ } private void print_debug(int count, int next_instr, int opcode, int oparg, PyStack stack, PyFrame f) { - System.err.println(co_name + ":" + - count + "," + f.f_lasti + "> opcode: " + - getOpname().__getitem__(Py.newInteger(opcode)) + - (opcode > Opcode.HAVE_ARGUMENT ? ", oparg: " + oparg : "") + - ", stack: " + stack.toString() + - ", blocks: " + stringify_blocks(f)); + if (debug) { + System.err.println(co_name + ":" + + count + "," + f.f_lasti + "> opcode: " + + getOpname().__getitem__(Py.newInteger(opcode)) + + (opcode > Opcode.HAVE_ARGUMENT ? ", oparg: " + oparg : "") + + ", stack: " + stack.toString() + + ", blocks: " + stringify_blocks(f)); + } } private static PyTryBlock popBlock(PyFrame f) { @@ -248,7 +254,9 @@ // 1. consider detaching the setting/getting of frame fields to improve performance, instead do this // in a shadow version of the frame that we copy back to on entry/exit and downcalls - System.err.println("Entry with " + f.f_lasti + " into " + co_code.length); + if (debug) { + System.err.println("Entry with " + f.f_lasti + " into " + co_code.length); + } if (f.f_lasti >= co_code.length) { throw Py.SystemError(""); } @@ -266,7 +274,7 @@ f.f_savedlocals = null; } - while (count < maxCount) { // XXX - replace with while(true) + while (!debug || (count < maxCount)) { // XXX - replace with while(true) try { @@ -290,7 +298,6 @@ next_instr += 1; f.f_lasti = next_instr; // should have no worries about needing co_lnotab, just keep this current - switch (opcode) { case Opcode.NOP: break; @@ -910,7 +917,7 @@ break; case Opcode.JUMP_ABSOLUTE: - next_instr = oparg; // XXX - continue to a label is probably much better + next_instr = oparg; break; case Opcode.GET_ITER: { @@ -1048,7 +1055,7 @@ case Opcode.EXTENDED_ARG: opcode = co_code[next_instr++]; next_instr += 2; - oparg = oparg << 16 | ((co_code[next_instr - 1] << 8) + (co_code[next_instr - 2])); + oparg = oparg << 16 | ((co_code[next_instr] << 8) + co_code[next_instr - 1]); break; default: @@ -1058,7 +1065,6 @@ f.f_lasti, opcode))); throw Py.SystemError("unknown opcode"); - } // end switch } // end try catch (Throwable t) { @@ -1133,9 +1139,11 @@ f.f_lasti = next_instr; // need to update on function entry, etc - System.err.println(count + "," + f.f_lasti + "> Returning from " + why + ": " + retval + - ", stack: " + stack.toString() + - ", blocks: " + stringify_blocks(f)); + if (debug) { + System.err.println(count + "," + f.f_lasti + "> Returning from " + why + ": " + retval + + ", stack: " + stack.toString() + + ", blocks: " + stringify_blocks(f)); + } if (why == why.EXCEPTION) { throw ts.exception; Modified: branches/pbcvm/src/org/python/core/PyFunction.java =================================================================== --- branches/pbcvm/src/org/python/core/PyFunction.java 2009-01-26 00:33:21 UTC (rev 5979) +++ branches/pbcvm/src/org/python/core/PyFunction.java 2009-01-26 01:19:12 UTC (rev 5980) @@ -195,10 +195,10 @@ @ExposedSet(name = "func_code") public void setFuncCode(PyCode code) { - if (func_code == null || !(code instanceof PyTableCode)) { + if (func_code == null || !(code instanceof PyBaseCode)) { throw Py.TypeError("func_code must be set to a code object"); } - PyTableCode tcode = (PyTableCode)code; + PyBaseCode tcode = (PyBaseCode)code; int nfree = tcode.co_freevars == null ? 0 : tcode.co_freevars.length; int nclosure = func_closure != null ? func_closure.__len__() : 0; if (nclosure != nfree) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |