6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 1:27 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Sun Jan 10, 2021 6:18 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
After disassembling the full Forth system and gaining a fairly good working knowledge of Forth, I have always felt that Forth could be stripped down even more.

I started separating all the word dependencies and have come to realize that the Interpreter, itself, is only dependent on a few words. This is great because the goal is to write applications or games with Forth, and once the game or application is complete, the Interpreter words are no longer needed. But stripping out the Interpreter and moving the program down to close up the space, looked like a real chore to have to readjust all the links.

As I moved the source code around and studied the Interpreter words, it became obvious that the Interpreter did not need to be part of the Forth system to do its job. With the Interpreter moved out of the way, OS words were then moved on top of the Forth system. I now have a stripped-down Forth system without an Interpreter, Editor or Assembler, but with disk-access words added on.

I am getting to a place where I want to be with Forth. With the Interpreter moved out of the way, I can now start building an application or game and just have the basic Forth needed to run the program.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 10, 2021 7:08 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
Are you talking about a metacompiled system where you can also compile headerless code since FIND will never be needed to look up words? That saves a very significant amount of memory, not just because you don't have INTERPRETER, FIND, COMPILER, COMPILE, ,, ALLOT, :, ], etc., but more than that, all the memory taken by headers. You can deliver applications where the user has no need to interpret or compile, and in fact doesn't even need to know that the application was written in Forth.

_________________
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: Mon Jan 11, 2021 12:18 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
GARTHWILSON wrote:
Are you talking about a metacompiled system where you can also compile headerless code since FIND will never be needed to look up words? That saves a very significant amount of memory, not just because you don't have INTERPRETER, FIND, COMPILER, COMPILE, <comma>, ALLOT, <colon>, ], etc., but more than that, all the memory taken by headers. You can deliver applications where the user has no need to interpret or compile, and in fact doesn't even need to know that the application was written in Forth.

I won't need a metacompiler. I can still make a headerless Forth with the use of FIND and INTERPRET. In another thread I mentioned using an insertion sort to sort words. The words are passed to the insertion sort with a beginning length byte and the CFA pointer after the word. The insertion sort not only inserts words into the sorted dictionary, but can also find any word and return the CFA after the word. The CFA obviously pointing to the actual code in the Forth system.

Because the words are sorted alphabetically, they can then be searched using a binary search method, which means they don't require the Link Field (LFA). It becomes even more handy for me that I can move the Interpreter to anywhere in memory, because the insertion sort can be part of the interpreter. I have not decided where to move it yet, because once the Interpreter is compiled at a certain location, it will have to stay there. I may end up with the Interpreter compiled at a couple of different locations, depending on how memory restrictions pop up.

Anyone wondering how I plan on compiling the interpreter without the Interpreter as part of the Forth system?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 11, 2021 12:30 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
IamRob wrote:
Because the words are sorted alphabetically, they can then be searched using a binary search method, which means they don't require the Link Field (LFA).


In traditional Forth, if a word is redefined, the more recent one is found.

Does your implementation guarantee that?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 11, 2021 1:54 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
BillG wrote:
IamRob wrote:
Because the words are sorted alphabetically, they can then be searched using a binary search method, which means they don't require the Link Field (LFA).


In traditional Forth, if a word is redefined, the more recent one is found.

Does your implementation guarantee that?

Not sure what you mean by traditional Forth as, there is almost certainly something in one standard that ends up broken in another standard. But there is always work-arounds.

With an insertion sort, normally there wouldn't be two words with exactly the same name, since with a search by the name itself, it would not be easy to distinguish the two word definitions apart. But I made it flexible enough that it could be programmed to check the words before and after the matching word, and only if they are the same, it can then compare the CFA addresses. It could then return the word with the CFA address that is higher in memory.

Unless the insertion sort method became popular, I probably wouldn't program it to do that as I am not a fan of having the same word with two different meanings. Instead I prefer to append a sequential number after the word if it already exists. This has the added benefit of being allowed to be inserted in the dictionary, and also lets me know as a programmer that there is more than one definition with the same name and to which one the listing is referring to.

It won't matter in the final compilation, as the code will be exactly the same.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 13, 2021 11:51 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
IamRob wrote:
With an insertion sort, normally there wouldn't be two words with exactly the same name, since with a search by the name itself, it would not be easy to distinguish the two word definitions apart. But I made it flexible enough that it could be programmed to check the words before and after the matching word, and only if they are the same, it can then compare the CFA addresses. It could then return the word with the CFA address that is higher in memory.

Unless the insertion sort method became popular, I probably wouldn't program it to do that as I am not a fan of having the same word with two different meanings. Instead I prefer to append a sequential number after the word if it already exists. This has the added benefit of being allowed to be inserted in the dictionary, and also lets me know as a programmer that there is more than one definition with the same name and to which one the listing is referring to.


Some Forth systems have a word VALUE that creates a word that, like a constant, returns it's value. Such words can be set with the word TO .
Code:
: TO  ( N -- )
   ' DUP @ [ ' #BUF @ ] LITERAL <>
   ABORT" NOT TO-ABLE"
   STATE @
   IF
      COMPILE (TO) , EXIT
   THEN
   >BODY ! ; IMMEDIATE

Suppose someone thinks that a double value, created with a new word 2VALUE would be a useful addition. This someone also thinks that it would be nice to set it with the same word TO .
Code:
: TO  ( D -- )
   <test if word is not a child of 2VALUE>
   IF  [COMPILE] TO EXIT  THEN  \ not a child of 2VALUE so call original TO and exit.
   STATE @
   IF
      COMPILE (2TO) , EXIT
   THEN
   >BODY 2! ; IMMEDIATE

Now suppose that someone finds that a version of VALUEs for floating point numbers would be useful.
Code:
: TO  ( FLOAT -- )
   <test if word is not a child of FVALUE>
   IF  [COMPILE] TO EXIT  THEN  \ not a child of FVALUE so call previous TO and exit.
   STATE @
   IF
      COMPILE (FTO) , EXIT
   THEN
   >BODY 2! ; IMMEDIATE

For each type of a VALUE word, the same 'syntax' is used: <some value> TO <some value word>.
Code:
4 TO #BUF
31415926. TO DOUBLE.VAL.PI
1.234E5 TO SOME.FLOAT.VALUE \ for those Forths that have floats.

Redefining a word is a convenient way to extend the word's functionality at a later date.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 14, 2021 4:54 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Quote:
Redefining a word is a convenient way to extend the word's functionality at a later date.

I guess I have not come across enough ways to extend a word's functionality yet to see any advantage. All I can see right now is that one loses the original word's functionality except to the words that already have been compiled to use it.

And using TO, TO1, TO2 lets me know that I have 3 words whose functionality is very similar, without losing the functionality of any of them.

Don't get me wrong. I am not trying to dissuade any one from doing it. I am just trying to persuade myself which way is actually better for me, and if I am missing something in its use, or lack of.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 14, 2021 6:02 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
JimBoyd wrote:
For each type of a VALUE word, the same 'syntax' is used: <some value> TO <some value word>.
Code:
4 TO #BUF
31415926. TO DOUBLE.VAL.PI
1.234E5 TO SOME.FLOAT.VALUE \ for those Forths that have floats.

I think I see a disadvantage to using methods like this.

I had to ask myself what my ultimate goal was, and the answer to that is, I would like to be able to create a headerless, self contained program in the end. The applications that I have disassembled so far do not have either an interpreter or a compiler, nor an editor or assembler included.

I guess that means the applications I want to create will have only run-time words. I won't be able to do deferred compiling.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 18, 2021 11:53 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
IamRob wrote:
All I can see right now is that one loses the original word's functionality except to the words that already have been compiled to use it.


Since TO is immediate, normally the only words compiled to use it would be later versions of TO and you don't lose the original versions' functionality because their functionality is subsumed in later versions.
There is also the possibility that VALUE , 2VALUE , and other VALUE type words could be creates as multi code field words. These are words with more than one code field. The first code field is executed or compiled unless the word is acted upon by another word.
There is a paper on Multiple Code Field Data Types and Prefix Operators by Klaus Schleisiek here.
If the VALUE type words have multiple code fields, there would only be one version of TO because it would do one of two things:
1) If interpreting, execute the second code field.
2) If compiling, compile the second code field.
In my example of redefining TO for different type of VALUE's , having only one name, TO , has the same usage as the multi code field version of VALUE .


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 20, 2021 8:11 pm 
Offline
User avatar

Joined: Mon May 12, 2014 6:18 pm
Posts: 365
Have you thought much about how to also cut all of the primary words that aren't used in the final program? It could save a lot of space although it would be tough to implement.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 21, 2021 1:27 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Druzyek wrote:
Have you thought much about how to also cut all of the primary words that aren't used in the final program? It could save a lot of space although it would be tough to implement.

Yep! Moving the interpreter and compiler out of the way along with associated words and only leaving the words that a Disk OS is dependent on, reduces the unused words down to a bare minimum. Words that were removed can be added back if the application requires them.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 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: