Next: , Previous: The Text Interpreter, Up: The Text Interpreter


5.13.1 Input Sources

By default, the text interpreter processes input from the user input device (the keyboard) when Forth starts up. The text interpreter can process input from any of these sources:

A program can identify the current input device from the values of source-id and blk.

source-id       – 0 | -1 | fileid         core-ext,file       “source-i-d”

Return 0 (the input source is the user input device), -1 (the input source is a string being processed by evaluate) or a fileid (the input source is the file specified by fileid).

blk       – addr         block       “b-l-k”

input-var variable – This cell contains the current block number

save-input       – x1 .. xn n         core-ext       “save-input”

The n entries xn - x1 describe the current state of the input source specification, in some platform-dependent way that can be used by restore-input.

restore-input       x1 .. xn n – flag         core-ext       “restore-input”

Attempt to restore the input source specification to the state described by the n entries xn - x1. flag is true if the restore fails. In Gforth with the new input code, it fails only with a flag that can be used to throw again; it is also possible to save and restore between different active input streams. Note that closing the input streams must happen in the reverse order as they have been opened, but in between everything is allowed.

evaluate       ... addr u – ...         core,block       “evaluate”

Save the current input source specification. Store -1 in source-id and 0 in blk. Set >IN to 0 and make the string c-addr u the input source and input buffer. Interpret. When the parse area is empty, restore the input source specification.

query              core-ext-obsolescent       “query”

Make the user input device the input source. Receive input into the Terminal Input Buffer. Set >IN to zero. OBSOLESCENT: superceeded by accept.