@lewin671/python-vm 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +58 -57
  2. package/README_zh-CN.md +58 -57
  3. package/dist/common/string-token.d.ts +5 -0
  4. package/dist/common/string-token.d.ts.map +1 -0
  5. package/dist/common/string-token.js +23 -0
  6. package/dist/common/string-token.js.map +1 -0
  7. package/dist/compiler/cfg_builder.d.ts +48 -0
  8. package/dist/compiler/cfg_builder.d.ts.map +1 -0
  9. package/dist/compiler/cfg_builder.js +1462 -0
  10. package/dist/compiler/cfg_builder.js.map +1 -0
  11. package/dist/compiler/compiler.d.ts.map +1 -0
  12. package/dist/compiler/compiler.js +27 -0
  13. package/dist/compiler/compiler.js.map +1 -0
  14. package/dist/compiler/index.d.ts.map +1 -0
  15. package/dist/compiler/index.js.map +1 -0
  16. package/dist/compiler/linearizer.d.ts +7 -0
  17. package/dist/compiler/linearizer.d.ts.map +1 -0
  18. package/dist/compiler/linearizer.js +112 -0
  19. package/dist/compiler/linearizer.js.map +1 -0
  20. package/dist/compiler/serializer.d.ts +17 -0
  21. package/dist/compiler/serializer.d.ts.map +1 -0
  22. package/dist/compiler/serializer.js +70 -0
  23. package/dist/compiler/serializer.js.map +1 -0
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +58 -8
  27. package/dist/index.js.map +1 -1
  28. package/dist/lexer/lexer.d.ts.map +1 -1
  29. package/dist/lexer/lexer.js +25 -11
  30. package/dist/lexer/lexer.js.map +1 -1
  31. package/dist/parser/expressions.d.ts.map +1 -1
  32. package/dist/parser/expressions.js +5 -2
  33. package/dist/parser/expressions.js.map +1 -1
  34. package/dist/parser/parser.js +3 -3
  35. package/dist/parser/parser.js.map +1 -1
  36. package/dist/parser/statements.d.ts.map +1 -1
  37. package/dist/parser/statements.js +60 -22
  38. package/dist/parser/statements.js.map +1 -1
  39. package/dist/python_compiler.d.ts +32 -0
  40. package/dist/python_compiler.d.ts.map +1 -0
  41. package/dist/{compiler.js → python_compiler.js} +19 -6
  42. package/dist/python_compiler.js.map +1 -0
  43. package/dist/types/ast.d.ts +286 -44
  44. package/dist/types/ast.d.ts.map +1 -1
  45. package/dist/types/ast.js +43 -36
  46. package/dist/types/ast.js.map +1 -1
  47. package/dist/types/bytecode.d.ts +106 -21
  48. package/dist/types/bytecode.d.ts.map +1 -1
  49. package/dist/types/bytecode.js +111 -23
  50. package/dist/types/bytecode.js.map +1 -1
  51. package/dist/types/cfg.d.ts +20 -0
  52. package/dist/types/cfg.d.ts.map +1 -0
  53. package/dist/types/cfg.js +3 -0
  54. package/dist/types/cfg.js.map +1 -0
  55. package/dist/types/index.d.ts +1 -0
  56. package/dist/types/index.d.ts.map +1 -1
  57. package/dist/types/index.js +1 -0
  58. package/dist/types/index.js.map +1 -1
  59. package/dist/vm/builtins.d.ts.map +1 -1
  60. package/dist/vm/builtins.js +23 -7
  61. package/dist/vm/builtins.js.map +1 -1
  62. package/dist/vm/callable.d.ts +6 -6
  63. package/dist/vm/callable.d.ts.map +1 -1
  64. package/dist/vm/callable.js +28 -7
  65. package/dist/vm/callable.js.map +1 -1
  66. package/dist/vm/execution-helpers.d.ts +17 -0
  67. package/dist/vm/execution-helpers.d.ts.map +1 -0
  68. package/dist/vm/execution-helpers.js +334 -0
  69. package/dist/vm/execution-helpers.js.map +1 -0
  70. package/dist/vm/execution.d.ts +4 -12
  71. package/dist/vm/execution.d.ts.map +1 -1
  72. package/dist/vm/execution.js +764 -255
  73. package/dist/vm/execution.js.map +1 -1
  74. package/dist/vm/expression-generator.d.ts +3 -1
  75. package/dist/vm/expression-generator.d.ts.map +1 -1
  76. package/dist/vm/expression-generator.js.map +1 -1
  77. package/dist/vm/expressions.d.ts +6 -6
  78. package/dist/vm/expressions.d.ts.map +1 -1
  79. package/dist/vm/expressions.js +29 -54
  80. package/dist/vm/expressions.js.map +1 -1
  81. package/dist/vm/imports.d.ts +4 -4
  82. package/dist/vm/imports.d.ts.map +1 -1
  83. package/dist/vm/imports.js.map +1 -1
  84. package/dist/vm/operations.d.ts +11 -10
  85. package/dist/vm/operations.d.ts.map +1 -1
  86. package/dist/vm/operations.js +83 -22
  87. package/dist/vm/operations.js.map +1 -1
  88. package/dist/vm/runtime-types.d.ts +64 -26
  89. package/dist/vm/runtime-types.d.ts.map +1 -1
  90. package/dist/vm/runtime-types.js +166 -19
  91. package/dist/vm/runtime-types.js.map +1 -1
  92. package/dist/vm/statements.d.ts +5 -5
  93. package/dist/vm/statements.d.ts.map +1 -1
  94. package/dist/vm/statements.js +95 -10
  95. package/dist/vm/statements.js.map +1 -1
  96. package/dist/vm/truthy.d.ts +2 -2
  97. package/dist/vm/truthy.d.ts.map +1 -1
  98. package/dist/vm/truthy.js +1 -1
  99. package/dist/vm/truthy.js.map +1 -1
  100. package/dist/vm/value-utils.d.ts +23 -25
  101. package/dist/vm/value-utils.d.ts.map +1 -1
  102. package/dist/vm/value-utils.js +216 -47
  103. package/dist/vm/value-utils.js.map +1 -1
  104. package/dist/vm/vm.d.ts +7 -3
  105. package/dist/vm/vm.d.ts.map +1 -1
  106. package/dist/vm/vm.js +3 -0
  107. package/dist/vm/vm.js.map +1 -1
  108. package/package.json +3 -3
  109. package/dist/compiler.d.ts +0 -20
  110. package/dist/compiler.d.ts.map +0 -1
  111. package/dist/compiler.js.map +0 -1
  112. package/dist/compiler_module/compiler.d.ts.map +0 -1
  113. package/dist/compiler_module/compiler.js +0 -22
  114. package/dist/compiler_module/compiler.js.map +0 -1
  115. package/dist/compiler_module/index.d.ts.map +0 -1
  116. package/dist/compiler_module/index.js.map +0 -1
  117. /package/dist/{compiler_module → compiler}/compiler.d.ts +0 -0
  118. /package/dist/{compiler_module → compiler}/index.d.ts +0 -0
  119. /package/dist/{compiler_module → compiler}/index.js +0 -0
package/README.md CHANGED
@@ -1,93 +1,94 @@
1
1
  # @lewin671/python-vm
2
2
 
3
- A Python compiler and interpreter implemented in TypeScript. The compiler currently packages the AST into a bytecode container that the VM executes.
3
+ [![License](https://img.shields.io/github/license/Lewin671/python-compiler-ts)](https://github.com/Lewin671/python-compiler-ts/blob/main/LICENSE)
4
+ [![NPM Version](https://img.shields.io/npm/v/@lewin671/python-vm)](https://www.npmjs.com/package/@lewin671/python-vm)
5
+
6
+ A high-performance Python compiler and Virtual Machine (VM) implemented entirely in TypeScript. This project aims to provide a robust, Python-compliant execution environment within the JavaScript ecosystem, featuring a complete compilation pipeline from source code to bytecode.
4
7
 
5
8
  [简体中文](README_zh-CN.md)
6
9
 
7
- ## Features
10
+ ## 🚀 Key Highlights
8
11
 
9
- - [x] CLI entry point for running `.py` files
10
- - [x] Lexer with indentation handling, numbers, strings (including f-strings), keywords, and operators
11
- - [x] Parser that builds ASTs for statements and expressions (functions, classes, loops, comprehensions, exceptions, and more)
12
- - [x] Bytecode compiler scaffold that passes ASTs to the VM
13
- - [x] AST-based virtual machine with scopes, control flow, functions, classes, generators, context managers, and exceptions
14
- - [x] Python data structures including lists, tuples, dicts, sets, slicing, and comprehensions
15
- - [x] Built-ins:
16
- - Type/conversion: int, float, str, bool, list, tuple, set, type, isinstance
17
- - Iteration: range, enumerate, zip, sorted, reversed, map, filter, next
18
- - Math/util: abs, round, sum, min, max
19
- - I/O: print, open
20
- - [x] Example scripts and Vitest suite that compare output against system Python
12
+ - **Advanced Compilation Pipeline**: Moves beyond simple interpretation by implementing a multi-stage pipeline: Source → Tokens → AST → Control Flow Graph (CFG) → Linear Bytecode → VM.
13
+ - **Python-Strict Semantics**: Carefully implemented data structures (`PyDict`, `PySet`, `PyList`) that strictly follow Python's rules for equality, hashing, and numeric types (including BigInt for arbitrary-precision integers and NaN handling).
14
+ - **Comprehensive Language Support**:
15
+ - **Core**: Full support for functions, classes, closures, and decorators.
16
+ - **Modern Features**: Includes `match` statements (Structural Pattern Matching), `with` statements (Context Managers), and `try/except/finally` blocks.
17
+ - **Control Flow**: Robust handling of generators (`yield`), list/dict/set comprehensions, and nested scopes (`global`, `nonlocal`).
18
+ - **Production-Ready Tooling**: Includes a high-fidelity Lexer with indentation/dedentation logic, a recursive descent Parser, and a stack-based VM.
21
19
 
22
- ## Getting Started
20
+ ## 🛠 Features
23
21
 
24
- ### Requirements
22
+ ### Compiler & VM
23
+ - [x] **Lexer**: Handles complex Python indentation, f-strings, and multi-line literals.
24
+ - [x] **Parser**: Generates a typed AST supporting a wide subset of Python 3.10+ syntax.
25
+ - [x] **CFG Builder**: Optimizes code structures into a Control Flow Graph before bytecode generation.
26
+ - [x] **Bytecode Virtual Machine**: A stack-based execution engine with local/global scope management.
27
+ - [x] **Exception System**: Full traceback support and Python-compliant exception hierarchy.
25
28
 
26
- - Node.js 18+
27
- - npm
28
- - Python 3 available on your PATH for tests (set `PYTHON=python3` if needed)
29
+ ### Standard Library & Built-ins
30
+ - **Data Types**: `int`, `float`, `str`, `bool`, `list`, `tuple`, `dict`, `set`, `None`.
31
+ - **Iteration**: `range`, `enumerate`, `zip`, `reversed`, `map`, `filter`, `sorted`.
32
+ - **Utilities**: `abs`, `round`, `sum`, `min`, `max`, `isinstance`, `type`, `print`, `open`, `next`.
29
33
 
30
- ### Install
34
+ ## 📦 Installation
31
35
 
32
36
  ```bash
33
- npm install
37
+ npm install @lewin671/python-vm
34
38
  ```
35
39
 
36
- ### Build
40
+ ## 📖 Usage
37
41
 
38
- ```bash
39
- npm run build
40
- ```
42
+ ### Running via CLI
41
43
 
42
- ### Test
43
-
44
- ```bash
45
- npm test
46
- ```
47
-
48
- If the tests cannot find Python, set the environment variable before running them, for example: `export PYTHON=python3`.
49
-
50
- ### Run
44
+ After cloning the repository, you can run Python files directly:
51
45
 
52
46
  ```bash
53
47
  npm run build
54
48
  npm start -- examples/hello.py
55
49
  ```
56
50
 
57
- Or run directly:
51
+ ### AOT Compilation (Ahead-Of-Time)
52
+
53
+ You can compile Python source files to a compressed binary bytecode format (`.pyc`) and execute them later. This avoids parsing overhead at runtime.
58
54
 
59
55
  ```bash
60
- node dist/index.js examples/hello.py
61
- ```
56
+ # 1. Compile source to bytecode
57
+ npm start -- compile examples/hello.py hello.pyc
62
58
 
63
- ### Use in TypeScript
59
+ # 2. Run the bytecode directly
60
+ npm start -- run hello.pyc
61
+ ```
64
62
 
65
- After `npm run build`, you can call the compiler from TypeScript. When consuming the package, import from `@lewin671/python-vm`. For local development in this repo, import from `./dist` instead.
63
+ ### Using in your TypeScript project
66
64
 
67
65
  ```ts
68
66
  import { PythonCompiler } from '@lewin671/python-vm';
69
67
 
70
68
  const compiler = new PythonCompiler();
71
- const result = compiler.run('print("Hello from TypeScript")');
72
69
 
73
- console.log(result);
74
- ```
70
+ // Execute code directly
71
+ const result = compiler.run(`
72
+ def greet(name):
73
+ return f"Hello, {name}!"
75
74
 
76
- ## Project Structure
75
+ result = [greet(x) for x in ["World", "TypeScript"]]
76
+ print(result)
77
+ `);
77
78
 
79
+ // Or run a file
80
+ // compiler.runFile('./script.py');
78
81
  ```
79
- @lewin671/python-vm/
80
- ├── dist/ # Compiled output
81
- ├── examples/ # Sample Python programs used by tests
82
- ├── src/
83
- │ ├── compiler.ts # Public PythonCompiler API
84
- │ ├── compiler_module/ # Bytecode compiler scaffold
85
- │ ├── index.ts # CLI entry + exports
86
- │ ├── lexer/ # Tokenizer
87
- │ ├── parser/ # AST parser
88
- │ ├── types/ # Tokens, AST, bytecode types
89
- │ └── vm/ # AST interpreter (virtual machine)
90
- ├── tests/ # Vitest suites comparing against CPython
91
- ├── package.json
92
- └── tsconfig.json
82
+
83
+ ## 🧪 Testing and Correctness
84
+
85
+ Correctness is a top priority. The project includes an extensive test suite using **Vitest** that compares the VM output against the system's CPython interpreter for parity.
86
+
87
+ ```bash
88
+ # Run all tests (requires Python 3 installed locally)
89
+ npm test
93
90
  ```
91
+
92
+ ## ⚖️ License
93
+
94
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/README_zh-CN.md CHANGED
@@ -1,93 +1,94 @@
1
1
  # @lewin671/python-vm
2
2
 
3
- 一个使用 TypeScript 实现的 Python 编译器与解释器。目前编译器会将 AST 打包到字节码容器中,由虚拟机执行。
3
+ [![License](https://img.shields.io/github/license/Lewin671/python-compiler-ts)](https://github.com/Lewin671/python-compiler-ts/blob/main/LICENSE)
4
+ [![NPM Version](https://img.shields.io/npm/v/@lewin671/python-vm)](https://www.npmjs.com/package/@lewin671/python-vm)
5
+
6
+ 一个完全使用 TypeScript 实现的高性能 Python 编译器与虚拟机 (VM)。本项目旨在为 JavaScript 生态提供一个鲁棒且符合 Python 语义的执行环境,包含从源码到字节码的完整编译流水线。
4
7
 
5
8
  [English](README.md)
6
9
 
7
- ## 功能特性
10
+ ## 🚀 项目亮点
8
11
 
9
- - [x] CLI 入口,用于运行 `.py` 文件
10
- - [x] 具备缩进处理、数字/字符串(含 f-string)、关键字与运算符的词法分析器
11
- - [x] 语法分析器生成 AST,覆盖函数、类、循环、推导式、异常等语句与表达式
12
- - [x] 字节码编译器框架,将 AST 交给虚拟机执行
13
- - [x] 基于 AST 的虚拟机,支持作用域、控制流、函数、类、生成器、上下文管理器与异常
14
- - [x] Python 数据结构支持:list、tuple、dict、set、切片与推导式
15
- - [x] 内置函数:
16
- - 类型/转换:int、float、str、bool、list、tuple、set、type、isinstance
17
- - 迭代相关:range、enumerate、zip、sorted、reversed、map、filter、next
18
- - 数值/工具:abs、round、sum、min、max
19
- - 输入输出:print、open
20
- - [x] 示例脚本与 Vitest 测试,输出对比系统 Python
12
+ - **先进的编译流水线**:超越简单的解释执行,实现了多阶段编译流程:源码 Token → AST (抽象语法树) → CFG (控制流图) → 线性字节码 → 虚拟机执行。
13
+ - **严格的 Python 语义**:精心实现的数据结构(`PyDict`, `PySet`, `PyList`)严格遵循 Python 关于等值性、哈希计算以及数值类型的规则(支持大整数 BigInt 和完整的 NaN 处理逻辑)。
14
+ - **全面的语言支持**:
15
+ - **核心语法**:完整支持函数、类、闭包及装饰器。
16
+ - **现代特性**:包括 `match` 语句(结构化模式匹配)、`with` 语句(上下文管理器)以及 `try/except/finally` 异常处理块。
17
+ - **控制流**:支持生成器 (`yield`)、列表/字典/集合推导式,以及复杂的嵌套作用域(`global`, `nonlocal`)。
18
+ - **工程化实现**:配备了支持缩进逻辑的高精度词法分析器 (Lexer)、递归下降语法分析器 (Parser) 以及一个高效的基于栈的虚拟机 (VM)。
21
19
 
22
- ## 快速开始
20
+ ## 🛠 功能特性
23
21
 
24
- ### 环境要求
22
+ ### 编译器与虚拟机
23
+ - [x] **词法分析器 (Lexer)**:处理复杂的 Python 缩进/反缩进、f-strings 以及多行字面量。
24
+ - [x] **语法分析器 (Parser)**:生成的类型化 AST 覆盖了 Python 3.10+ 的绝大部分常用语法。
25
+ - [x] **控制流图构建器 (CFG Builder)**:在生成字节码前优化代码结构。
26
+ - [x] **字节码虚拟机**:支持局部/全局作用域管理、调用栈以及高效的指令集执行。
27
+ - [x] **异常系统**:提供完整的 Traceback 支持和符合 Python 规范的异常层级。
25
28
 
26
- - Node.js 18+
27
- - npm
28
- - Python 3(运行测试需要,确保在 PATH 中;必要时设置 `PYTHON=python3`)
29
+ ### 标准库与内置函数
30
+ - **数据类型**:`int` (任意精度), `float`, `str`, `bool`, `list`, `tuple`, `dict`, `set`, `None`。
31
+ - **迭代工具**:`range`, `enumerate`, `zip`, `reversed`, `map`, `filter`, `sorted`。
32
+ - **内置工具**:`abs`, `round`, `sum`, `min`, `max`, `isinstance`, `type`, `print`, `open`, `next`。
29
33
 
30
- ### 安装依赖
34
+ ## 📦 安装使用
31
35
 
32
36
  ```bash
33
- npm install
37
+ npm install @lewin671/python-vm
34
38
  ```
35
39
 
36
- ### 构建
40
+ ## 📖 使用指南
37
41
 
38
- ```bash
39
- npm run build
40
- ```
42
+ ### 通过命令行运行
41
43
 
42
- ### 测试
43
-
44
- ```bash
45
- npm test
46
- ```
47
-
48
- 如果测试无法找到 Python,可先设置环境变量,例如:`export PYTHON=python3`。
49
-
50
- ### 运行
44
+ 克隆仓库后,您可以直接运行 Python 文件:
51
45
 
52
46
  ```bash
53
47
  npm run build
54
48
  npm start -- examples/hello.py
55
49
  ```
56
50
 
57
- 或直接运行:
51
+ ### AOT 预编译 (Ahead-Of-Time)
52
+
53
+ 您可以将 Python 源代码编译为压缩的二进制字节码格式 (`.pyc`),并在后续直接加载执行,从而避免运行时的解析开销。
58
54
 
59
55
  ```bash
60
- node dist/index.js examples/hello.py
61
- ```
56
+ # 1. 将源码编译为字节码
57
+ npm start -- compile examples/hello.py hello.pyc
62
58
 
63
- ### TypeScript 中调用
59
+ # 2. 直接运行字节码文件
60
+ npm start -- run hello.pyc
61
+ ```
64
62
 
65
- 运行 `npm run build` 后,可以在 TypeScript 中这样调用。作为依赖使用时请从 `@lewin671/python-vm` 导入,本仓库本地开发时则从 `./dist` 导入。
63
+ ### TypeScript 项目中调用
66
64
 
67
65
  ```ts
68
66
  import { PythonCompiler } from '@lewin671/python-vm';
69
67
 
70
68
  const compiler = new PythonCompiler();
71
- const result = compiler.run('print("Hello from TypeScript")');
72
69
 
73
- console.log(result);
74
- ```
70
+ // 直接执行代码
71
+ const result = compiler.run(`
72
+ def greet(name):
73
+ return f"Hello, {name}!"
75
74
 
76
- ## 项目结构
75
+ result = [greet(x) for x in ["World", "TypeScript"]]
76
+ print(result)
77
+ `);
77
78
 
79
+ // 或者运行文件
80
+ // compiler.runFile('./script.py');
78
81
  ```
79
- @lewin671/python-vm/
80
- ├── dist/ # 编译输出
81
- ├── examples/ # 测试用 Python 示例
82
- ├── src/
83
- │ ├── compiler.ts # PythonCompiler 公共 API
84
- │ ├── compiler_module/ # 字节码编译器框架
85
- │ ├── index.ts # CLI 入口 + 导出
86
- │ ├── lexer/ # 词法分析器
87
- │ ├── parser/ # 语法分析器
88
- │ ├── types/ # Token/AST/字节码类型
89
- │ └── vm/ # AST 解释执行器
90
- ├── tests/ # 与 CPython 对比的 Vitest 测试
91
- ├── package.json
92
- └── tsconfig.json
82
+
83
+ ## 🧪 测试与正确性
84
+
85
+ 正确性是本项目的核心指标。我们使用 **Vitest** 构建了庞大的测试套件,通过将虚拟机的输出与系统原生的 CPython 解释器进行对比,确保执行结果的一致性。
86
+
87
+ ```bash
88
+ # 运行所有测试(需要本地安装 Python 3)
89
+ npm test
93
90
  ```
91
+
92
+ ## ⚖️ 开源协议
93
+
94
+ 本项目基于 MIT 协议开源 - 详见 [LICENSE](LICENSE) 文件。
@@ -0,0 +1,5 @@
1
+ export declare const parseStringToken: (tokenValue: string) => {
2
+ value: string;
3
+ isFString: boolean;
4
+ };
5
+ //# sourceMappingURL=string-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-token.d.ts","sourceRoot":"","sources":["../../src/common/string-token.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,KAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAiBxF,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseStringToken = void 0;
4
+ const parseStringToken = (tokenValue) => {
5
+ let raw = tokenValue;
6
+ let isFString = false;
7
+ if (raw.startsWith('f') || raw.startsWith('F')) {
8
+ isFString = true;
9
+ raw = raw.slice(1);
10
+ }
11
+ const quote = raw[0];
12
+ if (raw.startsWith(quote.repeat(3))) {
13
+ const inner = raw.slice(3, -3);
14
+ return { value: inner, isFString };
15
+ }
16
+ const inner = raw.slice(1, -1);
17
+ return {
18
+ value: inner.replace(/\\n/g, '\n').replace(/\\t/g, '\t').replace(/\\"/g, '"').replace(/\\'/g, "'"),
19
+ isFString,
20
+ };
21
+ };
22
+ exports.parseStringToken = parseStringToken;
23
+ //# sourceMappingURL=string-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-token.js","sourceRoot":"","sources":["../../src/common/string-token.ts"],"names":[],"mappings":";;;AAAO,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAyC,EAAE;IAC5F,IAAI,GAAG,GAAG,UAAU,CAAC;IACrB,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,SAAS,GAAG,IAAI,CAAC;QACjB,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;IACD,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACrB,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IACrC,CAAC;IACD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/B,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;QAClG,SAAS;KACV,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,gBAAgB,oBAiB3B"}
@@ -0,0 +1,48 @@
1
+ import { ASTNode, CFG } from '../types';
2
+ export declare class CFGBuilder {
3
+ private blocks;
4
+ private currentBlock;
5
+ private blockIdCounter;
6
+ private constants;
7
+ private names;
8
+ private varnames;
9
+ private argcount;
10
+ private globalVars;
11
+ private nonlocalVars;
12
+ private loopStack;
13
+ constructor(argcount?: number, initialVarnames?: string[]);
14
+ private createBlock;
15
+ private addInstruction;
16
+ private getConstantIndex;
17
+ private getNameIndex;
18
+ private getVarIndex;
19
+ build(ast: ASTNode): CFG;
20
+ getConstants(): any[];
21
+ getNames(): string[];
22
+ getVarnames(): string[];
23
+ getArgcount(): number;
24
+ getGlobals(): string[];
25
+ getNonlocals(): string[];
26
+ private visit;
27
+ private addBinaryOperation;
28
+ private addInplaceOperation;
29
+ private addCompareOperation;
30
+ private visitTarget;
31
+ private visitIf;
32
+ private visitWhile;
33
+ private visitFor;
34
+ private visitFunctionDef;
35
+ private containsYield;
36
+ private findAssignedVariables;
37
+ private extractAssignedNames;
38
+ private visitLambda;
39
+ private addUnaryOperation;
40
+ private visitBoolOp;
41
+ private visitIfExpression;
42
+ private visitTry;
43
+ private visitWith;
44
+ private processWithItems;
45
+ private visitMatch;
46
+ private compilePattern;
47
+ }
48
+ //# sourceMappingURL=cfg_builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cfg_builder.d.ts","sourceRoot":"","sources":["../../src/compiler/cfg_builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EAKP,GAAG,EAcN,MAAM,UAAU,CAAC;AAKlB,qBAAa,UAAU;IACnB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,cAAc,CAAK;IAE3B,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,YAAY,CAA0B;IAI9C,OAAO,CAAC,SAAS,CAIT;gBAEI,QAAQ,GAAE,MAAU,EAAE,eAAe,GAAE,MAAM,EAAO;IAMhE,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,WAAW;IAOnB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG;IAUxB,YAAY;IACZ,QAAQ;IACR,WAAW;IACX,WAAW;IACX,UAAU;IACV,YAAY;IAEZ,OAAO,CAAC,KAAK;IAieb,OAAO,CAAC,kBAAkB;IAkB1B,OAAO,CAAC,mBAAmB;IAkB3B,OAAO,CAAC,mBAAmB;IAkB3B,OAAO,CAAC,WAAW;IAmFnB,OAAO,CAAC,OAAO;IAkDf,OAAO,CAAC,UAAU;IAsClB,OAAO,CAAC,QAAQ;IA6ChB,OAAO,CAAC,gBAAgB;IA4DxB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,qBAAqB;IAkE7B,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,WAAW;IAkCnB,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,WAAW;IAsCnB,OAAO,CAAC,iBAAiB;IA6BzB,OAAO,CAAC,QAAQ;IAiKhB,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,gBAAgB;IA4ExB,OAAO,CAAC,UAAU;IAoElB,OAAO,CAAC,cAAc;CAsJzB"}