mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-08 05:27: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)
|
||||
(chibi process)
|
||||
(chibi term edit-line)
|
||||
(srfi 18))
|
||||
(srfi 18)
|
||||
(srfi 38))
|
||||
(include "repl.scm"))
|
||||
|
|
|
@ -18,24 +18,29 @@
|
|||
thunk
|
||||
(lambda () (set-signal-action! sig old-handler)))))
|
||||
|
||||
(define (run-repl module env)
|
||||
(let ((line (edit-line (if module (string-append (symbol->string module) "> ") "> "))))
|
||||
(define (run-repl module env . o)
|
||||
(let ((history (make-history)))
|
||||
(let lp ((module module) (env env))
|
||||
(let ((line (edit-line (if module (string-append (symbol->string module) "> ") "> ")
|
||||
'history: history)))
|
||||
(cond
|
||||
((or (not line) (eof-object? line)))
|
||||
((equal? line "") (run-repl module env))
|
||||
((equal? line "") (lp module env))
|
||||
(else
|
||||
(handle-exceptions exn (print-exception exn (current-error-port))
|
||||
(let* ((expr (call-with-input-string line read))
|
||||
(history-commit! history line)
|
||||
(handle-exceptions
|
||||
exn (print-exception exn (current-error-port))
|
||||
(let* ((expr (call-with-input-string line read/ss))
|
||||
(thread (make-thread (lambda ()
|
||||
(let ((res (eval expr env)))
|
||||
(if (not (eq? res (if #f #f)))
|
||||
(write res)))))))
|
||||
(write/ss res))
|
||||
(newline))))))
|
||||
(with-signal-handler
|
||||
signal/interrupt
|
||||
(lambda (n) (thread-terminate! thread))
|
||||
(lambda () (thread-start! thread) (thread-join! thread)))))
|
||||
(newline)
|
||||
(run-repl module env)))))
|
||||
(lp module env)))))))
|
||||
|
||||
(define (repl)
|
||||
(run-repl #f (interaction-environment)))
|
||||
|
|
Loading…
Add table
Reference in a new issue