Update of /cvsroot/jython/jython/Misc
In directory usw-pr-cvs1:/tmp/cvs-serv10032
Modified Files:
make_binops.py
Log Message:
Support for the reworked Coercion Model (pep-0208).
Index: make_binops.py
===================================================================
RCS file: /cvsroot/jython/jython/Misc/make_binops.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** make_binops.py 2000/10/08 13:45:48 1.2
--- make_binops.py 2001/01/31 13:16:37 1.3
***************
*** 41,83 ****
* with these operands.
**/
! public final PyObject _%(name)s(PyObject o2_in) {
! PyObject o2 = o2_in;
! PyObject o1 = this;
! Object ctmp;
! if (o1.__class__ != o2.__class__) {
! ctmp = o1.__coerce_ex__(o2);
! if (ctmp != null) {
! if (ctmp instanceof PyObject[]) {
! o1 = ((PyObject[])ctmp)[0];
! o2 = ((PyObject[])ctmp)[1];
! } else {
! o2 = (PyObject)ctmp;
! }
! }
! } else ctmp = null;
!
! if (ctmp != Py.None && (o1 = o1.__%(name)s__(o2)) != null)
! return o1;
! o1 = this;
! o2 = o2_in;
! if (o1.__class__ != o2.__class__) {
! ctmp=o2.__coerce_ex__(o1);
! if (ctmp != null) {
! if (ctmp instanceof PyObject[]) {
! o2 = ((PyObject[])ctmp)[0];
! o1 = ((PyObject[])ctmp)[1];
! } else {
! o1 = (PyObject)ctmp;
! }
! }
! }
! if (ctmp != Py.None) {
! if (o1.__class__ == o2.__class__)
! o1 = o1.__%(name)s__(o2);
! else
! o1 = o2.__r%(name)s__(o1);
! if (o1 != null)
! return o1;
! }
throw Py.TypeError(
"__%(name)s__ nor __r%(name)s__ defined for these operands");
--- 41,51 ----
* with these operands.
**/
! public final PyObject _%(name)s(PyObject o2) {
! PyObject x = __%(name)s__(o2);
! if (x != null)
! return x;
! x = o2.__r%(name)s__(this);
! if (x != null)
! return x;
throw Py.TypeError(
"__%(name)s__ nor __r%(name)s__ defined for these operands");
***************
*** 149,157 ****
template = comment + """\
public PyObject __%(name)s__(PyObject o) {
! return invoke_ex("__%(name)s__", o);
}
"""
template2 = comment + """\
public PyObject __%(name)s__(PyObject o) {
--- 117,136 ----
template = comment + """\
public PyObject __%(name)s__(PyObject o) {
! Object ctmp = __coerce_ex__(o);
! if (ctmp == null || ctmp == Py.None)
! return invoke_ex("__%(name)s__", o);
! else {
! PyObject o1 = ((PyObject[])ctmp)[0];
! PyObject o2 = ((PyObject[])ctmp)[1];
! if (this == o1) // Prevent recusion if __coerce__ return self
! return invoke_ex("__%(name)s__", o2);
! else
! return %(function)s;
! }
}
"""
+
template2 = comment + """\
public PyObject __%(name)s__(PyObject o) {
***************
*** 166,171 ****
fp.write(' // Binary ops\n\n')
for name, op in binops:
! fp.write(template % {'name':name})
! fp.write(template % {'name':'r'+name})
if name != 'divmod':
fp.write(template2 % {'name':'i'+name
--- 145,150 ----
fp.write(' // Binary ops\n\n')
for name, op in binops:
! fp.write(template % {'name':name, 'function':'o1._%s(o2)' % name })
! fp.write(template % {'name':'r'+name, 'function':'o2._%s(o1)' % name })
if name != 'divmod':
fp.write(template2 % {'name':'i'+name
|