💾 Archived View for stack.tilde.cafe › gemlog › 2022-09-27.2xforth.gmi captured on 2023-09-28 at 16:12:02. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-09-08)
-=-=-=-=-=-=-
There are a bunch of rambling essays by Chuck Moore and Jeff Fox at www.ultratechnology.com, referring to 10x Forth and 100x Forth and whatnot.
They are a fun read for us desperate for Forth trivia and memorabilia... Jeff Fox (Godess rest his soul¹) was a bit of a windbag (look who is talking -- I am sure I am called worse), and was not a good explainer of things (neither is Chuck, honestly), but I am due to reread his site because there are morsels of good stuff there.
So it is with great amusement that in my new Forth implementation I use the word '2x'. It simply makes whatever happens next (to the end of the word) happen twice. So consider a simple word that outputs a space: preceding it by 2x makes it emit two spaces. Prepending another 2x makes it do 4 spaces
: 4sp 2x : 2sp 2x : sp 32 emit ;
The entire above sequence takes amortized 12 bytes in my Forth, because it uses byte tokens. So 5 tokens, a byte literal, plus an extra byte per dictionary byte for the jump table. Hah!
How does 2x work? It pushes the address of the next token, so that upon RETURN, we get to do whatever follows again. We can freely push execution addresses onto the stack -- there is no penalty for call/return mismatch because we are interpreting. And my interpreter does not need DOCOL, so we can jump to any token and execute until RETURN.
This will not work in your dad's Forth (GForth?), because of interleaved headers. I think you can do that in ColorForth. My newest Forth keeps heads elsewhere, so it is perfectly legal to run into the next-defined word. The colon definitions are really labels into code, and the definitions are just tokens (DOCOL is assumed by the inner interpreter).
This is just pure magic.
¹ Jeff Fox died on or around May 5, 2011, according to Chuck Moore: