;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;;;; Boston, MA 02111-1307 USA
;;;;
+;;;; As a special exception, the Free Software Foundation gives permission
+;;;; for additional uses of the text contained in its release of GUILE.
+;;;;
+;;;; The exception is that, if you link the GUILE library with other files
+;;;; to produce an executable, this does not by itself cause the
+;;;; resulting executable to be covered by the GNU General Public License.
+;;;; Your use of that executable is in no way restricted on account of
+;;;; linking the GUILE library code into it.
+;;;;
+;;;; This exception does not however invalidate any other reasons why
+;;;; the executable file might be covered by the GNU General Public License.
+;;;;
+;;;; This exception applies only to the code released by the
+;;;; Free Software Foundation under the name GUILE. If you copy
+;;;; code from other Free Software Foundation releases into a copy of
+;;;; GUILE, as the General Public License permits, the exception does
+;;;; not apply to the code that you add in this way. To avoid misleading
+;;;; anyone as to the status of such modified files, you must delete
+;;;; this exception notice from them.
+;;;;
+;;;; If you write modifications of your own for GUILE, it is your choice
+;;;; whether to permit this exception to apply to your modifications.
+;;;; If you do not wish that, delete this exception notice.
+;;;;
\f
;;; Commentary:
(define (provided? feature)
(and (memq feature *features*) #t))
-;;; presumably deprecated.
-(define feature? provided?)
+(begin-deprecated
+ (define feature? provided?))
;;; let format alias simple-format until the more complete version is loaded
(define format simple-format)
(define (and=> value procedure) (and value (procedure value)))
(define (make-hash-table k) (make-vector k '()))
-(begin-deprecated
- (define (id x)
- (issue-deprecation-warning "`id' is deprecated. Use `identity' instead.")
- (identity x))
- (define (-1+ n)
- (issue-deprecation-warning "`-1+' is deprecated. Use `1-' instead.")
- (1- n))
- (define (return-it . args)
- (issue-deprecation-warning "`return-it' is deprecated. Use `noop' instead.")
- (apply noop args)))
-
;;; apply-to-args is functionally redundant with apply and, worse,
;;; is less general than apply since it only takes two arguments.
;;;
(if (even? k) acc (proc acc x))
proc))))
-(begin-deprecated
- (define (string-character-length s)
- (issue-deprecation-warning "`string-character-length' is deprecated. Use `string-length' instead.")
- (string-length s))
- (define (flags . args)
- (issue-deprecation-warning "`flags' is deprecated. Use `logior' instead.")
- (apply logior args)))
-
\f
;;; {Symbol Properties}
;;;
(and (> sl sufl)
(string=? (substring str (- sl sufl) sl) suffix))))
+(define (system-error-errno args)
+ (if (eq? (car args) 'system-error)
+ (car (list-ref args 4))
+ #f))
+
\f
;;; {Error Handling}
;;;
(define (tms:cutime obj) (vector-ref obj 3))
(define (tms:cstime obj) (vector-ref obj 4))
-(define (file-position . args) (apply ftell args))
-(define (file-set-position . args) (apply fseek args))
+(define file-position ftell)
+(define (file-set-position port offset . whence)
+ (let ((whence (if (eq? whence '()) SEEK_SET (car whence))))
+ (seek port offset whence)))
(define (move->fdes fd/port fd)
(cond ((integer? fd/port)
(putenv (string-append name "=" value))
(putenv name)))
+(define (unsetenv name)
+ "Remove the entry for NAME from the environment."
+ (putenv name))
+
\f
;;; {Load Paths}
;;;
;; This is mostly for the internal use of the code generated by
;; scm_compile_shell_switches.
+
+(define (turn-on-debugging)
+ (debug-enable 'debug)
+ (debug-enable 'backtrace)
+ (read-enable 'positions))
+
(define (load-user-init)
(let* ((home (or (getenv "HOME")
(false-if-exception (passwd:dir (getpwuid (getuid))))
(read-hash-extend #\' (lambda (c port)
(read port)))
-(read-hash-extend #\. (lambda (c port)
- (eval (read port) (interaction-environment))))
+
+(define read-eval? (make-fluid))
+(fluid-set! read-eval? #f)
+(read-hash-extend #\.
+ (lambda (c port)
+ (if (fluid-ref read-eval?)
+ (eval (read port) (interaction-environment))
+ (error
+ "#. read expansion found and read-eval? is #f."))))
\f
;;; {Command Line Options}
;; to maximally one module.
(set-procedure-property! closure 'module module))))
-(begin-deprecated
- (define (eval-in-module exp mod)
- (issue-deprecation-warning
- "`eval-in-module' is deprecated. Use `eval' instead.")
- (eval exp mod)))
-
\f
;;; {Observer protocol}
;;;
((module-binder m) m v #t))
(begin
(let ((answer (make-undefined-variable)))
- (variable-set-name-hint! answer v)
(module-obarray-set! (module-obarray m) v answer)
(module-modified m)
answer))))
+;; module-ensure-local-variable! module symbol
+;;
+;; Ensure that there is a local variable in MODULE for SYMBOL. If
+;; there is no binding for SYMBOL, create a new uninitialized
+;; variable. Return the local variable.
+;;
+(define (module-ensure-local-variable! module symbol)
+ (or (module-local-variable module symbol)
+ (let ((var (make-undefined-variable)))
+ (module-add! module symbol var)
+ var)))
+
;; module-add! module symbol var
;;
;; ensure a particular variable for V in the local namespace of M.
(variable-set! variable value)
(module-modified module))
(let ((variable (make-variable value)))
- (variable-set-name-hint! variable name)
(module-add! module name variable)))))
;; MODULE-DEFINED? -- exported
;; Get/create it.
(make-modules-in (current-module) full-name))))))
-;; Cheat.
+;; Cheat. These bindings are needed by modules.c, but we don't want
+;; to move their real definition here because that would be unnatural.
+;;
(define try-module-autoload #f)
+(define process-define-module #f)
+(define process-use-modules #f)
+(define module-export! #f)
;; This boots the module system. All bindings needed by modules.c
;; must have been defined by now.
;; (define-special-value '(app modules new-ws) (lambda () (make-scm-module)))
(define (try-load-module name)
- (or (try-module-linked name)
- (try-module-autoload name)
- (try-module-dynamic-link name)))
+ (try-module-autoload name))
(define (purify-module! module)
"Removes bindings in MODULE which are inherited from the (guile) module."
(eq? (car (last-pair use-list)) the-scm-module))
(set-module-uses! module (reverse (cdr (reverse use-list)))))))
-;; Return a module interface made from SPEC.
-;; SPEC can be a list of symbols, in which case it names a module
-;; whose public interface is found and returned.
-;;
-;; SPEC can also be of the form:
-;; (MODULE-NAME [:select SELECTION] [:rename RENAMER])
-;; in which case a partial interface is newly created and returned.
-;; MODULE-NAME is a list of symbols, as above; SELECTION is a list of
-;; binding-specs to be imported; and RENAMER is a procedure that takes a
-;; symbol and returns its new name. A binding-spec is either a symbol or a
-;; pair of symbols (ORIG . SEEN), where ORIG is the name in the used module
-;; and SEEN is the name in the using module. Note that SEEN is also passed
-;; through RENAMER.
-;;
-;; The `:select' and `:rename' clauses are optional. If both are omitted, the
-;; returned interface has no bindings. If the `:select' clause is omitted,
-;; RENAMER operates on the used module's public interface.
-;;
-;; Signal "no code for module" error if module name is not resolvable or its
-;; public interface is not available. Signal "no binding" error if selected
-;; binding does not exist in the used module.
-;;
-(define (resolve-interface spec)
- (let* ((simple? (not (pair? (car spec))))
- (name (if simple? spec (car spec)))
+;; Return a module that is an interface to the module designated by
+;; NAME.
+;;
+;; `resolve-interface' takes two keyword arguments:
+;;
+;; #:select SELECTION
+;;
+;; SELECTION is a list of binding-specs to be imported; A binding-spec
+;; is either a symbol or a pair of symbols (ORIG . SEEN), where ORIG
+;; is the name in the used module and SEEN is the name in the using
+;; module. Note that SEEN is also passed through RENAMER, below. The
+;; default is to select all bindings. If you specify no selection but
+;; a renamer, only the bindings that already exist in the used module
+;; are made available in the interface. Bindings that are added later
+;; are not picked up.
+;;
+;; #:renamer RENAMER
+;;
+;; RENAMER is a procedure that takes a symbol and returns its new
+;; name. The default is to not perform any renaming.
+;;
+;; Signal "no code for module" error if module name is not resolvable
+;; or its public interface is not available. Signal "no binding"
+;; error if selected binding does not exist in the used module.
+;;
+(define (resolve-interface name . args)
+
+ (define (get-keyword-arg args kw def)
+ (cond ((memq kw args)
+ => (lambda (kw-arg)
+ (if (null? (cdr kw-arg))
+ (error "keyword without value: " kw))
+ (cadr kw-arg)))
+ (else
+ def)))
+
+ (let* ((select (get-keyword-arg args #:select #f))
+ (renamer (get-keyword-arg args #:renamer identity))
(module (resolve-module name))
(public-i (and module (module-public-interface module))))
(and (or (not module) (not public-i))
(error "no code for module" name))
- (if simple?
+ (if (and (not select) (eq? renamer identity))
public-i
- (let ((selection (cond ((memq ':select spec) => cadr)
- (else (module-map (lambda (sym var) sym)
- public-i))))
- (rename (cond ((memq ':rename spec)
- => (lambda (x)
- ;; fixme:ttn -- move to macroexpansion time
- (eval (cadr x) (current-module))))
- (else identity)))
+ (let ((selection (or select (module-map (lambda (sym var) sym)
+ public-i)))
(custom-i (make-module 31)))
(set-module-kind! custom-i 'interface)
+ ;; XXX - should use a lazy binder so that changes to the
+ ;; used module are picked up automatically.
(for-each (lambda (bspec)
(let* ((direct? (symbol? bspec))
(orig (if direct? bspec (car bspec)))
(seen (if direct? bspec (cdr bspec))))
- (module-add! custom-i (rename seen)
- (or (module-local-variable module orig)
+ (module-add! custom-i (renamer seen)
+ (or (module-local-variable public-i orig)
+ (module-local-variable module orig)
(error
;; fixme: format manually for now
(simple-format
(lambda (symbol)
(symbol-append prefix symbol)))
+;; This function is called from "modules.c". If you change it, be
+;; sure to update "modules.c" as well.
+
(define (process-define-module args)
(let* ((module-id (car args))
(module (resolve-module module-id #f))
(beautify-user-module! module)
(let loop ((kws kws)
(reversed-interfaces '())
- (exports '()))
+ (exports '())
+ (re-exports '()))
(if (null? kws)
(begin
(for-each (lambda (interface)
(module-use! module interface))
(reverse reversed-interfaces))
- (module-export! module exports))
- (let ((keyword (if (keyword? (car kws))
- (keyword->symbol (car kws))
- (and (symbol? (car kws))
- (let ((s (symbol->string (car kws))))
- (and (eq? (string-ref s 0) #\:)
- (string->symbol (substring s 1))))))))
- (case keyword
- ((use-module use-syntax)
- (or (pair? (cdr kws))
- (unrecognized kws))
- (let* ((spec (cadr kws))
- (interface (resolve-interface spec)))
- (and (eq? keyword 'use-syntax)
- (or (symbol? (car spec))
- (error "invalid module name for use-syntax"
- spec))
- (set-module-transformer!
- module
- (module-ref interface (car (last-pair module-name))
- #f)))
- (loop (cddr kws)
- (cons interface reversed-interfaces)
- exports)))
- ((autoload)
- (or (and (pair? (cdr kws)) (pair? (cddr kws)))
- (unrecognized kws))
- (loop (cdddr kws)
- (cons (make-autoload-interface module
- (cadr kws)
- (caddr kws))
- reversed-interfaces)
- exports))
- ((no-backtrace)
- (set-system-module! module #t)
- (loop (cdr kws) reversed-interfaces exports))
- ((pure)
- (purify-module! module)
- (loop (cdr kws) reversed-interfaces exports))
- ((export)
- (or (pair? (cdr kws))
- (unrecognized kws))
+ (module-export! module exports)
+ (module-re-export! module re-exports))
+ (case (car kws)
+ ((#:use-module #:use-syntax)
+ (or (pair? (cdr kws))
+ (unrecognized kws))
+ (let* ((interface-args (cadr kws))
+ (interface (apply resolve-interface interface-args)))
+ (and (eq? (car kws) #:use-syntax)
+ (or (symbol? (caar interface-args))
+ (error "invalid module name for use-syntax"
+ (car interface-args)))
+ (set-module-transformer!
+ module
+ (module-ref interface
+ (car (last-pair (car interface-args)))
+ #f)))
(loop (cddr kws)
- reversed-interfaces
- (append (cadr kws) exports)))
- (else
- (unrecognized kws))))))
- (set-current-module module)
+ (cons interface reversed-interfaces)
+ exports
+ re-exports)))
+ ((#:autoload)
+ (or (and (pair? (cdr kws)) (pair? (cddr kws)))
+ (unrecognized kws))
+ (loop (cdddr kws)
+ (cons (make-autoload-interface module
+ (cadr kws)
+ (caddr kws))
+ reversed-interfaces)
+ exports
+ re-exports))
+ ((#:no-backtrace)
+ (set-system-module! module #t)
+ (loop (cdr kws) reversed-interfaces exports re-exports))
+ ((#:pure)
+ (purify-module! module)
+ (loop (cdr kws) reversed-interfaces exports re-exports))
+ ((#:export #:export-syntax)
+ (or (pair? (cdr kws))
+ (unrecognized kws))
+ (loop (cddr kws)
+ reversed-interfaces
+ (append (cadr kws) exports)
+ re-exports))
+ ((#:re-export #:re-export-syntax)
+ (or (pair? (cdr kws))
+ (unrecognized kws))
+ (loop (cddr kws)
+ reversed-interfaces
+ exports
+ (append (cadr kws) re-exports)))
+ (else
+ (unrecognized kws)))))
module))
;;; {Autoload}
(define autoloads-in-progress '())
+;; This function is called from "modules.c". If you change it, be
+;; sure to update "modules.c" as well.
+
(define (try-module-autoload module-name)
(let* ((reverse-name (reverse module-name))
(name (symbol->string (car reverse-name)))
\f
;;; Dynamic linking of modules
-;; This method of dynamically linking Guile Extensions is deprecated.
-;; Use `dynamic-link' and `dynamic-call' explicitely from Scheme code
-;; instead.
-
-;; XXX - We can not offer the removal of this code thru the
-;; deprecation mechanism since we have no complete replacement yet.
-
-(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 '())
-
-(define (register-modules dynobj)
- (set! registered-modules
- (append! (convert-c-registered-modules dynobj)
- registered-modules)))
-
-(define (warn-autoload-deprecation modname)
- ;; Do nothing here until we can deprecate the code for real.
- (if #f
- (issue-deprecation-warning
- "Autoloading of compiled code modules is deprecated."
- "Write a Scheme file instead that uses `dynamic-link' directly.")))
-
-(define (init-dynamic-module modname)
- ;; Register any linked modules which have been registered on the C level
- (register-modules #f)
- (or-map (lambda (modinfo)
- (if (equal? (car modinfo) modname)
- (begin
- (warn-autoload-deprecation modname)
- (set! registered-modules (delq! modinfo registered-modules))
- (let ((mod (resolve-module modname #f)))
- (save-module-excursion
- (lambda ()
- (set-current-module mod)
- (set-module-public-interface! mod mod)
- (dynamic-call (cadr modinfo) (caddr modinfo))
- ))
- #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)))
-
-(define (dynamic-maybe-link filename)
- (catch #t ; could use false-if-exception here
- (lambda ()
- (dynamic-link filename))
- (lambda args
- #f)))
-
-(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"))
-
- ;; 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
- (let loop ((dirs "")
- (syms module-name))
- (if (null? (cdr syms))
- (cons dirs (string-append "lib" (symbol->string (car syms))))
- (loop (string-append dirs (symbol->string (car syms)) "/")
- (cdr syms)))))
- (init (make-init-name (apply string-append
- (map (lambda (s)
- (string-append "_"
- (symbol->string s)))
- module-name)))))
- (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)
- (let ((libtool-filename (in-vicinity libdir
- (string-append libname ".la"))))
- (and (file-exists? libtool-filename)
- libtool-filename)))
-
-(define (try-using-sharlib-name libdir libname)
- (in-vicinity libdir (string-append libname ".so")))
-
-(define (link-dynamic-module filename initname)
- ;; Register any linked modules which has been registered on the C level
- (register-modules #f)
- (let ((dynobj (dynamic-link filename)))
- (dynamic-call initname dynobj)
- (register-modules dynobj)))
-
-(define (try-module-linked module-name)
- (init-dynamic-module module-name))
-
-(define (try-module-dynamic-link module-name)
- (and (find-and-link-dynamic-module module-name)
- (init-dynamic-module module-name)))
-
-
-
(define autoloads-done '((guile . guile)))
(define (autoload-done-or-in-progress? p m)
(save-stack lazy-handler-dispatch)
(apply throw key args))
-(define enter-frame-handler default-lazy-handler)
-(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))
- ((enter-frame)
- (apply enter-frame-handler key args))
- (else
- (apply default-lazy-handler key args))))
+ (apply default-lazy-handler key args))
(define abort-hook (make-hook))
;;; {Module System Macros}
;;;
+;; Return a list of expressions that evaluate to the appropriate
+;; arguments for resolve-interface according to SPEC.
+
+(define (compile-interface-spec spec)
+ (define (make-keyarg sym key quote?)
+ (cond ((or (memq sym spec)
+ (memq key spec))
+ => (lambda (rest)
+ (if quote?
+ (list key (list 'quote (cadr rest)))
+ (list key (cadr rest)))))
+ (else
+ '())))
+ (define (map-apply func list)
+ (map (lambda (args) (apply func args)) list))
+ (define keys
+ ;; sym key quote?
+ '((:select #:select #t)
+ (:renamer #:renamer #f)))
+ (if (not (pair? (car spec)))
+ `(',spec)
+ `(',(car spec)
+ ,@(apply append (map-apply make-keyarg keys)))))
+
+(define (keyword-like-symbol->keyword sym)
+ (symbol->keyword (string->symbol (substring (symbol->string sym) 1))))
+
+(define (compile-define-module-args args)
+ ;; Just quote everything except #:use-module and #:use-syntax. We
+ ;; need to know about all arguments regardless since we want to turn
+ ;; symbols that look like keywords into real keywords, and the
+ ;; keyword args in a define-module form are not regular
+ ;; (i.e. no-backtrace doesn't take a value).
+ (let loop ((compiled-args `((quote ,(car args))))
+ (args (cdr args)))
+ (cond ((null? args)
+ (reverse! compiled-args))
+ ;; symbol in keyword position
+ ((symbol? (car args))
+ (loop compiled-args
+ (cons (keyword-like-symbol->keyword (car args)) (cdr args))))
+ ((memq (car args) '(#:no-backtrace #:pure))
+ (loop (cons (car args) compiled-args)
+ (cdr args)))
+ ((null? (cdr args))
+ (error "keyword without value:" (car args)))
+ ((memq (car args) '(#:use-module #:use-syntax))
+ (loop (cons* `(list ,@(compile-interface-spec (cadr args)))
+ (car args)
+ compiled-args)
+ (cddr args)))
+ ((eq? (car args) #:autoload)
+ (loop (cons* `(quote ,(caddr args))
+ `(quote ,(cadr args))
+ (car args)
+ compiled-args)
+ (cdddr args)))
+ (else
+ (loop (cons* `(quote ,(cadr args))
+ (car args)
+ compiled-args)
+ (cddr args))))))
+
(defmacro define-module args
`(eval-case
((load-toplevel)
- (process-define-module ',args))
+ (let ((m (process-define-module
+ (list ,@(compile-define-module-args args)))))
+ (set-current-module m)
+ m))
(else
(error "define-module can only be used at the top level"))))
-;; 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-interface-specs)
- (for-each (lambda (mif-spec)
- (let ((mod-iface (resolve-interface mif-spec)))
+;; The guts of the use-modules macro. Add the interfaces of the named
+;; modules to the use-list of the current module, in order.
+
+;; This function is called by "modules.c". If you change it, be sure
+;; to change scm_c_use_module as well.
+
+(define (process-use-modules module-interface-args)
+ (for-each (lambda (mif-args)
+ (let ((mod-iface (apply resolve-interface mif-args)))
(or mod-iface
- (error "no such module" mif-spec))
+ (error "no such module" mif-args))
(module-use! (current-module) mod-iface)))
- module-interface-specs))
+ module-interface-args))
(defmacro use-modules modules
`(eval-case
((load-toplevel)
- (process-use-modules ',modules))
+ (process-use-modules
+ (list ,@(map (lambda (m)
+ `(list ,@(compile-interface-spec m)))
+ modules))))
(else
(error "use-modules can only be used at the top level"))))
`(eval-case
((load-toplevel)
,@(if (pair? spec)
- `((process-use-modules ',(list spec))
+ `((process-use-modules (list
+ (list ,@(compile-interface-spec spec))))
(set-module-transformer! (current-module)
,(car (last-pair spec))))
- `((set-module-transformer! (current-module) ,spec)))
- (fluid-set! scm:eval-transformer (module-transformer (current-module))))
+ `((set-module-transformer! (current-module) ,spec))))
(else
(error "use-syntax can only be used at the top level"))))
(#t
(let ((name (defined-name (car args))))
`(begin
- (eval-case ((load-toplevel) (export ,name)))
- (define-private ,@args))))))
+ (define-private ,@args)
+ (eval-case ((load-toplevel) (export ,name))))))))
(defmacro defmacro-public args
(define (syntax)
(eval-case ((load-toplevel) (export ,name)))
(defmacro ,@args))))))
+;; Export a local variable
+
+;; This function is called from "modules.c". If you change it, be
+;; sure to update "modules.c" as well.
+
(define (module-export! m names)
(let ((public-i (module-public-interface m)))
(for-each (lambda (name)
- ;; Make sure there is a local variable:
- (module-define! m name (module-ref m name #f))
- ;; Make sure that local is exported:
- (module-add! public-i name (module-variable m name)))
+ (let ((var (module-ensure-local-variable! m name)))
+ (module-add! public-i name var)))
+ names)))
+
+;; Re-export a imported variable
+;;
+(define (module-re-export! m names)
+ (let ((public-i (module-public-interface m)))
+ (for-each (lambda (name)
+ (let ((var (module-variable m name)))
+ (cond ((not var)
+ (error "Undefined variable:" name))
+ ((eq? var (module-local-variable m name))
+ (error "re-exporting local variable:" name))
+ (else
+ (module-add! public-i name var)))))
names)))
(defmacro export names
(else
(error "export can only be used at the top level"))))
+(defmacro re-export names
+ `(eval-case
+ ((load-toplevel)
+ (module-re-export! (current-module) ',names))
+ (else
+ (error "re-export can only be used at the top level"))))
+
(define export-syntax export)
+(define re-export-syntax re-export)
(define load load-module)
;;;
;;; Remember to update the features list when adding more SRFIs.
-(define cond-expand-features
+(define %cond-expand-features
;; Adjust the above comment when changing this.
'(guile r5rs srfi-0))
-(define-macro (cond-expand clause . clauses)
-
- (let ((clauses (cons clause clauses))
- (syntax-error (lambda (cl)
- (error "invalid clause in `cond-expand'" cl))))
- (letrec
- ((test-clause
- (lambda (clause)
- (cond
- ((symbol? clause)
- (memq clause cond-expand-features))
- ((pair? clause)
+;; This table maps module public interfaces to the list of features.
+;;
+(define %cond-expand-table (make-hash-table 31))
+
+;; Add one or more features to the `cond-expand' feature list of the
+;; module `module'.
+;;
+(define (cond-expand-provide module features)
+ (let ((mod (module-public-interface module)))
+ (and mod
+ (hashq-set! %cond-expand-table mod
+ (append (hashq-ref %cond-expand-table mod '())
+ features)))))
+
+(define cond-expand
+ (procedure->memoizing-macro
+ (lambda (exp env)
+ (let ((clauses (cdr exp))
+ (syntax-error (lambda (cl)
+ (error "invalid clause in `cond-expand'" cl))))
+ (letrec
+ ((test-clause
+ (lambda (clause)
(cond
- ((eq? 'and (car clause))
- (let lp ((l (cdr clause)))
- (cond ((null? l)
- #t)
- ((pair? l)
- (and (test-clause (car l)) (lp (cdr l))))
- (else
- (syntax-error clause)))))
- ((eq? 'or (car clause))
- (let lp ((l (cdr clause)))
- (cond ((null? l)
- #f)
- ((pair? l)
- (or (test-clause (car l)) (lp (cdr l))))
- (else
- (syntax-error clause)))))
- ((eq? 'not (car clause))
- (cond ((not (pair? (cdr clause)))
- (syntax-error clause))
- ((pair? (cddr clause))
- ((syntax-error clause))))
- (not (test-clause (cadr clause))))
- (else
- (syntax-error clause))))
- (else
- (syntax-error clause))))))
- (let lp ((c clauses))
- (cond
- ((null? c)
- (error "Unfulfilled `cond-expand'"))
- ((not (pair? c))
- (syntax-error c))
- ((not (pair? (car c)))
- (syntax-error (car c)))
- ((test-clause (caar c))
- `(begin ,@(cdar c)))
- ((eq? (caar c) 'else)
- (if (pair? (cdr c))
+ ((symbol? clause)
+ (or (memq clause %cond-expand-features)
+ (let lp ((uses (module-uses (env-module env))))
+ (if (pair? uses)
+ (or (memq clause
+ (hashq-ref %cond-expand-table
+ (car uses) '()))
+ (lp (cdr uses)))
+ #f))))
+ ((pair? clause)
+ (cond
+ ((eq? 'and (car clause))
+ (let lp ((l (cdr clause)))
+ (cond ((null? l)
+ #t)
+ ((pair? l)
+ (and (test-clause (car l)) (lp (cdr l))))
+ (else
+ (syntax-error clause)))))
+ ((eq? 'or (car clause))
+ (let lp ((l (cdr clause)))
+ (cond ((null? l)
+ #f)
+ ((pair? l)
+ (or (test-clause (car l)) (lp (cdr l))))
+ (else
+ (syntax-error clause)))))
+ ((eq? 'not (car clause))
+ (cond ((not (pair? (cdr clause)))
+ (syntax-error clause))
+ ((pair? (cddr clause))
+ ((syntax-error clause))))
+ (not (test-clause (cadr clause))))
+ (else
+ (syntax-error clause))))
+ (else
+ (syntax-error clause))))))
+ (let lp ((c clauses))
+ (cond
+ ((null? c)
+ (error "Unfulfilled `cond-expand'"))
+ ((not (pair? c))
(syntax-error c))
- `(begin ,@(cdar c)))
- (else
- (lp (cdr c))))))))
+ ((not (pair? (car c)))
+ (syntax-error (car c)))
+ ((test-clause (caar c))
+ `(begin ,@(cdar c)))
+ ((eq? (caar c) 'else)
+ (if (pair? (cdr c))
+ (syntax-error c))
+ `(begin ,@(cdar c)))
+ (else
+ (lp (cdr c))))))))))
;; This procedure gets called from the startup code with a list of
;; numbers, which are the numbers of the SRFIs to be loaded on startup.
(string-append "srfi-" (number->string (car s)))))
(mod-i (resolve-interface (list 'srfi srfi))))
(module-use! (current-module) mod-i)
- (set! cond-expand-features
- (append cond-expand-features (list srfi)))
(lp (cdr s))))))
\f
;;; {Load emacs interface support if emacs option is given.}
(define (named-module-use! user usee)
- (module-use! (resolve-module user) (resolve-module usee)))
+ (module-use! (resolve-module user) (resolve-interface usee)))
(define (load-emacs-interface)
(and (provided? 'debug-extensions)
(lambda (v) (fluid-set! using-readline? v)))))
(define (top-repl)
-
- ;; Load emacs interface support if emacs option is given.
- (if (and (module-defined? the-root-module 'use-emacs-interface)
- (module-ref the-root-module 'use-emacs-interface))
- (load-emacs-interface))
-
- ;; Place the user in the guile-user module.
- (process-define-module
- '((guile-user)
- :use-module (guile) ;so that bindings will be checked here first
- :use-module (ice-9 session)
- :use-module (ice-9 debug)
- :autoload (ice-9 debugger) (debug))) ;load debugger on demand
- (and (provided? 'threads)
- (named-module-use! '(guile-user) '(ice-9 threads)))
- (and (provided? 'regex)
- (named-module-use! '(guile-user) '(ice-9 regex)))
-
- (let ((old-handlers #f)
- (signals (if (provided? 'posix)
- `((,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)
- ;; Make a backup copy of the stack
- (fluid-set! before-signal-stack
- (fluid-ref the-last-stack))
- (save-stack %deliver-signals)
- (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 ()
- (let ((status (scm-style-repl)))
- (run-hook exit-hook)
- status))
-
- ;; 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)))))
+ (let ((guile-user-module (resolve-module '(guile-user))))
+
+ ;; Load emacs interface support if emacs option is given.
+ (if (and (module-defined? the-root-module 'use-emacs-interface)
+ (module-ref the-root-module 'use-emacs-interface))
+ (load-emacs-interface))
+
+ ;; Use some convenient modules (in reverse order)
+
+ (if (provided? 'regex)
+ (module-use! guile-user-module (resolve-interface '(ice-9 regex))))
+ (if (provided? 'threads)
+ (module-use! guile-user-module (resolve-interface '(ice-9 threads))))
+ ;; load debugger on demand
+ (module-use! guile-user-module
+ (make-autoload-interface guile-user-module
+ '(ice-9 debugger) '(debug)))
+ (module-use! guile-user-module (resolve-interface '(ice-9 session)))
+ (module-use! guile-user-module (resolve-interface '(ice-9 debug)))
+ ;; so that builtin bindings will be checked first
+ (module-use! guile-user-module (resolve-interface '(guile)))
+
+ (set-current-module guile-user-module)
+
+ (let ((old-handlers #f)
+ (signals (if (provided? 'posix)
+ `((,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)
+ ;; Make a backup copy of the stack
+ (fluid-set! before-signal-stack
+ (fluid-ref the-last-stack))
+ (save-stack %deliver-signals)
+ (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 ()
+ (let ((status (scm-style-repl)))
+ (run-hook exit-hook)
+ status))
+
+ ;; 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))))))
(defmacro false-if-exception (expr)
`(catch #t (lambda () ,expr)
(define exit-hook (make-hook))
\f
-(define-module (guile))
+(append! %load-path (list "."))
+
+;; Place the user in the guile-user module.
+;;
-(append! %load-path (cons "." '()))
+(define-module (guile-user))
;;; boot-9.scm ends here