Update zh_CN bytecode_instructions.md

This commit is contained in:
Cai Bingjun 2023-01-20 22:39:46 +08:00 committed by GitHub
parent 0b2c9e1d29
commit f6f75c59e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,11 +1,20 @@
# Python 字节码指令
[![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3Ddoc/EN/python/bytecode_instructions.md%26commit_hash%3Dd15cbbf7b33df0f78a575cff9679d84c36ea3ab1)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/python/bytecode_instructions.md&commit_hash=d15cbbf7b33df0f78a575cff9679d84c36ea3ab1)
[![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3Ddoc/EN/python/bytecode_instructions.md%26commit_hash%3Dfd60746f6adcd0c9898d56e9fceca5dab5a0a927)](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/python/bytecode_instructions.md&commit_hash=fd60746f6adcd0c9898d56e9fceca5dab5a0a927)
Python 字节码变量操作命令通过 名称索引(名称索引)访问。这是为了在 Python 中实现动态变量访问(可以使用 eval 等作为字符串访问)
一条指令为 2 个字节,指令和参数以 little endian 形式存储
不带参数的指令也使用 2 个字节(参数部分为 0)
* 3.11的改动:指令不再是固定长度一些指令超过2字节。在大多数情况下额外的字节序列为零其目的未知但它被认为是一个优化选项。已知的不规则字节长度指令如下。
* `PRECALL` (4 bytes)
* `CALL` (10 byte)
* `BINARY_OP` (4 byte)
* `STORE_ATTR` (10 byte)
* `COMPARE_OP` (6 byte)
* `LOAD_GLOBAL` (12 byte)
* `LOAD_ATTR` (10 byte)
## STORE_NAME(名称索引)
```python
@ -115,4 +124,4 @@ fast_locals 对应的函数内部变量名称列表
## 单元格变量
对应于 cellvars
在函数内捕获到内部闭包函数的变量。由于制作了副本,因此原始变量保持原样。
在函数内捕获到内部闭包函数的变量。由于制作了副本,因此原始变量保持原样。