Sola - trying my hands on PL
So, here we are, followed the Crafting Interpreters book to some degree and wanting to play around with something new. Sola will be what I work on whenever I find the time.
The (admittedly very ambitious) goals are as follows:
Use the basic ideas of Go
- Super simple to learn and write, meaning
- Simple syntax
- Few concepts to learn
- GC
- Green threads
- Communicate using pipes
Learn from the amazing decisions of Rust
- Sum types
- Explicitness and Safety everywhere
- eg. Strings being guaranteed to be valid UTF8; String iteration being separated into bytes/chars
- Use LLVM as a backend. While this does have the possible downside of compile time, I think, it is a worthwhile trade off for ease of development and runtime speed.
- The kind of syntax (this might just be my preference, but it's my language)
- Lots and lots of small stuff
Sprinkle some of my own preferences in there
- We'll see what exactly this means, but probably where exactly the compromises between all the following lies
- Complexity to implement (very important right now)
- Complexity to write as a user of the language
- Verbosity to write as a user of the language
- Safety
- Performance
- We'll see what exactly this means, but probably where exactly the compromises between all the following lies
Right now, you can follow along with the development on my GitHub. The language is obviously in the very early stages of development, completely missing a standard library, FFI and stack allocation for a start. But it is technically Turing complete, having recursion, mutable variables and loops implemented.
Some of the big decisions that still need to be made include:
- What kind of garbage collection to use
- Likely candidates include:
- Arc everything
- The Boehm--Demers--Weiser garbage collector
- Likely candidates include:
- Stick with LALRPOP or write a manual lexer and parser?
It's now a few days and a few commits later. There are a few new things:
Firstly, I did not stick with LALRPOP and instead rewrote the lexer and parser using Logos and Chumsky, which allowed me to more freely express my grammar without needing to worry about making it LR(1).
For the most part, this worked fairly well, but I struggled a bit with figuring out why generating the parser would cause the stack to overflow. Turns out, I recursively called the expression parser, which was easily fixed by using the recursive
function provided by Chumsky.
After that was fixed, it was quite easy to implement the grammar rules I wanted to add which I wasn't able to in LALRPOP. In particular, supporting both if statements and if expressions.
Using Chumsky also made me look at Ariadne for error reporting. Ariadne allows for very easy, but very pretty error reporting. Right now, Sola barely has any of that implemented, but the basics are there. Span tacking is now implemented by using range<usize>
and having Ariadne convert that to the original source code.
Some very basic errors are also implemented using a custom error type that combines the Span with an error message String.