diff options
author | Andy Wingo <wingo@pobox.com> | 2011-11-23 12:40:33 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-11-23 12:54:09 +0100 |
commit | 9447207f0c9a52d48b2de20b444405dfdd43d465 (patch) | |
tree | 162696fc2bffb4991ef4139b89cd1d90c12bf38d /module | |
parent | c81c2ad3a59fdfb54260af2c159fac56de4daf3a (diff) |
Use default value for make-fluid in Scheme files
* module/ice-9/boot-9.scm (%exception-handler)
(%running-exception-handlers, read-eval?, *repl-stack*)
(make-mutable-parameter):
* module/ice-9/getopt-long.scm (%program-name):
* module/language/elisp/runtime.scm (built-in-macro, defspecial):
* module/srfi/srfi-39.scm (make-parameter/helper):
* module/system/base/language.scm (*current-language*):
* module/system/base/message.scm (*current-warning-port*):
(*current-warning-prefix*):
* module/system/base/target.scm (%target-type, %target-endianness)
(%target-word-size):
* module/texinfo/plain-text.scm (*indent*, *itemizer*):
* benchmark-suite/lib.scm (prefix-fluid):
* test-suite/lib.scm (prefix-fluid): Give fluids a useful default
value.
Diffstat (limited to 'module')
-rw-r--r-- | module/ice-9/boot-9.scm | 40 | ||||
-rw-r--r-- | module/ice-9/getopt-long.scm | 4 | ||||
-rw-r--r-- | module/language/elisp/runtime.scm | 14 | ||||
-rw-r--r-- | module/srfi/srfi-39.scm | 50 | ||||
-rw-r--r-- | module/system/base/language.scm | 4 | ||||
-rw-r--r-- | module/system/base/message.scm | 6 | ||||
-rw-r--r-- | module/system/base/target.scm | 15 | ||||
-rw-r--r-- | module/texinfo/plain-text.scm | 10 |
8 files changed, 62 insertions, 81 deletions
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 653c69376..5ac01b85e 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -69,23 +69,6 @@ (define with-throw-handler #f) (let () - ;; Ideally we'd like to be able to give these default values for all threads, - ;; even threads not created by Guile; but alack, that does not currently seem - ;; possible. So wrap the getters in thunks. - (define %running-exception-handlers (make-fluid)) - (define %exception-handler (make-fluid)) - - (define (running-exception-handlers) - (or (fluid-ref %running-exception-handlers) - (begin - (fluid-set! %running-exception-handlers '()) - '()))) - (define (exception-handler) - (or (fluid-ref %exception-handler) - (begin - (fluid-set! %exception-handler default-exception-handler) - default-exception-handler))) - (define (default-exception-handler k . args) (cond ((eq? k 'quit) @@ -98,18 +81,21 @@ (format (current-error-port) "guile: uncaught throw to ~a: ~a\n" k args) (primitive-exit 1)))) + (define %running-exception-handlers (make-fluid '())) + (define %exception-handler (make-fluid default-exception-handler)) + (define (default-throw-handler prompt-tag catch-k) - (let ((prev (exception-handler))) + (let ((prev (fluid-ref %exception-handler))) (lambda (thrown-k . args) (if (or (eq? thrown-k catch-k) (eqv? catch-k #t)) (apply abort-to-prompt prompt-tag thrown-k args) (apply prev thrown-k args))))) (define (custom-throw-handler prompt-tag catch-k pre) - (let ((prev (exception-handler))) + (let ((prev (fluid-ref %exception-handler))) (lambda (thrown-k . args) (if (or (eq? thrown-k catch-k) (eqv? catch-k #t)) - (let ((running (running-exception-handlers))) + (let ((running (fluid-ref %running-exception-handlers))) (with-fluids ((%running-exception-handlers (cons pre running))) (if (not (memq pre running)) (apply pre thrown-k args)) @@ -192,9 +178,9 @@ for key @var{key}, then invoke @var{thunk}." If there is no handler at all, Guile prints an error and then exits." (if (not (symbol? key)) - ((exception-handler) 'wrong-type-arg "throw" + ((fluid-ref %exception-handler) 'wrong-type-arg "throw" "Wrong type argument in position ~a: ~a" (list 1 key) (list key)) - (apply (exception-handler) key args))))) + (apply (fluid-ref %exception-handler) key args))))) @@ -1411,8 +1397,7 @@ VALUE." ;;; Reader code for various "#c" forms. ;;; -(define read-eval? (make-fluid)) -(fluid-set! read-eval? #f) +(define read-eval? (make-fluid #f)) (read-hash-extend #\. (lambda (c port) (if (fluid-ref read-eval?) @@ -2877,14 +2862,14 @@ module '(ice-9 q) '(make-q q-length))}." ;;; {Running Repls} ;;; -(define *repl-stack* (make-fluid)) +(define *repl-stack* (make-fluid '())) ;; 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. ;; (define (batch-mode?) - (null? (or (fluid-ref *repl-stack*) '()))) + (null? (fluid-ref *repl-stack*))) ;; Programs can re-enter batch mode, for example after a fork, by calling ;; `ensure-batch-mode!'. It's not a great interface, though; it would be better @@ -3301,8 +3286,7 @@ module '(ice-9 q) '(make-q q-length))}." ;;; (define* (make-mutable-parameter init #:optional (converter identity)) - (let ((fluid (make-fluid))) - (fluid-set! fluid (converter init)) + (let ((fluid (make-fluid (converter init)))) (case-lambda (() (fluid-ref fluid)) ((val) (fluid-set! fluid (converter val)))))) diff --git a/module/ice-9/getopt-long.scm b/module/ice-9/getopt-long.scm index 12f8c94c3..930ac0d88 100644 --- a/module/ice-9/getopt-long.scm +++ b/module/ice-9/getopt-long.scm @@ -164,9 +164,9 @@ #:use-module (ice-9 optargs) #:export (getopt-long option-ref)) -(define %program-name (make-fluid)) +(define %program-name (make-fluid "guile")) (define (program-name) - (or (fluid-ref %program-name) "guile")) + (fluid-ref %program-name)) (define (fatal-error fmt . args) (format (current-error-port) "~a: " (program-name)) diff --git a/module/language/elisp/runtime.scm b/module/language/elisp/runtime.scm index 025dc9629..0c84d102b 100644 --- a/module/language/elisp/runtime.scm +++ b/module/language/elisp/runtime.scm @@ -1,6 +1,6 @@ ;;; Guile Emacs Lisp -;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. +;;; Copyright (C) 2009, 2010, 2011 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 @@ -131,8 +131,8 @@ ((_ name value) (with-syntax ((scheme-name (make-id #'name 'macro- #'name))) #'(begin - (define-public scheme-name (make-fluid)) - (fluid-set! scheme-name (cons 'macro value)))))))) + (define-public scheme-name + (make-fluid (cons 'macro value))))))))) (define-syntax defspecial (lambda (x) @@ -140,10 +140,10 @@ ((_ name args body ...) (with-syntax ((scheme-name (make-id #'name 'compile- #'name))) #'(begin - (define scheme-name (make-fluid)) - (fluid-set! scheme-name - (cons 'special-operator - (lambda args body ...))))))))) + (define scheme-name + (make-fluid + (cons 'special-operator + (lambda args body ...)))))))))) ;;; Call a guile-primitive that may be rebound for elisp and thus needs ;;; absolute addressing. diff --git a/module/srfi/srfi-39.scm b/module/srfi/srfi-39.scm index dba86fdbb..d1c46d028 100644 --- a/module/srfi/srfi-39.scm +++ b/module/srfi/srfi-39.scm @@ -57,37 +57,41 @@ (define get-conv-tag (lambda () 'get-conv)) ;; arbitrary unique (as per eq?) value (define (make-parameter/helper val conv) - (let ((value (make-fluid)) - (conv conv)) - (begin - (fluid-set! value (conv val)) - (lambda new-value - (cond - ((null? new-value) (fluid-ref value)) - ((eq? (car new-value) get-fluid-tag) value) - ((eq? (car new-value) get-conv-tag) conv) - ((null? (cdr new-value)) (fluid-set! value (conv (car new-value)))) - (else (error "make-parameter expects 0 or 1 arguments" new-value))))))) + (let ((fluid (make-fluid (conv val)))) + (case-lambda + (() + (fluid-ref fluid)) + ((new-value) + (cond + ((eq? new-value get-fluid-tag) fluid) + ((eq? new-value get-conv-tag) conv) + (else (fluid-set! fluid (conv new-value)))))))) (define-syntax-rule (parameterize ((?param ?value) ...) ?body ...) (with-parameters* (list ?param ...) (list ?value ...) (lambda () ?body ...))) -(define (current-input-port . new-value) - (if (null? new-value) - ((@ (guile) current-input-port)) - (apply set-current-input-port new-value))) +(define current-input-port + (case-lambda + (() + ((@ (guile) current-input-port))) + ((new-value) + (set-current-input-port new-value)))) -(define (current-output-port . new-value) - (if (null? new-value) - ((@ (guile) current-output-port)) - (apply set-current-output-port new-value))) +(define current-output-port + (case-lambda + (() + ((@ (guile) current-output-port))) + ((new-value) + (set-current-output-port new-value)))) -(define (current-error-port . new-value) - (if (null? new-value) - ((@ (guile) current-error-port)) - (apply set-current-error-port new-value))) +(define current-error-port + (case-lambda + (() + ((@ (guile) current-error-port))) + ((new-value) + (set-current-error-port new-value)))) (define port-list (list current-input-port current-output-port current-error-port)) diff --git a/module/system/base/language.scm b/module/system/base/language.scm index 10d2d7408..5b27bc98d 100644 --- a/module/system/base/language.scm +++ b/module/system/base/language.scm @@ -111,7 +111,7 @@ ;;; Current language ;;; -(define *current-language* (make-fluid)) +(define *current-language* (make-fluid 'scheme)) (define (current-language) - (or (fluid-ref *current-language*) 'scheme)) + (fluid-ref *current-language*)) diff --git a/module/system/base/message.scm b/module/system/base/message.scm index 95468ca9a..aed35021c 100644 --- a/module/system/base/message.scm +++ b/module/system/base/message.scm @@ -56,15 +56,13 @@ (define *current-warning-port* ;; The port where warnings are sent. - (make-fluid)) + (make-fluid (current-error-port))) (fluid-set! *current-warning-port* (current-error-port)) (define *current-warning-prefix* ;; Prefix string when emitting a warning. - (make-fluid)) - -(fluid-set! *current-warning-prefix* ";;; ") + (make-fluid ";;; ")) (define-record-type <warning-type> diff --git a/module/system/base/target.scm b/module/system/base/target.scm index 80d80f310..a81b3d9f5 100644 --- a/module/system/base/target.scm +++ b/module/system/base/target.scm @@ -34,15 +34,15 @@ ;;; Target types ;;; -(define %target-type (make-fluid)) -(define %target-endianness (make-fluid)) -(define %target-word-size (make-fluid)) - (define %native-word-size ;; The native word size. Note: don't use `word-size' from ;; (system vm objcode) to avoid a circular dependency. ((@ (system foreign) sizeof) '*)) +(define %target-type (make-fluid %host-type)) +(define %target-endianness (make-fluid (native-endianness))) +(define %target-word-size (make-fluid %native-word-size)) + (define (validate-target target) (if (or (not (string? target)) (let ((parts (string-split target #\-))) @@ -100,8 +100,7 @@ (define (target-type) "Return the GNU configuration triplet of the target platform." - (or (fluid-ref %target-type) - %host-type)) + (fluid-ref %target-type)) (define (target-cpu) "Return the CPU name of the target platform." @@ -117,8 +116,8 @@ (define (target-endianness) "Return the endianness object of the target platform." - (or (fluid-ref %target-endianness) (native-endianness))) + (fluid-ref %target-endianness)) (define (target-word-size) "Return the word size, in bytes, of the target platform." - (or (fluid-ref %target-word-size) %native-word-size)) + (fluid-ref %target-word-size)) diff --git a/module/texinfo/plain-text.scm b/module/texinfo/plain-text.scm index 93a7c1d99..87e43e5bb 100644 --- a/module/texinfo/plain-text.scm +++ b/module/texinfo/plain-text.scm @@ -1,6 +1,6 @@ ;;;; (texinfo plain-text) -- rendering stexinfo as plain text ;;;; -;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. +;;;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. ;;;; Copyright (C) 2003,2004,2009 Andy Wingo <wingo at pobox dot com> ;;;; ;;;; This library is free software; you can redistribute it and/or @@ -41,9 +41,6 @@ (or (arg-ref key %-args) (error "Missing argument:" key %-args))) -(define *indent* (make-fluid)) -(define *itemizer* (make-fluid)) - (define (make-ticker str) (lambda () str)) (define (make-enumerator n) @@ -52,9 +49,8 @@ (set! n (1+ n)) (format #f "~A. " last)))) -(fluid-set! *indent* "") -;; Shouldn't be necessary to do this, but just in case. -(fluid-set! *itemizer* (make-ticker "* ")) +(define *indent* (make-fluid "")) +(define *itemizer* (make-fluid (make-ticker "* "))) (define-macro (with-indent n . body) `(with-fluids ((*indent* (string-append (fluid-ref *indent*) |