You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <pj...@us...> - 2009-10-03 20:35:17
|
Revision: 6829 http://jython.svn.sourceforge.net/jython/?rev=6829&view=rev Author: pjenvey Date: 2009-10-03 20:34:59 +0000 (Sat, 03 Oct 2009) Log Message: ----------- add the ability for the method exposer to optionally pass in the current ThreadState when a method signature requests it @ arg 0 Modified Paths: -------------- trunk/jython/src/org/python/expose/generate/ClassMethodExposer.java trunk/jython/src/org/python/expose/generate/InstanceMethodExposer.java trunk/jython/src/org/python/expose/generate/MethodExposer.java trunk/jython/src/org/python/expose/generate/PyTypes.java trunk/jython/tests/java/org/python/expose/generate/ExposedTypeProcessorTest.java trunk/jython/tests/java/org/python/expose/generate/MethodExposerTest.java trunk/jython/tests/java/org/python/expose/generate/SimpleExposed.java Modified: trunk/jython/src/org/python/expose/generate/ClassMethodExposer.java =================================================================== --- trunk/jython/src/org/python/expose/generate/ClassMethodExposer.java 2009-10-03 00:48:54 UTC (rev 6828) +++ trunk/jython/src/org/python/expose/generate/ClassMethodExposer.java 2009-10-03 20:34:59 UTC (rev 6829) @@ -29,12 +29,26 @@ private static Type[] getArgs(Type onType, String methodName, String desc) { Type[] args = Type.getArgumentTypes(desc); - if (args.length == 0 || !args[0].equals(PYTYPE)) { - throw new InvalidExposingException("The first argument to an ExposedClassMethod must be PyType[method=" - + onType.getClassName() + "." + methodName + "]"); + boolean needsThreadState = needsThreadState(args); + int offset = needsThreadState ? 1 : 0; + + if (args.length == offset || !args[offset].equals(PYTYPE)) { + String msg = String.format("ExposedClassMethod's first argument %smust be " + + "PyType[method=%s.%s]", + needsThreadState ? "(following ThreadState) " : "", + onType.getClassName(), methodName); + throw new InvalidExposingException(msg); } + + // Remove PyType from the exposed __call__'s args, it'll be already bound as self Type[] filledInArgs = new Type[args.length - 1]; - System.arraycopy(args, 1, filledInArgs, 0, filledInArgs.length); + if (needsThreadState) { + // ThreadState precedes PyType + filledInArgs[0] = args[0]; + System.arraycopy(args, 2, filledInArgs, 1, filledInArgs.length - 1); + } else { + System.arraycopy(args, 1, filledInArgs, 0, filledInArgs.length); + } return filledInArgs; } @@ -47,4 +61,13 @@ protected void checkSelf() { mv.visitTypeInsn(CHECKCAST, PYTYPE.getInternalName()); } + + @Override + protected void loadSelfAndThreadState() { + // ThreadState precedes self for ClassMethods, load it first if necessary + loadThreadState(); + // Push self on the stack so we can call it + get("self", PYOBJ); + checkSelf(); + } } Modified: trunk/jython/src/org/python/expose/generate/InstanceMethodExposer.java =================================================================== --- trunk/jython/src/org/python/expose/generate/InstanceMethodExposer.java 2009-10-03 00:48:54 UTC (rev 6828) +++ trunk/jython/src/org/python/expose/generate/InstanceMethodExposer.java 2009-10-03 20:34:59 UTC (rev 6829) @@ -99,7 +99,7 @@ + "', not a '"); } }); - mv.visitVarInsn(ALOAD, 1); + mv.visitVarInsn(ALOAD, !needsThreadState(args) ? 1 : 2); call(PYOBJ, "getType", PYTYPE); call(PYTYPE, "fastGetName", STRING); call(STRING_BUILDER, "append", STRING_BUILDER, STRING); Modified: trunk/jython/src/org/python/expose/generate/MethodExposer.java =================================================================== --- trunk/jython/src/org/python/expose/generate/MethodExposer.java 2009-10-03 00:48:54 UTC (rev 6828) +++ trunk/jython/src/org/python/expose/generate/MethodExposer.java 2009-10-03 20:34:59 UTC (rev 6829) @@ -132,14 +132,27 @@ } private void generateWideCall() { - startMethod("__call__", PYOBJ, APYOBJ, ASTRING); - get("self", PYOBJ); - checkSelf(); - mv.visitVarInsn(ALOAD, 1); - mv.visitVarInsn(ALOAD, 2); + boolean needsThreadState = needsThreadState(args); + int offset = needsThreadState ? 1 : 0; + Type[] callArgs; + + if (needsThreadState) { + callArgs = new Type[] {THREAD_STATE, APYOBJ, ASTRING}; + } else { + callArgs = new Type[] {APYOBJ, ASTRING}; + } + startMethod("__call__", PYOBJ, callArgs); + + loadSelfAndThreadState(); + mv.visitVarInsn(ALOAD, offset + 1); + mv.visitVarInsn(ALOAD, offset + 2); makeCall(); toPy(returnType); endMethod(ARETURN); + + if (needsThreadState) { + generateCallNoThreadState(callArgs); + } } private boolean hasDefault(int argIndex) { @@ -151,17 +164,25 @@ } private void generateCall(int numDefaults) { - int usedLocals = 1;// We always have one used local for self - Type[] callArgs = new Type[args.length - numDefaults]; - for(int i = 0; i < callArgs.length; i++) { + boolean needsThreadState = needsThreadState(args); + int requiredLength = args.length - numDefaults; + int offset = needsThreadState ? 1 : 0; + // We always have one used local for self, and possibly one for ThreadState + int usedLocals = 1 + offset; + Type[] callArgs = new Type[requiredLength]; + + if (needsThreadState) { + callArgs[0] = THREAD_STATE; + } + for(int i = offset; i < callArgs.length; i++) { callArgs[i] = PYOBJ; } startMethod("__call__", PYOBJ, callArgs); - // Push self on the stack so we can call it - get("self", PYOBJ); - checkSelf(); + + loadSelfAndThreadState(); // Push the passed in callArgs onto the stack, and convert them if necessary - for(int i = 0; i < callArgs.length; i++) { + int i; + for(i = offset; i < requiredLength; i++) { mv.visitVarInsn(ALOAD, usedLocals++); if(PRIMITIVES.containsKey(args[i])) { callStatic(PY, "py2" + args[i].getClassName(), args[i], PYOBJ); @@ -174,14 +195,47 @@ } } // Push the defaults onto the stack - for(int i = callArgs.length; i < args.length; i++) { + for(; i < args.length; i++) { pushDefault(getDefault(i), args[i]); } makeCall(); toPy(returnType); endMethod(ARETURN); + + if (needsThreadState) { + generateCallNoThreadState(callArgs); + } } + private void generateCallNoThreadState(Type[] callArgs) { + Type[] noThreadStateArgs = new Type[callArgs.length - 1]; + System.arraycopy(callArgs, 1, noThreadStateArgs, 0, noThreadStateArgs.length); + startMethod("__call__", PYOBJ, noThreadStateArgs); + + mv.visitVarInsn(ALOAD, 0); + callStatic(PY, "getThreadState", THREAD_STATE); + for (int i = 0; i < noThreadStateArgs.length; i++) { + mv.visitVarInsn(ALOAD, i + 1); + } + + call(thisType, "__call__", PYOBJ, callArgs); + endMethod(ARETURN); + } + + protected void loadSelfAndThreadState() { + // Push self on the stack so we can call it + get("self", PYOBJ); + checkSelf(); + // Load ThreadState if necessary + loadThreadState(); + } + + protected void loadThreadState() { + if (needsThreadState(args)) { + mv.visitVarInsn(ALOAD, 1); + } + } + protected abstract void checkSelf(); protected abstract void makeCall(); @@ -218,8 +272,14 @@ } } + protected static boolean needsThreadState(Type[] args) { + return args.length > 0 && args[0].equals(THREAD_STATE); + } + protected static boolean isWide(Type[] args) { - return args.length == 2 && args[0].equals(APYOBJ) && args[1].equals(ASTRING); + int offset = needsThreadState(args) ? 1 : 0; + return args.length == 2 + offset + && args[offset].equals(APYOBJ) && args[offset + 1].equals(ASTRING); } } Modified: trunk/jython/src/org/python/expose/generate/PyTypes.java =================================================================== --- trunk/jython/src/org/python/expose/generate/PyTypes.java 2009-10-03 00:48:54 UTC (rev 6828) +++ trunk/jython/src/org/python/expose/generate/PyTypes.java 2009-10-03 20:34:59 UTC (rev 6829) @@ -15,6 +15,7 @@ import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyType; +import org.python.core.ThreadState; import org.python.expose.ExposeAsSuperclass; import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedDelete; @@ -71,6 +72,8 @@ public static final Type BUILTIN_INFO = Type.getType(PyBuiltinCallable.Info.class); + public static final Type THREAD_STATE = Type.getType(ThreadState.class); + // Exposer Jython types public static final Type EXPOSED_TYPE = Type.getType(ExposedType.class); Modified: trunk/jython/tests/java/org/python/expose/generate/ExposedTypeProcessorTest.java =================================================================== --- trunk/jython/tests/java/org/python/expose/generate/ExposedTypeProcessorTest.java 2009-10-03 00:48:54 UTC (rev 6828) +++ trunk/jython/tests/java/org/python/expose/generate/ExposedTypeProcessorTest.java 2009-10-03 20:34:59 UTC (rev 6829) @@ -16,7 +16,7 @@ .getResourceAsStream("org/python/expose/generate/SimpleExposed.class"); ExposedTypeProcessor ice = new ExposedTypeProcessor(in); assertEquals("simpleexposed", ice.getName()); - assertEquals(19, ice.getMethodExposers().size()); + assertEquals(22, ice.getMethodExposers().size()); assertNotNull(ice.getNewExposer()); assertEquals(1, ice.getDescriptorExposers().size()); assertEquals("simpleexposed", ice.getTypeExposer().getName()); Modified: trunk/jython/tests/java/org/python/expose/generate/MethodExposerTest.java =================================================================== --- trunk/jython/tests/java/org/python/expose/generate/MethodExposerTest.java 2009-10-03 00:48:54 UTC (rev 6828) +++ trunk/jython/tests/java/org/python/expose/generate/MethodExposerTest.java 2009-10-03 20:34:59 UTC (rev 6829) @@ -6,6 +6,8 @@ import org.python.core.Py; import org.python.core.PyBuiltinCallable; import org.python.core.PyException; +import org.python.core.PyObject; +import org.python.core.ThreadState; import org.python.expose.MethodType; public class MethodExposerTest extends InterpTestCase implements Opcodes, PyTypes { @@ -226,6 +228,55 @@ assertEquals(3, bound.__call__(Py.newString("nothello"), Py.One).asInt()); } + public void testThreadState() throws Exception { + PyBuiltinCallable bound = createBound("needsThreadState", STRING, THREAD_STATE, STRING); + ThreadState ts = Py.getThreadState(); + PyObject expected = Py.newString("foo got state " + ts.hashCode()); + assertEquals(expected, bound.__call__(Py.getThreadState(), Py.newString("foo"))); + assertEquals(expected, bound.__call__(Py.newString("foo"))); + ts = new ThreadState(new Thread(), ts.systemState); + assertEquals(Py.newString("foo got state " + ts.hashCode()), + bound.__call__(ts, Py.newString("foo"))); + } + + public void testThreadStateFullArguments() throws Exception { + InstanceMethodExposer exp = new InstanceMethodExposer(Type.getType(SimpleExposed.class), + Opcodes.ACC_PUBLIC, + "needsThreadStateWide", + Type.getMethodDescriptor(Type.INT_TYPE, + new Type[] {THREAD_STATE, + APYOBJ, + ASTRING}), + "simpleexposed"); + PyBuiltinCallable bound = createBound(exp); + assertEquals(Py.Zero, bound.__call__(Py.getThreadState())); + assertEquals(Py.Zero, bound.__call__()); + assertEquals(Py.One, bound.__call__(Py.getThreadState(), Py.One)); + assertEquals(Py.One, bound.__call__(Py.One)); + } + + public void testThreadStateClassMethod() throws Exception { + ClassMethodExposer exp = new ClassMethodExposer(Type.getType(SimpleExposed.class), + Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, + "needsThreadStateClass", + Type.getMethodDescriptor(STRING, + new Type[] {THREAD_STATE, + PYTYPE, + STRING, + STRING}), + "simpleexposed", + new String[0], + new String[] {"null"}, + ""); + PyBuiltinCallable bound = createBound(exp); + ThreadState ts = Py.getThreadState(); + PyObject arg0 = Py.newString("bar"); + PyObject arg1 = Py.newString(" and extra"); + PyObject expected = Py.newString("bar got state " + ts.hashCode() + " got type and extra"); + assertEquals(expected, bound.__call__(Py.getThreadState(), arg0, arg1)); + assertEquals(expected, bound.__call__(arg0, arg1)); + } + public void test__new__() throws Exception { try { createExposer("__new__", VOID); Modified: trunk/jython/tests/java/org/python/expose/generate/SimpleExposed.java =================================================================== --- trunk/jython/tests/java/org/python/expose/generate/SimpleExposed.java 2009-10-03 00:48:54 UTC (rev 6828) +++ trunk/jython/tests/java/org/python/expose/generate/SimpleExposed.java 2009-10-03 20:34:59 UTC (rev 6829) @@ -6,6 +6,7 @@ import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyType; +import org.python.core.ThreadState; import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedDelete; import org.python.expose.ExposedGet; @@ -150,4 +151,32 @@ public String toStringVal = TO_STRING_RETURN; public static final String TO_STRING_RETURN = "A simple test class"; + + @ExposedMethod + public String needsThreadState(ThreadState state, String s) { + return needsThreadStateClass(state, null, s, null); + } + + @ExposedMethod + public int needsThreadStateWide(ThreadState state, PyObject[] args, String[] kws) { + if (state == null) { + return -1; + } + return args.length + kws.length; + } + + @ExposedClassMethod(defaults = {"null"}) + public static String needsThreadStateClass(ThreadState state, PyType onType, String s, + String possiblyNull) { + if (state != null) { + s += " got state " + state.hashCode(); + } + if (onType != null) { + s += " got type"; + } + if (possiblyNull != null) { + s += possiblyNull; + } + return s; + } } 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-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-02 20:29:09
|
Revision: 6826 http://jython.svn.sourceforge.net/jython/?rev=6826&view=rev Author: fwierzbicki Date: 2009-10-02 20:29:01 +0000 (Fri, 02 Oct 2009) Log Message: ----------- Initial import of the part of JRuby's CodegenUtils that we can use. Added Paths: ----------- trunk/jython/src/org/python/util/CodegenUtils.java Added: trunk/jython/src/org/python/util/CodegenUtils.java =================================================================== --- trunk/jython/src/org/python/util/CodegenUtils.java (rev 0) +++ trunk/jython/src/org/python/util/CodegenUtils.java 2009-10-02 20:29:01 UTC (rev 6826) @@ -0,0 +1,137 @@ +/* + * Initial code taken from Charlie Nutter's org.jruby.util.CodegenUtils. + */ + +package org.python.util; + +import java.util.Arrays; + +public class CodegenUtils { + + /** + * Creates a dotted class name from a path/package name + */ + public static String c(String p) { + return p.replace('/', '.'); + } + + /** + * Creates a class path name, from a Class. + */ + public static String p(Class n) { + return n.getName().replace('.','/'); + } + + /** + * Creates a class identifier of form Labc/abc;, from a Class. + */ + public static String ci(Class n) { + if (n.isArray()) { + n = n.getComponentType(); + if (n.isPrimitive()) { + if (n == Byte.TYPE) { + return "[B"; + } else if (n == Boolean.TYPE) { + return "[Z"; + } else if (n == Short.TYPE) { + return "[S"; + } else if (n == Character.TYPE) { + return "[C"; + } else if (n == Integer.TYPE) { + return "[I"; + } else if (n == Float.TYPE) { + return "[F"; + } else if (n == Double.TYPE) { + return "[D"; + } else if (n == Long.TYPE) { + return "[J"; + } else { + throw new RuntimeException("Unrecognized type in compiler: " + n.getName()); + } + } else { + return "[" + ci(n); + } + } else { + if (n.isPrimitive()) { + if (n == Byte.TYPE) { + return "B"; + } else if (n == Boolean.TYPE) { + return "Z"; + } else if (n == Short.TYPE) { + return "S"; + } else if (n == Character.TYPE) { + return "C"; + } else if (n == Integer.TYPE) { + return "I"; + } else if (n == Float.TYPE) { + return "F"; + } else if (n == Double.TYPE) { + return "D"; + } else if (n == Long.TYPE) { + return "J"; + } else if (n == Void.TYPE) { + return "V"; + } else { + throw new RuntimeException("Unrecognized type in compiler: " + n.getName()); + } + } else { + return "L" + p(n) + ";"; + } + } + } + + /** + * Create a method signature from the given param types and return values + */ + public static String sig(Class retval, Class... params) { + return sigParams(params) + ci(retval); + } + + public static String sig(Class retval, String descriptor, Class... params) { + return sigParams(descriptor, params) + ci(retval); + } + + public static String sigParams(Class... params) { + StringBuilder signature = new StringBuilder("("); + + for (int i = 0; i < params.length; i++) { + signature.append(ci(params[i])); + } + + signature.append(")"); + + return signature.toString(); + } + + public static String sigParams(String descriptor, Class... params) { + StringBuilder signature = new StringBuilder("("); + + signature.append(descriptor); + + for (int i = 0; i < params.length; i++) { + signature.append(ci(params[i])); + } + + signature.append(")"); + + return signature.toString(); + } + + public static Class[] params(Class... classes) { + return classes; + } + + public static Class[] params(Class cls, int times) { + Class[] classes = new Class[times]; + Arrays.fill(classes, cls); + return classes; + } + + public static Class[] params(Class cls1, Class clsFill, int times) { + Class[] classes = new Class[times + 1]; + Arrays.fill(classes, clsFill); + classes[0] = cls1; + return classes; + } + +} Property changes on: trunk/jython/src/org/python/util/CodegenUtils.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-02 04:06:12
|
Revision: 6824 http://jython.svn.sourceforge.net/jython/?rev=6824&view=rev Author: pjenvey Date: 2009-10-02 04:05:54 +0000 (Fri, 02 Oct 2009) Log Message: ----------- o convert PyFrame to exposed annotations o specify its cached type during construction to avoid repeated PyType.fromClass calls o fix the f_lineno value while tracing PyByteCode Modified Paths: -------------- trunk/jython/CoreExposed.includes trunk/jython/src/org/python/core/PyFrame.java trunk/jython/src/org/python/core/PyTraceback.java Modified: trunk/jython/CoreExposed.includes =================================================================== --- trunk/jython/CoreExposed.includes 2009-10-02 03:45:27 UTC (rev 6823) +++ trunk/jython/CoreExposed.includes 2009-10-02 04:05:54 UTC (rev 6824) @@ -17,6 +17,7 @@ org/python/core/PyEllipsis.class org/python/core/PyFile.class org/python/core/PyFloat.class +org/python/core/PyFrame.class org/python/core/PyFrozenSet.class org/python/core/PyFunction.class org/python/core/PyGenerator.class Modified: trunk/jython/src/org/python/core/PyFrame.java =================================================================== --- trunk/jython/src/org/python/core/PyFrame.java 2009-10-02 03:45:27 UTC (rev 6823) +++ trunk/jython/src/org/python/core/PyFrame.java 2009-10-02 04:05:54 UTC (rev 6824) @@ -4,50 +4,63 @@ */ package org.python.core; +import org.python.expose.ExposedDelete; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedSet; +import org.python.expose.ExposedType; + /** * A Python frame object. */ +@ExposedType(name = "frame", isBaseType = false) public class PyFrame extends PyObject { + public static final PyType TYPE = PyType.fromClass(PyFrame.class); + /** Previous frame or null. */ + @ExposedGet public PyFrame f_back; /** The underyling code object. */ + @ExposedGet public PyBaseCode f_code; - /** Local symbol table. */ - public PyObject f_locals; + /** builtin symbol table. */ + @ExposedGet + public PyObject f_builtins; /** Global symbol table. */ + @ExposedGet public PyObject f_globals; + /** Local symbol table. */ + public PyObject f_locals; + /** Current line number. */ public int f_lineno; - /** builtin symbol table. */ - public PyObject f_builtins; - public PyObject[] f_fastlocals; /** Nested scopes: cell + free env. */ public PyCell[] f_env; + private int env_j = 0; + public int f_ncells; public int f_nfreevars; + @ExposedGet public int f_lasti; public Object[] f_savedlocals; - private int env_j = 0; - private Object generatorInput = Py.None; /** with context exits - used by generated bytecode */ public PyObject[] f_exits; - /** an interface to functions suitable for tracing, e.g. via sys.settrace(). */ + /** An interface to functions suitable for tracing, e.g. via sys.settrace(). */ public TraceFunction tracefunc; private static final String NAME_ERROR_MSG = "name '%.200s' is not defined"; @@ -57,10 +70,8 @@ private static final String UNBOUNDLOCAL_ERROR_MSG = "local variable '%.200s' referenced before assignment"; - private static final String[] __members__ = {"f_back", "f_code", "f_locals", "f_globals", - "f_lineno", "f_builtins", "f_trace"}; - public PyFrame(PyBaseCode code, PyObject locals, PyObject globals, PyObject builtins) { + super(TYPE); f_code = code; f_locals = locals; f_globals = globals; @@ -112,14 +123,6 @@ } } - public PyObject __dir__() { - PyString members[] = new PyString[__members__.length]; - for (int i = 0; i < __members__.length; i++) { - members[i] = new PyString(__members__[i]); - } - return new PyList(members); - } - void setGeneratorInput(Object value) { generatorInput = value; } @@ -134,58 +137,13 @@ return generatorInput; } - private void throwReadonly(String name) { - for (String member : __members__) { - if (member == name) { - throw Py.TypeError("readonly attribute"); - } - } - throw Py.AttributeError(name); - } - - public void __setattr__(String name, PyObject value) { - // In CPython, some of the frame's attributes are read/writeable - if (name == "f_trace") { - tracefunc = new PythonTraceFunction(value); - } else { - throwReadonly(name); - } - // not yet implemented: - // f_exc_type - // f_exc_value - // f_exc_traceback - } - - public void __delattr__(String name) { - if (name == "f_trace") { - tracefunc = null; - } else { - throwReadonly(name); - } - // not yet implemented: - // f_exc_type - // f_exc_value - // f_exc_traceback - } - - public PyObject __findattr_ex__(String name) { - if (name == "f_locals") { - return getLocals(); - } else if (name == "f_trace") { - if (tracefunc instanceof PythonTraceFunction) { - return ((PythonTraceFunction)tracefunc).tracefunc; - } - return Py.None; - } - return super.__findattr_ex__(name); - } - /** * Return the locals dict. First merges the fast locals into * f_locals, then returns the updated f_locals. * * @return a PyObject mapping of locals */ + @ExposedGet(name = "f_locals") public PyObject getLocals() { if (f_locals == null) { f_locals = new PyStringMap(); @@ -218,6 +176,22 @@ return f_locals; } + @ExposedGet(name = "f_trace") + public PyObject getTrace() { + return tracefunc instanceof PythonTraceFunction ? + ((PythonTraceFunction)tracefunc).tracefunc : Py.None; + } + + @ExposedSet(name = "f_trace") + public void setTrace(PyObject trace) { + tracefunc = new PythonTraceFunction(trace); + } + + @ExposedDelete(name = "f_trace") + public void delTrace() { + tracefunc = null; + } + /** * Return the current f_locals dict. * @@ -243,8 +217,9 @@ } } + @ExposedGet(name = "f_lineno") public int getline() { - return f_code.getline(this); + return tracefunc != null ? f_lineno : f_code.getline(this); } public PyObject getlocal(int index) { Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2009-10-02 03:45:27 UTC (rev 6823) +++ trunk/jython/src/org/python/core/PyTraceback.java 2009-10-02 04:05:54 UTC (rev 6824) @@ -26,7 +26,7 @@ super(TYPE); tb_next = next; tb_frame = frame; - tb_lineno = frame.getline(); + tb_lineno = frame.f_code.getline(frame); } private String tracebackInfo() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-02 03:45:45
|
Revision: 6823 http://jython.svn.sourceforge.net/jython/?rev=6823&view=rev Author: pjenvey Date: 2009-10-02 03:45:27 +0000 (Fri, 02 Oct 2009) Log Message: ----------- pass the cached type through constructors Modified Paths: -------------- trunk/jython/src/org/python/antlr/PythonTree.java trunk/jython/src/org/python/core/PyDictionary.java trunk/jython/src/org/python/core/PyFunction.java trunk/jython/src/org/python/core/PyGenerator.java trunk/jython/src/org/python/core/PyMethod.java trunk/jython/src/org/python/core/PyStaticMethod.java trunk/jython/src/org/python/core/PyTraceback.java Modified: trunk/jython/src/org/python/antlr/PythonTree.java =================================================================== --- trunk/jython/src/org/python/antlr/PythonTree.java 2009-10-02 01:46:27 UTC (rev 6822) +++ trunk/jython/src/org/python/antlr/PythonTree.java 2009-10-02 03:45:27 UTC (rev 6823) @@ -25,6 +25,7 @@ } public PythonTree(PyType subType) { + super(subType); node = new CommonTree(); } Modified: trunk/jython/src/org/python/core/PyDictionary.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionary.java 2009-10-02 01:46:27 UTC (rev 6822) +++ trunk/jython/src/org/python/core/PyDictionary.java 2009-10-02 03:45:27 UTC (rev 6823) @@ -33,6 +33,7 @@ * Create an empty dictionary. */ public PyDictionary() { + super(TYPE); table = Generic.concurrentMap(); } @@ -48,6 +49,7 @@ * Create a new dictionary which is based on given map. */ public PyDictionary(Map<PyObject, PyObject> t) { + super(TYPE); table = Generic.concurrentMap(); table.putAll(t); } Modified: trunk/jython/src/org/python/core/PyFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyFunction.java 2009-10-02 01:46:27 UTC (rev 6822) +++ trunk/jython/src/org/python/core/PyFunction.java 2009-10-02 03:45:27 UTC (rev 6823) @@ -57,6 +57,7 @@ public PyFunction(PyObject globals, PyObject[] defaults, PyCode code, PyObject doc, PyObject[] closure_cells) { + super(TYPE); func_globals = globals; __name__ = code.co_name; __doc__ = doc != null ? doc : Py.None; Modified: trunk/jython/src/org/python/core/PyGenerator.java =================================================================== --- trunk/jython/src/org/python/core/PyGenerator.java 2009-10-02 01:46:27 UTC (rev 6822) +++ trunk/jython/src/org/python/core/PyGenerator.java 2009-10-02 03:45:27 UTC (rev 6823) @@ -7,6 +7,8 @@ @ExposedType(name = "generator", base = PyObject.class, isBaseType = false) public class PyGenerator extends PyIterator { + public static final PyType TYPE = PyType.fromClass(PyGenerator.class); + @ExposedGet protected PyFrame gi_frame; @@ -18,6 +20,7 @@ private PyObject closure; public PyGenerator(PyFrame frame, PyObject closure) { + super(TYPE); gi_frame = frame; this.closure = closure; Modified: trunk/jython/src/org/python/core/PyMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyMethod.java 2009-10-02 01:46:27 UTC (rev 6822) +++ trunk/jython/src/org/python/core/PyMethod.java 2009-10-02 03:45:27 UTC (rev 6823) @@ -28,6 +28,7 @@ public PyObject im_self; public PyMethod(PyObject function, PyObject self, PyObject type) { + super(TYPE); if (self == Py.None){ self = null; } Modified: trunk/jython/src/org/python/core/PyStaticMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyStaticMethod.java 2009-10-02 01:46:27 UTC (rev 6822) +++ trunk/jython/src/org/python/core/PyStaticMethod.java 2009-10-02 03:45:27 UTC (rev 6823) @@ -15,6 +15,7 @@ protected PyObject callable; public PyStaticMethod(PyObject callable) { + super(TYPE); this.callable = callable; } Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2009-10-02 01:46:27 UTC (rev 6822) +++ trunk/jython/src/org/python/core/PyTraceback.java 2009-10-02 03:45:27 UTC (rev 6823) @@ -23,6 +23,7 @@ public int tb_lineno; public PyTraceback(PyTraceback next, PyFrame frame) { + super(TYPE); tb_next = next; tb_frame = frame; tb_lineno = frame.getline(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-02 01:46:49
|
Revision: 6822 http://jython.svn.sourceforge.net/jython/?rev=6822&view=rev Author: pjenvey Date: 2009-10-02 01:46:27 +0000 (Fri, 02 Oct 2009) Log Message: ----------- allow exec of PyByteCode objects and simplify pycimport so it's not creating frames directly Modified Paths: -------------- trunk/jython/Lib/pycimport.py trunk/jython/src/org/python/core/Py.java Modified: trunk/jython/Lib/pycimport.py =================================================================== --- trunk/jython/Lib/pycimport.py 2009-10-02 00:59:40 UTC (rev 6821) +++ trunk/jython/Lib/pycimport.py 2009-10-02 01:46:27 UTC (rev 6822) @@ -1,7 +1,6 @@ -import sys +import imp import os - -from org.python.core import imp as _imp, PyFrame as _Frame, Py as _Py +import sys from marshal import Unmarshaller __debugging__ = False @@ -16,11 +15,11 @@ return magic, mtime def __makeModule(name, code, path): - module = _imp.addModule(name) - builtins = _Py.getSystemState().builtins - frame = _Frame(code, module.__dict__, module.__dict__, builtins) + module = sys.modules.get(name) + if not module: + module = sys.modules[name] = imp.new_module(name) module.__file__ = path - code.call(frame) # execute module code + exec code in module.__dict__ return module class __Importer(object): Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2009-10-02 00:59:40 UTC (rev 6821) +++ trunk/jython/src/org/python/core/Py.java 2009-10-02 01:46:27 UTC (rev 6822) @@ -1178,8 +1178,7 @@ return makeException(null); } - public static PyObject runCode(PyCode code, PyObject locals, - PyObject globals) { + public static PyObject runCode(PyCode code, PyObject locals, PyObject globals) { PyFrame f; ThreadState ts = getThreadState(); if (locals == null || locals == Py.None) { @@ -1194,13 +1193,12 @@ globals = ts.frame.f_globals; } - PyTableCode tc = null; - if (code instanceof PyTableCode) { - tc = (PyTableCode) code; + PyBaseCode baseCode = null; + if (code instanceof PyBaseCode) { + baseCode = (PyBaseCode) code; } - f = new PyFrame(tc, locals, globals, - Py.getSystemState().getBuiltins()); + f = new PyFrame(baseCode, locals, globals, Py.getSystemState().getBuiltins()); return code.call(ts, f); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-02 00:59:47
|
Revision: 6821 http://jython.svn.sourceforge.net/jython/?rev=6821&view=rev Author: pjenvey Date: 2009-10-02 00:59:40 +0000 (Fri, 02 Oct 2009) Log Message: ----------- small cleanup Modified Paths: -------------- trunk/jython/src/org/python/core/PyFrame.java Modified: trunk/jython/src/org/python/core/PyFrame.java =================================================================== --- trunk/jython/src/org/python/core/PyFrame.java 2009-10-01 20:48:58 UTC (rev 6820) +++ trunk/jython/src/org/python/core/PyFrame.java 2009-10-02 00:59:40 UTC (rev 6821) @@ -1,26 +1,35 @@ -// Copyright (c) Corporation for National Research Initiatives +/* + * Copyright (c) Corporation for National Research Initiatives + * Copyright (c) Jython Developers + */ package org.python.core; /** * A Python frame object. */ -public class PyFrame extends PyObject -{ +public class PyFrame extends PyObject { + + /** Previous frame or null. */ public PyFrame f_back; + /** The underyling code object. */ public PyBaseCode f_code; + /** Local symbol table. */ public PyObject f_locals; + /** Global symbol table. */ public PyObject f_globals; + /** Current line number. */ public int f_lineno; + /** builtin symbol table. */ public PyObject f_builtins; public PyObject[] f_fastlocals; - /** nested scopes: cell + free env. */ + /** Nested scopes: cell + free env. */ public PyCell[] f_env; public int f_ncells; @@ -35,11 +44,10 @@ private Object generatorInput = Py.None; - // with context exits - used by generated bytecode + /** with context exits - used by generated bytecode */ public PyObject[] f_exits; - - /** an interface to functions suitable for tracing, e.g. via - * sys.settrace(). */ + + /** an interface to functions suitable for tracing, e.g. via sys.settrace(). */ public TraceFunction tracefunc; private static final String NAME_ERROR_MSG = "name '%.200s' is not defined"; @@ -52,9 +60,7 @@ private static final String[] __members__ = {"f_back", "f_code", "f_locals", "f_globals", "f_lineno", "f_builtins", "f_trace"}; - public PyFrame(PyBaseCode code, PyObject locals, PyObject globals, - PyObject builtins) - { + public PyFrame(PyBaseCode code, PyObject locals, PyObject globals, PyObject builtins) { f_code = code; f_locals = locals; f_globals = globals; @@ -101,7 +107,7 @@ f_env[env_j] = new PyCell(); } // inherit the freevars - for (int i=0; env_j < ntotal; i++, env_j++) { + for (int i = 0; env_j < ntotal; i++, env_j++) { f_env[env_j] = (PyCell)freevars.pyget(i); } } @@ -123,7 +129,7 @@ generatorInput = Py.None; return input; } - + public Object checkGeneratorInput() { return generatorInput; } @@ -223,13 +229,13 @@ return f_locals; } - // - // Track the current line number. Called by generated code. - // - // This is not to be confused with the CPython method - // frame_setlineno() which causes the interpreter to jump to - // the given line. - // + /** + * Track the current line number. Called by generated code. + * + * This is not to be confused with the CPython method + * frame_setlineno() which causes the interpreter to jump to + * the given line. + */ public void setline(int line) { f_lineno = line; if (tracefunc != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-01 20:49:05
|
Revision: 6820 http://jython.svn.sourceforge.net/jython/?rev=6820&view=rev Author: fwierzbicki Date: 2009-10-01 20:48:58 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Added a comment for trailing whitespace handling in single mode. Tobias asked me what it did and it took way too long to answer :) Modified Paths: -------------- trunk/jython/grammar/Python.g Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2009-10-01 20:11:08 UTC (rev 6819) +++ trunk/jython/grammar/Python.g 2009-10-01 20:48:58 UTC (rev 6820) @@ -2030,6 +2030,15 @@ } } } else if (this.single && newlines == 1) { + // This is here for this case in interactive mode: + // + // def foo(): + // print 1 + // <spaces but no code> + // + // The above would complete in interactive mode instead + // of giving ... to wait for more input. + // throw new ParseException("Trailing space in single mode."); } else { // make a string of n newlines This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-01 20:11:21
|
Revision: 6819 http://jython.svn.sourceforge.net/jython/?rev=6819&view=rev Author: fwierzbicki Date: 2009-10-01 20:11:08 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Remove useless little inner subclasses, which where there just to add a behavior to nextToken() in Python.g -- since we override nextToken() in Python.g anyway, I relocated the functionality there. Modified Paths: -------------- trunk/jython/grammar/Python.g trunk/jython/grammar/PythonPartial.g trunk/jython/src/org/python/antlr/BaseParser.java trunk/jython/src/org/python/core/ParserFacade.java trunk/jython/tests/java/org/python/antlr/PythonPartialTester.java trunk/jython/tests/java/org/python/antlr/PythonTreeTester.java Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2009-10-01 01:25:40 UTC (rev 6818) +++ trunk/jython/grammar/Python.g 2009-10-01 20:11:08 UTC (rev 6819) @@ -228,6 +228,7 @@ * remain). */ public Token nextToken() { + startPos = getCharPositionInLine(); while (true) { state.token = null; state.channel = Token.DEFAULT_CHANNEL; Modified: trunk/jython/grammar/PythonPartial.g =================================================================== --- trunk/jython/grammar/PythonPartial.g 2009-10-01 01:25:40 UTC (rev 6818) +++ trunk/jython/grammar/PythonPartial.g 2009-10-01 20:11:08 UTC (rev 6819) @@ -121,6 +121,7 @@ * remain). */ public Token nextToken() { + startPos = getCharPositionInLine(); while (true) { state.token = null; state.channel = Token.DEFAULT_CHANNEL; Modified: trunk/jython/src/org/python/antlr/BaseParser.java =================================================================== --- trunk/jython/src/org/python/antlr/BaseParser.java 2009-10-01 01:25:40 UTC (rev 6818) +++ trunk/jython/src/org/python/antlr/BaseParser.java 2009-10-01 20:11:08 UTC (rev 6819) @@ -31,39 +31,10 @@ this.errorHandler = eh; } - public static class PyLexer extends PythonLexer { - public PyLexer(CharStream lexer, boolean single) { - super(lexer); - this.single = single; - } - - public PyLexer(CharStream lexer) { - this(lexer, false); - } - - - @Override - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - - public static class PyPartialLexer extends PythonPartialLexer { - public PyPartialLexer(CharStream lexer) { - super(lexer); - } - - @Override - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - private PythonParser setupParser(boolean single) { - PythonLexer lexer = new PyLexer(charStream, single); + PythonLexer lexer = new PythonLexer(charStream); lexer.setErrorHandler(errorHandler); + lexer.single = single; CommonTokenStream tokens = new CommonTokenStream(lexer); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename, single); tokens = new CommonTokenStream(indentedSource); Modified: trunk/jython/src/org/python/core/ParserFacade.java =================================================================== --- trunk/jython/src/org/python/core/ParserFacade.java 2009-10-01 01:25:40 UTC (rev 6818) +++ trunk/jython/src/org/python/core/ParserFacade.java 2009-10-01 20:11:08 UTC (rev 6819) @@ -232,7 +232,7 @@ try { bufreader.reset(); CharStream cs = new NoCloseReaderStream(bufreader); - lexer = new BaseParser.PyPartialLexer(cs); + lexer = new PythonPartialLexer(cs); CommonTokenStream tokens = new CommonTokenStream(lexer); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); tokens = new CommonTokenStream(indentedSource); Modified: trunk/jython/tests/java/org/python/antlr/PythonPartialTester.java =================================================================== --- trunk/jython/tests/java/org/python/antlr/PythonPartialTester.java 2009-10-01 01:25:40 UTC (rev 6818) +++ trunk/jython/tests/java/org/python/antlr/PythonPartialTester.java 2009-10-01 20:11:08 UTC (rev 6819) @@ -14,9 +14,8 @@ try { PythonTree result = null; CharStream input = new ANTLRFileStream(args[0]); - PythonPartialLexer lexer = new BaseParser.PyPartialLexer(input); + PythonPartialLexer lexer = new PythonPartialLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); - //PythonTokenSource indentedSource = new PythonTokenSource(tokens); PythonTokenSource indentedSource = new PythonTokenSource(tokens, "<test>"); tokens = new CommonTokenStream(indentedSource); PythonPartialParser parser = new PythonPartialParser(tokens); Modified: trunk/jython/tests/java/org/python/antlr/PythonTreeTester.java =================================================================== --- trunk/jython/tests/java/org/python/antlr/PythonTreeTester.java 2009-10-01 01:25:40 UTC (rev 6818) +++ trunk/jython/tests/java/org/python/antlr/PythonTreeTester.java 2009-10-01 20:11:08 UTC (rev 6819) @@ -30,7 +30,7 @@ //ErrorHandler eh = new ListErrorHandler(); ErrorHandler eh = new FailFastHandler(); CharStream input = new ANTLRFileStream(args[0]); - PythonLexer lexer = new BaseParser.PyLexer(input); + PythonLexer lexer = new PythonLexer(input); lexer.setErrorHandler(eh); CommonTokenStream tokens = new CommonTokenStream(lexer); PythonTokenSource indentedSource = new PythonTokenSource(tokens, args[0]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-01 01:25:52
|
Revision: 6818 http://jython.svn.sourceforge.net/jython/?rev=6818&view=rev Author: fwierzbicki Date: 2009-10-01 01:25:40 +0000 (Thu, 01 Oct 2009) Log Message: ----------- svn:ignore *$py.class in these. Property Changed: ---------------- trunk/jython/Lib/collections/ trunk/jython/Lib/compiler/ trunk/jython/Lib/distutils/ trunk/jython/Lib/distutils/command/ trunk/jython/Lib/distutils/tests/ trunk/jython/Lib/modjy/ trunk/jython/Lib/test/bugs/ trunk/jython/Lib/test/bugs/pr133/ trunk/jython/Lib/test/pbcvm/test/ trunk/jython/Lib/test/pyservlet/ trunk/jython/Lib/test/test_metaclass_support/ trunk/jython/Lib/test/zxjdbc/ trunk/jython/Lib/xml/etree/ trunk/jython/Lib/xml/parsers/ Property changes on: trunk/jython/Lib/collections ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/compiler ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/distutils ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/distutils/command ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/distutils/tests ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/modjy ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/test/bugs ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/test/bugs/pr133 ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/test/pbcvm/test ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/test/pyservlet ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/test/test_metaclass_support ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/test/zxjdbc ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/xml/etree ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/Lib/xml/parsers ___________________________________________________________________ Added: svn:ignore + *$py.class This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-01 01:16:50
|
Revision: 6817 http://jython.svn.sourceforge.net/jython/?rev=6817&view=rev Author: fwierzbicki Date: 2009-10-01 01:16:13 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Merged revisions 6762-6763,6766-6785,6788-6789,6795-6797,6800,6807-6808,6812,6814 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r6762 | zyasoft | 2009-09-07 16:41:45 -0400 (Mon, 07 Sep 2009) | 4 lines Fixed regression where threading._Lock, _RLock were no longer available as synonyms to Lock and RLock respectively, which Twisted needs. Added a test case to prevent recurrence. This resolves #1079. ........ r6763 | zyasoft | 2009-09-07 17:48:20 -0400 (Mon, 07 Sep 2009) | 5 lines CodeCompiler#visitAssert now looks up the AssertionError by using PyFrame#getglobal, so user code can redefine the behavior of assert. Fixes #1461 Bumped bytecode magic. ........ r6766 | pjenvey | 2009-09-08 22:58:36 -0400 (Tue, 08 Sep 2009) | 4 lines don't assume posix fixes #1425 thanks Matthew L Daniel ........ r6767 | pjenvey | 2009-09-08 23:06:20 -0400 (Tue, 08 Sep 2009) | 3 lines fix os.popen*/popen2 to only invoke a shell if cmd is a string refs http://bugs.python.org/issue5329 ........ r6768 | pjenvey | 2009-09-08 23:24:04 -0400 (Tue, 08 Sep 2009) | 3 lines fix array.to/fromfile on files in + mode fixes #1457 ........ r6769 | pjenvey | 2009-09-08 23:45:43 -0400 (Tue, 08 Sep 2009) | 4 lines fix __cmp__ specifying the wrong array type to lookup_where triggering an ArrayStoreException in some cases fixes #1382 ........ r6770 | pjenvey | 2009-09-08 23:47:22 -0400 (Tue, 08 Sep 2009) | 2 lines regen per r6769 ........ r6771 | pjenvey | 2009-09-09 00:16:49 -0400 (Wed, 09 Sep 2009) | 3 lines allow hashlib updating from arrays fixes #1443 ........ r6772 | pjenvey | 2009-09-09 00:59:15 -0400 (Wed, 09 Sep 2009) | 3 lines allow zlib input from arrays fixes #1444 ........ r6773 | pjenvey | 2009-09-09 01:47:17 -0400 (Wed, 09 Sep 2009) | 1 line whitespace ........ r6774 | fwierzbicki | 2009-09-09 08:11:47 -0400 (Wed, 09 Sep 2009) | 2 lines tab -> spaces. ........ r6775 | fwierzbicki | 2009-09-09 12:59:20 -0400 (Wed, 09 Sep 2009) | 2 lines Cleanup. ........ r6776 | fwierzbicki | 2009-09-09 13:28:32 -0400 (Wed, 09 Sep 2009) | 3 lines Add PyList testing for http://bugs.jython.org/issue1419, but it will also be a good place for testing the Java List interface of PyList in the future. ........ r6777 | fwierzbicki | 2009-09-09 13:35:38 -0400 (Wed, 09 Sep 2009) | 3 lines Test PyTuple for http://bugs.jython.org/issue1419 "Bug in PyTuple.indexOf and PyList.indexOf". ........ r6778 | fwierzbicki | 2009-09-09 13:47:39 -0400 (Wed, 09 Sep 2009) | 2 lines Give tests non-stupid names. ........ r6779 | fwierzbicki | 2009-09-09 13:59:05 -0400 (Wed, 09 Sep 2009) | 2 lines Also test the toArray() bugs fixed by Andrea's patch applied by Tobias. ........ r6780 | pjenvey | 2009-09-10 23:35:35 -0400 (Thu, 10 Sep 2009) | 4 lines support multiple ResultSets via cursor.nextset. to accommodate this staticFetch Statements are no longer immediately closed after execute (unless an exception was thrown), like dynamicFetch ........ r6781 | cgroves | 2009-09-11 01:22:00 -0400 (Fri, 11 Sep 2009) | 1 line Widening, standards ........ r6782 | pjenvey | 2009-09-11 01:34:56 -0400 (Fri, 11 Sep 2009) | 4 lines o fix PyTuple/List.equals not trying rich comparison (_eq) to all other PyObjects like PyObject.equals does o no need to synchronize all of PyList.equals ........ r6783 | pjenvey | 2009-09-11 01:52:44 -0400 (Fri, 11 Sep 2009) | 1 line cleanup ........ r6784 | zyasoft | 2009-09-11 02:44:19 -0400 (Fri, 11 Sep 2009) | 4 lines Added with-statement support to zxJDBC: * PyConnection - commit if no exception, otherwise rollback * PyCursor - always close this resource ........ r6785 | cgroves | 2009-09-11 02:55:34 -0400 (Fri, 11 Sep 2009) | 3 lines Use the builtin codecs when nothing is found in the registry. Fixes issue 1458. ........ r6788 | zyasoft | 2009-09-11 22:24:31 -0400 (Fri, 11 Sep 2009) | 1 line Updated NEWS re zxJDBC support of with-statement ........ r6789 | fwierzbicki | 2009-09-12 14:14:14 -0400 (Sat, 12 Sep 2009) | 2 lines Update versions. ........ r6795 | pjenvey | 2009-09-13 19:30:43 -0400 (Sun, 13 Sep 2009) | 1 line add @Overrides ........ r6796 | pjenvey | 2009-09-13 21:05:23 -0400 (Sun, 13 Sep 2009) | 4 lines force real O_APPEND for files' 'a' mode by going through FileOutputStream, otherwise emulate it with a performance hit for 'a+' mode fixes #1466 ........ r6797 | pjenvey | 2009-09-13 21:49:05 -0400 (Sun, 13 Sep 2009) | 1 line actually test 'a+' ........ r6800 | fwierzbicki | 2009-09-17 00:14:04 -0400 (Thu, 17 Sep 2009) | 2 lines Remove modules that now have modified versions living in our Lib/ ........ r6807 | fwierzbicki | 2009-09-23 20:16:35 -0400 (Wed, 23 Sep 2009) | 2 lines Update README for rc3. ........ r6808 | fwierzbicki | 2009-09-23 20:17:16 -0400 (Wed, 23 Sep 2009) | 2 lines Finish updating README for rc3. ........ r6812 | fwierzbicki | 2009-09-26 12:14:48 -0400 (Sat, 26 Sep 2009) | 2 lines Update README and version numbering. ........ r6814 | fwierzbicki | 2009-09-26 21:34:11 -0400 (Sat, 26 Sep 2009) | 2 lines Removed unused import from thread.java, expanded javadoc package scan. ........ Modified Paths: -------------- branches/indy/CPythonLib.includes branches/indy/Lib/distutils/util.py branches/indy/Lib/popen2.py branches/indy/Lib/test/test_array_jy.py branches/indy/Lib/test/test_cmp_jy.py branches/indy/Lib/test/test_hashlib_jy.py branches/indy/Lib/test/test_seq_jy.py branches/indy/Lib/test/test_threading_jy.py branches/indy/Lib/threading.py branches/indy/Lib/zlib.py branches/indy/NEWS branches/indy/README.txt branches/indy/build.xml branches/indy/src/com/ziclix/python/sql/PyConnection.java branches/indy/src/com/ziclix/python/sql/PyCursor.java branches/indy/src/org/python/antlr/PythonTree.java branches/indy/src/org/python/antlr/ast/AssertDerived.java branches/indy/src/org/python/antlr/ast/AssignDerived.java branches/indy/src/org/python/antlr/ast/AttributeDerived.java branches/indy/src/org/python/antlr/ast/AugAssignDerived.java branches/indy/src/org/python/antlr/ast/BinOpDerived.java branches/indy/src/org/python/antlr/ast/BoolOpDerived.java branches/indy/src/org/python/antlr/ast/BreakDerived.java branches/indy/src/org/python/antlr/ast/CallDerived.java branches/indy/src/org/python/antlr/ast/ClassDefDerived.java branches/indy/src/org/python/antlr/ast/CompareDerived.java branches/indy/src/org/python/antlr/ast/ContinueDerived.java branches/indy/src/org/python/antlr/ast/DeleteDerived.java branches/indy/src/org/python/antlr/ast/DictDerived.java branches/indy/src/org/python/antlr/ast/EllipsisDerived.java branches/indy/src/org/python/antlr/ast/ExceptHandlerDerived.java branches/indy/src/org/python/antlr/ast/ExecDerived.java branches/indy/src/org/python/antlr/ast/ExprDerived.java branches/indy/src/org/python/antlr/ast/ExpressionDerived.java branches/indy/src/org/python/antlr/ast/ExtSliceDerived.java branches/indy/src/org/python/antlr/ast/ForDerived.java branches/indy/src/org/python/antlr/ast/FunctionDefDerived.java branches/indy/src/org/python/antlr/ast/GeneratorExpDerived.java branches/indy/src/org/python/antlr/ast/GlobalDerived.java branches/indy/src/org/python/antlr/ast/IfDerived.java branches/indy/src/org/python/antlr/ast/IfExpDerived.java branches/indy/src/org/python/antlr/ast/ImportDerived.java branches/indy/src/org/python/antlr/ast/ImportFromDerived.java branches/indy/src/org/python/antlr/ast/IndexDerived.java branches/indy/src/org/python/antlr/ast/InteractiveDerived.java branches/indy/src/org/python/antlr/ast/LambdaDerived.java branches/indy/src/org/python/antlr/ast/ListCompDerived.java branches/indy/src/org/python/antlr/ast/ListDerived.java branches/indy/src/org/python/antlr/ast/ModuleDerived.java branches/indy/src/org/python/antlr/ast/NameDerived.java branches/indy/src/org/python/antlr/ast/NumDerived.java branches/indy/src/org/python/antlr/ast/PassDerived.java branches/indy/src/org/python/antlr/ast/PrintDerived.java branches/indy/src/org/python/antlr/ast/RaiseDerived.java branches/indy/src/org/python/antlr/ast/ReprDerived.java branches/indy/src/org/python/antlr/ast/ReturnDerived.java branches/indy/src/org/python/antlr/ast/SliceDerived.java branches/indy/src/org/python/antlr/ast/StrDerived.java branches/indy/src/org/python/antlr/ast/SubscriptDerived.java branches/indy/src/org/python/antlr/ast/SuiteDerived.java branches/indy/src/org/python/antlr/ast/TryExceptDerived.java branches/indy/src/org/python/antlr/ast/TryFinallyDerived.java branches/indy/src/org/python/antlr/ast/TupleDerived.java branches/indy/src/org/python/antlr/ast/UnaryOpDerived.java branches/indy/src/org/python/antlr/ast/WhileDerived.java branches/indy/src/org/python/antlr/ast/WithDerived.java branches/indy/src/org/python/antlr/ast/YieldDerived.java branches/indy/src/org/python/antlr/ast/aliasDerived.java branches/indy/src/org/python/antlr/ast/argumentsDerived.java branches/indy/src/org/python/antlr/ast/comprehensionDerived.java branches/indy/src/org/python/antlr/ast/keywordDerived.java branches/indy/src/org/python/antlr/op/AddDerived.java branches/indy/src/org/python/antlr/op/AndDerived.java branches/indy/src/org/python/antlr/op/AugLoadDerived.java branches/indy/src/org/python/antlr/op/AugStoreDerived.java branches/indy/src/org/python/antlr/op/BitAndDerived.java branches/indy/src/org/python/antlr/op/BitOrDerived.java branches/indy/src/org/python/antlr/op/BitXorDerived.java branches/indy/src/org/python/antlr/op/DelDerived.java branches/indy/src/org/python/antlr/op/DivDerived.java branches/indy/src/org/python/antlr/op/EqDerived.java branches/indy/src/org/python/antlr/op/FloorDivDerived.java branches/indy/src/org/python/antlr/op/GtDerived.java branches/indy/src/org/python/antlr/op/GtEDerived.java branches/indy/src/org/python/antlr/op/InDerived.java branches/indy/src/org/python/antlr/op/InvertDerived.java branches/indy/src/org/python/antlr/op/IsDerived.java branches/indy/src/org/python/antlr/op/IsNotDerived.java branches/indy/src/org/python/antlr/op/LShiftDerived.java branches/indy/src/org/python/antlr/op/LoadDerived.java branches/indy/src/org/python/antlr/op/LtDerived.java branches/indy/src/org/python/antlr/op/LtEDerived.java branches/indy/src/org/python/antlr/op/ModDerived.java branches/indy/src/org/python/antlr/op/MultDerived.java branches/indy/src/org/python/antlr/op/NotDerived.java branches/indy/src/org/python/antlr/op/NotEqDerived.java branches/indy/src/org/python/antlr/op/NotInDerived.java branches/indy/src/org/python/antlr/op/OrDerived.java branches/indy/src/org/python/antlr/op/ParamDerived.java branches/indy/src/org/python/antlr/op/PowDerived.java branches/indy/src/org/python/antlr/op/RShiftDerived.java branches/indy/src/org/python/antlr/op/StoreDerived.java branches/indy/src/org/python/antlr/op/SubDerived.java branches/indy/src/org/python/antlr/op/UAddDerived.java branches/indy/src/org/python/antlr/op/USubDerived.java branches/indy/src/org/python/compiler/CodeCompiler.java branches/indy/src/org/python/core/ClasspathPyImporterDerived.java branches/indy/src/org/python/core/PyArray.java branches/indy/src/org/python/core/PyArrayDerived.java branches/indy/src/org/python/core/PyBaseExceptionDerived.java branches/indy/src/org/python/core/PyBooleanDerived.java branches/indy/src/org/python/core/PyClassMethodDerived.java branches/indy/src/org/python/core/PyComplexDerived.java branches/indy/src/org/python/core/PyDictionaryDerived.java branches/indy/src/org/python/core/PyEnumerateDerived.java branches/indy/src/org/python/core/PyFileDerived.java branches/indy/src/org/python/core/PyFloatDerived.java branches/indy/src/org/python/core/PyFrozenSetDerived.java branches/indy/src/org/python/core/PyIntegerDerived.java branches/indy/src/org/python/core/PyList.java branches/indy/src/org/python/core/PyListDerived.java branches/indy/src/org/python/core/PyLongDerived.java branches/indy/src/org/python/core/PyModuleDerived.java branches/indy/src/org/python/core/PyObjectDerived.java branches/indy/src/org/python/core/PyPropertyDerived.java branches/indy/src/org/python/core/PySetDerived.java branches/indy/src/org/python/core/PySliceDerived.java branches/indy/src/org/python/core/PyStringDerived.java branches/indy/src/org/python/core/PySuperDerived.java branches/indy/src/org/python/core/PyTuple.java branches/indy/src/org/python/core/PyTupleDerived.java branches/indy/src/org/python/core/PyTypeDerived.java branches/indy/src/org/python/core/PyUnicodeDerived.java branches/indy/src/org/python/core/codecs.java branches/indy/src/org/python/core/imp.java branches/indy/src/org/python/core/io/FileIO.java branches/indy/src/org/python/modules/_collections/PyDefaultDictDerived.java branches/indy/src/org/python/modules/_collections/PyDequeDerived.java branches/indy/src/org/python/modules/_csv/PyDialectDerived.java branches/indy/src/org/python/modules/_functools/PyPartialDerived.java branches/indy/src/org/python/modules/_hashlib.java branches/indy/src/org/python/modules/_threading/_threading.java branches/indy/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/indy/src/org/python/modules/random/PyRandomDerived.java branches/indy/src/org/python/modules/thread/PyLocalDerived.java branches/indy/src/org/python/modules/thread/thread.java branches/indy/src/org/python/modules/zipimport/zipimporterDerived.java branches/indy/src/templates/object.derived Added Paths: ----------- branches/indy/Lib/test/print_sans_lib.py branches/indy/Lib/test/test_codecs_jy.py branches/indy/Lib/test/test_file_jy.py branches/indy/Lib/test/test_zlib_jy.py branches/indy/tests/java/org/python/core/PyListTest.java branches/indy/tests/java/org/python/core/PyTupleTest.java Property Changed: ---------------- branches/indy/ branches/indy/extlibs/xercesImpl-2.9.1.jar branches/indy/tests/java/org/python/tests/RedundantInterfaceDeclarations.java Property changes on: branches/indy ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-6751 + /trunk/jython:1-6814 Modified: svn:mergeinfo - /branches/jsr223:6285-6565 /branches/newstyle-java-types:5564-5663,5666-5729 /trunk/jython:6662-6741 + /branches/jsr223:6285-6565 /branches/newstyle-java-types:5564-5663,5666-5729 /trunk/jython:6662-6741,6762-6814 Modified: branches/indy/CPythonLib.includes =================================================================== --- branches/indy/CPythonLib.includes 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/CPythonLib.includes 2009-10-01 01:16:13 UTC (rev 6817) @@ -55,17 +55,14 @@ dummy_thread.py dummy_threading.py exceptions.py -fileinput.py fnmatch.py formatter.py fpformat.py ftplib.py functools.py getopt.py -gettext.py glob.py gopherlib.py -gzip.py hashlib.py heapq.py hmac.py @@ -76,13 +73,11 @@ ihooks.py imaplib.py imghdr.py -inspect.py keyword.py linecache.py locale.py macpath.py macurl2path.py -mailbox.py mailcap.py markupbase.py md5.py @@ -94,9 +89,7 @@ modulefinder.py multifile.py mutex.py -netrc.py nntplib.py -ntpath.py nturl2path.py opcode.py optparse.py @@ -104,15 +97,12 @@ pickle.py pickletools.py pipes.py -pkgutil.py -platform.py poplib.py posixfile.py pprint.py profile.py pstats.py pyclbr.py -pydoc.py Queue.py quopri.py random.py @@ -130,9 +120,7 @@ shelve.py shlex.py shutil.py -SimpleHTTPServer.py SimpleXMLRPCServer.py -site.py site-packages/README smtpd.py smtplib.py @@ -145,26 +133,20 @@ symbol.py tabnanny.py this.py -threading.py textwrap.py -timeit.py token.py tokenize.py trace.py traceback.py tzparse.py unittest.py -urllib.py urllib2.py urlparse.py user.py UserDict.py UserList.py UserString.py -uu.py uuid.py -warnings.py -weakref.py whichdb.py whrandom.py wsgiref.egg-info @@ -172,4 +154,3 @@ xdrlib.py xmllib.py xmlrpclib.py -zipfile.py Modified: branches/indy/Lib/distutils/util.py =================================================================== --- branches/indy/Lib/distutils/util.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/distutils/util.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -155,25 +155,26 @@ Otherwise, it requires making 'pathname' relative and then joining the two, which is tricky on DOS/Windows and Mac OS. """ - if os.name == 'posix' or os.name == 'java': + os_name = os._name if sys.platform.startswith('java') else os.name + if os_name == 'posix': if not os.path.isabs(pathname): return os.path.join(new_root, pathname) else: return os.path.join(new_root, pathname[1:]) - elif os.name == 'nt': + elif os_name == 'nt': (drive, path) = os.path.splitdrive(pathname) if path[0] == '\\': path = path[1:] return os.path.join(new_root, path) - elif os.name == 'os2': + elif os_name == 'os2': (drive, path) = os.path.splitdrive(pathname) if path[0] == os.sep: path = path[1:] return os.path.join(new_root, path) - elif os.name == 'mac': + elif os_name == 'mac': if not os.path.isabs(pathname): return os.path.join(new_root, pathname) else: @@ -184,7 +185,7 @@ else: raise DistutilsPlatformError, \ - "nothing known about platform '%s'" % os.name + "nothing known about platform '%s'" % os_name _environ_checked = 0 Modified: branches/indy/Lib/popen2.py =================================================================== --- branches/indy/Lib/popen2.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/popen2.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -34,7 +34,8 @@ process.""" stderr = subprocess.PIPE if capturestderr else None PIPE = subprocess.PIPE - self._popen = subprocess.Popen(cmd, bufsize=bufsize, shell=True, + self._popen = subprocess.Popen(cmd, bufsize=bufsize, + shell=isinstance(cmd, basestring), stdin=PIPE, stdout=PIPE, stderr=stderr) self._setup(cmd) @@ -73,7 +74,8 @@ def __init__(self, cmd, bufsize=-1): PIPE = subprocess.PIPE - self._popen = subprocess.Popen(cmd, bufsize=bufsize, shell=True, + self._popen = subprocess.Popen(cmd, bufsize=bufsize, + shell=isinstance(cmd, basestring), stdin=PIPE, stdout=PIPE, stderr=subprocess.STDOUT) self._setup(cmd) Copied: branches/indy/Lib/test/print_sans_lib.py (from rev 6814, trunk/jython/Lib/test/print_sans_lib.py) =================================================================== --- branches/indy/Lib/test/print_sans_lib.py (rev 0) +++ branches/indy/Lib/test/print_sans_lib.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -0,0 +1,4 @@ +import sys +sys.path = [path for path in sys.path if not path.startswith('/')] +encoded = u'hi'.encode("utf-8") +encoded.decode('utf-8') Modified: branches/indy/Lib/test/test_array_jy.py =================================================================== --- branches/indy/Lib/test/test_array_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_array_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -1,6 +1,7 @@ # The jarray module is being phased out, with all functionality # now available in the array module. - +from __future__ import with_statement +import os import unittest from test import test_support from array import array, zeros @@ -11,7 +12,6 @@ class ArrayJyTestCase(unittest.TestCase): def test_jarray(self): # until it is fully formally removed - # While jarray is still being phased out, just flex the initializers. # The rest of the test for array will catch all the big problems. import jarray @@ -44,8 +44,34 @@ Color.RGBtoHSB(0, 255, 255, hsb1) self.assertEqual(hsb, hsb1, "hsb float arrays were not equal") + +class ToFromfileTestCase(unittest.TestCase): + + def tearDown(self): + if os.path.exists(test_support.TESTFN): + os.remove(test_support.TESTFN) + + def test_tofromfile(self): + # http://bugs.jython.org/issue1457 + x = array('i', range(5)) + with open(test_support.TESTFN, 'wb') as f: + x.tofile(f) + + x = array('i', []) + with open(test_support.TESTFN, 'r+b') as f: + x.fromfile(f, 5) + x *= 2 + x.tofile(f) + + with open(test_support.TESTFN, 'rb') as f: + x.fromfile(f, 10) + self.assertEqual(x, array('i', range(5) * 4)) + + def test_main(): - test_support.run_unittest(ArrayJyTestCase) + test_support.run_unittest(ArrayJyTestCase, + ToFromfileTestCase) + if __name__ == "__main__": test_main() Modified: branches/indy/Lib/test/test_cmp_jy.py =================================================================== --- branches/indy/Lib/test/test_cmp_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_cmp_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -1,7 +1,18 @@ "Tests for cmp() compatibility with CPython" +import UserDict import unittest from test import test_support +class CmpGeneralTestCase(unittest.TestCase): + + def test_type_crash(self): + # Used to throw ArrayStoreException: + # http://bugs.jython.org/issue1382 + class Configuration(object, UserDict.DictMixin): + pass + self.assertNotEqual(Configuration(), None) + + class UnicodeDerivedCmp(unittest.TestCase): "Test for http://bugs.jython.org/issue1889394" def testCompareWithString(self): @@ -14,6 +25,7 @@ class B(unicode): pass self.assertEqual(A(), B()) + class LongDerivedCmp(unittest.TestCase): def testCompareWithString(self): class Test(long): @@ -21,6 +33,7 @@ self.assertNotEqual(Test(0), 'foo') self.assertTrue('foo' in [Test(12), 'foo']) + class IntStrCmp(unittest.TestCase): def testIntStrCompares(self): assert not (-1 > 'a') @@ -31,6 +44,7 @@ assert (-2 < 'a') assert not (-1 == 'a') + class CustomCmp(unittest.TestCase): def test___cmp___returns(self): class Foo(object): @@ -63,13 +77,16 @@ __eq__ = lambda self, other: True self.assertEqual(cmp(Foo(), Bar()), 1) + def test_main(): test_support.run_unittest( + CmpGeneralTestCase, UnicodeDerivedCmp, LongDerivedCmp, IntStrCmp, CustomCmp ) + if __name__ == '__main__': test_main() Copied: branches/indy/Lib/test/test_codecs_jy.py (from rev 6814, trunk/jython/Lib/test/test_codecs_jy.py) =================================================================== --- branches/indy/Lib/test/test_codecs_jy.py (rev 0) +++ branches/indy/Lib/test/test_codecs_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -0,0 +1,19 @@ +import subprocess +import sys +import test_support +import unittest + +class AccessBuiltinCodecs(unittest.TestCase): + def test_print_sans_lib(self): + '''Encodes and decodes using utf-8 after in an environment without the standard library + + Checks that the builtin utf-8 codec is always available: http://bugs.jython.org/issue1458''' + subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", + "-J-Dpython.security.respectJavaAccessibility=false", + test_support.findfile('print_sans_lib.py')]) + +def test_main(): + test_support.run_unittest(AccessBuiltinCodecs) + +if __name__ == "__main__": + test_main() Copied: branches/indy/Lib/test/test_file_jy.py (from rev 6814, trunk/jython/Lib/test/test_file_jy.py) =================================================================== --- branches/indy/Lib/test/test_file_jy.py (rev 0) +++ branches/indy/Lib/test/test_file_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -0,0 +1,39 @@ +"""Misc file tests. + +Made for Jython. +""" +from __future__ import with_statement +import os +import unittest +from test import test_support + +class FileTestCase(unittest.TestCase): + + def tearDown(self): + if os.path.exists(test_support.TESTFN): + os.remove(test_support.TESTFN) + + def test_append(self): + self._test_append('ab') + + def test_appendplus(self): + self._test_append('a+') + + def _test_append(self, mode): + # http://bugs.jython.org/issue1466 + fp1 = open(test_support.TESTFN, mode) + fp1.write('test1\n') + fp2 = open(test_support.TESTFN, mode) + fp2.write('test2\n') + fp1.close() + fp2.close() + with open(test_support.TESTFN) as fp: + self.assertEqual('test1\ntest2\n', fp.read()) + + +def test_main(): + test_support.run_unittest(FileTestCase) + + +if __name__ == '__main__': + test_main() Modified: branches/indy/Lib/test/test_hashlib_jy.py =================================================================== --- branches/indy/Lib/test/test_hashlib_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_hashlib_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -5,6 +5,7 @@ """ import hashlib import unittest +from array import array from test import test_support class HashlibTestCase(unittest.TestCase): @@ -14,7 +15,14 @@ 'acbd18db4cc2f85cedef654fccc4a4d8') self.assertRaises(UnicodeEncodeError, hashlib.md5, u'Gráin amháiñ') + def test_array(self): + self.assertEqual(hashlib.sha1(array('c', 'hovercraft')).hexdigest(), + '496df4d8de2c71973d7e917c4fbe57e6ad46d738') + intarray = array('i', range(5)) + self.assertEqual(hashlib.sha1(intarray).hexdigest(), + hashlib.sha1(intarray.tostring()).hexdigest()) + def test_main(): test_support.run_unittest(HashlibTestCase) Modified: branches/indy/Lib/test/test_seq_jy.py =================================================================== --- branches/indy/Lib/test/test_seq_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_seq_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -27,6 +27,14 @@ self.assertTrue(foo in seq1) self.assertFalse(eq_called) + def test_seq_equality(self): + class Foo(object): + def __eq__(self, other): + return True + foo = [Foo()] + for type2test in self.types2test: + self.assertTrue(type2test() in foo) + def test_seq_subclass_equality(self): # Various combinations of PyObject._eq, overriden Object.equals, # and cmp implementations Modified: branches/indy/Lib/test/test_threading_jy.py =================================================================== --- branches/indy/Lib/test/test_threading_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_threading_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -36,8 +36,14 @@ time.sleep(random.random()) +class TwistedTestCase(unittest.TestCase): + + def test_needs_underscored_versions(self): + self.assertEqual(threading.Lock, threading._Lock) + self.assertEqual(threading.RLock, threading._RLock) + def test_main(): - test_support.run_unittest(ThreadingTestCase) + test_support.run_unittest(ThreadingTestCase, TwistedTestCase) if __name__ == "__main__": Copied: branches/indy/Lib/test/test_zlib_jy.py (from rev 6814, trunk/jython/Lib/test/test_zlib_jy.py) =================================================================== --- branches/indy/Lib/test/test_zlib_jy.py (rev 0) +++ branches/indy/Lib/test/test_zlib_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -0,0 +1,37 @@ +"""Misc zlib tests + +Made for Jython. +""" +import unittest +import zlib +from array import array +from test import test_support + +class ArrayTestCase(unittest.TestCase): + + def test_array(self): + self._test_array(zlib.compress, zlib.decompress) + + def test_array_compressobj(self): + def compress(value): + co = zlib.compressobj() + return co.compress(value) + co.flush() + def decompress(value): + dco = zlib.decompressobj() + return dco.decompress(value) + dco.flush() + self._test_array(compress, decompress) + + def _test_array(self, compress, decompress): + self.assertEqual(compress(array('c', 'jython')), compress('jython')) + intarray = array('i', range(5)) + self.assertEqual(compress(intarray), compress(intarray.tostring())) + compressed = array('c', compress('jython')) + self.assertEqual('jython', decompress(compressed)) + + +def test_main(): + test_support.run_unittest(ArrayTestCase) + + +if __name__ == '__main__': + test_main() Modified: branches/indy/Lib/threading.py =================================================================== --- branches/indy/Lib/threading.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/threading.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -5,7 +5,7 @@ from org.python.util import jython from thread import _newFunctionThread from thread import _local as local -from _threading import Lock, RLock, Condition +from _threading import Lock, RLock, Condition, _Lock, _RLock import java.lang.Thread import weakref Modified: branches/indy/Lib/zlib.py =================================================================== --- branches/indy/Lib/zlib.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/zlib.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -13,7 +13,9 @@ Compressor objects support compress() and flush() methods; decompressor objects support decompress() and flush(). """ -import jarray, binascii +import array +import binascii +import jarray from java.util.zip import Adler32, Deflater, Inflater, DataFormatException from java.lang import Long, String @@ -59,13 +61,14 @@ if level < Z_BEST_SPEED or level > Z_BEST_COMPRESSION: raise error, "Bad compression level" deflater = Deflater(level, 0) + string = _to_input(string) deflater.setInput(string, 0, len(string)) deflater.finish() return _get_deflate_data(deflater) def decompress(string, wbits=0, bufsize=16384): inflater = Inflater(wbits < 0) - inflater.setInput(string) + inflater.setInput(_to_input(string)) return _get_inflate_data(inflater) @@ -84,6 +87,7 @@ def compress(self, string): if self._ended: raise error("compressobj may not be used after flush(Z_FINISH)") + string = _to_input(string) self.deflater.setInput(string, 0, len(string)) return _get_deflate_data(self.deflater) @@ -123,6 +127,7 @@ if max_length < 0: raise ValueError("max_length must be a positive integer") + string = _to_input(string) self.inflater.setInput(string) inflated = _get_inflate_data(self.inflater, max_length) @@ -146,6 +151,8 @@ self.inflater.end() return last +def _to_input(string): + return string.tostring() if isinstance(string, array.array) else string def _get_deflate_data(deflater): buf = jarray.zeros(1024, 'b') Modified: branches/indy/NEWS =================================================================== --- branches/indy/NEWS 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/NEWS 2009-10-01 01:16:13 UTC (rev 6817) @@ -1,5 +1,22 @@ Jython NEWS +Jython 2.5.1rc3 + Bugs Fixed + - [ 1466 ] wrong handling of append only files + +Jython 2.5.1rc2 + New Features + - zxJDBC supports the with-statement: connections are committed or rollbacked; cursors are closed + Bugs Fixed + - [ 1079 ] fixed regression on issue: twisted.python.threadable module: missing attribute '_RLock' + - [ 1461 ] assert statement should lookup AssertionError using getglobal + - [ 1425 ] distutils/util.py assumes too much posix + - [ 1457 ] Cannot write an array in a file opened in r+b mode. + - [ 1382 ] __cmp__ on certain types raises ArrayStoreException + - [ 1443 ] Can't update() hashlib.sha1() with array.array('c') + - [ 1444 ] Can't zlib.compress() with array.array('c') + - [ 1458 ] Builtin codecs aren't available without standard lib + Jython 2.5.1rc1 New Features - Upgraded to ANTLR 3.1.3 Modified: branches/indy/README.txt =================================================================== --- branches/indy/README.txt 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/README.txt 2009-10-01 01:16:13 UTC (rev 6817) @@ -1,10 +1,10 @@ -Welcome to Jython 2.5.1rc1 -========================== +Welcome to Jython 2.5.1 Final +============================= -This is the first release candidate of the 2.5.1 version of Jython. This -release fixes a number of bugs, including some major errors when using -coroutines and when using relative imports. Please see the NEWS file for -detailed release notes. +This is the final release of the 2.5.1 version of Jython. This release fixes a +number of bugs, including some major errors when using coroutines and when +using relative imports, as well as a potential data loss bug when writing to +files in append mode. Please see the NEWS file for detailed release notes. The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. Modified: branches/indy/build.xml =================================================================== --- branches/indy/build.xml 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/build.xml 2009-10-01 01:16:13 UTC (rev 6817) @@ -129,8 +129,8 @@ <property name="jython.major_version" value="2"/> <property name="jython.minor_version" value="5"/> <property name="jython.micro_version" value="1"/> - <property name="jython.release_level" value="${PY_RELEASE_LEVEL_GAMMA}"/> - <property name="jython.release_serial" value="1"/> + <property name="jython.release_level" value="${PY_RELEASE_LEVEL_FINAL}"/> + <property name="jython.release_serial" value="0"/> <condition property="do.snapshot.build"> <isset property="snapshot.revision" /> @@ -679,7 +679,7 @@ source="${jdk.source.version}" public="true" breakiterator="yes" - packagenames="org.python.core, org.python.util, com.ziclix.python.sql" + packagenames="org.python.core.*, org.python.util.*, org.python.modules.*, com.ziclix.python.sql, com.xhaus.modjy" windowtitle="Jython API documentation" bottom="<a href='http://www.jython.org' target='_top'>Jython homepage</a>" > Property changes on: branches/indy/extlibs/xercesImpl-2.9.1.jar ___________________________________________________________________ Modified: svn:mergeinfo - /branches/newstyle-java-types/extlibs/xercesImpl.jar:5564-5663,5666-5729 /trunk/jython/extlibs/xercesImpl-2.9.1.jar:6662-6741 + /branches/newstyle-java-types/extlibs/xercesImpl.jar:5564-5663,5666-5729 /trunk/jython/extlibs/xercesImpl-2.9.1.jar:6662-6741,6762-6814 Modified: branches/indy/src/com/ziclix/python/sql/PyConnection.java =================================================================== --- branches/indy/src/com/ziclix/python/sql/PyConnection.java 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/src/com/ziclix/python/sql/PyConnection.java 2009-10-01 01:16:13 UTC (rev 6817) @@ -17,6 +17,7 @@ import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyBuiltinMethodSet; +import org.python.core.PyException; import org.python.core.PyInteger; import org.python.core.PyList; import org.python.core.PyObject; @@ -24,7 +25,10 @@ import org.python.core.PyUnicode; import com.ziclix.python.sql.util.PyArgParser; +import org.python.core.ContextManager; +import org.python.core.ThreadState; + /** * A connection to the database. * @@ -32,7 +36,7 @@ * @author last revised by $Author$ * @version $Revision$ */ -public class PyConnection extends PyObject implements ClassDictInit { +public class PyConnection extends PyObject implements ClassDictInit, ContextManager { /** True if closed. */ protected boolean closed; @@ -40,6 +44,9 @@ /** Whether transactions are supported. */ protected boolean supportsTransactions; + /** Whether multiple ResultSets are supported. */ + protected boolean supportsMultipleResultSets; + /** The underlying java.sql.Connection. */ protected Connection connection; @@ -90,6 +97,8 @@ this.connection = connection; this.statements = new HashSet<PyStatement>(); this.supportsTransactions = this.connection.getMetaData().supportsTransactions(); + this.supportsMultipleResultSets = + this.connection.getMetaData().supportsMultipleResultSets(); if (this.supportsTransactions) { this.connection.setAutoCommit(false); @@ -132,6 +141,8 @@ zxJDBC.getString("rollback"))); dict.__setitem__("nativesql", new ConnectionFunc("nativesql", 4, 1, 1, zxJDBC.getString("nativesql"))); + dict.__setitem__("__enter__", new ConnectionFunc("__enter__", 5, 0, 0, "__enter__")); + dict.__setitem__("__exit__", new ConnectionFunc("__exit__", 6, 3, 3, "__exit__")); // hide from python dict.__setitem__("initModule", null); @@ -416,6 +427,33 @@ } return this.statements.contains(statement); } + + public PyObject __enter__(ThreadState ts) { + return this; + } + + public PyObject __enter__() { + return this; + } + + public boolean __exit__(ThreadState ts, PyException exception) { + if (exception == null) { + commit(); + } else { + rollback(); + } + return false; + } + + public boolean __exit__(PyObject type, PyObject value, PyObject traceback) { + if (type == null || type == Py.None) { + commit(); + } else { + rollback(); + } + return false; + } + } class ConnectionFunc extends PyBuiltinMethodSet { @@ -439,6 +477,8 @@ case 3: c.rollback(); return Py.None; + case 5: + return c.__enter__(); default: throw info.unexpectedCall(0, false); } @@ -463,6 +503,8 @@ switch (index) { case 2: return c.cursor(arg1.__nonzero__(), arg2, arg3); + case 6: + return Py.newBoolean(c.__exit__(arg1, arg2, arg3)); default: throw info.unexpectedCall(3, false); } Modified: branches/indy/src/com/ziclix/python/sql/PyCursor.java =================================================================== --- branches/indy/src/com/ziclix/python/sql/PyCursor.java 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/src/com/ziclix/python/sql/PyCursor.java 2009-10-01 01:16:13 UTC (rev 6817) @@ -26,7 +26,10 @@ import org.python.core.PyUnicode; import com.ziclix.python.sql.util.PyArgParser; +import org.python.core.ContextManager; +import org.python.core.ThreadState; + /** * These objects represent a database cursor, which is used to manage the * context of a fetch operation. @@ -35,7 +38,7 @@ * @author last revised by $Author$ * @version $Revision$ */ -public class PyCursor extends PyObject implements ClassDictInit, WarningListener { +public class PyCursor extends PyObject implements ClassDictInit, WarningListener, ContextManager { /** Field fetch */ protected Fetch fetch; @@ -260,6 +263,8 @@ dict.__setitem__("scroll", new CursorFunc("scroll", 10, 1, 2, "scroll the cursor in the result set to a new position according to mode")); dict.__setitem__("write", new CursorFunc("write", 11, 1, "execute the sql written to this file-like object")); dict.__setitem__("prepare", new CursorFunc("prepare", 12, 1, "prepare the sql statement for later execution")); + dict.__setitem__("__enter__", new CursorFunc("__enter__", 13, 0, 0, "__enter__")); + dict.__setitem__("__exit__", new CursorFunc("__exit__", 14, 3, 3, "__exit__")); // hide from python dict.__setitem__("classDictInit", null); @@ -482,15 +487,11 @@ throw zxJDBC.makeException(zxJDBC.NotSupportedError, zxJDBC.getString("noStoredProc")); } - } catch (PyException e) { - throw e; - } catch (Throwable e) { - throw zxJDBC.makeException(e); - } finally { - if (this.statement != null) { - // close what we opened - this.statement.close(); + } catch (Throwable t) { + if (statement != null) { + statement.close(); } + throw zxJDBC.makeException(t); } } @@ -584,17 +585,12 @@ this.execute(Py.None, Py.None); } } - } catch (PyException e) { - throw e; - } catch (Throwable e) { - throw zxJDBC.makeException(zxJDBC.Error, e, rowIndex); - } finally { - if (this.statement != null) { + } catch (Throwable t) { + if (statement != null && !(sql instanceof PyStatement)) { // only close static, single-use statements - if (!(sql instanceof PyStatement) && !this.dynamicFetch) { - this.statement.close(); - } + statement.close(); } + throw zxJDBC.makeException(zxJDBC.Error, t, rowIndex); } } @@ -605,18 +601,12 @@ protected void execute(PyObject params, PyObject bindings) { try { Statement stmt = this.statement.statement; - this.datahandler.preExecute(stmt); // this performs the SQL execution and fetch per the Statement type this.statement.execute(this, params, bindings); - this.lastrowid = this.datahandler.getRowId(stmt); - - int uc = stmt.getUpdateCount(); - - this.updatecount = uc < 0 ? Py.None : Py.newInteger(uc); - + this.updateAttributes(stmt.getUpdateCount()); warning(new WarningEvent(this, stmt.getWarnings())); this.datahandler.postExecute(stmt); } catch (PyException e) { @@ -627,6 +617,17 @@ } /** + * Update the cursor's lastrowid and updatecount. + * + * @param updateCount The int value of updatecount + * @throws SQLException + */ + private void updateAttributes(int updateCount) throws SQLException { + lastrowid = datahandler.getRowId(statement.statement); + updatecount = updateCount < 0 ? Py.None : Py.newInteger(updateCount); + } + + /** * Fetch the next row of a query result set, returning a single sequence, * or None when no more data is available. * @@ -691,7 +692,28 @@ */ public PyObject nextset() { ensureOpen(); - return this.fetch.nextset(); + PyObject nextset = fetch.nextset(); + + // If the fetch is exhausted and multiple ResultSets are supported, try addding a + // next ResultSet. XXX: DynamicFetch currently isn't so tailored for this + if (!nextset.__nonzero__() && connection.supportsMultipleResultSets && !dynamicFetch) { + Statement stmt = statement.statement; + try { + boolean hasMoreResults; + int updateCount = -1; + if ((hasMoreResults = stmt.getMoreResults()) + || (updateCount = stmt.getUpdateCount()) != -1) { + // Only call getUpdateCount once, per its docs + updateAttributes(!hasMoreResults ? updateCount : stmt.getUpdateCount()); + fetch.add(stmt.getResultSet()); + nextset = Py.One; + } + } catch (SQLException sqle) { + throw zxJDBC.makeException(sqle); + } + } + + return nextset; } /** @@ -784,12 +806,9 @@ } if (this.statement != null) { - // we can't close a dynamic fetch statement until everything has been - // consumed so the only time we can clean up is now - // but if this is a previously prepared statement we don't want to close - // it underneath someone; we can check this by looking in the set + // Finally done with the Statement: only close it if we created it try { - if (this.dynamicFetch && !this.connection.contains(this.statement)) { + if (!this.connection.contains(this.statement)) { this.statement.close(); } } finally { @@ -870,6 +889,24 @@ throw zxJDBC.makeException(zxJDBC.ProgrammingError, "cursor is closed"); } } + + public PyObject __enter__(ThreadState ts) { + return this; + } + + public PyObject __enter__() { + return this; + } + + public boolean __exit__(ThreadState ts, PyException exception) { + close(); + return false; + } + + public boolean __exit__(PyObject type, PyObject value, PyObject traceback) { + close(); + return false; + } } class CursorFunc extends PyBuiltinMethodSet { @@ -897,6 +934,8 @@ return cursor.fetchone(); case 4 : return cursor.nextset(); + case 13 : + return cursor.__enter__(); default : throw info.unexpectedCall(0, false); } @@ -969,6 +1008,8 @@ case 9 : cursor.executemany(arga, argb, argc, Py.None); return Py.None; + case 14 : + return Py.newBoolean(cursor.__exit__(arga, argc, argc)); default : throw info.unexpectedCall(3, false); } Modified: branches/indy/src/org/python/antlr/PythonTree.java =================================================================== --- branches/indy/src/org/python/antlr/PythonTree.java 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/src/org/python/antlr/PythonTree.java 2009-10-01 01:16:13 UTC (rev 6817) @@ -16,22 +16,10 @@ private int charStartIndex = -1; private int charStopIndex = -1; private CommonTree node; + + /** Who is the parent node of this node; if null, implies node is root */ private PythonTree parent; - /** A single token is the payload */ - //private Token token; - - /** What token indexes bracket all tokens associated with this node - * and below? - */ - //protected int startIndex=-1, stopIndex=-1; - - /** Who is the parent node of this node; if null, implies node is root */ - //private PythonTree parent; - - /** What index is this node in the child list? Range: 0..n-1 */ - //private int childIndex = -1; - public PythonTree() { node = new CommonTree(); } @@ -60,73 +48,73 @@ charStartIndex = tree.getCharStartIndex(); charStopIndex = tree.getCharStopIndex(); } - + public CommonTree getNode() { return node; } - public Token getToken() { - return node.getToken(); - } + public Token getToken() { + return node.getToken(); + } - public PythonTree dupNode() { - return new PythonTree(this); - } + public PythonTree dupNode() { + return new PythonTree(this); + } - public boolean isNil() { - return node.isNil(); - } + public boolean isNil() { + return node.isNil(); + } - public int getAntlrType() { - return node.getType(); - } + public int getAntlrType() { + return node.getType(); + } - public String getText() { - return node.getText(); - } + public String getText() { + return node.getText(); + } - public int getLine() { - if (node.getToken()==null || node.getToken().getLine()==0) { - if ( getChildCount()>0 ) { - return getChild(0).getLine(); - } - return 1; - } - return node.getToken().getLine(); - } + public int getLine() { + if (node.getToken()==null || node.getToken().getLine()==0) { + if ( getChildCount()>0 ) { + return getChild(0).getLine(); + } + return 1; + } + return node.getToken().getLine(); + } - public int getCharPositionInLine() { + public int getCharPositionInLine() { Token token = node.getToken(); - if (token==null || token.getCharPositionInLine()==-1) { - if (getChildCount()>0) { - return getChild(0).getCharPositionInLine(); - } - return 0; - } else if (token != null && token.getCharPositionInLine() == -2) { + if (token==null || token.getCharPositionInLine()==-1) { + if (getChildCount()>0) { + return getChild(0).getCharPositionInLine(); + } + return 0; + } else if (token != null && token.getCharPositionInLine() == -2) { //XXX: yucky fix because CPython's ast uses -1 as a real value // for char pos in certain circumstances (for example, the // char pos of multi-line strings. I would just use -1, // but ANTLR is using -1 in special ways also. return -1; } - return token.getCharPositionInLine(); - } + return token.getCharPositionInLine(); + } - public int getTokenStartIndex() { + public int getTokenStartIndex() { return node.getTokenStartIndex(); - } + } - public void setTokenStartIndex(int index) { - node.setTokenStartIndex(index); - } + public void setTokenStartIndex(int index) { + node.setTokenStartIndex(index); + } - public int getTokenStopIndex() { + public int getTokenStopIndex() { return node.getTokenStopIndex(); - } + } - public void setTokenStopIndex(int index) { - node.setTokenStopIndex(index); - } + public void setTokenStopIndex(int index) { + node.setTokenStopIndex(index); + } public int getCharStartIndex() { if (charStartIndex == -1 && node.getToken() != null) { @@ -160,33 +148,33 @@ charStopIndex = index; } - public int getChildIndex() { - return node.getChildIndex(); - } + public int getChildIndex() { + return node.getChildIndex(); + } - public PythonTree getParent() { - return parent; - } + public PythonTree getParent() { + return parent; + } - public void setParent(PythonTree t) { - this.parent = t; - } + public void setParent(PythonTree t) { + this.parent = t; + } - public void setChildIndex(int index) { - node.setChildIndex(index); - } + public void setChildIndex(int index) { + node.setChildIndex(index); + } @Override public String toString() { if (isNil()) { return "None"; } - if ( getAntlrType()==Token.INVALID_TOKEN_TYPE ) { - return "<errornode>"; - } - if ( node.getToken()==null ) { - return null; - } + if ( getAntlrType()==Token.INVALID_TOKEN_TYPE ) { + return "<errornode>"; + } + if ( node.getToken()==null ) { + return null; + } return node.getToken().getText() + "(" + this.getLine() + "," + this.getCharPositionInLine() + ")"; } @@ -251,203 +239,194 @@ } //XXX: From here down copied from org.antlr.runtime.tree.BaseTree - protected List<PythonTree> children; + protected List<PythonTree> children; - public PythonTree getChild(int i) { - if ( children==null || i>=children.size() ) { - return null; - } - return children.get(i); - } + public PythonTree getChild(int i) { + if ( children==null || i>=children.size() ) { + return null; + } + return children.get(i); + } - /** Get the children internal List; note that if you directly mess with - * the list, do so at your own risk. - */ - public List<PythonTree> getChildren() { - return children; - } + /** Get the children internal List; note that if you directly mess with + * the list, do so at your own risk. + */ + public List<PythonTree> getChildren() { + return children; + } - public PythonTree getFirstChildWithType(int type) { - for (int i = 0; children!=null && i < children.size(); i++) { - PythonTree t = children.get(i); - if ( t.getAntlrType()==type ) { - return t; - } - } - return null; - } + public PythonTree getFirstChildWithType(int type) { + for (int i = 0; children!=null && i < children.size(); i++) { + PythonTree t = children.get(i); + if ( t.getAntlrType()==type ) { + return t; + } + } + return null; + } - public int getChildCount() { - if ( children==null ) { - return 0; - } - return children.size(); - } + public int getChildCount() { + if ( children==null ) { + return 0; + } + return children.size(); + } - /** Add t as child of this node. - * - * Warning: if t has no children, but child does - * and child isNil then this routine moves children to t via - * t.children = child.children; i.e., without copying the array. - */ - public void addChild(PythonTree t) { - //System.out.println("add child "+t.toStringTree()+" "+this.toStringTree()); - //System.out.println("existing children: "+children); - if ( t==null ) { - return; // do nothing upon addChild(null) - } - PythonTree childTree = t; - if ( childTree.isNil() ) { // t is an empty node possibly with children - if ( this.children!=null && this.children == childTree.children ) { - throw new RuntimeException("attempt to add child list to itself"); - } - // just add all of childTree's children to this - if ( childTree.children!=null ) { - if ( this.children!=null ) { // must copy, this has children already - int n = childTree.children.size(); - for (int i = 0; i < n; i++) { - PythonTree c = childTree.children.get(i); - this.children.add(c); - // handle double-link stuff for each child of nil root - c.setParent(this); - c.setChildIndex(children.size()-1); - } - } - else { - // no children for this but t has children; just set pointer - // call general freshener routine - this.children = childTree.children; - this.freshenParentAndChildIndexes(); - } - } - } - else { // child is not nil (don't care about children) - if ( children==null ) { - children = createChildrenList(); // create children list on demand - } - children.add(t); - childTree.setParent(this); - childTree.setChildIndex(children.size()-1); - } - // System.out.println("now children are: "+children); - } + /** Add t as child of this node. + * + * Warning: if t has no children, but child does + * and child isNil then this routine moves children to t via + * t.children = child.children; i.e., without copying the array. + */ + public void addChild(PythonTree t) { + if ( t==null ) { + return; // do nothing upon addChild(null) + } + PythonTree childTree = t; + if ( childTree.isNil() ) { // t is an empty node possibly with children + if ( this.children!=null && this.children == childTree.children ) { + throw new RuntimeException("attempt to add child list to itself"); + } + // just add all of childTree's children to this + if ( childTree.children!=null ) { + if ( this.children!=null ) { // must copy, this has children already + int n = childTree.children.size(); + for (int i = 0; i < n; i++) { + PythonTree c = childTree.children.get(i); + this.children.add(c); + // handle double-link stuff for each child of nil root + c.setParent(this); + c.setChildIndex(children.size()-1); + } + } + else { + // no children for this but t has children; just set pointer + // call general freshener routine + this.children = childTree.children; + this.freshenParentAndChildIndexes(); + } + } + } + else { // child is not nil (don't care about children) + if ( children==null ) { + children = createChildrenList(); // create children list on demand + } + children.add(t); + childTree.setParent(this); + childTree.setChildIndex(children.size()-1); + } + } - /** Add all elements of kids list as children of this node */ - public void addChildren(List<PythonTree> kids) { - for (int i = 0; i < kids.size(); i++) { - PythonTree t = kids.get(i); - addChild(t); - } - } + /** Add all elements of kids list as children of this node */ + public void addChildren(List<PythonTree> kids) { + for (int i = 0; i < kids.size(); i++) { + PythonTree t = kids.get(i); + addChild(t); + } + } - public void setChild(int i, PythonTree t) { - if ( t==null ) { - return; - } - if ( t.isNil() ) { - throw new IllegalArgumentException("Can't set single child to a list"); - } - if ( children==null ) { - children = createChildrenList(); - } - children.set(i, t); - t.setParent(this); - t.setChildIndex(i); - } - - public Object deleteChild(int i) { - if ( children==null ) { - return null; - } - PythonTree killed = children.remove(i); - // walk rest and decrement their child indexes - this.freshenParentAndChildIndexes(i); - return killed; - } + public void setChild(int i, PythonTree t) { + if ( t==null ) { + return; + } + if ( t.isNil() ) { + throw new IllegalArgumentException("Can't set single child to a list"); + } + if ( children==null ) { + children = createChildrenList(); + } + children.set(i, t); + t.setParent(this); + t.setChildIndex(i); + } + + public Object deleteChild(int i) { + if ( children==null ) { + return null; + } + PythonTree killed = children.remove(i); + // walk rest and decrement their child indexes + this.freshenParentAndChildIndexes(i); + return killed; + } - /** Delete children from start to stop and replace with t even if t is - * a list (nil-root tree). num of children can increase or decrease. - * For huge child lists, inserting children can force walking rest of - * children to set their childindex; could be slow. - */ - public void replaceChildren(int startChildIndex, int stopChildIndex, Object t) { - /* - System.out.println("replaceChildren "+startChildIndex+", "+stopChildIndex+ - " with "+((PythonTree)t).toStringTree()); - System.out.println("in="+toStringTree()); - */ - if ( children==null ) { - throw new IllegalArgumentException("indexes invalid; no children in list"); - } - int replacingHowMany = stopChildIndex - startChildIndex + 1; - int replacingWithHowMany; - PythonTree newTree = (PythonTree)t; - List<PythonTree> newChildren = null; - // normalize to a list of c... [truncated message content] |
From: <pj...@us...> - 2009-10-01 01:13:24
|
Revision: 6816 http://jython.svn.sourceforge.net/jython/?rev=6816&view=rev Author: pjenvey Date: 2009-10-01 01:13:04 +0000 (Thu, 01 Oct 2009) Log Message: ----------- correct the callable check fixes #1478 Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/modules/_collections/PyDefaultDict.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-10-01 01:06:20 UTC (rev 6815) +++ trunk/jython/NEWS 2009-10-01 01:13:04 UTC (rev 6816) @@ -1,5 +1,9 @@ Jython NEWS +Jython 2.5.2a1 + Bugs Fixed + - [ 1478 ] defaultdict & weakref.WeakKeyDictionary [TypeError: first argument must be callable] + Jython 2.5.1rc3 Bugs Fixed - [ 1466 ] wrong handling of append only files Modified: trunk/jython/src/org/python/modules/_collections/PyDefaultDict.java =================================================================== --- trunk/jython/src/org/python/modules/_collections/PyDefaultDict.java 2009-10-01 01:06:20 UTC (rev 6815) +++ trunk/jython/src/org/python/modules/_collections/PyDefaultDict.java 2009-10-01 01:13:04 UTC (rev 6816) @@ -54,7 +54,7 @@ int nargs = args.length - kwds.length; if (nargs != 0) { defaultFactory = args[0]; - if (defaultFactory.__findattr__("__call__") == null) { + if (!defaultFactory.isCallable()) { throw Py.TypeError("first argument must be callable"); } PyObject newargs[] = new PyObject[args.length - 1]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-01 01:06:45
|
Revision: 6815 http://jython.svn.sourceforge.net/jython/?rev=6815&view=rev Author: pjenvey Date: 2009-10-01 01:06:20 +0000 (Thu, 01 Oct 2009) Log Message: ----------- allow del of default_factory, small cleanup Modified Paths: -------------- trunk/jython/src/org/python/modules/_collections/PyDefaultDict.java Modified: trunk/jython/src/org/python/modules/_collections/PyDefaultDict.java =================================================================== --- trunk/jython/src/org/python/modules/_collections/PyDefaultDict.java 2009-09-27 01:34:11 UTC (rev 6814) +++ trunk/jython/src/org/python/modules/_collections/PyDefaultDict.java 2009-10-01 01:06:20 UTC (rev 6815) @@ -1,3 +1,4 @@ +/* Copyright (c) Jython Developers */ package org.python.modules._collections; import java.util.Map; @@ -7,6 +8,7 @@ import org.python.core.PyObject; import org.python.core.PyTuple; import org.python.core.PyType; +import org.python.expose.ExposedDelete; import org.python.expose.ExposedGet; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; @@ -14,25 +16,25 @@ import org.python.expose.ExposedType; /** - * PyDefaultDict - This is a subclass of the builtin dict(PyDictionary) class. It supports one - * additional method __missing__ and adds one writable instance variable default_factory. The - * remaining functionality is the same as for the dict class. - * - * collections.defaultdict([default_factory[, ...]]) - returns a new dictionary-like object. The - * first argument provides the initial value for the default_factory attribute; it defaults to None. - * All remaining arguments are treated the same as if they were passed to the dict constructor, - * including keyword arguments. + * PyDefaultDict - This is a subclass of the builtin dict(PyDictionary) class. It supports + * one additional method __missing__ and adds one writable instance variable + * defaultFactory. The remaining functionality is the same as for the dict class. + * + * collections.defaultdict([defaultFactory[, ...]]) - returns a new dictionary-like + * object. The first argument provides the initial value for the defaultFactory attribute; + * it defaults to None. All remaining arguments are treated the same as if they were + * passed to the dict constructor, including keyword arguments. */ @ExposedType(name = "collections.defaultdict") public class PyDefaultDict extends PyDictionary { - + public static final PyType TYPE = PyType.fromClass(PyDefaultDict.class); - + /** - * This attribute is used by the __missing__ method; it is initialized from - * the first argument to the constructor, if present, or to None, if absent. + * This attribute is used by the __missing__ method; it is initialized from the first + * argument to the constructor, if present, or to None, if absent. */ - private PyObject default_factory = Py.None; + private PyObject defaultFactory = Py.None; public PyDefaultDict() { this(TYPE); @@ -41,18 +43,18 @@ public PyDefaultDict(PyType subtype) { super(subtype); } - + public PyDefaultDict(PyType subtype, Map<PyObject, PyObject> map) { super(subtype, map); } - + @ExposedMethod @ExposedNew final void defaultdict___init__(PyObject[] args, String[] kwds) { int nargs = args.length - kwds.length; - if (nargs != 0) { - default_factory = args[0]; - if (default_factory.__findattr__("__call__") == null) { + if (nargs != 0) { + defaultFactory = args[0]; + if (defaultFactory.__findattr__("__call__") == null) { throw Py.TypeError("first argument must be callable"); } PyObject newargs[] = new PyObject[args.length - 1]; @@ -61,28 +63,30 @@ } } + @Override public PyObject __finditem__(PyObject key) { return dict___getitem__(key); } /** - * This method is called by the __getitem__ method of the dict class when - * the requested key is not found; whatever it returns or raises is then - * returned or raised by __getitem__. + * This method is called by the __getitem__ method of the dict class when the + * requested key is not found; whatever it returns or raises is then returned or + * raised by __getitem__. */ @ExposedMethod final PyObject defaultdict___missing__(PyObject key) { - if (default_factory == Py.None) { + if (defaultFactory == Py.None) { throw Py.KeyError(key); - } - PyObject value = default_factory.__call__(); + } + PyObject value = defaultFactory.__call__(); if (value == null) { return value; - } + } __setitem__(key, value); return value; } + @Override public PyObject __reduce__() { return defaultdict___reduce__(); } @@ -90,47 +94,49 @@ @ExposedMethod final PyObject defaultdict___reduce__() { PyTuple args = null; - if (default_factory == Py.None) { + if (defaultFactory == Py.None) { args = new PyTuple(); - } else { - PyObject[] ob = {default_factory}; + } else { + PyObject[] ob = {defaultFactory}; args = new PyTuple(ob); - } + } return new PyTuple(getType(), args, Py.None, Py.None, items()); } + @Override public PyDictionary copy() { return defaultdict_copy(); } - @ExposedMethod - final PyDefaultDict defaultdict_copy() { - return defaultdict___copy__(); - } - - @ExposedMethod - final PyDefaultDict defaultdict___copy__() { + @ExposedMethod(names = {"copy", "__copy__"}) + final PyDefaultDict defaultdict_copy() { PyDefaultDict ob = new PyDefaultDict(TYPE, table); - ob.default_factory = default_factory; + ob.defaultFactory = defaultFactory; return ob; } + @Override public String toString() { return defaultdict_toString(); } @ExposedMethod(names = "__repr__") final String defaultdict_toString() { - return String.format("defaultdict(%s, %s)", default_factory, super.toString()); + return String.format("defaultdict(%s, %s)", defaultFactory, super.toString()); } @ExposedGet(name = "default_factory") public PyObject getDefaultFactory() { - return default_factory; + return defaultFactory; } @ExposedSet(name = "default_factory") public void setDefaultFactory(PyObject value) { - default_factory = value; + defaultFactory = value; } + + @ExposedDelete(name = "default_factory") + public void delDefaultFactory() { + defaultFactory = Py.None; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-27 01:34:21
|
Revision: 6814 http://jython.svn.sourceforge.net/jython/?rev=6814&view=rev Author: fwierzbicki Date: 2009-09-27 01:34:11 +0000 (Sun, 27 Sep 2009) Log Message: ----------- Removed unused import from thread.java, expanded javadoc package scan. Modified Paths: -------------- trunk/jython/build.xml trunk/jython/src/org/python/modules/thread/thread.java Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-09-26 17:43:16 UTC (rev 6813) +++ trunk/jython/build.xml 2009-09-27 01:34:11 UTC (rev 6814) @@ -647,7 +647,7 @@ source="${jdk.source.version}" public="true" breakiterator="yes" - packagenames="org.python.core, org.python.util, com.ziclix.python.sql, com.xhaus.modjy" + packagenames="org.python.core.*, org.python.util.*, org.python.modules.*, com.ziclix.python.sql, com.xhaus.modjy" windowtitle="Jython API documentation" bottom="<a href='http://www.jython.org' target='_top'>Jython homepage</a>" > Modified: trunk/jython/src/org/python/modules/thread/thread.java =================================================================== --- trunk/jython/src/org/python/modules/thread/thread.java 2009-09-26 17:43:16 UTC (rev 6813) +++ trunk/jython/src/org/python/modules/thread/thread.java 2009-09-27 01:34:11 UTC (rev 6814) @@ -8,7 +8,6 @@ import org.python.core.PyInteger; import org.python.core.PyObject; import org.python.core.PyString; -import org.python.core.PyTableCode; import org.python.core.PyType; import org.python.core.PyTuple; @@ -64,10 +63,10 @@ /** * Interrupts all running threads spawned by the thread module. * - * This works in conjunction with:<ul> - * <li>{@link PyTableCode#call(org.python.core.PyFrame, PyObject)}: - * checks for the interrupted status of the current thread and raise - * a SystemRestart exception if a interruption is detected.</li> + * This works in conjunction with:<ul> <li> + * {@link org.python.core.PyTableCode#call}: checks for the interrupted + * status of the current thread and raise a SystemRestart exception if a + * interruption is detected.</li> * <li>{@link FunctionThread#run()}: exits the current thread when a * SystemRestart exception is not caught.</li> * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-26 17:43:26
|
Revision: 6813 http://jython.svn.sourceforge.net/jython/?rev=6813&view=rev Author: fwierzbicki Date: 2009-09-26 17:43:16 +0000 (Sat, 26 Sep 2009) Log Message: ----------- Tag 2.5.1 final Added Paths: ----------- tags/Release_2_5_1/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-26 16:14:57
|
Revision: 6812 http://jython.svn.sourceforge.net/jython/?rev=6812&view=rev Author: fwierzbicki Date: 2009-09-26 16:14:48 +0000 (Sat, 26 Sep 2009) Log Message: ----------- Update README and version numbering. Modified Paths: -------------- trunk/jython/README.txt trunk/jython/build.xml Modified: trunk/jython/README.txt =================================================================== --- trunk/jython/README.txt 2009-09-25 03:13:10 UTC (rev 6811) +++ trunk/jython/README.txt 2009-09-26 16:14:48 UTC (rev 6812) @@ -1,11 +1,10 @@ -Welcome to Jython 2.5.1rc3 -========================== +Welcome to Jython 2.5.1 Final +============================= -This is the third release candidate of the 2.5.1 version of Jython. This -release fixes a number of bugs, including some major errors when using -coroutines and when using relative imports, as well as a potential data loss -bug when writing to files in append mode. Please see the NEWS file for detailed -release notes. +This is the final release of the 2.5.1 version of Jython. This release fixes a +number of bugs, including some major errors when using coroutines and when +using relative imports, as well as a potential data loss bug when writing to +files in append mode. Please see the NEWS file for detailed release notes. The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-09-25 03:13:10 UTC (rev 6811) +++ trunk/jython/build.xml 2009-09-26 16:14:48 UTC (rev 6812) @@ -129,8 +129,8 @@ <property name="jython.major_version" value="2"/> <property name="jython.minor_version" value="5"/> <property name="jython.micro_version" value="1"/> - <property name="jython.release_level" value="${PY_RELEASE_LEVEL_GAMMA}"/> - <property name="jython.release_serial" value="2"/> + <property name="jython.release_level" value="${PY_RELEASE_LEVEL_FINAL}"/> + <property name="jython.release_serial" value="0"/> <condition property="do.snapshot.build"> <isset property="snapshot.revision" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-25 03:13:19
|
Revision: 6811 http://jython.svn.sourceforge.net/jython/?rev=6811&view=rev Author: fwierzbicki Date: 2009-09-25 03:13:10 +0000 (Fri, 25 Sep 2009) Log Message: ----------- Remove leftover experimental code for now. Modified Paths: -------------- branches/indy/src/org/python/compiler/Module.java Modified: branches/indy/src/org/python/compiler/Module.java =================================================================== --- branches/indy/src/org/python/compiler/Module.java 2009-09-25 03:08:49 UTC (rev 6810) +++ branches/indy/src/org/python/compiler/Module.java 2009-09-25 03:13:10 UTC (rev 6811) @@ -16,7 +16,6 @@ import org.python.core.CodeFlag; import org.python.core.CodeLoader; import org.python.core.CompilerFlags; -import org.python.core.invokedynamic.InvokeDynamicSupport; import org.python.core.Py; import org.python.core.PyException; import org.python.core.PyRunnableBootstrap; @@ -541,10 +540,6 @@ Code c = classfile.addMethod("<init>", "(Ljava/lang/String;)V", ACC_PUBLIC); c.aload(0); c.invokespecial("org/python/core/IndyFunctionTable", "<init>", "()V"); - - //HERE - //c.invokestatic(p(InvokeDynamicSupport.class), "registerBootstrap", sig(void.class, Class.class)); - addConstants(c); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-25 03:08:57
|
Revision: 6810 http://jython.svn.sourceforge.net/jython/?rev=6810&view=rev Author: fwierzbicki Date: 2009-09-25 03:08:49 +0000 (Fri, 25 Sep 2009) Log Message: ----------- Replace tableswitch in modules with MethodHandles. Modified Paths: -------------- branches/indy/build.xml branches/indy/src/org/python/compiler/ClassConstants.java branches/indy/src/org/python/compiler/Code.java branches/indy/src/org/python/compiler/Module.java branches/indy/src/org/python/core/Py.java branches/indy/src/org/python/core/imp.java Added Paths: ----------- branches/indy/src/org/python/core/IndyCode.java branches/indy/src/org/python/core/IndyFunctionTable.java branches/indy/src/org/python/util/CodegenUtils.java Modified: branches/indy/build.xml =================================================================== --- branches/indy/build.xml 2009-09-24 01:34:49 UTC (rev 6809) +++ branches/indy/build.xml 2009-09-25 03:08:49 UTC (rev 6810) @@ -171,11 +171,11 @@ <property name="dist.dir" value="${work.dir}/dist" /> <property name="apidoc.dir" value="${dist.dir}/Doc/javadoc" /> <property name="junit.reports" value="${dist.dir}/testreports" /> + <!-- <property name="javac.Xlint" value="-Xlint -Xlint:-serial -Xlint:-unchecked -Xlint:-cast -Xbootclasspath/p:${extlibs.dir}/jsr292-mock.jar"/> - <!-- + --> <property name="javac.Xlint" value="-Xlint -Xlint:-serial -XDinvokedynamic -Xlint:-unchecked -Xlint:-cast"/> - --> <!-- classpaths --> <path id="main.classpath"> <pathelement path="${extlibs.dir}/libreadline-java-0.8.jar" /> Modified: branches/indy/src/org/python/compiler/ClassConstants.java =================================================================== --- branches/indy/src/org/python/compiler/ClassConstants.java 2009-09-24 01:34:49 UTC (rev 6809) +++ branches/indy/src/org/python/compiler/ClassConstants.java 2009-09-25 03:08:49 UTC (rev 6810) @@ -15,7 +15,7 @@ final static String $pyFloat = "Lorg/python/core/PyFloat;"; final static String $pyComplex = "Lorg/python/core/PyComplex;"; final static String $pyRunnable = "Lorg/python/core/PyRunnable;"; - final static String $pyFuncTbl = "Lorg/python/core/PyFunctionTable;"; + final static String $pyFuncTbl = "Lorg/python/core/IndyFunctionTable;"; final static String $pyProxy = "Lorg/python/core/PyProxy;"; final static String $obj = "Ljava/lang/Object;"; Modified: branches/indy/src/org/python/compiler/Code.java =================================================================== --- branches/indy/src/org/python/compiler/Code.java 2009-09-24 01:34:49 UTC (rev 6809) +++ branches/indy/src/org/python/compiler/Code.java 2009-09-25 03:08:49 UTC (rev 6810) @@ -480,7 +480,11 @@ public void invokevirtual(String owner, String name, String type) { mv.visitMethodInsn(INVOKEVIRTUAL, owner, name, type); } - + + public void invokedynamic(String owner, String name, String type) { + mv.visitMethodInsn(INVOKEDYNAMIC, owner, name, type); + } + public void ireturn() { mv.visitInsn(IRETURN); } Modified: branches/indy/src/org/python/compiler/Module.java =================================================================== --- branches/indy/src/org/python/compiler/Module.java 2009-09-24 01:34:49 UTC (rev 6809) +++ branches/indy/src/org/python/compiler/Module.java 2009-09-25 03:08:49 UTC (rev 6810) @@ -16,6 +16,7 @@ import org.python.core.CodeFlag; import org.python.core.CodeLoader; import org.python.core.CompilerFlags; +import org.python.core.invokedynamic.InvokeDynamicSupport; import org.python.core.Py; import org.python.core.PyException; import org.python.core.PyRunnableBootstrap; @@ -24,6 +25,7 @@ import org.python.antlr.PythonTree; import org.python.antlr.ast.Suite; import org.python.antlr.base.mod; +import static org.python.util.CodegenUtils.*; class PyIntegerConstant extends Constant implements ClassConstants, Opcodes { @@ -268,8 +270,23 @@ c.getstatic(module.classfile.name, "self", "L"+module.classfile.name+";"); - c.iconst(id); + //REPLACING WITH METH HANDLE + //c.iconst(id); +c.visitMethodInsn(INVOKESTATIC, "java/dyn/MethodHandles", "lookup", "()Ljava/dyn/MethodHandles$Lookup;"); +c.visitLdcInsn(Type.getType("L"+module.classfile.name+";")); +c.visitLdcInsn(fname); +c.visitLdcInsn(Type.getType("Lorg/python/core/PyObject;")); +c.visitLdcInsn(Type.getType("Lorg/python/core/PyFrame;")); +c.visitInsn(ICONST_1); +c.visitTypeInsn(ANEWARRAY, "java/lang/Class"); +c.visitInsn(DUP); +c.visitInsn(ICONST_0); +c.visitLdcInsn(Type.getType("Lorg/python/core/ThreadState;")); +c.visitInsn(AASTORE); +c.visitMethodInsn(INVOKESTATIC, "java/dyn/MethodType", "make", "(Ljava/lang/Class;Ljava/lang/Class;[Ljava/lang/Class;)Ljava/dyn/MethodType;"); +c.visitMethodInsn(INVOKEVIRTUAL, "java/dyn/MethodHandles$Lookup", "findVirtual", "(Ljava/lang/Class;Ljava/lang/String;Ljava/dyn/MethodType;)Ljava/dyn/MethodHandle;"); + if (cellvars != null) { int strArray = CodeCompiler.makeStrings(c, cellvars); c.aload(strArray); @@ -287,7 +304,7 @@ c.iconst(moreflags); - c.invokestatic("org/python/core/Py", "newCode", "(I" + $strArr + $str + $str + "IZZ" + $pyFuncTbl + "I" + $strArr + $strArr + "II)" + $pyCode); + c.invokestatic("org/python/core/Py", "newCode", "(I" + $strArr + $str + $str + "IZZ" + $pyFuncTbl + "Ljava/dyn/MethodHandle;" + $strArr + $strArr + "II)" + $pyCode); c.putstatic(module.classfile.name, name, $pyCode); } } @@ -310,7 +327,7 @@ public Module(String name, String filename, boolean linenumbers, long mtime) { this.linenumbers = linenumbers; this.mtime = mtime; - classfile = new ClassFile(name, "org/python/core/PyFunctionTable", + classfile = new ClassFile(name, "org/python/core/IndyFunctionTable", ACC_SYNCHRONIZED | ACC_PUBLIC, mtime); constants = new Hashtable<Constant,Constant>(); sfilename = filename; @@ -523,7 +540,11 @@ public void addInit() throws IOException { Code c = classfile.addMethod("<init>", "(Ljava/lang/String;)V", ACC_PUBLIC); c.aload(0); - c.invokespecial("org/python/core/PyFunctionTable", "<init>", "()V"); + c.invokespecial("org/python/core/IndyFunctionTable", "<init>", "()V"); + + //HERE + //c.invokestatic(p(InvokeDynamicSupport.class), "registerBootstrap", sig(void.class, Class.class)); + addConstants(c); } @@ -584,30 +605,22 @@ public void addFunctions() throws IOException { Code code = classfile.addMethod( "call_function", - "(I" + $pyFrame + $threadState + ")" + $pyObj, + "(Ljava/dyn/MethodHandle;" + $pyFrame + $threadState + ")" + $pyObj, ACC_PUBLIC); + code.aload(1); // handle code.aload(0); // this code.aload(2); // frame code.aload(3); // thread state + /* Label def = new Label(); Label[] labels = new Label[codes.size()]; int i; for(i=0; i<labels.length; i++) labels[i] = new Label(); - //Get index for function to call - code.iload(1); - code.tableswitch(0, labels.length - 1, def, labels); - for(i=0; i<labels.length; i++) { - code.label(labels[i]); - code.invokevirtual(classfile.name, (codes.get(i)).fname, "(" + $pyFrame + $threadState + ")" + $pyObj); - code.areturn(); - } - code.label(def); - - //Should probably throw internal exception here - code.aconst_null(); + */ + code.invokevirtual("java/dyn/MethodHandle", "invoke", "(Ljava/lang/Object;" + $pyFrame + $threadState + ")" + $pyObj); code.areturn(); } Added: branches/indy/src/org/python/core/IndyCode.java =================================================================== --- branches/indy/src/org/python/core/IndyCode.java (rev 0) +++ branches/indy/src/org/python/core/IndyCode.java 2009-09-25 03:08:49 UTC (rev 6810) @@ -0,0 +1,212 @@ +// Copyright (c) Corporation for National Research Initiatives +package org.python.core; + +/** + * An implementation of PyCode where the actual executable content + * is stored as a PyFunctionTable instance and an integer index. + */ + +import org.python.modules._systemrestart; +import java.dyn.MethodHandle; + +public class IndyCode extends PyBaseCode +{ + + IndyFunctionTable funcs; + MethodHandle func_id; + public String co_code = ""; // only used by inspect + + public IndyCode(int argcount, String varnames[], + String filename, String name, + int firstlineno, + boolean varargs, boolean varkwargs, + IndyFunctionTable funcs, MethodHandle func_id) + { + this(argcount, varnames, filename, name, firstlineno, varargs, + varkwargs, funcs, func_id, null, null, 0, 0); + } + + public IndyCode(int argcount, String varnames[], + String filename, String name, + int firstlineno, + boolean varargs, boolean varkwargs, + IndyFunctionTable funcs, MethodHandle func_id, + String[] cellvars, String[] freevars, int npurecell, + int moreflags) // may change + { + co_argcount = nargs = argcount; + co_varnames = varnames; + co_nlocals = varnames.length; + co_filename = filename; + co_firstlineno = firstlineno; + co_cellvars = cellvars; + co_freevars = freevars; + this.jy_npurecell = npurecell; + this.varargs = varargs; + co_name = name; + if (varargs) { + co_argcount -= 1; + co_flags.setFlag(CodeFlag.CO_VARARGS); + } + this.varkwargs = varkwargs; + if (varkwargs) { + co_argcount -= 1; + co_flags.setFlag(CodeFlag.CO_VARKEYWORDS); + } + co_flags = new CompilerFlags(co_flags.toBits() | moreflags); + this.funcs = funcs; + this.func_id = func_id; + } + + private static final String[] __members__ = { + "co_name", "co_argcount", + "co_varnames", "co_filename", "co_firstlineno", + "co_flags","co_cellvars","co_freevars","co_nlocals" + // not supported: co_code, co_consts, co_names, + // co_lnotab, co_stacksize + }; + + public PyObject __dir__() { + PyString members[] = new PyString[__members__.length]; + for (int i = 0; i < __members__.length; i++) + members[i] = new PyString(__members__[i]); + return new PyList(members); + } + + private void throwReadonly(String name) { + for (int i = 0; i < __members__.length; i++) + if (__members__[i] == name) + throw Py.TypeError("readonly attribute"); + throw Py.AttributeError(name); + } + + public void __setattr__(String name, PyObject value) { + // no writable attributes + throwReadonly(name); + } + + public void __delattr__(String name) { + throwReadonly(name); + } + + private static PyTuple toPyStringTuple(String[] ar) { + if (ar == null) return Py.EmptyTuple; + int sz = ar.length; + PyString[] pystr = new PyString[sz]; + for (int i = 0; i < sz; i++) { + pystr[i] = new PyString(ar[i]); + } + return new PyTuple(pystr); + } + + public PyObject __findattr_ex__(String name) { + // have to craft co_varnames specially + if (name == "co_varnames") { + return toPyStringTuple(co_varnames); + } + if (name == "co_cellvars") { + return toPyStringTuple(co_cellvars); + } + if (name == "co_freevars") { + return toPyStringTuple(co_freevars); + } + if (name == "co_filename") { + return new PyString(co_filename); + } + if (name == "co_name") { + return new PyString(co_name); + } + if (name == "co_flags") { + return Py.newInteger(co_flags.toBits()); + } + return super.__findattr_ex__(name); + } + + @Override + public PyObject call(ThreadState ts, PyFrame frame, PyObject closure) { +// System.err.println("tablecode call: "+co_name); + if (ts.systemState == null) { + ts.systemState = Py.defaultSystemState; + } + //System.err.println("got ts: "+ts+", "+ts.systemState); + + // Cache previously defined exception + PyException previous_exception = ts.exception; + + // Push frame + frame.f_back = ts.frame; + if (frame.f_builtins == null) { + if (frame.f_back != null) { + frame.f_builtins = frame.f_back.f_builtins; + } else { + //System.err.println("ts: "+ts); + //System.err.println("ss: "+ts.systemState); + frame.f_builtins = PySystemState.builtins; + } + } + // nested scopes: setup env with closure + // this should only be done once, so let the frame take care of it + frame.setupEnv((PyTuple)closure); + + ts.frame = frame; + + // Handle trace function for debugging + if (ts.tracefunc != null) { + frame.f_lineno = co_firstlineno; + frame.tracefunc = ts.tracefunc.traceCall(frame); + } + + // Handle trace function for profiling + if (ts.profilefunc != null) { + ts.profilefunc.traceCall(frame); + } + + PyObject ret; + try { + ret = funcs.call_function(func_id, frame, ts); + } catch (Throwable t) { + // Convert exceptions that occured in Java code to PyExceptions + PyException pye = Py.JavaError(t); + pye.tracebackHere(frame); + + frame.f_lasti = -1; + + if (frame.tracefunc != null) { + frame.tracefunc.traceException(frame, pye); + } + if (ts.profilefunc != null) { + ts.profilefunc.traceException(frame, pye); + } + + // Rethrow the exception to the next stack frame + ts.exception = previous_exception; + ts.frame = ts.frame.f_back; + throw pye; + } + + if (frame.tracefunc != null) { + frame.tracefunc.traceReturn(frame, ret); + } + // Handle trace function for profiling + if (ts.profilefunc != null) { + ts.profilefunc.traceReturn(frame, ret); + } + + // Restore previously defined exception + ts.exception = previous_exception; + + ts.frame = ts.frame.f_back; + + // Check for interruption, which is used for restarting the interpreter + // on Jython + if (Thread.currentThread().isInterrupted()) { + throw new PyException(_systemrestart.SystemRestart); + } + return ret; + } + + @Override + protected PyObject interpret(PyFrame f, ThreadState ts) { + throw new UnsupportedOperationException("Inlined interpret to improve call performance (may want to reconsider in the future)."); + } +} Property changes on: branches/indy/src/org/python/core/IndyCode.java ___________________________________________________________________ Added: svn:eol-style + native Added: branches/indy/src/org/python/core/IndyFunctionTable.java =================================================================== --- branches/indy/src/org/python/core/IndyFunctionTable.java (rev 0) +++ branches/indy/src/org/python/core/IndyFunctionTable.java 2009-09-25 03:08:49 UTC (rev 6810) @@ -0,0 +1,15 @@ +// Copyright (c) Corporation for National Research Initiatives +package org.python.core; + +import java.dyn.MethodHandle; +/** + * An entry point for class that implements several function calls. + * <P> + * Used together with the PyTableCode class. + * + * @see PyTableCode + */ + +public abstract class IndyFunctionTable { + abstract public PyObject call_function(MethodHandle mh, PyFrame frame, ThreadState ts); +} Property changes on: branches/indy/src/org/python/core/IndyFunctionTable.java ___________________________________________________________________ Added: svn:eol-style + native Modified: branches/indy/src/org/python/core/Py.java =================================================================== --- branches/indy/src/org/python/core/Py.java 2009-09-24 01:34:49 UTC (rev 6809) +++ branches/indy/src/org/python/core/Py.java 2009-09-25 03:08:49 UTC (rev 6810) @@ -1,6 +1,7 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; +import java.dyn.MethodHandle; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; @@ -630,10 +631,10 @@ public static PyCode newCode(int argcount, String varnames[], String filename, String name, boolean args, boolean keywords, - PyFunctionTable funcs, int func_id, + IndyFunctionTable funcs, MethodHandle func_id, String[] cellvars, String[] freevars, int npurecell, int moreflags) { - return new PyTableCode(argcount, varnames, + return new IndyCode(argcount, varnames, filename, name, 0, args, keywords, funcs, func_id, cellvars, freevars, npurecell, moreflags); @@ -643,10 +644,10 @@ String filename, String name, int firstlineno, boolean args, boolean keywords, - PyFunctionTable funcs, int func_id, + IndyFunctionTable funcs, MethodHandle func_id, String[] cellvars, String[] freevars, int npurecell, int moreflags) { - return new PyTableCode(argcount, varnames, + return new IndyCode(argcount, varnames, filename, name, firstlineno, args, keywords, funcs, func_id, cellvars, freevars, npurecell, moreflags); @@ -656,8 +657,8 @@ public static PyCode newCode(int argcount, String varnames[], String filename, String name, boolean args, boolean keywords, - PyFunctionTable funcs, int func_id) { - return new PyTableCode(argcount, varnames, + IndyFunctionTable funcs, MethodHandle func_id) { + return new IndyCode(argcount, varnames, filename, name, 0, args, keywords, funcs, func_id); } @@ -666,8 +667,8 @@ String filename, String name, int firstlineno, boolean args, boolean keywords, - PyFunctionTable funcs, int func_id) { - return new PyTableCode(argcount, varnames, + IndyFunctionTable funcs, MethodHandle func_id) { + return new IndyCode(argcount, varnames, filename, name, firstlineno, args, keywords, funcs, func_id); } @@ -1194,9 +1195,9 @@ globals = ts.frame.f_globals; } - PyTableCode tc = null; - if (code instanceof PyTableCode) { - tc = (PyTableCode) code; + IndyCode tc = null; + if (code instanceof IndyCode) { + tc = (IndyCode) code; } f = new PyFrame(tc, locals, globals, Modified: branches/indy/src/org/python/core/imp.java =================================================================== --- branches/indy/src/org/python/core/imp.java 2009-09-24 01:34:49 UTC (rev 6809) +++ branches/indy/src/org/python/core/imp.java 2009-09-25 03:08:49 UTC (rev 6810) @@ -308,9 +308,9 @@ public static PyObject createFromCode(String name, PyCode c, String moduleLocation) { PyModule module = addModule(name); - PyTableCode code = null; - if (c instanceof PyTableCode) { - code = (PyTableCode) c; + IndyCode code = null; + if (c instanceof IndyCode) { + code = (IndyCode) c; } if (moduleLocation != null) { Added: branches/indy/src/org/python/util/CodegenUtils.java =================================================================== --- branches/indy/src/org/python/util/CodegenUtils.java (rev 0) +++ branches/indy/src/org/python/util/CodegenUtils.java 2009-09-25 03:08:49 UTC (rev 6810) @@ -0,0 +1,137 @@ +/* + * Initial code taken from Charlie Nutter's org.jruby.util.CodegenUtils. + */ + +package org.python.util; + +import java.util.Arrays; + +public class CodegenUtils { + + /** + * Creates a dotted class name from a path/package name + */ + public static String c(String p) { + return p.replace('/', '.'); + } + + /** + * Creates a class path name, from a Class. + */ + public static String p(Class n) { + return n.getName().replace('.','/'); + } + + /** + * Creates a class identifier of form Labc/abc;, from a Class. + */ + public static String ci(Class n) { + if (n.isArray()) { + n = n.getComponentType(); + if (n.isPrimitive()) { + if (n == Byte.TYPE) { + return "[B"; + } else if (n == Boolean.TYPE) { + return "[Z"; + } else if (n == Short.TYPE) { + return "[S"; + } else if (n == Character.TYPE) { + return "[C"; + } else if (n == Integer.TYPE) { + return "[I"; + } else if (n == Float.TYPE) { + return "[F"; + } else if (n == Double.TYPE) { + return "[D"; + } else if (n == Long.TYPE) { + return "[J"; + } else { + throw new RuntimeException("Unrecognized type in compiler: " + n.getName()); + } + } else { + return "[" + ci(n); + } + } else { + if (n.isPrimitive()) { + if (n == Byte.TYPE) { + return "B"; + } else if (n == Boolean.TYPE) { + return "Z"; + } else if (n == Short.TYPE) { + return "S"; + } else if (n == Character.TYPE) { + return "C"; + } else if (n == Integer.TYPE) { + return "I"; + } else if (n == Float.TYPE) { + return "F"; + } else if (n == Double.TYPE) { + return "D"; + } else if (n == Long.TYPE) { + return "J"; + } else if (n == Void.TYPE) { + return "V"; + } else { + throw new RuntimeException("Unrecognized type in compiler: " + n.getName()); + } + } else { + return "L" + p(n) + ";"; + } + } + } + + /** + * Create a method signature from the given param types and return values + */ + public static String sig(Class retval, Class... params) { + return sigParams(params) + ci(retval); + } + + public static String sig(Class retval, String descriptor, Class... params) { + return sigParams(descriptor, params) + ci(retval); + } + + public static String sigParams(Class... params) { + StringBuilder signature = new StringBuilder("("); + + for (int i = 0; i < params.length; i++) { + signature.append(ci(params[i])); + } + + signature.append(")"); + + return signature.toString(); + } + + public static String sigParams(String descriptor, Class... params) { + StringBuilder signature = new StringBuilder("("); + + signature.append(descriptor); + + for (int i = 0; i < params.length; i++) { + signature.append(ci(params[i])); + } + + signature.append(")"); + + return signature.toString(); + } + + public static Class[] params(Class... classes) { + return classes; + } + + public static Class[] params(Class cls, int times) { + Class[] classes = new Class[times]; + Arrays.fill(classes, cls); + return classes; + } + + public static Class[] params(Class cls1, Class clsFill, int times) { + Class[] classes = new Class[times + 1]; + Arrays.fill(classes, clsFill); + classes[0] = cls1; + return classes; + } + +} Property changes on: branches/indy/src/org/python/util/CodegenUtils.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-24 01:35:01
|
Revision: 6809 http://jython.svn.sourceforge.net/jython/?rev=6809&view=rev Author: fwierzbicki Date: 2009-09-24 01:34:49 +0000 (Thu, 24 Sep 2009) Log Message: ----------- tag rc3 Added Paths: ----------- tags/Release_2_5_1rc3/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-24 01:22:32
|
Revision: 6808 http://jython.svn.sourceforge.net/jython/?rev=6808&view=rev Author: fwierzbicki Date: 2009-09-24 00:17:16 +0000 (Thu, 24 Sep 2009) Log Message: ----------- Finish updating README for rc3. Modified Paths: -------------- trunk/jython/README.txt Modified: trunk/jython/README.txt =================================================================== --- trunk/jython/README.txt 2009-09-24 00:16:35 UTC (rev 6807) +++ trunk/jython/README.txt 2009-09-24 00:17:16 UTC (rev 6808) @@ -1,4 +1,4 @@ -Welcome to Jython 2.5.1rc2 +Welcome to Jython 2.5.1rc3 ========================== This is the third release candidate of the 2.5.1 version of Jython. This This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-24 01:22:21
|
Revision: 6807 http://jython.svn.sourceforge.net/jython/?rev=6807&view=rev Author: fwierzbicki Date: 2009-09-24 00:16:35 +0000 (Thu, 24 Sep 2009) Log Message: ----------- Update README for rc3. Modified Paths: -------------- trunk/jython/README.txt Modified: trunk/jython/README.txt =================================================================== --- trunk/jython/README.txt 2009-09-23 20:45:33 UTC (rev 6806) +++ trunk/jython/README.txt 2009-09-24 00:16:35 UTC (rev 6807) @@ -1,10 +1,11 @@ Welcome to Jython 2.5.1rc2 ========================== -This is the second release candidate of the 2.5.1 version of Jython. This +This is the third release candidate of the 2.5.1 version of Jython. This release fixes a number of bugs, including some major errors when using -coroutines and when using relative imports. Please see the NEWS file for -detailed release notes. +coroutines and when using relative imports, as well as a potential data loss +bug when writing to files in append mode. Please see the NEWS file for detailed +release notes. The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-23 20:45:46
|
Revision: 6806 http://jython.svn.sourceforge.net/jython/?rev=6806&view=rev Author: fwierzbicki Date: 2009-09-23 20:45:33 +0000 (Wed, 23 Sep 2009) Log Message: ----------- Fixed up call_function and classpath in indy shell script. Modified Paths: -------------- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java trunk/sandbox/wierzbicki/indy_jython/indy Modified: trunk/sandbox/wierzbicki/indy_jython/IndyDump.java =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java 2009-09-23 17:34:06 UTC (rev 6805) +++ trunk/sandbox/wierzbicki/indy_jython/IndyDump.java 2009-09-23 20:45:33 UTC (rev 6806) @@ -150,7 +150,7 @@ mv.visitLdcInsn(Type.getType("Lorg/python/core/ThreadState;")); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKESTATIC, "java/dyn/MethodType", "make", "(Ljava/lang/Class;Ljava/lang/Class;[Ljava/lang/Class;)Ljava/dyn/MethodType;"); -mv.visitMethodInsn(INVOKEVIRTUAL, "java/dyn/MethodHandles$Lookup", "findStatic", "(Ljava/lang/Class;Ljava/lang/String;Ljava/dyn/MethodType;)Ljava/dyn/MethodHandle;"); +mv.visitMethodInsn(INVOKEVIRTUAL, "java/dyn/MethodHandles$Lookup", "findVirtual", "(Ljava/lang/Class;Ljava/lang/String;Ljava/dyn/MethodType;)Ljava/dyn/MethodHandle;"); mv.visitInsn(ACONST_NULL); mv.visitInsn(ACONST_NULL); @@ -188,7 +188,7 @@ mv.visitLdcInsn(Type.getType("Lorg/python/core/ThreadState;")); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKESTATIC, "java/dyn/MethodType", "make", "(Ljava/lang/Class;Ljava/lang/Class;[Ljava/lang/Class;)Ljava/dyn/MethodType;"); -mv.visitMethodInsn(INVOKEVIRTUAL, "java/dyn/MethodHandles$Lookup", "findStatic", "(Ljava/lang/Class;Ljava/lang/String;Ljava/dyn/MethodType;)Ljava/dyn/MethodHandle;"); +mv.visitMethodInsn(INVOKEVIRTUAL, "java/dyn/MethodHandles$Lookup", "findVirtual", "(Ljava/lang/Class;Ljava/lang/String;Ljava/dyn/MethodType;)Ljava/dyn/MethodHandle;"); mv.visitInsn(ACONST_NULL); mv.visitInsn(ACONST_NULL); @@ -197,7 +197,7 @@ mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newCode", "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/IndyFunctionTable;Ljava/dyn/MethodHandle;[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); mv.visitFieldInsn(PUTSTATIC, "Hello", "greet$1", "Lorg/python/core/PyCode;"); mv.visitInsn(RETURN); -mv.visitMaxs(13, 3); +mv.visitMaxs(17, 3); mv.visitEnd(); } { @@ -236,13 +236,12 @@ mv = cw.visitMethod(ACC_PUBLIC, "call_function", "(Ljava/dyn/MethodHandle;Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;", null, null); mv.visitCode(); mv.visitFrame(Opcodes.F_NEW, 0, new Object[] {}, 0, new Object[] {}); +mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 3); +mv.visitMethodInsn(INVOKEVIRTUAL, "java/dyn/MethodHandle", "invoke", "(LHello;Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;"); -//MethodHandle -mv.visitVarInsn(ALOAD, 1); - /* Label l0 = new Label(); Label l1 = new Label(); Modified: trunk/sandbox/wierzbicki/indy_jython/indy =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/indy 2009-09-23 17:34:06 UTC (rev 6805) +++ trunk/sandbox/wierzbicki/indy_jython/indy 2009-09-23 20:45:33 UTC (rev 6806) @@ -5,4 +5,4 @@ $JAVA_HOME/bin/javac -classpath $JARS:. IndyDump.java $JAVA_HOME/bin/java -classpath $JARS:. IndyDump -$JAVA_HOME/bin/java -classpath $JARS:. Hello +$JAVA_HOME/bin/java -Xbootclasspath/a:.:$JARS -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles -XX:+EnableInvokeDynamic Hello This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-23 17:34:15
|
Revision: 6805 http://jython.svn.sourceforge.net/jython/?rev=6805&view=rev Author: fwierzbicki Date: 2009-09-23 17:34:06 +0000 (Wed, 23 Sep 2009) Log Message: ----------- Okay, simple call to a MethodHandle works from some bytecode works. Modified Paths: -------------- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java Modified: trunk/sandbox/wierzbicki/indy_jython/IndyDump.java =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java 2009-09-22 22:45:39 UTC (rev 6804) +++ trunk/sandbox/wierzbicki/indy_jython/IndyDump.java 2009-09-23 17:34:06 UTC (rev 6805) @@ -137,7 +137,20 @@ mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); ////MethodHandle goes here -mv.visitInsn(ACONST_NULL); +////mv.visitInsn(ACONST_NULL); +mv.visitMethodInsn(INVOKESTATIC, "java/dyn/MethodHandles", "lookup", "()Ljava/dyn/MethodHandles$Lookup;"); +mv.visitLdcInsn(Type.getType("LHello;")); +mv.visitLdcInsn("f$0"); +mv.visitLdcInsn(Type.getType("Lorg/python/core/PyObject;")); +mv.visitLdcInsn(Type.getType("Lorg/python/core/PyFrame;")); +mv.visitInsn(ICONST_1); +mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); +mv.visitInsn(DUP); +mv.visitInsn(ICONST_0); +mv.visitLdcInsn(Type.getType("Lorg/python/core/ThreadState;")); +mv.visitInsn(AASTORE); +mv.visitMethodInsn(INVOKESTATIC, "java/dyn/MethodType", "make", "(Ljava/lang/Class;Ljava/lang/Class;[Ljava/lang/Class;)Ljava/dyn/MethodType;"); +mv.visitMethodInsn(INVOKEVIRTUAL, "java/dyn/MethodHandles$Lookup", "findStatic", "(Ljava/lang/Class;Ljava/lang/String;Ljava/dyn/MethodType;)Ljava/dyn/MethodHandle;"); mv.visitInsn(ACONST_NULL); mv.visitInsn(ACONST_NULL); @@ -162,7 +175,20 @@ mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); ////MethodHandle goes here -mv.visitInsn(ACONST_NULL); +////mv.visitInsn(ACONST_NULL); +mv.visitMethodInsn(INVOKESTATIC, "java/dyn/MethodHandles", "lookup", "()Ljava/dyn/MethodHandles$Lookup;"); +mv.visitLdcInsn(Type.getType("LHello;")); +mv.visitLdcInsn("greet$1"); +mv.visitLdcInsn(Type.getType("Lorg/python/core/PyObject;")); +mv.visitLdcInsn(Type.getType("Lorg/python/core/PyFrame;")); +mv.visitInsn(ICONST_1); +mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); +mv.visitInsn(DUP); +mv.visitInsn(ICONST_0); +mv.visitLdcInsn(Type.getType("Lorg/python/core/ThreadState;")); +mv.visitInsn(AASTORE); +mv.visitMethodInsn(INVOKESTATIC, "java/dyn/MethodType", "make", "(Ljava/lang/Class;Ljava/lang/Class;[Ljava/lang/Class;)Ljava/dyn/MethodType;"); +mv.visitMethodInsn(INVOKEVIRTUAL, "java/dyn/MethodHandles$Lookup", "findStatic", "(Ljava/lang/Class;Ljava/lang/String;Ljava/dyn/MethodType;)Ljava/dyn/MethodHandle;"); mv.visitInsn(ACONST_NULL); mv.visitInsn(ACONST_NULL); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-22 22:45:48
|
Revision: 6804 http://jython.svn.sourceforge.net/jython/?rev=6804&view=rev Author: fwierzbicki Date: 2009-09-22 22:45:39 +0000 (Tue, 22 Sep 2009) Log Message: ----------- Put MethodHandle into call_function signature. Modified Paths: -------------- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java Modified: trunk/sandbox/wierzbicki/indy_jython/IndyDump.java =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java 2009-09-22 18:00:39 UTC (rev 6803) +++ trunk/sandbox/wierzbicki/indy_jython/IndyDump.java 2009-09-22 22:45:39 UTC (rev 6804) @@ -136,8 +136,8 @@ mv.visitInsn(ICONST_0); mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); +////MethodHandle goes here mv.visitInsn(ACONST_NULL); -////mv.visitInsn(ICONST_0); mv.visitInsn(ACONST_NULL); mv.visitInsn(ACONST_NULL); @@ -161,8 +161,8 @@ mv.visitInsn(ICONST_0); mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); +////MethodHandle goes here mv.visitInsn(ACONST_NULL); -////mv.visitInsn(ICONST_1); mv.visitInsn(ACONST_NULL); mv.visitInsn(ACONST_NULL); @@ -207,13 +207,17 @@ mv.visitEnd(); } { -mv = cw.visitMethod(ACC_PUBLIC, "call_function", "(ILorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;", null, null); +mv = cw.visitMethod(ACC_PUBLIC, "call_function", "(Ljava/dyn/MethodHandle;Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;", null, null); mv.visitCode(); mv.visitFrame(Opcodes.F_NEW, 0, new Object[] {}, 0, new Object[] {}); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 3); -mv.visitVarInsn(ILOAD, 1); + +//MethodHandle +mv.visitVarInsn(ALOAD, 1); + +/* Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); @@ -228,9 +232,10 @@ mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_NEW, 4, new Object[] {"Hello", Opcodes.INTEGER, "org/python/core/PyFrame", "org/python/core/ThreadState"}, 3, new Object[] {"Hello", "org/python/core/PyFrame", "org/python/core/ThreadState"}); +*/ mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); -mv.visitMaxs(4, 4); +mv.visitMaxs(5, 4); mv.visitEnd(); } cw.visitEnd(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |