news:36148df9-ee6c-43b3...@d17g2000yql.googlegroups.com...
>
> Don't confuse the behavior of the words with the implementation of the
> words ~ a danger if you are implementing a Forth without first
> programming a couple of applications in Forth.
If my implementation correctly implements the behavior of the words, does it
matter if I confuse them?
E.g., if my Forth eventually becomes ANS and passes the Hayes core tests,
does it matter if I "wrongly" implemented the functionality of some words?
I.e., a word may have an understanding, or specification meaning, or
historical meaning that is not captured by the tests or implemented by me,
but passes the test. If so, is the error on my side or the compliance suite
side? I think it's the latter ... I have been attempting to capture the
essence of various words as they were implemented in other older Forths.
Sometimes they all do things the same way and other times it's wildly split
as to what was done and what works.
> > AIUI, DOVAR and @ can be equivalent to DOCON. DODOES
> > performs DOVAR as part of it's functionality.
>
> In that approach ~ which again, is an *implementation* approach not a
> language behavior design question ~ DODOES is not in the CFA in any
> event. Its compiled as a code stub in the word that contained DOES> to
> start up the interpreting of the following section, and the CFA
> contains a pointer to that code.
Ok. Mine works a bit differently, currently.
I have a CFA routine which I call DODOES. It gets the address for the "code
stub in the word that contained DOES> to start up the interpreting of the
following section" which I'll refer to as after-DOES> address hereafter.
The after-DOES> address is compiled by DOES> into a word's PFA. DOES> also
compiles DODOES into the CFA. AIUI, I have to compile the after-DOES>
address into the PFA due to my use of C. I describe my implementation in
some depth, after which I have a question about using , COMMA with CREATE
and DOES> prior to the DOES> which could break my implementation.
It's in C not assembly, so I can't put "raw" jump-to addresses into the CFA.
If it were in assembly, the CFA could be set to any address where a valid
assembly routine exists. I.e., for assembly that works that way, the CFA
can be set to the exact starting point of the after-DOES> code. It just
jumps there using the CFA value. Since mine is in C, the CFA must point to
a valid C routine. I can't place a C routine inlined with the after-DOES>
code and call that routine. I don't have a built-in C compiler in my Forth
interpreter. So, I can't create address values at runtime for the CFA. All
CFA values must be known at compile time. This means I have a limited and
fixed set of legitimate CFA values, unlike an assembly implementation which
could have a huge number of them. In this case, that means one of my
primitive (low-level) routines is used for CFA's: DOVAR DOCON DOCOL
DODOES etc. The after-DOES> code is in compiled Forth as interpretable
addresses. That means I have to have a routine which interprets the
addresses there. DOCOL (or ENTER) does just that, but it needs to be
redirected to the after-DOES> code. So, DODOES is a routine that gets
the address for the after-DOES> code from within the word compiled using
DOES> and does the redirection.
Currrently, my DOES> looks like this:
: DOES> R> , LIT DODOES LAST @ CFA ! ;
Recently, I was able to implement it as a defintion in ASCII text. It's
definition was changed recently too. I broke it a while back and just fixed
it. fig-Forth has a SMUDGE in it. I don't yet. Obviously, the R>
indicates it's an interpreted Forth, in this case ITC. LAST is probably
non-standard. I'd have to recheck was LAST is supposed to do ... Due to
implementation issues, I have both LAST and LATEST. LATEST is only for the
NFA. Actually, LATEST for the dictionary bits that are normally part of the
NFA, but I needed to relocate away from the name portion of the NFA. LAST
gets the address of the start of current dictionary entry. LAST is that
address no matter how I reorganize the dictionary structure. It could be
NFA, LFA, CFA, or PFA. I had LFA's first, but that caused an issue with a
fig-Forth like definition when I converted from word-by-word parsing to
line-by-line. So, I reorganized with NFA first, at least temporarily. The
sequence "LAST @ CFA !" stores DODOES into the CFA overwriting a
DOVAR put there via CREATE. The sequence "R> ," stores the address of
the after-DOES> code in the PFA.
DODOES is a primitive (low-level word) in C. It's placed into the CFA.
When executed instead of ENTER or DOCOL, it pushes the W register onto
the data/parameter stack. W register is the current instruction pointer for
the interpreter. DODOES then pushes the 1st PFA value onto the return
stack. That value is the address that DOES> comma'd into a definition.
It's the address of the after-DOES> code.
Since I'm storing the address of the after-DOES> code in the PFA, I suspect
that a , COMMA could insert values prior to the stored after-DOES> address.
In which case, DODOES would fail. It doesn't "know" that the after-DOES>
address is not in the location it expects. Is it valid to use , COMMA
between CREATE and DOES> ? If someone knows of valid, functional examples
of a , COMMA being used between CREATE and DOES> in a word, could you
post them? I'll need something to break and/or test with.
> But if its indirect or direct threaded, and you were trying to bring
> up fig-Forth fashion, but with a minimum of code, you COULD have a
> stub in the coded section that does:
>
> DOVAR:
> CALL DODOES
> .WORD FETCH,EXIT
>
> ... and that's your DOVAR.
Did you mean DOCON due to the FETCH?
Well, either way, that won't work in my current implementation. Both DOCON
and DODOES manipulate the return stack, while DOVAR doesn't. DOCON
continues execution after the constant. DOVAR doesn't. DODOES continues
execution at the after-DOES> address stored in the word by DOES>, i.e., the
DOES> "jump-to" address is in the 1st PFA. All three are primitives
(low-level words).
> It depends on what your objectives are.
My current main objective is to reduce my set of primitives and pre-compiled
Forth code. I'm migrating to Forth words in ASCII text. The issue I'm
having is the parsing words are needed to parse words in ASCII text, i.e.,
catch-22. I may actually have to add some primitives that I didn't
implement since there is no easy way to implement them in high level Forth.
Rod Pemberton