1996-07-25 22:56:11 +00:00
|
|
|
|
;;; installed-scm-file
|
|
|
|
|
|
|
1997-01-18 11:29:20 +00:00
|
|
|
|
;;;; Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
;;;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
;;;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
|
;;;; any later version.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
;;;; GNU General Public License for more details.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
|
;;;; along with this software; see the file COPYING. If not, write to
|
* COPYING, boot-9.scm, debug.scm, emacs.scm, expect.scm, gtcl.scm,
gwish.scm, hcons.scm, lineio.scm, mapping.scm, nonblocking.scm,
oldprint.scm, poe.scm, r4rs.scm, source.scm, tags.scm, test.scm,
threads.scm: New address for FSF.
1997-05-26 22:26:48 +00:00
|
|
|
|
;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
|
|
;;;; Boston, MA 02111-1307 USA
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; This file is the first thing loaded into Guile. It adds many mundane
|
|
|
|
|
|
;;; definitions and a few that are interesting.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; The module system (hence the hierarchical namespace) are defined in this
|
|
|
|
|
|
;;; file.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Features}
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (provide sym)
|
|
|
|
|
|
(if (not (memq sym *features*))
|
|
|
|
|
|
(set! *features* (cons sym *features*))))
|
|
|
|
|
|
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {R4RS compliance}
|
|
|
|
|
|
|
|
|
|
|
|
(primitive-load-path "ice-9/r4rs.scm")
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {Simple Debugging Tools}
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; peek takes any number of arguments, writes them to the
|
|
|
|
|
|
;; current ouput port, and returns the last argument.
|
|
|
|
|
|
;; It is handy to wrap around an expression to look at
|
|
|
|
|
|
;; a value each time is evaluated, e.g.:
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; (+ 10 (troublesome-fn))
|
|
|
|
|
|
;; => (+ 10 (pk 'troublesome-fn-returned (troublesome-fn)))
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (peek . stuff)
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(display ";;; ")
|
|
|
|
|
|
(write stuff)
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(car (last-pair stuff)))
|
|
|
|
|
|
|
|
|
|
|
|
(define pk peek)
|
|
|
|
|
|
|
|
|
|
|
|
(define (warn . stuff)
|
|
|
|
|
|
(with-output-to-port (current-error-port)
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(display ";;; WARNING ")
|
1996-09-22 22:51:01 +00:00
|
|
|
|
(display stuff)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(newline)
|
|
|
|
|
|
(car (last-pair stuff)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
;;; {Trivial Functions}
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
|
|
|
|
|
|
(define (id x) x)
|
|
|
|
|
|
(define (1+ n) (+ n 1))
|
|
|
|
|
|
(define (-1+ n) (+ n -1))
|
|
|
|
|
|
(define 1- -1+)
|
|
|
|
|
|
(define return-it noop)
|
1997-01-08 01:27:01 +00:00
|
|
|
|
(define (and=> value procedure) (and value (procedure value)))
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
(define (make-hash-table k) (make-vector k '()))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; apply-to-args is functionally redunant with apply and, worse,
|
|
|
|
|
|
;;; is less general than apply since it only takes two arguments.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; On the other hand, apply-to-args is a syntacticly convenient way to
|
|
|
|
|
|
;;; perform binding in many circumstances when the "let" family of
|
|
|
|
|
|
;;; of forms don't cut it. E.g.:
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; (apply-to-args (return-3d-mouse-coords)
|
|
|
|
|
|
;;; (lambda (x y z)
|
|
|
|
|
|
;;; ...))
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (apply-to-args args fn) (apply fn args))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Integer Math}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (ipow-by-squaring x k acc proc)
|
|
|
|
|
|
(cond ((zero? k) acc)
|
|
|
|
|
|
((= 1 k) (proc acc x))
|
1997-06-13 05:50:49 +00:00
|
|
|
|
(else (ipow-by-squaring (proc x x)
|
|
|
|
|
|
(quotient k 2)
|
|
|
|
|
|
(if (even? k) acc (proc acc x))
|
|
|
|
|
|
proc))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define string-character-length string-length)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; A convenience function for combining flag bits. Like logior, but
|
|
|
|
|
|
;; handles the cases of 0 and 1 arguments.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (flags . args)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((null? args) 0)
|
|
|
|
|
|
((null? (cdr args)) (car args))
|
|
|
|
|
|
(else (apply logior args))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Symbol Properties}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (symbol-property sym prop)
|
|
|
|
|
|
(let ((pair (assoc prop (symbol-pref sym))))
|
|
|
|
|
|
(and pair (cdr pair))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (set-symbol-property! sym prop val)
|
|
|
|
|
|
(let ((pair (assoc prop (symbol-pref sym))))
|
|
|
|
|
|
(if pair
|
|
|
|
|
|
(set-cdr! pair val)
|
|
|
|
|
|
(symbol-pset! sym (acons prop val (symbol-pref sym))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (symbol-property-remove! sym prop)
|
|
|
|
|
|
(let ((pair (assoc prop (symbol-pref sym))))
|
|
|
|
|
|
(if pair
|
|
|
|
|
|
(symbol-pset! sym (delq! pair (symbol-pref sym))))))
|
|
|
|
|
|
|
1997-01-25 18:24:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Line and Delimited I/O}
|
|
|
|
|
|
|
|
|
|
|
|
;;; corresponds to SCM_LINE_INCREMENTORS in libguile.
|
|
|
|
|
|
(define scm-line-incrementors "\n")
|
|
|
|
|
|
|
|
|
|
|
|
(define (read-line! string . maybe-port)
|
|
|
|
|
|
(let* ((port (if (pair? maybe-port)
|
|
|
|
|
|
(car maybe-port)
|
|
|
|
|
|
(current-input-port))))
|
|
|
|
|
|
(let* ((rv (%read-delimited! scm-line-incrementors
|
|
|
|
|
|
string
|
|
|
|
|
|
#t
|
|
|
|
|
|
port))
|
|
|
|
|
|
(terminator (car rv))
|
|
|
|
|
|
(nchars (cdr rv)))
|
|
|
|
|
|
(cond ((and (= nchars 0)
|
|
|
|
|
|
(eof-object? terminator))
|
|
|
|
|
|
terminator)
|
|
|
|
|
|
((not terminator) #f)
|
|
|
|
|
|
(else nchars)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (read-delimited! delims buf . args)
|
|
|
|
|
|
(let* ((num-args (length args))
|
|
|
|
|
|
(port (if (> num-args 0)
|
|
|
|
|
|
(car args)
|
|
|
|
|
|
(current-input-port)))
|
|
|
|
|
|
(handle-delim (if (> num-args 1)
|
|
|
|
|
|
(cadr args)
|
|
|
|
|
|
'trim))
|
|
|
|
|
|
(start (if (> num-args 2)
|
|
|
|
|
|
(caddr args)
|
|
|
|
|
|
0))
|
|
|
|
|
|
(end (if (> num-args 3)
|
|
|
|
|
|
(cadddr args)
|
|
|
|
|
|
(string-length buf))))
|
|
|
|
|
|
(let* ((rv (%read-delimited! delims
|
|
|
|
|
|
buf
|
|
|
|
|
|
(not (eq? handle-delim 'peek))
|
|
|
|
|
|
port
|
|
|
|
|
|
start
|
|
|
|
|
|
end))
|
|
|
|
|
|
(terminator (car rv))
|
|
|
|
|
|
(nchars (cdr rv)))
|
|
|
|
|
|
(cond ((or (not terminator) ; buffer filled
|
|
|
|
|
|
(eof-object? terminator))
|
|
|
|
|
|
(if (zero? nchars)
|
|
|
|
|
|
(if (eq? handle-delim 'split)
|
|
|
|
|
|
(cons terminator terminator)
|
|
|
|
|
|
terminator)
|
|
|
|
|
|
(if (eq? handle-delim 'split)
|
|
|
|
|
|
(cons nchars terminator)
|
|
|
|
|
|
nchars)))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(case handle-delim
|
|
|
|
|
|
((trim peek) nchars)
|
|
|
|
|
|
((concat) (string-set! buf nchars terminator)
|
|
|
|
|
|
(+ nchars 1))
|
|
|
|
|
|
((split) (cons nchars terminator))
|
|
|
|
|
|
(else (error "unexpected handle-delim value: "
|
|
|
|
|
|
handle-delim))))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (read-delimited delims . args)
|
|
|
|
|
|
(let* ((port (if (pair? args)
|
|
|
|
|
|
(let ((pt (car args)))
|
|
|
|
|
|
(set! args (cdr args))
|
|
|
|
|
|
pt)
|
|
|
|
|
|
(current-input-port)))
|
|
|
|
|
|
(handle-delim (if (pair? args)
|
|
|
|
|
|
(car args)
|
|
|
|
|
|
'trim)))
|
|
|
|
|
|
(let loop ((substrings ())
|
|
|
|
|
|
(total-chars 0)
|
|
|
|
|
|
(buf-size 100)) ; doubled each time through.
|
|
|
|
|
|
(let* ((buf (make-string buf-size))
|
|
|
|
|
|
(rv (%read-delimited! delims
|
|
|
|
|
|
buf
|
|
|
|
|
|
(not (eq? handle-delim 'peek))
|
|
|
|
|
|
port))
|
|
|
|
|
|
(terminator (car rv))
|
|
|
|
|
|
(nchars (cdr rv))
|
|
|
|
|
|
(join-substrings
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(apply string-append
|
|
|
|
|
|
(reverse
|
|
|
|
|
|
(cons (if (and (eq? handle-delim 'concat)
|
|
|
|
|
|
(not (eof-object? terminator)))
|
|
|
|
|
|
(string terminator)
|
|
|
|
|
|
"")
|
|
|
|
|
|
(cons (make-shared-substring buf 0 nchars)
|
|
|
|
|
|
substrings))))))
|
|
|
|
|
|
(new-total (+ total-chars nchars)))
|
|
|
|
|
|
(cond ((not terminator)
|
|
|
|
|
|
;; buffer filled.
|
|
|
|
|
|
(loop (cons (substring buf 0 nchars) substrings)
|
|
|
|
|
|
new-total
|
|
|
|
|
|
(* buf-size 2)))
|
|
|
|
|
|
((eof-object? terminator)
|
|
|
|
|
|
(if (zero? new-total)
|
|
|
|
|
|
(if (eq? handle-delim 'split)
|
|
|
|
|
|
(cons terminator terminator)
|
|
|
|
|
|
terminator)
|
|
|
|
|
|
(if (eq? handle-delim 'split)
|
|
|
|
|
|
(cons (join-substrings) terminator)
|
|
|
|
|
|
(join-substrings))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(case handle-delim
|
|
|
|
|
|
((trim peek concat) (join-substrings))
|
|
|
|
|
|
((split) (cons (join-substrings) terminator))
|
1997-12-13 08:33:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
1997-01-25 18:24:54 +00:00
|
|
|
|
(else (error "unexpected handle-delim value: "
|
|
|
|
|
|
handle-delim)))))))))
|
1997-12-13 08:33:33 +00:00
|
|
|
|
|
|
|
|
|
|
;;; read-line [PORT [HANDLE-DELIM]] reads a newline-terminated string
|
|
|
|
|
|
;;; from PORT. The return value depends on the value of HANDLE-DELIM,
|
|
|
|
|
|
;;; which may be one of the symbols `trim', `concat', `peek' and
|
|
|
|
|
|
;;; `split'. If it is `trim' (the default), the trailing newline is
|
|
|
|
|
|
;;; removed and the string is returned. If `concat', the string is
|
|
|
|
|
|
;;; returned with the trailing newline intact. If `peek', the newline
|
|
|
|
|
|
;;; is left in the input port buffer and the string is returned. If
|
|
|
|
|
|
;;; `split', the newline is split from the string and read-line
|
|
|
|
|
|
;;; returns a pair consisting of the truncated string and the newline.
|
|
|
|
|
|
|
1997-01-25 18:24:54 +00:00
|
|
|
|
(define (read-line . args)
|
1997-12-13 08:33:33 +00:00
|
|
|
|
(let* ((port (if (null? args)
|
|
|
|
|
|
(current-input-port)
|
|
|
|
|
|
(car args)))
|
|
|
|
|
|
(handle-delim (if (> (length args) 1)
|
|
|
|
|
|
(cadr args)
|
|
|
|
|
|
'trim))
|
|
|
|
|
|
(line/delim (%read-line port))
|
|
|
|
|
|
(line (car line/delim))
|
|
|
|
|
|
(delim (cdr line/delim)))
|
|
|
|
|
|
(case handle-delim
|
|
|
|
|
|
((trim) line)
|
|
|
|
|
|
((split) line/delim)
|
|
|
|
|
|
((concat) (if (and (string? line) (char? delim))
|
|
|
|
|
|
(string-append line (string delim))
|
|
|
|
|
|
line))
|
|
|
|
|
|
((peek) (if (char? delim)
|
|
|
|
|
|
(unread-char delim port))
|
|
|
|
|
|
line)
|
|
|
|
|
|
(else
|
|
|
|
|
|
(error "unexpected handle-delim value: " handle-delim)))))
|
1997-01-25 18:24:54 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Arrays}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(define uniform-vector? array?)
|
|
|
|
|
|
(define make-uniform-vector dimensions->uniform-array)
|
|
|
|
|
|
; (define uniform-vector-ref array-ref)
|
|
|
|
|
|
(define (uniform-vector-set! u i o)
|
1997-02-15 18:48:12 +00:00
|
|
|
|
(uniform-array-set1! u o i))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define uniform-vector-fill! array-fill!)
|
|
|
|
|
|
(define uniform-vector-read! uniform-array-read!)
|
|
|
|
|
|
(define uniform-vector-write uniform-array-write)
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-array fill . args)
|
|
|
|
|
|
(dimensions->uniform-array args () fill))
|
|
|
|
|
|
(define (make-uniform-array prot . args)
|
|
|
|
|
|
(dimensions->uniform-array args prot))
|
|
|
|
|
|
(define (list->array ndim lst)
|
|
|
|
|
|
(list->uniform-array ndim '() lst))
|
|
|
|
|
|
(define (list->uniform-vector prot lst)
|
|
|
|
|
|
(list->uniform-array 1 prot lst))
|
|
|
|
|
|
(define (array-shape a)
|
|
|
|
|
|
(map (lambda (ind) (if (number? ind) (list 0 (+ -1 ind)) ind))
|
|
|
|
|
|
(array-dimensions a))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Keywords}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (symbol->keyword symbol)
|
|
|
|
|
|
(make-keyword-from-dash-symbol (symbol-append '- symbol)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (keyword->symbol kw)
|
|
|
|
|
|
(let ((sym (keyword-dash-symbol kw)))
|
1997-09-16 20:16:57 +00:00
|
|
|
|
(string->symbol (substring sym 1 (string-length sym)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (kw-arg-ref args kw)
|
|
|
|
|
|
(let ((rem (member kw args)))
|
|
|
|
|
|
(and rem (pair? (cdr rem)) (cadr rem))))
|
|
|
|
|
|
|
1997-06-04 22:39:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
1997-10-03 00:47:48 +00:00
|
|
|
|
;;; {Structs}
|
1997-06-04 22:39:09 +00:00
|
|
|
|
|
|
|
|
|
|
(define (struct-layout s)
|
1997-10-03 00:47:48 +00:00
|
|
|
|
(struct-ref (struct-vtable s) vtable-index-layout))
|
1997-06-04 22:39:09 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Records}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
1997-06-04 22:39:09 +00:00
|
|
|
|
;; Printing records: by default, records are printed as
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; #<type-name field1: val1 field2: val2 ...>
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; You can change that by giving a custom printing function to
|
|
|
|
|
|
;; MAKE-RECORD-TYPE (after the list of field symbols). This function
|
|
|
|
|
|
;; will be called like
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; (<printer> object port)
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; It should print OBJECT to PORT.
|
|
|
|
|
|
|
1997-10-31 22:16:24 +00:00
|
|
|
|
(define (inherit-print-state old-port new-port)
|
|
|
|
|
|
(if (pair? old-port)
|
|
|
|
|
|
(cons (if (pair? new-port) (car new-port) new-port)
|
|
|
|
|
|
(cdr old-port))
|
|
|
|
|
|
new-port))
|
|
|
|
|
|
|
1997-10-03 00:47:48 +00:00
|
|
|
|
;; 0: type-name, 1: fields
|
1997-06-04 22:39:09 +00:00
|
|
|
|
(define record-type-vtable
|
1997-10-03 00:47:48 +00:00
|
|
|
|
(make-vtable-vtable "prpr" 0
|
|
|
|
|
|
(lambda (s p)
|
|
|
|
|
|
(cond ((eq? s record-type-vtable)
|
|
|
|
|
|
(display "#<record-type-vtable>" p))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(display "#<record-type " p)
|
|
|
|
|
|
(display (record-type-name s) p)
|
|
|
|
|
|
(display ">" p))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (record-type? obj)
|
|
|
|
|
|
(and (struct? obj) (eq? record-type-vtable (struct-vtable obj))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-record-type type-name fields . opt)
|
1996-10-03 05:47:12 +00:00
|
|
|
|
(let ((printer-fn (and (pair? opt) (car opt))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let ((struct (make-struct record-type-vtable 0
|
1996-10-21 23:53:01 +00:00
|
|
|
|
(make-struct-layout
|
|
|
|
|
|
(apply symbol-append
|
|
|
|
|
|
(map (lambda (f) "pw") fields)))
|
1997-10-03 00:47:48 +00:00
|
|
|
|
(or printer-fn
|
|
|
|
|
|
(lambda (s p)
|
|
|
|
|
|
(display "#<" p)
|
|
|
|
|
|
(display type-name p)
|
|
|
|
|
|
(let loop ((fields fields)
|
|
|
|
|
|
(off 0))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((not (null? fields))
|
|
|
|
|
|
(display " " p)
|
|
|
|
|
|
(display (car fields) p)
|
|
|
|
|
|
(display ": " p)
|
|
|
|
|
|
(display (struct-ref s off) p)
|
|
|
|
|
|
(loop (cdr fields) (+ 1 off)))))
|
|
|
|
|
|
(display ">" p)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
type-name
|
|
|
|
|
|
(copy-tree fields))))
|
|
|
|
|
|
struct)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-type-name obj)
|
|
|
|
|
|
(if (record-type? obj)
|
1997-10-03 00:47:48 +00:00
|
|
|
|
(struct-ref obj vtable-offset-user)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(error 'not-a-record-type obj)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-type-fields obj)
|
|
|
|
|
|
(if (record-type? obj)
|
1997-10-03 00:47:48 +00:00
|
|
|
|
(struct-ref obj (+ 1 vtable-offset-user))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(error 'not-a-record-type obj)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-constructor rtd . opt)
|
1996-10-03 05:47:12 +00:00
|
|
|
|
(let ((field-names (if (pair? opt) (car opt) (record-type-fields rtd))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(eval `(lambda ,field-names
|
|
|
|
|
|
(make-struct ',rtd 0 ,@(map (lambda (f)
|
|
|
|
|
|
(if (memq f field-names)
|
|
|
|
|
|
f
|
|
|
|
|
|
#f))
|
|
|
|
|
|
(record-type-fields rtd)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-predicate rtd)
|
|
|
|
|
|
(lambda (obj) (and (struct? obj) (eq? rtd (struct-vtable obj)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-accessor rtd field-name)
|
|
|
|
|
|
(let* ((pos (list-index (record-type-fields rtd) field-name)))
|
|
|
|
|
|
(if (not pos)
|
|
|
|
|
|
(error 'no-such-field field-name))
|
|
|
|
|
|
(eval `(lambda (obj)
|
|
|
|
|
|
(and (eq? ',rtd (record-type-descriptor obj))
|
|
|
|
|
|
(struct-ref obj ,pos))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-modifier rtd field-name)
|
|
|
|
|
|
(let* ((pos (list-index (record-type-fields rtd) field-name)))
|
|
|
|
|
|
(if (not pos)
|
|
|
|
|
|
(error 'no-such-field field-name))
|
|
|
|
|
|
(eval `(lambda (obj val)
|
|
|
|
|
|
(and (eq? ',rtd (record-type-descriptor obj))
|
|
|
|
|
|
(struct-set! obj ,pos val))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (record? obj)
|
|
|
|
|
|
(and (struct? obj) (record-type? (struct-vtable obj))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-type-descriptor obj)
|
|
|
|
|
|
(if (struct? obj)
|
|
|
|
|
|
(struct-vtable obj)
|
|
|
|
|
|
(error 'not-a-record obj)))
|
|
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(provide 'record)
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Booleans}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (->bool x) (not (not x)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Symbols}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (symbol-append . args)
|
|
|
|
|
|
(string->symbol (apply string-append args)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (list->symbol . args)
|
|
|
|
|
|
(string->symbol (apply list->string args)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (symbol . args)
|
|
|
|
|
|
(string->symbol (apply string args)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (obarray-symbol-append ob . args)
|
|
|
|
|
|
(string->obarray-symbol (apply string-append ob args)))
|
|
|
|
|
|
|
1997-09-01 22:27:58 +00:00
|
|
|
|
(define (obarray-gensym obarray . opt)
|
|
|
|
|
|
(if (null? opt)
|
|
|
|
|
|
(gensym "%%gensym" obarray)
|
|
|
|
|
|
(gensym (car opt) obarray)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Lists}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (list-index l k)
|
|
|
|
|
|
(let loop ((n 0)
|
|
|
|
|
|
(l l))
|
|
|
|
|
|
(and (not (null? l))
|
|
|
|
|
|
(if (eq? (car l) k)
|
|
|
|
|
|
n
|
|
|
|
|
|
(loop (+ n 1) (cdr l))))))
|
|
|
|
|
|
|
1997-06-23 23:44:20 +00:00
|
|
|
|
(define (make-list n . init)
|
|
|
|
|
|
(if (pair? init) (set! init (car init)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let loop ((answer '())
|
|
|
|
|
|
(n n))
|
|
|
|
|
|
(if (<= n 0)
|
|
|
|
|
|
answer
|
|
|
|
|
|
(loop (cons init answer) (- n 1)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {and-map, or-map, and map-in-order}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; (and-map fn lst) is like (and (fn (car lst)) (fn (cadr lst)) (fn...) ...)
|
|
|
|
|
|
;;; (or-map fn lst) is like (or (fn (car lst)) (fn (cadr lst)) (fn...) ...)
|
|
|
|
|
|
;;; (map-in-order fn lst) is like (map fn lst) but definately in order of lst.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; and-map f l
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Apply f to successive elements of l until exhaustion or f returns #f.
|
|
|
|
|
|
;; If returning early, return #f. Otherwise, return the last value returned
|
|
|
|
|
|
;; by f. If f has never been called because l is empty, return #t.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (and-map f lst)
|
|
|
|
|
|
(let loop ((result #t)
|
|
|
|
|
|
(l lst))
|
|
|
|
|
|
(and result
|
|
|
|
|
|
(or (and (null? l)
|
|
|
|
|
|
result)
|
|
|
|
|
|
(loop (f (car l)) (cdr l))))))
|
|
|
|
|
|
|
|
|
|
|
|
;; or-map f l
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Apply f to successive elements of l until exhaustion or while f returns #f.
|
|
|
|
|
|
;; If returning early, return the return value of f.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (or-map f lst)
|
|
|
|
|
|
(let loop ((result #f)
|
|
|
|
|
|
(l lst))
|
|
|
|
|
|
(or result
|
|
|
|
|
|
(and (not (null? l))
|
|
|
|
|
|
(loop (f (car l)) (cdr l))))))
|
|
|
|
|
|
|
|
|
|
|
|
;; map-in-order
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Like map, but guaranteed to process the list in order.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (map-in-order fn l)
|
|
|
|
|
|
(if (null? l)
|
|
|
|
|
|
'()
|
|
|
|
|
|
(cons (fn (car l))
|
|
|
|
|
|
(map-in-order fn (cdr l)))))
|
|
|
|
|
|
|
1997-03-01 01:34:23 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Hooks}
|
|
|
|
|
|
(define (run-hooks hook)
|
|
|
|
|
|
(for-each (lambda (thunk) (thunk)) hook))
|
|
|
|
|
|
|
|
|
|
|
|
(define add-hook!
|
|
|
|
|
|
(procedure->macro
|
|
|
|
|
|
(lambda (exp env)
|
|
|
|
|
|
`(let ((thunk ,(caddr exp)))
|
|
|
|
|
|
(if (not (memq thunk ,(cadr exp)))
|
|
|
|
|
|
(set! ,(cadr exp)
|
|
|
|
|
|
(cons thunk ,(cadr exp))))))))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Files}
|
|
|
|
|
|
;;; !!!! these should be implemented using Tcl commands, not fports.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
1996-10-06 06:33:11 +00:00
|
|
|
|
(define (feature? feature)
|
|
|
|
|
|
(and (memq feature *features*) #t))
|
|
|
|
|
|
|
1996-10-27 23:26:35 +00:00
|
|
|
|
;; Using the vector returned by stat directly is probably not a good
|
|
|
|
|
|
;; idea (it could just as well be a record). Hence some accessors.
|
|
|
|
|
|
(define (stat:dev f) (vector-ref f 0))
|
|
|
|
|
|
(define (stat:ino f) (vector-ref f 1))
|
|
|
|
|
|
(define (stat:mode f) (vector-ref f 2))
|
|
|
|
|
|
(define (stat:nlink f) (vector-ref f 3))
|
|
|
|
|
|
(define (stat:uid f) (vector-ref f 4))
|
|
|
|
|
|
(define (stat:gid f) (vector-ref f 5))
|
|
|
|
|
|
(define (stat:rdev f) (vector-ref f 6))
|
|
|
|
|
|
(define (stat:size f) (vector-ref f 7))
|
|
|
|
|
|
(define (stat:atime f) (vector-ref f 8))
|
|
|
|
|
|
(define (stat:mtime f) (vector-ref f 9))
|
|
|
|
|
|
(define (stat:ctime f) (vector-ref f 10))
|
|
|
|
|
|
(define (stat:blksize f) (vector-ref f 11))
|
|
|
|
|
|
(define (stat:blocks f) (vector-ref f 12))
|
|
|
|
|
|
|
|
|
|
|
|
;; derived from stat mode.
|
|
|
|
|
|
(define (stat:type f) (vector-ref f 13))
|
|
|
|
|
|
(define (stat:perms f) (vector-ref f 14))
|
|
|
|
|
|
|
1996-10-06 06:33:11 +00:00
|
|
|
|
(define file-exists?
|
|
|
|
|
|
(if (feature? 'posix)
|
|
|
|
|
|
(lambda (str)
|
|
|
|
|
|
(access? str F_OK))
|
|
|
|
|
|
(lambda (str)
|
|
|
|
|
|
(let ((port (catch 'system-error (lambda () (open-file str OPEN_READ))
|
|
|
|
|
|
(lambda args #f))))
|
|
|
|
|
|
(if port (begin (close-port port) #t)
|
|
|
|
|
|
#f)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define file-is-directory?
|
|
|
|
|
|
(if (feature? 'i/o-extensions)
|
|
|
|
|
|
(lambda (str)
|
1996-10-27 23:26:35 +00:00
|
|
|
|
(eq? (stat:type (stat str)) 'directory))
|
1996-10-06 06:33:11 +00:00
|
|
|
|
(lambda (str)
|
|
|
|
|
|
(display str)
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(let ((port (catch 'system-error
|
|
|
|
|
|
(lambda () (open-file (string-append str "/.")
|
|
|
|
|
|
OPEN_READ))
|
|
|
|
|
|
(lambda args #f))))
|
|
|
|
|
|
(if port (begin (close-port port) #t)
|
|
|
|
|
|
#f)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (has-suffix? str suffix)
|
|
|
|
|
|
(let ((sufl (string-length suffix))
|
|
|
|
|
|
(sl (string-length str)))
|
|
|
|
|
|
(and (> sl sufl)
|
|
|
|
|
|
(string=? (substring str (- sl sufl) sl) suffix))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Error Handling}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (error . args)
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(save-stack)
|
1996-09-19 09:04:55 +00:00
|
|
|
|
(if (null? args)
|
* boot-9.scm (error): replace another throw with scm-error. Throw
to 'misc-error instead of 'error (no need to distinguish these.)
Don't set up 'error as a key.
Set up regex-error as a key, if regex is available.
(signal-handler): use scm-error, not throw.
(%try-load, try-load-with-path, %load, load-with-path,
basic-try-load-with-path, basic-load-with-path,
try-load-module-with-path,load-module-with-path): deleted, since
they seem redundant.
(try-load): define using %try-load, not try-load-with-path.
(load): rewritten. load tries to open the file directly and
with a .scm extension before searching the library directories
(should "." be added to %load-path? then load could still open
directly files starting with "/").
(try-module-autoload): use load, not load-with-path.
(%load-indent): deleted, -2 was causing errors.
(%read-sharp): use port-line, not line-number.
1996-09-28 19:38:45 +00:00
|
|
|
|
(scm-error 'misc-error #f "?" #f #f)
|
1996-09-19 09:04:55 +00:00
|
|
|
|
(let loop ((msg "%s")
|
|
|
|
|
|
(rest (cdr args)))
|
|
|
|
|
|
(if (not (null? rest))
|
|
|
|
|
|
(loop (string-append msg " %S")
|
|
|
|
|
|
(cdr rest))
|
* boot-9.scm (error): replace another throw with scm-error. Throw
to 'misc-error instead of 'error (no need to distinguish these.)
Don't set up 'error as a key.
Set up regex-error as a key, if regex is available.
(signal-handler): use scm-error, not throw.
(%try-load, try-load-with-path, %load, load-with-path,
basic-try-load-with-path, basic-load-with-path,
try-load-module-with-path,load-module-with-path): deleted, since
they seem redundant.
(try-load): define using %try-load, not try-load-with-path.
(load): rewritten. load tries to open the file directly and
with a .scm extension before searching the library directories
(should "." be added to %load-path? then load could still open
directly files starting with "/").
(try-module-autoload): use load, not load-with-path.
(%load-indent): deleted, -2 was causing errors.
(%read-sharp): use port-line, not line-number.
1996-09-28 19:38:45 +00:00
|
|
|
|
(scm-error 'misc-error #f msg args #f)))))
|
1996-09-20 09:02:14 +00:00
|
|
|
|
|
1996-10-05 16:55:06 +00:00
|
|
|
|
;; bad-throw is the hook that is called upon a throw to a an unhandled
|
1996-10-17 21:45:04 +00:00
|
|
|
|
;; key (unless the throw has four arguments, in which case
|
|
|
|
|
|
;; it's usually interpreted as an error throw.)
|
|
|
|
|
|
;; If the key has a default handler (a throw-handler-default property),
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; it is applied to the throw.
|
|
|
|
|
|
;;
|
1996-10-05 16:55:06 +00:00
|
|
|
|
(define (bad-throw key . args)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let ((default (symbol-property key 'throw-handler-default)))
|
|
|
|
|
|
(or (and default (apply default key args))
|
1996-09-19 09:04:55 +00:00
|
|
|
|
(apply error "unhandled-exception:" key args))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {Non-polymorphic versions of POSIX functions}
|
|
|
|
|
|
|
1996-08-02 23:26:33 +00:00
|
|
|
|
(define (getgrnam name) (getgr name))
|
|
|
|
|
|
(define (getgrgid id) (getgr id))
|
|
|
|
|
|
(define (gethostbyaddr addr) (gethost addr))
|
|
|
|
|
|
(define (gethostbyname name) (gethost name))
|
|
|
|
|
|
(define (getnetbyaddr addr) (getnet addr))
|
|
|
|
|
|
(define (getnetbyname name) (getnet name))
|
|
|
|
|
|
(define (getprotobyname name) (getproto name))
|
|
|
|
|
|
(define (getprotobynumber addr) (getproto addr))
|
|
|
|
|
|
(define (getpwnam name) (getpw name))
|
|
|
|
|
|
(define (getpwuid uid) (getpw uid))
|
1997-01-08 07:48:03 +00:00
|
|
|
|
(define (getservbyname name proto) (getserv name proto))
|
|
|
|
|
|
(define (getservbyport port proto) (getserv port proto))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (endgrent) (setgr))
|
|
|
|
|
|
(define (endhostent) (sethost))
|
|
|
|
|
|
(define (endnetent) (setnet))
|
|
|
|
|
|
(define (endprotoent) (setproto))
|
|
|
|
|
|
(define (endpwent) (setpw))
|
|
|
|
|
|
(define (endservent) (setserv))
|
1996-08-02 23:26:33 +00:00
|
|
|
|
(define (getgrent) (getgr))
|
|
|
|
|
|
(define (gethostent) (gethost))
|
|
|
|
|
|
(define (getnetent) (getnet))
|
|
|
|
|
|
(define (getprotoent) (getproto))
|
|
|
|
|
|
(define (getpwent) (getpw))
|
|
|
|
|
|
(define (getservent) (getserv))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (reopen-file . args) (apply freopen args))
|
* boot-9.scm: define accessor procedures for the objects returned
by getpw, getgr, gethost, getnet, getproto, getserv (e.g.,
passwd:name, where the first component is the name of the C structure
and the second is the unprefixed C member name.)
* * boot-9.scm (setpwent, setgrent, sethostent, setnetent, setprotoent,
setservent): no longer take an argument, it was bogus.
1997-03-22 18:26:32 +00:00
|
|
|
|
(define (setgrent) (setgr #f))
|
|
|
|
|
|
(define (sethostent) (sethost #t))
|
|
|
|
|
|
(define (setnetent) (setnet #t))
|
|
|
|
|
|
(define (setprotoent) (setproto #t))
|
|
|
|
|
|
(define (setpwent) (setpw #t))
|
|
|
|
|
|
(define (setservent) (setserv #t))
|
|
|
|
|
|
|
|
|
|
|
|
(define (passwd:name obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (passwd:passwd obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (passwd:uid obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (passwd:gid obj) (vector-ref obj 3))
|
|
|
|
|
|
(define (passwd:gecos obj) (vector-ref obj 4))
|
|
|
|
|
|
(define (passwd:dir obj) (vector-ref obj 5))
|
|
|
|
|
|
(define (passwd:shell obj) (vector-ref obj 6))
|
|
|
|
|
|
|
|
|
|
|
|
(define (group:name obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (group:passwd obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (group:gid obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (group:mem obj) (vector-ref obj 3))
|
|
|
|
|
|
|
|
|
|
|
|
(define (hostent:name obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (hostent:aliases obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (hostent:addrtype obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (hostent:length obj) (vector-ref obj 3))
|
|
|
|
|
|
(define (hostent:addr-list obj) (vector-ref obj 4))
|
|
|
|
|
|
|
|
|
|
|
|
(define (netent:name obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (netent:aliases obj) (vector-ref obj 1))
|
1997-03-29 18:38:21 +00:00
|
|
|
|
(define (netent:addrtype obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (netent:net obj) (vector-ref obj 3))
|
* boot-9.scm: define accessor procedures for the objects returned
by getpw, getgr, gethost, getnet, getproto, getserv (e.g.,
passwd:name, where the first component is the name of the C structure
and the second is the unprefixed C member name.)
* * boot-9.scm (setpwent, setgrent, sethostent, setnetent, setprotoent,
setservent): no longer take an argument, it was bogus.
1997-03-22 18:26:32 +00:00
|
|
|
|
|
|
|
|
|
|
(define (protoent:name obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (protoent:aliases obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (protoent:proto obj) (vector-ref obj 2))
|
|
|
|
|
|
|
|
|
|
|
|
(define (servent:name obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (servent:aliases obj) (vector-ref obj 1))
|
1997-03-29 18:38:21 +00:00
|
|
|
|
(define (servent:port obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (servent:proto obj) (vector-ref obj 3))
|
|
|
|
|
|
|
|
|
|
|
|
(define (sockaddr:fam obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (sockaddr:path obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (sockaddr:addr obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (sockaddr:port obj) (vector-ref obj 2))
|
|
|
|
|
|
|
|
|
|
|
|
(define (utsname:sysname obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (utsname:nodename obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (utsname:release obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (utsname:version obj) (vector-ref obj 3))
|
|
|
|
|
|
(define (utsname:machine obj) (vector-ref obj 4))
|
* boot-9.scm: define accessor procedures for the objects returned
by getpw, getgr, gethost, getnet, getproto, getserv (e.g.,
passwd:name, where the first component is the name of the C structure
and the second is the unprefixed C member name.)
* * boot-9.scm (setpwent, setgrent, sethostent, setnetent, setprotoent,
setservent): no longer take an argument, it was bogus.
1997-03-22 18:26:32 +00:00
|
|
|
|
|
1997-04-05 21:58:35 +00:00
|
|
|
|
(define (tm:sec obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (tm:min obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (tm:hour obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (tm:mday obj) (vector-ref obj 3))
|
|
|
|
|
|
(define (tm:mon obj) (vector-ref obj 4))
|
|
|
|
|
|
(define (tm:year obj) (vector-ref obj 5))
|
|
|
|
|
|
(define (tm:wday obj) (vector-ref obj 6))
|
|
|
|
|
|
(define (tm:yday obj) (vector-ref obj 7))
|
|
|
|
|
|
(define (tm:isdst obj) (vector-ref obj 8))
|
|
|
|
|
|
(define (tm:gmtoff obj) (vector-ref obj 9))
|
|
|
|
|
|
(define (tm:zone obj) (vector-ref obj 10))
|
|
|
|
|
|
|
|
|
|
|
|
(define (set-tm:sec obj val) (vector-set! obj 0 val))
|
|
|
|
|
|
(define (set-tm:min obj val) (vector-set! obj 1 val))
|
|
|
|
|
|
(define (set-tm:hour obj val) (vector-set! obj 2 val))
|
|
|
|
|
|
(define (set-tm:mday obj val) (vector-set! obj 3 val))
|
|
|
|
|
|
(define (set-tm:mon obj val) (vector-set! obj 4 val))
|
|
|
|
|
|
(define (set-tm:year obj val) (vector-set! obj 5 val))
|
|
|
|
|
|
(define (set-tm:wday obj val) (vector-set! obj 6 val))
|
|
|
|
|
|
(define (set-tm:yday obj val) (vector-set! obj 7 val))
|
|
|
|
|
|
(define (set-tm:isdst obj val) (vector-set! obj 8 val))
|
|
|
|
|
|
(define (set-tm:gmtoff obj val) (vector-set! obj 9 val))
|
|
|
|
|
|
(define (set-tm:zone obj val) (vector-set! obj 10 val))
|
|
|
|
|
|
|
* stime.h: prototype for scm_times.
* stime.c (scm_times): new procedure.
* ioext.c (scm_fseek): if the first argument is a file descriptor
call lseek.
(scm_ftell): if the first argument is a file descriptor call lseek
(sic).
* filesys.h: prototypes for scm_open_fdes, scm_fsync.
* filesys.c (scm_chmod): if the first argument is a file descriptor,
call fchmod.
(scm_chown): if the first argument is a port or file descriptor,
call fchown.
(scm_truncate_file): new procedure.
Add DEFER/ALLOW INTS to a few other procedures.
(scm_fsync): new procedure.
(scm_open_fdes): new procedure.
(scm_open): use scm_open_fdes. If mode isn't specified, 666 will
now be used.
(scm_fcntl): the first argument can now be a file descriptor. The
third argument is now optional.
* posix.c (scm_execl, scm_execlp): make the filename argument
compulsory, since omitting it causes SEGV.
(scm_sync): return unspecified instead of #f.
(scm_execle): new procedure.
(environ_list_to_c): new procedure.
(scm_environ): use environ_list_to_c. disable interrupts.
(scm_convert_exec_args): take pos and subr arguments and
improve error checking.
* boot-9.scm: define tms accessors: clock, utime, stime, cutime,
cstime.
1997-08-16 18:48:44 +00:00
|
|
|
|
(define (tms:clock obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (tms:utime obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (tms:stime obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (tms:cutime obj) (vector-ref obj 3))
|
|
|
|
|
|
(define (tms:cstime obj) (vector-ref obj 4))
|
|
|
|
|
|
|
* boot-9.scm: define accessor procedures for the objects returned
by getpw, getgr, gethost, getnet, getproto, getserv (e.g.,
passwd:name, where the first component is the name of the C structure
and the second is the unprefixed C member name.)
* * boot-9.scm (setpwent, setgrent, sethostent, setnetent, setprotoent,
setservent): no longer take an argument, it was bogus.
1997-03-22 18:26:32 +00:00
|
|
|
|
(define (file-position . args) (apply ftell args))
|
|
|
|
|
|
(define (file-set-position . args) (apply fseek args))
|
1996-08-04 22:32:07 +00:00
|
|
|
|
|
1997-04-05 21:58:35 +00:00
|
|
|
|
(define (open-input-pipe command) (open-pipe command OPEN_READ))
|
|
|
|
|
|
(define (open-output-pipe command) (open-pipe command OPEN_WRITE))
|
|
|
|
|
|
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
(define (move->fdes fd/port fd)
|
|
|
|
|
|
(cond ((integer? fd/port)
|
1997-07-29 02:21:08 +00:00
|
|
|
|
(dup->fdes fd/port fd)
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
(close fd/port)
|
|
|
|
|
|
fd)
|
|
|
|
|
|
(else
|
|
|
|
|
|
(primitive-move->fdes fd/port fd)
|
|
|
|
|
|
(set-port-revealed! fd/port 1)
|
|
|
|
|
|
fd/port)))
|
1996-08-04 22:32:07 +00:00
|
|
|
|
|
|
|
|
|
|
(define (release-port-handle port)
|
|
|
|
|
|
(let ((revealed (port-revealed port)))
|
|
|
|
|
|
(if (> revealed 0)
|
|
|
|
|
|
(set-port-revealed! port (- revealed 1)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
(define (dup->port port/fd mode . maybe-fd)
|
1997-07-29 02:21:08 +00:00
|
|
|
|
(let ((port (fdopen (apply dup->fdes port/fd maybe-fd)
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
mode)))
|
|
|
|
|
|
(if (pair? maybe-fd)
|
|
|
|
|
|
(set-port-revealed! port 1))
|
|
|
|
|
|
port))
|
|
|
|
|
|
|
|
|
|
|
|
(define (dup->inport port/fd . maybe-fd)
|
|
|
|
|
|
(apply dup->port port/fd "r" maybe-fd))
|
|
|
|
|
|
|
|
|
|
|
|
(define (dup->outport port/fd . maybe-fd)
|
|
|
|
|
|
(apply dup->port port/fd "w" maybe-fd))
|
|
|
|
|
|
|
|
|
|
|
|
(define (dup port/fd . maybe-fd)
|
|
|
|
|
|
(if (integer? port/fd)
|
|
|
|
|
|
(apply dup->fdes port/fd maybe-fd)
|
|
|
|
|
|
(apply dup->port port/fd (port-mode port/fd) maybe-fd)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (duplicate-port port modes)
|
|
|
|
|
|
(dup->port port modes))
|
|
|
|
|
|
|
|
|
|
|
|
(define (fdes->inport fdes)
|
|
|
|
|
|
(let loop ((rest-ports (fdes->ports fdes)))
|
|
|
|
|
|
(cond ((null? rest-ports)
|
|
|
|
|
|
(let ((result (fdopen fdes "r")))
|
|
|
|
|
|
(set-port-revealed! result 1)
|
|
|
|
|
|
result))
|
|
|
|
|
|
((input-port? (car rest-ports))
|
|
|
|
|
|
(set-port-revealed! (car rest-ports)
|
|
|
|
|
|
(+ (port-revealed (car rest-ports)) 1))
|
|
|
|
|
|
(car rest-ports))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(loop (cdr rest-ports))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (fdes->outport fdes)
|
|
|
|
|
|
(let loop ((rest-ports (fdes->ports fdes)))
|
|
|
|
|
|
(cond ((null? rest-ports)
|
|
|
|
|
|
(let ((result (fdopen fdes "w")))
|
|
|
|
|
|
(set-port-revealed! result 1)
|
|
|
|
|
|
result))
|
|
|
|
|
|
((output-port? (car rest-ports))
|
|
|
|
|
|
(set-port-revealed! (car rest-ports)
|
|
|
|
|
|
(+ (port-revealed (car rest-ports)) 1))
|
|
|
|
|
|
(car rest-ports))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(loop (cdr rest-ports))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (port->fdes port)
|
|
|
|
|
|
(set-port-revealed! port (+ (port-revealed port) 1))
|
|
|
|
|
|
(fileno port))
|
|
|
|
|
|
|
1997-07-26 20:37:05 +00:00
|
|
|
|
(define (setenv name value)
|
|
|
|
|
|
(if value
|
|
|
|
|
|
(putenv (string-append name "=" value))
|
|
|
|
|
|
(putenv name)))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Load Paths}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;; Here for backward compatability
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define scheme-file-suffix (lambda () ".scm"))
|
|
|
|
|
|
|
1996-09-05 16:33:42 +00:00
|
|
|
|
(define (in-vicinity vicinity file)
|
|
|
|
|
|
(let ((tail (let ((len (string-length vicinity)))
|
1997-09-20 13:57:22 +00:00
|
|
|
|
(if (zero? len)
|
|
|
|
|
|
#f
|
1996-09-05 16:33:42 +00:00
|
|
|
|
(string-ref vicinity (- len 1))))))
|
|
|
|
|
|
(string-append vicinity
|
1997-09-20 13:57:22 +00:00
|
|
|
|
(if (or (not tail)
|
|
|
|
|
|
(eq? tail #\/))
|
|
|
|
|
|
""
|
|
|
|
|
|
"/")
|
1996-09-05 16:33:42 +00:00
|
|
|
|
file)))
|
1996-08-30 21:09:23 +00:00
|
|
|
|
|
1997-04-19 13:04:38 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Help for scm_shell}
|
|
|
|
|
|
;;; The argument-processing code used by Guile-based shells generates
|
|
|
|
|
|
;;; Scheme code based on the argument list. This page contains help
|
|
|
|
|
|
;;; functions for the code it generates.
|
|
|
|
|
|
|
|
|
|
|
|
(define (command-line) (program-arguments))
|
|
|
|
|
|
|
1997-05-15 21:22:25 +00:00
|
|
|
|
;; This is mostly for the internal use of the code generated by
|
|
|
|
|
|
;; scm_compile_shell_switches.
|
1997-04-19 13:04:38 +00:00
|
|
|
|
(define (load-user-init)
|
|
|
|
|
|
(define (has-init? dir)
|
|
|
|
|
|
(let ((path (in-vicinity dir ".guile")))
|
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let ((stats (stat path)))
|
|
|
|
|
|
(if (not (eq? (stat:type stats) 'directory))
|
|
|
|
|
|
path)))
|
|
|
|
|
|
(lambda dummy #f))))
|
1997-07-11 05:41:24 +00:00
|
|
|
|
(let ((path (or (has-init? (or (getenv "HOME") "/"))
|
|
|
|
|
|
(has-init? (passwd:dir (getpw (getuid)))))))
|
1997-04-19 13:04:38 +00:00
|
|
|
|
(if path (primitive-load path))))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-10-29 03:59:35 +00:00
|
|
|
|
;;; {Loading by paths}
|
|
|
|
|
|
|
|
|
|
|
|
;;; Load a Scheme source file named NAME, searching for it in the
|
|
|
|
|
|
;;; directories listed in %load-path, and applying each of the file
|
|
|
|
|
|
;;; name extensions listed in %load-extensions.
|
|
|
|
|
|
(define (load-from-path name)
|
|
|
|
|
|
(start-stack 'load-stack
|
1997-03-08 19:02:20 +00:00
|
|
|
|
(primitive-load-path name)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
* boot-9.scm (error): replace another throw with scm-error. Throw
to 'misc-error instead of 'error (no need to distinguish these.)
Don't set up 'error as a key.
Set up regex-error as a key, if regex is available.
(signal-handler): use scm-error, not throw.
(%try-load, try-load-with-path, %load, load-with-path,
basic-try-load-with-path, basic-load-with-path,
try-load-module-with-path,load-module-with-path): deleted, since
they seem redundant.
(try-load): define using %try-load, not try-load-with-path.
(load): rewritten. load tries to open the file directly and
with a .scm extension before searching the library directories
(should "." be added to %load-path? then load could still open
directly files starting with "/").
(try-module-autoload): use load, not load-with-path.
(%load-indent): deleted, -2 was causing errors.
(%read-sharp): use port-line, not line-number.
1996-09-28 19:38:45 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Transcendental Functions}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Derived from "Transcen.scm", Complex trancendental functions for SCM.
|
|
|
|
|
|
;;; Copyright (C) 1992, 1993 Jerry D. Hedden.
|
|
|
|
|
|
;;; See the file `COPYING' for terms applying to this program.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (exp z)
|
|
|
|
|
|
(if (real? z) ($exp z)
|
|
|
|
|
|
(make-polar ($exp (real-part z)) (imag-part z))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (log z)
|
|
|
|
|
|
(if (and (real? z) (>= z 0))
|
|
|
|
|
|
($log z)
|
|
|
|
|
|
(make-rectangular ($log (magnitude z)) (angle z))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (sqrt z)
|
|
|
|
|
|
(if (real? z)
|
|
|
|
|
|
(if (negative? z) (make-rectangular 0 ($sqrt (- z)))
|
|
|
|
|
|
($sqrt z))
|
|
|
|
|
|
(make-polar ($sqrt (magnitude z)) (/ (angle z) 2))))
|
|
|
|
|
|
|
|
|
|
|
|
(define expt
|
|
|
|
|
|
(let ((integer-expt integer-expt))
|
|
|
|
|
|
(lambda (z1 z2)
|
|
|
|
|
|
(cond ((exact? z2)
|
|
|
|
|
|
(integer-expt z1 z2))
|
|
|
|
|
|
((and (real? z2) (real? z1) (>= z1 0))
|
|
|
|
|
|
($expt z1 z2))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(exp (* z2 (log z1))))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (sinh z)
|
|
|
|
|
|
(if (real? z) ($sinh z)
|
|
|
|
|
|
(let ((x (real-part z)) (y (imag-part z)))
|
|
|
|
|
|
(make-rectangular (* ($sinh x) ($cos y))
|
|
|
|
|
|
(* ($cosh x) ($sin y))))))
|
|
|
|
|
|
(define (cosh z)
|
|
|
|
|
|
(if (real? z) ($cosh z)
|
|
|
|
|
|
(let ((x (real-part z)) (y (imag-part z)))
|
|
|
|
|
|
(make-rectangular (* ($cosh x) ($cos y))
|
|
|
|
|
|
(* ($sinh x) ($sin y))))))
|
|
|
|
|
|
(define (tanh z)
|
|
|
|
|
|
(if (real? z) ($tanh z)
|
|
|
|
|
|
(let* ((x (* 2 (real-part z)))
|
|
|
|
|
|
(y (* 2 (imag-part z)))
|
|
|
|
|
|
(w (+ ($cosh x) ($cos y))))
|
|
|
|
|
|
(make-rectangular (/ ($sinh x) w) (/ ($sin y) w)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (asinh z)
|
|
|
|
|
|
(if (real? z) ($asinh z)
|
|
|
|
|
|
(log (+ z (sqrt (+ (* z z) 1))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (acosh z)
|
|
|
|
|
|
(if (and (real? z) (>= z 1))
|
|
|
|
|
|
($acosh z)
|
|
|
|
|
|
(log (+ z (sqrt (- (* z z) 1))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (atanh z)
|
|
|
|
|
|
(if (and (real? z) (> z -1) (< z 1))
|
|
|
|
|
|
($atanh z)
|
|
|
|
|
|
(/ (log (/ (+ 1 z) (- 1 z))) 2)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (sin z)
|
|
|
|
|
|
(if (real? z) ($sin z)
|
|
|
|
|
|
(let ((x (real-part z)) (y (imag-part z)))
|
|
|
|
|
|
(make-rectangular (* ($sin x) ($cosh y))
|
|
|
|
|
|
(* ($cos x) ($sinh y))))))
|
|
|
|
|
|
(define (cos z)
|
|
|
|
|
|
(if (real? z) ($cos z)
|
|
|
|
|
|
(let ((x (real-part z)) (y (imag-part z)))
|
|
|
|
|
|
(make-rectangular (* ($cos x) ($cosh y))
|
|
|
|
|
|
(- (* ($sin x) ($sinh y)))))))
|
|
|
|
|
|
(define (tan z)
|
|
|
|
|
|
(if (real? z) ($tan z)
|
|
|
|
|
|
(let* ((x (* 2 (real-part z)))
|
|
|
|
|
|
(y (* 2 (imag-part z)))
|
|
|
|
|
|
(w (+ ($cos x) ($cosh y))))
|
|
|
|
|
|
(make-rectangular (/ ($sin x) w) (/ ($sinh y) w)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (asin z)
|
|
|
|
|
|
(if (and (real? z) (>= z -1) (<= z 1))
|
|
|
|
|
|
($asin z)
|
|
|
|
|
|
(* -i (asinh (* +i z)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (acos z)
|
|
|
|
|
|
(if (and (real? z) (>= z -1) (<= z 1))
|
|
|
|
|
|
($acos z)
|
|
|
|
|
|
(+ (/ (angle -1) 2) (* +i (asinh (* +i z))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (atan z . y)
|
|
|
|
|
|
(if (null? y)
|
|
|
|
|
|
(if (real? z) ($atan z)
|
|
|
|
|
|
(/ (log (/ (- +i z) (+ +i z))) +2i))
|
|
|
|
|
|
($atan2 z (car y))))
|
|
|
|
|
|
|
|
|
|
|
|
(set! abs magnitude)
|
|
|
|
|
|
|
1997-04-12 19:47:09 +00:00
|
|
|
|
(define (log10 arg)
|
|
|
|
|
|
(/ (log arg) (log 10)))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Reader Extensions}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;; Reader code for various "#c" forms.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
1997-06-24 03:30:11 +00:00
|
|
|
|
;;; Parse the portion of a #/ list that comes after the first slash.
|
|
|
|
|
|
(define (read-path-list-notation slash port)
|
|
|
|
|
|
(letrec
|
|
|
|
|
|
|
|
|
|
|
|
;; Is C a delimiter?
|
|
|
|
|
|
((delimiter? (lambda (c) (or (eof-object? c)
|
|
|
|
|
|
(char-whitespace? c)
|
|
|
|
|
|
(string-index "()\";" c))))
|
|
|
|
|
|
|
|
|
|
|
|
;; Read and return one component of a path list.
|
|
|
|
|
|
(read-component
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let loop ((reversed-chars '()))
|
|
|
|
|
|
(let ((c (peek-char port)))
|
|
|
|
|
|
(if (or (delimiter? c)
|
|
|
|
|
|
(char=? c #\/))
|
|
|
|
|
|
(string->symbol (list->string (reverse reversed-chars)))
|
|
|
|
|
|
(loop (cons (read-char port) reversed-chars))))))))
|
|
|
|
|
|
|
|
|
|
|
|
;; Read and return a path list.
|
|
|
|
|
|
(let loop ((reversed-path (list (read-component))))
|
|
|
|
|
|
(let ((c (peek-char port)))
|
|
|
|
|
|
(if (and (char? c) (char=? c #\/))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(read-char port)
|
|
|
|
|
|
(loop (cons (read-component) reversed-path)))
|
|
|
|
|
|
(reverse reversed-path))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-03-08 19:02:20 +00:00
|
|
|
|
(read-hash-extend #\' (lambda (c port)
|
|
|
|
|
|
(read port)))
|
|
|
|
|
|
(read-hash-extend #\. (lambda (c port)
|
|
|
|
|
|
(eval (read port))))
|
|
|
|
|
|
|
|
|
|
|
|
(if (feature? 'array)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(let ((make-array-proc (lambda (template)
|
|
|
|
|
|
(lambda (c port)
|
|
|
|
|
|
(read:uniform-vector template port)))))
|
|
|
|
|
|
(for-each (lambda (char template)
|
|
|
|
|
|
(read-hash-extend char
|
|
|
|
|
|
(make-array-proc template)))
|
|
|
|
|
|
'(#\b #\a #\u #\e #\s #\i #\c)
|
|
|
|
|
|
'(#t #\a 1 -1 1.0 1/3 0+i)))
|
|
|
|
|
|
(let ((array-proc (lambda (c port)
|
|
|
|
|
|
(read:array c port))))
|
|
|
|
|
|
(for-each (lambda (char) (read-hash-extend char array-proc))
|
|
|
|
|
|
'(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)))))
|
|
|
|
|
|
|
1997-03-08 19:57:08 +00:00
|
|
|
|
;; pushed to the beginning of the alist since it's used more than the
|
|
|
|
|
|
;; others at present.
|
1997-06-24 03:30:11 +00:00
|
|
|
|
(read-hash-extend #\/ read-path-list-notation)
|
1997-03-08 19:57:08 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (read:array digit port)
|
|
|
|
|
|
(define chr0 (char->integer #\0))
|
|
|
|
|
|
(let ((rank (let readnum ((val (- (char->integer digit) chr0)))
|
|
|
|
|
|
(if (char-numeric? (peek-char port))
|
|
|
|
|
|
(readnum (+ (* 10 val)
|
|
|
|
|
|
(- (char->integer (read-char port)) chr0)))
|
|
|
|
|
|
val)))
|
|
|
|
|
|
(prot (if (eq? #\( (peek-char port))
|
|
|
|
|
|
'()
|
|
|
|
|
|
(let ((c (read-char port)))
|
|
|
|
|
|
(case c ((#\b) #t)
|
|
|
|
|
|
((#\a) #\a)
|
|
|
|
|
|
((#\u) 1)
|
|
|
|
|
|
((#\e) -1)
|
|
|
|
|
|
((#\s) 1.0)
|
|
|
|
|
|
((#\i) 1/3)
|
|
|
|
|
|
((#\c) 0+i)
|
|
|
|
|
|
(else (error "read:array unknown option " c)))))))
|
|
|
|
|
|
(if (eq? (peek-char port) #\()
|
1997-03-08 19:02:20 +00:00
|
|
|
|
(list->uniform-array rank prot (read port))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(error "read:array list not found"))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (read:uniform-vector proto port)
|
|
|
|
|
|
(if (eq? #\( (peek-char port))
|
1997-03-08 19:02:20 +00:00
|
|
|
|
(list->uniform-array 1 proto (read port))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(error "read:uniform-vector list not found")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Command Line Options}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (get-option argv kw-opts kw-args return)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((null? argv)
|
|
|
|
|
|
(return #f #f argv))
|
|
|
|
|
|
|
|
|
|
|
|
((or (not (eq? #\- (string-ref (car argv) 0)))
|
|
|
|
|
|
(eq? (string-length (car argv)) 1))
|
|
|
|
|
|
(return 'normal-arg (car argv) (cdr argv)))
|
|
|
|
|
|
|
|
|
|
|
|
((eq? #\- (string-ref (car argv) 1))
|
|
|
|
|
|
(let* ((kw-arg-pos (or (string-index (car argv) #\=)
|
|
|
|
|
|
(string-length (car argv))))
|
|
|
|
|
|
(kw (symbol->keyword (substring (car argv) 2 kw-arg-pos)))
|
|
|
|
|
|
(kw-opt? (member kw kw-opts))
|
|
|
|
|
|
(kw-arg? (member kw kw-args))
|
|
|
|
|
|
(arg (or (and (not (eq? kw-arg-pos (string-length (car argv))))
|
|
|
|
|
|
(substring (car argv)
|
|
|
|
|
|
(+ kw-arg-pos 1)
|
|
|
|
|
|
(string-length (car argv))))
|
|
|
|
|
|
(and kw-arg?
|
|
|
|
|
|
(begin (set! argv (cdr argv)) (car argv))))))
|
|
|
|
|
|
(if (or kw-opt? kw-arg?)
|
|
|
|
|
|
(return kw arg (cdr argv))
|
|
|
|
|
|
(return 'usage-error kw (cdr argv)))))
|
|
|
|
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
(let* ((char (substring (car argv) 1 2))
|
|
|
|
|
|
(kw (symbol->keyword char)))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
|
|
|
|
((member kw kw-opts)
|
|
|
|
|
|
(let* ((rest-car (substring (car argv) 2 (string-length (car argv))))
|
|
|
|
|
|
(new-argv (if (= 0 (string-length rest-car))
|
|
|
|
|
|
(cdr argv)
|
|
|
|
|
|
(cons (string-append "-" rest-car) (cdr argv)))))
|
|
|
|
|
|
(return kw #f new-argv)))
|
|
|
|
|
|
|
|
|
|
|
|
((member kw kw-args)
|
|
|
|
|
|
(let* ((rest-car (substring (car argv) 2 (string-length (car argv))))
|
|
|
|
|
|
(arg (if (= 0 (string-length rest-car))
|
|
|
|
|
|
(cadr argv)
|
|
|
|
|
|
rest-car))
|
|
|
|
|
|
(new-argv (if (= 0 (string-length rest-car))
|
|
|
|
|
|
(cddr argv)
|
|
|
|
|
|
(cdr argv))))
|
|
|
|
|
|
(return kw arg new-argv)))
|
|
|
|
|
|
|
|
|
|
|
|
(else (return 'usage-error kw argv)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (for-next-option proc argv kw-opts kw-args)
|
|
|
|
|
|
(let loop ((argv argv))
|
|
|
|
|
|
(get-option argv kw-opts kw-args
|
|
|
|
|
|
(lambda (opt opt-arg argv)
|
|
|
|
|
|
(and opt (proc opt opt-arg argv loop))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (display-usage-report kw-desc)
|
|
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (kw)
|
|
|
|
|
|
(or (eq? (car kw) #t)
|
|
|
|
|
|
(eq? (car kw) 'else)
|
|
|
|
|
|
(let* ((opt-desc kw)
|
|
|
|
|
|
(help (cadr opt-desc))
|
|
|
|
|
|
(opts (car opt-desc))
|
|
|
|
|
|
(opts-proper (if (string? (car opts)) (cdr opts) opts))
|
|
|
|
|
|
(arg-name (if (string? (car opts))
|
|
|
|
|
|
(string-append "<" (car opts) ">")
|
|
|
|
|
|
""))
|
|
|
|
|
|
(left-part (string-append
|
|
|
|
|
|
(with-output-to-string
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(map (lambda (x) (display (keyword-symbol x)) (display " "))
|
|
|
|
|
|
opts-proper)))
|
|
|
|
|
|
arg-name))
|
1997-09-16 20:16:57 +00:00
|
|
|
|
(middle-part (if (and (< (string-length left-part) 30)
|
|
|
|
|
|
(< (string-length help) 40))
|
|
|
|
|
|
(make-string (- 30 (string-length left-part)) #\ )
|
1996-07-25 22:56:11 +00:00
|
|
|
|
"\n\t")))
|
|
|
|
|
|
(display left-part)
|
|
|
|
|
|
(display middle-part)
|
|
|
|
|
|
(display help)
|
|
|
|
|
|
(newline))))
|
|
|
|
|
|
kw-desc))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (transform-usage-lambda cases)
|
|
|
|
|
|
(let* ((raw-usage (delq! 'else (map car cases)))
|
|
|
|
|
|
(usage-sans-specials (map (lambda (x)
|
|
|
|
|
|
(or (and (not (list? x)) x)
|
|
|
|
|
|
(and (symbol? (car x)) #t)
|
|
|
|
|
|
(and (boolean? (car x)) #t)
|
|
|
|
|
|
x))
|
|
|
|
|
|
raw-usage))
|
1996-12-23 04:38:04 +00:00
|
|
|
|
(usage-desc (delq! #t usage-sans-specials))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(kw-desc (map car usage-desc))
|
|
|
|
|
|
(kw-opts (apply append (map (lambda (x) (and (not (string? (car x))) x)) kw-desc)))
|
|
|
|
|
|
(kw-args (apply append (map (lambda (x) (and (string? (car x)) (cdr x))) kw-desc)))
|
|
|
|
|
|
(transmogrified-cases (map (lambda (case)
|
|
|
|
|
|
(cons (let ((opts (car case)))
|
|
|
|
|
|
(if (or (boolean? opts) (eq? 'else opts))
|
|
|
|
|
|
opts
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((symbol? (car opts)) opts)
|
|
|
|
|
|
((boolean? (car opts)) opts)
|
|
|
|
|
|
((string? (caar opts)) (cdar opts))
|
|
|
|
|
|
(else (car opts)))))
|
|
|
|
|
|
(cdr case)))
|
|
|
|
|
|
cases)))
|
|
|
|
|
|
`(let ((%display-usage (lambda () (display-usage-report ',usage-desc))))
|
|
|
|
|
|
(lambda (%argv)
|
|
|
|
|
|
(let %next-arg ((%argv %argv))
|
|
|
|
|
|
(get-option %argv
|
|
|
|
|
|
',kw-opts
|
|
|
|
|
|
',kw-args
|
|
|
|
|
|
(lambda (%opt %arg %new-argv)
|
|
|
|
|
|
(case %opt
|
|
|
|
|
|
,@ transmogrified-cases))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Low Level Modules}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; These are the low level data structures for modules.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; !!! warning: The interface to lazy binder procedures is going
|
|
|
|
|
|
;;; to be changed in an incompatible way to permit all the basic
|
|
|
|
|
|
;;; module ops to be virtualized.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; (make-module size use-list lazy-binding-proc) => module
|
|
|
|
|
|
;;; module-{obarray,uses,binder}[|-set!]
|
|
|
|
|
|
;;; (module? obj) => [#t|#f]
|
|
|
|
|
|
;;; (module-locally-bound? module symbol) => [#t|#f]
|
|
|
|
|
|
;;; (module-bound? module symbol) => [#t|#f]
|
|
|
|
|
|
;;; (module-symbol-locally-interned? module symbol) => [#t|#f]
|
|
|
|
|
|
;;; (module-symbol-interned? module symbol) => [#t|#f]
|
|
|
|
|
|
;;; (module-local-variable module symbol) => [#<variable ...> | #f]
|
|
|
|
|
|
;;; (module-variable module symbol) => [#<variable ...> | #f]
|
|
|
|
|
|
;;; (module-symbol-binding module symbol opt-value)
|
|
|
|
|
|
;;; => [ <obj> | opt-value | an error occurs ]
|
|
|
|
|
|
;;; (module-make-local-var! module symbol) => #<variable...>
|
|
|
|
|
|
;;; (module-add! module symbol var) => unspecified
|
|
|
|
|
|
;;; (module-remove! module symbol) => unspecified
|
|
|
|
|
|
;;; (module-for-each proc module) => unspecified
|
|
|
|
|
|
;;; (make-scm-module) => module ; a lazy copy of the symhash module
|
|
|
|
|
|
;;; (set-current-module module) => unspecified
|
|
|
|
|
|
;;; (current-module) => #<module...>
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {Printing Modules}
|
|
|
|
|
|
;; This is how modules are printed. You can re-define it.
|
1997-06-04 22:39:09 +00:00
|
|
|
|
;; (Redefining is actually more complicated than simply redefining
|
|
|
|
|
|
;; %print-module because that would only change the binding and not
|
|
|
|
|
|
;; the value stored in the vtable that determines how record are
|
|
|
|
|
|
;; printed. Sigh.)
|
|
|
|
|
|
|
|
|
|
|
|
(define (%print-module mod port) ; unused args: depth length style table)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(display "#<" port)
|
|
|
|
|
|
(display (or (module-kind mod) "module") port)
|
|
|
|
|
|
(let ((name (module-name mod)))
|
|
|
|
|
|
(if name
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display " " port)
|
|
|
|
|
|
(display name port))))
|
|
|
|
|
|
(display " " port)
|
|
|
|
|
|
(display (number->string (object-address mod) 16) port)
|
|
|
|
|
|
(display ">" port))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-type
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; A module is characterized by an obarray in which local symbols
|
|
|
|
|
|
;; are interned, a list of modules, "uses", from which non-local
|
|
|
|
|
|
;; bindings can be inherited, and an optional lazy-binder which
|
1996-11-21 16:16:46 +00:00
|
|
|
|
;; is a (CLOSURE module symbol) which, as a last resort, can provide
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; bindings that would otherwise not be found locally in the module.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define module-type
|
1997-09-10 20:07:04 +00:00
|
|
|
|
(make-record-type 'module
|
|
|
|
|
|
'(obarray uses binder eval-closure transformer name kind)
|
1996-10-16 02:18:33 +00:00
|
|
|
|
%print-module))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
;; make-module &opt size uses binder
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;
|
1996-10-16 02:18:33 +00:00
|
|
|
|
;; Create a new module, perhaps with a particular size of obarray,
|
|
|
|
|
|
;; initial uses list, or binding procedure.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;
|
|
|
|
|
|
(define make-module
|
|
|
|
|
|
(lambda args
|
|
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(define (parse-arg index default)
|
|
|
|
|
|
(if (> (length args) index)
|
|
|
|
|
|
(list-ref args index)
|
|
|
|
|
|
default))
|
|
|
|
|
|
|
|
|
|
|
|
(if (> (length args) 3)
|
|
|
|
|
|
(error "Too many args to make-module." args))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(let ((size (parse-arg 0 1021))
|
|
|
|
|
|
(uses (parse-arg 1 '()))
|
|
|
|
|
|
(binder (parse-arg 2 #f)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(if (not (integer? size))
|
|
|
|
|
|
(error "Illegal size to make-module." size))
|
|
|
|
|
|
(if (not (and (list? uses)
|
|
|
|
|
|
(and-map module? uses)))
|
|
|
|
|
|
(error "Incorrect use list." uses))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (and binder (not (procedure? binder)))
|
|
|
|
|
|
(error
|
|
|
|
|
|
"Lazy-binder expected to be a procedure or #f." binder))
|
|
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(let ((module (module-constructor (make-vector size '())
|
1997-09-10 20:07:04 +00:00
|
|
|
|
uses binder #f #f #f #f)))
|
1996-10-16 02:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
;; We can't pass this as an argument to module-constructor,
|
|
|
|
|
|
;; because we need it to close over a pointer to the module
|
|
|
|
|
|
;; itself.
|
1996-11-21 16:16:46 +00:00
|
|
|
|
(set-module-eval-closure! module
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(lambda (symbol define?)
|
|
|
|
|
|
(if define?
|
|
|
|
|
|
(module-make-local-var! module symbol)
|
|
|
|
|
|
(module-variable module symbol))))
|
|
|
|
|
|
|
|
|
|
|
|
module))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(define module-constructor (record-constructor module-type))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define module-obarray (record-accessor module-type 'obarray))
|
|
|
|
|
|
(define set-module-obarray! (record-modifier module-type 'obarray))
|
|
|
|
|
|
(define module-uses (record-accessor module-type 'uses))
|
|
|
|
|
|
(define set-module-uses! (record-modifier module-type 'uses))
|
|
|
|
|
|
(define module-binder (record-accessor module-type 'binder))
|
|
|
|
|
|
(define set-module-binder! (record-modifier module-type 'binder))
|
1996-11-21 16:16:46 +00:00
|
|
|
|
(define module-eval-closure (record-accessor module-type 'eval-closure))
|
|
|
|
|
|
(define set-module-eval-closure! (record-modifier module-type 'eval-closure))
|
1997-09-10 20:07:04 +00:00
|
|
|
|
(define module-transformer (record-accessor module-type 'transformer))
|
|
|
|
|
|
(define set-module-transformer! (record-modifier module-type 'transformer))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define module-name (record-accessor module-type 'name))
|
|
|
|
|
|
(define set-module-name! (record-modifier module-type 'name))
|
|
|
|
|
|
(define module-kind (record-accessor module-type 'kind))
|
|
|
|
|
|
(define set-module-kind! (record-modifier module-type 'kind))
|
|
|
|
|
|
(define module? (record-predicate module-type))
|
|
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (eval-in-module exp module)
|
1996-11-21 16:16:46 +00:00
|
|
|
|
(eval2 exp (module-eval-closure module)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Module Searching in General}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; We sometimes want to look for properties of a symbol
|
|
|
|
|
|
;;; just within the obarray of one module. If the property
|
|
|
|
|
|
;;; holds, then it is said to hold ``locally'' as in, ``The symbol
|
|
|
|
|
|
;;; DISPLAY is locally rebound in the module `safe-guile'.''
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Other times, we want to test for a symbol property in the obarray
|
|
|
|
|
|
;;; of M and, if it is not found there, try each of the modules in the
|
|
|
|
|
|
;;; uses list of M. This is the normal way of testing for some
|
|
|
|
|
|
;;; property, so we state these properties without qualification as
|
|
|
|
|
|
;;; in: ``The symbol 'fnord is interned in module M because it is
|
|
|
|
|
|
;;; interned locally in module M2 which is a member of the uses list
|
|
|
|
|
|
;;; of M.''
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; module-search fn m
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; return the first non-#f result of FN applied to M and then to
|
|
|
|
|
|
;; the modules in the uses of m, and so on recursively. If all applications
|
|
|
|
|
|
;; return #f, then so does this function.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-search fn m v)
|
|
|
|
|
|
(define (loop pos)
|
|
|
|
|
|
(and (pair? pos)
|
|
|
|
|
|
(or (module-search fn (car pos) v)
|
|
|
|
|
|
(loop (cdr pos)))))
|
|
|
|
|
|
(or (fn m v)
|
|
|
|
|
|
(loop (module-uses m))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Is a symbol bound in a module?}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Symbol S in Module M is bound if S is interned in M and if the binding
|
|
|
|
|
|
;;; of S in M has been set to some well-defined value.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; module-locally-bound? module symbol
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Is a symbol bound (interned and defined) locally in a given module?
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-locally-bound? m v)
|
|
|
|
|
|
(let ((var (module-local-variable m v)))
|
|
|
|
|
|
(and var
|
|
|
|
|
|
(variable-bound? var))))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-bound? module symbol
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Is a symbol bound (interned and defined) anywhere in a given module
|
|
|
|
|
|
;; or its uses?
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-bound? m v)
|
|
|
|
|
|
(module-search module-locally-bound? m v))
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Is a symbol interned in a module?}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Symbol S in Module M is interned if S occurs in
|
|
|
|
|
|
;;; of S in M has been set to some well-defined value.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; It is possible to intern a symbol in a module without providing
|
|
|
|
|
|
;;; an initial binding for the corresponding variable. This is done
|
|
|
|
|
|
;;; with:
|
|
|
|
|
|
;;; (module-add! module symbol (make-undefined-variable))
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; In that case, the symbol is interned in the module, but not
|
|
|
|
|
|
;;; bound there. The unbound symbol shadows any binding for that
|
|
|
|
|
|
;;; symbol that might otherwise be inherited from a member of the uses list.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-obarray-get-handle ob key)
|
|
|
|
|
|
((if (symbol? key) hashq-get-handle hash-get-handle) ob key))
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-obarray-ref ob key)
|
|
|
|
|
|
((if (symbol? key) hashq-ref hash-ref) ob key))
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-obarray-set! ob key val)
|
|
|
|
|
|
((if (symbol? key) hashq-set! hash-set!) ob key val))
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-obarray-remove! ob key)
|
|
|
|
|
|
((if (symbol? key) hashq-remove! hash-remove!) ob key))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-symbol-locally-interned? module symbol
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; is a symbol interned (not neccessarily defined) locally in a given module
|
|
|
|
|
|
;; or its uses? Interned symbols shadow inherited bindings even if
|
|
|
|
|
|
;; they are not themselves bound to a defined value.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-symbol-locally-interned? m v)
|
|
|
|
|
|
(not (not (module-obarray-get-handle (module-obarray m) v))))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-symbol-interned? module symbol
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; is a symbol interned (not neccessarily defined) anywhere in a given module
|
|
|
|
|
|
;; or its uses? Interned symbols shadow inherited bindings even if
|
|
|
|
|
|
;; they are not themselves bound to a defined value.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-symbol-interned? m v)
|
|
|
|
|
|
(module-search module-symbol-locally-interned? m v))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Mapping modules x symbols --> variables}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; module-local-variable module symbol
|
|
|
|
|
|
;; return the local variable associated with a MODULE and SYMBOL.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;;; This function is very important. It is the only function that can
|
|
|
|
|
|
;;; return a variable from a module other than the mutators that store
|
|
|
|
|
|
;;; new variables in modules. Therefore, this function is the location
|
|
|
|
|
|
;;; of the "lazy binder" hack.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; If symbol is defined in MODULE, and if the definition binds symbol
|
|
|
|
|
|
;;; to a variable, return that variable object.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; If the symbols is not found at first, but the module has a lazy binder,
|
|
|
|
|
|
;;; then try the binder.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; If the symbol is not found at all, return #f.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
(define (module-local-variable m v)
|
1996-10-06 06:33:11 +00:00
|
|
|
|
; (caddr
|
|
|
|
|
|
; (list m v
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let ((b (module-obarray-ref (module-obarray m) v)))
|
|
|
|
|
|
(or (and (variable? b) b)
|
|
|
|
|
|
(and (module-binder m)
|
1996-10-06 06:33:11 +00:00
|
|
|
|
((module-binder m) m v #f)))))
|
|
|
|
|
|
;))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; module-variable module symbol
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; like module-local-variable, except search the uses in the
|
|
|
|
|
|
;; case V is not found in M.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-variable m v)
|
|
|
|
|
|
(module-search module-local-variable m v))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Mapping modules x symbols --> bindings}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; These are similar to the mapping to variables, except that the
|
|
|
|
|
|
;;; variable is dereferenced.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; module-symbol-binding module symbol opt-value
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; return the binding of a variable specified by name within
|
|
|
|
|
|
;; a given module, signalling an error if the variable is unbound.
|
|
|
|
|
|
;; If the OPT-VALUE is passed, then instead of signalling an error,
|
|
|
|
|
|
;; return OPT-VALUE.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-symbol-local-binding m v . opt-val)
|
|
|
|
|
|
(let ((var (module-local-variable m v)))
|
|
|
|
|
|
(if var
|
|
|
|
|
|
(variable-ref var)
|
|
|
|
|
|
(if (not (null? opt-val))
|
|
|
|
|
|
(car opt-val)
|
|
|
|
|
|
(error "Locally unbound variable." v)))))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-symbol-binding module symbol opt-value
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; return the binding of a variable specified by name within
|
|
|
|
|
|
;; a given module, signalling an error if the variable is unbound.
|
|
|
|
|
|
;; If the OPT-VALUE is passed, then instead of signalling an error,
|
|
|
|
|
|
;; return OPT-VALUE.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-symbol-binding m v . opt-val)
|
|
|
|
|
|
(let ((var (module-variable m v)))
|
|
|
|
|
|
(if var
|
|
|
|
|
|
(variable-ref var)
|
|
|
|
|
|
(if (not (null? opt-val))
|
|
|
|
|
|
(car opt-val)
|
|
|
|
|
|
(error "Unbound variable." v)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Adding Variables to Modules}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; module-make-local-var! module symbol
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; ensure a variable for V in the local namespace of M.
|
|
|
|
|
|
;; If no variable was already there, then create a new and uninitialzied
|
|
|
|
|
|
;; variable.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-make-local-var! m v)
|
|
|
|
|
|
(or (let ((b (module-obarray-ref (module-obarray m) v)))
|
|
|
|
|
|
(and (variable? b) b))
|
|
|
|
|
|
(and (module-binder m)
|
|
|
|
|
|
((module-binder m) m v #t))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(let ((answer (make-undefined-variable v)))
|
|
|
|
|
|
(module-obarray-set! (module-obarray m) v answer)
|
|
|
|
|
|
answer))))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-add! module symbol var
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; ensure a particular variable for V in the local namespace of M.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-add! m v var)
|
|
|
|
|
|
(if (not (variable? var))
|
|
|
|
|
|
(error "Bad variable to module-add!" var))
|
|
|
|
|
|
(module-obarray-set! (module-obarray m) v var))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-remove!
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; make sure that a symbol is undefined in the local namespace of M.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-remove! m v)
|
|
|
|
|
|
(module-obarray-remove! (module-obarray m) v))
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-clear! m)
|
|
|
|
|
|
(vector-fill! (module-obarray m) '()))
|
|
|
|
|
|
|
|
|
|
|
|
;; MODULE-FOR-EACH -- exported
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Call PROC on each symbol in MODULE, with arguments of (SYMBOL VARIABLE).
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-for-each proc module)
|
|
|
|
|
|
(let ((obarray (module-obarray module)))
|
|
|
|
|
|
(do ((index 0 (+ index 1))
|
|
|
|
|
|
(end (vector-length obarray)))
|
|
|
|
|
|
((= index end))
|
|
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (bucket)
|
|
|
|
|
|
(proc (car bucket) (cdr bucket)))
|
|
|
|
|
|
(vector-ref obarray index)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-map proc module)
|
|
|
|
|
|
(let* ((obarray (module-obarray module))
|
|
|
|
|
|
(end (vector-length obarray)))
|
|
|
|
|
|
|
|
|
|
|
|
(let loop ((i 0)
|
|
|
|
|
|
(answer '()))
|
|
|
|
|
|
(if (= i end)
|
|
|
|
|
|
answer
|
|
|
|
|
|
(loop (+ 1 i)
|
|
|
|
|
|
(append!
|
|
|
|
|
|
(map (lambda (bucket)
|
|
|
|
|
|
(proc (car bucket) (cdr bucket)))
|
|
|
|
|
|
(vector-ref obarray i))
|
|
|
|
|
|
answer))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Low Level Bootstrapping}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; make-root-module
|
|
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
;; A root module uses the symhash table (the system's privileged
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; obarray). Being inside a root module is like using SCM without
|
|
|
|
|
|
;; any module system.
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-11-21 16:16:46 +00:00
|
|
|
|
(define (root-module-closure m s define?)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let ((bi (and (symbol-interned? #f s)
|
|
|
|
|
|
(builtin-variable s))))
|
|
|
|
|
|
(and bi
|
|
|
|
|
|
(or define? (variable-bound? bi))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(module-add! m s bi)
|
|
|
|
|
|
bi))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-root-module)
|
1996-11-21 16:16:46 +00:00
|
|
|
|
(make-module 1019 '() root-module-closure))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; make-scm-module
|
|
|
|
|
|
|
|
|
|
|
|
;; An scm module is a module into which the lazy binder copies
|
|
|
|
|
|
;; variable bindings from the system symhash table. The mapping is
|
|
|
|
|
|
;; one way only; newly introduced bindings in an scm module are not
|
|
|
|
|
|
;; copied back into the system symhash table (and can be used to override
|
|
|
|
|
|
;; bindings from the symhash table).
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-scm-module)
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(make-module 1019 '()
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(lambda (m s define?)
|
|
|
|
|
|
(let ((bi (and (symbol-interned? #f s)
|
|
|
|
|
|
(builtin-variable s))))
|
|
|
|
|
|
(and bi
|
|
|
|
|
|
(variable-bound? bi)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(module-add! m s bi)
|
|
|
|
|
|
bi))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; the-module
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define the-module #f)
|
|
|
|
|
|
|
1997-09-10 20:07:04 +00:00
|
|
|
|
;; scm:eval-transformer
|
1997-09-05 01:21:02 +00:00
|
|
|
|
;;
|
1997-09-10 20:07:04 +00:00
|
|
|
|
(define scm:eval-transformer #f)
|
1997-09-05 01:21:02 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; set-current-module module
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; set the current module as viewed by the normalizer.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (set-current-module m)
|
1997-09-10 20:07:04 +00:00
|
|
|
|
(set! the-module m)
|
|
|
|
|
|
(if m
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(set! *top-level-lookup-closure* (module-eval-closure the-module))
|
|
|
|
|
|
(set! scm:eval-transformer (module-transformer the-module)))
|
|
|
|
|
|
(set! *top-level-lookup-closure* #f)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; current-module
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; return the current module as viewed by the normalizer.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (current-module) the-module)
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Module-based Loading}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (save-module-excursion thunk)
|
|
|
|
|
|
(let ((inner-module (current-module))
|
|
|
|
|
|
(outer-module #f))
|
|
|
|
|
|
(dynamic-wind (lambda ()
|
|
|
|
|
|
(set! outer-module (current-module))
|
|
|
|
|
|
(set-current-module inner-module)
|
|
|
|
|
|
(set! inner-module #f))
|
|
|
|
|
|
thunk
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(set! inner-module (current-module))
|
|
|
|
|
|
(set-current-module outer-module)
|
|
|
|
|
|
(set! outer-module #f)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define basic-load load)
|
|
|
|
|
|
|
|
|
|
|
|
(define (load-module . args)
|
|
|
|
|
|
(save-module-excursion (lambda () (apply basic-load args))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {MODULE-REF -- exported}
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;
|
|
|
|
|
|
;; Returns the value of a variable called NAME in MODULE or any of its
|
|
|
|
|
|
;; used modules. If there is no such variable, then if the optional third
|
|
|
|
|
|
;; argument DEFAULT is present, it is returned; otherwise an error is signaled.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-ref module name . rest)
|
|
|
|
|
|
(let ((variable (module-variable module name)))
|
|
|
|
|
|
(if (and variable (variable-bound? variable))
|
|
|
|
|
|
(variable-ref variable)
|
|
|
|
|
|
(if (null? rest)
|
|
|
|
|
|
(error "No variable named" name 'in module)
|
|
|
|
|
|
(car rest) ; default value
|
|
|
|
|
|
))))
|
|
|
|
|
|
|
|
|
|
|
|
;; MODULE-SET! -- exported
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Sets the variable called NAME in MODULE (or in a module that MODULE uses)
|
|
|
|
|
|
;; to VALUE; if there is no such variable, an error is signaled.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-set! module name value)
|
|
|
|
|
|
(let ((variable (module-variable module name)))
|
|
|
|
|
|
(if variable
|
|
|
|
|
|
(variable-set! variable value)
|
|
|
|
|
|
(error "No variable named" name 'in module))))
|
|
|
|
|
|
|
|
|
|
|
|
;; MODULE-DEFINE! -- exported
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Sets the variable called NAME in MODULE to VALUE; if there is no such
|
|
|
|
|
|
;; variable, it is added first.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-define! module name value)
|
|
|
|
|
|
(let ((variable (module-local-variable module name)))
|
|
|
|
|
|
(if variable
|
|
|
|
|
|
(variable-set! variable value)
|
|
|
|
|
|
(module-add! module name (make-variable value name)))))
|
|
|
|
|
|
|
1997-02-27 15:36:04 +00:00
|
|
|
|
;; MODULE-DEFINED? -- exported
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Return #t iff NAME is defined in MODULE (or in a module that MODULE
|
|
|
|
|
|
;; uses)
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-defined? module name)
|
|
|
|
|
|
(let ((variable (module-variable module name)))
|
|
|
|
|
|
(and variable (variable-bound? variable))))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; MODULE-USE! module interface
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Add INTERFACE to the list of interfaces used by MODULE.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-use! module interface)
|
|
|
|
|
|
(set-module-uses! module
|
1997-09-10 20:07:04 +00:00
|
|
|
|
(cons interface (delq! interface (module-uses module)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Recursive Namespaces}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; A hierarchical namespace emerges if we consider some module to be
|
|
|
|
|
|
;;; root, and variables bound to modules as nested namespaces.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; The routines in this file manage variable names in hierarchical namespace.
|
|
|
|
|
|
;;; Each variable name is a list of elements, looked up in successively nested
|
|
|
|
|
|
;;; modules.
|
|
|
|
|
|
;;;
|
1996-09-13 03:02:38 +00:00
|
|
|
|
;;; (nested-ref some-root-module '(foo bar baz))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; => <value of a variable named baz in the module bound to bar in
|
|
|
|
|
|
;;; the module bound to foo in some-root-module>
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; There are:
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; ;; a-root is a module
|
|
|
|
|
|
;;; ;; name is a list of symbols
|
|
|
|
|
|
;;;
|
1996-09-13 03:02:38 +00:00
|
|
|
|
;;; nested-ref a-root name
|
|
|
|
|
|
;;; nested-set! a-root name val
|
|
|
|
|
|
;;; nested-define! a-root name val
|
|
|
|
|
|
;;; nested-remove! a-root name
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; (current-module) is a natural choice for a-root so for convenience there are
|
|
|
|
|
|
;;; also:
|
|
|
|
|
|
;;;
|
1996-09-13 03:02:38 +00:00
|
|
|
|
;;; local-ref name == nested-ref (current-module) name
|
|
|
|
|
|
;;; local-set! name val == nested-set! (current-module) name val
|
|
|
|
|
|
;;; local-define! name val == nested-define! (current-module) name val
|
|
|
|
|
|
;;; local-remove! name == nested-remove! (current-module) name
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (nested-ref root names)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let loop ((cur root)
|
|
|
|
|
|
(elts names))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((null? elts) cur)
|
|
|
|
|
|
((not (module? cur)) #f)
|
|
|
|
|
|
(else (loop (module-ref cur (car elts) #f) (cdr elts))))))
|
|
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (nested-set! root names val)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let loop ((cur root)
|
|
|
|
|
|
(elts names))
|
|
|
|
|
|
(if (null? (cdr elts))
|
|
|
|
|
|
(module-set! cur (car elts) val)
|
|
|
|
|
|
(loop (module-ref cur (car elts)) (cdr elts)))))
|
|
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (nested-define! root names val)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let loop ((cur root)
|
|
|
|
|
|
(elts names))
|
|
|
|
|
|
(if (null? (cdr elts))
|
|
|
|
|
|
(module-define! cur (car elts) val)
|
|
|
|
|
|
(loop (module-ref cur (car elts)) (cdr elts)))))
|
|
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (nested-remove! root names)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let loop ((cur root)
|
|
|
|
|
|
(elts names))
|
|
|
|
|
|
(if (null? (cdr elts))
|
|
|
|
|
|
(module-remove! cur (car elts))
|
|
|
|
|
|
(loop (module-ref cur (car elts)) (cdr elts)))))
|
|
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (local-ref names) (nested-ref (current-module) names))
|
|
|
|
|
|
(define (local-set! names val) (nested-set! (current-module) names val))
|
|
|
|
|
|
(define (local-define names val) (nested-define! (current-module) names val))
|
|
|
|
|
|
(define (local-remove names) (nested-remove! (current-module) names))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-06-24 16:26:27 +00:00
|
|
|
|
;;; {The (app) module}
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; The root of conventionally named objects not directly in the top level.
|
|
|
|
|
|
;;;
|
1997-06-24 16:26:27 +00:00
|
|
|
|
;;; (app modules)
|
|
|
|
|
|
;;; (app modules guile)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; The directory of all modules and the standard root module.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-public-interface m) (module-ref m '%module-public-interface #f))
|
|
|
|
|
|
(define (set-module-public-interface! m i) (module-define! m '%module-public-interface i))
|
|
|
|
|
|
(define the-root-module (make-root-module))
|
|
|
|
|
|
(define the-scm-module (make-scm-module))
|
|
|
|
|
|
(set-module-public-interface! the-root-module the-scm-module)
|
|
|
|
|
|
(set-module-name! the-root-module 'the-root-module)
|
|
|
|
|
|
(set-module-name! the-scm-module 'the-scm-module)
|
|
|
|
|
|
|
|
|
|
|
|
(set-current-module the-root-module)
|
|
|
|
|
|
|
|
|
|
|
|
(define app (make-module 31))
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(local-define '(app modules) (make-module 31))
|
|
|
|
|
|
(local-define '(app modules guile) the-root-module)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; (define-special-value '(app modules new-ws) (lambda () (make-scm-module)))
|
|
|
|
|
|
|
1996-12-21 09:50:38 +00:00
|
|
|
|
(define (resolve-module name . maybe-autoload)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let ((full-name (append '(app modules) name)))
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(let ((already (local-ref full-name)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(or already
|
|
|
|
|
|
(begin
|
1996-12-21 09:50:38 +00:00
|
|
|
|
(if (or (null? maybe-autoload) (car maybe-autoload))
|
1997-09-16 21:31:19 +00:00
|
|
|
|
(or (try-module-linked name)
|
|
|
|
|
|
(try-module-autoload name)
|
1997-01-18 11:29:20 +00:00
|
|
|
|
(try-module-dynamic-link name)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(make-modules-in (current-module) full-name))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (beautify-user-module! module)
|
|
|
|
|
|
(if (not (module-public-interface module))
|
|
|
|
|
|
(let ((interface (make-module 31)))
|
|
|
|
|
|
(set-module-name! interface (module-name module))
|
|
|
|
|
|
(set-module-kind! interface 'interface)
|
|
|
|
|
|
(set-module-public-interface! module interface)))
|
1997-03-08 02:29:35 +00:00
|
|
|
|
(if (and (not (memq the-scm-module (module-uses module)))
|
|
|
|
|
|
(not (eq? module the-root-module)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(set-module-uses! module (append (module-uses module) (list the-scm-module)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-modules-in module name)
|
|
|
|
|
|
(if (null? name)
|
|
|
|
|
|
module
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((module-ref module (car name) #f) => (lambda (m) (make-modules-in m (cdr name))))
|
|
|
|
|
|
(else (let ((m (make-module 31)))
|
|
|
|
|
|
(set-module-kind! m 'directory)
|
|
|
|
|
|
(set-module-name! m (car name))
|
|
|
|
|
|
(module-define! module (car name) m)
|
|
|
|
|
|
(make-modules-in m (cdr name)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (resolve-interface name)
|
|
|
|
|
|
(let ((module (resolve-module name)))
|
|
|
|
|
|
(and module (module-public-interface module))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define %autoloader-developer-mode #t)
|
|
|
|
|
|
|
|
|
|
|
|
(define (process-define-module args)
|
|
|
|
|
|
(let* ((module-id (car args))
|
1996-12-21 09:50:38 +00:00
|
|
|
|
(module (resolve-module module-id #f))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(kws (cdr args)))
|
|
|
|
|
|
(beautify-user-module! module)
|
1996-12-21 09:50:38 +00:00
|
|
|
|
(let loop ((kws kws)
|
|
|
|
|
|
(reversed-interfaces '()))
|
|
|
|
|
|
(if (null? kws)
|
|
|
|
|
|
(for-each (lambda (interface)
|
|
|
|
|
|
(module-use! module interface))
|
|
|
|
|
|
reversed-interfaces)
|
1997-03-10 15:03:41 +00:00
|
|
|
|
(case (cond ((keyword? (car kws))
|
|
|
|
|
|
(keyword->symbol (car kws)))
|
1997-03-10 15:10:48 +00:00
|
|
|
|
((and (symbol? (car kws))
|
|
|
|
|
|
(eq? (string-ref (car kws) 0) #\:))
|
1997-03-10 15:03:41 +00:00
|
|
|
|
(string->symbol (substring (car kws) 1)))
|
1997-03-10 15:10:48 +00:00
|
|
|
|
(else #f))
|
1997-03-10 15:03:41 +00:00
|
|
|
|
((use-module)
|
1996-12-21 09:50:38 +00:00
|
|
|
|
(if (not (pair? (cdr kws)))
|
|
|
|
|
|
(error "unrecognized defmodule argument" kws))
|
|
|
|
|
|
(let* ((used-name (cadr kws))
|
|
|
|
|
|
(used-module (resolve-module used-name)))
|
|
|
|
|
|
(if (not (module-ref used-module '%module-public-interface #f))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
((if %autoloader-developer-mode warn error)
|
|
|
|
|
|
"no code for module" (module-name used-module))
|
|
|
|
|
|
(beautify-user-module! used-module)))
|
|
|
|
|
|
(let ((interface (module-public-interface used-module)))
|
|
|
|
|
|
(if (not interface)
|
|
|
|
|
|
(error "missing interface for use-module" used-module))
|
|
|
|
|
|
(loop (cddr kws) (cons interface reversed-interfaces)))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(error "unrecognized defmodule argument" kws)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
module))
|
|
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {Autoloading modules}
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define autoloads-in-progress '())
|
|
|
|
|
|
|
|
|
|
|
|
(define (try-module-autoload module-name)
|
1996-10-06 06:33:11 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (sfx name) (string-append name (scheme-file-suffix)))
|
|
|
|
|
|
(let* ((reverse-name (reverse module-name))
|
|
|
|
|
|
(name (car reverse-name))
|
|
|
|
|
|
(dir-hint-module-name (reverse (cdr reverse-name)))
|
|
|
|
|
|
(dir-hint (apply symbol-append (map (lambda (elt) (symbol-append elt "/")) dir-hint-module-name))))
|
1996-12-21 09:50:38 +00:00
|
|
|
|
(resolve-module dir-hint-module-name #f)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(and (not (autoload-done-or-in-progress? dir-hint name))
|
|
|
|
|
|
(let ((didit #f))
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
|
(lambda () (autoload-in-progress! dir-hint name))
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let loop ((dirs %load-path))
|
|
|
|
|
|
(and (not (null? dirs))
|
|
|
|
|
|
(or
|
|
|
|
|
|
(let ((d (car dirs))
|
|
|
|
|
|
(trys (list
|
|
|
|
|
|
dir-hint
|
|
|
|
|
|
(sfx dir-hint)
|
|
|
|
|
|
(in-vicinity dir-hint name)
|
|
|
|
|
|
(in-vicinity dir-hint (sfx name)))))
|
|
|
|
|
|
(and (or-map (lambda (f)
|
|
|
|
|
|
(let ((full (in-vicinity d f)))
|
|
|
|
|
|
full
|
1996-10-06 06:33:11 +00:00
|
|
|
|
(and (file-exists? full)
|
|
|
|
|
|
(not (file-is-directory? full))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(begin
|
|
|
|
|
|
(save-module-excursion
|
|
|
|
|
|
(lambda ()
|
* boot-9.scm (error): replace another throw with scm-error. Throw
to 'misc-error instead of 'error (no need to distinguish these.)
Don't set up 'error as a key.
Set up regex-error as a key, if regex is available.
(signal-handler): use scm-error, not throw.
(%try-load, try-load-with-path, %load, load-with-path,
basic-try-load-with-path, basic-load-with-path,
try-load-module-with-path,load-module-with-path): deleted, since
they seem redundant.
(try-load): define using %try-load, not try-load-with-path.
(load): rewritten. load tries to open the file directly and
with a .scm extension before searching the library directories
(should "." be added to %load-path? then load could still open
directly files starting with "/").
(try-module-autoload): use load, not load-with-path.
(%load-indent): deleted, -2 was causing errors.
(%read-sharp): use port-line, not line-number.
1996-09-28 19:38:45 +00:00
|
|
|
|
(load (string-append
|
|
|
|
|
|
d "/" f))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
#t))))
|
|
|
|
|
|
trys)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(set! didit #t)
|
|
|
|
|
|
#t)))
|
|
|
|
|
|
(loop (cdr dirs))))))
|
|
|
|
|
|
(lambda () (set-autoloaded! dir-hint name didit)))
|
|
|
|
|
|
didit))))
|
|
|
|
|
|
|
1997-01-18 11:29:20 +00:00
|
|
|
|
;;; Dynamic linking of modules
|
|
|
|
|
|
|
|
|
|
|
|
;; Initializing a module that is written in C is a two step process.
|
|
|
|
|
|
;; First the module's `module init' function is called. This function
|
|
|
|
|
|
;; is expected to call `scm_register_module_xxx' to register the `real
|
|
|
|
|
|
;; init' function. Later, when the module is referenced for the first
|
|
|
|
|
|
;; time, this real init function is called in the right context. See
|
|
|
|
|
|
;; gtcltk-lib/gtcltk-module.c for an example.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; The code for the module can be in a regular shared library (so that
|
|
|
|
|
|
;; the `module init' function will be called when libguile is
|
|
|
|
|
|
;; initialized). Or it can be dynamically linked.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; You can safely call `scm_register_module_xxx' before libguile
|
|
|
|
|
|
;; itself is initialized. You could call it from an C++ constructor
|
|
|
|
|
|
;; of a static object, for example.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; To make your Guile extension into a dynamic linkable module, follow
|
|
|
|
|
|
;; these easy steps:
|
|
|
|
|
|
;;
|
1997-06-24 16:26:27 +00:00
|
|
|
|
;; - Find a name for your module, like (ice-9 gtcltk)
|
1997-01-18 11:29:20 +00:00
|
|
|
|
;; - Write a function with a name like
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; scm_init_ice_9_gtcltk_module
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; This is your `module init' function. It should call
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; scm_register_module_xxx ("ice-9 gtcltk", scm_init_gtcltk);
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; "ice-9 gtcltk" is the C version of the module name. Slashes are
|
|
|
|
|
|
;; replaced by spaces, the rest is untouched. `scm_init_gtcltk' is
|
1997-02-27 15:36:04 +00:00
|
|
|
|
;; the real init function that executes the usual initializations
|
1997-01-18 11:29:20 +00:00
|
|
|
|
;; like making new smobs, etc.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; - Make a shared library with your code and a name like
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; ice-9/libgtcltk.so
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; and put it somewhere in %load-path.
|
|
|
|
|
|
;;
|
1997-06-24 16:26:27 +00:00
|
|
|
|
;; - Then you can simply write `:use-module (ice-9 gtcltk)' and it
|
1997-01-18 11:29:20 +00:00
|
|
|
|
;; will be linked automatically.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; This is all very experimental.
|
|
|
|
|
|
|
|
|
|
|
|
(define (split-c-module-name str)
|
|
|
|
|
|
(let loop ((rev '())
|
|
|
|
|
|
(start 0)
|
|
|
|
|
|
(pos 0)
|
|
|
|
|
|
(end (string-length str)))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((= pos end)
|
|
|
|
|
|
(reverse (cons (string->symbol (substring str start pos)) rev)))
|
|
|
|
|
|
((eq? (string-ref str pos) #\space)
|
|
|
|
|
|
(loop (cons (string->symbol (substring str start pos)) rev)
|
|
|
|
|
|
(+ pos 1)
|
|
|
|
|
|
(+ pos 1)
|
|
|
|
|
|
end))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(loop rev start (+ pos 1) end)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (convert-c-registered-modules dynobj)
|
|
|
|
|
|
(let ((res (map (lambda (c)
|
|
|
|
|
|
(list (split-c-module-name (car c)) (cdr c) dynobj))
|
|
|
|
|
|
(c-registered-modules))))
|
|
|
|
|
|
(c-clear-registered-modules)
|
|
|
|
|
|
res))
|
|
|
|
|
|
|
|
|
|
|
|
(define registered-modules (convert-c-registered-modules #f))
|
|
|
|
|
|
|
|
|
|
|
|
(define (init-dynamic-module modname)
|
|
|
|
|
|
(or-map (lambda (modinfo)
|
|
|
|
|
|
(if (equal? (car modinfo) modname)
|
|
|
|
|
|
(let ((mod (resolve-module modname #f)))
|
|
|
|
|
|
(save-module-excursion
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(set-current-module mod)
|
|
|
|
|
|
(dynamic-call (cadr modinfo) (caddr modinfo))
|
|
|
|
|
|
(set-module-public-interface! mod mod)))
|
|
|
|
|
|
(set! registered-modules (delq! modinfo registered-modules))
|
|
|
|
|
|
#t)
|
|
|
|
|
|
#f))
|
|
|
|
|
|
registered-modules))
|
|
|
|
|
|
|
|
|
|
|
|
(define (dynamic-maybe-call name dynobj)
|
|
|
|
|
|
(catch #t ; could use false-if-exception here
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(dynamic-call name dynobj))
|
|
|
|
|
|
(lambda args
|
|
|
|
|
|
#f)))
|
|
|
|
|
|
|
1997-02-27 15:36:04 +00:00
|
|
|
|
(define (dynamic-maybe-link filename)
|
|
|
|
|
|
(catch #t ; could use false-if-exception here
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(dynamic-link filename))
|
|
|
|
|
|
(lambda args
|
|
|
|
|
|
#f)))
|
|
|
|
|
|
|
1997-01-18 11:29:20 +00:00
|
|
|
|
(define (find-and-link-dynamic-module module-name)
|
|
|
|
|
|
(define (make-init-name mod-name)
|
|
|
|
|
|
(string-append 'scm_init
|
|
|
|
|
|
(list->string (map (lambda (c)
|
|
|
|
|
|
(if (or (char-alphabetic? c)
|
|
|
|
|
|
(char-numeric? c))
|
|
|
|
|
|
c
|
|
|
|
|
|
#\_))
|
|
|
|
|
|
(string->list mod-name)))
|
|
|
|
|
|
'_module))
|
1997-11-28 17:22:20 +00:00
|
|
|
|
|
|
|
|
|
|
;; Put the subdirectory for this module in the car of SUBDIR-AND-LIBNAME,
|
|
|
|
|
|
;; and the `libname' (the name of the module prepended by `lib') in the cdr
|
|
|
|
|
|
;; field. For example, if MODULE-NAME is the list (inet tcp-ip udp), then
|
|
|
|
|
|
;; SUBDIR-AND-LIBNAME will be the pair ("inet/tcp-ip" . "libudp").
|
|
|
|
|
|
(let ((subdir-and-libname
|
1997-01-18 11:29:20 +00:00
|
|
|
|
(let loop ((dirs "")
|
|
|
|
|
|
(syms module-name))
|
1997-11-28 17:22:20 +00:00
|
|
|
|
(if (null? (cdr syms))
|
|
|
|
|
|
(cons dirs (string-append "lib" (car syms)))
|
|
|
|
|
|
(loop (string-append dirs (car syms) "/") (cdr syms)))))
|
1997-01-18 11:29:20 +00:00
|
|
|
|
(init (make-init-name (apply string-append
|
|
|
|
|
|
(map (lambda (s)
|
|
|
|
|
|
(string-append "_" s))
|
|
|
|
|
|
module-name)))))
|
1997-11-28 17:22:20 +00:00
|
|
|
|
(let ((subdir (car subdir-and-libname))
|
|
|
|
|
|
(libname (cdr subdir-and-libname)))
|
|
|
|
|
|
|
|
|
|
|
|
;; Now look in each dir in %LOAD-PATH for `subdir/libfoo.la'. If that
|
|
|
|
|
|
;; file exists, fetch the dlname from that file and attempt to link
|
|
|
|
|
|
;; against it. If `subdir/libfoo.la' does not exist, or does not seem
|
|
|
|
|
|
;; to name any shared library, look for `subdir/libfoo.so' instead and
|
|
|
|
|
|
;; link against that.
|
|
|
|
|
|
(let check-dirs ((dir-list %load-path))
|
|
|
|
|
|
(if (null? dir-list)
|
|
|
|
|
|
#f
|
|
|
|
|
|
(let* ((dir (in-vicinity (car dir-list) subdir))
|
|
|
|
|
|
(sharlib-full
|
|
|
|
|
|
(or (try-using-libtool-name dir libname)
|
|
|
|
|
|
(try-using-sharlib-name dir libname))))
|
|
|
|
|
|
(if (and sharlib-full (file-exists? sharlib-full))
|
|
|
|
|
|
(link-dynamic-module sharlib-full init)
|
|
|
|
|
|
(check-dirs (cdr dir-list)))))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (try-using-libtool-name libdir libname)
|
|
|
|
|
|
;; FIXME: is `use-modules' legal inside `define'?
|
|
|
|
|
|
(use-modules (ice-9 regex))
|
|
|
|
|
|
(let ((libtool-filename (in-vicinity libdir
|
|
|
|
|
|
(string-append libname ".la"))))
|
|
|
|
|
|
(and (file-exists? libtool-filename)
|
|
|
|
|
|
(let ((dlname-pattern (make-regexp "^dlname='(.*)'")))
|
|
|
|
|
|
(with-input-from-file libtool-filename
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let loop ((ln (read-line)))
|
|
|
|
|
|
(cond ((eof-object? ln) #f)
|
|
|
|
|
|
((regexp-exec dlname-pattern ln)
|
|
|
|
|
|
=> (lambda (match)
|
|
|
|
|
|
(in-vicinity libdir (match:substring match 1))))
|
|
|
|
|
|
(else (loop (read-line)))))))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (try-using-sharlib-name libdir libname)
|
|
|
|
|
|
(in-vicinity libdir (string-append libname ".so")))
|
1997-01-18 11:29:20 +00:00
|
|
|
|
|
|
|
|
|
|
(define (link-dynamic-module filename initname)
|
1997-04-30 13:35:11 +00:00
|
|
|
|
(let ((dynobj (dynamic-link filename)))
|
|
|
|
|
|
(dynamic-call initname dynobj)
|
|
|
|
|
|
(set! registered-modules
|
|
|
|
|
|
(append! (convert-c-registered-modules dynobj)
|
|
|
|
|
|
registered-modules))))
|
1997-09-16 21:31:19 +00:00
|
|
|
|
|
|
|
|
|
|
(define (try-module-linked module-name)
|
|
|
|
|
|
(init-dynamic-module module-name))
|
|
|
|
|
|
|
1997-01-18 11:29:20 +00:00
|
|
|
|
(define (try-module-dynamic-link module-name)
|
1997-09-16 21:31:19 +00:00
|
|
|
|
(and (find-and-link-dynamic-module module-name)
|
|
|
|
|
|
(init-dynamic-module module-name)))
|
1997-01-18 11:29:20 +00:00
|
|
|
|
|
1997-02-27 15:36:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define autoloads-done '((guile . guile)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (autoload-done-or-in-progress? p m)
|
|
|
|
|
|
(let ((n (cons p m)))
|
|
|
|
|
|
(->bool (or (member n autoloads-done)
|
|
|
|
|
|
(member n autoloads-in-progress)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (autoload-done! p m)
|
|
|
|
|
|
(let ((n (cons p m)))
|
|
|
|
|
|
(set! autoloads-in-progress
|
|
|
|
|
|
(delete! n autoloads-in-progress))
|
|
|
|
|
|
(or (member n autoloads-done)
|
|
|
|
|
|
(set! autoloads-done (cons n autoloads-done)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (autoload-in-progress! p m)
|
|
|
|
|
|
(let ((n (cons p m)))
|
|
|
|
|
|
(set! autoloads-done
|
|
|
|
|
|
(delete! n autoloads-done))
|
|
|
|
|
|
(set! autoloads-in-progress (cons n autoloads-in-progress))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (set-autoloaded! p m done?)
|
|
|
|
|
|
(if done?
|
|
|
|
|
|
(autoload-done! p m)
|
|
|
|
|
|
(let ((n (cons p m)))
|
|
|
|
|
|
(set! autoloads-done (delete! n autoloads-done))
|
|
|
|
|
|
(set! autoloads-in-progress (delete! n autoloads-in-progress)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Macros}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
1997-09-10 20:07:04 +00:00
|
|
|
|
(define (primitive-macro? m)
|
|
|
|
|
|
(and (macro? m)
|
|
|
|
|
|
(not (macro-transformer m))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Defmacros}
|
|
|
|
|
|
;;;
|
1996-08-20 16:54:53 +00:00
|
|
|
|
(define macro-table (make-weak-key-hash-table 523))
|
|
|
|
|
|
(define xformer-table (make-weak-key-hash-table 523))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (defmacro? m) (hashq-ref macro-table m))
|
|
|
|
|
|
(define (assert-defmacro?! m) (hashq-set! macro-table m #t))
|
|
|
|
|
|
(define (defmacro-transformer m) (hashq-ref xformer-table m))
|
|
|
|
|
|
(define (set-defmacro-transformer! m t) (hashq-set! xformer-table m t))
|
|
|
|
|
|
|
|
|
|
|
|
(define defmacro:transformer
|
|
|
|
|
|
(lambda (f)
|
|
|
|
|
|
(let* ((xform (lambda (exp env)
|
|
|
|
|
|
(copy-tree (apply f (cdr exp)))))
|
|
|
|
|
|
(a (procedure->memoizing-macro xform)))
|
|
|
|
|
|
(assert-defmacro?! a)
|
|
|
|
|
|
(set-defmacro-transformer! a f)
|
|
|
|
|
|
a)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define defmacro
|
|
|
|
|
|
(let ((defmacro-transformer
|
|
|
|
|
|
(lambda (name parms . body)
|
|
|
|
|
|
(let ((transformer `(lambda ,parms ,@body)))
|
|
|
|
|
|
`(define ,name
|
|
|
|
|
|
(,(lambda (transformer)
|
|
|
|
|
|
(defmacro:transformer transformer))
|
|
|
|
|
|
,transformer))))))
|
|
|
|
|
|
(defmacro:transformer defmacro-transformer)))
|
|
|
|
|
|
|
|
|
|
|
|
(define defmacro:syntax-transformer
|
|
|
|
|
|
(lambda (f)
|
|
|
|
|
|
(procedure->syntax
|
|
|
|
|
|
(lambda (exp env)
|
|
|
|
|
|
(copy-tree (apply f (cdr exp)))))))
|
|
|
|
|
|
|
1997-02-27 15:36:04 +00:00
|
|
|
|
|
|
|
|
|
|
;; XXX - should the definition of the car really be looked up in the
|
|
|
|
|
|
;; current module?
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (macroexpand-1 e)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((pair? e) (let* ((a (car e))
|
1997-02-27 15:36:04 +00:00
|
|
|
|
(val (and (symbol? a) (local-ref (list a)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (defmacro? val)
|
|
|
|
|
|
(apply (defmacro-transformer val) (cdr e))
|
|
|
|
|
|
e)))
|
|
|
|
|
|
(#t e)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (macroexpand e)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((pair? e) (let* ((a (car e))
|
1997-02-27 15:36:04 +00:00
|
|
|
|
(val (and (symbol? a) (local-ref (list a)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (defmacro? val)
|
|
|
|
|
|
(macroexpand (apply (defmacro-transformer val) (cdr e)))
|
|
|
|
|
|
e)))
|
|
|
|
|
|
(#t e)))
|
|
|
|
|
|
|
1997-09-01 22:27:58 +00:00
|
|
|
|
(define (gentemp)
|
|
|
|
|
|
(gensym "scm:G"))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-09-20 13:57:22 +00:00
|
|
|
|
(provide 'defmacro)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-09-28 20:12:17 +00:00
|
|
|
|
;;; {Run-time options}
|
|
|
|
|
|
|
|
|
|
|
|
((let* ((names '((debug-options-interface
|
|
|
|
|
|
(debug-options debug-enable debug-disable)
|
|
|
|
|
|
(debug-set!))
|
|
|
|
|
|
|
|
|
|
|
|
(evaluator-traps-interface
|
|
|
|
|
|
(traps trap-enable trap-disable)
|
|
|
|
|
|
(trap-set!))
|
|
|
|
|
|
|
|
|
|
|
|
(read-options-interface
|
|
|
|
|
|
(read-options read-enable read-disable)
|
|
|
|
|
|
(read-set!))
|
|
|
|
|
|
|
|
|
|
|
|
(print-options-interface
|
|
|
|
|
|
(print-options print-enable print-disable)
|
|
|
|
|
|
(print-set!))
|
|
|
|
|
|
))
|
|
|
|
|
|
(option-name car)
|
|
|
|
|
|
(option-value cadr)
|
|
|
|
|
|
(option-documentation caddr)
|
|
|
|
|
|
|
|
|
|
|
|
(print-option (lambda (option)
|
|
|
|
|
|
(display (option-name option))
|
|
|
|
|
|
(if (< (string-length
|
|
|
|
|
|
(symbol->string (option-name option)))
|
|
|
|
|
|
8)
|
|
|
|
|
|
(display #\tab))
|
|
|
|
|
|
(display #\tab)
|
|
|
|
|
|
(display (option-value option))
|
|
|
|
|
|
(display #\tab)
|
|
|
|
|
|
(display (option-documentation option))
|
|
|
|
|
|
(newline)))
|
|
|
|
|
|
|
|
|
|
|
|
;; Below follows the macros defining the run-time option interfaces.
|
|
|
|
|
|
|
|
|
|
|
|
(make-options (lambda (interface)
|
|
|
|
|
|
`(lambda args
|
|
|
|
|
|
(cond ((null? args) (,interface))
|
|
|
|
|
|
((pair? (car args))
|
|
|
|
|
|
(,interface (car args)) (,interface))
|
1997-09-29 01:23:59 +00:00
|
|
|
|
(else (for-each ,print-option
|
1997-09-28 20:12:17 +00:00
|
|
|
|
(,interface #t)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(make-enable (lambda (interface)
|
|
|
|
|
|
`(lambda flags
|
|
|
|
|
|
(,interface (append flags (,interface)))
|
|
|
|
|
|
(,interface))))
|
|
|
|
|
|
|
|
|
|
|
|
(make-disable (lambda (interface)
|
|
|
|
|
|
`(lambda flags
|
|
|
|
|
|
(let ((options (,interface)))
|
|
|
|
|
|
(for-each (lambda (flag)
|
|
|
|
|
|
(set! options (delq! flag options)))
|
|
|
|
|
|
flags)
|
|
|
|
|
|
(,interface options)
|
|
|
|
|
|
(,interface)))))
|
|
|
|
|
|
|
|
|
|
|
|
(make-set! (lambda (interface)
|
|
|
|
|
|
`((name exp)
|
|
|
|
|
|
(,'quasiquote
|
|
|
|
|
|
(begin (,interface (append (,interface)
|
|
|
|
|
|
(list '(,'unquote name)
|
|
|
|
|
|
(,'unquote exp))))
|
|
|
|
|
|
(,interface))))))
|
|
|
|
|
|
)
|
|
|
|
|
|
(procedure->macro
|
|
|
|
|
|
(lambda (exp env)
|
|
|
|
|
|
(cons 'begin
|
|
|
|
|
|
(apply append
|
|
|
|
|
|
(map (lambda (group)
|
|
|
|
|
|
(let ((interface (car group)))
|
|
|
|
|
|
(append (map (lambda (name constructor)
|
|
|
|
|
|
`(define ,name
|
|
|
|
|
|
,(constructor interface)))
|
|
|
|
|
|
(cadr group)
|
|
|
|
|
|
(list make-options
|
|
|
|
|
|
make-enable
|
|
|
|
|
|
make-disable))
|
|
|
|
|
|
(map (lambda (name constructor)
|
|
|
|
|
|
`(defmacro ,name
|
|
|
|
|
|
,@(constructor interface)))
|
|
|
|
|
|
(caddr group)
|
|
|
|
|
|
(list make-set!)))))
|
|
|
|
|
|
names)))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Running Repls}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (repl read evaler print)
|
1997-03-08 19:02:20 +00:00
|
|
|
|
(let loop ((source (read (current-input-port))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(print (evaler source))
|
1997-03-08 19:02:20 +00:00
|
|
|
|
(loop (read (current-input-port)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; A provisional repl that acts like the SCM repl:
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define scm-repl-silent #f)
|
|
|
|
|
|
(define (assert-repl-silence v) (set! scm-repl-silent v))
|
|
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(define *unspecified* (if #f #f))
|
|
|
|
|
|
(define (unspecified? v) (eq? v *unspecified*))
|
|
|
|
|
|
|
|
|
|
|
|
(define scm-repl-print-unspecified #f)
|
|
|
|
|
|
(define (assert-repl-print-unspecified v) (set! scm-repl-print-unspecified v))
|
|
|
|
|
|
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
(define scm-repl-verbose #f)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (assert-repl-verbosity v) (set! scm-repl-verbose v))
|
|
|
|
|
|
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
(define scm-repl-prompt "guile> ")
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
(define (set-repl-prompt! v) (set! scm-repl-prompt v))
|
|
|
|
|
|
|
1997-03-01 01:01:09 +00:00
|
|
|
|
(define (default-lazy-handler key . args)
|
|
|
|
|
|
(save-stack lazy-handler-dispatch)
|
|
|
|
|
|
(apply throw key args))
|
|
|
|
|
|
|
|
|
|
|
|
(define apply-frame-handler default-lazy-handler)
|
|
|
|
|
|
(define exit-frame-handler default-lazy-handler)
|
|
|
|
|
|
|
|
|
|
|
|
(define (lazy-handler-dispatch key . args)
|
|
|
|
|
|
(case key
|
|
|
|
|
|
((apply-frame)
|
|
|
|
|
|
(apply apply-frame-handler key args))
|
|
|
|
|
|
((exit-frame)
|
|
|
|
|
|
(apply exit-frame-handler key args))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(apply default-lazy-handler key args))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-03-01 01:34:23 +00:00
|
|
|
|
(define abort-hook '())
|
|
|
|
|
|
|
1997-11-09 23:36:17 +00:00
|
|
|
|
;; these definitions are used if running a script.
|
|
|
|
|
|
;; otherwise redefined in error-catching-loop.
|
|
|
|
|
|
(define (set-batch-mode?! arg) #t)
|
|
|
|
|
|
(define (batch-mode?) #t)
|
1997-10-11 20:42:24 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (error-catching-loop thunk)
|
1997-10-11 20:42:24 +00:00
|
|
|
|
(let ((status #f)
|
|
|
|
|
|
(interactive #t))
|
|
|
|
|
|
(set! set-batch-mode?! (lambda (arg)
|
|
|
|
|
|
(cond (arg
|
|
|
|
|
|
(set! interactive #f)
|
|
|
|
|
|
(restore-signals))
|
|
|
|
|
|
(#t
|
|
|
|
|
|
(error "sorry, not implemented")))))
|
|
|
|
|
|
(set! batch-mode? (lambda () (not interactive)))
|
1997-03-02 06:09:41 +00:00
|
|
|
|
(define (loop first)
|
|
|
|
|
|
(let ((next
|
|
|
|
|
|
(catch #t
|
1996-10-17 21:45:04 +00:00
|
|
|
|
|
1997-03-02 06:09:41 +00:00
|
|
|
|
(lambda ()
|
|
|
|
|
|
(lazy-catch #t
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
|
(lambda () (unmask-signals))
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(first)
|
|
|
|
|
|
|
|
|
|
|
|
;; This line is needed because mark
|
|
|
|
|
|
;; doesn't do closures quite right.
|
|
|
|
|
|
;; Unreferenced locals should be
|
|
|
|
|
|
;; collected.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(set! first #f)
|
|
|
|
|
|
(let loop ((v (thunk)))
|
|
|
|
|
|
(loop (thunk)))
|
|
|
|
|
|
#f)
|
|
|
|
|
|
(lambda () (mask-signals))))
|
|
|
|
|
|
|
|
|
|
|
|
lazy-handler-dispatch))
|
|
|
|
|
|
|
|
|
|
|
|
(lambda (key . args)
|
|
|
|
|
|
(case key
|
|
|
|
|
|
((quit)
|
|
|
|
|
|
(force-output)
|
|
|
|
|
|
(set! status args)
|
|
|
|
|
|
#f)
|
|
|
|
|
|
|
|
|
|
|
|
((switch-repl)
|
|
|
|
|
|
(apply throw 'switch-repl args))
|
|
|
|
|
|
|
|
|
|
|
|
((abort)
|
|
|
|
|
|
;; This is one of the closures that require
|
|
|
|
|
|
;; (set! first #f) above
|
|
|
|
|
|
;;
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(run-hooks abort-hook)
|
|
|
|
|
|
(force-output)
|
|
|
|
|
|
(display "ABORT: " (current-error-port))
|
|
|
|
|
|
(write args (current-error-port))
|
|
|
|
|
|
(newline (current-error-port))
|
1997-10-11 20:42:24 +00:00
|
|
|
|
(if interactive
|
|
|
|
|
|
(if (and (not has-shown-debugger-hint?)
|
|
|
|
|
|
(not (memq 'backtrace
|
|
|
|
|
|
(debug-options-interface)))
|
1997-11-29 01:11:21 +00:00
|
|
|
|
(stack? (fluid-ref the-last-stack)))
|
1997-10-11 20:42:24 +00:00
|
|
|
|
(begin
|
|
|
|
|
|
(newline (current-error-port))
|
|
|
|
|
|
(display
|
|
|
|
|
|
"Type \"(backtrace)\" to get more information.\n"
|
|
|
|
|
|
(current-error-port))
|
|
|
|
|
|
(set! has-shown-debugger-hint? #t)))
|
|
|
|
|
|
(primitive-exit 1))
|
1997-03-02 06:09:41 +00:00
|
|
|
|
(set! stack-saved? #f)))
|
|
|
|
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
;; This is the other cons-leak closure...
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(cond ((= (length args) 4)
|
|
|
|
|
|
(apply handle-system-error key args))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(apply bad-throw key args))))))))))
|
|
|
|
|
|
(if next (loop next) status)))
|
|
|
|
|
|
(loop (lambda () #t))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-11-29 01:11:21 +00:00
|
|
|
|
;;(define the-last-stack (make-fluid)) Defined by scm_init_backtrace ()
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(define stack-saved? #f)
|
|
|
|
|
|
|
|
|
|
|
|
(define (save-stack . narrowing)
|
|
|
|
|
|
(cond (stack-saved?)
|
|
|
|
|
|
((not (memq 'debug (debug-options-interface)))
|
1997-11-29 01:11:21 +00:00
|
|
|
|
(fluid-set! the-last-stack #f)
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(set! stack-saved? #t))
|
|
|
|
|
|
(else
|
1997-11-29 01:11:21 +00:00
|
|
|
|
(fluid-set!
|
|
|
|
|
|
the-last-stack
|
|
|
|
|
|
(case (stack-id #t)
|
|
|
|
|
|
((repl-stack)
|
|
|
|
|
|
(apply make-stack #t save-stack eval narrowing))
|
|
|
|
|
|
((load-stack)
|
|
|
|
|
|
(apply make-stack #t save-stack 0 narrowing))
|
|
|
|
|
|
((tk-stack)
|
|
|
|
|
|
(apply make-stack #t save-stack tk-stack-mark narrowing))
|
|
|
|
|
|
((#t)
|
|
|
|
|
|
(apply make-stack #t save-stack 0 1 narrowing))
|
|
|
|
|
|
(else (let ((id (stack-id #t)))
|
|
|
|
|
|
(and (procedure? id)
|
|
|
|
|
|
(apply make-stack #t save-stack id narrowing))))))
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(set! stack-saved? #t))))
|
1996-10-17 23:43:23 +00:00
|
|
|
|
|
1997-03-01 01:34:23 +00:00
|
|
|
|
(define before-error-hook '())
|
|
|
|
|
|
(define after-error-hook '())
|
|
|
|
|
|
(define before-backtrace-hook '())
|
|
|
|
|
|
(define after-backtrace-hook '())
|
1996-10-17 23:43:23 +00:00
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(define has-shown-debugger-hint? #f)
|
|
|
|
|
|
|
1996-10-17 21:56:22 +00:00
|
|
|
|
(define (handle-system-error key . args)
|
|
|
|
|
|
(let ((cep (current-error-port)))
|
1997-11-29 01:11:21 +00:00
|
|
|
|
(cond ((not (stack? (fluid-ref the-last-stack))))
|
1996-11-02 20:51:30 +00:00
|
|
|
|
((memq 'backtrace (debug-options-interface))
|
1997-03-01 01:34:23 +00:00
|
|
|
|
(run-hooks before-backtrace-hook)
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(newline cep)
|
1997-11-29 01:11:21 +00:00
|
|
|
|
(display-backtrace (fluid-ref the-last-stack) cep)
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(newline cep)
|
1997-03-01 01:34:23 +00:00
|
|
|
|
(run-hooks after-backtrace-hook)))
|
|
|
|
|
|
(run-hooks before-error-hook)
|
1997-11-29 01:11:21 +00:00
|
|
|
|
(apply display-error (fluid-ref the-last-stack) cep args)
|
1997-03-01 01:34:23 +00:00
|
|
|
|
(run-hooks after-error-hook)
|
1996-10-17 21:56:22 +00:00
|
|
|
|
(force-output cep)
|
|
|
|
|
|
(throw 'abort key)))
|
1996-11-02 20:51:30 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (quit . args)
|
|
|
|
|
|
(apply throw 'quit args))
|
|
|
|
|
|
|
1997-03-02 19:53:32 +00:00
|
|
|
|
(define exit quit)
|
|
|
|
|
|
|
1997-02-10 01:05:50 +00:00
|
|
|
|
;;(define has-shown-backtrace-hint? #f) Defined by scm_init_backtrace ()
|
|
|
|
|
|
|
|
|
|
|
|
;; Replaced by C code:
|
|
|
|
|
|
;;(define (backtrace)
|
1997-11-29 01:11:21 +00:00
|
|
|
|
;; (if (fluid-ref the-last-stack)
|
1997-02-10 01:05:50 +00:00
|
|
|
|
;; (begin
|
|
|
|
|
|
;; (newline)
|
1997-11-29 01:11:21 +00:00
|
|
|
|
;; (display-backtrace (fluid-ref the-last-stack) (current-output-port))
|
1997-02-10 01:05:50 +00:00
|
|
|
|
;; (newline)
|
|
|
|
|
|
;; (if (and (not has-shown-backtrace-hint?)
|
|
|
|
|
|
;; (not (memq 'backtrace (debug-options-interface))))
|
|
|
|
|
|
;; (begin
|
|
|
|
|
|
;; (display
|
|
|
|
|
|
;;"Type \"(debug-enable 'backtrace)\" if you would like a backtrace
|
|
|
|
|
|
;;automatically if an error occurs in the future.\n")
|
|
|
|
|
|
;; (set! has-shown-backtrace-hint? #t))))
|
|
|
|
|
|
;; (display "No backtrace available.\n")))
|
1996-11-02 20:51:30 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (error-catching-repl r e p)
|
|
|
|
|
|
(error-catching-loop (lambda () (p (e (r))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (gc-run-time)
|
|
|
|
|
|
(cdr (assq 'gc-time-taken (gc-stats))))
|
|
|
|
|
|
|
1997-03-01 01:34:23 +00:00
|
|
|
|
(define before-read-hook '())
|
|
|
|
|
|
(define after-read-hook '())
|
1996-10-17 23:43:23 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (scm-style-repl)
|
|
|
|
|
|
(letrec (
|
|
|
|
|
|
(start-gc-rt #f)
|
|
|
|
|
|
(start-rt #f)
|
1997-10-27 07:07:03 +00:00
|
|
|
|
(repl-report-reset (lambda () #f))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(repl-report-start-timing (lambda ()
|
|
|
|
|
|
(set! start-gc-rt (gc-run-time))
|
|
|
|
|
|
(set! start-rt (get-internal-run-time))))
|
|
|
|
|
|
(repl-report (lambda ()
|
|
|
|
|
|
(display ";;; ")
|
|
|
|
|
|
(display (inexact->exact
|
|
|
|
|
|
(* 1000 (/ (- (get-internal-run-time) start-rt)
|
|
|
|
|
|
internal-time-units-per-second))))
|
|
|
|
|
|
(display " msec (")
|
|
|
|
|
|
(display (inexact->exact
|
|
|
|
|
|
(* 1000 (/ (- (gc-run-time) start-gc-rt)
|
|
|
|
|
|
internal-time-units-per-second))))
|
|
|
|
|
|
(display " msec in gc)\n")))
|
1997-05-13 00:02:05 +00:00
|
|
|
|
|
|
|
|
|
|
(consume-trailing-whitespace
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let ((ch (peek-char)))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((eof-object? ch))
|
|
|
|
|
|
((or (char=? ch #\space) (char=? ch #\tab))
|
|
|
|
|
|
(read-char)
|
|
|
|
|
|
(consume-trailing-whitespace))
|
|
|
|
|
|
((char=? ch #\newline)
|
|
|
|
|
|
(read-char))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(-read (lambda ()
|
1997-10-27 07:07:03 +00:00
|
|
|
|
(if scm-repl-prompt
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display (cond ((string? scm-repl-prompt)
|
|
|
|
|
|
scm-repl-prompt)
|
|
|
|
|
|
((thunk? scm-repl-prompt)
|
|
|
|
|
|
(scm-repl-prompt))
|
|
|
|
|
|
(else "> ")))
|
|
|
|
|
|
(force-output)
|
|
|
|
|
|
(repl-report-reset)))
|
1997-03-01 01:34:23 +00:00
|
|
|
|
(run-hooks before-read-hook)
|
1997-10-27 07:07:03 +00:00
|
|
|
|
(let ((val (read (current-input-port))))
|
1997-05-13 00:02:05 +00:00
|
|
|
|
;; As described in R4RS, the READ procedure updates the
|
|
|
|
|
|
;; port to point to the first characetr past the end of
|
|
|
|
|
|
;; the external representation of the object. This
|
|
|
|
|
|
;; means that it doesn't consume the newline typically
|
|
|
|
|
|
;; found after an expression. This means that, when
|
|
|
|
|
|
;; debugging Guile with GDB, GDB gets the newline, which
|
|
|
|
|
|
;; it often interprets as a "continue" command, making
|
|
|
|
|
|
;; breakpoints kind of useless. So, consume any
|
|
|
|
|
|
;; trailing newline here, as well as any whitespace
|
|
|
|
|
|
;; before it.
|
|
|
|
|
|
(consume-trailing-whitespace)
|
1997-03-01 01:34:23 +00:00
|
|
|
|
(run-hooks after-read-hook)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (eof-object? val)
|
|
|
|
|
|
(begin
|
1997-03-02 19:53:32 +00:00
|
|
|
|
(repl-report-start-timing)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if scm-repl-verbose
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(display ";;; EOF -- quitting")
|
|
|
|
|
|
(newline)))
|
|
|
|
|
|
(quit 0)))
|
|
|
|
|
|
val)))
|
|
|
|
|
|
|
|
|
|
|
|
(-eval (lambda (sourc)
|
|
|
|
|
|
(repl-report-start-timing)
|
1996-10-14 20:28:39 +00:00
|
|
|
|
(start-stack 'repl-stack (eval sourc))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(-print (lambda (result)
|
|
|
|
|
|
(if (not scm-repl-silent)
|
|
|
|
|
|
(begin
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(if (or scm-repl-print-unspecified
|
|
|
|
|
|
(not (unspecified? result)))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(write result)
|
|
|
|
|
|
(newline)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if scm-repl-verbose
|
|
|
|
|
|
(repl-report))
|
|
|
|
|
|
(force-output)))))
|
|
|
|
|
|
|
1997-03-02 06:09:41 +00:00
|
|
|
|
(-quit (lambda (args)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if scm-repl-verbose
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display ";;; QUIT executed, repl exitting")
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(repl-report)))
|
1997-03-02 06:09:41 +00:00
|
|
|
|
args))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(-abort (lambda ()
|
|
|
|
|
|
(if scm-repl-verbose
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display ";;; ABORT executed.")
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(repl-report)))
|
|
|
|
|
|
(repl -read -eval -print))))
|
|
|
|
|
|
|
1997-03-02 06:09:41 +00:00
|
|
|
|
(let ((status (error-catching-repl -read
|
|
|
|
|
|
-eval
|
|
|
|
|
|
-print)))
|
|
|
|
|
|
(-quit status))))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {IOTA functions: generating lists of numbers}
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (reverse-iota n) (if (> n 0) (cons (1- n) (reverse-iota (1- n))) '()))
|
1997-09-15 21:43:41 +00:00
|
|
|
|
(define (iota n) (reverse! (reverse-iota n)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {While}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; with `continue' and `break'.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro while (cond . body)
|
|
|
|
|
|
`(letrec ((continue (lambda () (or (not ,cond) (begin (begin ,@ body) (continue)))))
|
|
|
|
|
|
(break (lambda val (apply throw 'break val))))
|
|
|
|
|
|
(catch 'break
|
|
|
|
|
|
(lambda () (continue))
|
|
|
|
|
|
(lambda v (cadr v)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-07-26 20:03:23 +00:00
|
|
|
|
;;; {with-fluids}
|
|
|
|
|
|
|
|
|
|
|
|
;; with-fluids is a convenience wrapper for the builtin procedure
|
|
|
|
|
|
;; `with-fluids*'. The syntax is just like `let':
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; (with-fluids ((fluid val)
|
|
|
|
|
|
;; ...)
|
|
|
|
|
|
;; body)
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro with-fluids (bindings . body)
|
|
|
|
|
|
`(with-fluids* (list ,@(map car bindings)) (list ,@(map cadr bindings))
|
|
|
|
|
|
(lambda () ,@body)))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Macros}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; actually....hobbit might be able to hack these with a little
|
|
|
|
|
|
;; coaxing
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro define-macro (first . rest)
|
|
|
|
|
|
(let ((name (if (symbol? first) first (car first)))
|
|
|
|
|
|
(transformer
|
|
|
|
|
|
(if (symbol? first)
|
|
|
|
|
|
(car rest)
|
|
|
|
|
|
`(lambda ,(cdr first) ,@rest))))
|
|
|
|
|
|
`(define ,name (defmacro:transformer ,transformer))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro define-syntax-macro (first . rest)
|
|
|
|
|
|
(let ((name (if (symbol? first) first (car first)))
|
|
|
|
|
|
(transformer
|
|
|
|
|
|
(if (symbol? first)
|
|
|
|
|
|
(car rest)
|
|
|
|
|
|
`(lambda ,(cdr first) ,@rest))))
|
|
|
|
|
|
`(define ,name (defmacro:syntax-transformer ,transformer))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Module System Macros}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro define-module args
|
|
|
|
|
|
`(let* ((process-define-module process-define-module)
|
|
|
|
|
|
(set-current-module set-current-module)
|
|
|
|
|
|
(module (process-define-module ',args)))
|
|
|
|
|
|
(set-current-module module)
|
|
|
|
|
|
module))
|
|
|
|
|
|
|
1997-04-29 18:22:54 +00:00
|
|
|
|
;; the guts of the use-modules macro. add the interfaces of the named
|
|
|
|
|
|
;; modules to the use-list of the current module, in order
|
|
|
|
|
|
(define (process-use-modules module-names)
|
|
|
|
|
|
(for-each (lambda (module-name)
|
|
|
|
|
|
(let ((mod-iface (resolve-interface module-name)))
|
|
|
|
|
|
(or mod-iface
|
|
|
|
|
|
(error "no such module" module-name))
|
|
|
|
|
|
(module-use! (current-module) mod-iface)))
|
|
|
|
|
|
(reverse module-names)))
|
|
|
|
|
|
|
1997-01-05 23:38:10 +00:00
|
|
|
|
(defmacro use-modules modules
|
1997-04-29 18:22:54 +00:00
|
|
|
|
`(process-use-modules ',modules))
|
1997-01-05 23:38:10 +00:00
|
|
|
|
|
1997-09-10 20:07:04 +00:00
|
|
|
|
(define (use-syntax transformer)
|
|
|
|
|
|
(set-module-transformer! (current-module) transformer)
|
|
|
|
|
|
(set! scm:eval-transformer transformer))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define define-private define)
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro define-public args
|
|
|
|
|
|
(define (syntax)
|
|
|
|
|
|
(error "bad syntax" (list 'define-public args)))
|
|
|
|
|
|
(define (defined-name n)
|
|
|
|
|
|
(cond
|
1997-07-11 05:13:59 +00:00
|
|
|
|
((symbol? n) n)
|
|
|
|
|
|
((pair? n) (defined-name (car n)))
|
|
|
|
|
|
(else (syntax))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(cond
|
1997-07-11 05:13:59 +00:00
|
|
|
|
((null? args) (syntax))
|
|
|
|
|
|
|
|
|
|
|
|
(#t (let ((name (defined-name (car args))))
|
|
|
|
|
|
`(begin
|
|
|
|
|
|
(let ((public-i (module-public-interface (current-module))))
|
|
|
|
|
|
;; Make sure there is a local variable:
|
|
|
|
|
|
;;
|
|
|
|
|
|
(module-define! (current-module)
|
|
|
|
|
|
',name
|
|
|
|
|
|
(module-ref (current-module) ',name #f))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-07-11 05:13:59 +00:00
|
|
|
|
;; Make sure that local is exported:
|
|
|
|
|
|
;;
|
|
|
|
|
|
(module-add! public-i ',name
|
|
|
|
|
|
(module-variable (current-module) ',name)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-07-11 05:13:59 +00:00
|
|
|
|
;; Now (re)define the var normally. Bernard URBAN
|
|
|
|
|
|
;; suggests we use eval here to accomodate Hobbit; it lets
|
|
|
|
|
|
;; the interpreter handle the define-private form, which
|
|
|
|
|
|
;; Hobbit can't digest.
|
|
|
|
|
|
(eval '(define-private ,@ args)))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro defmacro-public args
|
|
|
|
|
|
(define (syntax)
|
|
|
|
|
|
(error "bad syntax" (list 'defmacro-public args)))
|
|
|
|
|
|
(define (defined-name n)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((symbol? n) n)
|
|
|
|
|
|
(else (syntax))))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((null? args) (syntax))
|
|
|
|
|
|
|
|
|
|
|
|
(#t (let ((name (defined-name (car args))))
|
|
|
|
|
|
`(begin
|
|
|
|
|
|
(let ((public-i (module-public-interface (current-module))))
|
|
|
|
|
|
;; Make sure there is a local variable:
|
|
|
|
|
|
;;
|
|
|
|
|
|
(module-define! (current-module)
|
|
|
|
|
|
',name
|
|
|
|
|
|
(module-ref (current-module) ',name #f))
|
|
|
|
|
|
|
|
|
|
|
|
;; Make sure that local is exported:
|
|
|
|
|
|
;;
|
|
|
|
|
|
(module-add! public-i ',name (module-variable (current-module) ',name)))
|
|
|
|
|
|
|
|
|
|
|
|
;; Now (re)define the var normally.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(defmacro ,@ args))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define load load-module)
|
1996-10-17 23:43:23 +00:00
|
|
|
|
;(define (load . args)
|
|
|
|
|
|
; (start-stack 'load-stack (apply load-module args)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {I/O functions for Tcl channels (disabled)}
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; (define in-ch (get-standard-channel TCL_STDIN))
|
|
|
|
|
|
;; (define out-ch (get-standard-channel TCL_STDOUT))
|
|
|
|
|
|
;; (define err-ch (get-standard-channel TCL_STDERR))
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; (define inp (%make-channel-port in-ch "r"))
|
|
|
|
|
|
;; (define outp (%make-channel-port out-ch "w"))
|
|
|
|
|
|
;; (define errp (%make-channel-port err-ch "w"))
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; (define %system-char-ready? char-ready?)
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; (define (char-ready? p)
|
|
|
|
|
|
;; (if (not (channel-port? p))
|
|
|
|
|
|
;; (%system-char-ready? p)
|
|
|
|
|
|
;; (let* ((channel (%channel-port-channel p))
|
|
|
|
|
|
;; (old-blocking (channel-option-ref channel :blocking)))
|
|
|
|
|
|
;; (dynamic-wind
|
|
|
|
|
|
;; (lambda () (set-channel-option the-root-tcl-interpreter channel :blocking "0"))
|
|
|
|
|
|
;; (lambda () (not (eof-object? (peek-char p))))
|
|
|
|
|
|
;; (lambda () (set-channel-option the-root-tcl-interpreter channel :blocking old-blocking))))))
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; (define (top-repl)
|
|
|
|
|
|
;; (with-input-from-port inp
|
|
|
|
|
|
;; (lambda ()
|
|
|
|
|
|
;; (with-output-to-port outp
|
|
|
|
|
|
;; (lambda ()
|
|
|
|
|
|
;; (with-error-to-port errp
|
|
|
|
|
|
;; (lambda ()
|
|
|
|
|
|
;; (scm-style-repl))))))))
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; (set-current-input-port inp)
|
|
|
|
|
|
;; (set-current-output-port outp)
|
|
|
|
|
|
;; (set-current-error-port errp)
|
|
|
|
|
|
|
* scmsigs.h, async.h: updated.
* _scm.h: if HAVE_RESTARTS is defined then don't use a SYSCALL
loop.
* posix.c (scm_uname): interpret only negative values as an error.
Solaris normally returns a positive value.
* script.c (scm_compile_shell_switches): if we are not going into
an interactive repl, set scm_mask_ints to zero so that asyncs can
run.
* simpos.c (scm_system): don't ignore/unignore signals around
the "system" call.
* posix.c (scm_open_pipe): don't ignore/unignore signals around
the "popen" call.
* init.c (scm_boot_guile_1): don't call scm_init_signals, it's
done in boot-9.scm instead.
* scmsigs.c, async.c: Major rewriting of signal handling code.
(scm_sigaction): new procedure.
(scm_sleep): don't wrap sleep in SCM_SYSCALL, it would mess up the
timing.
(scm_raise): return unspecified, throw error on failure.
* boot-9.scm: signal-handler, alarm-thunk: removed.
don't define ticks-interrupt etc.
top-repl: install signal handlers for SIGINT, SIGFPE, SIGSEGV, SIGBUS
during call to scm-style-repl.
* acconfig.h: mention HAVE_RESTARTS.
* configure.in: check for sigaction and restartable system calls.
1997-05-31 19:02:38 +00:00
|
|
|
|
;; this is just (scm-style-repl) with a wrapper to install and remove
|
|
|
|
|
|
;; signal handlers.
|
1997-03-02 06:09:41 +00:00
|
|
|
|
(define (top-repl)
|
* scmsigs.h, async.h: updated.
* _scm.h: if HAVE_RESTARTS is defined then don't use a SYSCALL
loop.
* posix.c (scm_uname): interpret only negative values as an error.
Solaris normally returns a positive value.
* script.c (scm_compile_shell_switches): if we are not going into
an interactive repl, set scm_mask_ints to zero so that asyncs can
run.
* simpos.c (scm_system): don't ignore/unignore signals around
the "system" call.
* posix.c (scm_open_pipe): don't ignore/unignore signals around
the "popen" call.
* init.c (scm_boot_guile_1): don't call scm_init_signals, it's
done in boot-9.scm instead.
* scmsigs.c, async.c: Major rewriting of signal handling code.
(scm_sigaction): new procedure.
(scm_sleep): don't wrap sleep in SCM_SYSCALL, it would mess up the
timing.
(scm_raise): return unspecified, throw error on failure.
* boot-9.scm: signal-handler, alarm-thunk: removed.
don't define ticks-interrupt etc.
top-repl: install signal handlers for SIGINT, SIGFPE, SIGSEGV, SIGBUS
during call to scm-style-repl.
* acconfig.h: mention HAVE_RESTARTS.
* configure.in: check for sigaction and restartable system calls.
1997-05-31 19:02:38 +00:00
|
|
|
|
(let ((old-handlers #f)
|
|
|
|
|
|
(signals `((,SIGINT . "User interrupt")
|
|
|
|
|
|
(,SIGFPE . "Arithmetic error")
|
|
|
|
|
|
(,SIGBUS . "Bad memory access (bus error)")
|
|
|
|
|
|
(,SIGSEGV . "Bad memory access (Segmentation violation)"))))
|
|
|
|
|
|
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
|
|
|
|
|
|
|
;; call at entry
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let ((make-handler (lambda (msg)
|
|
|
|
|
|
(lambda (sig)
|
1997-08-14 18:24:46 +00:00
|
|
|
|
(save-stack %deliver-signals)
|
* scmsigs.h, async.h: updated.
* _scm.h: if HAVE_RESTARTS is defined then don't use a SYSCALL
loop.
* posix.c (scm_uname): interpret only negative values as an error.
Solaris normally returns a positive value.
* script.c (scm_compile_shell_switches): if we are not going into
an interactive repl, set scm_mask_ints to zero so that asyncs can
run.
* simpos.c (scm_system): don't ignore/unignore signals around
the "system" call.
* posix.c (scm_open_pipe): don't ignore/unignore signals around
the "popen" call.
* init.c (scm_boot_guile_1): don't call scm_init_signals, it's
done in boot-9.scm instead.
* scmsigs.c, async.c: Major rewriting of signal handling code.
(scm_sigaction): new procedure.
(scm_sleep): don't wrap sleep in SCM_SYSCALL, it would mess up the
timing.
(scm_raise): return unspecified, throw error on failure.
* boot-9.scm: signal-handler, alarm-thunk: removed.
don't define ticks-interrupt etc.
top-repl: install signal handlers for SIGINT, SIGFPE, SIGSEGV, SIGBUS
during call to scm-style-repl.
* acconfig.h: mention HAVE_RESTARTS.
* configure.in: check for sigaction and restartable system calls.
1997-05-31 19:02:38 +00:00
|
|
|
|
(scm-error 'signal
|
|
|
|
|
|
#f
|
|
|
|
|
|
msg
|
|
|
|
|
|
#f
|
|
|
|
|
|
(list sig))))))
|
|
|
|
|
|
(set! old-handlers
|
|
|
|
|
|
(map (lambda (sig-msg)
|
|
|
|
|
|
(sigaction (car sig-msg)
|
|
|
|
|
|
(make-handler (cdr sig-msg))))
|
|
|
|
|
|
signals))))
|
|
|
|
|
|
|
|
|
|
|
|
;; the protected thunk.
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(scm-style-repl))
|
|
|
|
|
|
|
|
|
|
|
|
;; call at exit.
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(map (lambda (sig-msg old-handler)
|
|
|
|
|
|
(if (not (car old-handler))
|
|
|
|
|
|
;; restore original C handler.
|
|
|
|
|
|
(sigaction (car sig-msg) #f)
|
|
|
|
|
|
;; restore Scheme handler, SIG_IGN or SIG_DFL.
|
|
|
|
|
|
(sigaction (car sig-msg)
|
|
|
|
|
|
(car old-handler)
|
|
|
|
|
|
(cdr old-handler))))
|
|
|
|
|
|
signals old-handlers)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-08-02 23:26:33 +00:00
|
|
|
|
(defmacro false-if-exception (expr)
|
|
|
|
|
|
`(catch #t (lambda () ,expr)
|
|
|
|
|
|
(lambda args #f)))
|
|
|
|
|
|
|
1996-08-23 04:54:23 +00:00
|
|
|
|
;;; {Load debug extension code if debug extensions present.}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; *fixme* This is a temporary solution.
|
|
|
|
|
|
;;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-08-23 04:54:23 +00:00
|
|
|
|
(if (memq 'debug-extensions *features*)
|
1996-10-05 17:47:59 +00:00
|
|
|
|
(define-module (guile) :use-module (ice-9 debug)))
|
|
|
|
|
|
|
1997-03-08 15:14:00 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Load session support if present.}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; *fixme* This is a temporary solution.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(if (%search-load-path "ice-9/session.scm")
|
|
|
|
|
|
(define-module (guile) :use-module (ice-9 session)))
|
|
|
|
|
|
|
1996-10-05 17:47:59 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Load thread code if threads are present.}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; *fixme* This is a temporary solution.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(if (memq 'threads *features*)
|
|
|
|
|
|
(define-module (guile) :use-module (ice-9 threads)))
|
|
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Load emacs interface support if emacs option is given.}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; *fixme* This is a temporary solution.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
1997-03-23 13:04:49 +00:00
|
|
|
|
(if (and (module-defined? the-root-module 'use-emacs-interface)
|
|
|
|
|
|
use-emacs-interface)
|
1997-07-23 18:15:37 +00:00
|
|
|
|
(begin
|
|
|
|
|
|
(if (memq 'debug-extensions *features*)
|
|
|
|
|
|
(debug-enable 'backtrace))
|
|
|
|
|
|
(define-module (guile) :use-module (ice-9 emacs))))
|
1996-11-02 20:51:30 +00:00
|
|
|
|
|
1997-05-29 02:47:14 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Load regexp code if regexp primitives are available.}
|
|
|
|
|
|
|
|
|
|
|
|
(if (memq 'regex *features*)
|
|
|
|
|
|
(define-module (guile) :use-module (ice-9 regex)))
|
|
|
|
|
|
|
1997-06-22 23:46:41 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Check that the interpreter and scheme code match up.}
|
|
|
|
|
|
|
|
|
|
|
|
(let ((show-line
|
|
|
|
|
|
(lambda args
|
|
|
|
|
|
(with-output-to-port (current-error-port)
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(display (car (command-line)))
|
|
|
|
|
|
(display ": ")
|
|
|
|
|
|
(for-each (lambda (string) (display string))
|
|
|
|
|
|
args)
|
|
|
|
|
|
(newline))))))
|
|
|
|
|
|
|
|
|
|
|
|
(load-from-path "ice-9/version.scm")
|
|
|
|
|
|
|
|
|
|
|
|
(if (not (string=?
|
|
|
|
|
|
(libguile-config-stamp) ; from the interprpreter
|
|
|
|
|
|
(ice-9-config-stamp))) ; from the Scheme code
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(show-line "warning: different versions of libguile and ice-9:")
|
|
|
|
|
|
(show-line "libguile: configured on " (libguile-config-stamp))
|
|
|
|
|
|
(show-line "ice-9: configured on " (ice-9-config-stamp)))))
|
|
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-10-05 17:47:59 +00:00
|
|
|
|
(define-module (guile))
|
1996-10-06 06:33:11 +00:00
|
|
|
|
|
|
|
|
|
|
(append! %load-path (cons "." ()))
|