@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.
- package/README.md +58 -57
- package/README_zh-CN.md +58 -57
- package/dist/common/string-token.d.ts +5 -0
- package/dist/common/string-token.d.ts.map +1 -0
- package/dist/common/string-token.js +23 -0
- package/dist/common/string-token.js.map +1 -0
- package/dist/compiler/cfg_builder.d.ts +48 -0
- package/dist/compiler/cfg_builder.d.ts.map +1 -0
- package/dist/compiler/cfg_builder.js +1462 -0
- package/dist/compiler/cfg_builder.js.map +1 -0
- package/dist/compiler/compiler.d.ts.map +1 -0
- package/dist/compiler/compiler.js +27 -0
- package/dist/compiler/compiler.js.map +1 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/linearizer.d.ts +7 -0
- package/dist/compiler/linearizer.d.ts.map +1 -0
- package/dist/compiler/linearizer.js +112 -0
- package/dist/compiler/linearizer.js.map +1 -0
- package/dist/compiler/serializer.d.ts +17 -0
- package/dist/compiler/serializer.d.ts.map +1 -0
- package/dist/compiler/serializer.js +70 -0
- package/dist/compiler/serializer.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -8
- package/dist/index.js.map +1 -1
- package/dist/lexer/lexer.d.ts.map +1 -1
- package/dist/lexer/lexer.js +25 -11
- package/dist/lexer/lexer.js.map +1 -1
- package/dist/parser/expressions.d.ts.map +1 -1
- package/dist/parser/expressions.js +5 -2
- package/dist/parser/expressions.js.map +1 -1
- package/dist/parser/parser.js +3 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/statements.d.ts.map +1 -1
- package/dist/parser/statements.js +60 -22
- package/dist/parser/statements.js.map +1 -1
- package/dist/python_compiler.d.ts +32 -0
- package/dist/python_compiler.d.ts.map +1 -0
- package/dist/{compiler.js → python_compiler.js} +19 -6
- package/dist/python_compiler.js.map +1 -0
- package/dist/types/ast.d.ts +286 -44
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/ast.js +43 -36
- package/dist/types/ast.js.map +1 -1
- package/dist/types/bytecode.d.ts +106 -21
- package/dist/types/bytecode.d.ts.map +1 -1
- package/dist/types/bytecode.js +111 -23
- package/dist/types/bytecode.js.map +1 -1
- package/dist/types/cfg.d.ts +20 -0
- package/dist/types/cfg.d.ts.map +1 -0
- package/dist/types/cfg.js +3 -0
- package/dist/types/cfg.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/vm/builtins.d.ts.map +1 -1
- package/dist/vm/builtins.js +23 -7
- package/dist/vm/builtins.js.map +1 -1
- package/dist/vm/callable.d.ts +6 -6
- package/dist/vm/callable.d.ts.map +1 -1
- package/dist/vm/callable.js +28 -7
- package/dist/vm/callable.js.map +1 -1
- package/dist/vm/execution-helpers.d.ts +17 -0
- package/dist/vm/execution-helpers.d.ts.map +1 -0
- package/dist/vm/execution-helpers.js +334 -0
- package/dist/vm/execution-helpers.js.map +1 -0
- package/dist/vm/execution.d.ts +4 -12
- package/dist/vm/execution.d.ts.map +1 -1
- package/dist/vm/execution.js +764 -255
- package/dist/vm/execution.js.map +1 -1
- package/dist/vm/expression-generator.d.ts +3 -1
- package/dist/vm/expression-generator.d.ts.map +1 -1
- package/dist/vm/expression-generator.js.map +1 -1
- package/dist/vm/expressions.d.ts +6 -6
- package/dist/vm/expressions.d.ts.map +1 -1
- package/dist/vm/expressions.js +29 -54
- package/dist/vm/expressions.js.map +1 -1
- package/dist/vm/imports.d.ts +4 -4
- package/dist/vm/imports.d.ts.map +1 -1
- package/dist/vm/imports.js.map +1 -1
- package/dist/vm/operations.d.ts +11 -10
- package/dist/vm/operations.d.ts.map +1 -1
- package/dist/vm/operations.js +83 -22
- package/dist/vm/operations.js.map +1 -1
- package/dist/vm/runtime-types.d.ts +64 -26
- package/dist/vm/runtime-types.d.ts.map +1 -1
- package/dist/vm/runtime-types.js +166 -19
- package/dist/vm/runtime-types.js.map +1 -1
- package/dist/vm/statements.d.ts +5 -5
- package/dist/vm/statements.d.ts.map +1 -1
- package/dist/vm/statements.js +95 -10
- package/dist/vm/statements.js.map +1 -1
- package/dist/vm/truthy.d.ts +2 -2
- package/dist/vm/truthy.d.ts.map +1 -1
- package/dist/vm/truthy.js +1 -1
- package/dist/vm/truthy.js.map +1 -1
- package/dist/vm/value-utils.d.ts +23 -25
- package/dist/vm/value-utils.d.ts.map +1 -1
- package/dist/vm/value-utils.js +216 -47
- package/dist/vm/value-utils.js.map +1 -1
- package/dist/vm/vm.d.ts +7 -3
- package/dist/vm/vm.d.ts.map +1 -1
- package/dist/vm/vm.js +3 -0
- package/dist/vm/vm.js.map +1 -1
- package/package.json +3 -3
- package/dist/compiler.d.ts +0 -20
- package/dist/compiler.d.ts.map +0 -1
- package/dist/compiler.js.map +0 -1
- package/dist/compiler_module/compiler.d.ts.map +0 -1
- package/dist/compiler_module/compiler.js +0 -22
- package/dist/compiler_module/compiler.js.map +0 -1
- package/dist/compiler_module/index.d.ts.map +0 -1
- package/dist/compiler_module/index.js.map +0 -1
- /package/dist/{compiler_module → compiler}/compiler.d.ts +0 -0
- /package/dist/{compiler_module → compiler}/index.d.ts +0 -0
- /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
|
-
|
|
3
|
+
[](https://github.com/Lewin671/python-compiler-ts/blob/main/LICENSE)
|
|
4
|
+
[](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
|
-
##
|
|
10
|
+
## 🚀 Key Highlights
|
|
8
11
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
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
|
-
##
|
|
20
|
+
## 🛠 Features
|
|
23
21
|
|
|
24
|
-
###
|
|
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
|
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
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
|
-
|
|
34
|
+
## 📦 Installation
|
|
31
35
|
|
|
32
36
|
```bash
|
|
33
|
-
npm install
|
|
37
|
+
npm install @lewin671/python-vm
|
|
34
38
|
```
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
## 📖 Usage
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
npm run build
|
|
40
|
-
```
|
|
42
|
+
### Running via CLI
|
|
41
43
|
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
56
|
+
# 1. Compile source to bytecode
|
|
57
|
+
npm start -- compile examples/hello.py hello.pyc
|
|
62
58
|
|
|
63
|
-
|
|
59
|
+
# 2. Run the bytecode directly
|
|
60
|
+
npm start -- run hello.pyc
|
|
61
|
+
```
|
|
64
62
|
|
|
65
|
-
|
|
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
|
-
|
|
74
|
-
|
|
70
|
+
// Execute code directly
|
|
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
|
+
// Or run a file
|
|
80
|
+
// compiler.runFile('./script.py');
|
|
78
81
|
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
3
|
+
[](https://github.com/Lewin671/python-compiler-ts/blob/main/LICENSE)
|
|
4
|
+
[](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
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
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
|
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
56
|
+
# 1. 将源码编译为字节码
|
|
57
|
+
npm start -- compile examples/hello.py hello.pyc
|
|
62
58
|
|
|
63
|
-
|
|
59
|
+
# 2. 直接运行字节码文件
|
|
60
|
+
npm start -- run hello.pyc
|
|
61
|
+
```
|
|
64
62
|
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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 @@
|
|
|
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"}
|