Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Rod Pemberton Newsgroups: comp.lang.forth Subject: Re: Forth implementation in pure Forth? Date: Tue, 27 Sep 2016 21:04:06 -0400 Organization: Aioe.org NNTP Server Lines: 82 Message-ID: <20160927210406.432a22dc@_> References: <874b78c5-4f2d-4485-851d-2095e710f615@googlegroups.com> NNTP-Posting-Host: n4wpt9zq8xR26Ttf9mo2BA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Claws Mail 3.13.1 (GTK+ 2.24.13; x86_64-unknown-linux-gnu) Xref: csiph.com comp.lang.forth:51412 On Mon, 26 Sep 2016 18:54:37 -0700 (PDT) Alex Dowad wrote: > A Google search reveals many free Forths written in C, assembler, > Java, etc. But none written in Forth itself. Does anybody have one > available? >=20 > If your answer is "write one yourself"... well, I've written several, > but would like to compare. >=20 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. =46rom 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-vood= oo.html JonesForth http://git.annexia.org/?p=3Djonesforth.git;a=3Dtree;hb=3DHEAD 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.