Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gnrlleclerc/brainfuck-jit
A toy compiler for the Brainfuck language, in Rust
https://github.com/gnrlleclerc/brainfuck-jit
Last synced: about 8 hours ago
JSON representation
A toy compiler for the Brainfuck language, in Rust
- Host: GitHub
- URL: https://github.com/gnrlleclerc/brainfuck-jit
- Owner: GnRlLeclerc
- License: apache-2.0
- Created: 2024-02-02T14:23:41.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2024-02-02T18:08:50.000Z (12 months ago)
- Last Synced: 2024-11-20T14:34:14.622Z (about 2 months ago)
- Language: Rust
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Brainfuck JIT in Rust
Author: Thibaut de Saivre
A simple brainfuck interpreter and JIT implemented as an exercize for course INF559 at Ecole Polytechnique.
The few implemented optimizations were taken from https://bfc.wilfred.me.uk/.Run with
```bash
cargo run -- -h
cargo run -- examples/mandelbrot.bf -t
```## Projet structure
This project uses `cargo workspaces`.
```bash
├── bin # CLI executable
│ └── main
├── examples # Example brainfuck programs
└── lib # Implementation logic
├── compiler # JIT compiler implementation
├── instructions # Instructions Enum definitions
├── interpreter # Interpreter implementation
├── lexer # Simple tokenization function
├── lib # Root lib module
├── optimizer # JIT optimization functions
└── x86_64 # Conversion from tokens to machine code
```## Optimizations performed
### Interpreter optimizations
- Identify jump target indexes in the source code using a linear scan before execution.
### JIT compiler optimizations
- Regroup `+` and `-` instructions
- Regroup `>` and `<` instructions
- Replace `[-]` loops with a "set to 0" instruction