r/Forth • u/NieDzejkob • Jun 11 '21
Fitting a FORTH in 512 bytes
https://niedzejkob.p4.team/bootstrap/miniforth/8
u/drivers9001 Jun 11 '21
Very cool! Inspiring. When I get around to implementing forth (targeting Raspberry Pi Zero, so different machine language) ultimately I don't want to rely on an assembly tool chain and would want to start with a forth program that writes out the bytes needed for a kernel.img file which goes on the SD Card to boot off of.
4
2
2
Jun 15 '21 edited Jun 15 '21
I think your source is a nice to understand example to show the minimal effort which is needed for bootstrapping a classical Forth environment. Well done. By the way you may squize more machine code into a block though code compression or self modificating code.
1
0
u/gousey Jun 19 '21 edited Jun 19 '21
512 bytes is just too small. There is a long history of claims that Forth can be reduced to absurdly small footprints, but utility just disappears.
This is a bootstrapping routine, not a true Forth.
Personally I'd avoid anything under 4Kbytes and would prefer 32Kbytes of RAM.
Dr. C.H. Ting has well proven the minimums for a Forth kernel in his eForth demonstrations.
3
u/telemachus_sneezed Jun 21 '21
There is a long history of claims that Forth can be reduced to absurdly small footprints, but utility just disappears.
You're right about its "usefulness" being compromised as it shrinks. But look at Forth as a "working" language; ideal for embedded code. Most semiconductor chips don't have megs of RAM; they have to get their work done in 16K or less.
The smaller and more integral the dictionary, the more RAM it has to work with. You can have a basic, working FORTH kernel in as much as 2K (although it would be better to be able to implement a 4K kernel).
4
u/Wootery Jun 11 '21
Very neat project, but it doesn't count as a Forth if it isn't even Turing complete, which it presumably isn't: