improve error handling mechanism
This commit is contained in:
parent
abc86efc55
commit
d8cbcde157
|
@ -2,25 +2,19 @@
|
||||||
(import (scheme base)
|
(import (scheme base)
|
||||||
(scheme read)
|
(scheme read)
|
||||||
(scheme write)
|
(scheme write)
|
||||||
(scheme eval)
|
(scheme eval))
|
||||||
(picrin macro)
|
|
||||||
(picrin library))
|
|
||||||
|
|
||||||
;; FIXME picrin doesn't offer cond-expand for now, so we define a macro ourselves
|
(cond-expand
|
||||||
(define-syntax define-readline
|
((library (picrin readline))
|
||||||
(er-macro-transformer
|
(import (picrin readline)
|
||||||
(lambda (form rename compare)
|
(picrin readline history)))
|
||||||
(if (member '(picrin readline) (libraries))
|
(else
|
||||||
`(import (picrin readline)
|
(begin
|
||||||
(picrin readline history))
|
|
||||||
`(begin
|
|
||||||
(define (readline str)
|
(define (readline str)
|
||||||
(display str)
|
(display str)
|
||||||
(read-line))
|
(read-line))
|
||||||
(define (add-history str)
|
(define (add-history str)
|
||||||
#f))))))
|
#f))))
|
||||||
|
|
||||||
(define-readline)
|
|
||||||
|
|
||||||
(define (repl)
|
(define (repl)
|
||||||
(let loop ((buf ""))
|
(let loop ((buf ""))
|
||||||
|
@ -33,23 +27,27 @@
|
||||||
(lambda (exit)
|
(lambda (exit)
|
||||||
(with-exception-handler
|
(with-exception-handler
|
||||||
(lambda (condition)
|
(lambda (condition)
|
||||||
|
(if (error-object? condition)
|
||||||
(unless (equal? (error-object-message condition) "unexpected EOF")
|
(unless (equal? (error-object-message condition) "unexpected EOF")
|
||||||
(display (error-object-message condition) (current-error-port))
|
(display "error: ")
|
||||||
|
(display (error-object-message condition))
|
||||||
(newline)
|
(newline)
|
||||||
(set! str ""))
|
(set! str ""))
|
||||||
|
(begin
|
||||||
|
(display "raised: ")
|
||||||
|
(write condition)
|
||||||
|
(newline)
|
||||||
|
(set! str "")))
|
||||||
(exit))
|
(exit))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
;; FIXME
|
(call-with-port (open-input-string str)
|
||||||
;; non-local exception jump from inside call-with-port
|
(lambda (port)
|
||||||
;; fails with segv, though i don't know why...
|
|
||||||
(let ((port (open-input-string str)))
|
|
||||||
(let next ((expr (read port)))
|
(let next ((expr (read port)))
|
||||||
(unless (eof-object? expr)
|
(unless (eof-object? expr)
|
||||||
(write (eval expr '(picrin user)))
|
(write (eval expr '(picrin user)))
|
||||||
(newline)
|
(newline)
|
||||||
(set! str "")
|
(set! str "")
|
||||||
(next (read port))))
|
(next (read port))))))))))
|
||||||
(close-port port))))))
|
|
||||||
(loop str))))))
|
(loop str))))))
|
||||||
|
|
||||||
(export repl))
|
(export repl))
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 06971a1144404bab62f0a9a7e7f881b18b6afde4
|
Subproject commit c4258153138a33441054e75072ea30e4012f9265
|
Loading…
Reference in New Issue