QUIT

( -- ) ( R: i * x -- )

Empty the return stack, store zero in SOURCE-ID if it is present, make the user input device the input source, and enter interpretation state. Do not display a message. Repeat the following:

  • Accept a line from the input source into the input buffer, set >IN to zero, and interpret.
  • Display the implementation-defined system prompt if in interpretation state, all processing has been completed, and no ambiguous condition exists.

See:

Implementation:

: QUIT
   ( empty the return stack and set the input source to the user input device )
   POSTPONE [
     REFILL
   WHILE
     ['] INTERPRET CATCH
     CASE
     0 OF STATE @ 0= IF ." OK" THEN CR ENDOF
     -1 OF ( Aborted ) ENDOF
     -2 OF ( display message from ABORT" ) ENDOF
     ( default ) DUP ." Exception # " .
     ENDCASE
   REPEAT BYE
;

This assumes the existence of a system-implementation word INTERPRET that embodies the text interpreter semantics described in 3.4 The Forth text interpreter. Further discussion of the interpret loop can be found in A.6.2.0945 COMPILE,.

ContributeContributions

alextangentavatar of alextangent The reference implementation is incorrectSuggested reference implementation2019-03-16 14:59:29

: QUIT ( empty the return stack and ) ( set the input source to the user input device ) POSTPONE [ BEGIN ( missing in the reference implementation) REFILL WHILE ['] INTERPRET CATCH CASE 0 OF STATE @ 0= IF ." OK" THEN CR ENDOF -1 OF ( Aborted) ENDOF -2 OF ( display message from ABORT" ) ENDOF ( default ) DUP ." Exception # " . ENDCASE REPEAT BYE ;

Reported by marek.brunda at gmail.com

Reply