A small compiler I am working on to learn more about Rust, Compilers, LLVM and mostly have fun.
Very deep lore easter egg reference to PoSharp.
Although I am interested in both Compilers and languages somewhat, I am not qualified enough in any way to make something even remotely useful (or usable even). My only experience with (an interpreted) language design is a university course which I just barely passed.
This plus the fact that I don't have a specific use case for this language means that I will most likely not focus too much on the language itself but rather on some accompanying utility that would come with a language.
I want to experiment with syntax highlighting, nice and helpful error messages, perhaps some interoperability with PoSharp and maybe even a language server.
Now that I got the fact that you really shouldn't take this project seriously as a learning or a good practice resource, I'll showcase some of the stuff currently present in the language.
Also worth mentioning that I decided to not use any dependencies except for a Parser Generator called LALRPOP as I would rather do most stuff myself rather than accelerate the development process since I don't care as much about the end result anyways.
Right now the idea is to create a simple, statically typed language with numeric and boolean primitives. In the future, I might add control flow stuff (ifs, fors etc) but for now, I want to keep stuff simple.
As of writing this, the only thing fully implemented is basically the following:
// Comments
let x = 41;
let y = 1 + x; // Nested expressions don't work yet
// Printing
print(y); // 42Basic arithmetic isn't yet fully implemented (only addition works so far) and neither are booleans. Right now, the main bottle-kneck is my non-existent knowledge of the LLVM Intermediate Language + deciding when to stop refactoring my code.
One of the main goals of this project is to experiment a lot with error reporting (and later on perhaps even provide suggestions for fixing them through a language server).
As you may have noticed from the previous image, I am also working on syntax highlighting.
Right now I'm working on a Visual Studio Code extension (the rustsharp folder) which you can
try out locally by running UpdateHighlighting.ps1 (if you're not on windows just read the file,
it's 2 lines long).
I think that one of the interesting ideas is the Read Evaluate Program Loop which instead of interpreting as you'd probably expect, actually gives you back (hopefully) valid LLVM IR. This should in theory work properly incrementally and you can see it working here
The compiler is a plain old Rust project. Just
running cargo run will probably spin up the REPL. I say probably because I also set it up
so it can read code from this code file and I just toggle comment
the last line in my main file.
To actually run the generated IR, you need WSL (if on windows) as well as LLVM installed.
I remember having some issues getting the LLVM compiler to work locally, I think in the end
running sudo apt-get install llvm solved it but not sure. If you are having issues with this
open an issue and I'll try to help.
The compiler itself doesn't currently output the IR anywhere so I just copy paste it to
this file. I also have a small run script in the folder
to compile and execute it.
In the end, the code ended up being mostly mine (evident by how bad it is) for the most part but a few people helped me get started on the project or gave me some ideas through the content they created and I wanted to mention them;
- Seán Kelleher's Writing a Programming Language
- Immo Landwerth's Building a Compiler
- Casey Muratori and Jonathan Blow who both made me want to leap out of my comfort zone and try a different aspect of programming.
I will perhaps blog about this at some point.

