Skip to content

izabera/bf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 

Repository files navigation

bf

A brainfuck interpreter (a jit compiler to bash) written in bash

FEATURES

  • EOF = 0
  • 2^64-1 cells to the right of the start position (can be easily changed to start in the middle but it's slower)
  • 8-bit unsigned values in cells
  • times itself if the environment variable TIMES is found
  • prints the compiled code if the environment variable PRINT is found
  • pretty prints the brainfuck code if the environment variable PRETTY is found
  • removes as much dead code as possible if the environment variable DEADCODE is found

OPTIMIZATIONS

  • Pointless code is removed
  • Multiple increments/decrements of value and pointer are merged together
  • Clear loops ([-] and [+]), possibly followed by increments/decrements, are reduced
  • Shifted increments/decrements (>>>>++<<<<, <<----->>...) are reduced to a single instruction
  • Multiplication loops ([->+>++>+++<<<]) are reduced to a single instruction (unless they clear a cell, in which case they're converted into an if + that instruction)

Optimizing scan loops ([>] and [<]) doesn't make sense in bash

TODO

  • Nested loops
  • Precompute tape
  • moar

USAGE

bf filename-of-your-bf-program
bf -c 'your-bf-code-here'

BUGS

It's extremely slow compared to anything that compiles to C or to assembly.

That said, it's probably faster than many interpreters written in "faster" languages.

CONTRIBUTORS

  • elliott
  • gniourf

About

a brainfuck interpreter written in bash

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages