Merry Christmas 🎄
At about 1 am christmas morning, I "finished" credence.
Five months. If you subtract the hours of my work organization, you can see exactly when I started on the backend in my GitHub contribution graph:
Credence has been the culmination of a lot of professional and hobby work since the idea was first conceived. The first commit in the parser is about 7 years old. Since then, I've designed languages and built compilers at my workplace.
It is my Magnum Opus
As of last night, I am wholly content with the machine code it generates for x64 on Linux, and BSD. I will leave ARM64 as a separate, future project.
The final test was the translation of switch control structures from my IR, the JMP_E ITA statement.
If you're interested in what the machine code looks like, you should peek at the test suite. The code coverage is impressively exhaustive, with about 80% of all functions and lines covered, according to llvm-lcov.
As I begin to reflect, by far the most challenging section was designing the Intermediate Representation. Unlike other parts, its design was purely academic - there is no specification to follow. The last time I was in this position was when I needed to re-create left-recursion in a PEG grammar for work, for which I needed a Microsoft paper to complete.
I am very thankful for this lecture at Stanford - it gave me a lot of inspiration. Here is a snippet of the IR for the switch program above:
__main():
BeginFunc ;
LOCL x;
LOCL y;
x = (10:int:4);
_L2:
_t5 = x >= (5:int:4);
IF _t5 GOTO _L4;
_L3:
y = (10:int:4);
_L1:
LEAVE;
_L4:
_t6 = CMP x;
JMP_E _t6 (10:int:4) _L8;
JMP_E _t6 (6:int:4) _L16;
JMP_E _t6 (7:int:4) _L18;
...
...
...
_L18:
x = (5:int:4);
GOTO _L17;
EndFunc ;
I have learned that regardless of the size of your compiler or interpreter, you should choose a good IR for your project's size. It makes the difference.
I am going to take a break and spend some time in the mountains. Next time around, I want to work on something much closer to hardware - I was thinking an audio interface and its drivers.
Until then 🤘