3 ms·
An interesting curiosity about Forth is the fact that the final stage of FreeBSD kernel bootstrapping, the loader program, contains a Forth interpreter. If you
by codetrotter 6y ago
An interesting curiosity about Forth is the fact that the final stage of FreeBSD kernel bootstrapping, the loader program, contains a Forth interpreter. If you have a look in the /boot directory on a FreeBSD system, you will see quite a few files named with the extension "4th" there, and in the loader(8) man page we find among other things the following:
> loader [...] provides a scripting language that can be used to automate tasks, do pre-configuration or assist in recovery procedures. This scripting language is roughly divided in two main components. [...] The bigger component is an ANS Forth compatible Forth interpreter based on FICL, by John Sadler.
> [...]
> BUILTINS AND FORTH
> All builtin words are state-smart, immediate words. If interpreted, they behave exactly as described previously. If they are compiled, though, they extract their arguments from the stack instead of the command line.
> If compiled, the builtin words expect to find, at execution time, the following parameters on the stack:
> addrN lenN ... addr2 len2 addr1 len1 N
> where addrX lenX are strings which will compose the command line that will be parsed into the builtin's arguments. Internally, these strings are concatenated in from 1 to N, with a space put between each one.
> If no arguments are passed, a 0 must be passed, even if the builtin accepts no arguments.
> While this behavior has benefits, it has its trade-offs. If the execution token of a builtin is acquired (through ' or [']), and then passed to catch or execute, the builtin behavior will depend on the system state at the time catch or execute is processed! This is particularly annoying for programs that want or need to handle exceptions. In this case, the use of a proxy is recommended. For example:
> : (boot) boot;
> FICL
> FICL is a Forth interpreter written in C, in the form of a forth virtual machine library that can be called by C functions and vice versa.
> In loader, each line read interactively is then fed to FICL, which may call loader back to execute the builtin words. The builtin include will also feed FICL, one line at a time.
> The words available to FICL can be classified into four groups. The ANS Forth standard words, extra FICL words, extra FreeBSD words, and the builtin commands; the latter were already described. The ANS Forth standard words are listed in the STANDARDS section. The words falling in the two other groups are described in the following subsections.
https://www.freebsd.org/cgi/man.cgi?query=loader&apropos=0&sektion=8&manpath=FreeBSD+12.1-RELEASE+and+Ports&arch=default&format=html https://www.freebsd.org/cgi/man.cgi?query=loader&apropos=0&s...
- yjftsjthsd-h 6y agoForth seems to have made its way into a lot of boot environments; it was also used for open firmware