所以我最近看到了对 Python 解释器和编译器(特别是 CPython)的解释。
如果我错了,请纠正我。我只是想确保我理解这些具体概念。
那么 CPython 既被编译(为字节码),又被解释(在 PVM 中)?PVM 到底是做什么的?它是否逐行读取字节码,并将每一行转换为可以在特定计算机上执行的二进制指令?这是否意味着基于 Intel 处理器的计算机需要与基于 AMD 的计算机不同的 PVM?
if/else语句,例如“如果当前指令是这个,则执行此操作;如果指令是这个,则执行另一件事”,等等。指令不会转换为二进制 - 这就是它被称为解释器的原因。
if/else语句来决定它正在查看什么指令。例如:
curr_byte = read_byte()
if curr_byte == 0x00:
# Parse instruction with no arguments
curr_instruction = DO_THING_A;
args = NULL;
elif curr_byte == 0x01:
another_byte = read_byte()
if another_byte == 0x00:
# Parse a two-byte instruction
curr_instruction = DO_THING_B;
args = NULL;
else:
# Parse a one-byte instruction
# with one argument
curr_instruction = DO_THING_C;
args = another_byte >> 1; # or whatever
elif curr_byte == ...:
... # go on and on and on
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
612 次 |
| 最近记录: |