Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brainfudge Interpreter

A fast Brainfuck interpreter written in Rust. It reads source code, translates it into optimized opcodes, and executes it on a virtual machine.

Optimizations

  • Opcode Folding: Consecutive +/- and </> are collapsed into AddN(n) and ShiftN(n) (zero-net runs are removed).
  • Direct Jumps: Loop brackets are precomputed into JumpIfZero and JumpIfNotZero with absolute targets, eliminating bracket scanning during execution.

Installation

git clone https://github.com/jeffreywangcf/brainfudge-interpreter.git
cd brainfudge-interpreter
cargo build --release

Usage

There are two ways to use the interpreter:

Run a file

./target/release/brainfudge-interpreter <path_to_file>

Example:

> ./target/release/brainfudge-interpreter tests/fixtures/bf/hello_world.b
Hello World!

Interactive Shell

If no file path is provided, the interpreter starts in REPL mode.

./target/release/brainfudge-interpreter

Example:

> ./target/release/brainfudge-interpreter
Interactive Brainfuck REPL
Type Brainfuck code and press Enter to run.
Type `exit()` to quit.

bf> ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
Hello World!
bf> exit()

>

About

A fast Brainfuck interpreter written in Rust. It reads source code, translates it into optimized opcodes, and executes it on a virtual machine.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages