EuroPython 2016

Exploring our Python Interpreter

Speaker(s) Stephane Wirtel

During my last CPython sprint, I started to contribute to the CPython code and I wanted to understand the beast.

In this case, there is only one solution, trace the code from the beginning. From the command line to the interpreter, we will take part to an adventure

  • Overview of the structure of the project and the directories.
  • From the Py_Main function to the interpreter.
  • The used technics for the Lexer, Parser and the generation of the AST and of course of the Bytecodes.
  • We will see some bytecodes with the dis module.
  • How does VM works, it’s a stack machine.
  • The interpreter and its main loop of the Virtual Machine.

The idea behind is just to show how CPython works for a new contributor to CPython.

From the command line, we will learn that Python is a library and that we can embed it in a C project. In fact we will see the Py_Main function to the ceval.c file of the interpreter.

But there is no magic in the CPython code, we will travel in the lexer and the parser of CPython, and why not, by the AST for one Python expression.

After the AST, we will visit the Compiler and the Bytecodes for the interpreter. Of course, we will learn there is the peepholer where some basic instructions are optimised by the this component.

And of course, the interpreter, this virtual machine is really interesting for the newbiew, because it’s a big stack where the bytecodes are executed one by one on the stack and the ceval.c file.

in on Tuesday 19 July at 15:45 See schedule

Do you have some questions on this talk?

New comment