Python source code analysis is a commonly used computer language in the computer application process. This article gives a detailed introduction to three aspects of Python source code analysis, if you want to better understand the computer-related languages, do not browse the following articles.
1. Overall Python Architecture
At the highest level, the overall Python architecture can be divided into four main parts, as shown in architecture 1. On the left is a large number of modules provided by Python, libraries, and user-defined modules. For example, when you execute import OS, This OS is a built-in Python module. Of course, you can also use custom modules to expand the Python system. In this series of articles, we will not examine this part too much.
Python runtime environment, including Object/Type structures, Memory distributor Memory Allocator, and Current State of Python ). The runtime status maintains the interpreter's switching between different statuses when executing bytecode. we can regard it as a huge and complex finite state machine. The memory distributor is solely responsible for applying for memory when creating an object in Python. In fact, it is an interface layer between the Python runtime and the malloc in C. The object/type system contains various built-in objects in Python, such as integers, lists, and dict.
In the middle part, you can see the Python core, interpreter ). In the interpreter, the direction of the arrow indicates the direction of the data stream during Python runtime. The token corresponds to the lexical analysis. The Python source code input by the file or a line of Python code input from the command line is segmented into one token. The Parser corresponds to the syntax analysis section, perform syntax analysis on the explain analysis results to create an abstract syntax tree AST); Compiler generates a command set based on the established AST-Python bytecode byte code ), as the Java compiler and C # compiler do, Code Evaluator will explain and execute these bytecode. Therefore, Code Evaluator can be called an execution engine.
In the object/type system on the Right of Interpreter, the Arrow between the memory distributor represents the "use" relationship, and the Arrow between the memory distributor represents the modification relationship, that is, Python constantly modifies the status of the current interpreter during execution and switches between different statuses.
- Basic Application of Python to generate random numbers and random strings
- Benefits of Python Image Processing
- Basic Steps for installing and configuring Python
- How to solve infinite loops in Python Loops
- Python programming language user experience
2. Python source code Organization
There is an old saying in China that it is hard for us to have no rice. To analyze the Python source code, you must first obtain the Python source code.
3. Compile Python
Now, after downloading the Python source code, we can go through the first step of analyzing the Python source code -- compiling Python :)
Python2.4.1 was developed in the Visual Studio 2003 environment. In the PCBuild directory, you can see the VS2003 project file. After opening the project, you need to make some settings to compile it successfully.
We also need a pythonnt_rc_d.h file which is not provided in the Python2.4.1 source code package. It must be compiled using a make_versioninfo sub-project to generate it automatically.
Now, compile again, and everything will be done smoothly.