190 points · by jpegqs · 5y ago · 57 comments
The linked post is really impressive. The author went way beyond what I did. I'm especially impressed by the I/O stuff.
Although the standard was withdrawn in 2000, it continued to be used by PowerPC Macs until Apple moved to x86 and EFI/UEFI.
Open Firmware is now actually open source as OpenBIOS (and OpenBoot is also available under a BSD license.) Apparently it can be used as a qemu boot rom for Linux, BSD, Solaris, and PowerPC versions of Mac OS 9 and OS X.[2]
I mean I know a lot of foundational code of yesteryear was hacked together in C, but C lacks a certain ineffable cachet in my view. A cachet that Forth definitely has.
In my experience, FORTH doesn't really scale to big projects, or things that need a lot of dynamic allocation. It's great at low-level stuff like hardware bringup (we used it on the Atari ST, back in the day, and even the hardware engineers were writing code to exercise their designs), but doing anything at scale is going to be tough. You probably don't want to write a modern web server platform in it, for instance. But it's probably great on an Arduino with a serial port.
There were a lot of games started at Atari in FORTH ("Hey, this is simple! Who needs to hire expensive assembly language programmers?") but the only project that shipped was the pinball machine "Four by Four". I saw a bunch of expensive disasters and mostly steered away from it.
Consider control statements like conditionals or loops. They are implemented in Forth to express what is essential for imperative programming.
You can just as easily implement region handling much like what Cyclone [1] did. Invent region, dispose region, allocate within region, etc. You can augment semicolon word to not only check for control statements to be valid, but also check for region handling correctness.
[1] https://en.wikipedia.org/wiki/Cyclone_(programming_language)
Of course, you have to be either well educated or highly inventive to do that. ;)
And at the time of Atari most of programming projects were expensive disasters, not only games written in Forth.
I wrote malloc.fth for Mitch Bradley's ForthMacs, which ended up in OpenFirmware:
https://github.com/openbios/openfirmware/blob/master/ofw/cor...
\ Forth dynamic storage managment.
\
\ By Don Hopkins, University of Maryland
\ Modified by Mitch Bradley, Bradley Forthware
\ Public Domain
\
\ First fit storage allocation of blocks of varying size.
\ Blocks are prefixed with a usage flag and a length count.
\ Free blocks are collapsed downwards during free-memory and while
\ searching during allocate-memory. Based on the algorithm described
\ in Knuth's _An_Introduction_To_Data_Structures_With_Applications_,
\ sections 5-6.2 and 5-6.3, pp. 501-511.
Forth systems running on C libraries can also call back to the native malloc/free implementation, but it's nice to have a pure FORTH implementation for embedded applications.FORTH is all fun and such (well, the stack counting gets old after a while), but I have difficulties seeing it in larger, multi-person projects (were there any?). A good idea who's time came and went.
Interesting how developers today impicitly assume the term "scale" mean "scale up".
It is not only in the Forth community that one hears disaster stories like: we did the software for client X in 3 weeks with a team of 4 programmers, but after a few decades they lost the know-how of our language so they decided to rewrite in a "modern" language that "can scale". They hired a team of 40 developers, it took 3 years, and the result is less reliable than the original. The only thing that scaled up were the development and maintenance costs and the only thing that was modernized is HR policy (i.e. let's hire disposable developers).
These were written by third parties and published by Atari. Atari did not have any game programmers on the payroll at that point (all the software folks were working on the ST and related things). There might have been some contracting going on, but the days of an Atari employee coming up with a new game idea and shipping a new cartridge were gone.
https://github.com/nineties/planckforth
You start with a very tiny address or bytecode interpreter, much smaller than 512 bytes. Then you load several levels of bootstrap interpreters into it until you have a fairly featureful Forth. So that occupies ram but not program space on the target computer. You would load the non-initial stuff from a remote computer that didn't have tiny memory constraints.
A Turing machine is not stack-based, but tape-based. A pushdown automaton (PDA) is stack-based.
Why? I guess it depends on how you define "kernel." But to be able to do a batch process like compilation, you can get away with a little.
Can you clarify what batch process means in this case?
I /think/ the authors definition of a kernel is a program that can host other programs in some way.
A video game on a boot sector can't do that (even though it likely would have it's own kernel to function), but some kind of input loop to write memory could.
You don't need to host another program to compile something. All you need to do is to read data off disk, then write other data back.
The only way to avoid that is to hand-punch a tape or something like that (with lots of practice and patience, it may be possible to program a small PROM or write an early floppy by hand)
On early machines (large and small) with front panel hardware, you could use switches to manually enter the boot loader into memory and then start it.