Tech News
← Back to articles

Nimony (eventually Nim 3.0) Design Principles

read original related products more articles

Nimony: Design principles

2025-05-03

Minor edits: 2025-05-10

Nimony is a new compiler for a variant of Nim which will become Nim 3.0, eventually. However, Nim is a big language so replicating what it does will take its time.

While we wait for this to happen, it turns out Nimony implements a streamlined, beautiful language useful in its own right! This article aims to describe this language here.

Following Nim's evolution, we aim to support hard real-time and embedded systems with a (mostly) memory safe language. The primary reason for the choice of this domain is generality: If you can run well on embedded systems you run well on everything else.

WCET ("worst case execution time") is an important consideration: Operations should take a fixed amount of time and the produced machine code should be predictable. This rules out just-in-time compilers and tracing garbage collectors. The primitive types like int and char directly map to machine words and bytes. Complex types are formed without indirections: An object with fields a, b: float takes up 2 * sizeof(float) bytes and is inlined directly into a stack frame or an embedding structure. (This is nothing new, Nim 2 does all of that already.)

Automatic memory management

Automatic memory management (MM) is crucial for safety: If memory is not freed explicitly then it cannot be used after it has been freed! There are other solutions that offer both explicit MM and safety but Nim focuses on concise code. Implicit is good.

Like Nim 2.0, Rust and C++, Nimony offers scope-based MM based on destructors and move semantics. Unlike Nim 2.0 the plethora of mm switches is gone, only mm:atomicArc is offered. There is a novel cycle collection algorithm in development but it's unclear if or when it will be ready for production. In any case, objects involved in potential cycles need to be annotated with the new .cyclic pragma, as .acyclic is the new default.

... continue reading