quozl at laptop.org
Tue Jun 12 20:00:26 EDT 2012
On Tue, Jun 12, 2012 at 11:08:29AM -0400, Kevin Gordon wrote:
> Disclaimer: Newbie Forth question ....:-)
> We are trying to create a consolidated unsecured update stick.
I worked on a secured update drive last week, so the techniques are on
> So for those coming from a non-Forth background, we have hit a road
> block. Is there perhaps a way to store a 'possible' command into a
> variable then execute that 'variable' as a command, thereby perhaps
> bypassing any of the apparent syntax error checking? Unexpected
> end-of-line is the most common result from attempting to call within
> an if statement. Or, we get copy-nand? on the 1.5 or fs-update? on
> the 1.0 when the command exists in the source - whether it will
> actually get 'called' or not ,based on the variable containing the
> machine type..
evaluate or eval is a word that expects a string descriptor on the
stack, and then executes the string as if it were typed.
: eval ( adr len -- ) ... ;
ok " 8 ." eval
: install-xo-1 " copy-nand u:\fs.img" eval ;
The string can be assembled from pieces rather than from literals.
You may find an example of that in the power log collector on the
wiki, which assembles filenames.
If there is a possibility that the evaluated command may fail, you
should catch the exception and handle it. Use catch for that.
Good reference for catch and throw:
" copy-nand u:\fs.img" ( adr len )
['] eval ( adr len 'eval )
catch ( ??? ??? exception# | 0 )
if ( ??? ??? )
2drop ( )
." copy-nand failed, press any key" key drop
then ( )
You might also place the exception handler higher up.
We also have $fs-update in later XO-1.5 and XO-1.75 versions, so that
eval is not needed. There is no $copy-nand .
More information about the Devel