Skip to content

Commit

Permalink
GH-59 QUIT is not an exception and cannot be caught, since it resets
Browse files Browse the repository at this point in the history
the execption stack (or should); as such it should not result in an
exit status 3 when Post4 terminates.

See also https://forth-standard.org/standard/core/QUIT#reply-852
  • Loading branch information
SirWumpus committed Nov 9, 2024
1 parent e9ede99 commit 1396cdc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/post4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ p4Repl(P4_Ctx *ctx, int thrown)
#define w_semi words[2]
P4_WORD("_abort", &&_abort, 0, 0x00), // p4
#define w_abort words[3]
P4_WORD("_quit", &&_quit, 0, 0x00), // p4
P4_WORD("QUIT", &&_quit, 0, 0x00),
#define w_quit words[4]
P4_WORD("_interpret", &&_interpret, 0, 0x00), // p4
#define w_interpret words[5]
Expand Down Expand Up @@ -1314,6 +1314,9 @@ _abort: P4_RESET(ctx->ds);
#ifdef HAVE_MATH_H
P4_RESET(ctx->fs);
#endif
if (!is_tty) {
exit(P4_EXIT_EXCEPTION);
}
/*@fallthrough@*/
case P4_THROW_QUIT:
_quit: P4_RESET(ctx->rs);
Expand All @@ -1323,9 +1326,6 @@ _quit: P4_RESET(ctx->rs);
ctx->frame = 0;
/* Reset level, else next trace the indentation might be skewed. */
ctx->level = 0;
if (!is_tty) {
exit(P4_EXIT_EXCEPTION);
}
/*@fallthrough@*/
case P4_THROW_OK:
;
Expand Down
3 changes: 0 additions & 3 deletions src/post4.p4
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

\ Post4 Copyright 2007, 2024 by Anthony Howe. All rights reserved.

\ ( -- ⊥ )
: QUIT -56 _longjmp ;

\ ( -- ⊥ )
: BYE 0 bye-status ;

Expand Down
12 changes: 6 additions & 6 deletions test/makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ test_quit_catch : ${PROG}
! printf "' QUIT CATCH \n -123 THROW" | ${PROG} -c ${WORDS}
printf 'S" 0 THROW" '\'' EVALUATE CATCH' | ${PROG} -c ${WORDS}
printf 'S" -1 THROW" '\'' EVALUATE CATCH' | ${PROG} -c ${WORDS}
! printf ": tw_keep_ds [: 123 QUIT ;] CATCH 456 . THROW ;\n tw_keep_ds \n . CR" | ${PROG} -c ${WORDS}
printf ": tw_keep_ds [: 123 QUIT ;] CATCH 456 . THROW ;\n tw_keep_ds \n . CR" | ${PROG} -c ${WORDS}
@echo "-OK-"

# GH-54
test_include_quit: ${PROG}
@printf "==== Testing INCLUDE with QUIT\n"
! ${PROG} -c ${WORDS} <${top_srcdir}/test/data/quit0.p4
! echo | ${PROG} -c ${WORDS} ${top_srcdir}/test/data/quit0.p4
! echo | ${PROG} -c ${WORDS} -i ${top_srcdir}/test/data/quit0.p4
! printf "INCLUDE ${top_srcdir}/test/data/quit0.p4" | ${PROG} -c ${WORDS}
! printf "INCLUDE ${top_srcdir}/test/data/quit0.p4 \n BYE" | ${PROG} -c ${WORDS}
${PROG} -c ${WORDS} <${top_srcdir}/test/data/quit0.p4
echo | ${PROG} -c ${WORDS} ${top_srcdir}/test/data/quit0.p4
echo | ${PROG} -c ${WORDS} -i ${top_srcdir}/test/data/quit0.p4
printf "INCLUDE ${top_srcdir}/test/data/quit0.p4" | ${PROG} -c ${WORDS}
printf "INCLUDE ${top_srcdir}/test/data/quit0.p4 \n BYE" | ${PROG} -c ${WORDS}
@echo "-OK-"

# GH-54
Expand Down

0 comments on commit 1396cdc

Please sign in to comment.