From c5381d4cb3ec7cb6a06a337ecf915c978731260b Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Sun, 3 Aug 2008 13:50:20 -0700 Subject: [PATCH] Applied a patch fixing error when the standard input/output ports are closed before the interactive session terminates. --- scheme/ikarus.cafe.ss | 86 ++++++++++++++++++++++++------------------- scheme/last-revision | 2 +- 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/scheme/ikarus.cafe.ss b/scheme/ikarus.cafe.ss index 0fb860f..b6f5600 100644 --- a/scheme/ikarus.cafe.ss +++ b/scheme/ikarus.cafe.ss @@ -53,48 +53,58 @@ description: (display ">" (console-output-port)) (display-prompt (fx+ i 1)))))) - (define my-read - (lambda (k) - (parameterize ([interrupt-handler - (lambda () - (flush-output-port (console-output-port)) - (reset-input-port! (console-input-port)) - (newline (console-output-port)) - (k))]) - (read (console-input-port))))) - + (define (print-ex ex) + (flush-output-port (console-output-port)) + (display "Unhandled exception\n" (console-error-port)) + (print-condition ex (console-error-port))) + + (define (reset k) + (reset-input-port! (console-input-port)) + (k)) + (define wait (lambda (eval-proc escape-k) (call/cc (lambda (k) - (with-exception-handler - (lambda (con) - (reset-input-port! (console-input-port)) - (k (void))) - (lambda () - (with-exception-handler - (lambda (con) - (flush-output-port (console-output-port)) - (display "Unhandled exception\n" (console-error-port)) - (print-condition con (console-error-port)) - (when (interrupted-condition? con) - (raise-continuable con))) - (lambda () - (display-prompt 0) - (let ([x (my-read k)]) - (cond - [(eof-object? x) - (newline (console-output-port)) - (escape-k (void))] - [else - (call-with-values - (lambda () (eval-proc x)) - (lambda v* - (unless (andmap (lambda (v) (eq? v (void))) v*) - (for-each - (lambda (v) - (pretty-print v (console-output-port))) - v*))))])))))))) + (display-prompt 0) + (let ([x (with-exception-handler + (lambda (ex) + (cond [(lexical-violation? ex) + (print-ex ex) + (reset k)] + [(interrupted-condition? ex) + (flush-output-port (console-output-port)) + (newline (console-output-port)) + (reset k)] + [else (raise-continuable ex)])) + (lambda () + (read (console-input-port))))]) + (cond + [(eof-object? x) + (newline (console-output-port)) + (escape-k (void))] + [else + (call-with-values + (lambda () + (with-exception-handler + (lambda (ex) + (if (non-continuable-violation? ex) + (reset k) + (raise-continuable ex))) + (lambda () + (with-exception-handler + (lambda (ex) + (print-ex ex) + (when (serious-condition? ex) + (reset k))) + (lambda () + (eval-proc x)))))) + (lambda v* + (unless (andmap (lambda (v) (eq? v (void))) v*) + (for-each + (lambda (v) + (pretty-print v (console-output-port))) + v*))))])))) (wait eval-proc escape-k))) (define do-new-cafe diff --git a/scheme/last-revision b/scheme/last-revision index 41b2fe9..1c631e1 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1567 +1568