https://github.com/hez2010/brainfly
A high-performance Brainfuck JIT and AOT compiler built on top of C# type system
https://github.com/hez2010/brainfly
brainfuck compiler csharp dotnet hacktoberfest
Last synced: 8 months ago
JSON representation
A high-performance Brainfuck JIT and AOT compiler built on top of C# type system
- Host: GitHub
- URL: https://github.com/hez2010/brainfly
- Owner: hez2010
- License: mit
- Created: 2025-01-30T21:03:26.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-10-16T12:22:42.000Z (8 months ago)
- Last Synced: 2025-10-17T15:04:19.993Z (8 months ago)
- Topics: brainfuck, compiler, csharp, dotnet, hacktoberfest
- Language: C#
- Homepage:
- Size: 914 KB
- Stars: 46
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Brainfly
A Brainf**k JIT and AOT compiler built on top of C# type system.
Leveraged .NET generic type system and abstract static interface methods to achieve great performance.
See [Introduction](Intro.md) for details.
## Build
```bash
dotnet build -c Release
```
## Usage
```bash
dotnet run -c Release -- build
dotnet run -c Release -- run
dotnet run -c Release -- bench
```
For example,
```bash
dotnet run -c Release -- build 1024 a.bf # produce a self-contained a.cs so that you can run it directly with .NET or build it with .NET NativeAOT
dotnet run -c Release -- run 1024 a.bf # running directly from source file a.bf
dotnet run -c Release -- bench 1024 a.bf # benchmark directly from source file a.bf
```
## Benchmarks
### Mandelbrot
| Name | Time (ms) | Rank | Ratio | Binary size | Description |
| --- | --- | --- | --- | --- | --- |
| Interpreter in C | 4,874.6587 | 5 | 5.59 | N/A | A Brainfuck interpreter written in C |
| GCC | 901.0225 | 3 | 1.03 | **52 KB** | Translate to C, then build with `gcc -O3 -march=native` |
| Clang | 881.7177 | 2 | 1.01 | 56 KB | Translate to C, then build with `clang -O3 -march=native` |
| .NET JIT | 925.1596 | 4 | 1.06 | N/A | Use JIT to generate the type and then instantiate it for running |
| .NET AOT | **872.2287** | 1 | 1.00 | 1732 KB | Use .NET NativeAOT to build the exe that runs the compiled type directly |