Skip to content

Commit

Permalink
GH-8 Change the behaviour of -13 Undefined Word exception to behave
Browse files Browse the repository at this point in the history
like `ABORT` according to Forth-2019 draft.  The previous behaviour
was more like `QUIT` which was useful for interactive debugging
since it did not reset the data stack, but it was non-standard.

TODO Consider a variable, eg. `TRUE KEEP_DATA !`, for debugging
the stack after an execption.
  • Loading branch information
SirWumpus committed Aug 7, 2024
1 parent 4818b89 commit 6858dc8
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/post4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,7 @@ p4Repl(P4_Ctx *ctx)
case P4_THROW_ABORT_MSG:
case P4_THROW_DS_OVER:
case P4_THROW_DS_UNDER:
case P4_THROW_UNDEFINED:
P4_RESET(ctx->ds);
/*@fallthrough@*/
#if defined(HAVE_MATH_H)
Expand All @@ -1587,7 +1588,6 @@ p4Repl(P4_Ctx *ctx)
case P4_THROW_SIGSEGV: /* Retain data stack. */
case P4_THROW_RS_OVER:
case P4_THROW_RS_UNDER:
case P4_THROW_UNDEFINED: /* Retain data stack. */
case P4_THROW_LOOP_DEPTH:
P4_RESET(ctx->rs);
/* Normally at this point one would reset input
Expand All @@ -1606,7 +1606,7 @@ p4Repl(P4_Ctx *ctx)
* - set interpretation state and begin text interpretation;
*/
default:
/* Flush the current input buffer. */
/* Discard the current input buffer. */
ctx->input.offset = ctx->input.length = 0;
ctx->state = P4_STATE_INTERPRET;
}
Expand All @@ -1630,14 +1630,6 @@ p4Repl(P4_Ctx *ctx)
if (p4StrNum(str, ctx->radix, &x, &is_float) != str.length) {
/* Not a word, not a number. */
(void) printf("\"%.*s\" ", (int)str.length, str.string);
/* An earlier version treated most exceptions like ABORT
* which would empty the stack, which is annoying when
* interactive as this could upset work in progress.
*
* An undefined word does not need to behave like ABORT,
* so the stacks can remain untouched. See Forth 200x
* Draft 19.1 section 3.4 d.
*/
THROW(P4_THROW_UNDEFINED);
}
if (ctx->state == P4_STATE_COMPILE) {
Expand Down

0 comments on commit 6858dc8

Please sign in to comment.