I'm currently reading Brad Rodriguez's
Moving Forth articles, and I want to see if I understand something correctly (especially the bold).
Assumptions: I'm ignoring the dictionary header here, which just contains a linked list/metadata for each Forth word. When I say "native code", I mean your CPU's assembly language. Assume CORE words are all coded in ASM. ITC Forth.
All Forth words resolve to an address which points to machine ("native") code to execute that implements the relevant side effects in the Forth VM environment; traditionally, this is known as the Code Field. Some Forth words have code pointed to by their Code Field which require data to operate upon to execute properly as defined. Traditionally, the data to operate upon is placed directly after the Code Field; this data is called the Parameter Field. A Header, a Code Field, and a Parameter Field form the basis of a canonical Forth dictionary definition (
I'm sure there are other ways to do a dictionary, though).
Words that compile directly to native code will not have/
do not need a Parameter Field, and can be fully defined in terms of native code that performs the relevant side effects and jumps to the next location in the thread (in this ITC case, the next location in the thread contains the address of another Code Field). However, some words that are written strictly in native code- called Defining Words- can indirectly (addressing mode) access small snippets (
not the word I'm looking for) of native code which DO assume a Parameter Field exist (DOCON, DOVAR, ENTER are traditional examples). These snippets of native code are NOT pointed to by the Code Field of any word strictly written in assembly. However, Defining Words will create new Forth Words whose Code Field points to these special snippets of native code. The Defining Words will also ensure that the new Forth Words created have the correct Parameter Field, and that the special snippets of native code can correctly access the Parameter Field.
Do I understand the above correctly?
Are Defining Words the only Forth Words coded in ASM that require knowledge of Parameter Fields (in this case, Defining Words create Words with Parameter Field)?
The Parameter Field appears analogous to the second example in the Direct Threading section of the threaded code
Wikipedia article. Push contains the arguments to itself directly within the thread, and the implementation of push makes sure it knows how to get to push's arguments by incrementing the IP, just like native code snippets which need access to the Parameter Field will use an offset from the Code Field pointer to find the Parameter Field. However, these two cases differ in the sense that ITC Forth won't have parameters directly in the thread proper (I don't think literals count, being that they'll be placed on the Parameter Stack prior to being used), like the Wikipedia example, but rather in each definition.