Contribute Media
A thank you to everyone who has made this possible: Read More

Exploring our Python Interpreter

Translations: en

Description

Stephane Wirtel - Exploring our Python Interpreter [EuroPython 2016] [19 July 2016] [Bilbao, Euskadi, Spain] (https://ep2016.europython.eu//conference/talks/exploring-our-python-interpreter)

During the last CPython sprints at PyCon US (Montreal), I started to contribute to the CPython project 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. The idea behind is just to show how CPython works for a new contributor.


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.

Improve this page