BrainflipKit

main

An overly-underengineered brainf**k interpreter in Swift — moved to https://codeberg.org/kaascevich/brainflipkit
kaascevich/BrainflipKit

BrainflipKit

An overly-underengineered brainf**k interpreter in Swift

Overview

BrainflipKit is a Swift command-line app that interprets brainf**k programs.

If you're here, then chances are you already know what brainf**k is (if not, here's a quick and dirty reference). So instead of dwelling on the basics, I'll go over what makes this interpreter marginally unique.

  • Full Unicode support. That's just what happens when you're using Swift.
  • The cells are 32-bit instead of 8-bit, due to the aforementioned Unicode support. Most well-written brainf**k programs shouldn't be heavily affected by this.
  • The tape is infinite in both directions.
  • The end-of-input behavior is customizable -- you can ignore EOI, set the cell to 0, set the cell to its maximum, or throw an error. (Why you'd throw an error on EOI, I don't know, but the option is there for the taking.)
  • Cell wrapping can be disabled (by throwing an error).
  • Some relatively basic optimizations are performed, including:
    • Condensing repeated instructions
    • Merging +/- and </> instructions (and removing pairs that cancel each other out)
    • Replacing [-] with an instruction that directly clears the cell
    • Replacing copy loops and multiplication loops with a dedicated instruction
    • Replacing scan loops ([>], [<<<], etc.) with a dedicated instruction
  • There are some extra instructions that can be enabled if you wish.

Description

  • Swift Tools 6.1.0
View More Packages from this Author

Dependencies

Last updated: Thu May 15 2025 12:12:20 GMT-0900 (Hawaii-Aleutian Daylight Time)