X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/aa14a4cddcb96b681d5c19a2ec8bad382f43b264..9ec578d9fe450b7e7f9030dc9d930185593aa991:/src/module-proto.lisp diff --git a/src/module-proto.lisp b/src/module-proto.lisp index 93034a4..4152329 100644 --- a/src/module-proto.lisp +++ b/src/module-proto.lisp @@ -57,13 +57,10 @@ `((setf (documentation ',name 'variable) ,documentation))) (add-module-binding ',name (lambda () ,value-form)))) -(export 'call-with-module-environment) -(defun call-with-module-environment (thunk) - "Invoke THUNK with a new collection of bindings for the module variables." - (progv - (mapcar #'car *module-bindings-alist*) - (mapcar (compose #'cdr #'funcall) *module-bindings-alist*) - (funcall thunk))) +(export 'with-module-environment) +(defmacro with-module-environment ((&optional (module '*module*)) &body body) + "Evaluate the BODY with MODULE's variable bindings in scope." + `(call-with-module-environment (lambda () ,@body) ,module)) ;;;-------------------------------------------------------------------------- ;;; The reset switch. @@ -118,14 +115,16 @@ It's not usual to modify the current module. Inserting things into the `*module-type-map*' is a good plan.") - (:method (object) nil)) + (:method (object) + (declare (ignore object)) + nil)) (export 'add-to-module) (defgeneric add-to-module (module item) (:documentation "Add ITEM to the MODULE's list of accumulated items. - The module items participate in the `module-import' and `add-output-hooks' + The module items participate in the `module-import' and `hook-output' protocols.")) (export 'finalize-module) @@ -153,6 +152,9 @@ (items :initarg :items :initform nil :type list :accessor module-items) (dependencies :initarg :dependencies :initform nil :type list :accessor module-dependencies) + (variables :initarg :variables :type list :accessor module-variables + :initform (mapcar (compose #'cdr #'funcall) + *module-bindings-alist*)) (state :initarg :state :initform nil :accessor module-state)) (:documentation "A module is a container for the definitions made in a source file. @@ -173,6 +175,9 @@ * A list of other modules that this one depends on. + * A list of module-variable values, in the order in which they're named + in `*module-bindings-alist*'. + Modules are usually constructed by the `read-module' function, though there's nothing to stop fancy extensions building modules programmatically.")) @@ -208,4 +213,9 @@ ,@(and truenamep `(:truename ,truename)) ,@(and locationp `(:location ,location)))) +(export 'with-temporary-module) +(defmacro with-temporary-module ((&key) &body body) + "Evaluate BODY within the context of a temporary module." + `(call-with-temporary-module (lambda () ,@body))) + ;;;----- That's all, folks --------------------------------------------------