diff options
Diffstat (limited to 'scheme/racket/geiser/user.rkt')
-rw-r--r-- | scheme/racket/geiser/user.rkt | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/scheme/racket/geiser/user.rkt b/scheme/racket/geiser/user.rkt index 20f8a00..37763b9 100644 --- a/scheme/racket/geiser/user.rkt +++ b/scheme/racket/geiser/user.rkt @@ -11,9 +11,10 @@ #lang racket/base -(provide enter!) +(provide init-geiser-repl run-geiser-repl enter!) -(require geiser/main geiser/enter geiser/eval (for-syntax racket/base)) +(require (for-syntax racket/base) + geiser/main geiser/enter geiser/eval geiser/modules) (define top-namespace (current-namespace)) @@ -29,37 +30,53 @@ mod)))) (define orig-loader (current-load/use-compiled)) +(define geiser-loader (module-loader orig-loader)) -(define orig-reader (current-prompt-read)) +(define geiser-send-null (make-parameter #f)) (define (geiser-eval) (define geiser-main (module->namespace 'geiser/main)) - (let* ((mod (read)) - (lang (read)) - (form (read))) + (geiser-send-null #t) + (let* ([mod (read)] + [lang (read)] + [form (read)]) (datum->syntax #f (list 'quote - (cond ((equal? form '(unquote apply)) - (let* ((proc (eval (read) geiser-main)) - (args (read))) - ((geiser:eval lang) `(,proc ,@args) mod))) - (else ((geiser:eval lang) form mod))))))) + (cond [(equal? form '(unquote apply)) + (let* ([proc (eval (read) geiser-main)] + [args (read)]) + ((geiser:eval lang) `(,proc ,@args) mod))] + [else ((geiser:eval lang) form mod)]))))) (define (geiser-read) - (let ((form (orig-reader))) + (if (geiser-send-null) + (begin (geiser-send-null #f) + (write-char #\nul)) + (printf "racket@~a> " (namespace->module-name (current-namespace)))) + (flush-output) + (let* ([in (current-input-port)] + [form ((current-read-interaction) (object-name in) in)]) (syntax-case form () - ((uq cmd) (eq? 'unquote (syntax-e #'uq)) + [(uq cmd) (eq? 'unquote (syntax-e #'uq)) (case (syntax-e #'cmd) ((enter) (enter! (read) #'cmd)) ((geiser-eval) (geiser-eval)) ((geiser-no-values) (datum->syntax #f (void))) - (else form))) - (_ form)))) + (else form))] + [_ form]))) -(define (init) +(define geiser-prompt-read (make-repl-reader geiser-read)) + +(define (init-geiser-repl) (compile-enforce-module-constants #f) - (current-load/use-compiled (module-loader orig-loader)) - (current-prompt-read - (compose (make-repl-reader geiser-read) current-namespace))) + (current-load/use-compiled geiser-loader) + (current-prompt-read geiser-prompt-read)) -(init) +(define (run-geiser-repl in out enforce-module-constants) + (parameterize [(compile-enforce-module-constants enforce-module-constants) + (current-input-port in) + (current-output-port out) + (current-error-port out) + (current-load/use-compiled geiser-loader) + (current-prompt-read geiser-prompt-read)] + (read-eval-print-loop))) |