IamRob wrote:
GARTHWILSON wrote:
JimBoyd wrote:
It's my understanding that fig-Forth does it the other way around. FIND returns the address of a word's body and the word CFA is used to go from the parameter field address to the code field address.
Yes; but what goes the other direction? It's not
PFA, because that takes the NFA to give you the PFA; and
NFA goes the opposite direction. I'm looking in the fig-Forth assembly source code and the installation manual and I'm not finding a word to do that. I guess you're just supposed to know to use
2+.
This kind of confusion is why I am kind of adopting a "best suited" method. Some words don't even have a PFA as the code is or can be redirected to elsewhere in memory.
My Forth breaks more if I use
: PFA CFA 2+, so I rewrote it so that FIND returns the CFA, then to get the PFA it is just
: PFA CFA @. Even with an STC forth, PFA, instead of being 3+, could be made to work with CFA @, without breaking STC or DTC portability.
I don't know, but I think this seems to be an easier port between different threaded Forths.
After reading some other topics and finally understanding them, I see that
>BODY makes sense if only used with words without
CODE.
Since
>BODY can damage a code word, wouldn't it be more prudent to define
>BODY to only allow a change to the body of a word if that word is a
COLON word? Maybe something like this:
: >BODY ( cfa --- ) DUP @ [ ' DO @ ] = IF 2+ ELSE DROP # ERROR THEN ;
it seems to me that any word that can cause damage, or allow to cause damage, to another word (by human error) should have at least a little error checking.