Tuesday, October 9, 2018

Actor-based programming language called "X"


Though there have been no blog posts on the actual development on ttOS, I have been doing some off-and-on work on it. There have been too many changes for me to write them all down, but I can show you this screenshot of the "changelog" output:

It looks very different than the last blogpost, where ttOS was still in text mode, so a lot has changed both visually and internally. I swapped out my old hand-crafted heap allocator for Doug Lea's dlmalloc heap allocator, and received a tremendous speed increase with it.

Another major step in the direction I want to take this project is the X programming language. The version you see in the screenshot above has a fairly complete implementation of my compiler and VM. Actually, the command line interface is implemented using X.

So, what is X?

I am a very big fan of the actor model. Actually, I use it in one of my bigger projects with which I hope to one day earn some money. What it boils down to, is that you can spawn so-called actors, which are autonomous, isolated "mini-processes". Each actor has its own mailbox, and each can send and receive messages to other actors. An actor's state is stored in the context of itself, so the state can only be modified by sending it a message. This has a tremendous positive effect on potential concurrency problems like race conditions!

Another benefit is that the actor model allows for very sophisticated error handling: the actor system (i.e. the collection of all actors within a certain system) is made up of a single tree. Each actor (except for the root actor) is always a child of another actor. Through a process called escalation, a child actor notifies the parent of any exceptions that occur within its execution, and the parent can decide which course of action to take. Some strategies are to simply restart the actor (and its state), or to escalate the exception up to the parent of the parent.

If you want to know more about the actor model, you can visit the Wikipedia article, or the Akka project (which I use the .NET port of, Akka.NET).

Code Example

Of course, you want to see how the code looks. This is the code for the console, which is an actor in itself. It receives commands from the terminal widget, and then executes it. It's still pretty rough, but already works very nicely.

The dollar commands you see are called "DolDoc routines". I got inspired by Terry Davis' TempleOS, and decided to implement a subset of it in order to add some graphical spunk to the console.

What's next?

Currently, I am working on a garbage collector. Right now it only ever allocates objects, but never frees them. Fun for now, but not so fun when it is going to actually do something in the future. And writing a garbage collector is fun anyway :).

I also want to add introspection and attributes/annotations to the language.

Stay tuned for more. Don't know when though.

No comments:

Post a Comment