Quxlang IRv2

It’s been a while since I posted the last update. I have been, for lack of better words, busy. Unfortunately moving is chaotic and yada yada. So is Quxlang still in development and what’s the progress look like? The answer is yes, but development isn’t as far along as I’d hoped earlier. Now, I’m not too concerned, but the main thing that delayed me is the sad realization that I needed to rewrite the Quxlang VM IR format. Broadly speaking, the compiler worked in several stages:

  1. Source code files, are aggregated into a
  2. Source bundle which a collection that represents the entire source tree as one atomic snapshot, which is translated into an
  3. Abstract Syntax Tree, which is a graph structure of the syntax of the program, which is then converted into,
  4. Quxlang VM IR, which is a read-expression and store operation based IR, which is converted into
  5. LLVM IR, which is the beginning of the backend, which is converted into
  6. Object Code, which is linked to create
  7. Binary output

The problem started arising at step 4. It quickly became very obvious that this design pushed way too much work onto the AST -> Quxlang IR translation regarding handling of constructors and destruction. It also made the LLVM IR generator do too much work when dealing with these things, because I had pushed a lot of the control flow into the LLVM layer. (example, vm_while)

After some thought, I decided a new IR format was needed that works based on slots. The new IR format is both higher and lower level at the same time. It has low level control flow (jump, branch, and return) whereas things like for and while loops are implemented at the IR generation level. On the other hand, value lifetimes are now implicit during block transitions, so I can avoid generating direct destructor calls (this makes exception handling much simpler).

Another problem with the old codebase was that I couldn’t generate code for freestanding expressions (this was a blocker for INCLUDE_IF), they had to be inside a function. A (slow) rewrite, and this problem is now solved.

The IR being generated looks correct now, so the next steps are to rewrite function generation (which is relatively trivial, compared to expression generation) and the LLVM layer. After that, constexpr support needs to be added, which shouldn’t be too difficult with the new IR layer.

When those things are done, it will basically come down to testing the generated code, and then we it seems solid, we can have the 0.0.1beta release.

Ideally, this would be about a week of work, unfortunately this is unpaid work in my free time and so I really have no idea when I’ll have enough free time and motivation to finish it. 😀

Leave a comment