chiark / gitweb /
Work in progress. Mostly bug fixing.
[sod] / src / module-impl.lisp
index 753ca0a1dc86c208417cfd078cbdbdfe37ecd399..5343ad08650fc77cd911d433b2f80a43e80d0df7 100644 (file)
@@ -91,6 +91,19 @@ (defun build-module
       (when (and truename (not (eq (module-state *module*) t)))
        (remhash truename *module-map*)))))
 
+(defun call-with-temporary-module (thunk)
+  "Invoke THUNK in the context of a temporary module, returning its values.
+
+   This is mainly useful for testing things which depend on module variables.
+   This is the functionality underlying `with-temporary-module'."
+  (let ((*module* (make-instance 'module
+                                :name "<temp>"
+                                :state nil)))
+    (call-with-module-environment
+     (lambda ()
+       (module-import *builtin-module*)
+       (funcall thunk)))))
+
 ;;;--------------------------------------------------------------------------
 ;;; Type definitions.