From: <zy...@us...> - 2009-01-24 16:48:04
|
Revision: 5969 http://jython.svn.sourceforge.net/jython/?rev=5969&view=rev Author: zyasoft Date: 2009-01-24 16:47:59 +0000 (Sat, 24 Jan 2009) Log Message: ----------- Added support for basic coroutines (no support for throw) and generator expressions. Modified Paths: -------------- branches/pbcvm/src/org/python/core/PyBytecode.java Modified: branches/pbcvm/src/org/python/core/PyBytecode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-24 04:36:06 UTC (rev 5968) +++ branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-24 16:47:59 UTC (rev 5969) @@ -200,8 +200,9 @@ return buf.toString(); } - private static void print_debug(int count, int next_instr, int opcode, int oparg, PyStack stack, PyFrame f) { - System.err.println(count + "," + f.f_lasti + "> opcode: " + + 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() + @@ -257,18 +258,22 @@ // goto on_error; // } + // the restore stack aspets should occur ONLY after a yield if (f.f_savedlocals != null) { for (int i = 0; i < f.f_savedlocals.length; i++) { PyObject v = (PyObject) (f.f_savedlocals[i]); stack.push(v); } - stack.push(Py.None); // put the generator input in here + Object generatorInput = f.getGeneratorInput(); + if (generatorInput instanceof PyException) { + throw (PyException)generatorInput; + } + stack.push((PyObject)generatorInput); // put the generator input in here f.f_savedlocals = null; } while (count < maxCount) { // XXX - replace with while(true) - opcode = co_code[next_instr]; if (opcode > Opcode.HAVE_ARGUMENT) { next_instr += 2; @@ -662,16 +667,6 @@ case Opcode.YIELD_VALUE: retval = stack.pop(); - // need to implement something like this when we reenter after a yield -// code.invokevirtual("org/python/core/PyFrame", "getGeneratorInput", "()" + $obj); -// code.dup(); -// code.instanceof_("org/python/core/PyException"); -// Label done2 = new Label(); -// code.ifeq(done2); -// code.checkcast("java/lang/Throwable"); -// code.athrow(); -// code.label(done2); -// code.checkcast("org/python/core/PyObject"); why = Why.YIELD; break; @@ -910,7 +905,7 @@ break; case Opcode.JUMP_ABSOLUTE: - next_instr = oparg - 1; // XXX - continue to a label is probably much better + next_instr = oparg; // XXX - continue to a label is probably much better break; case Opcode.GET_ITER: { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |