From fdaf2e1594bb3b68a9e7c179388ac8afa9025204 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Wed, 15 May 2024 20:16:42 -0500 Subject: [PATCH 1/3] Add *module/make-env* --- CHANGELOG.md | 2 ++ src/boot/boot.janet | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 370f7e8c..efd8fc3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Add *module/make-env* dynamic binding +- Add buffer/format-at - Add long form command line options for readable CLI usage - Fix bug with `net/accept-loop` that would sometimes miss connections. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index f3dbfd2a..8af8fb27 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2771,6 +2771,7 @@ (defdyn *module/paths* "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/make-env* "Dynamic binding for creating new environments for `import`, `require`, and `dofile`. Overrides `make-env`.") (def module/cache "A table, mapping loaded module identifiers to their environments." @@ -2958,7 +2959,7 @@ :core/stream path (file/open path :rb))) (def path-is-file (= f path)) - (default env (make-env (curenv))) + (default env ((dyn *module/make-env* make-env))) (def spath (string path)) (put env :source (or source (if-not path-is-file spath path))) (var exit-error nil) From fe540136794627e5101bbaa10e78475c102fe416 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 16 May 2024 19:11:25 -0500 Subject: [PATCH 2/3] Update naming *module-make-env* for #1447 --- src/boot/boot.janet | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 8af8fb27..c465dfcb 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -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-project-relative [x] (if (string/has-prefix? "/" x) x)) -(defdyn *module/cache* "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/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-cache* "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-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`.") (def module/cache "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`. ``` [ext loader] - (def mp (dyn *module/paths* module/paths)) + (def mp (dyn *module-paths* module/paths)) (defn- find-prefix [pre] (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 ".janet" :source) (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 (defn- fexists @@ -2849,7 +2849,7 @@ ``` [path] (var ret nil) - (def mp (dyn *module/paths* module/paths)) + (def mp (dyn *module-paths* module/paths)) (each [p mod-kind checker] mp (when (mod-filter checker path) (if (function? p) @@ -2959,7 +2959,7 @@ :core/stream path (file/open path :rb))) (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)) (put env :source (or source (if-not path-is-file spath path))) (var exit-error nil) @@ -3021,12 +3021,12 @@ of files as modules.`` @{:native (fn native-loader [path &] (native path (make-env))) :source (fn source-loader [path args] - (def ml (dyn *module/loading* module/loading)) + (def ml (dyn *module-loading* module/loading)) (put ml path true) (defer (put ml path nil) (dofile 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)] (if (function? m) (set (mc path) (m path ;args)) @@ -3037,9 +3037,9 @@ [path args kargs] (def [fullpath mod-kind] (module/find path)) (unless fullpath (error mod-kind)) - (def mc (dyn *module/cache* module/cache)) - (def ml (dyn *module/loading* module/loading)) - (def mls (dyn *module/loaders* module/loaders)) + (def mc (dyn *module-cache* module/cache)) + (def ml (dyn *module-loading* module/loading)) + (def mls (dyn *module-loaders* module/loaders)) (if-let [check (if-not (kargs :fresh) (in mc fullpath))] check (if (ml fullpath) From e914eaf05542b1050bd9a2fa241af0239770ecf0 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 16 May 2024 21:37:08 -0500 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efd8fc3c..6613d4c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? -- Add *module/make-env* dynamic binding +- Add *module-make-env* dynamic binding - Add buffer/format-at - Add long form command line options for readable CLI usage - Fix bug with `net/accept-loop` that would sometimes miss connections.