Inspiration
We were enamored by how funny the esolang brainf*** was, and, knowing it was turing complete, we decided to abuse that knowledge.
Hello world in BF: our backend language
++++++++++[>+++++++>++++++++++>+++>+<<<<-
]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.
+++.------.--------.>+.>.
What it does
We wrote a collection of compilers that in the end, writes an equivalent program in brainf*** from our own high-level language. The amount of steps in-between, however, obfuscates our project into a hilarious mess.
fn putcharln(ch: char) -> void =
do
putchar(ch);
putchar('\n');
end
in
do
putchar('H');
putchar('i');
putcharln('!');
end
The program above, in our language, gets compiled to...
[-]++++++++++++++>>>[-]<<<>>>++++++++++++++<<<+*[-]&*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++&*.&*[-]&-+*[-]&*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++&*.&*[-]&-+*[-]&*+++++++++++++++++++++++++++++++++&+*[-]&*+&*?&>[-]<>>>>[-]<<<<*[&>>>>+<<<<>+<*-&*]&>[<*+&>-<>]<*[-]&-+>[-]<*[-]&>>>>[<<<<*+&>+<>>>>-<<<<>>>>]<<<<>[<>>>>+<<<<>-<>]<+>[-]<*[-]&>>>>[<<<<*+&>+<>>>>-<<<<>>>>]<<<<>[<>>>>+<<<<>-<>]<>[-]<>>>>>>>[-]<<<<<<<*[&>>>>>>>+<<<<<<<>+<*-&*]&>[<*+&>-<>]<*[-]&->[-]<>>>>[-]<<<<*[&>>>>+<<<<>+<*-&*]&>[<*+&>-<>]<*[-]&->[-]<>>>>*[-]&<<<<*[&>>>>*+&<<<<>+<*-&*]&>[<*+&>-<>]<*[-]&-+>[-]<*[-]&>>>[<<<*+&>+<>>>-<<<>>>]<<<>[<>>>+<<<>-<>]<>[-]<>>>[-]<<<[>>>+<<<>+<-]>[<+>-<>]<>>>+<<<+>[-]<*[-]&>>>>>>>[<<<<<<<*+&>+<>>>>>>>-<<<<<<<>>>>>>>]<<<<<<<>[<>>>>>>>+<<<<<<<>-<>]<>[-]<>>>>[-]<<<<*[&>>>>+<<<<>+<*-&*]&>[<*+&>-<>]<*[-]&-+>[-]<*[-]&>>>>*[&<<<<*+&>+<>>>>*-&<<<<>>>>*]&<<<<>[<>>>>*+&<<<<>-<>]<+>[-]<*[-]&>>>>>>>[<<<<<<<*+&>+<>>>>>>>-<<<<<<<>>>>>>>]<<<<<<<>[<>>>>>>>+<<<<<<<>-<>]<*!&*[-]&-+>[-]<*[-]&>>>[<<<*+&>+<>>>-<<<>>>]<<<>[<>>>+<<<>-<>]<+*[-]&*&>[-]<>>>>[-]<<<<*[&>>>>+<<<<>+<*-&*]&>[<*+&>-<>]<*[-]&->[-]<>>>>>[-]<<<<<*[&>>>>>+<<<<<>+<*-&*]&>[<*+&>-<>]<*[-]&->[-]<>>>>[<<<<>>>>>+<<<<<>+<>>>>-<<<<>>>>]<<<<>[<>>>>+<<<<>-<>]<+>[-]<*[-]&>>>>>[<<<<<*+&>+<>>>>>-<<<<<>>>>>]<<<<<>[<>>>>>+<<<<<>-<>]<>[-]<>>>>[-]<<<<*[&>>>>+<<<<>+<*-&*]&>[<*+&>-<>]<*[-]&-+>[-]<*[-]&>>>>*[&<<<<*+&>+<>>>>*-&<<<<>>>>*]&<<<<>[<>>>>*+&<<<<>-<>]<*.&*[-]&-+*[-]&*++++++++++&*.&*[-]&-->[-]<>>>[-]<<<*[&>>>+<<<>+<*-&*]&>[<*+&>-<>]<*[-]&->>>>>>>[-]<<<<<<<
How we built it
We implemented multiple layers of languages that slowly built up enough abstraction to implement our high level language. First we implemented a superset of BF called "How?", and then we created an assembly language called "Why?" which compiles to "How?". Finally, we created our high level, C-like language called "What?" which compiles to "Why?" assembly (which is compiled to "How?" in turn).
Challenges we ran into
(Adam McDaniel) I haven't had enough caffeine. I got two hours of sleep, and I was so tired I barely had motivation to do things.
(Vicky Chakpuang) I have never written in C before working with my team and only had a rudimentary understanding of pointers in C++. Additionally, I attempted to write a program equivalent to my C template file in Adam's language (Free), which, in his own words, is terrible. It was my first time working with someone else's project.
(Logan Wrinkle) Despite my best efforts, we delivered our project on time and as expected (I like to derail Adam). Also, I spent a lot of time trying to understand this, which was especially difficult due to perpetual sleepiness.
Accomplishments that we're proud of
(Adam McDaniel) I am very proud that we were able to implement a C-like language with a simple type system to compile to brainf*** in under twenty-four hours. It's a huge milestone.
(Vicky Chakpuang) I'm astounded this works. I'm really happy to have helped finish something in such a short amount of time, especially with my personal track record (lol).
(Logan Wrinkle) I have always believed that the universe was deterministic, and witnessing such a feat has convinced me that there must be magic that can't be explained by logic.
What we learned
(Adam McDaniel) Brainf*** is really fun. Writing compilers is really fun. Hackathons are really fun.
(Vicky Chakpuang) I finally learned what a compiler looks like and how to write one. It turns out, low-level programming can also be super fun once you get the hang of it! Also, my friends have good taste in music.
(Logan Wrinkle) I learned how brainf*** worked by comparing it to a turing machine. Compilers are magic, and we are wizards.
What's next for TF
We want to implement "Where" into the process...somewhere. We need to make it even more obtuse.
Log in or sign up for Devpost to join the conversation.