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

View File

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