Higgs has Exceptions
I just finished implementing exceptions in the Higgs interpreter, complete with support for the finally block and optional catch clauses. The fact that Higgs is an interpreter and tracing JIT instead of a method-based compiler definitely made this process somewhat simpler. The interpreter uses a calling convention where all arguments are pushed on the stack and each stack frame has a fixed size, making stack unwinding very easy. The tracing JIT won’t have to do any special treatment of exceptions: it will simply fall back to the interpreter.
Since my interpreter uses an intermediate representation built on basic blocks and sequences of instructions, I had to compile finally blocks in-line at every point where they would be run, which meant handling a multitude of corner cases. I believe this complexity reveals that finally blocks are a fundamentally “unnatural” language feature. I say unnatural because the control flow involved is convoluted and unintuitive to programmers. Preventing a return statement from executing seems like the kind of black magic that simply shouldn’t be possible.
I’m quite happy to have exception support as I believe it will make debugging the Higgs runtime and standard libraries (both written in extended JS) much easier. Now that this is done, I will be moving towards one of the biggest pieces of the puzzle: implementing a garbage collector for Higgs. Since the focus of my research isn’t garbage collection, I will implement a simple and minimalist stop-the-world copying GC. Having previously implemented a similar GC for Tachyon, I anticipate that I should be able to complete this task within approximately two weeks. The task will be sped up by the automatic generation of code to visit heap-allocated objects.