1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-25 22:53:16 +00:00

Update naming *module-make-env* for #1447

This commit is contained in:
Calvin Rose 2024-05-16 19:11:25 -05:00
parent fdaf2e1594
commit fe54013679

View File

@ -2767,11 +2767,11 @@
(defn- check-is-dep [x] (unless (or (string/has-prefix? "/" x) (string/has-prefix? "@" x) (string/has-prefix? "." x)) x)) (defn- check-is-dep [x] (unless (or (string/has-prefix? "/" x) (string/has-prefix? "@" x) (string/has-prefix? "." x)) x))
(defn- check-project-relative [x] (if (string/has-prefix? "/" x) x)) (defn- check-project-relative [x] (if (string/has-prefix? "/" x) x))
(defdyn *module/cache* "Dynamic binding for overriding `module/cache`") (defdyn *module-cache* "Dynamic binding for overriding `module/cache`")
(defdyn *module/paths* "Dynamic binding for overriding `module/cache`") (defdyn *module-paths* "Dynamic binding for overriding `module/cache`")
(defdyn *module/loading* "Dynamic binding for overriding `module/cache`") (defdyn *module-loading* "Dynamic binding for overriding `module/cache`")
(defdyn *module/loaders* "Dynamic binding for overriding `module/loaders`") (defdyn *module-loaders* "Dynamic binding for overriding `module/loaders`")
(defdyn *module/make-env* "Dynamic binding for creating new environments for `import`, `require`, and `dofile`. Overrides `make-env`.") (defdyn *module-make-env* "Dynamic binding for creating new environments for `import`, `require`, and `dofile`. Overrides `make-env`.")
(def module/cache (def module/cache
"A table, mapping loaded module identifiers to their environments." "A table, mapping loaded module identifiers to their environments."
@ -2801,7 +2801,7 @@
keyword name of a loader in `module/loaders`. Returns the modified `module/paths`. keyword name of a loader in `module/loaders`. Returns the modified `module/paths`.
``` ```
[ext loader] [ext loader]
(def mp (dyn *module/paths* module/paths)) (def mp (dyn *module-paths* module/paths))
(defn- find-prefix (defn- find-prefix
[pre] [pre]
(or (find-index |(and (string? ($ 0)) (string/has-prefix? pre ($ 0))) mp) 0)) (or (find-index |(and (string? ($ 0)) (string/has-prefix? pre ($ 0))) mp) 0))
@ -2819,7 +2819,7 @@
(module/add-paths "/init.janet" :source) (module/add-paths "/init.janet" :source)
(module/add-paths ".janet" :source) (module/add-paths ".janet" :source)
(module/add-paths ".jimage" :image) (module/add-paths ".jimage" :image)
(array/insert module/paths 0 [(fn is-cached [path] (if (in (dyn *module/cache* module/cache) path) path)) :preload check-not-relative]) (array/insert module/paths 0 [(fn is-cached [path] (if (in (dyn *module-cache* module/cache) path) path)) :preload check-not-relative])
# Version of fexists that works even with a reduced OS # Version of fexists that works even with a reduced OS
(defn- fexists (defn- fexists
@ -2849,7 +2849,7 @@
``` ```
[path] [path]
(var ret nil) (var ret nil)
(def mp (dyn *module/paths* module/paths)) (def mp (dyn *module-paths* module/paths))
(each [p mod-kind checker] mp (each [p mod-kind checker] mp
(when (mod-filter checker path) (when (mod-filter checker path)
(if (function? p) (if (function? p)
@ -2959,7 +2959,7 @@
:core/stream path :core/stream path
(file/open path :rb))) (file/open path :rb)))
(def path-is-file (= f path)) (def path-is-file (= f path))
(default env ((dyn *module/make-env* make-env))) (default env ((dyn *module-make-env* make-env)))
(def spath (string path)) (def spath (string path))
(put env :source (or source (if-not path-is-file spath path))) (put env :source (or source (if-not path-is-file spath path)))
(var exit-error nil) (var exit-error nil)
@ -3021,12 +3021,12 @@
of files as modules.`` of files as modules.``
@{:native (fn native-loader [path &] (native path (make-env))) @{:native (fn native-loader [path &] (native path (make-env)))
:source (fn source-loader [path args] :source (fn source-loader [path args]
(def ml (dyn *module/loading* module/loading)) (def ml (dyn *module-loading* module/loading))
(put ml path true) (put ml path true)
(defer (put ml path nil) (defer (put ml path nil)
(dofile path ;args))) (dofile path ;args)))
:preload (fn preload-loader [path & args] :preload (fn preload-loader [path & args]
(def mc (dyn *module/cache* module/cache)) (def mc (dyn *module-cache* module/cache))
(when-let [m (in mc path)] (when-let [m (in mc path)]
(if (function? m) (if (function? m)
(set (mc path) (m path ;args)) (set (mc path) (m path ;args))
@ -3037,9 +3037,9 @@
[path args kargs] [path args kargs]
(def [fullpath mod-kind] (module/find path)) (def [fullpath mod-kind] (module/find path))
(unless fullpath (error mod-kind)) (unless fullpath (error mod-kind))
(def mc (dyn *module/cache* module/cache)) (def mc (dyn *module-cache* module/cache))
(def ml (dyn *module/loading* module/loading)) (def ml (dyn *module-loading* module/loading))
(def mls (dyn *module/loaders* module/loaders)) (def mls (dyn *module-loaders* module/loaders))
(if-let [check (if-not (kargs :fresh) (in mc fullpath))] (if-let [check (if-not (kargs :fresh) (in mc fullpath))]
check check
(if (ml fullpath) (if (ml fullpath)