A Python program developer, is also a C language enthusiast, in order to strengthen their understanding of the Python language implementation, recently chose to read under the Chen Ru Teacher's book, read the Python3.5.1 source code, and then record the reading notes.
First, the overall structure of Python
PYthon is generally divided into three parts: File system (Files Groups), interpreter (interpreter), Runtime Environment (Runtim environement):
The file system is used to store Python script files (. py), mainly divided into built-in modules, third-party modules, user-defined modules;
The interpreter is used to scan, parse, compile and run the Python script file, mainly divided into scanner, Parser, Complier, exauator four parts;
1, Scanner
Used for lexical parsing of Python scripts, splitting the script into tokens
2, Parser
Syntax parsing of all tokens, creating an abstract syntax tree
3, Complier
Create a collection of instructions (Python bytecode) based on an abstract syntax tree
4, Exauator
Run Python bytecode
Second, the runtime environment is mainly divided into object/type system, memory allocator, run-time state information
1. Object/Type System
Contains all built-in objects for Python, user-defined types, and objects
2. Memory Splitter
Responsible for maintaining the memory request when the Python object is created
3. Run-time status information
Responsible for maintaining the interpreter switching actions between different states when executing byte codes
Third, the overall structure diagram:
Preparation of Python source code profiling