use readline in repl

This commit is contained in:
Yuichi Nishiwaki 2014-08-31 01:00:13 +09:00
parent 029d98338d
commit ac15ac6e2d
2 changed files with 15 additions and 7 deletions

View File

@ -2,14 +2,16 @@
(import (scheme base) (import (scheme base)
(scheme read) (scheme read)
(scheme write) (scheme write)
(scheme eval)) (scheme eval)
(picrin readline)
(picrin readline history))
(define (repl) (define (repl)
(display "> ") (let ((line (readline "> ")))
(let ((expr (read))) (if (eof-object? line)
(if (eof-object? expr)
(newline) ; exit (newline) ; exit
(begin (begin
(add-history line)
(call/cc (call/cc
(lambda (exit) (lambda (exit)
(with-exception-handler (with-exception-handler
@ -18,8 +20,13 @@
(newline) (newline)
(exit)) (exit))
(lambda () (lambda ()
(write (eval expr '(picrin user))) (let ((port (open-input-string line)))
(newline))))) (let loop ((expr (read port)))
(unless (eof-object? expr)
(write (eval expr '(picrin user)))
(newline)
(loop (read port))))
(close-port port))))))
(repl))))) (repl)))))
(export repl)) (export repl))

View File

@ -118,7 +118,8 @@ pic_init_core(pic_state *pic)
pic_init_eval(pic); DONE; pic_init_eval(pic); DONE;
pic_init_lib(pic); DONE; pic_init_lib(pic); DONE;
pic_load_piclib(pic); DONE;
pic_init_contrib(pic); DONE; pic_init_contrib(pic); DONE;
pic_load_piclib(pic); DONE;
} }
} }