Tags: Oli-Nat Documentation Oli-Nat Introduction Docs
import banner from ’../../assets/Images/Oli-Nat-Logo-Banner.png’
A small, statically typed language you can run in your browser, and read from source code to bytecode.
Oli-Nat is a hand-built programming language written in pure C. Source code travels through a full pipeline (scanner, Pratt parser, AST, type checker, bytecode compiler) and runs on a custom stack-based virtual machine with its own garbage collector. Every stage is written from scratch, and every stage is documented. I wrote these docs, and this language, to showcase my passions for low-level programming and learning in general.
#pullf io
class Player
{
make int health = 100;
make string name = "hero";
make empty takeDamage(int amount)
{
health = health - amount;
}
}
make Player p = Player();
p.health = p.health - 10;
println(p.health);
make int x = 10;
make string greeting = "hello";
if (x > 5)
{
make int y = x + 1;
println(y);
}
for (make int i = 0; i < 5; i++)
{
println(i);
}Source --> Scanner -> ASTCompiler --> TypeChecker --> ByteCodeCompiler --> GarbageCollector --> VM
-
Small enough to understand.
A two-pass compiler, a static type checker, a virtual machine, a mark-and-sweep garbage collector, closures, and classes, and more, all in under 7,000 lines of C, excluding test case files. When I first became interested in language hacking, I was daunted by very large languages. There, I made Oli-Nat as a language that is meant to be read, and the documentation walks through the implementation alongside the features, documenting implementation and personal understanding.
Fun cloc stats: ASTcompiler.c ~ 1,394 lines, vm.c ~ 1,104 lines, typechecker.c ~ 938 lines -
Portable
Oli-Nat depends on nothing but a C compiler. No LLVM, no parser generators, no external libraries. It builds on
Linux, macOS, and Windows, and the resulting executable is small and self-contained. See the Installation Guide Doc -
Hackable
Because the whole implementation is plain, readable C, adding a feature is approachable if you know a little C. New native functions take a few lines, and each pipeline stage lives in its own file. Oli-Nat is open-source under the MIT license, and issues and pull requests are welcome.
-
Oli-Nat is teachable
In tandem to the flexible compilation options, and the customization, this page includes a code playground, which allows you to write Oli-Nat code inside the browser without compilation. Allowing you to get a good feel for the language, see the syntax, and even mess around with the program!
Acknowledgments:
- Oli-Nat’s VM design is inspired by Robert Nystrom’s Crafting Interpreters; Oli-Nat extends it with a separate AST stage, static type checking, typed arrays, a fleshed out stdlib, and more.
- Users:
- Mxnnyy
- MXD-K1
- Anubhavaanand
- Voyagerroc
- Have all contributed in part to the language, be it adding testcases, bug fixes, or adding to to the stdlib, a huge thank you to them all!