Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #51412

Re: Forth implementation in pure Forth?

Path csiph.com!aioe.org!.POSTED!not-for-mail
From Rod Pemberton <NoHaveNotOne@zxdehrnyya.cam>
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@_> (permalink)
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

Show key headers only | View raw


On Mon, 26 Sep 2016 18:54:37 -0700 (PDT)
Alex Dowad <alexinbeijing@gmail.com> 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?
> 
> If your answer is "write one yourself"... well, I've written several,
> but would like to compare.
> 

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.

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Forth implementation in pure Forth? Alex Dowad <alexinbeijing@gmail.com> - 2016-09-26 18:54 -0700
  Re: Forth implementation in pure Forth? Michael Barry <barrym95838@yahoo.com> - 2016-09-26 20:20 -0700
  Re: Forth implementation in pure Forth? Paul Rubin <no.email@nospam.invalid> - 2016-09-26 21:37 -0700
    Re: Forth implementation in pure Forth? Lars Brinkhoff <lars.spam@nocrew.org> - 2016-09-27 08:27 +0200
      Re: Forth implementation in pure Forth? Cecil Bayona <cbayona@cbayona.com> - 2016-09-27 02:22 -0500
      Re: Forth implementation in pure Forth? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-09-27 14:22 +0200
        Re: Forth implementation in pure Forth? Alex Dowad <alexinbeijing@gmail.com> - 2016-09-27 05:42 -0700
          Re: Forth implementation in pure Forth? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-09-27 15:23 +0200
            Re: Forth implementation in pure Forth? rickman <gnuarm@gmail.com> - 2016-09-28 11:13 -0400
          Re: Forth implementation in pure Forth? Alex <alex@rivadpm.com> - 2016-09-27 14:25 +0100
            Re: Forth implementation in pure Forth? Alex <alex@rivadpm.com> - 2016-09-27 14:27 +0100
      Re: Forth implementation in pure Forth? Alex Dowad <alexinbeijing@gmail.com> - 2016-09-27 05:40 -0700
        Re: Forth implementation in pure Forth? Lars Brinkhoff <lars.spam@nocrew.org> - 2016-09-27 15:47 +0200
        Re: Forth implementation in pure Forth? hughaguilar96@gmail.com - 2016-09-27 11:43 -0700
          Re: Forth implementation in pure Forth? Jan Coombs <jenfhaomndgfwutc@murmic.plus.com> - 2016-09-27 21:51 +0100
            Re: Forth implementation in pure Forth? Cecil Bayona <cbayona@cbayona.com> - 2016-09-27 16:04 -0500
    Re: Forth implementation in pure Forth? "Elizabeth D. Rather" <erather@forth.com> - 2016-09-26 21:10 -1000
  Re: Forth implementation in pure Forth? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-09-27 14:18 +0200
  Re: Forth implementation in pure Forth? stephen@mpeforth.com (Stephen Pelc) - 2016-09-27 12:12 +0000
  Re: Forth implementation in pure Forth? Rod Pemberton <NoHaveNotOne@zxdehrnyya.cam> - 2016-09-27 21:04 -0400
    Re: Forth implementation in pure Forth? Lars Brinkhoff <lars.spam@nocrew.org> - 2016-09-28 10:57 +0200
      Re: Forth implementation in pure Forth? "Elizabeth D. Rather" <erather@forth.com> - 2016-09-27 23:19 -1000
        Re: Forth implementation in pure Forth? rickman <gnuarm@gmail.com> - 2016-09-28 11:42 -0400
      Re: Forth implementation in pure Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-09-28 04:51 -0500
      Re: Forth implementation in pure Forth? Alex Dowad <alexinbeijing@gmail.com> - 2016-09-28 03:41 -0700
        Re: Forth implementation in pure Forth? Alex Dowad <alexinbeijing@gmail.com> - 2016-09-28 03:51 -0700
        Re: Forth implementation in pure Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-09-28 20:42 +0100
  Re: Forth implementation in pure Forth? Chris Curl <ccurl609@gmail.com> - 2016-09-27 20:40 -0700
  Re: Forth implementation in pure Forth? Jan Coombs <jenfhaomndgfwutc@murmic.plus.com> - 2016-09-28 07:59 +0100

csiph-web