Any pointers/advice to help learn CPython source?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • seberino@spawar.navy.mil

    #1

    Any pointers/advice to help learn CPython source?

    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

  • nnorwitz@gmail.com

    #2
    Re: Any pointers/advice to help learn CPython source?

    seberino@spawar .navy.mil wrote:[color=blue]
    > 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?[/color]

    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

    Comment

    • seberino@spawar.navy.mil

      #3
      Re: Any pointers/advice to help learn CPython source?

      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

      Comment

      • sébastien

        #4
        Re: Any pointers/advice to help learn CPython source?

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

        Historically (through 2.4), compilation from source code to bytecode involved two steps:


        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

        --
        sébastien


        Comment

        Working...