Accessibility

Bunch of Xmas news

Krzysztof Wodnicki, 23 December 2024

Merry Christmas and a happy New Year!

Holidays are coming and it's the perfect opportunity to share some pleasant news with you.

Newsletter

Firstly, you’ve been able to join our newsletter for some time now. Unfortunately, due to some technical difficulties we haven't posted anything there yet. We managed to fix this issue and the first news should be out around the same time this post goes online.

The Duckling subreddit

We recently launched this blog. To further engage and build our community we are launching a subreddit as well. Not only will this be a place to discuss the language, compiler and VM, but also to comment on the content posted on the blog. We want every blog post to have a corresponding thread on the subreddit for you to give us feedback and engage in meaningful discussion.

We kindly encourage you to join and help us build the community!

First fully compiled Duckling program

Another thing we have to share with you is the first fully compiled program written in Duckling!

fun main() = {
  return;
}

Those of you that have some experience with programming may notice that it.. does nothing? Yes, exactly. The program defines its main function, which returns an empty value - that's not particularly impressive. So why are we making a big deal out of this? Although the program itself doesn't do much, the compiler does. Our team develops the compiler in a way that will allow easier introduction of new language elements and won't require too much refactoring in the future. That is why so far we've been mostly focused on the early stages of compilation. Those stages are when most of the heavy lifting is done.

What does the compiler do?

Since, as mentioned above, the early stages of compilation got all the love, one may ask: are they done already? What happens during these early stages? And what stages even are there?

Compiler architecture

Simplified compiler architecture schema

Parser

The compilation process starts with scanning the module directory. In this directory, the main module file is found and parsed to the Parser Syntax Tree, a.k.a. the PST — a tree-like structure that distinguishes elements of the code such as functions, expressions, statements or declarations. Similar structures are usually called Abstract Syntax Trees in other compilers.

HELIoS

Next, the PST is processed by the HELIoS module (the name stands for "Holistic Examination and Logical Inference of Semantics). The main function is found and compiled to HOUT intermediate representation (HELIoS output).

HELIoS performs a significant portion of semantic analysis, i.e. it interprets the actual meaning of the code, catches various errors, and generates a representation of the code which is simpler and closer to machine code. HELIoS has many responsibilities, but among others, it:

  • finds the declarations of the variables, functions and other elements of the code,
  • matches names with their definitions,
  • identifies all symbols' types and performs type checking,
  • resolves macros and does compile time evaluation,
  • instantiates generic types and functions.

HELIoS produces HOUT representation, which can be divided into HUs (HOUT units). An HU represents a connected code fragment such as a function, class, namespace, or even an entire module.

MIR and LIR

In the next step, all HUs are compiled into MIR (Middle Intermediate Representation). In this stage, destructor calls are inserted and move semantics checks are performed. It is likely that in the future more checks will be added to this phase. MIR is further compiled to LIR (Low Intermediate Representation). LIR's purpose is to provide a smooth transition to various backends.

LLVM

At the moment, our main backend is LLVM, but in the future we aim to support another very important one, our own virtual machine (you will certainly get to read more about it soon).

The compiler emits LLVM modules corresponding to all the compiled HUs and performs LLVM optimizations. Finally, at the end, we get an executable file.


Now this sounds much better than a program that doesn't do anything!

Meet the compiler

This short summary of compiler design certainly doesn't answer all your questions, so to feed your curiosity we give you the last of today's presents — with the beginning of the new year we are starting a new blog series called Meet the compiler.

It will be the first series dedicated to sharing more details and technicalities of our work. As the name suggests, this series will focus on the compiler and related topics.

Best wishes from the DuckType team

We hope you find today's news interesting and that you will keep following our project's progress. We again invite you to join our newly opened subreddit and await posts from the new Meet the compiler series.

Meanwhile, we wish you a merry Christmas and a happy New Year!