Classic Computer Magazine Archive COMPUTE! ISSUE 26 / JULY 1982 / PAGE 174

The FORTH Page
Headless Metacompilation

Richard Mansfield
Assistant Editor

After you've written a FORTH program, you can metacompile, leaving out words which are not a working part of the application.

Somehow, the prefix meta always sounds both glamorous and forbidding. Attached to a word, meta usually adds a special meaning involving "over" or "beyond" or "transformed" – it can seem paradoxical. A metatruck would be a truck that carries other trucks. MetaFORTH, likewise, means using FORTH to compile itself.

"FORTH for PET," an adaptation of FORTH by L. C. Cargile and Michael Riley, supports a FORTH Metacompiler (for Upgrade or 4.0 BASIC with 32K RAM) which can be purchased separately for $30. "FORTH for PET" itself does not require the extra memory.

The goal of metacompilation is to reduce memory size or modify FORTH itself by recompiling the entire FORTH dictionary. Obviously, you cannot eliminate words like DUP and SWAP. They are in the definitions of many other words and will always be central in any working FORTH application.

However, there are applications which will not need keyboard entry, disk access, or other such normal FORTH capabilities. If you write a game which does not involve the disk, you could metacompile a special FORTH which does not have such words as FLUSH, LOAD, etc.

Clear, Step-by-step Instructions

The Metacompiler's instruction booklet is written so clearly that a relative novice in FORTH will have little difficulty with it. The process of metacompilation is essentially straightforward and the manual leads you through it, step-by-step, explaining what's happening along the way. You load your ordinary FORTH into the computer, load screen ten from the Metacompiler disk, and it requests a target address for a new, temporary FORTH. Since regular FORTH starts at hex $0400, you can respond with $4000 as the start of the new version. Both will be resident in memory simultaneously, but after metacompilation, control of the computer is passed to the upper one.

After you've indicated your target address, you can sit back and watch the dictionary being recreated at the new location. The words are put on screen as they are recompiled. Or you can leave and come back about six minutes later to find two FORTHs in the computer. You'll be able to communicate with the upper version and it will respond normally.

The final step is to compile back down, giving $0400 as the target this time, and making any changes you want to the Metacompiler's disk screens. These changes will be reflected in the new FORTH you are creating.

The manual takes you carefully through an entire editing process where you create a stand-alone "Calendar" program. This calendar application is truly a FORTH transfigured: when run, it uses DUP and other key words, of course, but it will not recognize them from the keyboard. It can do nothing with the disk. In fact, it understands only the few words that relate to the calendar functions to which it is dedicated. What's more, it's headless.

Removing Heads

In FORTH, there are four "fields" to an ordinary word: the name, link, code, and parameter fields. The "head" of a word is the name and link fields, taken together. If a word in your new FORTH application will only be used in further definitions and will never be independently executed, you can type DROP-HEADS before it on the Metacompiler disk. That word and any words after it will be compiled without name or link fields when the new FORTH is created. To resume head compilation, type COMPILE-HEADS.

An Excellent FORTH Adaptation

It is gratifying to find this metacompilation capability, a valuable and sophisticated technique, available on PET/CBM computers. Equally pleasing is the excellent FORTH implementation by the same authors, "FORTH for PET" ($50, 16 or 32K, Upgrade or 4.0 BASIC, with disk) to which this Metacompiler is an optional addition.

"FORTH for PET" is a full FIG FORTH system (allowing all FORTH 79 extensions as an option), a complete assembler, several sample programs, many utilities, and introductory and reference manuals. Perhaps most attractive is the fact that the full, powerful Commodore screen editing system works the same way that it works in BASIC. You move anywhere fast and modify screens with great ease. Other versions of FORTH are sometimes encumbered by awkward editing procedures.

"FORTH for PET," and "Metacompiler for FORTH" are both available from A B Computers, 525 Bethlehem Pike, Colmar, PA, 18915.