MMBasic for Windows - betas


Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3927
Posted: 10:59pm 02 Mar 2022      

Picking up from https://www.thebackshed.com/forum/ViewTopic.php?TID=14585&P=7

  matherp said  Going back to the READ issue. How about READ SAVE/RESTORE? These commands could be used by an INC file to save the current datapointer then do the local read, then restore it after. That way the INC could know it was being a good citizen.


Thanks again for implementing this Peter. I did wonder at the time whether I was "just being difficult", but when I switched my encryption code (used by SAAINT) to initialise from DATA statements rather than a "misused" CSUB my unit-tests for that code (which were also using DATA) immediately hit this very issue, so not artifical or made up.

EDIT: Having "played" with it, I'm inclined to think:

1. Report an error when READ RESTORE called without a prior READ SAVE: "READ RESTORE called before READ SAVE"
2. Have READ RESTORE clear the cached state, and have READ SAVE report an error if the cached state isn't clear: "READ SAVE called twice without intervening READ RESTORE"

I think this would help lock the behaviour down and would help avoid breaking any existing programs if in the future it was extended to support multiple levels of READ SAVE (presumably using a stack).

IMHO it's a real pity the global data pointer isn't a single atomic value that could simply be PEEKed and POKEed as that would provide ultimate flexibility for those advanced users who actually need this facility.

YMMV,

Tom
Edited 2022-03-03 09:54 by thwill