Something I'm thinking about, maybe someone who has implemented a Forth can help me out a bit. Assume an ITC Forth.
ANS Forth requires that the Forth interpreter start by awaiting input from an interactive device.
From what I gather looking at Forth source code, Forth programs are created by compiling their own custom definitions into the dictionary and then stringing definitions together. Typically, the final word to be compiled could be considered analogous to "program invocation"; the entire program is compiled into a single word in the dictionary that executes/encompasses all the required Forth words. In effect, you create each program you want to use before invocation by feeding in source code (pretty cool). So unless you have a smart terminal emulator with copy/paste, a block device, a file device, or a second input device that can send/receive ASCII, one is expected to manually compile a Forth program before running it
one line at a time. Additionally, a program cannot be invoked automatically- after compilation, one is expected to invoke the program manually (unless you include a line to run the previously compiled code at the end
).
For an environment where one might to save code between power on and power off, or want code to run automatically in response to external non-interactive events (i.e. power on, reset, timer int), I can see this becoming tedious/limiting very quickly. Waiting for compilation could become tedious. It feels as if Forth could use an autoinit to bootstrap more (pre-compiled) definitions.
This leads me to two questions:
- Does ANS Forth have provisions to load a previously compiled source file (input source doesn't matter, but in my case it's the serial console repurposed for binary transfer)? I.e. instead of adding a dictionary entries from reading a Forth source file from input, the interpreter reads and loads into memory already-compiled dictionary definitions. Or possibly even just a set of threads and relevant subroutines.
- Does ANS Forth have provisions to automatically compile and run a source file, or load and execute a pre-compiled set of dictionary definitions without having to wait for external input from the user (i.e. at Forth initialization, akin to Unix init- this isn't practical on my system since the serial device is interactive , but it makes sense on a Forth with mass storage access), or in response to an external event (i.e. in response to a timer interrupt- which occurs without user intervention, or a background process)?
Of course, I could implement this on my own.
The question is- is this something that other Forth systems do? I mean, I'm sure in case of failure/reset, those satellites running Forth CPUs aren't going to an input prompt waiting for a program to run.