4tH interactive. 4tH 4tH Forth compiler
Tangazo
Tangazo
Chapter 4
A guided tour
4.1
4tH interactive
4tH’s interactive mode was introduced with version 3.3c, but it is still fully compatible with previous versions, so you can still use all your external IDE’s and script files. The interactive mode is especially useful when you are using an environment where other tools are not available or impossible to use. This document shows you how to use interactive mode and get the most out of it.
4.2
Starting up 4tH
You can enter 4tH’s interactive mode by just clicking the icon (when you are using MS-
Windows) or by issuing this command on the Unix or MS-DOS commandline:
4th
4tH will respond by showing you this screen:
(S)creen file: new.scr
(O)bject file: out
(E)dit (C)ompile (R)un (A)rguments
(Q)uit (G)enerate (B)uild (D)ecompile
>_
This is the main menu. It is slightly reminiscent to the earlier versions of Turbo Pascal. At the bottom is the prompt. Just press the appropriate key and hit enter, e.g. "S", which stands for the name of the screenfile. 4tH will now prompt you for the name of the screenfile. Note that 4tH is not case sensitive, so both "s" and "S" will do.
4.3
Running a program
We assume you’ve installed 4tH according to the instructions. If not, this might not work.
Now press ”S” and hit enter. 4tH will prompt you for the name of a screenfile:
42
CHAPTER 4. A GUIDED TOUR 43
Screen file name:
Answer by typing ”examples/romans.scr”
1 and hit answer. 4tH will return to the menu:
Screen file name: examples/romans.scr
(S)creen file: examples/romans.scr
(O)bject file: out
(E)dit (C)ompile (R)un (A)rguments
(Q)uit (G)enerate (B)uild (D)ecompile
>
Now hit ”R” and press enter. What now appears is your program that is actually running:
>r
Enter number: 2005
Roman number: MMV
After the program has ended, you will return to the menu. Well, that wasn’t too hard, was it?
4.4
Starting an editing session
We start by entering the editor mode. Just type ”e” and hit enter. Ignore any file opening errors. The ”OK” prompt shows you you’re now in the editor. Now type:
0 clear
This will erase the first screen and select it for editing. 4tH’s editor is a typical Forth editor.
Forth organizes its mass storage into "screens" of 1024 characters. Forth may have one screen in memory at a time for storing text. The screens are numbered, starting with screen
0.
Each screen is organized as 16 lines with 64 characters. The Forth screens are merely an arrangement of virtual memory and do not correspond to the screen format of the target machine.
Depending on memory model and operating system, you have either 28, 32 or 64 screens available. This will be sufficient in most situations. These screens correspond to a region in memory, which acts like a RAM drive.
The actual editing is done in an area that is called the ’workspace’. With the word ’clear’ you wipe all information in the workspace. With the word ’list’ you can select a certain screen for editing and load its information from the RAM disk into the workspace. The figure below shows you how to transfer information between the screenfile, the RAM disk and the workspace (figure 4.1).
When you enter the editor the file is automatically loaded into the RAM disk. With ’list’ you transfer the source from a screen in the RAM disk into the workspace. Since we started a new file (that’s why you got the error message) all screens are empty. That why we cleared screen 0 and selected it for editing. You can quit the editor without changes by pressing
”q” and hitting the enter key.
1
This works for both Windows and Unix type Operating Systems.
Pakua
Tangazo