summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2010-06-18 12:28:18 +0200
committerAndy Wingo <wingo@pobox.com>2010-06-18 12:28:18 +0200
commit9346b857afd0121f5fbdf13a4944ec259090826d (patch)
tree9693c963d7449809cc16408c32961c6fcc9209cd
parent410e83c0127750c55058d550f81dc2a4a751c5f6 (diff)
downloadguile-9346b857afd0121f5fbdf13a4944ec259090826d.tar.gz
batch-mode? in terms of *repl-level*
* module/ice-9/boot-9.scm (*repl-level*): New global fluid, moved here from (system repl common). (batch-mode?): Reimplement in terms of *repl-level*. (ensure-batch-mode!): A replacement for set-batch-mode?!. * module/ice-9/deprecated.scm (set-batch-mode?!): Deprecate. * module/ice-9/popen.scm (open-process): Use ensure-batch-mode!. * module/ice-9/scm-style-repl.scm (error-catching-loop): Override ensure-batch-mode!. * module/system/repl/common.scm: Remove *repl-level*.
-rw-r--r--module/ice-9/boot-9.scm19
-rw-r--r--module/ice-9/deprecated.scm15
-rw-r--r--module/ice-9/popen.scm4
-rw-r--r--module/ice-9/scm-style-repl.scm9
-rw-r--r--module/system/repl/common.scm5
5 files changed, 35 insertions, 17 deletions
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 19c273f0b..bc7003540 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -2661,6 +2661,7 @@ module '(ice-9 q) '(make-q q-length))}."
;;; Currently Guile represents unspecified values via one particular value,
;;; which may be obtained by evaluating (if #f #f). It would be nice in the
;;; future if we could replace this with a return of 0 values, though.
+;;;
(define-syntax *unspecified*
(identifier-syntax (if #f #f)))
@@ -2691,10 +2692,20 @@ module '(ice-9 q) '(make-q q-length))}."
(define abort-hook (make-hook))
-;; these definitions are used if running a script.
-;; otherwise redefined in error-catching-loop.
-(define (set-batch-mode?! arg) #t)
-(define (batch-mode?) #t)
+;; Programs can call `batch-mode?' to see if they are running as part of a
+;; script or if they are running interactively. REPL implementations ensure that
+;; `batch-mode?' returns #f during their extent.
+;;
+;; Programs can re-enter batch mode, for example after a fork, by calling
+;; `ensure-batch-mode!'. This will also restore signal handlers. It's not a
+;; great interface, though; it would be better to abort to the outermost prompt,
+;; and call a thunk there.
+(define *repl-level* (make-fluid))
+(define (batch-mode?)
+ (negative? (or (fluid-ref *repl-level*) -1)))
+(define (ensure-batch-mode!)
+ (fluid-set! *repl-level* #f)
+ (restore-signals))
;;(define the-last-stack (make-fluid)) Defined by scm_init_backtrace ()
(define before-signal-stack (make-fluid))
diff --git a/module/ice-9/deprecated.scm b/module/ice-9/deprecated.scm
index 4748bce45..10c33f170 100644
--- a/module/ice-9/deprecated.scm
+++ b/module/ice-9/deprecated.scm
@@ -54,7 +54,8 @@
assert-repl-silence
assert-repl-print-unspecified
assert-repl-verbosity
- set-repl-prompt!)
+ set-repl-prompt!
+ set-batch-mode?!)
#:replace (module-ref-submodule module-define-submodule!))
@@ -595,3 +596,15 @@ better yet, use the repl from `(system repl repl)'.")
"`set-repl-prompt!' is deprecated. Use `repl-default-prompt-set!' from
the `(system repl common)' module.")
((@ (system repl common) repl-default-prompt-set!) v))
+
+(define (set-batch-mode?! arg)
+ (cond
+ (arg
+ (issue-deprecation-warning
+ "`set-batch-mode?!' is deprecated. Use `ensure-batch-mode!' instead.")
+ (ensure-batch-mode!))
+ (else
+ (issue-deprecation-warning
+ "`set-batch-mode?!' with an argument of `#f' is deprecated. Use the
+`*repl-level*' fluid instead.")
+ #t)))
diff --git a/module/ice-9/popen.scm b/module/ice-9/popen.scm
index 1a1892851..c5b02f7f1 100644
--- a/module/ice-9/popen.scm
+++ b/module/ice-9/popen.scm
@@ -1,6 +1,6 @@
;; popen emulation, for non-stdio based ports.
-;;;; Copyright (C) 1998, 1999, 2000, 2001, 2003, 2006 Free Software Foundation, Inc.
+;;;; Copyright (C) 1998, 1999, 2000, 2001, 2003, 2006, 2010 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -59,7 +59,7 @@
(let ((pid (primitive-fork)))
(cond ((= pid 0)
;; child
- (set-batch-mode?! #t)
+ (ensure-batch-mode!)
;; select the three file descriptors to be used as
;; standard descriptors 0, 1, 2 for the new
diff --git a/module/ice-9/scm-style-repl.scm b/module/ice-9/scm-style-repl.scm
index 0e6f13616..c316c382c 100644
--- a/module/ice-9/scm-style-repl.scm
+++ b/module/ice-9/scm-style-repl.scm
@@ -129,12 +129,9 @@
default-pre-unwind-handler)))
(if next (loop next) status)))
- (set! set-batch-mode?! (lambda (arg)
- (cond (arg
- (set! interactive #f)
- (restore-signals))
- (#t
- (error "sorry, not implemented")))))
+ (set! ensure-batch-mode! (lambda ()
+ (set! interactive #f)
+ (restore-signals)))
(set! batch-mode? (lambda () (not interactive)))
(call-with-blocked-asyncs
(lambda () (loop (lambda () #t))))))
diff --git a/module/system/repl/common.scm b/module/system/repl/common.scm
index fc9f45f86..1b4e2aca0 100644
--- a/module/system/repl/common.scm
+++ b/module/system/repl/common.scm
@@ -30,8 +30,7 @@
repl-parse repl-print repl-option-ref repl-option-set!
repl-default-option-set! repl-default-prompt-set!
puts ->string user-error
- *warranty* *copying* *version*
- *repl-level*))
+ *warranty* *copying* *version*))
(define *version*
(format #f "GNU Guile ~A
@@ -95,8 +94,6 @@ copy of the Program in return for a fee.
See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
-(define *repl-level* (make-fluid))
-
;;;
;;; Repl type