Sujet : Re: QUIT and ABORT
De : mhx (at) *nospam* iae.nl (mhx)
Groupes : comp.lang.forthDate : 05. May 2025, 23:05:47
Autres entêtes
Organisation : novaBBS
Message-ID : <eb7292e0cd166c6a9c5ce7bd766179d4@www.novabbs.com>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Rocksolid Light
On Sun, 4 May 2025 13:33:31 +0000, Anton Ertl wrote:
dxf <dxforth@gmail.com> writes:
On 4/05/2025 2:02 am, Anton Ertl wrote:
dxf <dxforth@gmail.com> writes:
[..]
In iForth 5.1-mini QUIT preserves the stack while an uncaught -56
THROW resets it to empty (as it should); the uncaught -56 THROW does
not produce a message. For the cases with CATCH, the FOO variant does
not put the -56 on the stack and does not text-interpret the 5
afterwards, but it does preserve the 2 that was pushed earlier.
Strange. The BAR variant behaves as expected. If I try
>
2 : foo 3 1 throw ; ' foo catch 5
..s
>
iForth 5.1-mini behaves as follows:
>
FORTH> 2 : foo 3 1 throw ; ' foo catch 5 ok
[3]FORTH> .s
Data: 2 1 5 ---
System: ---
Float: --- ok
>
This is expected, so it seems to do something special for -56 THROW.
Searching for: -56 THROW
D:\dfwforth\examples\misc\risky-program.frt(3): \ A heated debate is
possible over the exact action -56 THROW should have. Should it QUIT ?
D:\dfwforth\examples\misc\risky-program.frt(57): 2: 1999 12 [ -56 throw -56 THROW executed
Found 3 occurrence(s) in 1 file(s), 39514 ms
There must have been a convincing reason.
-marcel
---
\ Het Vijgeblaadje #17, december 1999
\ CATCH en THROW (II) De Schoolmeester (Albert Nijhof)
\ A heated debate is possible over the exact action -56 THROW should
have.
\ Should it QUIT ?
ANEW -risky-program
: .DEPTH ( -- )
DEPTH 0 .R ." : "
DEPTH 0>= IF exit ENDIF
BEGIN 0 DEPTH 0= UNTIL \ Repair stack if necessary
." Stack underflow " ;
: .TOP2 ( -- )
DEPTH 1 > IF OVER . ENDIF
DEPTH IF DUP . ENDIF ;
: .TOP4 ( -- )
DEPTH 4 > IF ." ~ " ENDIF
DEPTH 2 > IF 2>R .TOP2 2R> ENDIF
.TOP2 ;
: STATE-SIGN ( -- )
STATE @ IF [CHAR] ]
ELSE [CHAR] [
ENDIF ;
: .SITUATION ( -- )
CR .DEPTH .TOP4 STATE-SIGN EMIT SPACE ;
CREATE inputbuffer #80 ALLOT
: INPUT ( -- addr len )
inputbuffer DUP #80 ACCEPT SPACE ;
: RISKY-PROGRAM ( --)
.SITUATION INPUT EVALUATE ;
: VB ( -- )
BEGIN
['] RISKY-PROGRAM CATCH
?DUP IF . ." THROW executed " ENDIF
AGAIN ;
DOC
(*
FORTH> vb
0: [ drop -4 THROW executed
0: [ 12
1: 12 [ 1999
2: 12 1999 [ : zwap
2: 12 1999 ] qwerty -2 THROW executed
2: 12 1999 ] 2>r
2: 12 1999 ] r> r>
2: 12 1999 ] ;
2: 12 1999 [ zwap
2: 1999 12 [ ' asdf -13 THROW executed
2: 1999 12 [ -56 throw -56 THROW executed
2: 1999 12 [ quit
FORTH> .s
Data: 1999 12 ---
System: ---
Float: --- ok
FORTH> . . 12 1999 ok
FORTH> vb
0: [ abort -1 THROW executed
0: [ true abort" hello" -14 THROW executed
0: [ : test true abort" hello" ;
0: [ test -2 THROW executed
0: [ quit
FORTH> .s
Data: ---
System: ---
Float: --- ok
*)
ENDDOC