Post Reply 
FORTH for the HP 50G
09-28-2022, 03:08 PM
Post: #1
FORTH for the HP 50G
For fun, I ported a simple C implementation of FORTH to the HP 50G and made a video to demonstrate it.

The performance is surprisingly good and solves N-Queens for an 8x8 board in less than 2.5 seconds which is almost as fast as native SysRPL.

Standalone download included.

Happy to receive any feedback which may spur me on to make further enhancements :-)

There's bound to be bugs still and the memory management/allocation is not perfect but see how you go.

Regards, dmh




Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
09-28-2022, 11:52 PM
Post: #2
RE: FORTH for the HP 50G
Very nice!
Which Forth source are you using?
How to view a list of defined words? I've tried WORDS and VLIST, without success.
I found a bug: 16384 2 * . gives --.)*(

Jean-Charles
Find all posts by this user
Quote this message in a reply
09-29-2022, 12:09 AM
Post: #3
RE: FORTH for the HP 50G
Thanks - such a simple test too that I didn't try :-).

The default cell size is 16 bits and signed so this calculation is on these limits (note 16383 2 * . works). I'm not sure how FORTH typically handles this but it may not be consistent with all implementations. I will have a look into it though.

I have noticed that many FORTH implementations don't have a standard way of listing words and this implementation doesn't include one either.

What is the defacto standard for this? I've also noticed some list new words and some list all.

I will look at adding this pending some research and further feedback.

The implementation is based on lbForth.

Thanks for your feedback.

(09-28-2022 11:52 PM)Helix Wrote:  Very nice!
Which Forth source are you using?
How to view a list of defined words? I've tried WORDS and VLIST, without success.
I found a bug: 16384 2 * . gives --.)*(

Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
09-29-2022, 12:33 AM
Post: #4
RE: FORTH for the HP 50G
BTW, I have built a version using 32 bit default cell size which is much nicer for calculations but the memory use/management blew out and the code comments suggest it expects 16 bits so I'm not sure it will fully cope with the larger size (ie may introduce further bugs/issues as this wasn't expected).

(09-28-2022 11:52 PM)Helix Wrote:  Very nice!
Which Forth source are you using?
How to view a list of defined words? I've tried WORDS and VLIST, without success.
I found a bug: 16384 2 * . gives --.)*(

Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
09-29-2022, 10:14 PM
Post: #5
RE: FORTH for the HP 50G
(09-29-2022 12:09 AM)dmh Wrote:  The default cell size is 16 bits and signed so this calculation is on these limits (note 16383 2 * . works). I'm not sure how FORTH typically handles this but it may not be consistent with all implementations. I will have a look into it though.

I have several Forth systems that I can test with Dosbox, and they all give -32768 as a result for this operation, which seems logical.
The standard however doesn’t precise the behavior, if I understand correctly:
https://forth-standard.org/standard/core/Times


(09-29-2022 12:09 AM)dmh Wrote:  I have noticed that many FORTH implementations don't have a standard way of listing words and this implementation doesn't include one either.

What is the defacto standard for this? I've also noticed some list new words and some list all.

Again, all the Forth system I know give the entire list of words.
https://forth-standard.org/standard/tools/WORDS

I don't know how lbforth is built. I see that WORDS is defined in this file:
https://github.com/larsbrinkhoff/lbForth.../tools.fth
Does that mean that only a few words are available, and that other words must be compiled?

I've noticed that when Forth is terminated with BYE, all definitions are lost. Maybe it's expected, but it's not convenient Wink

Jean-Charles
Find all posts by this user
Quote this message in a reply
09-30-2022, 07:11 AM (This post was last modified: 09-30-2022 03:00 PM by dmh.)
Post: #6
RE: FORTH for the HP 50G
Here is WORDS. I'll add it to the next update. In the meantime add to string before starting FORTH:

Code:

: WORDS HERE CELL - @ BEGIN DUP CELL + DUP 1+ SWAP C@ 31 AND TYPE SPACE @ DUP @ 0= UNTIL CELL + DUP 1+ SWAP C@ 31 AND TYPE ;

The result you get makes sense but from further research (not just FORTH) it appears the result for this is undefined which means anything could be returned I guess.

Yes, state isn't saved when you quit (BYE), as per original version, sorry. I guess I would add everything to the load string but that doesn't help while you are developing something interactively.

Options I guess are saving the actual memory state or decompiling it back to a string to put on the stack. First option sounds easier :-)

Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
09-30-2022, 12:13 PM
Post: #7
RE: FORTH for the HP 50G
Although the result is undefined, the following will give the result you expect / seems logical and I'll update in the next version.

Code:
: .POS BASE @ /MOD ABS ?DUP IF RECURSE THEN ABS .DIGIT ;
: . .SIGN DUP IF .POS ELSE .DIGIT THEN ;
: . . SPACE ;

(09-28-2022 11:52 PM)Helix Wrote:  Very nice!
Which Forth source are you using?
How to view a list of defined words? I've tried WORDS and VLIST, without success.
I found a bug: 16384 2 * . gives --.)*(

Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
10-01-2022, 05:14 PM
Post: #8
RE: FORTH for the HP 50G
(09-30-2022 07:11 AM)dmh Wrote:  Here is WORDS. I'll add it to the next update. In the meantime add to string before starting FORTH:

Code:

: WORDS HERE CELL - @ BEGIN DUP CELL + DUP 1+ SWAP C@ 31 AND TYPE SPACE @ DUP @ 0= UNTIL CELL + DUP 1+ SWAP C@ 31 AND TYPE ;

Thank you!
It works, but only a part of the list is displayed. I could certainly try to modify this defenition, but I guess you are more familiar with Forth than me. Wink

Jean-Charles
Find all posts by this user
Quote this message in a reply
10-02-2022, 01:50 AM
Post: #9
RE: FORTH for the HP 50G
The list looked complete to me but scrolled off the top of the screen. Did you see it scroll?

Also, I noticed the lbForth link you posted is a totally different lbForth so the definitions won’t be the same. This one is designed to be small and portable.

(10-01-2022 05:14 PM)Helix Wrote:  
(09-30-2022 07:11 AM)dmh Wrote:  Here is WORDS. I'll add it to the next update. In the meantime add to string before starting FORTH:

Code:

: WORDS HERE CELL - @ BEGIN DUP CELL + DUP 1+ SWAP C@ 31 AND TYPE SPACE @ DUP @ 0= UNTIL CELL + DUP 1+ SWAP C@ 31 AND TYPE ;

Thank you!
It works, but only a part of the list is displayed. I could certainly try to modify this defenition, but I guess you are more familiar with Forth than me. Wink

Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
10-02-2022, 12:49 PM
Post: #10
RE: FORTH for the HP 50G
(10-02-2022 01:50 AM)dmh Wrote:  The list looked complete to me but scrolled off the top of the screen.

That's precisely the problem! The list scrolls too fast and can't be stopped.
So, I will reformulate my question: where can I find a complete list of available words?

Jean-Charles
Find all posts by this user
Quote this message in a reply
10-02-2022, 12:57 PM
Post: #11
RE: FORTH for the HP 50G
Here you go. I guess it needs a scroll bar or paging.

Code:
 OK
: WORDS HERE CELL - @ BEGIN DUP CELL + DUP 1+ SWAP C@ 31 AND TYPE SPACE @ DUP @ 0= UNTIL CELL + DUP 1+ SWAP C@ 31 AND TYPE ;
 OK
WORDS
WORDS DMAX DMIN D0= MAX MIN COUNT ( ." s" ALIGN TYPE .S ? . .R DIGITS COUNTPOS . 
.POS .SIGN .DIGIT DABS ABS SPACES I +LOOP LOOP DO UNLESS REPEAT WHILE AGAIN UNTIL
 BEGIN ELSE THEN IF 2VARIABLE VARIABLE 2CONSTANT CONSTANT DOCOL RECURSE [CHAR]
 [COMPILE] +! D2/ 2* 2/ 2- 2+ 1- 1+ 0>= 0<= >= <= <> 0> 0< 0= FALSE TRUE ALLOT 
CELLS DNEGATE NEGATE SPACE CR BL MOD / TUCK 2NIP NIP 2DROP 2DUP OCTAL HEX 
DECIMAL 2ROT 2OVER 2SWAP D/ D* D- D+ DU< D> D< D= */MOD */ XOR NOT LITSTRING 
DSP@ S0@ ?DUP FREE IMMEDIATE 0BRANCH BRANCH OR AND > < = KEY? ' J R@ >R R> ; : 
LIT HIDE CREATE ] [ ROT /MOD * - + STATE BASE HERE LATEST BYE NUMBER QUIT EXIT >CFA
 FIND WORD C, , OVER DROP DUP SWAP EMIT KEY C! C@ ! @ CELL RUNDOCOL OK

(10-02-2022 12:49 PM)Helix Wrote:  
(10-02-2022 01:50 AM)dmh Wrote:  The list looked complete to me but scrolled off the top of the screen.

That's precisely the problem! The list scrolls too fast and can't be stopped.
So, I will reformulate my question: where can I find a complete list of available words?

Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
10-02-2022, 02:14 PM
Post: #12
RE: FORTH for the HP 50G
thank you!

Jean-Charles
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)