mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-08 13:37:35 +02:00
keeping track of history in repl
This commit is contained in:
parent
37f8c6c8b9
commit
bfb698fd1b
2 changed files with 25 additions and 19 deletions
|
@ -5,5 +5,6 @@
|
||||||
(import (chibi ast)
|
(import (chibi ast)
|
||||||
(chibi process)
|
(chibi process)
|
||||||
(chibi term edit-line)
|
(chibi term edit-line)
|
||||||
(srfi 18))
|
(srfi 18)
|
||||||
|
(srfi 38))
|
||||||
(include "repl.scm"))
|
(include "repl.scm"))
|
||||||
|
|
|
@ -18,24 +18,29 @@
|
||||||
thunk
|
thunk
|
||||||
(lambda () (set-signal-action! sig old-handler)))))
|
(lambda () (set-signal-action! sig old-handler)))))
|
||||||
|
|
||||||
(define (run-repl module env)
|
(define (run-repl module env . o)
|
||||||
(let ((line (edit-line (if module (string-append (symbol->string module) "> ") "> "))))
|
(let ((history (make-history)))
|
||||||
(cond
|
(let lp ((module module) (env env))
|
||||||
((or (not line) (eof-object? line)))
|
(let ((line (edit-line (if module (string-append (symbol->string module) "> ") "> ")
|
||||||
((equal? line "") (run-repl module env))
|
'history: history)))
|
||||||
(else
|
(cond
|
||||||
(handle-exceptions exn (print-exception exn (current-error-port))
|
((or (not line) (eof-object? line)))
|
||||||
(let* ((expr (call-with-input-string line read))
|
((equal? line "") (lp module env))
|
||||||
(thread (make-thread (lambda ()
|
(else
|
||||||
(let ((res (eval expr env)))
|
(history-commit! history line)
|
||||||
(if (not (eq? res (if #f #f)))
|
(handle-exceptions
|
||||||
(write res)))))))
|
exn (print-exception exn (current-error-port))
|
||||||
(with-signal-handler
|
(let* ((expr (call-with-input-string line read/ss))
|
||||||
signal/interrupt
|
(thread (make-thread (lambda ()
|
||||||
(lambda (n) (thread-terminate! thread))
|
(let ((res (eval expr env)))
|
||||||
(lambda () (thread-start! thread) (thread-join! thread)))))
|
(if (not (eq? res (if #f #f)))
|
||||||
(newline)
|
(write/ss res))
|
||||||
(run-repl module env)))))
|
(newline))))))
|
||||||
|
(with-signal-handler
|
||||||
|
signal/interrupt
|
||||||
|
(lambda (n) (thread-terminate! thread))
|
||||||
|
(lambda () (thread-start! thread) (thread-join! thread)))))
|
||||||
|
(lp module env)))))))
|
||||||
|
|
||||||
(define (repl)
|
(define (repl)
|
||||||
(run-repl #f (interaction-environment)))
|
(run-repl #f (interaction-environment)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue