Guide to the python interp. source?
Neil Schemenauer
nas at python.ca
Fri Jul 26 13:58:55 EDT 2002
Tim Gahnström /Bladerman wrote:
> Is there a guide or a recomended way to "get to know" the source code to the
> python interpreter?
Not that I know of. Here are a few pointers:
* Python/ceval.c:eval_frame is the heart of the virtual machine. This
is were most of the work is done. Use the 'dis' module to
disassemble bytecode to get an idea of how the VM works. For
example:
>>> def foo():
... return 10 + 20
...
>>> import dis
>>> dis.dis(foo)
0 SET_LINENO 1
3 SET_LINENO 2
6 LOAD_CONST 1 (10)
9 LOAD_CONST 2 (20)
12 BINARY_ADD
13 RETURN_VALUE
14 LOAD_CONST 0 (None)
17 RETURN_VALUE
* The data structures in Include/object.h are key. You should
study PyObject, PyVarObject and PyTypeObject.
* Most builtin objects live in the 'Objects' directory. There is
usually one file for each object. Some objects have header
information in 'Include'.
* The parser lives in 'Parser' and the compiler is in 'Python'. I
would recommend studying the compiler written in Python (in
Lib/compiler) rather than the one written in C.
HTH,
Neil
More information about the Python-list
mailing list