NieDżejkob's ramblings

Bootstrapping

What if all software suddenly disappeared? What's the minimum you'd need to bootstrap a practical system? I decided to start with a one sector (512-byte) seed and find out how far I can get.

Fitting a Forth in 512 bytes

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. Read more

No branches? No problem — a Forth assembler

The set of words available after Miniforth boots is quite bare-bones. One reader even claimed that, since there's no branches, it is not Turing-complete, and therefore not worthy of being called a Forth! Today is the day we prove them wrong. Read more

Branches: No assembly required

Last time, we started from the barebones Miniforth kernel, and implemented branches by writing additional primitive words in assembly. For pragmatic reasons, that is the road I will be pursuing further, but I noticed that it is also possible to implement branches in pure Forth. I believe that this approach is quite interesting, so let's take a detour and get a closer look. Read more

How Forth implements exceptions

Considering Forth's low-level nature, some might consider it surprising how well-suited it is to handling exceptions. But indeed, ANS Forth does specify a simple exception handling mechanism. As Forth doesn't have a typesystem capable of supporting a mechanism like Rust's Result, exceptions are the preferred error handling strategy. Let's take a closer look at how they're used, and how they're implemented. Read more

Contextful exceptions with Forth metaprogramming

A typical Forth system provides a simple exception handling mechanism, in which a single integer, that identifies the exception, is thrown. If we end up catching the exception, this scheme works reasonably well. However, if it bubbles up to the very top and gets printed to the user, we'd like to show a bit more context. Read more