RiscFORTH

Reviewed by David Spencer

Silicon Vision's RiscFORTH is the first and so far only implementation of Forth for the Archimedes. This review will concentrate not only on RiscFORTH, but also on Forth itself for those who may be unfamiliar with this language.

FIRST, SECOND, THIRD ...

Forth is quite an interesting programming language, not least because of its total non-similarity to most other languages, except perhaps Prolog. Forth was designed by one Charles Moore in the early seventies, and got its name from the fact that Moore saw it as the first fourth-generation language. However, the IBM mainframe it was developed on allowed only five letter filenames, and therefore the 'u' was missed out.

As mentioned above, Forth is unlike any other modern high-level language, and indeed is also unlike any assembler language. In fact implementations of Forth cannot even by classed as either interpreters or compilers (See page 17 of RISC User Vol.2 No.2 for the difference between these). It is instead a type of language known as a Threaded Interpretive Language (TIL). A TIL consists of a set of Words linked together in a linked list (hence the term threaded). Each Word consists of a header that contains the name of that Word and a link to the next Word, and a body which contains the machine code instructions to define the task performed by that particular Word. A simple Word, such as one to add two numbers together, would normally just contain the code to perform the operation directly, whereas a more complex Word, such as one to print out a numeric value, might in turn call other Words to perform the task.

The concept of a program doesn't exist as such in a TIL. Instead, a complex task is performed by defining a new Word which makes calls to existing Words in order to perform that task. The process of creating a new Word is called 'compiling', and usually consists of creating a new entry in the linked list of Words, and building up the machine code instructions to call the Words that make up the new Word. Once a new Word is created it can be treated in the same way as existing Words, and can therefore be used in further definitions of other, more complex, Words.

Forth also differs from other languages because arithmetic expressions are represented using a form called Postfix Notation, or more commonly, Reverse Polish Notation, invented by the Polish mathematician Lukasiewicz. If you consider the operation of addition in a normal language, the two operands appear on either side of the plus sign, for example:
A = 12 + 23
However, with Reverse Polish, all operands are stored on a stack. When an operation is performed the appropriate number of values are pulled from the stack, and the result is returned to the stack. In this form, our addition operation would look like:
12 23 +

This starts off by pushing first the value 12, and then the 23, onto the stack. The add operator then removes these two values from the stack, performs the addition and puts the result back on the stack. Assuming that the stack was empty at the start, then it will contain the single value of 35 when the above operation has been performed. This value could then be pulled off and stored in a variable if desired. This method is extremely efficient to execute.

STANDARDS

The problem with a language such as Forth that can be so easily modified and extended, is that every user has a different version of the language. To overcome problems caused by this, attempts have been made to standardise the Forth language. Unfortunately, there are two differing standards. The official Forth standard, is called Forth-83. The opposing standard is Fig-Forth, named after the Forth Interest Group. The latter has lost popularity in recent years.

I shall now concentrate on RiscForth itself. This is an implementation of Forth-83, with a number of system dependent extensions to take full advantage of the Archimedes' features. The software is supplied on a single 800K disc, along with the manual, in a white plastic 'video case'. The system is started simply by booting the disc.

EDITORS AND SCREENS

As programs don't exist in Forth, neither can the concept of saving a program. Instead, Word definitions can be stored as plain text in the so-called Screens file. This is simply a file containing a variable number of 1K chunks of text, arranged as 16 lines of 64 characters. RiscFORTH includes a screen editor (written in Forth) to manipulate the screens files. Once saved, selected screens can be loaded and compiled. Word definitions can also be saved as normal text files.

ASSEMBLER

RiscFORTH also includes an ARM assembler, which in addition to normal instructions also supports the floating point op-codes. The assembler adheres to the doctrine of Reverse Polish, and hence its syntax will seem a bit strange.

STAND-ALONE CODE

The only way to produce stand-alone code from Forth is to save an entire copy of the language. This would normally result in a breach of copyright, however, Silicon Vision have provided a way around this problem. By using a special Forth Word it is possible to prevent the user from accessing directly any of the standard Words of the language. Provided this is done, you are free to distribute a 'copy' of the language.

MULTI-TASKING

RiscFORTH provides a form of multi-tasking. This is a co-operative system, similar in some ways to that offered by RISC OS, although RiscFORTH doesn't restrict you to a WIMP environment. Instead, multi-tasking is achieved by defining a set of Words, each being an infinite loop, and each containing a special Word that switches between tasks. Each Word is then executed in turn in a Round-Robin type of arrangement. The multi-tasking system is particularly effective for the execution of multiple real-time applications.

RiscFORTH contains a demonstration of multi-tasking in which a Mandelbrot fractal is drawn on the screen, while other Words can be executed simultaneously in a text window at the bottom of the screen.

DOCUMENTATION

Forth is not an easy language to learn, especially if it is your first programming language. Therefore, you might need to resort to a tutorial guide on Forth at an early stage. However, don't expect to find such a book supplied with RiscFORTH. Instead, the 163 page A5 format manual is very much a reference guide.

The main section, consisting of about half the manual, is a glossary of all the Words defined in the language as standard. The descriptions of each Word are fairly brief, and I have discovered by delving into the code itself that there are some Words which are not documented at all, although these are mostly low-level system Words. One very useful feature of the manual is that the ASCII character set is printed in order at the foot of each page in this section. Many Forth words start with non-alphabetical characters, and this guide makes it very easy to locate them in the list.

Other sections cover the extensions in RiscFORTH, such as multi-tasking, the screen editor, the assembler and support for graphics. There are also sections on system dependent features and details of how particular Words are implemented. On the whole, the manual served well as a reference guide, and it even lists some suggested titles for beginners to read. My only quibble is the binding. This is of the plastic comb form, with the comb being several sizes too small for the number of pages. It gets annoying after a while picking up pages from the floor.

CONCLUSION

RiscFORTH provides a good implementation of the Forth-83 standard, and is written in such a way as to make full use of the Archimedes' speed. Being the first version of Forth available makes it very hard to rate the standard of the package, although I could not find fault with it. The price of £99.95 inc. VAT is comparable with that of other Archimedes languages.
ProductRiscFORTH
SupplierSilicon Vision Ltd.,
 Signal House,
 Lyon Road, Harrow
 Middlesex HA1 2AG.
 Tel. 01-422 2274
 or 01-861 2173
Price£99.95 inc. VAT