Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: <pjenvey@us...> - 2008-07-23 20:36:44
|
Revision: 4991 http://jython.svn.sourceforge.net/jython/?rev=4991&view=rev Author: pjenvey Date: 2008-07-23 20:36:42 +0000 (Wed, 23 Jul 2008) Log Message: ----------- o fix passing chars > 256 to Py.makeCharacter o make struct.error a class and raise struct.errors instead of OverflowErrors Modified Paths: -------------- branches/asm/src/org/python/core/Py.java branches/asm/src/org/python/modules/struct.java Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-07-23 19:13:04 UTC (rev 4990) +++ branches/asm/src/org/python/core/Py.java 2008-07-23 20:36:42 UTC (rev 4991) @@ -1444,6 +1444,11 @@ static final PyString makeCharacter(int codepoint, boolean toUnicode) { if (toUnicode) { return new PyUnicode(codepoint); + } else if (codepoint > 65536) { + throw new IllegalArgumentException(String.format("Codepoint > 65536 (%d) requires " + + "toUnicode argument", codepoint)); + } else if (codepoint > 256) { + return new PyString((char)codepoint); } if (letters == null) { Modified: branches/asm/src/org/python/modules/struct.java =================================================================== --- branches/asm/src/org/python/modules/struct.java 2008-07-23 19:13:04 UTC (rev 4990) +++ branches/asm/src/org/python/modules/struct.java 2008-07-23 20:36:42 UTC (rev 4991) @@ -16,6 +16,7 @@ import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyString; +import org.python.core.PyStringMap; import org.python.core.PyTuple; import java.math.BigInteger; @@ -257,7 +258,7 @@ * Exception raised on various occasions; argument is a * string describing what is wrong. */ - public static PyString error = new PyString("struct.error"); + public static final PyObject error = Py.makeClass("error", Py.Exception, exceptionNamespace()); public static String __doc__ = "Functions to convert between Python values and C structs.\n" + @@ -330,8 +331,9 @@ long get_long(PyObject value) { if (value instanceof PyLong){ Object v = value.__tojava__(Long.TYPE); - if (v == Py.NoConversion) - throw Py.OverflowError("long int too long to convert"); + if (v == Py.NoConversion) { + throw StructError("long int too long to convert"); + } return ((Long) v).longValue(); } else return get_int(value); @@ -341,7 +343,7 @@ if (value instanceof PyLong){ BigInteger v = (BigInteger)value.__tojava__(BigInteger.class); if (v.compareTo(PyLong.maxULong) > 0){ - throw Py.OverflowError("unsigned long int too long to convert"); + throw StructError("unsigned long int too long to convert"); } return v; } else @@ -1041,4 +1043,10 @@ private static PyException StructError(String explanation) { return new PyException(error, explanation); } + + private static PyObject exceptionNamespace() { + PyObject dict = new PyStringMap(); + dict.__setitem__("__module__", new PyString("struct")); + return dict; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pjenvey@us...> - 2008-07-23 20:36:44
|
Revision: 4991 http://jython.svn.sourceforge.net/jython/?rev=4991&view=rev Author: pjenvey Date: 2008-07-23 20:36:42 +0000 (Wed, 23 Jul 2008) Log Message: ----------- o fix passing chars > 256 to Py.makeCharacter o make struct.error a class and raise struct.errors instead of OverflowErrors Modified Paths: -------------- branches/asm/src/org/python/core/Py.java branches/asm/src/org/python/modules/struct.java Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-07-23 19:13:04 UTC (rev 4990) +++ branches/asm/src/org/python/core/Py.java 2008-07-23 20:36:42 UTC (rev 4991) @@ -1444,6 +1444,11 @@ static final PyString makeCharacter(int codepoint, boolean toUnicode) { if (toUnicode) { return new PyUnicode(codepoint); + } else if (codepoint > 65536) { + throw new IllegalArgumentException(String.format("Codepoint > 65536 (%d) requires " + + "toUnicode argument", codepoint)); + } else if (codepoint > 256) { + return new PyString((char)codepoint); } if (letters == null) { Modified: branches/asm/src/org/python/modules/struct.java =================================================================== --- branches/asm/src/org/python/modules/struct.java 2008-07-23 19:13:04 UTC (rev 4990) +++ branches/asm/src/org/python/modules/struct.java 2008-07-23 20:36:42 UTC (rev 4991) @@ -16,6 +16,7 @@ import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyString; +import org.python.core.PyStringMap; import org.python.core.PyTuple; import java.math.BigInteger; @@ -257,7 +258,7 @@ * Exception raised on various occasions; argument is a * string describing what is wrong. */ - public static PyString error = new PyString("struct.error"); + public static final PyObject error = Py.makeClass("error", Py.Exception, exceptionNamespace()); public static String __doc__ = "Functions to convert between Python values and C structs.\n" + @@ -330,8 +331,9 @@ long get_long(PyObject value) { if (value instanceof PyLong){ Object v = value.__tojava__(Long.TYPE); - if (v == Py.NoConversion) - throw Py.OverflowError("long int too long to convert"); + if (v == Py.NoConversion) { + throw StructError("long int too long to convert"); + } return ((Long) v).longValue(); } else return get_int(value); @@ -341,7 +343,7 @@ if (value instanceof PyLong){ BigInteger v = (BigInteger)value.__tojava__(BigInteger.class); if (v.compareTo(PyLong.maxULong) > 0){ - throw Py.OverflowError("unsigned long int too long to convert"); + throw StructError("unsigned long int too long to convert"); } return v; } else @@ -1041,4 +1043,10 @@ private static PyException StructError(String explanation) { return new PyException(error, explanation); } + + private static PyObject exceptionNamespace() { + PyObject dict = new PyStringMap(); + dict.__setitem__("__module__", new PyString("struct")); + return dict; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwierzbicki@us...> - 2008-07-26 01:27:27
|
Revision: 4999 http://jython.svn.sourceforge.net/jython/?rev=4999&view=rev Author: fwierzbicki Date: 2008-07-26 01:27:25 +0000 (Sat, 26 Jul 2008) Log Message: ----------- Re-enabled APIVersion checking in imp.java. Used ASM to read and write APIVersion as an annotation. Incremented APIVersion from 12 to 13. Modified Paths: -------------- branches/asm/src/org/python/compiler/APIVersion.java branches/asm/src/org/python/compiler/ClassFile.java branches/asm/src/org/python/compiler/Module.java branches/asm/src/org/python/core/imp.java Added Paths: ----------- branches/asm/src/org/python/core/APIReader.java Modified: branches/asm/src/org/python/compiler/APIVersion.java =================================================================== --- branches/asm/src/org/python/compiler/APIVersion.java 2008-07-25 06:07:24 UTC (rev 4998) +++ branches/asm/src/org/python/compiler/APIVersion.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -1,21 +1,13 @@ -// Copyright (c) Corporation for National Research Initiatives - +/* + * Copyright (c) 2008 Jython Developers + * Licensed to PSF under a Contributor Agreement. + */ package org.python.compiler; -import java.io.DataOutputStream; -import java.io.IOException; -public class APIVersion { - int attName; - int version; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; - public APIVersion(int version) throws IOException { - //FJW attName = pool.UTF8("org.python.APIVersion"); - //FJW this.version = version; - } - - public void write(DataOutputStream stream) throws IOException { - //FJW stream.writeShort(attName); - //FJW stream.writeInt(4); - //FJW stream.writeInt(version); - } +@Retention(RetentionPolicy.RUNTIME) +public @interface APIVersion { + int value(); } Modified: branches/asm/src/org/python/compiler/ClassFile.java =================================================================== --- branches/asm/src/org/python/compiler/ClassFile.java 2008-07-25 06:07:24 UTC (rev 4998) +++ branches/asm/src/org/python/compiler/ClassFile.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.List; +import org.python.objectweb.asm.AnnotationVisitor; import org.python.objectweb.asm.Attribute; import org.python.objectweb.asm.ClassWriter; import org.python.objectweb.asm.FieldVisitor; @@ -26,7 +27,6 @@ String[] interfaces; List<MethodVisitor> methodVisitors; List<FieldVisitor> fieldVisitors; - List<Attribute> attributes; public static String fixName(String n) { if (n.indexOf('.') == -1) @@ -53,7 +53,6 @@ methodVisitors = Collections.synchronizedList(new ArrayList()); fieldVisitors = Collections.synchronizedList(new ArrayList()); - attributes = Collections.synchronizedList(new ArrayList()); } public void setSource(String name) { @@ -67,7 +66,6 @@ interfaces = new_interfaces; } - //FIXME: Should really return a MethodVisitor public Code addMethod(String name, String type, int access) throws IOException { @@ -84,14 +82,6 @@ fieldVisitors.add(fv); } - public void endAttributes() - throws IOException - { - for (Attribute attr : attributes) { - cw.visitAttribute(attr); - } - } - public void endFields() throws IOException { @@ -110,17 +100,16 @@ } } - public void addAttribute(Attribute attr) throws IOException { - //FIXME: Do nothing for now. - //attributes.add(attr); - } - public void write(OutputStream stream) throws IOException { cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, this.name, null, this.superclass, interfaces); + AnnotationVisitor av = cw.visitAnnotation("Lorg/python/compiler/APIVersion;", true); + //XXX: should imp.java really house this value or should imp.java point into org.python.compiler? + av.visit("value", new Integer(org.python.core.imp.APIVersion)); + av.visitEnd(); + if (sfilename != null) { cw.visitSource(sfilename, null); } - endAttributes(); endFields(); endMethods(); Modified: branches/asm/src/org/python/compiler/Module.java =================================================================== --- branches/asm/src/org/python/compiler/Module.java 2008-07-25 06:07:24 UTC (rev 4998) +++ branches/asm/src/org/python/compiler/Module.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -574,8 +574,6 @@ if (sfilename != null) { classfile.setSource(sfilename); } - //FIXME: switch to asm style. - //classfile.addAttribute(new APIVersion(org.python.core.imp.APIVersion)); classfile.write(stream); } Added: branches/asm/src/org/python/core/APIReader.java =================================================================== --- branches/asm/src/org/python/core/APIReader.java (rev 0) +++ branches/asm/src/org/python/core/APIReader.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2008 Jython Developers + * Licensed to PSF under a Contributor Agreement. + */ +package org.python.core; + +import org.python.objectweb.asm.AnnotationVisitor; +import org.python.objectweb.asm.ClassReader; +import org.python.objectweb.asm.commons.EmptyVisitor; + +import java.io.InputStream; +import java.io.IOException; + +/** + * This class reads a classfile from a byte array and pulls out the value of + * the class annotation for APIVersion, which can then be retrieved by a call + * to getVersion(). + * + * Hopefully the use of ClassReader in this implementation is not too + * expensive. I suspect it is not since EmptyVisitor is just a bag of empty + * methods so shouldn't cost too much. If it turns out to cost too much, we + * will want to implement a special purpose ClassReader that only reads out the + * APIVersion annotation I think. + */ +public class APIReader extends EmptyVisitor { + + private boolean nextVisitIsVersion = false; + + private int version = -1; + + public APIReader(byte[] data) throws IOException { + ClassReader r = new ClassReader(data); + r.accept(this, 0); + } + + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + nextVisitIsVersion = desc.equals("Lorg/python/compiler/APIVersion;"); + return this; + } + + public void visit(String name, Object value) { + if (nextVisitIsVersion) { + version = (Integer)value; + nextVisitIsVersion = false; + } + } + + public int getVersion() { + return version; + } +} Modified: branches/asm/src/org/python/core/imp.java =================================================================== --- branches/asm/src/org/python/core/imp.java 2008-07-25 06:07:24 UTC (rev 4998) +++ branches/asm/src/org/python/core/imp.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -22,7 +22,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - public static final int APIVersion = 12; + public static final int APIVersion = 13; /** A non-empty fromlist for __import__'ing sub-modules. */ private static final PyObject nonEmptyFromlist = new PyTuple(Py.newString("__doc__")); @@ -113,11 +113,13 @@ byte[] data = readBytes(fp); int n = data.length; - //Need to find another way to check the api version -- probably using - //an Annotation instead of an Attribute makes sense. - /* - int api = (data[n - 4] << 24) + (data[n - 3] << 16) - + (data[n - 2] << 8) + data[n - 1]; + int api; + try { + APIReader ar = new APIReader(data); + api = ar.getVersion(); + } catch (IOException i) { + api = -1; + } if (api != APIVersion) { if (testing) { return null; @@ -126,7 +128,6 @@ + APIVersion + ") in: " + name); } } - */ return data; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pjenvey@us...> - 2008-07-28 06:40:14
|
Revision: 5008 http://jython.svn.sourceforge.net/jython/?rev=5008&view=rev Author: pjenvey Date: 2008-07-28 06:40:09 +0000 (Mon, 28 Jul 2008) Log Message: ----------- deriveds changes for __index__ Modified Paths: -------------- branches/asm/src/org/python/core/PyArrayDerived.java branches/asm/src/org/python/core/PyBaseExceptionDerived.java branches/asm/src/org/python/core/PyBooleanDerived.java branches/asm/src/org/python/core/PyClassMethodDerived.java branches/asm/src/org/python/core/PyComplexDerived.java branches/asm/src/org/python/core/PyDictionaryDerived.java branches/asm/src/org/python/core/PyEnumerateDerived.java branches/asm/src/org/python/core/PyFileDerived.java branches/asm/src/org/python/core/PyFloatDerived.java branches/asm/src/org/python/core/PyFrozenSetDerived.java branches/asm/src/org/python/core/PyIntegerDerived.java branches/asm/src/org/python/core/PyListDerived.java branches/asm/src/org/python/core/PyLongDerived.java branches/asm/src/org/python/core/PyModuleDerived.java branches/asm/src/org/python/core/PyObjectDerived.java branches/asm/src/org/python/core/PyPropertyDerived.java branches/asm/src/org/python/core/PySetDerived.java branches/asm/src/org/python/core/PySliceDerived.java branches/asm/src/org/python/core/PyStringDerived.java branches/asm/src/org/python/core/PySuperDerived.java branches/asm/src/org/python/core/PyTupleDerived.java branches/asm/src/org/python/core/PyTypeDerived.java branches/asm/src/org/python/core/PyUnicodeDerived.java branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java branches/asm/src/org/python/modules/collections/PyDequeDerived.java branches/asm/src/org/python/modules/random/PyRandomDerived.java branches/asm/src/org/python/modules/thread/PyLocalDerived.java branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java Modified: branches/asm/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyBaseExceptionDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBaseExceptionDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyBaseExceptionDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -830,6 +830,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom @@ -867,29 +881,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1029,6 +1057,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyFileDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFileDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyFileDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyListDerived.java =================================================================== --- branches/asm/src/org/python/core/PyListDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyListDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyLongDerived.java =================================================================== --- branches/asm/src/org/python/core/PyLongDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyLongDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -881,29 +881,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1043,6 +1057,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyObjectDerived.java =================================================================== --- branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyPropertyDerived.java =================================================================== --- branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PySetDerived.java =================================================================== --- branches/asm/src/org/python/core/PySetDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PySetDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PySliceDerived.java =================================================================== --- branches/asm/src/org/python/core/PySliceDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PySliceDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyStringDerived.java =================================================================== --- branches/asm/src/org/python/core/PyStringDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyStringDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PySuperDerived.java =================================================================== --- branches/asm/src/org/python/core/PySuperDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PySuperDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyTupleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTupleDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyTupleDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyTypeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTypeDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyTypeDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -881,29 +881,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1043,6 +1057,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyUnicodeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java =================================================================== --- branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -907,29 +907,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1069,6 +1083,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -907,29 +907,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1069,6 +1083,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/modules/collections/PyDequeDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -907,29 +907,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1069,6 +1083,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/modules/random/PyRandomDerived.java =================================================================== --- branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -907,29 +907,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1069,6 +1083,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/modules/thread/PyLocalDerived.java =================================================================== --- branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -883,29 +883,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1045,6 +1059,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -883,29 +883,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1045,6 +1059,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwierzbicki@us...> - 2008-07-29 01:40:34
|
Revision: 5017 http://jython.svn.sourceforge.net/jython/?rev=5017&view=rev Author: fwierzbicki Date: 2008-07-29 01:40:32 +0000 (Tue, 29 Jul 2008) Log Message: ----------- IParserHost is no longer used. Modified Paths: -------------- branches/asm/src/org/python/core/ParserFacade.java Removed Paths: ------------- branches/asm/src/org/python/antlr/IParserHost.java Deleted: branches/asm/src/org/python/antlr/IParserHost.java =================================================================== --- branches/asm/src/org/python/antlr/IParserHost.java 2008-07-28 23:13:21 UTC (rev 5016) +++ branches/asm/src/org/python/antlr/IParserHost.java 2008-07-29 01:40:32 UTC (rev 5017) @@ -1,23 +0,0 @@ -package org.python.antlr; - -/** - * - * literal creation callbacks from the parser to the its host - * - **/ - -public interface IParserHost { - - public Object newLong(String s); - - public Object newLong(java.math.BigInteger i); - - public Object newFloat(double v); - - public Object newImaginary(double v); - - public Object newInteger(int i); - - public String decode_UnicodeEscape(String str, int start, int end, - String errors, boolean unicode); -} Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-07-28 23:13:21 UTC (rev 5016) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-07-29 01:40:32 UTC (rev 5017) @@ -24,7 +24,6 @@ import org.python.antlr.PythonParser; import org.python.antlr.PythonTree; import org.python.core.util.StringUtil; -import org.python.antlr.IParserHost; import org.python.antlr.PythonTree; import org.python.antlr.PythonPartialLexer; import org.python.antlr.PythonPartialParser; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zyasoft@us...> - 2008-07-30 15:46:36
|
Revision: 5022 http://jython.svn.sourceforge.net/jython/?rev=5022&view=rev Author: zyasoft Date: 2008-07-30 15:46:31 +0000 (Wed, 30 Jul 2008) Log Message: ----------- Support inf, -inf, nan literals (and any uppercasing). struct.pack("d") ducktypes like CPython and calls __float__. This fixes a number of issues for PyAMF. Modified Paths: -------------- branches/asm/src/org/python/core/PyFloat.java branches/asm/src/org/python/core/PyString.java branches/asm/src/org/python/modules/struct.java Modified: branches/asm/src/org/python/core/PyFloat.java =================================================================== --- branches/asm/src/org/python/core/PyFloat.java 2008-07-29 22:40:05 UTC (rev 5021) +++ branches/asm/src/org/python/core/PyFloat.java 2008-07-30 15:46:31 UTC (rev 5022) @@ -105,6 +105,10 @@ } private String formatDouble(int precision) { + if (Double.isNaN(value)) { + return "nan"; + } + String result = String.format("%%.%dg", precision); result = Py.newString(result).__mod__(this).toString(); Modified: branches/asm/src/org/python/core/PyString.java =================================================================== --- branches/asm/src/org/python/core/PyString.java 2008-07-29 22:40:05 UTC (rev 5021) +++ branches/asm/src/org/python/core/PyString.java 2008-07-30 15:46:31 UTC (rev 5022) @@ -1510,6 +1510,10 @@ try { // Double.valueOf allows format specifier ("d" or "f") at the end String lowSval = sval.toLowerCase(); + if (lowSval.equals("nan")) return Double.NaN; + else if (lowSval.equals("inf")) return Double.POSITIVE_INFINITY; + else if (lowSval.equals("-inf")) return Double.NEGATIVE_INFINITY; + if (lowSval.endsWith("d") || lowSval.endsWith("f")) { throw new NumberFormatException("format specifiers not allowed"); } Modified: branches/asm/src/org/python/modules/struct.java =================================================================== --- branches/asm/src/org/python/modules/struct.java 2008-07-29 22:40:05 UTC (rev 5021) +++ branches/asm/src/org/python/modules/struct.java 2008-07-30 15:46:31 UTC (rev 5022) @@ -351,8 +351,6 @@ } double get_float(PyObject value) { - if (!(value instanceof PyFloat)) - throw StructError("required argument is not an float"); return value.__float__().getValue(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nriley@us...> - 2008-08-01 23:02:50
|
Revision: 5050 http://jython.svn.sourceforge.net/jython/?rev=5050&view=rev Author: nriley Date: 2008-08-01 23:02:47 +0000 (Fri, 01 Aug 2008) Log Message: ----------- JYTHONPATH support. Modified Paths: -------------- branches/asm/src/org/python/core/PySystemState.java branches/asm/src/org/python/util/jython.java Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-08-01 22:38:32 UTC (rev 5049) +++ branches/asm/src/org/python/core/PySystemState.java 2008-08-01 23:02:47 UTC (rev 5050) @@ -440,13 +440,14 @@ } catch (Exception exc) { } } + try { + String jythonpath = System.getenv("JYTHONPATH"); + if (jythonpath != null) + registry.setProperty("python.path", jythonpath); + } catch (SecurityException e) { + } if (postProperties != null) { - for (Enumeration e=postProperties.keys(); e.hasMoreElements();) - { - String key = (String)e.nextElement(); - String value = (String)postProperties.get(key); - registry.put(key, value); - } + registry.putAll(postProperties); } if (standalone) { // set default standalone property (if not yet set) Modified: branches/asm/src/org/python/util/jython.java =================================================================== --- branches/asm/src/org/python/util/jython.java 2008-08-01 22:38:32 UTC (rev 5049) +++ branches/asm/src/org/python/util/jython.java 2008-08-01 23:02:47 UTC (rev 5050) @@ -54,7 +54,10 @@ //"-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n" + "file : program read from script file\n" + "- : program read from stdin (default; interactive mode if a tty)\n" + - "arg ... : arguments passed to program in sys.argv[1:]"; + "arg ... : arguments passed to program in sys.argv[1:]\n" + + "Other environment variables:\n" + + "JYTHONPATH: '" + java.io.File.pathSeparator + "'-separated list of directories prefixed to the default module\n" + + " search path. The result is sys.path."; public static void runJar(String filename) { // TBD: this is kind of gross because a local called `zipfile' just This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwierzbicki@us...> - 2008-08-04 17:57:43
|
Revision: 5077 http://jython.svn.sourceforge.net/jython/?rev=5077&view=rev Author: fwierzbicki Date: 2008-08-04 17:57:34 +0000 (Mon, 04 Aug 2008) Log Message: ----------- In test_decorators.py, test_eval_order cleverly instruments a decorated call so the order of evaluation and calls can be determined. It also checks to see if the decoration works exactly the same when translated to nested function calls. Jython was evaluating the arguments before the function name, the opposite of CPython. This patch makes the order correct for both decorators and normal function calls. Also, PyObject.invoke states in its comments that it is for use from Java and shows the equivalent o.__getattr__(name).__call__(args, keywords) which is how I am constructing a call in the bytecode. I also thought that "Invoke" with a capitalized name was non-ideal, so I changed the name to invokeNoKeywords, which also allowed me to remove a comment that conveyed the same meaning. Modified Paths: -------------- branches/asm/src/org/python/compiler/CodeCompiler.java branches/asm/src/org/python/core/imp.java Modified: branches/asm/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-04 03:23:57 UTC (rev 5076) +++ branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-04 17:57:34 UTC (rev 5077) @@ -1385,29 +1385,30 @@ c.freeLocal(strings); } - public Object Invoke(Attribute node, PythonTree[] values) + public Object invokeNoKeywords(Attribute node, PythonTree[] values) throws Exception { String name = getName(node.attr); visit(node.value); code.ldc(name); + code.invokevirtual("org/python/core/PyObject", "__getattr__", "(" + $str + ")" + $pyObj); switch (values.length) { case 0: - code.invokevirtual("org/python/core/PyObject", "invoke", "(" + $str + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__call__", "()" + $pyObj); break; case 1: visit(values[0]); - code.invokevirtual("org/python/core/PyObject", "invoke", "(" + $str + $pyObj + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); break; case 2: visit(values[0]); visit(values[1]); - code.invokevirtual("org/python/core/PyObject", "invoke", "(" + $str + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + ")" + $pyObj); break; default: makeArray(values); - code.invokevirtual("org/python/core/PyObject", "invoke", "(" + $str + $pyObjArr + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObjArr + ")" + $pyObj); break; } return null; @@ -1425,11 +1426,10 @@ values[node.args.length + i] = node.keywords[i].value; } - // Detect a method invocation with no keywords if ((node.keywords == null || node.keywords.length == 0)&& node.starargs == null && node.kwargs == null && node.func instanceof Attribute) { - return Invoke((Attribute) node.func, values); + return invokeNoKeywords((Attribute) node.func, values); } visit(node.func); Modified: branches/asm/src/org/python/core/imp.java =================================================================== --- branches/asm/src/org/python/core/imp.java 2008-08-04 03:23:57 UTC (rev 5076) +++ branches/asm/src/org/python/core/imp.java 2008-08-04 17:57:34 UTC (rev 5077) @@ -22,7 +22,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - public static final int APIVersion = 14; + public static final int APIVersion = 15; /** A non-empty fromlist for __import__'ing sub-modules. */ private static final PyObject nonEmptyFromlist = new PyTuple(Py.newString("__doc__")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zyasoft@us...> - 2008-08-08 15:37:54
|
Revision: 5105 http://jython.svn.sourceforge.net/jython/?rev=5105&view=rev Author: zyasoft Date: 2008-08-08 15:37:43 +0000 (Fri, 08 Aug 2008) Log Message: ----------- With statements now keep their own stack of exit functions in PyFrame so that they don't get stepped on by generators save/restore of local temporary registers. Fixes most problems in test_with, including JVM verification errors. (Remaining issues seem to be with generator exit issues, to be resolved separately.) Modified Paths: -------------- branches/asm/src/org/python/compiler/CodeCompiler.java branches/asm/src/org/python/compiler/ScopeInfo.java branches/asm/src/org/python/compiler/ScopesCompiler.java branches/asm/src/org/python/core/PyFrame.java Modified: branches/asm/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-07 21:18:44 UTC (rev 5104) +++ branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-08 15:37:43 UTC (rev 5105) @@ -137,6 +137,7 @@ public int bcfLevel = 0; int yield_count = 0; + int with_count = 0; public CodeCompiler(Module module, boolean print_results) { this.module = module; @@ -261,6 +262,15 @@ tbl = scope.tbl; optimizeGlobals = fast_locals&&!scope.exec&&!scope.from_import_star; + + if (scope.max_with_count > 0) { + // allocate for all the with-exits we will have in the frame; + // this allows yield and with to happily co-exist + loadFrame(); + code.iconst(scope.max_with_count); + code.anewarray("org/python/core/PyObject"); + code.putfield("org/python/core/PyFrame", "f_exits", $pyObjArr); + } Object exit = visit(node); @@ -2005,70 +2015,77 @@ if (!module.getFutures().withStatementSupported()) { throw new ParseException("'with' will become a reserved keyword in Python 2.6", node); } - - int mgr_tmp = code.getLocal("org/python/core/PyObject"); - int exit_tmp = code.getLocal("org/python/core/PyObject"); - int value_tmp = code.getLocal("org/python/core/PyObject"); - int exc_tmp = code.getLocal("java/lang/Throwable"); - + + int my_with_count = with_count; + with_count++; + Label label_body_start = new Label(); Label label_body_end = new Label(); Label label_catch = new Label(); Label label_finally = new Label(); Label label_end = new Label(); - + Method getattr = Method.getMethod("org.python.core.PyObject __getattr__ (String)"); Method call = Method.getMethod("org.python.core.PyObject __call__ ()"); Method call3 = Method.getMethod("org.python.core.PyObject __call__ (org.python.core.PyObject,org.python.core.PyObject,org.python.core.PyObject)"); - - setline(node); - + // mgr = (EXPR) visit(node.context_expr); + int mgr_tmp = code.getLocal("org/python/core/PyObject"); code.astore(mgr_tmp); - - // exit = mgr.__exit__ # Not calling it yet + + // exit = mgr.__exit__ # Not calling it yet, so storing in the frame + loadFrame(); + code.getfield("org/python/core/PyFrame", "f_exits", $pyObjArr); + code.iconst(my_with_count); code.aload(mgr_tmp); code.ldc("__exit__"); code.invokevirtual(Type.getType(PyObject.class).getInternalName(), getattr.getName(), getattr.getDescriptor()); - code.astore(exit_tmp); + code.aastore(); // value = mgr.__enter__() code.aload(mgr_tmp); + code.freeLocal(mgr_tmp); code.ldc("__enter__"); code.invokevirtual(Type.getType(PyObject.class).getInternalName(), getattr.getName(), getattr.getDescriptor()); code.invokevirtual(Type.getType(PyObject.class).getInternalName(), call.getName(), call.getDescriptor()); + int value_tmp = code.getLocal("org/python/core/PyObject"); code.astore(value_tmp); // exc = True # not necessary, since we don't exec finally if exception // try-catch block here code.trycatch(label_body_start, label_body_end, label_catch, "java/lang/Throwable"); - + // VAR = value # Only if "as VAR" is present code.label(label_body_start); if (node.optional_vars != null) { - set(node.optional_vars, value_tmp); + set(node.optional_vars, value_tmp); } + code.freeLocal(value_tmp); + // BLOCK suite(node.body); code.goto_(label_finally); code.label(label_body_end); - + // CATCH code.label(label_catch); - code.astore(exc_tmp); - - code.aload(exc_tmp); + loadFrame(); code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); - code.astore(exc_tmp); - - code.invokestatic("org/python/core/Py", "getThreadState", "()Lorg/python/core/ThreadState;"); + code.pop(); + + code.invokestatic("org/python/core/Py", "getThreadState", "()Lorg/python/core/ThreadState;"); code.getfield("org/python/core/ThreadState", "exception", $pyExc); int ts_tmp = storeTop(); + // # The exceptional case is handled here + // exc = False # implicit // if not exit(*sys.exc_info()): - code.aload(exit_tmp); + loadFrame(); + code.getfield("org/python/core/PyFrame", "f_exits", $pyObjArr); + code.iconst(my_with_count); + code.aaload(); code.aload(ts_tmp); code.getfield("org/python/core/PyException", "type", $pyObj); code.aload(ts_tmp); @@ -2079,10 +2096,13 @@ code.invokevirtual(Type.getType(PyObject.class).getInternalName(), call3.getName(), call3.getDescriptor()); code.invokevirtual("org/python/core/PyObject", "__nonzero__", "()Z"); code.ifne(label_end); - // raise + // 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.athrow(); + + code.freeLocal(ts_tmp); // FINALLY // ordinarily with a finally, we need to duplicate the code. that's not the case here @@ -2091,24 +2111,20 @@ // exit(None, None, None) code.label(label_finally); + + loadFrame(); + code.getfield("org/python/core/PyFrame", "f_exits", $pyObjArr); + code.iconst(my_with_count); + code.aaload(); getNone(); - int none_tmp = storeTop(); - - code.aload(exit_tmp); - code.aload(none_tmp); - code.aload(none_tmp); - code.aload(none_tmp); + code.dup(); + code.dup(); code.invokevirtual(Type.getType(PyObject.class).getInternalName(), call3.getName(), call3.getDescriptor()); code.pop(); code.label(label_end); + with_count--; - code.freeLocal(ts_tmp); - code.freeLocal(exc_tmp); - code.freeLocal(value_tmp); - code.freeLocal(exit_tmp); - code.freeLocal(mgr_tmp); - return null; } Modified: branches/asm/src/org/python/compiler/ScopeInfo.java =================================================================== --- branches/asm/src/org/python/compiler/ScopeInfo.java 2008-08-07 21:18:44 UTC (rev 5104) +++ branches/asm/src/org/python/compiler/ScopeInfo.java 2008-08-08 15:37:43 UTC (rev 5105) @@ -54,6 +54,7 @@ public boolean from_import_star; public boolean generator; public int yield_count; + public int max_with_count; public ArgListCompiler ac; Modified: branches/asm/src/org/python/compiler/ScopesCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/ScopesCompiler.java 2008-08-07 21:18:44 UTC (rev 5104) +++ branches/asm/src/org/python/compiler/ScopesCompiler.java 2008-08-08 15:37:43 UTC (rev 5105) @@ -269,4 +269,11 @@ return null; } + public Object visitWith(With node) throws Exception { + cur.max_with_count++; + traverse(node); + + return null; + } + } Modified: branches/asm/src/org/python/core/PyFrame.java =================================================================== --- branches/asm/src/org/python/core/PyFrame.java 2008-08-07 21:18:44 UTC (rev 5104) +++ branches/asm/src/org/python/core/PyFrame.java 2008-08-08 15:37:43 UTC (rev 5105) @@ -41,6 +41,9 @@ 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(). */ public TraceFunction tracefunc; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |