On Mon, 26 Sep 2016 18:54:37 -0700 (PDT)
This idea of "Forth in Forth" should be a FAQ, well, technically, it'd
be a FEC (frequently explained concept).
The best that most seem to be able to do is to write a Forth mostly in
Forth, but not completely. Such Forths usually use threaded-code (DTC
or ITC). They don't compile Forth directly to machine language like
modern Forths do. The threaded-code Forths are able to eliminate all
but a handful of Forth words which must be coded in another language.
These words are mostly low-level words that do the work. They're
usually referred to as "primitives". These can vary from a minimum of
around 9 or so and up to 72 or more. General "consensus" is that you
need around 35 primitives. Fewer than that and the threaded-code Forth
becomes too slow. The reason that you need primitives for
threaded-code Forths is that threaded-code colon-definitions only store
the sequence of operations as an address list. The colon-definitions
don't do any actual work in a threaded interpreter. They just group
Forth words (or instructions) together. So, you must have some Forth
words that do some actual work, i.e., some which aren't coded in
high-level Forth. These are coded in another language, which must be
compiled to machine language, e.g., using assembly or C etc.
eForth by Bill Muench was one of the first to attempt to write a Forth
using only a small set of primitives.
From what I've seen, I'd say that the typical threaded-code Forth
interpreter is usually built up this way:
1) inner or address interpreter (coded in assembly or C etc)
2) 35 primitives (varies from 9 to 72, also in assembly or C etc)
3) outer or text interpreter (pre-compiled threaded-code Forth, also
coded in assembly or C)
4) remainder of dictionary words in high-level (text) Forth
The inner or address interpreter is coded in assembly or C etc and
compiled to machine language. Next, a bunch of low-level Forth words
called "primitives" which do basic work are coded. Then, the outer or
text interpreter is coded using the primitives. This is pre-compiled
Forth code or an address list since the outer or text interpreter,
dictionary, and colon-definitions aren't implemented at this point.
Next, some related words are needed to compile words, and some
bootstrap words may also be needed. Finally, the other Forth words can
be coded in high-level Forth. You can also create more complete
versions of built-in Forth words now by using high-level Forth.
eForth
http://www.forth.org/eforth.html
Forths
https://www.taygeta.com/forthcomp.html
Itsy
http://www.retroprogramming.com/2012/09/itsy-documenting-bit-twiddling-voodoo.html
JonesForth
http://git.annexia.org/?p=jonesforth.git;a=tree;hb=HEAD
An old post of mine with the quantity of primitives per various Forths:
https://groups.google.com/d/msg/comp.lang.forth/KHw28PKZXUk/JrXcjrYshxAJ
(Usenet msg id g4gqv4$qk9$
1...@aioe.org)
Rod Pemberton
P.S. Please remind Hugh that some C compilers can produce machine-code
directly without using assembly.
P.P.S. Please remind Hugh that Bradford Rodriguez, PhD, of "Moving
Forth" fame, also recognizes that Forth in C has advantages. See "Part
4: Assemble or Metacompile?" at bottom.