Get the latest tech news

Fitting a Forth in 512 bytes (2021)


Software is full of circular dependencies if you look deep enough. Compilers written in the language they compile are the most obvious example, but not the only one. To compile a kernel, you need a running kernel. Linkers, build systems, shells. Even text editors, if you want to write the code instead of just downloading it. How do you break this cycle? Since the bootstrapping problem has first come to my attention, I've been drawn to this unique area of software engineering. Not out of fear that someone would try to implement a trusting trust attack, but simply as an interesting challenge.

As it turns out, a special compression scheme that can only handle this one repeating pattern is worth it, as long as you combine it with the following observation: NEXT is almost always followed by the dictionary entry of the next primitive, of which the link field is predictable. It detects both spaces and null bytes in one fell swoop, but also also turns off the bit that differs between uppercase and lowercase letters, which allows handling both cases of hexadecimal numbers at no extra cost. For a system constrained to the boot sector, I can pretty much call it feature-complete — I can't think of anything that would significantly simplify the bootstrap, while taking few enough bytes that it seems remotely within the reach of code golf.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of bytes

bytes

Photo of Forth

Forth

Related news:

News photo

Common Lisp implementation of the Forth 2012 Standard

News photo

Activating a Playstation-Only Cheat on PC in Just Nine Bytes

News photo

Callisto: Reverse polish notation programming language inspired by YSL-C3, Forth