From 82d237a5f176dc47002c89d3926a122c4778dac5 Mon Sep 17 00:00:00 2001 From: Anthony Howe Date: Sat, 9 Nov 2024 14:58:56 -0500 Subject: [PATCH] GH-64 Fix misplaced return stack underflow check. Fix Post4.repl() forgot to set the initial input source to standard input. Remove Post4.repl() loop around p4Repl(). --- jni/Post4.c | 1 + jni/Post4.java | 5 +---- src/post4.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/jni/Post4.c b/jni/Post4.c index 75eae02..7c01503 100644 --- a/jni/Post4.c +++ b/jni/Post4.c @@ -136,6 +136,7 @@ Java_post4_jni_Post4_repl(JNIEnv *env, jobject self) ctx->jenv = env; sig_init(); rc = SETJMP(sig_break_glass); + p4ResetInput(ctx, stdin); rc = p4Repl(ctx, P4_THROW_OK); sig_fini(); return rc; diff --git a/jni/Post4.java b/jni/Post4.java index b85f52b..a22a688 100644 --- a/jni/Post4.java +++ b/jni/Post4.java @@ -50,7 +50,6 @@ protected void finalize() public static void main(String[] args) { - int rc; Post4 p4 = new Post4(args); if (0 < args.length) { @@ -76,9 +75,7 @@ public static void main(String[] args) """ ); - while ((rc = p4.repl()) != Post4Exception.THROW_OK) { - ; // Remain in the REPL until EOF or BYE. - } + p4.repl(); } catch (Exception e) { // Something else happened on this day, lost in time. System.err.println(e); diff --git a/src/post4.c b/src/post4.c index 53fdb98..8d679c5 100755 --- a/src/post4.c +++ b/src/post4.c @@ -1331,7 +1331,6 @@ _quit: P4_RESET(ctx->rs); ; } ip = (P4_Cell *)(repl+1); - // (S: -- ) _interpret: P4_PUSH(ctx->rs, ip); @@ -1387,8 +1386,8 @@ _forth: exec[0].xt = word; (void) printf(ANSI_CYAN"ok "ANSI_NORMAL); (void) fflush(stdout); } - p4StackIsEmpty(ctx, &ctx->rs, P4_THROW_RS_UNDER); } while (p4Refill(ctx->input)); + p4StackIsEmpty(ctx, &ctx->rs, P4_THROW_RS_UNDER); ip = P4_POP(ctx->rs).p; NEXT;