[Python-Dev] Is there a reference manual for Python bytecode?
Hi. Looking at ceval.c and peephole.c, there is - of course - lots of specific hard-coded knowledge of the bytecode (e.g., number of operands and other attributes). I'd like to experiment at this level, but I can't seem to find a reference for the bytecode. Is there the equivalent of something like the ARM ARM(*) for Python bytecode? I can read Python or C code if it's encoded that way, but I'm looking for something that's a bit more immediate than deciphering what an interpreter or optimizer is trying to do (i.e., some sort of table layout or per-opcode set of attributes). BR, E. (*) http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Is there a reference manual for Python bytecode?
The number and meaning of the arguments are documented in the dis module: https://docs.python.org/3.6/library/dis.html On Sat, Dec 26, 2015 at 5:20 PM, Erik wrote: > Hi. > > Looking at ceval.c and peephole.c, there is - of course - lots of specific > hard-coded knowledge of the bytecode (e.g., number of operands and other > attributes). I'd like to experiment at this level, but I can't seem to find > a reference for the bytecode. > > Is there the equivalent of something like the ARM ARM(*) for Python > bytecode? I can read Python or C code if it's encoded that way, but I'm > looking for something that's a bit more immediate than deciphering what an > interpreter or optimizer is trying to do (i.e., some sort of table layout > or per-opcode set of attributes). > > BR, > E. > > (*) > http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html > ___ > Python-Dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/joe%40quantopian.com > ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Is there a reference manual for Python bytecode?
Also there's a great talk by Allison Kaptur on YouTube about this topic: https://www.youtube.com/watch?v=HVUTjQzESeo -- --Guido van Rossum (python.org/~guido) ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Is there a reference manual for Python bytecode?
Hi Joe, On 26/12/15 22:36, Joe Jevnik wrote: The number and meaning of the arguments are documented in the dis module: https://docs.python.org/3.6/library/dis.html OK - I *did* find that, but perhaps didn't immediately understand what it was telling me. So, something documented as "OP_CODE" is a 1-byte op, something documented as "OP_CODE(foo)" is a 2-byte op - and unless I missed one, there are no 3-byte ops? Thanks, E. ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Thanks for your hard work and my New Years resolutions
+1 Thanks to everyone who has contributed to Python! And thanks everyone for being such an awesome community. Oh, and thanks to Brett for taking on those unpopular jobs. --Guido On Fri, Dec 25, 2015 at 10:46 AM, Brett Cannon wrote: > I just wanted to quickly thank everyone for the work they put into this > project. I realize most of us either get only a little bit of paid time to > work on Python or none at all, so contributing easily ends up using > personal time which I know is a precious thing. So thank you for caring > enough about this project to put in your valuable time and effort while > trying to keep it enjoyable for everyone else. > > As we go into 2016, I hope to do my part to indirectly thank everyone by > making our developer workflow easier to work with so that not only the > lives of the core developers become easier but we once again become a > project that is viewed as welcoming to outside contribution (instead of our > current reputation as having patches sit in the issue tracker, languishing; > join core-workflow if you want to help out with that). I also hope to see > zipimport rewritten -- either by someone else or me if necessary -- so that > my importlib.resources idea can land in time for Python 3.6 (join the > import-sig if that interests you). Otherwise I plan to keep promoting > Python 3 as we get ever closer to 2020. :) > > ___ > Python-Dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/guido%40python.org > > -- --Guido van Rossum (python.org/~guido) ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Is there a reference manual for Python bytecode?
On 26/12/15 23:10, Joe Jevnik wrote: All arguments are 2 bytes, if there needs to be more, EXTENDED_ARG is used OK, got it - many thanks. E. ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Is there a reference manual for Python bytecode?
On 12/26/15 6:13 PM, Erik wrote: On 26/12/15 23:10, Joe Jevnik wrote: All arguments are 2 bytes, if there needs to be more, EXTENDED_ARG is used OK, got it - many thanks. One thing to understand that may not be immediately apparent: the byte code can (and does) change between versions, so Python 2.7 doesn't have the exact same byte code as 3.4, which is also different from 3.5. --Ned. E. ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ned%40nedbatchelder.com ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Is there a reference manual for Python bytecode?
Ned also neglected to mention his byterun project which is a pure Python implementation of the CPython eval loop: https://github.com/nedbat/byterun On Sat, 26 Dec 2015, 16:38 Ned Batchelder wrote: > On 12/26/15 6:13 PM, Erik wrote: > > On 26/12/15 23:10, Joe Jevnik wrote: > >> All arguments are 2 bytes, if there needs to be more, EXTENDED_ARG is > >> used > > > > OK, got it - many thanks. > One thing to understand that may not be immediately apparent: the byte > code can (and does) change between versions, so Python 2.7 doesn't have > the exact same byte code as 3.4, which is also different from 3.5. > > --Ned. > > > > E. > > ___ > > Python-Dev mailing list > > [email protected] > > https://mail.python.org/mailman/listinfo/python-dev > > Unsubscribe: > > > https://mail.python.org/mailman/options/python-dev/ned%40nedbatchelder.com > > ___ > Python-Dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/brett%40python.org > ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Is there a reference manual for Python bytecode?
All arguments are 2 bytes, if there needs to be more, EXTENDED_ARG is used On Sat, Dec 26, 2015 at 5:51 PM, Erik wrote: > Hi Joe, > > On 26/12/15 22:36, Joe Jevnik wrote: > >> The number and meaning of the arguments are documented in the dis >> module: https://docs.python.org/3.6/library/dis.html >> > > OK - I *did* find that, but perhaps didn't immediately understand what it > was telling me. > > So, something documented as "OP_CODE" is a 1-byte op, something documented > as "OP_CODE(foo)" is a 2-byte op - and unless I missed one, there are no > 3-byte ops? > > Thanks, > E. > ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Is there a reference manual for Python bytecode?
On Sat, Dec 26, 2015 at 6:06 PM, Brett Cannon wrote: > Ned also neglected to mention his byterun project which is a pure Python > implementation of the CPython eval loop: https://github.com/nedbat/byterun > >From the commit log it looks like it's a co-production between Ned and Allison Kaptur (who gave the talk I mentioned). -- --Guido van Rossum (python.org/~guido) ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Is there a reference manual for Python bytecode?
On 27 December 2015 at 12:23, Guido van Rossum wrote: > On Sat, Dec 26, 2015 at 6:06 PM, Brett Cannon wrote: >> >> Ned also neglected to mention his byterun project which is a pure Python >> implementation of the CPython eval loop: https://github.com/nedbat/byterun > > From the commit log it looks like it's a co-production between Ned and > Allison Kaptur (who gave the talk I mentioned). It occurred to me that "byterun" would make a good see-also link from the dis module docs, and looking into that idea brought me to this article Allison wrote about it for the "500 lines" project: http://aosabook.org/en/500L/a-python-interpreter-written-in-python.html For a detailed semantic reference, byterun's eval loop is likely one of the most readable sources of information: https://github.com/nedbat/byterun/blob/master/byterun/pyvm2.py In terms of formal documentation, the main problem with providing reference bytecode tables is keeping them up to date as the eval loop changes. However, it would theoretically be possible to create a custom Sphinx directive that uses the dis module to generate the tables automatically during the docs build process, rather than maintaining them by hand - something like that could be experimented with outside CPython, and potentially incorporated into the dis module docs if folks are able to figure out something that works well. Regards, Nick. -- Nick Coghlan | [email protected] | Brisbane, Australia ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
