mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-18 17:50:29 +02:00
Merge remote-tracking branch 'origin/stable-2.0'
Conflicts: configure.ac
This commit is contained in:
commit
bfe35b90ff
10 changed files with 199 additions and 107 deletions
|
@ -732,6 +732,9 @@ If there is no handler at all, Guile prints an error and then exits."
|
|||
(_ (default-printer)))
|
||||
args))
|
||||
|
||||
(define (getaddrinfo-error-printer port key args default-printer)
|
||||
(format port "In procedure getaddrinfo: ~a" (gai-strerror (car args))))
|
||||
|
||||
(set-exception-printer! 'goops-error scm-error-printer)
|
||||
(set-exception-printer! 'host-not-found scm-error-printer)
|
||||
(set-exception-printer! 'keyword-argument-error scm-error-printer)
|
||||
|
@ -751,7 +754,9 @@ If there is no handler at all, Guile prints an error and then exits."
|
|||
(set-exception-printer! 'wrong-number-of-args scm-error-printer)
|
||||
(set-exception-printer! 'wrong-type-arg scm-error-printer)
|
||||
|
||||
(set-exception-printer! 'syntax-error syntax-error-printer))
|
||||
(set-exception-printer! 'syntax-error syntax-error-printer)
|
||||
|
||||
(set-exception-printer! 'getaddrinfo-error getaddrinfo-error-printer))
|
||||
|
||||
|
||||
|
||||
|
@ -2874,6 +2879,36 @@ module '(ice-9 q) '(make-q q-length))}."
|
|||
...)
|
||||
body body* ...)))))))
|
||||
|
||||
|
||||
;;;
|
||||
;;; Current ports as parameters.
|
||||
;;;
|
||||
|
||||
(let ((fluid->parameter
|
||||
(lambda (fluid conv)
|
||||
(make-struct <parameter> 0
|
||||
(case-lambda
|
||||
(() (fluid-ref fluid))
|
||||
((x) (let ((prev (fluid-ref fluid)))
|
||||
(fluid-set! fluid (conv x))
|
||||
prev)))
|
||||
fluid conv))))
|
||||
(define-syntax-rule (port-parameterize! binding fluid predicate msg)
|
||||
(begin
|
||||
(set! binding (fluid->parameter (module-ref (current-module) 'fluid)
|
||||
(lambda (x)
|
||||
(if (predicate x) x
|
||||
(error msg x)))))
|
||||
(module-remove! (current-module) 'fluid)))
|
||||
|
||||
(port-parameterize! current-input-port %current-input-port-fluid
|
||||
input-port? "expected an input port")
|
||||
(port-parameterize! current-output-port %current-output-port-fluid
|
||||
output-port? "expected an output port")
|
||||
(port-parameterize! current-error-port %current-error-port-fluid
|
||||
output-port? "expected an output port"))
|
||||
|
||||
|
||||
|
||||
;;;
|
||||
;;; Warnings.
|
||||
|
@ -3611,8 +3646,9 @@ module '(ice-9 q) '(make-q q-length))}."
|
|||
srfi-4 ;; homogenous numeric vectors
|
||||
srfi-6 ;; open-input-string etc, in the guile core
|
||||
srfi-13 ;; string library
|
||||
srfi-23 ;; `error` procedure
|
||||
srfi-14 ;; character sets
|
||||
srfi-23 ;; `error` procedure
|
||||
srfi-39 ;; parameterize
|
||||
srfi-55 ;; require-extension
|
||||
srfi-61 ;; general cond clause
|
||||
))
|
||||
|
|
|
@ -17,16 +17,17 @@
|
|||
|
||||
|
||||
(define-module (ice-9 session)
|
||||
:use-module (ice-9 documentation)
|
||||
:use-module (ice-9 regex)
|
||||
:use-module (ice-9 rdelim)
|
||||
:export (help
|
||||
add-value-help-handler! remove-value-help-handler!
|
||||
add-name-help-handler! remove-name-help-handler!
|
||||
apropos apropos-internal apropos-fold apropos-fold-accessible
|
||||
apropos-fold-exported apropos-fold-all source arity
|
||||
procedure-arguments
|
||||
module-commentary))
|
||||
#:use-module (ice-9 documentation)
|
||||
#:use-module (ice-9 regex)
|
||||
#:use-module (ice-9 rdelim)
|
||||
#:export (help
|
||||
add-value-help-handler! remove-value-help-handler!
|
||||
add-name-help-handler! remove-name-help-handler!
|
||||
apropos-hook
|
||||
apropos apropos-internal apropos-fold apropos-fold-accessible
|
||||
apropos-fold-exported apropos-fold-all source arity
|
||||
procedure-arguments
|
||||
module-commentary))
|
||||
|
||||
|
||||
|
||||
|
@ -284,8 +285,13 @@ where OPTIONSET is one of debug, read, eval, print
|
|||
;;; Author: Roland Orre <orre@nada.kth.se>
|
||||
;;;
|
||||
|
||||
;; Two arguments: the module, and the pattern, as a string.
|
||||
;;
|
||||
(define apropos-hook (make-hook 2))
|
||||
|
||||
(define (apropos rgx . options)
|
||||
"Search for bindings: apropos regexp {options= 'full 'shadow 'value}"
|
||||
(run-hook apropos-hook (current-module) rgx)
|
||||
(if (zero? (string-length rgx))
|
||||
"Empty string not allowed"
|
||||
(let* ((match (make-regexp rgx))
|
||||
|
@ -354,6 +360,7 @@ Fourth arg FOLDER is one of
|
|||
(apropos-fold-accessible MODULE) ;fold over bindings accessible in MODULE
|
||||
apropos-fold-exported ;fold over all exported bindings
|
||||
apropos-fold-all ;fold over all bindings"
|
||||
(run-hook apropos-hook (current-module) rgx)
|
||||
(let ((match (make-regexp rgx))
|
||||
(recorded (make-hash-table)))
|
||||
(let ((fold-module
|
||||
|
|
|
@ -99,6 +99,47 @@
|
|||
(or (proc (vlist-ref vlist i))
|
||||
(lp (1+ i)))))))
|
||||
|
||||
(define (truncate-values x)
|
||||
"Discard all but the first value of X."
|
||||
(let loop ((x x))
|
||||
(match x
|
||||
(($ <const>) x)
|
||||
(($ <lexical-ref>) x)
|
||||
(($ <void>) x)
|
||||
(($ <lexical-ref>) x)
|
||||
(($ <primitive-ref>) x)
|
||||
(($ <module-ref>) x)
|
||||
(($ <toplevel-ref>) x)
|
||||
(($ <conditional> src condition subsequent alternate)
|
||||
(make-conditional src condition (loop subsequent) (loop alternate)))
|
||||
(($ <application> _ ($ <primitive-ref> _ 'values) (first _ ...))
|
||||
first)
|
||||
(($ <application> _ ($ <primitive-ref> _ 'values) (val))
|
||||
val)
|
||||
(($ <application> src
|
||||
(and prim ($ <primitive-ref> _ (? singly-valued-primitive?)))
|
||||
args)
|
||||
(make-application src prim (map loop args)))
|
||||
(($ <application> src proc args)
|
||||
(make-application src proc (map loop args)))
|
||||
(($ <sequence> src (exps ... last))
|
||||
(make-sequence src (append exps (list (loop last)))))
|
||||
(($ <lambda>) x)
|
||||
(($ <dynlet> src fluids vals body)
|
||||
(make-dynlet src fluids vals (loop body)))
|
||||
(($ <let> src names gensyms vals body)
|
||||
(make-let src names gensyms vals (loop body)))
|
||||
(($ <letrec> src in-order? names gensyms vals body)
|
||||
(make-letrec src in-order? names gensyms vals (loop body)))
|
||||
(($ <fix> src names gensyms vals body)
|
||||
(make-fix src names gensyms vals body))
|
||||
(($ <let-values> src exp body)
|
||||
(make-let-values src exp (loop body)))
|
||||
(else
|
||||
(make-application (tree-il-src x)
|
||||
(make-primitive-ref #f 'values)
|
||||
(list x))))))
|
||||
|
||||
;; Peval will do a one-pass analysis on the source program to determine
|
||||
;; the set of assigned lexicals, and to identify unreferenced and
|
||||
;; singly-referenced lexicals.
|
||||
|
@ -278,8 +319,10 @@
|
|||
(constant-value operand-constant-value set-operand-constant-value!))
|
||||
|
||||
(define* (make-operand var sym #:optional source visit)
|
||||
;; Bind SYM to VAR, with value SOURCE.
|
||||
;; Bound operands are considered copyable until we prove otherwise.
|
||||
(%make-operand var sym visit source 0 #f (and source #t) #f #f))
|
||||
(let ((source (if source (truncate-values source) source)))
|
||||
(%make-operand var sym visit source 0 #f (and source #t) #f #f)))
|
||||
|
||||
(define (make-bound-operands vars syms sources visit)
|
||||
(map (lambda (x y z) (make-operand x y z visit)) vars syms sources))
|
||||
|
|
|
@ -35,104 +35,19 @@
|
|||
;;; Code:
|
||||
|
||||
(define-module (srfi srfi-39)
|
||||
#:use-module (srfi srfi-16)
|
||||
|
||||
#:export (make-parameter)
|
||||
#:export-syntax (parameterize)
|
||||
|
||||
;; helper procedure not in srfi-39.
|
||||
#:export (with-parameters*)
|
||||
#:replace (current-input-port current-output-port current-error-port))
|
||||
#:re-export (make-parameter
|
||||
parameterize
|
||||
current-input-port current-output-port current-error-port))
|
||||
|
||||
;; Make 'srfi-39 available as a feature identifiere to `cond-expand'.
|
||||
;;
|
||||
(cond-expand-provide (current-module) '(srfi-39))
|
||||
|
||||
(define make-parameter
|
||||
(case-lambda
|
||||
((val) (make-parameter/helper val (lambda (x) x)))
|
||||
((val conv) (make-parameter/helper val conv))))
|
||||
|
||||
(define get-fluid-tag (lambda () 'get-fluid)) ;; arbitrary unique (as per eq?) value
|
||||
(define get-conv-tag (lambda () 'get-conv)) ;; arbitrary unique (as per eq?) value
|
||||
|
||||
(define (make-parameter/helper val conv)
|
||||
(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
|
||||
(case-lambda
|
||||
(()
|
||||
((@ (guile) current-input-port)))
|
||||
((new-value)
|
||||
(set-current-input-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
|
||||
(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))
|
||||
|
||||
;; There are no fluids behind current-input-port etc, so those parameter
|
||||
;; objects are picked out of the list and handled separately with a
|
||||
;; dynamic-wind to swap their values to and from a location (the "value"
|
||||
;; variable in the swapper procedure "let").
|
||||
;;
|
||||
;; current-input-port etc are already per-dynamic-root, so this arrangement
|
||||
;; works the same as a fluid. Perhaps they could become fluids for ease of
|
||||
;; implementation here.
|
||||
;;
|
||||
;; Notice the use of a param local variable for the swapper procedure. It
|
||||
;; ensures any application changes to the PARAMS list won't affect the
|
||||
;; winding.
|
||||
;;
|
||||
(define (with-parameters* params values thunk)
|
||||
(let more ((params params)
|
||||
(values values)
|
||||
(fluids '()) ;; fluids from each of PARAMS
|
||||
(convs '()) ;; VALUES with conversion proc applied
|
||||
(swapper noop)) ;; wind/unwind procedure for ports handling
|
||||
(convs '())) ;; VALUES with conversion proc applied
|
||||
(if (null? params)
|
||||
(if (eq? noop swapper)
|
||||
(with-fluids* fluids convs thunk)
|
||||
(dynamic-wind
|
||||
swapper
|
||||
(lambda ()
|
||||
(with-fluids* fluids convs thunk))
|
||||
swapper))
|
||||
(if (memq (car params) port-list)
|
||||
(more (cdr params) (cdr values)
|
||||
fluids convs
|
||||
(let ((param (car params))
|
||||
(value (car values))
|
||||
(prev-swapper swapper))
|
||||
(lambda ()
|
||||
(set! value (param value))
|
||||
(prev-swapper))))
|
||||
(more (cdr params) (cdr values)
|
||||
(cons ((car params) get-fluid-tag) fluids)
|
||||
(cons (((car params) get-conv-tag) (car values)) convs)
|
||||
swapper)))))
|
||||
(with-fluids* fluids convs thunk)
|
||||
(more (cdr params) (cdr values)
|
||||
(cons (parameter-fluid (car params)) fluids)
|
||||
(cons ((parameter-converter (car params)) (car values)) convs)))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue