X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/1d8cc67a3f4ded443f5efc673a616883cbae9c50..9ec578d9fe450b7e7f9030dc9d930185593aa991:/src/module-proto.lisp diff --git a/src/module-proto.lisp b/src/module-proto.lisp index cce9b86..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. @@ -155,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. @@ -175,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."))