Any pointers/advice to help learn CPython source?

S

seberino

Anyone have any good advice to someone interested in learning about
innards of Python implementation?

e.g. What is best place to start?

Where can I get a 10,000 ft. overview of general structure?

Anyone written docs on helping do this?

How did other people successfully make it through?

Chris
 
N

nnorwitz

Anyone have any good advice to someone interested in learning about
innards of Python implementation?

e.g. What is best place to start?

Where can I get a 10,000 ft. overview of general structure?

Anyone written docs on helping do this?

How did other people successfully make it through?

Depends on what you want to get out of it. There are only a handful of
top level directories that are interesting:

Include - include files
Objects - all Python objects (list, dict, int, float, functions, and
many others)
Python - core interpreter and other support facilities

Lib - Python stdlib (Lib/test is the test suite)
Modules - C extension modules
Parser - simple parser/tokenizer

The last three probably aren't interesting. However, if you are
interested in the GC (or SRE) implementation, then you should look
under Modules as gcmodule.c and _sre.c are there. So are a bunch of
others.

Include/ isn't particularly interesting. Objects/ isn't too
interesting either from the standpoint of learning about the
interpreter. Although the object implementations may be interesting in
their own right. Each object is in an unsurprising file named
something like: listobject.c or intobject.c.

That leaves Python/ which is where the real innards are. If you are
interested in the interpreter, then Python/ceval.c is pretty much it.
The compiler is primarly in Python/compile.c, but also see Python/ast.c
(2.5 only) and Python/symtable.c. All the global builtin functions are
in Python/bltinmodule.c. Import support is in Python/import.c. Most
of the other files in Python/ are small and/or platform specific. They
probably aren't as interesting in general.

n
 
S

seberino

Wow thanks for your detailed reply. Mainly I just wanted to understand
the theory and ideas needed to make an interpreter. Your directory
description helped.

Chris
 
?

=?iso-8859-1?B?c+liYXN0aWVu?=

There is also an interesting pep which describe the front-end

http://www.python.org/dev/peps/pep-0339/

It doesn't explain the whole things, but it gives few hints where to
start to read the code. BTW, the main difficulty is that there are fat
C files and you should ask yourself what do you want to learn, because
instead it can be interesting to read the compiler module or to look at
pypy source code. Obviously if your motivations are to understand some
internals of CPython you want to study CPython ! lol
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,187
Latest member
RosaDemko

Latest Threads

Top