A Taste of Direct Programming
Presented at the EuroFORTH conference 1994
Software projects usually change. The goal of the project evolves with the experience gained in the tests of the program. This is unavoidable, if the product is meant to be useful. We thus need dynamic development systems, which easily handle changes and which let us gain the necessary experience early in the development cycle. Although this is not a particularly new point of view there are very few software production systems available, which facilitate dynamic development. This is the promised land of Forth.
I want to demonstrate the new kind of directness available in programming on an integrated interactive cross-platform development system based on Forth.
A new method of development has silently emerged in the Forth world. It is the interactive programming across platforms, which has become known under names like umbilical development. The host system is connected to the target system via a communication link. With the aid of a tiny monitor in the target the host has full control of the target during development.
In such a system we can load executable code into the target, examine single words, send stack contents to the target and read the changed stack back after execution of a word. We can, in principle, change the code of single words, which provides for an immediate edit-test cycle. And the system also allows debugging with single step execution of both Forth words and assembler code.
The ultimate form of interactive cross-platform development is working on a live program. Contrary to my initial apprehension, I learned that it can be perfectly safe to exchange the code in a running program. This can be done automatically through the development system.
Umbilical development is usually connected with working down into a much simpler system. We use cross- development because of the missing resources in the target system. But there is no fundamental reason why we should restrict ourselves to cross-development for embedded systems. We could as well build an application on a second DOS-system with an umbilical link between two PC's running DOS. Or we could cross-develop applications up to more complicated platforms, say, a different operating system like MS Windows.
Holon is a new kind of development system for Forth programs [2,3,4,5]. The most important change compared to conventional Forth systems is the inclusion of text management into the Forth dictionary. All Forth words are managed in a database (identical to the Forth dictionary) with access to both text and code. The following description shows Holon-11, a version for 68HC11 based targets.
Figure 1. The user interface of Holon-11 is a browser showing the program as a collection of modules, groups and words. We have selected the word /mod in group Arithmetics of module Forth.
The user interface of Holon is a browser (Figure 1). The words are collected in groups and several groups constitute a module. This representation is comparable to a book with chapters, sections and paragraphs. Therefore the program is as readable as a book. You can browse the program with the cursor keys. You see the available groups of the chosen module, the words of the chosen group and the text (definition and comment) of the chosen word. You can access every word directly (quick find) and look up any word in a definition (hypertext). Words, groups and modules can be moved around in a simple way, thus it is easy to keep the program in a well structured understandable state.
The modules can be exported and imported in a new project. Holon also imports text files and converts a linear source file into the internal database format.
Commands are entered via the function keys directly or in combination with the control, alt and shift keys. The commands are state dependent and the menus change with the context. In every state context dependent help is available with function key F1
Holon provides a rich Forth kernel with many useful functions. Probably your program will use only a subset of these functions and you can choose to load only the words, which are really used. Holon includes selective loading (automatic code stripping).
Every word can be changed and reloaded and the corresponding code is automatically exchanged in the target. Holon offers an instant edit-test cycle.
You can test words interactively in the usual Forth way. In addition to the normal Forth command line interpreter Holon also allows testing directly in the browser. If the word needs parameters, you can enter the values directly into the stack window. The RUN function then copies the stack to the target, executes the word and reads the stack from the target back into the host. Thus you act on the target in a transparent way. The stack commands offer a display in decimal or hex and as signed or unsigned numbers.
Figure 2: The debugger in action. The word that is about to be executed (single-stepping) is highlighted in the definition. We are debugging the word /mod (Figure 1) and have stepped down into um/mod. Please note the change to hexadecimal notation in the stack and the fact that the assembler interprets numbers as hex by default.
If you have detected a problem with a word, you can choose to run the word in single-step mode. Holon integrates the debugger with the editor (Figure 2). While executing step by step, the highlight shifts according to the actual execution, tracing loops and conditionals. At each step Holon shows the contents of both data and return stack for high level colon words. For a code word Holon shows the contents of the CPU registers and the data stack. Showing the data stack while executing a code word is useful, because most code words act on the data stack. You can trace the execution automatically at the natural pace of the system (defined by the communication delays, typically 3 steps per second). In a colon word you can choose to continue execution in a subword or jump back to a calling word. Holon automatically follows jumps to other words and displays the text of the new word.
For inspection of the target code both ROM and RAM contents can be dumped to the comment window. The display starts with the code of the current word. Differences between code in the target and in the code file are marked. Since the monitor sends code under interrupt control, you can inspect a running program in this way.
And since the monitor also reads and loads code in the target in an interrupt routine, you can change the code in a running program. Holon appends the new code at the end of the code space and inserts a jump to the new code at the beginning of the old code. With this simple mechanism it is safe to exchange code. If the program is actually running in the old code at the moment of change, it will not be disturbed. The new code comes into effect as soon as the program reenters the changed word.
Holon also uses a new concept of meta-compilation, which allows the full Forth freedom of expression in a cross-development situation without having access to the internals of the host. The Holon host is shielded whereas the target is completely open. All target code is provided in text form. The host is transparent. You always see the target program and always act directly on the target.
There is more to Holon than I could describe here. I wanted to convey a feeling of working with a direct programming system. Thanks to the rapid feedback and experience gained in the process, the program evolves in an organic way.
Holon is presented as an example of a direct programming system. Direct programming offers a new approach to quality. Its characteristic is evolution in place of building. Forth is the ideal evolutionary language.
 Frederick P. Brooks, No Silver Bullet - Essence and Accidents of Software Engineering, IEEE Computer, Vol. 20, No. 4 (April 1987), p. 10 - 19
 Wolf Wejgaard, Not Screens Nor Files But Words, Proc. FORML 1989
 Wolf Wejgaard, The Beauty of Separate Systems, Proc. FORML 1990
 Wolf Wejgaard, Holon - A New Way of Forth, Proc. EuroFORTH, 1992
 Wolf Wejgaard, Interactive Cross Platform Development, Proc. EuroFORTH 1993