Actor-based programming language "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
actor Console {
	Hashtable commands;
	string currentDrive;
	onStart() {
		currentDrive = "ram0";
		commands = new Hashtable();
		commands.add("help", new HelpCommand());
		commands.add("cls", new ClearScreenCommand());
		commands.add("changes", new ChangelogCommand());
		commands.add("charmap", new CharmapCommand());
		commands.add("hello", new HelloCommand());
		commands.add("reboot", new RebootCommand());
		commands.add("tasks", new TasksCommand());
		commands.add("ruben", new RubenCommand());
		write("$CR$$CR$$FG,GREEN$$TX+CX,\"ttOS " + VERSION + "\"$$FG,BLACK$$CR$");
		write("$FG,GREEN$$TX+CX,\"Copyright (C) 2016-2018, Dennis Seller\"$$FG,BLACK$$CR$");
	@receive(ConsoleCommand msg) {
		if (msg.line.length > 0)
			if (msg.line.startsWith("eval")) {
				var spaceIdx = msg.line.find(" ");
				if (spaceIdx != null) {
					var cmd2 = msg.line.substring(spaceIdx + 1);
			var cmd = commands.get(msg.line);
			if (cmd == null) {
				write("$FG,RED$Command '" + msg.line + "' not recognized.\n $FG$");
			} else {;
	writePrompt() { write("$FG,LGRAY$" + currentDrive + "> $FG,BLACK$"); }
	write(var txt) {
		LogHelper.log("Console", txt);

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.

Show Comments