1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00

Merged from mvo-vcell-cleanup-1-branch.

This commit is contained in:
Marius Vollmer 2001-05-15 14:59:42 +00:00
parent 86d31dfe7d
commit 296ff5e78b
7 changed files with 90 additions and 121 deletions

View file

@ -397,7 +397,7 @@ SCM scm_readline_completion_function_var;
static char * static char *
completion_function (char *text, int continuep) completion_function (char *text, int continuep)
{ {
SCM compfunc = SCM_CDR (scm_readline_completion_function_var); SCM compfunc = SCM_VARIABLE_REF (scm_readline_completion_function_var);
SCM res; SCM res;
if (SCM_FALSEP (compfunc)) if (SCM_FALSEP (compfunc))
@ -542,7 +542,7 @@ scm_init_readline ()
#ifdef HAVE_RL_GETC_FUNCTION #ifdef HAVE_RL_GETC_FUNCTION
#include "guile-readline/readline.x" #include "guile-readline/readline.x"
scm_readline_completion_function_var scm_readline_completion_function_var
= scm_sysintern ("*readline-completion-function*", SCM_BOOL_F); = scm_c_define ("*readline-completion-function*", SCM_BOOL_F);
rl_getc_function = current_input_getc; rl_getc_function = current_input_getc;
rl_redisplay_function = redisplay; rl_redisplay_function = redisplay;
rl_completion_entry_function = (Function*) completion_function; rl_completion_entry_function = (Function*) completion_function;

View file

@ -1250,7 +1250,8 @@
(and (module-binder m) (and (module-binder m)
((module-binder m) m v #t)) ((module-binder m) m v #t))
(begin (begin
(let ((answer (make-undefined-variable v))) (let ((answer (make-undefined-variable)))
(variable-set-name-hint! answer v)
(module-obarray-set! (module-obarray m) v answer) (module-obarray-set! (module-obarray m) v answer)
(module-modified m) (module-modified m)
answer)))) answer))))
@ -1313,43 +1314,28 @@
;; make-root-module ;; make-root-module
;; A root module uses the symhash table (the system's privileged ;; A root module uses the pre-modules-obarray as its obarray. This
;; obarray). Being inside a root module is like using SCM without ;; special obarray accumulates all bindings that have been established
;; any module system. ;; before the module system is fully booted.
;; ;;
;; (The obarray continues to be used by code that has been closed over
;; before the module system has been booted.)
(define (root-module-closure m s define?)
(let ((bi (builtin-variable s)))
(and bi
(or define? (variable-bound? bi))
(begin
(module-add! m s bi)
bi))))
(define (make-root-module) (define (make-root-module)
(make-module 1019 '() root-module-closure)) (let ((m (make-module 0)))
(set-module-obarray! m (%get-pre-modules-obarray))
m))
;; make-scm-module ;; make-scm-module
;; An scm module is a module into which the lazy binder copies ;; The root interface is a module that uses the same obarray as the
;; variable bindings from the system symhash table. The mapping is ;; root module. It does not allow new definitions, tho.
;; 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 (scm-module-closure m s define?)
(let ((bi (builtin-variable s)))
(and bi
(variable-bound? bi)
(begin
(module-add! m s bi)
bi))))
(define (make-scm-module) (define (make-scm-module)
(make-module 1019 '() scm-module-closure)) (let ((m (make-module 0)))
(set-module-obarray! m (%get-pre-modules-obarray))
(set-module-eval-closure! m (standard-interface-eval-closure m))
m))
@ -1422,7 +1408,9 @@
(begin (begin
(variable-set! variable value) (variable-set! variable value)
(module-modified module)) (module-modified module))
(module-add! module name (make-variable value name))))) (let ((variable (make-variable value)))
(variable-set-name-hint! variable name)
(module-add! module name variable)))))
;; MODULE-DEFINED? -- exported ;; MODULE-DEFINED? -- exported
;; ;;
@ -1539,18 +1527,33 @@
(set-module-kind! the-scm-module 'interface) (set-module-kind! the-scm-module 'interface)
(for-each set-system-module! (list the-root-module the-scm-module) '(#t #t)) (for-each set-system-module! (list the-root-module the-scm-module) '(#t #t))
(set-current-module the-root-module) ;; NOTE: This binding is used in libguile/modules.c.
;;
(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 (append (or (module-name module)
'())
(list (car name))))
(module-define! module (car name) m)
(make-modules-in m (cdr name)))))))
(define app (make-module 31)) (define (beautify-user-module! module)
(local-define '(app modules) (make-module 31)) (let ((interface (module-public-interface module)))
(local-define '(app modules guile) the-root-module) (if (or (not interface)
(eq? interface module))
;; (define-special-value '(app modules new-ws) (lambda () (make-scm-module))) (let ((interface (make-module 31)))
(set-module-name! interface (module-name module))
(define (try-load-module name) (set-module-kind! interface 'interface)
(or (try-module-linked name) (set-module-public-interface! module interface))))
(try-module-autoload name) (if (and (not (memq the-scm-module (module-uses module)))
(try-module-dynamic-link name))) (not (eq? module the-root-module)))
(set-module-uses! module (append (module-uses module) (list the-scm-module)))))
;; NOTE: This binding is used in libguile/modules.c. ;; NOTE: This binding is used in libguile/modules.c.
;; ;;
@ -1574,18 +1577,24 @@
;; Get/create it. ;; Get/create it.
(make-modules-in (current-module) full-name)))))) (make-modules-in (current-module) full-name))))))
(define (beautify-user-module! module) ;; Cheat.
(let ((interface (module-public-interface module))) (define try-module-autoload #f)
(if (or (not interface)
(eq? interface module)) ;; This boots the module system. All bindings needed by modules.c
(let ((interface (make-module 31))) ;; must have been defined by now.
(set-module-name! interface (module-name module)) ;;
(set-module-kind! interface 'interface) (set-current-module the-root-module)
(set-module-public-interface! module interface))))
(if (and (not (memq the-scm-module (module-uses module))) (define app (make-module 31))
(not (eq? module the-root-module))) (local-define '(app modules) (make-module 31))
(set-module-uses! module (append (module-uses module) (local-define '(app modules guile) the-root-module)
(list the-scm-module)))))
;; (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)))
(define (purify-module! module) (define (purify-module! module)
"Removes bindings in MODULE which are inherited from the (guile) module." "Removes bindings in MODULE which are inherited from the (guile) module."
@ -1594,21 +1603,10 @@
(eq? (car (last-pair use-list)) the-scm-module)) (eq? (car (last-pair use-list)) the-scm-module))
(set-module-uses! module (reverse (cdr (reverse use-list))))))) (set-module-uses! module (reverse (cdr (reverse use-list)))))))
;; NOTE: This binding is used in libguile/modules.c. (define (resolve-interface name)
;; (let ((module (resolve-module name)))
(define (make-modules-in module name) (and module (module-public-interface module))))
(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 (append (or (module-name module)
'())
(list (car name))))
(module-define! module (car name) m)
(make-modules-in m (cdr name)))))))
;; Return a module interface made from SPEC. ;; Return a module interface made from SPEC.
;; SPEC can be a list of symbols, in which case it names a module ;; SPEC can be a list of symbols, in which case it names a module

View file

@ -109,7 +109,8 @@
;;; A fix to get the error handling working together with the module system. ;;; A fix to get the error handling working together with the module system.
;;; ;;;
(variable-set! (builtin-variable 'debug-options) debug-options) ;;; XXX - Still needed?
(module-set! the-root-module 'debug-options debug-options)

View file

@ -1704,7 +1704,7 @@
(define format format:format) (define format format:format)
;; Thanks to Shuji Narazaki ;; Thanks to Shuji Narazaki
(variable-set! (builtin-variable 'format) format) (module-set! the-root-module 'format format)
;; If this is not possible then a continuation is used to recover ;; If this is not possible then a continuation is used to recover
;; properly from a format error. In this case format returns #f. ;; properly from a format error. In this case format returns #f.

View file

@ -31,7 +31,6 @@
;;; a convenient and attractive syntax. ;;; a convenient and attractive syntax.
;;; ;;;
;;; exported macros are: ;;; exported macros are:
;;; bound?
;;; let-optional ;;; let-optional
;;; let-optional* ;;; let-optional*
;;; let-keywords ;;; let-keywords
@ -61,36 +60,19 @@
(define-module (ice-9 optargs)) (define-module (ice-9 optargs))
;; bound? var
;; Checks if a variable is bound in the current environment.
;;
;; defined? doesn't quite cut it as it stands, since it only
;; checks bindings in the top-level environment, not those in
;; local scope only.
;;
(defmacro-public bound? (var)
`(catch 'misc-error
(lambda ()
,var
(not (eq? ,var ,(variable-ref
(make-undefined-variable)))))
(lambda args #f)))
;; let-optional rest-arg (binding ...) . body ;; let-optional rest-arg (binding ...) . body
;; let-optional* rest-arg (binding ...) . body ;; let-optional* rest-arg (binding ...) . body
;; macros used to bind optional arguments ;; macros used to bind optional arguments
;; ;;
;; These two macros give you an optional argument interface that ;; These two macros give you an optional argument interface that is
;; is very "Schemey" and introduces no fancy syntax. They are ;; very "Schemey" and introduces no fancy syntax. They are compatible
;; compatible with the scsh macros of the same name, but are slightly ;; with the scsh macros of the same name, but are slightly
;; extended. Each of binding may be of one of the forms <var> or ;; extended. Each of binding may be of one of the forms <var> or
;; (<var> <default-value>). rest-arg should be the rest-argument of ;; (<var> <default-value>). rest-arg should be the rest-argument of
;; the procedures these are used from. The items in rest-arg are ;; the procedures these are used from. The items in rest-arg are
;; sequentially bound to the variable namess are given. When rest-arg ;; sequentially bound to the variable namess are given. When rest-arg
;; runs out, the remaining vars are bound either to the default values ;; runs out, the remaining vars are bound either to the default values
;; or left unbound if no default value was specified. rest-arg remains ;; or to `#f' if no default value was specified. rest-arg remains
;; bound to whatever may have been left of rest-arg. ;; bound to whatever may have been left of rest-arg.
;; ;;
@ -130,8 +112,7 @@
(let ((bindings (map (lambda (x) (let ((bindings (map (lambda (x)
(if (list? x) (if (list? x)
x x
(list x (variable-ref (list x #f)))
(make-undefined-variable)))))
BINDINGS))) BINDINGS)))
`(,let-type ,(map proc bindings) ,@BODY))) `(,let-type ,(map proc bindings) ,@BODY)))
@ -219,8 +200,7 @@
;; (lambda* (a b #:optional c d . e) '()) ;; (lambda* (a b #:optional c d . e) '())
;; creates a procedure with fixed arguments a and b, optional arguments c ;; creates a procedure with fixed arguments a and b, optional arguments c
;; and d, and rest argument e. If the optional arguments are omitted ;; and d, and rest argument e. If the optional arguments are omitted
;; in a call, the variables for them are unbound in the procedure. This ;; in a call, the variables for them are bound to `#f'.
;; can be checked with the bound? macro.
;; ;;
;; lambda* can also take keyword arguments. For example, a procedure ;; lambda* can also take keyword arguments. For example, a procedure
;; defined like this: ;; defined like this:

View file

@ -220,15 +220,9 @@ where OPTIONSET is one of debug, read, eval, print
(set! value #t))) (set! value #t)))
(for-each (for-each
(lambda (module) (lambda (module)
(let* ((builtin (or (eq? module the-scm-module) (let* ((name (module-name module))
(eq? module the-root-module))) (obarray (module-obarray module)))
(name (module-name module)) ;; XXX - should use hash-fold here
(obarray (if builtin
(builtin-bindings)
(module-obarray module)))
(get-ref (if builtin
identity
variable-ref)))
(array-for-each (array-for-each
(lambda (oblist) (lambda (oblist)
(for-each (for-each
@ -237,20 +231,19 @@ where OPTIONSET is one of debug, read, eval, print
(display name) (display name)
(display ": ") (display ": ")
(display (car x)) (display (car x))
(cond ((procedure? (get-ref (cdr x))) (cond ((procedure? (variable-ref (cdr x)))
(display separator) (display separator)
(display (get-ref (cdr x)))) (display (variable-ref (cdr x))))
(value (value
(display separator) (display separator)
(display (get-ref (cdr x))))) (display (variable-ref (cdr x)))))
(if (and shadow (if (and shadow
(not (eq? (module-ref module (not (eq? (module-ref module
(car x)) (car x))
(module-ref (current-module) (module-ref (current-module)
(car x))))) (car x)))))
(display " shadowed")) (display " shadowed"))
(newline) (newline))))
)))
oblist)) oblist))
obarray))) obarray)))
modules)))) modules))))
@ -295,12 +288,7 @@ Fourth arg FOLDER is one of
(module-filter (module-filter
(lambda (name var data) (lambda (name var data)
(obarray-filter name (variable-ref var) data)))) (obarray-filter name (variable-ref var) data))))
(cond ((or (eq? module the-scm-module) (cond (module (hash-fold module-filter
(eq? module the-root-module))
(hash-fold obarray-filter
data
(builtin-bindings)))
(module (hash-fold module-filter
data data
(module-obarray module))) (module-obarray module)))
(else data)))))) (else data))))))

View file

@ -114,6 +114,8 @@
(define (compile-method methods types) (define (compile-method methods types)
(let* ((proc (method-procedure (car methods))) (let* ((proc (method-procedure (car methods)))
;; XXX - procedure-source can not be guaranteed to be
;; reliable or efficient
(src (procedure-source proc)) (src (procedure-source proc))
(formals (source-formals src)) (formals (source-formals src))
(body (source-body src))) (body (source-body src)))