6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 16, 2024 3:49 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Jan 29, 2015 1:01 pm 
Offline

Joined: Wed Feb 05, 2014 7:02 pm
Posts: 158
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 29, 2015 6:03 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8541
Location: Southern California
Brad and probably others can give a better reply than I, but until then, to keep you from waiting:
In ITC, if there's assembly language in the parameter field, it's a primitive, also called a code definition. If the CFA points to assembly language elsewhere (like the address of const being in the CFA in the case of a constant created by CONSTANT), I would still call that a primitive. I can't think of any particular association with whether or not they're defining words. Defining words are normally written in Forth, not assembly. They are secondaries, also called colon definitions. They tend to be IMMEDIATE words that compile something else at compile time.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 30, 2015 5:34 pm 
Offline

Joined: Tue Jan 07, 2014 8:40 am
Posts: 91
cr1901 wrote:
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)?


Well....not exactly. Your understanding above that statement is correct, I think (as I have read it). But there is one more case to consider: the colon definition. In a word which contains high level Forth code, when threading is being used (not STC), the thread is normally contained in that word's parameter field.

The example you gave from Wikipedia, of "push", is an example of a word picking up an inline parameter from a thread. This doesn't require "knowledge" of the parameter field, except in the abstract sense that threads are usually part of a Forth word's parameter field. But some Forth implementations will also use "naked threads" for some purposes, so you can't guarantee that any particular thread is part of a parameter field.

There are also rare cases of primitives that are not part of a defining word, which act directly on the Parameter Field of a Forth word. One common example is the word TO, which in some implementations stores a new value into the Parameter Field of a specified Forth word.

_________________
Because there are never enough Forth implementations: http://www.camelforth.com


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: