Catalog PyPI
PACKAGE EXPLORERView in registry

advanced-brainfuck

PyPI

High-performance Brainfuck interpreter with JIT acceleration, library imports, and interactive REPL

Versions collected1
Direct dependencies7From release 2.2.0
Last observed20 Oct, 19:57 UTC

README

Version 2.2.0 documentation

advanced-brainfuck

advanced-brainfuck

A high-performance Brainfuck language interpreter for Python with JIT acceleration, library imports, and an interactive REPL.

Documentation | PyPI | Changelog


Features

  • JIT-accelerated execution — Compiles Brainfuck programs to an intermediate representation (IR) with run-length encoding, then executes via Numba's @jit(nopython=True) for 3-5x speedup
  • Segmented JIT with checkpoints — All programs use the JIT path; I/O operations (,, *, &) trigger checkpoints where Python handles input/output before resuming JIT execution
  • Interpreted fallback — If JIT compilation fails, falls back to interpreted IR execution with full compatibility
  • Library system — Import external .bf files with {libname} syntax; recursive imports supported
  • Interactive REPL — Run brainfuck with no arguments for an interactive shell
  • Python API — from brainfuck import BrainFuck for programmatic use

Quick Start

Installation

pip install advanced-brainfuck

Command Line

# Run a program and exit
brainfuck --command-line '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'

# Run a program from file (recommended for large programs)
brainfuck --command-line -f program.b

# Run a program then enter interactive REPL
brainfuck '+++++++++++++++++++++++++++++++++++++++++++++++++++.'

# Redirect output to a file
brainfuck --command-line --output result.txt '+++++++++[>++++++++<-]>+.'

# Save tape state after execution
brainfuck --command-line --dump tape.json '+++'

# Load tape state, run program, and dump result
brainfuck --command-line --load tape.json --output result.txt --dump out.json '.>+++.'

# Enter interactive REPL
brainfuck

Python API

from brainfuck import BrainFuck

bf = BrainFuck()
bf.execute('+++++++++++++++++++++++++++++++++++++++++++++++++++.')  # prints: 3
bf.execute('[-]')                    # clears cell 0
bf.execute('{p10}*{tochar}')         # imports and prints: |10|
bf.execute('&')                       # prints command history
bf.save_tape('tape.json')            # save tape state to file
bf.load_tape('tape.json')            # restore tape state from file
bf.interpreter()                      # starts interactive REPL

Brainfuck Commands

Standard Commands

CommandDescription
>Increment the data pointer
<Decrement the data pointer
+Increment the value at the data pointer
-Decrement the value at the data pointer
.Output the value at the data pointer
,Accept one integer of input
[Jump forward past matching ] if value is zero
]Jump back to matching [ if value is non-zero

Additional Commands

CommandDescription
{LIB}Import external Brainfuck code from bflib/LIB.bf
*Output all cells with pointer highlighted
&Output command history
helpShow command reference (REPL only)
quit / exitExit the REPL
save [FILE]Save tape state to JSON file (default: tape.json, REPL only)

Library Modules

The bflib/ directory contains 31 reusable Brainfuck modules:

ModuleDescription
sumSum current cell and next cell
subSubtract next cell from current cell
mulMultiply current cell by next cell
mul2Multiply current cell by two
divDivide current cell by next cell
modModulo of current cell divided by next cell
copyCopy current cell into next cell
moveMove current cell to next cell (copy + clear)
swapSwap current cell and next cell
zeroClear current cell (set to zero)
notLogical NOT of current cell
andLogical AND of current and next cell
orLogical OR of current and next cell
eqTest if current cell equals next cell
ifIf current cell is non-zero, set next cell to 1
sqrtInteger square root of current cell
p5Add 5 to current cell
p10, p32, p48, p50, p65, p100Add 5, 10, 32 (space), 48 (digit '0'), 50, 65 ('A'), 100 to current cell
m10, m50, m100Subtract 10, 50, 100 from current cell
tointConvert ASCII digit character to integer
tocharConvert integer (0-9) to ASCII character
newlineOutput a newline character (ASCII 10)
lowerConvert uppercase ASCII to lowercase
upperConvert lowercase ASCII to uppercase

Architecture

Source Code → Import Resolution → IR Compilation → Execution
                                                        ↓
                                               ┌── Segmented JIT ──┐
                                               │ execute_jit()      │
                                               │ via Numba          │
                                               │                    │
                                               │ Checkpoints at:    │
                                               │  , * &             │
                                               │                    │
                                               │ Python handles I/O │
                                               │ then resumes JIT   │
                                               └────────────────────┘
                                               ┌── Fallback ────────┐
                                               │ (JIT compilation   │
                                               │  failure only)     │
                                               │ Python IR loop     │
                                               └────────────────────┘

IR Compilation

Source code is compiled to an intermediate representation with:

  • Run-length encoding — +++++ becomes ('add', 5) in a single operation
  • Pre-resolved jumps — [ and ] targets are computed at compile time
  • Numeric encoding — IR tuples converted to NumPy int32 arrays for JIT

Tape Memory

Cells use a pre-allocated NumPy tape of 65,536 cells (64K) for JIT execution, with a hybrid Python storage model for the REPL:

  • Pre-allocated list of 30,000 integers for indices 0-29,999 (O(1) access)
  • Sparse defaultdict for negative indices (rarely used but supported)

Requirements

  • Python >= 3.13
  • Numba >= 0.58.0
  • NumPy >= 1.24.0

Project Structure

advanced-brainfuck/
├── brainfuck/               # Python package
│   ├── __init__.py          # Public API re-exports
│   ├── __main__.py          # python -m brainfuck entry point
│   ├── core.py              # Core interpreter, compiler, JIT, CLI
│   └── bflib/               # Reusable Brainfuck library modules
│       ├── sum.bf
│       ├── copy.bf
│       ├── mul.bf
│       ├── div.bf
│       ├── toint.bf
│       └── ...              # 31 modules total
├── docs/
│   ├── spec/              # Product & technical specifications
│   ├── adr/               # Architecture decision records
│   └── features/           # Feature specifications
├── tests/
│   └── features/           # Test files
├── pyproject.toml          # Package configuration
└── README.md

License

GPLv3 — See LICENSE for details.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
2.2.03 May 20267

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
nullhack/advanced-brainfuck

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:57 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:0921aaf6d05be47baa89abffa4bedaa5c633ba094a062075dab8eec1896acdc6