BitsySwift is a compiler for the Bitsy language implemented in Swift. It is currently the canonical implementation of Bitsy.
Bitsy is a programming language which aims to be the best language to implement when building your first compiler or interpreter. It is a resource for programmers learning about language implementation.
To learn more about Bitsy or to try implementing it yourself, in your favorite language, check out the runnable, test based language specification, BitsySpec.
You can read more about the motivation behind creating Bitsy on the ScopeLift Blog.
This version of BitsySwift has been tested with:
- OS X/macOS 10.11 (El Capitan) or later
- Xcode 8.0
- Swift 3.0
Linux support is currently limited by Swift Foundation but should come eventually.
To 'install' the compiler, simply clone and build the repository. You must have
xcodebuild utility installed.
git clone https://github.com/apbendi/bitsy-swift.git cd bitsy-swift ./build.sh
Once built, you can use the
runbitsy script to conveniently build and immediately
./runbitsy samples/collatz.bitsy # Print the Collatz sequence for 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
runbitsy script currently hangs for Bitsy programs which accept
user input, though the binaries themselves run fine.
bash experts know why?
Alternatively, you may directly use the
bitsy-swift command line utility
directly for additional options:
bin/bitsy-swift --help Usage: bin/bitsy-swift [options] -v, --version: Print the version of bitsy-swift -h, --help: Display bitsy-swift usage -c, --read-cli: Read Bitsy code from the command line, terminated by a '.' -o, --output: Specify a name for the binary output -e, --emit-cli: Emit intermediate compilation to command line -r, --run-delete: Immediately run and delete the compiled binary -i, --retain-intermediate: Retain results of intermediate representation
While Bitsy has been created partially in response to a perceived lack of approachable resources for learning language implementation, there are still some good places to start.
- Let's Build a Compiler; this paper from the late 80's (!) is an excellent introduction to compilation. The biggest downside is the use of Pascal and m68K assembly. While working through this tutorial, I partially translate his code to Swift.
- A Nanopass Framework for Compiler Education (PDF)
- Stanford Compiler Course with Alex Aiken; an advanced resource for learning some theory and going deeper.
Contributions of all types are welcome! Open an issue, create a pull request, or just ask a question. The only requirement is that you be respectful of others.
Please checkout the BitsySpec repo and join the discussion to codify version 1.0 of the Bitsy language specification.