arrc

I wanted to see just how small I could make a self-hosting compiler and arrc was the result. I wrote a 100-line bootstrap compiler in C (targeting x86 assembly), and then a self-hosting compiler in arr itself. The self hosted version is a bit longer, and totally unreadable, but it was a lot of fun to make.

The language is stack based and has some limitations that make it fun (or not, depending on your attitude) to use. For instance, you can only use 26 variable a-z. This was, of course, to make the compiler easier to self-host, but it also has the nice benefit of making anything written in the language totally unreadable.

Here’s some example code from the readme:

. # . pops from the front of the input array
, # , writes the last thing to the front of the output array

.A # a capital letter stores the last thing in that variable
a # a lowercase letter gets the value from that variable

:B # makes a label called B

@D # @ calls D

\A # \ makes a literal char
? # = compares the top two things on the stack
=F # jumps to F if the comparison is true

123 # numbers are literals
A # store 123 in a
2 1 - # == 1

:D # d label
; # ; returns

2 & + # & duplicates the top item on the stack

\A \B \C \D 1 ! , # prints C
# !:
# let n = the top item on the stack
# duplicate the n-th value on the stack (starting at 0)
# and put it on the top of the stack

The repo is available here.

Leave a Reply

Your email address will not be published. Required fields are marked *