Hello, Orbit

Why I started writing yet another programming language, what I learned from Argon, and where this series is headed.

4 min readOrbit
Read in: Italiano

Orbit is an interpreted programming language with a register-based VM, designed for concurrency, that I’m building from scratch.

import "io"

"Hello world" |> io.print

One of the first questions that comes to mind when looking at a project like this is: why? Why build a programming language from scratch? There are already so many of them, and the ones people actually use aren’t built overnight: they take years.

Usually a language is born to make life easier, to experiment with constructs that don’t exist anywhere else, or to live inside a bigger product: that’s the case with ABAP, born inside SAP to write its applications.

Orbit doesn’t fall into any of these categories and, to be honest, I don’t have a precise answer. Like Argon, the language that came before it, it comes from the urge to experiment and to understand how things work from the inside.

Early attempts: Argon

I think it all started by chance. The year was 2019, I had just changed jobs, and at the time I was really into shells: I wanted to build my own, with a nicer syntax (at least to me) than the ones out there.

While experimenting, though, I realised that the part I found most interesting was the shell’s own language. I remember the first results weren’t great: a small tree-walking interpreter that worked, but was very slow.

Tree-walking interpreter: one of the simplest kinds of interpreter. It runs the program by visiting (“walking”) the syntax tree directly.

That partial result was enough to plant one of those ideas that are hard to ignore: it’s working and I’m having fun, so why stop at a shell? Why not push further and build an entire language from scratch?

That was the question that started it all: a long project, a risky idea. Perfect, as far as I was concerned.

The name

I suspect I’m not the only one, but I can’t start a project without first finding it a proper name. So how did I end up with Argon? I haven’t mentioned it yet, but I’m a chemistry enthusiast: back then I grabbed the periodic table and stopped at the noble gases. Inert, stable: exactly what I wanted from my language. A noble gas as a name seemed like a great idea, so I picked argon.

Never was a name more fitting, though not in the way I’d hoped. Argon comes from the Greek argós, “lazy, idle”, and my interpreter certainly wasn’t known for its speed (ahem, atomic reference counting? More on that in a moment). And argon isn’t entirely inert either: under extreme conditions, it can form a compound. Just like my first attempt, which didn’t turn out to be all that stable. Nomen omen.

Starting over

Argon was a great springboard: it let me experiment a lot, even if not every choice turned out to be the right one. Three in particular:

  • Reference counting in a concurrent system. Every object keeps count of how many references point to it; in a concurrent system that counter has to be updated with atomic operations, which are expensive. On a stack machine, on top of that, the count changes on every push and pop: in practice, all the time.
  • No FFI (Foreign Function Interface). Argon couldn’t call C functions directly: to talk to the outside world you had to hand-write a native wrapper for each one.
  • Closures, which weren’t implemented entirely correctly.

None of these problems could be solved with a patch: fixing them meant rewriting almost everything. At that point, knowing where I’d gone wrong and how to put it right, the most sensible choice was to start over.

What Orbit wants to be

Can we say Orbit is Argon’s future? More or less: it’s the attempt that worked, after a lot of experiments. Mind you, that doesn’t mean Orbit is perfect. It has its own problems too, but this time they’re the kind you can fix with a patch (and I’m working on it).

Over time the idea found a direction: a language that’s easy to read and write, with native support for concurrency. Argon is still its main inspiration: Orbit inherits many of its concepts, which I had in turn borrowed from other languages, including Erlang, Rust and Go. Ideas I liked and wanted to find all in one place.

And Argon’s three problems? Orbit was also born to answer them: the VM is register-based instead of stack-based, memory is handled by a generational garbage collector, C functions are called directly with native func, and closures were redesigned from scratch.

What’s next

Well, if you’ve made it this far, it’s time to let you in on the plan. This is the first in a (hopefully long) series of posts where I’ll tell you how a programming language is built, and how Orbit tackled the problems it ran into along the way.

We’ll talk about:

  • how to build a compiler, from the scanner to the bytecode;
  • how a register-based VM works;
  • how to write an event loop;
  • how to build a memory allocator from scratch.

See you in the next post.