6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 12:33 am

All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Fig Forth Vocabulary
PostPosted: Thu Jan 19, 2017 6:19 am 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
I'm looking at the Fig Forth 6502 source code. I recall seeing this before when I was doing my port, but I'm looking at it again.

If you look at the Fig Forth source, in Forth, you come across this definition for VOCABULARY:

Code:
: VOCABULARY  ( CREATE VOCAB WITH 'V-HEAD' AT VOC INTERSECT. *)
        <BUILDS  A081  ,  CURRENT  @  CFA  ,
        HERE  VOC-LINK  @  ,  VOC-LINK  !
        DOES>  2+  CONTEXT  !  ;

The machine code is essentially a literal translation of this:
Code:
;
;                                       VOCABULARY
;                                       SCREEN 53 LINE 4
;
L2321     .BYTE $8A,'VOCABULAR',$D9
          .WORD L2309    ; link to IMMEDIATE
          .WORD DOCOL
          .WORD BUILD
          .WORD LIT,$A081
          .WORD COMMA
          .WORD CURR
          .WORD AT
          .WORD CFA
          .WORD COMMA
          .WORD HERE
          .WORD VOCL
          .WORD AT
          .WORD COMMA
          .WORD VOCL
          .WORD STORE
          .WORD DOES
DOVOC     .WORD TWOP
          .WORD CON
          .WORD STORE
          .WORD SEMIS

And here we see the implementation, in machine code, of the word FORTH, which is a VOCABULARY:
Code:
L2346     .BYTE $C5,'FORT',$C8
          .WORD L2321    ; link to VOCABULARY
FORTH     .WORD DODOE
          .WORD DOVOC
          .WORD $A081
XFOR      .WORD NTOP     ; points to top name in FORTH
VL0       .WORD 0        ; last vocab link ends at zero

My question.

Does any one have ANY idea of what the $A081 is for. It looks sinisterly like a magic number.

In 6502, it's simply LDY#81. Which is fine, but what is it doing here? I can't see why anything would jump to this? There's no code surrounding it. It's not an address -- the Fig listing doesn't go that high (and who would hard code an address like that).

Also, Y is a scratch register in Fig.

So, I was trying to grok out vocabularies, and this just stands out like a big shiny red history eraser button, look but don't touch, and I was curious what it could be for.


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Thu Jan 19, 2017 6:33 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
whartung wrote:
... Does any one have ANY idea of what the $A081 is for. It looks sinisterly like a magic number.

In 6502, it's simply LDY#81. Which is fine, but what is it doing here? I can't see why anything would jump to this? There's no code surrounding it. It's not an address -- the Fig listing doesn't go that high (and who would hard code an address like that).
...

I don't know enough about how <BUILDS and DOES> work to be of much help, but maybe it's little-endian, and $A081 is getting "comma"d in as STA ($A0,X) ???

Dr. Brad might be providing related clues here:

http://www.bradrodriguez.com/papers/tcjassem.txt

... but it's a bit too advanced for me to fully grok.

Mike B.


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Thu Jan 19, 2017 7:21 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
When FIG was publishing Forth Dimensions magazine and I was taking it the last few years it was being put out, there was an old man, Walter J. Rottenkolber, who had, in nearly every issue IIRC, a short, practical article. It was always really good stuff, and never terribly complicated. Brad Rodriguez undoubtedly remembers him, and may be able to tell us if he's still alive. I sent Mr. Rottenkolber a letter asking about this (it was over 20 years ago, before we all had email—or at least before he did), and he sent the attached response which I just now scanned. If he's still alive, I'm sure he would enjoy the credit and the fact that his work is still promoting Forth here. Shucks—I see in the preview that the pages show up in reverse order.


Attachments:
RottenkolberA081-4.gif
RottenkolberA081-4.gif [ 35.95 KiB | Viewed 10886 times ]
RottenkolberA081-3.gif
RottenkolberA081-3.gif [ 89.11 KiB | Viewed 10886 times ]
RottenkolberA081-2.gif
RottenkolberA081-2.gif [ 142.34 KiB | Viewed 10886 times ]
RottenkolberA081-1.gif
RottenkolberA081-1.gif [ 87.9 KiB | Viewed 10886 times ]

_________________
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  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Thu Jan 19, 2017 7:36 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Ah, well done Garth! Walter might be about 81 years old, and living in Visalia, CA. So the $81 $A0 is a decorated name field for a word with the name {space} ... at least I was slightly on track with my little-endian comment.

Mike B.


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Thu Jan 19, 2017 7:42 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
He was in Mariposa, CA at the time, and seemed to be about that age at the time also. It's probably not a very common name though, so if you looked him up, that's probably the man. Or, maybe it's his son!

_________________
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  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Thu Jan 19, 2017 6:22 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Garth, that is amazing.

I suspected that it might be a name as well, but how it was used, I couldn't say -- I hadn't followed through the search logic.

It would not surprise me if you were the only person on earth right know who knows this bit of Forth lore. :) Thanks for sharing it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Thu Jan 19, 2017 10:00 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
whartung wrote:
Does any one have ANY idea of what the $A081 is for. It looks sinisterly like a magic number.

One way to unravel this is to follow through the search logic, just as you say. Trace what (FIND) does. The $A081 links a branch vocabulary to its trunk vocabulary -- and (FIND) is what traverses all the links, including those between vocabulary chains. So just pick a test case for (FIND) and follow how it jumps through the little hoop. :)

I documented FIG vocabulary linking for myself in 1985, and I expect many others did the same. FIG was quite a popular Forth back in the day. But FIG doc left a great deal unsaid!

PS- Thanks for scanning and sharing Mr Rottenkolber's explanation, Garth! And the 2nd-last paragraph is food for thought. I wasn't aware of the alternative approaches used by Forth-79 and Forth-83.

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Thu Jan 26, 2017 9:47 pm 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
RottenkolberA081-2.gif wrote:
I don't know what the designers of figForth intended the Voc-link pointer to be used for since it links vocabs. by the order in which they are defined, and not the branch sequence. Some Utility words apparently find a use for it.

I've just been going through the Forth Dimensions archive (http://forth.org/fd/FDcover.html), and FD II/6 has an article by Dave Kilbridge titled "Forgiving FORGET" that uses VOC-LINK to make FORGET a lot more robust than in the original implementation... but the link apparently already existed at that time. FORGET itself is the only reference to VOC-LINK in the forth65.zip archive available here, but I get the distinct feeling that there's a source block file or similar (not found with a few minutes of searching) that could contain more information (or a more authoritative source for the FIG model). Additionally, the implementation of FORGET in forth65 differs from both versions presented in FD II/6.

Update, 2017-01-26: I did end up finding some version of the source block file, dated May 1979, as part of a PDF scan of the fig-FORTH manual set. It's even a 6502 version of the system, though it seems incomplete (it uses some assembler syntax, but lacks an assembler implementation, for example). The supplementary blocks that define an editor go to the trouble of updating the "cold-init" copy of VOC-LINK, and the tail end of the system source likewise, but nothing seems to use it (and the version that I found seems to pre-date FD II/6). Overall, what I found looks as though it is intended to be metacompiled, but lacks the metacompiler and assembler.


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Fri Jan 27, 2017 5:27 am 
Offline

Joined: Tue Jun 08, 2004 11:51 pm
Posts: 213
Meta compiling is the easiest way to create a Forth, if you have a working
Forth someplace.
Using an assembler is always a pain.
Keeping track of links and such it a pain in the assembler but one can write
a simple compiler to do all that for you in Forth.
The 80A1 is a magic number as mentioned. It is just there as an end of
a linked list. One need a way to know when you are at the end.
As was mentioned it is 20H and not a valid word.
The original fig Forth allowed one to create nested vocabularies and allowed
one to bounce around from vocabulary to vocabulary at will.
This was always an a problem for 'forget' that just trashed everything after a
certain address. If there were mixed vocabularies in that address space, searches
of those other vocabularies would crash. fig Forth had no protection for this.
Most Forths have no protection either. 'forget' is a dangerous word.
Used with care it can be handy.
If you intend to create words that are for temporary use, it is better to move the
compiling pointer off someplace and have a special word to unlink them when
no longer needed.
Such unlinking is implementation dependent but not all that hard.
An example of doing such is that you might have the assembler off someplace
and create a number of assembly level words and when done with the assembler,
you just unlink it to free that space for data or other use. It can be compiled in
a space not part of the rest of the Forth words.
Dwight


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Fri Jan 27, 2017 6:24 am 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
And I just got to FD III/5 in my read-through of FD, and with it the Ragsdale 6502 assembler, which looks as though it corresponds with the assembler syntax for the fig-FORTH source that I found, and the given block numbers in the listing fit in the gap between the end of the system source and the start of the editor source, and the dates in the block comments match up with a single exception (one block is marked 79JUN03, where as the system source is given as being from May of that year)... But I'm getting slightly off-topic.

The conclusions that I draw are: First, Ragsdale probably knew what was going on with that VOC-LINK thing as far as FIG is concerned. Second, either it was used in some other FIG-related source that I have yet to find, it was inherited from an even earlier version of the system (the PDP version that DECUS ended up with a copy of, maybe?), or there was a planned use which may never have materialized. Third, "Forgiving FORGET" in FD II/6 could be a rediscovery of the original purpose for VOC-LINK... or "just" a clever use of it post-facto. Fourth, Ragsdale probably (almost certainly?) had a metacompiler (and, if so, there was some way for it to handle forward references in Forth code).

Update, 2017-01-27: The fig-FORTH Installation Manual section for the Glossary has this to say about VOC-LINK:
Code:
VOC-LINK     ---  addr                       U
         A user variable containing the addr-
         ess of a field in the definition of
         the most recently created vocabulary.
         All vocabulary names are linked by
         these fields to allow control for
         FORGETting thru multiple vocabularys.

Sounds like they originally intended the "Forgiving FORGET" in FD II/6, but didn't end up implementing it?


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Fri Jan 27, 2017 1:20 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
I was debating porting F83 to the 6502 using the meta compiler, firing it all up on DOS BOX and scraping the screen files. Just think it's a bit opaque if things go bad, hard to debug -- not sure yet.


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Fri Jan 27, 2017 3:28 pm 
Offline

Joined: Tue Jun 08, 2004 11:51 pm
Posts: 213
In the original fig Meta compiling, there were only a couple
of forward references. As I recall, 'quit' was one of them.
These were handled by an explicit patch at the end of the compile.
There were two ways of doing the meta compile. One with an
offset word that created code that had an offset and required being
moved off to some mass storage before it could be executed.
The other was to recompile above the compiling Forth and then
just starting up the second Forth.
This idea of a second Forth allowed easier debug and testing because
it could be built in parts rather than the entire Forth at once.
One could compile a single screen and test its functioning.
( one of the advantages of screens over streamy storage )
For this reason, most meta compiling was done on the machine
that was targeted. A stripped down Forth was first made that could
handle the meta compiler. It was put on the target and then used
to create the complete target Forth.
I never saw this done but it was often talked about.
I've never done meta compiling on a fig Forth but have used it extensively
when upgrading my NC4000 Forth. I'd often debug on the second
Forth. The primary Forth was ROM'd so was a simple reset away.
It was shadowed into RAM so I had full control. On reset, reads would
read ROM and writes would only write RAM. Once a particular address
was accessed the ROM was turned off. ( NC4000 had not specific I/O map )
By that time I was running in the RAM/ROM overlapped code.
Anyway, the concept of 'current' and 'context' were specifically created
to allow safe meta compiling.
Dwight


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Fri Jan 27, 2017 8:15 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
dwight wrote:
This idea of a second Forth allowed easier debug and testing because
it could be built in parts rather than the entire Forth at once.
One could compile a single screen and test its functioning.
( one of the advantages of screens over streamy storage )

I've done this with text files (and so has Dr. Jefyll), marking blocks as little as a line or even a word (not a screen) at a time, not leaving the text editor, but "printing" the block out to what does the compiling. For a more automatic way where one place in the source code tells Forth to compile another section, without requiring manual intervention, without using screens or INCLude files, and still use text files, I suppose you could use line numbers or some kind of labels the system would search for. It's too far down my list of priorities to ever get to trying it though.

_________________
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  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Fri Jan 27, 2017 9:43 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
I certainly can appreciate using Forth to debug Forth, but there's just getting the fundamentals to work initially to get to that stage.

Brad uses/used F83 to build up a 6809 Camel Forth.

I think it would take a lot of analysis to strip F83 to it's essence for a first go. I mean, maybe not, have to dig in to it.

But I think that would be the way to do it. First have to port the 6502 assembler over there (should be NBD).

I brought this up notably because F83 makes pretty extensive use of Vocabularies (I think it has 4 or 5 in the base image), and those words are kind of mixed in with each other in the source code, so the point about maintaining the Vocabulary chain within an assembly listing rings extra loud with an F83 port.

I guess a good test would be to get a 6502 version metacompiled, and booted, and then have it metacompile itself again and make sure a) that it succeeds and b) that it matches the original one. If that works, probably fair to say the port was reasonably successful.

Once it's ported, then perhaps some work could be done to ANSify it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Fig Forth Vocabulary
PostPosted: Tue Jan 31, 2017 1:23 am 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Stumbled across a nice PDF describing FIG Forth in detail.

https://docs.google.com/file/d/0B_gErHT ... luMUk/edit

It mentions the magic number as a dummy header, but doesn't go in to much more detail (it describes the headers later, but not how this one is special).

But this is an interesting guide, as it's practically a line by line commentary of the FIG system.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

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: