Skip to content

Commit c8cbb32

Browse files
committed
docs: redraw remaining diagrams as SVG and refine the site
- redesign the long/list/dict/set chapter diagrams as SVG and drop the old raster images (including the object chapter jpgs) - split the book homepage (background + roadmap) out of README so the online preface no longer shows install/build instructions - render roadmap task lists via markdown-it-task-lists
1 parent 3e133c6 commit c8cbb32

30 files changed

Lines changed: 589 additions & 16 deletions

.vitepress/config.mts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from 'vitepress'
2+
import taskLists from 'markdown-it-task-lists'
23

34
// https://vitepress.dev/reference/site-config
45
export default defineConfig({
@@ -9,20 +10,20 @@ export default defineConfig({
910
// 部署在 https://flaggo.github.io/python3-source-code-analysis/
1011
base: '/python3-source-code-analysis/',
1112

12-
// 用仓库根目录作为内容源;README.md 作为首页
13+
// 用仓库根目录作为内容源;首页为 index.md(背景 + Roadmap)
1314
srcDir: '.',
14-
rewrites: {
15-
'README.md': 'index.md'
16-
},
17-
// 不作为页面渲染的文件 / 旧构建产物
18-
srcExclude: ['SUMMARY.md', '_book/**', '**/node_modules/**'],
15+
// 不作为页面渲染的文件:README 仅供 GitHub 仓库使用,不进站点
16+
srcExclude: ['README.md', 'SUMMARY.md', '_book/**', '**/node_modules/**'],
1917

2018
lastUpdated: true,
2119
cleanUrls: true,
2220
ignoreDeadLinks: true,
2321

2422
markdown: {
25-
lineNumbers: true
23+
lineNumbers: true,
24+
config: (md) => {
25+
md.use(taskLists)
26+
}
2627
},
2728

2829
themeConfig: {

index.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 前言
2+
3+
本项目致力于对 Python 3.7 的源码分析,深度参考陈儒大大的《Python 源码剖析》,编写 Python 3 的版本。
4+
5+
希望各位 Python 爱好者能参与其中,一起探索 Python 魔法背后的奥秘!
6+
7+
## Roadmap
8+
9+
大体按照《Python 源码剖析》中的目录结构进行编写。依次介绍 Python 源码基本信息、内建对象和虚拟机。
10+
11+
- [x] 章节
12+
- [x] 序章
13+
- [x] 前言
14+
- [x] Python 源代码的组织
15+
- [x] Windows 环境下编译 Python
16+
- [x] UNIX/Linux 环境下编译 Python
17+
- [x] 修改 Python 源码
18+
- [ ] Python 内建对象
19+
- [x] Python 对象初探
20+
- [x] Python 整数对象
21+
- [ ] Python 字符串 对象
22+
- [x] Python List 对象
23+
- [x] Python Dict 对象
24+
- [x] Python Set 对象
25+
- [ ] 实现简版 Python
26+
- [ ] Python 虚拟机
27+
- [ ] Python 编译结果
28+
- [ ] Python 虚拟机框架
29+
- [ ] 虚拟机一般表达式
30+
- [ ] Python 虚拟机控制流
31+
- [ ] Python 虚拟机函数机制
32+
- [ ] Python 运行环境初始化
33+
- [ ] Python 模块加载机制
34+
- [ ] Python 多线程机制
35+
- [ ] Python 内存管理机制

objects/dict-object/dict-mem.png

-114 KB
Binary file not shown.

objects/dict-object/dict-mem.svg

Lines changed: 89 additions & 0 deletions
Loading

objects/dict-object/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ struct _dictkeysobject {
127127
```
128128

129129
相关数据结构的内存布局为;
130-
![python_dict_mem](dict-mem.png)
130+
![python_dict_mem](dict-mem.svg)
131131

132132
## Python 字典示例
133133

-11.4 KB
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Loading

objects/list-object/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ lst.append(1)
3939

4040
其存储结构如下图
4141

42-
![PyList structure](PyListStructure.png)
42+
![PyList structure](PyListStructure.svg)
4343

4444

4545

objects/long-object/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ print(num)
387387

388388
如下图所示
389389

390-
![longobject storage](long-storage.png)
390+
![longobject storage](long-storage.svg)
391391

392392
注:这里的 30 是由 **PyLong_SHIFT** 决定的,64 位系统中,**PyLong_SHIFT** 为 30,否则 **PyLong_SHIFT** 为 15
393393

@@ -524,7 +524,7 @@ x_add(PyLongObject *a, PyLongObject *b)
524524

525525
加法运算函数 x_add 从 ob_digit 数组的低位开始依次按位相加,carry 做进位处理,然后处理 a 对象的高位数字,最后使用 long_normalize 函数调整 ob_size,确保 ob_digit[abs(ob_size)-1]不为零,这与普通四则运算的加法运算相同,只不过进位单元不同而已
526526

527-
![longobject x_add](long-x-add.png)
527+
![longobject x_add](long-x-add.svg)
528528

529529
`源文件:`[Objects/longobject.c](https://github.com/python/cpython/blob/v3.7.0/Objects/longobject.c#L3025)
530530

@@ -593,7 +593,7 @@ x_sub(PyLongObject *a, PyLongObject *b)
593593
与普通四则运算减法相同,数不够大则向高一位借位,
594594
减法运算函数 x_sub 的示例图如下,注:PyLong_SHIFT 为 30
595595
596-
![longobject x_sub](long-x-sub.png)
596+
![longobject x_sub](long-x-sub.svg)
597597
598598
### 整数相乘
599599
-15.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)