support file execution

This commit is contained in:
Yuichi Nishiwaki 2014-07-29 15:43:43 +09:00
parent 96f8a969e0
commit 36f4a8fa66
1 changed files with 17 additions and 13 deletions

View File

@ -41,30 +41,34 @@
(else (else
(file->string (car args))))))) (file->string (car args)))))))
(define (main-loop) (define (main-loop in out)
(display "> ") (display "> " out)
(let ((expr (read))) (let ((expr (read in)))
(if (eof-object? expr) (if (eof-object? expr)
(newline) ; exit (newline out) ; exit
(begin (begin
(call/cc (call/cc
(lambda (leave) (lambda (leave)
(with-exception-handler (with-exception-handler
(lambda (condition) (lambda (condition)
(display (error-object-message condition)) (display (error-object-message condition) (current-error-port))
(newline) (newline)
(leave)) (leave))
(lambda () (lambda ()
(print (eval expr '(picrin user))))))) (print (eval expr '(picrin user)) out)))))
(main-loop))))) (main-loop in out)))))
(define (run-repl program)
(let ((in (if program
(open-input-string program)
(current-input-port)))
(out (if program
(open-output-string) ; ignore output
(current-output-port))))
(main-loop in out)))
(define (repl) (define (repl)
(let ((program (getopt))) (let ((program (getopt)))
(parameterize (run-repl program)))
((current-input-port
(if program
(open-input-string program)
(current-input-port))))
(main-loop))))
(export repl)) (export repl))