It has been a few weeks since the last devlog. I took a break for like 2 weeks around Easter holidays to relax and enjoy the time off. Since then, I have been making some progress on the compiler.
Progress on Types #
The first thing I worked on after my break was codegen for type constructors. It took a bit to click on how they should work. The LLVM codegen generates a hidden this pointer as the first parameter for constructors so that I can decouple the memory allocation from the initialization.
The constructor for a type with one field for example would look like this:
%Number = type { i32 }
define void @Number.new(ptr nonnull %this, i32 %para) {
entry:
%value = getelementptr inbounds nuw %Number, ptr %this, i32 0, i32 0
store i32 %para, ptr %value, align 4
ret void
}
The GetElementPtr instruction loads a pointer to the field and the Store instruction sets the data from the constructor parameter.
The next task after this was methods and field access, which also works now. After that, I enabled the LLVM Test project and worked on getting more and more tests passing.
Bugfixes #
I noticed that the order independent declaration still didn't work as expected, so I had to make some changes to the type checker. It now collects all names first and then works through the function and method bodies. This seems to work great so far.
I also had to fix some parsing bugs for member access, the following code wasn't passing the parser test yet:
type Number(value: i32)
{
value := value
def clamp()
{
if .value < 0
.value = 0;
}
}
Currently all of the 208 parser and 208 type checker tests are passing now, which is really nice!
The LLVM tests are at 183/208 passing and 25/208 skipping.
First contributor #
Shoutout to Caracal's first contributor Gipson62, check out his language Atlas77 at: https://github.com/atlas77-lang/atlas77
What is next #
Next I'm working on finally using CaraReport for compiler diagnostics. I didn't work on diagnostics yet because getting codegen further along was more important to me than integrating the library.
Another task that I'm gonna work on next, probably after compiler diagnostics, is to split up the current codegen into lowering to an IR layer and from there do the codegen. This should make working on the compiler a bit easier and allow me to add optimizations in the future.
Armin