www.jupiter-ace.co.uk
 
Previous Page > Index of General Forth Information > IBM Comes FORTH.
Personal Computer World July 1983 page 198.
IBM COMES FORTH
An exclusive review of PolyForth as presented by Dick Olney
As the popularity of Forth among micro users increases so, too, does the number of compilers available. The problem is that either they are cassette-based or they run under one of the standard operating systems, both of which situations disguise the language's full potential.
PolyForth, from Forth Inc of California, is unique in providing a standalone multi-tasking operating system and an overwhelming selection of extensions and utilities for a mere £250. It was designed to run on an IBM PC with at least one single-sided disk drive. A conversion utility is included which allowed me quickly to reconfigure the software and make full use of the dual 320k drives installed in the machine I was using.
The PC automatically boots up the PolyForth when it's switched on, whereupon a title and date appear in the top left-hand corner of the screen together with the word 'HI'. At this point the Forth 'nucleus', that is, those words which are pre compiled on the system disk, is already in place and most of the major features have been loaded (like any good Forth all the non-standard extensions are supplied as source). Typing 'HI' at this stage loads a further selection of utilities and displays a help screen containing brief details of a selection of useful commands.
MS-DOS users might be rather disturbed at this point to find the cursor and edit controls on the numeric pad completely disenabled (the keys always echo their number value). This is because these functions - like the rest of the keyboard - are dealt with in software. In fact the Forth has a keyboard interpretation chart residing in block 0 of the system disk. The version I used was still configured to a US keyboard. The " and @ symbols were reversed and the £ returned a #. Comsol, the European distributor of this product, is working on a UK conversion utility to be included in the package. It is possible to use all of the special keys but you will need to develop your own routines to handle their functions. The ten keys labelled F1 to F10 can be attached to a word simply by naming it with the legend on the key as in: F1 ." This is Function F1"; which will cause the embedded text to print out whenever the F1 key is depressed. For other keys, however, such as CTRL and ALT you will need to test for ASCII values in a special input routine.
The basic system includes most standard Forth words and much more besides. One omission
which might surprise Fig Forth users is VLIST (giving a listing of the dictionary). It's easy to test for the existence of a word and the command LOCATE will automatically display the source of any word loaded from disk not contained in the object nucleus - an invaluable debugging aid. A full selection of 32-bit math's operators is included as well as an 8088 assembler - written in Forth - and a standard line editor.
As is usual the assembler and editor words are held in discrete vocabularies which must be declared before they are used. A further 5 user vocabularies can be added. The system keeps track of these using an array called GOLDEN which contains the start (or end, depending on how you look at it) of the dictionary lists. At any one time up to four vocabularies can be current, with the compiler following a pre-specified search sequence determined by the contents of the variable CURRENT. Used in conjunction with the turnkey compiler (see below) this enables the programmer to create a self-loading application where the user can only access an appropriate selection of high level commands.
A copy of the GOLDEN array, called CONTEXT, has its link addresses updated as new words are added to the various vocabularies. The word EMPTY copies the contents of GOLDEN into CONTEXT, thereby erasing from the dictionary any entries compiled since its previous execution. The source for this reads GOLDEN CONTEXT 20 MOVE. The reversed phrase CONTEXT GOLDEN 20 MOVE re-initialises GOLDEN thus protecting all currently compiled words from the use of EMPTY. In this way applications can be efficiently re-compiled during development and protected after successful debugging using a technique which is much more controlled than the traditional FORGET.
All dates in the system, including today's, are held as 16-bit numbers described as 'modified Julian dates' giving the number of days which have elapsed since 1 January, 1900. They use a compact representation which allows arithmetic to be performed on the date directly. Two formats are provided for input and output of which examples are 14 MAY 1983 or 5/ 14/83. Little effort has been put into conversion for the British market though it would be no problem to develop your own routines using the existing low level words.
Multi tasking
Multi-tasking is probably the most exciting feature of PolyForth not least because of its ease of use. It relies upon a tiny (25 bytes) core routine called PAUSE. When executed in a program this word passes control to an idle loop which runs around a circular chain of addresses called a 'round robin' searching for the next task ready to be activated. New background tasks are created using three programmer-supplied values. The first of these represents the 'user area' in which key variables may be protected from other tasks. Such variables are defined in the format: offset USER name
where the offset is added to the task's base address to give the address of the variable. Each task maintains its own parameter and return stack, and the other two values represent the byte sizes of these. To define a background task the command is:
user parameter return BACKGROUND name
which constructs a table to be used when the task is initialised with the word BUILD, whereupon it is linked into the round robin.
Once a task has been defined and created it can be activated by any program using the following convention: word task-name ACTIVATE (words executed by task);
There are, however a number of vital restrictions of which the programmer must be aware if this is to be successful. First a background task cannot perform terminal I/O and is thus unable to issue error messages, so if anything goes wrong the whole system will crash. A similar effect occurs if the task is allowed to reach the semi-colon, and it must therefore be explicitly terminated with the word STOP.
The reason that a background task cannot perform terminal I/O is that such a potential demands the ability to vector to unique,routines when executing words like TYPE and CR. It is possible to overcome this by moving text directly into screen memory, but you will need to develop your own routines in assembler to access memory above 64k. The two predefined tasks called OPERATOR and TYPIST are, of course, capable of terminal I/O since they control screen and printer respectively. This means that screen activity remains relatively unaffected when the printer is active.
Although the multi-tasking facility is simple and effective much of its operation depends on the programmer. Remember that in reality only one task is actually active at any one time, and it is therefore essential in both foreground and background tasks
Personal Computer World July 1983 page 201.
IBM COMES FORTH. . .
ground tasks to use PAUSE in a fashion most appropriate to the application. In addition the use of any shared resources, such as the disk buffers, must be carefully monitored and, if necessary, controlled using special routines. Note that, once built into the round robin task, definitions cannot be erased from the memory by EMPTY or FORGET and any attempt to do so has dire consequences.
Despite the vulnerability of the PolyForth multi-tasking, it does give this system an immediate lead over most of the more conventional operating systems currently available. Used properly with careful and extensive debugging it could provide the basis for many impressive applications.
Programmer Utilities
The initialisation of diskettes and the manipulation of data on them is fundamental to any disk-based operating system.
In this system these functions are grouped in a utility dubbed 'Disking'. All the standard commands are provided including initialisation, backup, and block copying as well as disk diagnostics. One command that is particularly useful is MATCHES, which is not used to activate an optional cigarette lighter, but to compare the contents of two specified ranges of blocks and report any discrepancies.
The most common criticism of Forth is that the source is unreadable to anyone but the originator. Forth Inc has attempted to counter this with a facility called 'shadow documentation'. Two disks are supplied with the package, the system disk which resides in drive 0, and a documentation disk for use in drive 1. The documentation or shadow disk contains brief descriptions of all the words existing as source on the system disk. To access the shadow blocks you must first LIST the relevant source: at this point the command Q will toggle the display between the source and its associated documentation. This idea is that shadow documentation is written at the same time as the source to assist in any future modification or debugging.
The printing utility makes use of the shadow documentation by allowing double-sided printing. With careful positioning of the paper the source and shadow blocks can be printed so as to appear opposite each other when filed in an A4 binder. Alternatively, source without shadow documentation can be laid out with alternate pages on different sides of the paper to give a similar effect. Printing is initialised by preceding any valid words with the command PRINT. This literally sends the rest of the input stream to the TYPIST terminal task. Because of its mode of operation, however, this word cannot be used inside colon definitions, where TYPIST ACTIVATE performs a similar function. The system gives full support for the standard IBM (Epson) parallel printer, though you need to write your own
control functions using EMIT and the ASCII values given in the IBM Guide to Operations
Additional Options
To complete the image of this package as a powerful software development tool, a number of additional support features have been included. One of the most exciting of these, especially bearing in mind the multi-tasking capability, is the colour graphics option. Unfortunately, I do not have access to a colour display so I was unable to use this facility, though I did see a demonstration on one of IBM's machines which drew some fairly convincing square spirals. The option allows basic point plotting in medium-resolution (200 x 320) colour mode. From the manual I would guess it's fairly primitive but, like the rest of this system, I'm sure it could be extended into a powerful vocabulary.
Another option is the screen editor, which uses all the IBM function keys, and which I used to write this review. It's better than using my old typewriter but lines do not run on, neither do blocks, so it's hardly a word processor. Nevertheless it serves its purpose and perusal of the source reveals an interesting definition of a word named :K which reads: :K (k) : LAST @ @ CFA 2+ SWAP 'FUNCTION ;
The colon within this definition means that upon execution :K will itself cause a new word to be compiled from the input stream, and it is at this time that the colon is presented with a matching semi-colon. When :K encounters the latter compilation ceases and the rest of the code is executed. The technique is used here to place the execution address of a colon definition into a function table at the time it is compiled, thereby facilitating vectored execution. The word :K expects the offset in the table for the new word to be on the stack. An example of its use is: 71 :K HOME 0 C# ! 0 L# !:
where HOME places the cursor at the first position on a block by zeroing the column and line counts.
Although IBM apparently does not support it, there is a spare socket on the system board for an 8087 math's processor, and the PolyForth manual gives full instructions for installation and details of an extensive supporting vocabulary. The conditions of sale from IBM, however, suggest that such a modification would render the warranty invalid, so I resisted the temptation to test out this option.
If applications are to be written in Forth, then sooner or later they are bound to be presented with files created under PC DOS, and the next option on the list is PC DOS file handler. All this really does is to take care of the DOS sectoring and provide for basic file manipulation. Actually to access data in applications you'd need to extend considerably the vocabulary. Still, the basis of it is there and it would be fairly easy to impose your own data structures over the DOS format.
Last, but not least, is the turnkey compiler which allows
self-booting application disks to be created. This is achieved by first EMPTYing the dictionary then loading up your applications, followed by the turnkey utility. At this point a controlling application word to be executed on entry can be specified together with any blocks to be loaded from disk at that time. The word PROGRAM then transfers a custom bootstrap dictionary to an initialised diskette in drive 1 (instructions are also provided for generating turnkey diskettes on single drive machines). Applications, using a startup program in conjunction with sealed vocabularies or closed program loops, can effectively deny a user access to the Forth itself, even though the core code is resident in the application. If Forth Inc is convinced that you have done this properly then the company won't claim for any copyright payments.

Benchmark timings
magnifier 1.7
do-loop 5.8
literal 6.6
literal-store11.3
variable 7.4
variable-fetch9.6
constant 7.8
dup9.6
increment 9.4
test>12.7
test<12.7
while-loop 14.3
until-loop 13.3
dictionary-search5.7
arithmetic4.1
mixed maths5.3

I timed the PolyForth using the Forth benchmark programs published in the January issue of PCW. To do this I had to write an assembler routine to reset the stack pointer, which luckily turned out to be very simple (my assembler is limited to say the least!) and my version of SP! reads:
CODE (SP!) S POP NEXT :
SP! SO @ 2 - (SP!)
Having checked the reliability of the system clock I decided to let the machine time itself and printed out the contents of the system variable TICKS at the beginning and end of the multiplier routine. Remember that the timing for this word is subtracted from the other values to give the true figure so it doesn't matter that my version takes slightly longer.
The results are the fastest recorded Forth benchmarks, particularly the arithmetic program which this system runs four times faster than its nearest competitor. An additional test of my own, using double-number and mixed operators, ran almost as fast as the original arithmetic program. There's no doubt that if it's speed you're after then this is the package for you. (For 'mixed maths' benchmarks, see below.)


Mixed math's benchmarks
1
2: mixed-maths .TICKS 10001 1 DO 3 900 900 M* 9 M/ 0 90000 D+ 90000 D-
4 SP! LOOP .TICKS ;
Personal Computer World July 1983 page 204.
IBM COMES FORTH...
Documentation
Very sensibly Forth Inc has used the superb Starting Forth as one the manuals for its PolyForth. This book has become the Forth programmer's bible, providing the beginner with a detailed overview of the language and many useful examples. The other manual supplied with the package, held in a solid foam-backed binder, contains general details of specific features, though really to understand how everything works you will need to read the shadow documentation as well. Everything is covered and the manual includes an excellent index and glossary, as well as full source and shadow listings.
Expandability
Level 2 PolyForth is at the bottom end of a range of three products. Level 3,  which  costs £490,   in-
cludes a database system and support for multi-terminal tasking and networking. It also includes a much more detailed manual. The most expensive system, Level 4, adds a target compiler and carries full source listings of all words. It costs £2750, but this buys you certain rights of reproduction as well. Unfortunately, you get no discount on Level 3 if you have already got a Level 2, though full discount is offered when upgrading from Level 3 to Level 4. It is, however, possible to write most of the features included in Level 3 with the facilities available in Level 2.
Conclusion
As you may have guessed, I was extremely impressed with this package. Forth remains (in this country at least) relatively unexploited as a serious software development tool, partly because many of the compilers  available
many of the compilers available are simply not suitable for this purpose. Level 2 PolyForth is a quality product aimed at the professional or semi-professional programmer (at a price that should present no problem to anyone who can afford an IBM PC!). How successful it is in competing with the mainstream languages and operating systems will depend to some extent on the marketing, an area about which Comsol is still hazy, though it has been submitted to IBM for approval. I do know that the company plans to go all out in the autumn, and is looking for big sales to make the venture worthwhile.
Enquiries should be directed to: Computer Solutions Ltd, Treway House, Han worth Lane, Chertsey, Surrey KT16 9LA. Tel: Chertsey (00000) 000000.
PCW July 1983 cover

PCW July 1983 page 198   PCW July 1983 page 199

PCW July 1983 page 201    PCW July 1983 page 204