6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 1:08 pm

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Sun Jan 20, 2019 9:11 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
As I said, the example is straight out of "Thinking Forth". It's in Appendix B where Leo Brodie explains how DOER/MAKE works and gives implementations for various Forth systems. I don't think any of them were subroutine threaded systems though. I don't know if the Forth you're using is ITC ( indirect threaded ), DTC ( direct threaded ), or STC ( subroutine threaded ), or possibly some other threading technique. I successfully ported DOER/MAKE to my Forth, Fleet Forth for the Commodore 64, a short while ago. It's an ITC Forth. Last night I took a look at Durex Forth for the Commodore 64. It appears to use subroutine threaded code. I managed to port DOER/MAKE to it. Be warned! it has had minimal testing! That said, it should work with other subroutine threaded Forths for the 6502 based processors. Maybe someone using Tali Forth or Liara Forth could test it? :D
Code:
( DOER/MAKE For A Subroutine Threaded Forth)
: NOTHING ;
: DOER
   CREATE ['] NOTHING , DOES>
      @ 1- >R ;
VARIABLE DMARKER  \ Doer marker
: (MAKE)
   R>  1+  DUP 2+ DUP 3 +
   SWAP 1+ @ >BODY !
   @ ?DUP IF  >R  THEN ;
: MAKE
   STATE @ 0= ABORT" COMPILING ONLY!"
   POSTPONE (MAKE)
   HERE DMARKER ! 0 , ; IMMEDIATE
: ;AND
   POSTPONE EXIT
   HERE 1- DMARKER @ ! ; IMMEDIATE
: UNDO
   ['] NOTHING  ' >BODY ! ;

If you've had time to read "Thinking Forth", you'll notice one ability that's missing. The ability to use MAKE outside a colon definition to create an unnamed section of high level code that the DOER word performs. That ability is not needed in the examples I've shown and it would require knowledge of how a given system implements : ( colon) and ; ( semicolon).

Cheers,
Jim

[Edit: Corrected two typos.]


Last edited by JimBoyd on Wed Jan 23, 2019 9:24 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 22, 2019 8:41 pm 
Offline

Joined: Sun May 13, 2018 5:49 pm
Posts: 255
JimBoyd wrote:
Maybe someone using Tali Forth or Liara Forth could test it? :D

It works on Tali, but I had to put a "T" in POSTPONE in two spots and add a definition for 2+. Here's the version that works on Tali Forth 2:
Code:
( DOER/MAKE For A Subroutine Threaded Forth - Tali Forth version)
: 2+ 2 + ;
: NOTHING ;
: DOER
   CREATE ['] NOTHING , DOES>
      @ 1- >R ;
VARIABLE DMARKER  \ Doer marker
: (MAKE)
   R>  1+  DUP 2+ DUP 3 +
   SWAP 1+ @ >BODY !
   @ ?DUP IF  >R  THEN ;
: MAKE
   STATE @ 0= ABORT" COMPILING ONLY!"
   POSTPONE (MAKE)
   HERE DMARKER ! 0 , ; IMMEDIATE
: ;AND
   POSTPONE EXIT
   HERE 1- DMARKER @ ! ; IMMEDIATE
: UNDO
   ['] NOTHING  ' >BODY ! ;


Code:
recital
YOUR DADDY IS STANDING ON THE TABLE.  ASK HIM 'WHY?'  ok
why?
TO CHANGE THE LIGHT BULB.why?
BECAUSE IT'S BURNED OUT.why?
BECAUSE IT WAS OLD.why?
BECAUSE WE PUT IT IN THERE A LONG TIME AGO.why?
BECAUSE IT WAS DARK!


One oddity is that the " ok" message was missing after each run, leaving the cursor just after the printed message but accepting new input. It looks like the OK message is similarly missing in the example from Thinking Forth that JimBoyd showed a few posts back. Tali doesn't normally print carriage returns at the end of a string, so the new "why?" that I typed ended up on the end of each message, but the doer/make behavior seems to be working properly.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 23, 2019 7:45 pm 
Offline

Joined: Sun May 13, 2018 5:49 pm
Posts: 255
SamCoVT wrote:
One oddity is that the " ok" message was missing after each run, leaving the cursor just after the printed message but accepting new input. It looks like the OK message is similarly missing in the example from Thinking Forth that JimBoyd showed a few posts back. Tali doesn't normally print carriage returns at the end of a string, so the new "why?" that I typed ended up on the end of each message, but the doer/make behavior seems to be working properly.


The missing " ok" message is because of the QUIT in WHY?. Sneaking an extra CR in there makes it work identically to the Thinking Forth version.

I changed why? to:
Code:
: WHY? CR ANSWER CR QUIT ;

and now it works like:
Code:
recital
YOUR DADDY IS STANDING ON THE TABLE.  ASK HIM 'WHY?'  ok
why?
TO CHANGE THE LIGHT BULB.
why?
BECAUSE IT'S BURNED OUT.
why?
BECAUSE IT WAS OLD.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 23, 2019 9:36 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
SamCoVT wrote:
It works on Tali, but I had to put a "T" in POSTPONE in two spots and add a definition for 2+.

Oops. I just fixed my typos. I already had DOER/MAKE working on Fleet Forth, an ITC Forth. I didn't know what Forth commodorejohn was using so I ported it to Durex Forth for the Commodore 64 which appears to be an STC Forth. I got frustrated with the Durex editor, specifically how to get out of insert mode and back to the Forth interpreter, so I entered the code interactively. I copied the working code to a text file by hand and somehow missed the 'T' in POSTPONE in both places!


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

All times are UTC


Who is online

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