16 September 2025
JIT-ing a stack machine (with SLJIT)
From bytebeat to JIT
Recently, I got nerdsniped with bytebeat. I made a simple program for editting it live with visualization . Then I found the expression language quite limted and started making extensions. Half way through, I realized it could just be a “real programming language” ™ which could be edit in a “real text editor” and get hot reloaded on change.
Since I already have that, a new version was developed. It looks something like this:
A long the way, I noticed that the CPU usage was a bit high. While it is nothing my monster of a desktop can’t handle, it would be a problem on smaller devices . So I finally have an execuse to explore JIT compilation. And this is the result.
While this post is about JIT’ing the uxn machine, a VM for a stack-based language, a lot of techniques are transferable to other languages. After all, many languages also target a stack machine under the hood.
The plan
Currently, to execute any bytecode, I’d call: buxn_vm_execute . If JIT is truly magic, it should be a drop-in replacement: buxn_jit_execute .
Just like everything else, I have never written a JIT compiler before but intuitively, it should work like this:
... continue reading