Digest #269 2024-07-11

Contributions

[350] 2024-07-10 09:40:03 albert wrote:

comment - SAVE-INPUT

If you have a Forth that always slurps the file for including and lock blocks that are interpreted in memory, life becomes much easier. I remembered testing properly handling exceptions coming from a string evaluated from a block that you have loaded from a file. That was in transputer forth and Marcel Hendrix was able to pull that off. I am not sure I could do that flawlessly in ciforth and honestly I'm not sure tforth was defect-free despite the elaborate testing. If everything is in memory you can get away with SAVE and RESTORE. The remember the start and end and the current parsepointer, and restoring it is a breeze. E.g. : EXECUTE-PARSING ROT ROT SAVE SET-SRC CATCH RESTORE THROW ; A simple exeampe counting words in a string
SAVE SET-SRC 0 BEGIN NAME NIP WHILE 1+ REPEAT RESTORE shows that you don't have to manipulate execution tokens, as long as SET-SRC can make a given string the input buffer. I can't propose to replace SAVE-INPUT and RESTORE-INPUT by SAVE and RESTORE, because not having REFILL and line by line compilation is too revolutionary. Most modern Forth will slurp files for include nowadays, however.