Our Forth system consists not only of primitives, but also of definitions written in Forth. Since the Forth compiler itself belongs to those definitions, it is not possible to start the system with the primitives and the Forth source alone. Therefore we provide the Forth code as an image file in nearly executable form. At the start of the system a C routine loads the image file into memory, optionally relocates the addresses, then sets up the memory (stacks etc.) according to information in the image file, and starts executing Forth code.
The image file variants represent different compromises between the goals of making it easy to generate image files and making them portable.
Win32Forth 3.4 and Mitch Bradleys
cforth use relocation at
run-time. This avoids many of the complications discussed below (image
files are data relocatable without further ado), but costs performance
(one addition per memory access).
By contrast, our loader performs relocation at image load time. The loader also has to replace tokens standing for primitive calls with the appropriate code-field addresses (or code addresses in the case of direct threading).
There are three kinds of image files, with different degrees of relocatability: non-relocatable, data-relocatable, and fully relocatable image files.
These image file variants have several restrictions in common; they are caused by the design of the image file loader:
ALLOCATEd memory chunks (and pointers to them). And the contents of the stacks are not represented, either.
wordlists for this purpose, you will have no problem, because the hash tables are recomputed automatically when the system is started. If you use your own hash tables, you will have to do something similar.
XORed addresses. You could represent such lists as singly-linked in the image file, and restore the doubly-linked representation on startup.(8)
docol:cannot be represented in the image file (because their tokens would be replaced by machine code in direct threaded implementations). As a workaround, compute these addresses at run-time with
>code-addressfrom the executions tokens of appropriate words (see the definitions of
docol:and friends in `kernel.fs').
CODEwords that contain absolute addresses in this form in a relocatable image file. Workarounds are representing the address in some relative form (e.g., relative to the CFA, which is present in some register), or loading the address from a place where it is stored in a non-mangled form.
Go to the first, previous, next, last section, table of contents.