SamCoVT / TaliForth2

A Subroutine Threaded Code (STC) ANSI-like Forth for the 65c02
Other
28 stars 4 forks source link

All user words are flagged with HC=1 #105

Closed patricksurry closed 1 month ago

patricksurry commented 1 month ago

Learning about header bits: CREATE tags new words with the HC status bit. : uses CREATE to start new user words. It later deletes the default jsr dovar but doesn't unset the HC bit, so all user words seem to collect that flag. Perhaps a side entry point to xt_create could track whether to include the HC/jsr or not, which would also save the effort of reverting it later.

: foo 3 ;  ok
see foo 
nt: 800  xt: 80B 
flags (CO AN IM NN UF HC): 0 0 0 1 0 1 
size (decimal): 8 

080B  A9 03 CA CA 95 00 74 01   ......t. 

80B      3 lda.#
80D        dex
80E        dex
80F      0 sta.zx
811      1 stz.zx
 ok
SamCoVT commented 1 month ago

I'm not exactly sure about the use of that flag, as technically all of the words have a code field in an STC forth. The manual says:

 | HC | Has CFA. Consider first three bytes of the word’s code the Code Field
Area (CFA) of the word. Used by words defined with create so >body returns
the correct value. |

Looking at >BODY, it appears to add three to the xt for these items, and has a note about DOVAR, DOCONST, DODEFER, and DODOES. The comment for that word says:

        ; This is a
        ; difficult word for STC Forths, because most words don't actually
        ; have a Code Field Area (CFA) to skip. We solve this by having CREATE
        ; add a flag, "has CFA" (HC), in the header so >BODY know to skip
        ; the subroutine jumps to DOVAR, DOCONST, or DODOES

That would seem to imply that all words created with CREATE should have HC set, but I can see how : should not leave that bit set. I can't think of a situation where a : defined word would need the flag, so I agree with you that this is a bug.