In article <CEFCrG.AxA@dcs.glasgow.ac.uk>,
Robin Popplestone <pop@dcs.glasgow.ac.uk> wrote:
>How good can Forth code be made? Is
>a built in garbage collector desirable?
Forth lets you write computer programs in many different styles. It
is very interactive and is not exactly the same language when used with
a multi-tasking DOS, a single user DOS, a stand alone system or just as
a boot ROM.
Take the case of a stand alone system with one user and a disk drive.
This was the original form. There was no garbage collection because
it was not needed. There is a linked list used to look up words in a
dictionary. Most of the data was stored on a stack, and is created and
consumed as needed. The dictionary would need to be cleaned up as new
words were added and old words found to need changes. What you do is
make changes to your source on disk, remove the new code you are working
on from memory, and reload the stuff you are working on from the source
on disk. Eventually everything will be tested and debugged and you can
make a new binary that will load at startup and do exactly what you
want.
There are different areas that could need garbage collection in
Forth, and different ways to do it. The source code on the original
Forth was essentially stored as one file that took up the whole disk
drive. New code was written in blocks of 1024 bytes, and after a while,
it would turn into a mass of spagetti with the system jumping around
to different block numbers to compile applications. Many experienced Forth
programmers say this is no problem and they have written a few simple
words to take care of things. Other Forth programmers say this is a
completely impossible way to work and they use the popular DOS's with
the usual editors. These editors and disk operating systems are much
more complicated than a stand alone Forth system. There should be
a way to have garbage collection for Forth screens to satisfy both
camps, but nobody has found it yet.
Another area where the idea of garbage collection could be
used is in the creation of a small executable binary written in Forth.
After creating an application, the code for creating new Forth words
is still in memory, so saving the code as a memory image produces a
large file with dead code. The garbage collection process to avoid this
is called a metacompilier or recompilier. There have been many ways
developed to do this, but no nice simple one that everyone could understand
and would want to use.
If you use Forth to work with symbolic data, manipulate text
strings, and such stuff, then you'd probably want to incorporate the
same type of garbage collection as is used by the langauges that are
usually used to do this work. But this is not a part of Forth, it is
an extension for a particular application.
--
Michael Coughlin mikc@gnu.ai.mit.edu Cambridge, MA USA
|