6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun May 12, 2024 3:59 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Forth-83 FORGET
PostPosted: Mon Sep 10, 2018 9:36 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 858
From the Forth-83 standard:
Quote:
FORGET -- M,83
Used in the form:
FORGET <name>
If <name> is found in the compilation vocabulary, delete
<name> from the dictionary and all words added to the
dictionary after <name> regardless of their vocabulary.
Failure to find <name> is an error condition. An error
condition also exists if the compilation vocabulary is
deleted. See: "10.2 General Error Conditions"

I assume that the compilation vocabulary is the vocabulary returned by CURRENT @.
My question is, if <name> is not found in the current vocabulary, can FORGET search the parent vocabulary(ies) of the current vocabulary for <name> or is it limited to only searching the current vocabulary?


Top
 Profile  
Reply with quote  
 Post subject: Re: Forth-83 FORGET
PostPosted: Tue Sep 11, 2018 12:12 am 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 858
Perhaps I should elaborate. My Forth's FORGET starts like this:
Code:
: FORGET  ( -- )
   NAME  CURRENT @ DUP CONTEXT !
   (FIND) 0= ?FIND  >LINK

VOCABULARY is written such that vocabularies are not chained to their parent vocabulary but they do have the address of their parent in their second cell. This is to keep FORGET from finding <name> if it is not defined in the current vocabulary. The high level word FIND takes care of following the chains, but it might be a bit slow:
Code:
: FIND  ( ADR -- ADR2 FLAG )
   CONTEXT
   BEGIN
      @ ?DUP
   WHILE
      TUCK (FIND) ?DUP
      IF  ROT DROP EXIT  THEN
      SWAP 2+
   REPEAT
   CURRENT @ (FIND) ;

If the standard permits FORGET finding <name> in the current vocabulary or one of its parent vocabularies, I would like to rewrite VOCABULARY so that vocabularies are more like the the fig Forth model. I could then change FIND to:
Code:
: FIND  ( ADR -- ADR2 FLAG )
   CONTEXT @ (FIND)
   ?DUP 0= 0EXIT
   CURRENT @ (FIND) ;

By the way, 0EXIT is a code word that exits if the top of the stack is false
0EXIT ( FLAG -- )

This is why I would appreciate some clarification on the Forth-83 standard's meaning concerning FORGET.

[EDIT:] Problem solved with a little creative rewriting of the find primitive and adding a new primitive VFIND which only finds a name in a given vocabulary. VFIND has no parameter field. Its code field points one byte into (FIND)'s parameter field.


Top
 Profile  
Reply with quote  
 Post subject: Re: Forth-83 FORGET
PostPosted: Thu Oct 04, 2018 9:30 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 858
When FORGET is used, all words, including vocabularies, that are defined after the forget point ( word to be forgotten ) are forgotten as well. The vocabulary structure in my Forth is a tree. Forth is the root vocabulary. A new vocabulary's parent vocabulary ( the one searched after the new vocabulary is searched ) is the vocabulary where it was defined.
These are the features of FORGET in my Forth:
Sets CONTEXT equal to CURRENT incase the context vocabulary is forgotten. This could be changed so that only if the context vocabulary will be forgotten will CONTEXT be set equal to CURRENT.
Only searches the CURRENT vocabulary.
Prunes VOC-LINK so that the latest defined vocabulary that will not be forgotten will be the latest vocabulary in the link, the one VOC-LINK points to.
Follows VOC-LINK and prunes all remaining vocabularies.
If any of the kernel defered words has a 'vector' that will be forgotten, FORGET resets that defered word to its default value. This is handled with a table and a DO LOOP to keep it small.
It has an internal fence ( a literal in the definition of FORGET ) as well as the variable FENCE. The forget point must be above both of them or FORGET aborts with the message "PROTECTED".

I think this is a safe FORGET, but can it be made better?

A little information about EMPTY, the word to reset the dictionary to its bootup state, or smaller.

There is a place in the definition of FORGET just after the word to be forgotten has been found, the word's link field address is on the stack. This Forth's EMPTY branches to that address after doing the following. It fetches the 'empty address' from a location in the boot area and takes the unsigned minimum of it and HERE. It then stores a copy of that value in the 'empty address' location. Finally, it executes FORTH DEFINITIONS before branching to FORGET with that value on the stack.

Any suggestions? Ideas for improving both FORGET and EMPTY?


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 4 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: