Skip to content

otherfunc/otherfunc-brainfuck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

otherfunc-brainfuck

Brainfuck interpreter with pre-compiled bracket map and configurable instruction limits.

Implementation

  • 8 standard commands (> < + - . , [ ]), all other characters are ignored
  • 33,000-cell tape of u8 values with wrapping arithmetic
  • Cells 0–29,999: normal workspace; cells 30,000–32,004: memory-mapped I/O region
  • Pre-compiles a HashMap<usize, usize> bracket map for O(1) jump lookups
  • Default instruction limit: 10,000,000 (configurable via with_instruction_limit())
  • Detects unmatched brackets at compile time before execution begins

Memory-Mapped I/O

The tape region from cell 30,000 onward provides HTTP, KV storage, and environment variable access without any new commands:

Region Cells Purpose
URL / Key buffer 30,000–30,499 Write URL or KV key here
Body / Value buffer 30,500–30,999 Write POST body or KV value here
Response buffer 31,000–31,999 Read response data here
IO_STATUS 32,000 HTTP status or success flag
IO_METHOD 32,001 1=GET, 2=POST, 3=KV_GET, 4=KV_SET, 5=KV_DEL, 6=ENV
IO_RESP_LEN 32,002–32,003 Response length (big-endian u16)
IO_EXEC 32,004 Write non-zero here to trigger the I/O operation

Install

cargo install --path .

Usage

# Inline code
bf "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++."

# From file
bf -f program.bf

# Piped input (for , commands)
echo "hello" | bf ",+.>,.>,."

As a Library

use otherfunc_brainfuck::BrainfuckInterpreter;
use otherfunc_core::Interpreter;

let mut bf = BrainfuckInterpreter::new();
let output = bf.execute("++++++[>++++++++++<-]>+++++.", "").unwrap();
assert_eq!(output, "A");

Tests

cargo test -p otherfunc-brainfuck    # 19 tests

About

Brainfuck interpreter with memory-mapped I/O

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages