#| -*-Scheme-*-
-$Id: rep.scm,v 14.62 2004/02/16 05:38:05 cph Exp $
+$Id: rep.scm,v 14.63 2005/03/29 05:04:00 cph Exp $
Copyright 1986,1987,1988,1989,1990,1991 Massachusetts Institute of Technology
Copyright 1992,1993,1994,1998,1999,2001 Massachusetts Institute of Technology
-Copyright 2003 Massachusetts Institute of Technology
+Copyright 2003,2004,2005 Massachusetts Institute of Technology
This file is part of MIT/GNU Scheme.
(define (initialize-package!)
(set! *nearest-cmdl* #f)
+ (set! hook/repl-read default/repl-read)
(set! hook/repl-eval default/repl-eval)
(set! hook/repl-write default/repl-write)
(set! hook/set-default-environment default/set-default-environment)
(operations cmdl/operations)
(properties cmdl/properties))
+(define-guarantee cmdl "command loop")
+
(define (make-cmdl parent port driver state operations)
(if (not (or (not parent) (cmdl? parent)))
(error:wrong-type-argument parent "cmdl" 'MAKE-CMDL))
(operation repl condition)))
(hook/error-decision
(hook/error-decision repl condition)))))
- (let ((reader-history (repl/reader-history repl))
- (printer-history (repl/printer-history repl)))
- (port/set-default-environment (cmdl/port repl) (repl/environment repl))
+ (port/set-default-environment (cmdl/port repl) (repl/environment repl))
+ (let ((queue (repl/input-queue repl)))
(do () (#f)
- (let ((s-expression
- (prompt-for-command-expression (cons 'STANDARD (repl/prompt repl))
- (cmdl/port repl))))
- (repl-history/record! reader-history s-expression)
- (let ((value
- (hook/repl-eval repl s-expression (repl/environment repl))))
- (repl-history/record! printer-history value)
- (hook/repl-write repl s-expression value))))))
+ (if (queue-empty? queue)
+ (let ((s-expression (repl-read repl)))
+ (repl-write repl s-expression (repl-eval repl s-expression)))
+ ((dequeue! queue) repl)))))
+
+(define (run-in-nearest-repl procedure)
+ (guarantee-procedure-of-arity procedure 1 'run-in-nearest-repl)
+ (enqueue! (repl/input-queue (nearest-repl)) procedure))
+
+(define (repl-read repl)
+ (guarantee-repl repl 'repl-read)
+ (hook/repl-read repl))
+
+(define hook/repl-read)
+(define (default/repl-read repl)
+ (prompt-for-command-expression (cons 'STANDARD (repl/prompt repl))
+ (cmdl/port repl)))
+
+(define (repl-eval repl s-expression)
+ (guarantee-repl repl 'repl-eval)
+ (repl-history/record! (repl/reader-history repl) s-expression)
+ (let ((value (hook/repl-eval repl s-expression (repl/environment repl))))
+ (repl-history/record! (repl/printer-history repl) value)
+ value))
(define hook/repl-eval)
(define (default/repl-eval repl s-expression environment)
- (let ((scode (syntax s-expression environment)))
- (with-repl-eval-boundary repl
- (lambda ()
- (extended-scode-eval scode environment)))))
+ (repl-scode-eval repl (syntax s-expression environment) environment))
(define (repl-scode-eval repl scode environment)
(with-repl-eval-boundary repl
with-repl-eval-boundary
repl))
+(define (repl-write repl s-expression value)
+ (guarantee-repl repl 'repl-write)
+ (hook/repl-write repl s-expression value))
+
(define hook/repl-write)
(define (default/repl-write repl s-expression object)
(port/write-result (cmdl/port repl)
environment
(condition #f read-only #t)
(reader-history (make-repl-history repl-reader-history-size))
- (printer-history (make-repl-history repl-printer-history-size)))
+ (printer-history (make-repl-history repl-printer-history-size))
+ (input-queue (make-queue) read-only #t))
(define (repl? object)
(and (cmdl? object)
(repl-state? (cmdl/state object))))
+(define-guarantee repl "read-eval-print loop")
+
(define-integrable (repl/prompt repl)
(repl-state/prompt (cmdl/state repl)))
(define-integrable (set-repl/printer-history! repl printer-history)
(set-repl-state/printer-history! (cmdl/state repl) printer-history))
+(define-integrable (repl/input-queue repl)
+ (repl-state/input-queue (cmdl/state repl)))
+
(define (repl/parent repl)
(skip-non-repls (cmdl/parent repl)))
(set-repl/environment! (nearest-repl) environment)
environment))
-(define (->environment object #!optional procedure)
- (let ((procedure
- (if (or (default-object? procedure) (not procedure))
- '->ENVIRONMENT
- procedure)))
+(define (->environment object #!optional caller)
+ (let ((caller (if (default-object? caller) '->ENVIRONMENT caller)))
(cond ((environment? object) object)
((package? object) (package/environment object))
((procedure? object) (procedure-environment object))
(and package-name
(name->package package-name)))))
(if (not package)
- (error:wrong-type-argument object "environment" procedure))
+ (error:wrong-type-argument object "environment" caller))
(package/environment package))))))
(define (re #!optional index)
(let ((repl (nearest-repl)))
- (hook/repl-eval repl
- (let ((history (repl/reader-history repl)))
- (let ((s-expression
- (repl-history/read history
- (if (default-object? index)
- 1
- index))))
- (repl-history/replace-current! history s-expression)
- s-expression))
- (repl/environment repl))))
+ (repl-eval repl
+ (repl-history/read (repl/reader-history repl)
+ (if (default-object? index) 1 index)))))
(define (in #!optional index)
(repl-history/read (repl/reader-history (nearest-repl))
#| -*-Scheme-*-
-$Id: runtime.pkg,v 14.534 2005/03/19 05:08:28 cph Exp $
+$Id: runtime.pkg,v 14.535 2005/03/29 05:04:09 cph Exp $
Copyright 1988,1989,1990,1991,1992,1993 Massachusetts Institute of Technology
Copyright 1994,1995,1996,1997,1998,1999 Massachusetts Institute of Technology
continuation/dynamic-state
continuation/type
continuation?
+ error:not-continuation
guarantee-continuation
make-continuation
non-reentrant-call-with-current-continuation
entity-extra
entity-procedure
entity?
+ error:not-compiled-procedure
+ error:not-compound-procedure
+ error:not-primitive-procedure
+ error:not-procedure
guarantee-compiled-procedure
guarantee-compound-procedure
guarantee-primitive-procedure
guarantee-procedure
+ guarantee-procedure-of-arity
implemented-primitive-procedure?
make-apply-hook
make-arity-dispatched-procedure
procedure-components
procedure-environment
procedure-lambda
+ procedure-of-arity?
procedure?
set-apply-hook-extra!
set-apply-hook-procedure!
error:not-list
error:not-pair
error:not-restricted-keyword-list
+ error:not-unique-keyword-list
error:not-weak-list
except-last-pair
except-last-pair!
guarantee-list-of-type->length
guarantee-pair
guarantee-restricted-keyword-list
+ guarantee-unique-keyword-list
guarantee-weak-list
keep-matching-items
keyword-list->alist
tenth
third
tree-copy
+ unique-keyword-list?
weak-car
weak-cdr
weak-cons
cmdl?
condition-type:breakpoint
condition/breakpoint?
+ error:not-cmdl
+ error:not-repl
ge
+ guarantee-cmdl
+ guarantee-repl
+ hook/repl-eval
+ hook/repl-read
+ hook/repl-write
in
initial-top-level-repl
make-cmdl
push-repl
re
read-eval-print
+ repl-eval
repl-history/read
repl-history/record!
repl-history/size
repl-printer-history-size
+ repl-read
repl-reader-history-size
repl-scode-eval
+ repl-write
repl/base
repl/condition
repl/environment
repl:write-result-hash-numbers?
repl?
restart
+ run-in-nearest-repl
set-cmdl/state!
set-repl/environment!
set-repl/printer-history!
standard-breakpoint-hook
ve
with-repl-eval-boundary)
- (export (runtime load)
- hook/repl-eval
- hook/repl-write)
+ (export (runtime load))
(export (runtime emacs-interface)
hook/error-decision
set-cmdl/port!)
- (export (runtime user-interface)
- hook/repl-eval)
(export (runtime debugger)
write-restarts)
(export (runtime working-directory)