Re: Eliminating Special Method Lookup

Jim Baker <[email protected]>
Newsgroups gmane.comp.lang.jython.devel
Message-ID <CAOhO=aMrd5XpTnvuv9XpbaV6bX7pWCq9s8DR3qz8VEC9pXkhbw@mail.gmail.com>
Laura,

Binary operations like + are compiled to Java bytecode to use
PyObject::_add; this in turn dispatches through PyObject::_basic_add, which
in turns goes through, for classes that derive from object,
PyObjectDerived::#__add__ with a boilerplate implementation like so:

    public PyObject __add__(PyObject other) {
        PyType self_type=getType();
        PyObject impl=self_type.lookup("__add__");
        if (impl!=null) {
            PyObject res=impl.__get__(this,self_type).__call__(other);
            if (res==Py.NotImplemented)
                return null;
            return res;
        }
        return super.__add__(other);
    }

This means that the lookup is only against the type, not against the
object's __dict__. So we follow the same data model for special methods
that CPython uses.

This process should inline well for the more common case of adding ints and
floats, which was the conclusion of the analysis that Cliff Click performed
a few years ago at the JVM Language Summit (as part of a study of Jython
and other alternative JVM languages).

- Jim

On Mon, Dec 7, 2015 at 12:57 PM, Laura Creighton <[email protected]> wrote:

>
> see this thread (if you are not reading it already)
> https://mail.python.org/pipermail/python-ideas/2015-December/037354.html
>
> I do not know whether current Jythons work as
> old Jythons were described to -- and I am am too lazy to write code
> to check.  But I figure that before we get a BDFL pronouncement
> prohibiting something that Jython does all the time for a reason,
> people around here needed to know that the axe was about to fall,
> so they could speak up and say, hmm, that's not a great idea.
>
> Laura
>
>
>
> ------------------------------------------------------------------------------
> Go from Idea to Many App Stores Faster with Intel(R) XDK
> Give your users amazing mobile app experiences with Intel(R) XDK.
> Use one codebase in this all-in-one HTML5 development environment.
> Design, debug & build mobile apps & 2D/3D high-impact games for multiple
> OSs.
> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
> _______________________________________________
> Jython-dev mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jython-dev
>

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140

_______________________________________________
Jython-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.