2014-07-27 22:37:46 -04:00
|
|
|
(define-library (picrin repl)
|
|
|
|
(import (scheme base)
|
|
|
|
(scheme read)
|
|
|
|
(scheme write)
|
2014-08-30 12:00:13 -04:00
|
|
|
(scheme eval)
|
2014-08-30 12:41:12 -04:00
|
|
|
(picrin macro)
|
|
|
|
(picrin library))
|
|
|
|
|
2014-08-30 12:41:37 -04:00
|
|
|
;; FIXME picrin doesn't offer cond-expand for now, so we define a macro ourselves
|
2014-08-30 12:41:12 -04:00
|
|
|
(define-syntax define-readline
|
|
|
|
(er-macro-transformer
|
|
|
|
(lambda (form rename compare)
|
|
|
|
(if (member '(picrin readline) (libraries))
|
|
|
|
`(import (picrin readline)
|
|
|
|
(picrin readline history))
|
|
|
|
`(begin
|
|
|
|
(define (readline str)
|
|
|
|
(display str)
|
|
|
|
(read-line))
|
|
|
|
(define (add-history str)
|
|
|
|
#f))))))
|
|
|
|
|
|
|
|
(define-readline)
|
2014-07-27 22:37:46 -04:00
|
|
|
|
2014-08-30 11:36:20 -04:00
|
|
|
(define (repl)
|
2014-08-30 12:00:13 -04:00
|
|
|
(let ((line (readline "> ")))
|
|
|
|
(if (eof-object? line)
|
2014-08-30 11:36:20 -04:00
|
|
|
(newline) ; exit
|
2014-07-27 22:37:46 -04:00
|
|
|
(begin
|
2014-08-30 12:00:13 -04:00
|
|
|
(add-history line)
|
2014-07-27 22:37:46 -04:00
|
|
|
(call/cc
|
2014-08-30 11:36:20 -04:00
|
|
|
(lambda (exit)
|
2014-07-27 22:37:46 -04:00
|
|
|
(with-exception-handler
|
|
|
|
(lambda (condition)
|
2014-07-29 02:43:43 -04:00
|
|
|
(display (error-object-message condition) (current-error-port))
|
2014-07-27 22:37:46 -04:00
|
|
|
(newline)
|
2014-08-30 11:36:20 -04:00
|
|
|
(exit))
|
2014-07-27 22:37:46 -04:00
|
|
|
(lambda ()
|
2014-08-30 12:41:37 -04:00
|
|
|
;; FIXME
|
|
|
|
;; non-local exception jump from inside call-with-port
|
|
|
|
;; fails with segv, though i don't know why...
|
2014-08-30 12:00:13 -04:00
|
|
|
(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))))))
|
2014-08-30 11:36:20 -04:00
|
|
|
(repl)))))
|
2014-07-27 22:37:46 -04:00
|
|
|
|
|
|
|
(export repl))
|
2014-08-30 10:30:04 -04:00
|
|
|
|