SamCoVT / TaliForth2

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

Hex digits ED in hex mode can trigger ed editor word #49

Closed bjchapm closed 4 months ago

bjchapm commented 5 months ago

I suppose this isn't really a bug, but it caught me by surprise and took me a while to figure out, so I wanted to mention it. Perhaps it would be something to add to the documentation somewhere.

I was attempting to paste in a previously generated table of CRC-16 CRCs. One of the lines in the table is

C6 c, ED c, E6 c, FD c, 86 c, CD c, A6 c, DD c,

I was already in hex mode. The digits ED will interrupt the data load and cause a cryptic '?' to appear in the console, which was confusing until I remembered the 'ed' editor word. You can enter q to exit ed and get back to a prompt.

Workarounds are:

  1. Not loading the ed line-editor unless you plan to use it. In Tali on the Planck, ed is not loaded; however, the ed word has been left in the header file. This will generate an even more mysterious 'stack underflow' error.
  2. Prefix every hex byte with $, as in $ED. This will work even in hex mode and is probably what I'll do going forward. I did see that this is mentioned under the numbers section at the top of page 16 of the PDF version of the manual. 0ED will also work.
SamCoVT commented 5 months ago

That is an interesting problem - the kind that will be super-confusing for a new person who doesn't know what it going on (ed is confusing enough as it is!).

We could also rename ed to something like tali-ed to make that scenario impossible.

Technically, you can run into this other ways as well. Tali supports up to base 36, but if you set BASE to 36 then any alphanumeric utterance is a valid number if it's not in the dictionary. I do agree that it's annoying for HEX, though, which is a base I would actually expect people to be using. It would be nice if new users did not have to be aware of this.

SamCoVT commented 5 months ago

If ed is removed from assembling using the platform file configuration option TALI_OPTIONAL_WORDS, then it should not show up in the dictionary (the header is also removed by that option). Let me know if that's not the case. It lives in the FORTH wordlist rather than the EDITOR-WORDLIST, and changing that may be a different way to reduce the chance of people stumbling into it.

patricksurry commented 5 months ago

adding a non-alpha might also be good, e.g. ed:. using one or two-letter 'hex' words [a-f]{1-2} as builtins will definitely bite people

SamCoVT commented 5 months ago

I agree. I was thinking of moving it to the EDITOR-WORDLIST, but that just postpones the confusion until someone tries adding that wordlist to their search order. ed: probably isn't good because : is generally reserved for words that create something like buffer:.... although ed does create a string in memory as its result, so maybe ed: does make sense. I'll let that rattle around in my head for a bit, but that's probably a good name.

The manual will need to be updated as well.

SamCoVT commented 4 months ago

Fixed in latest commit - renamed to ed: and updated the documentation.