ForthOS Metacompilation


Most Forth implementations available today are coded in C; you use a C compiler to build an executable, and when you run that executable you interact with the Forth environment which was implemented in C. If you want to code up a Forth application, you type it into this environment. If you want to change or extend the Forth implementation, you code in C.

ForthOS is different; it takes the philosophy that one of the great strengths of Forth is that it provides continuous stratum of functionality, with all higher layers able to leverage mechanisms from the layers below. When the Forth system is coded in C, this natural synergy is lost at the language boundary. Thus, ForthOS is implemented from top to bottom in Forth, with the lowest primitives implemented as Forth "code" words.


When Forth is coded in Forth, the process of building a new Forth system is called metacompilation. Like most metacompilers, ForthOS's has restrictions on what kinds of Forth code are permissable. Thus, ForthOS's system build is structured in two passes; in the first, a core set of functionality (inner interpreter, console, and disk access words) is built, and this generated system is booted. Then the rest of the system is built by loading normal Forth words into this system.

Most users of ForthOS will probably never need to monkey with the metacompiler. Coding for it--and debugging your mistakes--takes a degree of skill and attention to detail much more demanding than coding normal Forth words. If you're interested, the system distribution has some documentation on the metacompilation process.