Implement read-eval-print-loop
using #%kernel
.
Makes the repl faster to load when using a very small language such as `racket/kernel/init`
This commit is contained in:
parent
ba8c79f502
commit
73c3341001
|
@ -5,7 +5,7 @@
|
||||||
(module misc '#%kernel
|
(module misc '#%kernel
|
||||||
(#%require "small-scheme.rkt" "define.rkt" "path.rkt" "old-path.rkt"
|
(#%require "small-scheme.rkt" "define.rkt" "path.rkt" "old-path.rkt"
|
||||||
"path-list.rkt" "executable-path.rkt"
|
"path-list.rkt" "executable-path.rkt"
|
||||||
"reading-param.rkt"
|
"reading-param.rkt" "repl.rkt"
|
||||||
(for-syntax '#%kernel "qq-and-or.rkt" "stx.rkt" "stxcase-scheme.rkt" "stxcase.rkt"))
|
(for-syntax '#%kernel "qq-and-or.rkt" "stx.rkt" "stxcase-scheme.rkt" "stxcase.rkt"))
|
||||||
|
|
||||||
;; -------------------------------------------------------------------------
|
;; -------------------------------------------------------------------------
|
||||||
|
@ -81,30 +81,7 @@
|
||||||
|
|
||||||
;; -------------------------------------------------------------------------
|
;; -------------------------------------------------------------------------
|
||||||
|
|
||||||
(define (read-eval-print-loop)
|
|
||||||
(let repl-loop ()
|
|
||||||
;; This prompt catches all error escapes, including from read and print.
|
|
||||||
(call-with-continuation-prompt
|
|
||||||
(lambda ()
|
|
||||||
(let ([v ((current-prompt-read))])
|
|
||||||
(unless (eof-object? v)
|
|
||||||
(call-with-values
|
|
||||||
(lambda ()
|
|
||||||
;; This prompt catches escapes during evaluation.
|
|
||||||
;; Unlike the outer prompt, the handler prints
|
|
||||||
;; the results.
|
|
||||||
(call-with-continuation-prompt
|
|
||||||
(lambda ()
|
|
||||||
(let ([w (cons '#%top-interaction v)])
|
|
||||||
((current-eval) (if (syntax? v)
|
|
||||||
(namespace-syntax-introduce
|
|
||||||
(datum->syntax #f w v))
|
|
||||||
w))))))
|
|
||||||
(lambda results (for-each (current-print) results)))
|
|
||||||
;; Abort to loop. (Calling `repl-loop` directly would not be a tail call.)
|
|
||||||
(abort-current-continuation (default-continuation-prompt-tag)))))
|
|
||||||
(default-continuation-prompt-tag)
|
|
||||||
(lambda args (repl-loop)))))
|
|
||||||
|
|
||||||
(define load/cd
|
(define load/cd
|
||||||
(lambda (n)
|
(lambda (n)
|
||||||
|
|
33
racket/collects/racket/private/repl.rkt
Normal file
33
racket/collects/racket/private/repl.rkt
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
(module repl '#%kernel
|
||||||
|
|
||||||
|
(#%provide read-eval-print-loop)
|
||||||
|
|
||||||
|
(define-values (read-eval-print-loop)
|
||||||
|
(lambda ()
|
||||||
|
(letrec-values ([(repl-loop)
|
||||||
|
(lambda ()
|
||||||
|
;; This prompt catches all error escapes, including from read and print.
|
||||||
|
(call-with-continuation-prompt
|
||||||
|
(lambda ()
|
||||||
|
(let-values ([(v) ((current-prompt-read))])
|
||||||
|
(if (eof-object? v)
|
||||||
|
(void)
|
||||||
|
(begin
|
||||||
|
(call-with-values
|
||||||
|
(lambda ()
|
||||||
|
;; This prompt catches escapes during evaluation.
|
||||||
|
;; Unlike the outer prompt, the handler prints
|
||||||
|
;; the results.
|
||||||
|
(call-with-continuation-prompt
|
||||||
|
(lambda ()
|
||||||
|
(let-values ([(w) (cons '#%top-interaction v)])
|
||||||
|
((current-eval) (if (syntax? v)
|
||||||
|
(namespace-syntax-introduce
|
||||||
|
(datum->syntax #f w v))
|
||||||
|
w))))))
|
||||||
|
(lambda results (for-each (current-print) results)))
|
||||||
|
;; Abort to loop. (Calling `repl-loop` directly would not be a tail call.)
|
||||||
|
(abort-current-continuation (default-continuation-prompt-tag))))))
|
||||||
|
(default-continuation-prompt-tag)
|
||||||
|
(lambda args (repl-loop))))])
|
||||||
|
(repl-loop)))))
|
Loading…
Reference in New Issue
Block a user