Liste des Groupes | Revenir à cl forth |
Irrespective of the merits such a change to the spec for THROW wouldReturning to OS can be useful not only for a turnkey program, but also for batch mode, in which the Forth system must return to the OS on any uncaught error.
be not be practical given most systems appear to use ANS' QUIT-based
exception handler. But for new implementers or the curious here is
how I organised mine and which is readily changeable.
\ return to OS with exit code
: RETURN ( code -- ) ... ;
\ perform ANS QUIT
: (quit) ( -- ) r0 @ rp! reset normal /interpret
begin cr (refill) drop interpret state? 0= if (vstat)
@execute then again ;
\ exit to OS or back to forth
: ?return ( code -- ) turnkey? if return then drop (quit) ;
\ clear data stacksI use `quit` only for testing and debugging. And I expect to get into the Forth text interpreter (Forth shell) exactly in the current program state (as far as possible).
: (abort) ( i*x -- ) s0 @ sp! fs0 @ fsp ! 1 ?return ;
\ part of THROW
: error ( n -- )
-1 of (abort) then
-2 of boot cell+ @ 0= if .error then
space errmsg 2@ type (abort) then
." THROW #" @base decimal swap . !base (abort) ;
: QUIT ( -- ) 0 ?return ; \ QUIT not trapped
\ QUIT is not trapped in DX-Forth but may be made so by
\ adding -56 of 1 ?return then to 'error' and defining
\ : QUIT -56 throw ;
: ?ABORT ( flag c-addr u -- )--
rot if errmsg 2! -2 throw then 2drop ;
: (abort") ( flag -- ) r> count 2dup + >r ?abort ;
: ABORT" state @ if postpone (abort") ," end
postpone s" ?abort ; immediate
: ABORT -1 throw ;
Les messages affichés proviennent d'usenet.