Saturday, May 24, 2008

Loading text files into an image

While Retro has no direct access to the host system, it is possible to load text files into an image and then save the results, or use it interactively. The process assumes that you are running on some form of Unix. It's pretty simple:

./build
cd bin
cat filename | ./ngaro forth.image

Or, for interactive mode:

cat filename - | ./ngaro forth.image

There is a limiting factor. The standard Retro image only recognizes space as valid whitespace, so any use of tabs or newlines will cause problems. This can be fixed by starting your code with the following line. This should be one single line. Be sure to include a space at the end of the line:

: fix dup 10 =if drop 32 then dup 13 =if drop 32 then
dup 9 =if drop 32 then ; ' fix is (remap-keys)

If you want, this can be disabled later by doing:

devector remap-keys

If you aren't going to drop to an interactive prompt, end with bye. Be sure to save your state if you want any changes to be present when you next load your Retro image.

No comments: