|
1 | | -*Update this documentation upon completion of the compiler (https://edgepython.com/resources/architecture)* |
| 1 | +## Edge Python |
| 2 | + |
| 3 | +Single-pass SSA compiler for Python 3.13: logos lexer, token-to-bytecode parser, adaptive VM with inline caching, template memoization, and configurable sandbox limits. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +### Architecture |
| 8 | + |
| 9 | +- **Lexer**: DFA-driven tokenization, offset-indexed, zero-alloc |
| 10 | +- **Parser**: Single-pass SSA, phi nodes, precedence climbing, direct bytecode emission |
| 11 | +- **VM**: Adaptive stack machine, inline caching, template memoization |
| 12 | +- **Sandbox**: Configurable recursion, operation, and heap limits |
| 13 | + |
| 14 | +### Quick Start |
| 15 | + |
| 16 | +```bash |
| 17 | +cd compiler/ |
| 18 | + |
| 19 | +cargo build --release |
| 20 | +./target/release/edge -c 'print("Hello, world!")' |
| 21 | +``` |
| 22 | + |
| 23 | +### Usage |
| 24 | + |
| 25 | +| Command | Description | |
| 26 | +|---------------------------------|---------------------------------------------------| |
| 27 | +| `edge script.py` | Run with no limits | |
| 28 | +| `edge --sandbox script.py` | Run with sandbox (512 calls, 100M ops, 100K heap) | |
| 29 | +| `edge -d --sandbox script.py` | Debug output (verbosity level 1) | |
| 30 | +| `edge -dd --sandbox script.py` | Debug output (verbosity level 2) | |
| 31 | + |
| 32 | +### Building for WebAssembly |
| 33 | + |
| 34 | +```bash |
| 35 | +rustup target add wasm32-unknown-unknown |
| 36 | +cargo build --target wasm32-unknown-unknown --release --no-default-features --features wasm |
| 37 | +``` |
| 38 | + |
| 39 | +*Exported functions: `src_ptr()`, `out_ptr()`, `run(len: usize)` -> `usize`* |
| 40 | + |
| 41 | +### Project Structure |
2 | 42 |
|
3 | 43 | ```bash |
| 44 | +├── Cargo.lock |
| 45 | +├── Cargo.toml |
| 46 | +├── main.py |
| 47 | +├── README.md |
| 48 | +├── src |
| 49 | +│ ├── lib.rs |
| 50 | +│ ├── main.rs |
| 51 | +│ ├── modules |
| 52 | +│ │ ├── lexer.rs |
| 53 | +│ │ ├── parser.rs |
| 54 | +│ │ └── vm.rs |
| 55 | +│ └── wasm.rs |
| 56 | +└── tests |
| 57 | + ├── cases |
| 58 | + │ ├── lexer_cases.json |
| 59 | + │ ├── parser_cases.json |
| 60 | + │ └── vm_cases.json |
| 61 | + ├── integration_test.rs |
| 62 | + ├── lexer_test.rs |
| 63 | + ├── parser_test.rs |
| 64 | + └── vm_test.rs |
| 65 | +``` |
4 | 66 |
|
5 | | -lexer.rs |
6 | | - Tokenizes Python source into a stream of spanned Token variants. |
| 67 | +### Tests |
7 | 68 |
|
8 | | -parser.rs |
9 | | - Single-pass SSA bytecode emitter. No AST. Variables versioned on assignment (new def per write), phi-joined (select reaching defs) at control flow boundaries. |
| 69 | +```bash |
| 70 | +cargo test |
| 71 | +cargo test -- --ignored |
| 72 | +cargo test --features wasm-tests |
10 | 73 | ``` |
11 | 74 |
|
12 | | -*upx packer* |
| 75 | +### License |
| 76 | + |
| 77 | +MIT OR Apache-2.0 |
0 commit comments