jc Compiler Development Log #1: February 2020
After the last development log set the scene, its time to start digging into the actual development of the compiler. I did a lot of work this month, and while the language is not as developed as I’d like it to be in some areas it is much further developed in others. I should also clarify this post is not in chronological order of feature development. Without further ado, let’s jump in!
Variables and Arrays#
Variable declaration and definitions are in for signed integer and floating point types. I am actively working on the other types but it does require some modification for the future. Honestly this isn’t that impressive but I figured I should start with the basics and work up. Arrays for these types have also been implemented. There is no way to initialise them without looping through them though, which is a task for next month. The code block below shows these features in the language as it is right now.
i32 i;
f16 f = 1.0f;
i32 arr[12];
Function Declarations and Definitions#
Function declarations and definitions are in a fairly good state right now. Given the design of the language to work similar to other modular languages such as Python, Java and C# it may seem like a strange choice but this enables another feature I will talk about later in this post. The code block below shows the current syntax for both of these things.
i32 printf(i8 *str);
i32 add(i32 x, i32 y)
{
return x + y;
}
Pointers#
Raw pointer types are working in the language. At the moment they haven’t been tested as thoroughly as I’d like but they are working. The syntax is the same as C/C++ for the moment but that might change.
i32 *i;
i32 j = 12;
i = &j;
j = *i;
Unary and Binary Operators#
Basic unary and binary operators have been implemented. I should point out that these currently only work consistently on the signed integer type. The systems for this will definitely go through several iterations to fix this and because I do plan to implement operator overloading in some capacity. The last two subsections show unary and binary operator syntax in action.
Branching Constructs#
Branching is now supported in the language through the classic if-else systems. The syntax for this is show below.
i32 x = 1;
if (x == 2)
{
return 10;
}
else if (x == 1)
return 5;
}
else
{
return 0;
}
Looping Constructs#
As of this month two looping constructs are functioning in their most primitive form in the compiler. Two code examples are shown below, the first being a while loop and the second being a for loop.
while (x == 5)
{
x++;
}
i32 x;
for (i32 i = 0; i < 36; i++)
{
x = i;
}
Foreign Function Interface#
The C FFI is in a somewhat working state. It is now technically possible to print things out in the language, although a few more features need to be added before this will be fully usable. That’s all for this month!
We’re off to a flying start with a large chunk of the core language features in place at the end of February, Next month will be all about implementing more of the core features and possibly a few extra bells and whistles. If you want slightly more regular updates on the compiler’s progress I’d recommend following me on Twitter where I post about it semi-frequently. Thanks for reading and see you in the next log!