OK, so the setting is boostrapping a system that will eventually be
able to read from a configuration file or engage in a dialog to
determine what Forth implementation (or model) it is loading under,
and will know where to go to get implementation-specific code to
implement the user's preferences.
That will include whether or not error trapping works by ``ABORT'',
``THROW'', or some other mechanism ... and, indeed, if more than one
are available, which one the user wants to use.
However, there is a buffer overflow possibility at a low level early
on, long before that is in place. So, how to get the primitive error
handling in place that can be used in both simple and complex systems.
The current approach is the following, and the question is whether
this is workable or whether there is a hidden pitfall that I don't
see.
I am using CORE EXT words if the situation arises, and I'll sort out
which are going to be dependencies and which will have optional back-
up definitions later.
[DEFINED] and [UNDEFINED] are defined ... well, very first thing if
they are not available from the outset. That's a bootstrap I worked
out a long while back.
\ .warning prints a cautionary warning ... you will want to use
something
\ more elaborate than TYPE for full screen applications
[UNDEFINED] .warning [IF]
' TYPE VALUE {.warning}
: .warning ( ca u -- ) {.warning} EXECUTE
[THEN]
\ .error prints a cautionary warning, then returns as an exception
\ If you use CATCH/THROW, you will wish to use THROW for {error}
[UNDEFINED] .error [IF]
' ABORT VALUE {error}
: .error ( throw# ca u -- ) {.warning} EXECUTE {error} EXECUTE
[THEN]
For a long while, I was hung up on the fact that THROW required the
throw code and ABORT did not, until it occurred to me that ... yeah,
obviously, but then I never said programming was my field ... what
harm is an extra parameter on the stack if you are calling ABORT?
"At worst" ABORT will be throwing away the throw code, and at best the
stack state will be displayed or available on ABORT, so that the throw
code gives useful information in any event.


|