mirror of
https://github.com/janet-lang/janet
synced 2024-11-29 03:19:54 +00:00
Also re-add circular dependency detection.
This commit is contained in:
parent
e202d30835
commit
5c612095a1
@ -2101,7 +2101,7 @@
|
|||||||
[ext loader]
|
[ext loader]
|
||||||
(defn- find-prefix
|
(defn- find-prefix
|
||||||
[pre]
|
[pre]
|
||||||
(or (find-index |(string/has-prefix? pre ($ 0)) module/paths) 0))
|
(or (find-index |(and (string? ($ 0)) (string/has-prefix? pre ($ 0))) module/paths) 0))
|
||||||
(array/insert module/paths 0 [(string ":cur:/:all:" ext) loader check-.])
|
(array/insert module/paths 0 [(string ":cur:/:all:" ext) loader check-.])
|
||||||
(def all-index (find-prefix ":all:"))
|
(def all-index (find-prefix ":all:"))
|
||||||
(array/insert module/paths all-index [(string ":all:" ext) loader not-check-.])
|
(array/insert module/paths all-index [(string ":all:" ext) loader not-check-.])
|
||||||
@ -2184,6 +2184,7 @@
|
|||||||
[path &keys
|
[path &keys
|
||||||
{:exit exit
|
{:exit exit
|
||||||
:env env
|
:env env
|
||||||
|
:source src
|
||||||
:expander expander
|
:expander expander
|
||||||
:evaluator evaluator}]
|
:evaluator evaluator}]
|
||||||
(def f (if (= (type path) :core/file)
|
(def f (if (= (type path) :core/file)
|
||||||
@ -2192,8 +2193,8 @@
|
|||||||
(def path-is-file (= f path))
|
(def path-is-file (= f path))
|
||||||
(default env (make-env))
|
(default env (make-env))
|
||||||
(def spath (string path))
|
(def spath (string path))
|
||||||
(put env :current-file (if-not path-is-file spath))
|
(put env :current-file (or src (if-not path-is-file spath)))
|
||||||
(put env :source (if-not path-is-file spath path))
|
(put env :source (or src (if-not path-is-file spath path)))
|
||||||
(defn chunks [buf _] (file/read f 2048 buf))
|
(defn chunks [buf _] (file/read f 2048 buf))
|
||||||
(defn bp [&opt x y]
|
(defn bp [&opt x y]
|
||||||
(def ret (bad-parse x y))
|
(def ret (bad-parse x y))
|
||||||
@ -2216,7 +2217,7 @@
|
|||||||
(if exit (os/exit 1) (eflush))))
|
(if exit (os/exit 1) (eflush))))
|
||||||
:evaluator evaluator
|
:evaluator evaluator
|
||||||
:expander expander
|
:expander expander
|
||||||
:source (if path-is-file "<anonymous>" spath)}))
|
:source (or src (if path-is-file "<anonymous>" spath))}))
|
||||||
(if-not path-is-file (file/close f))
|
(if-not path-is-file (file/close f))
|
||||||
nenv)
|
nenv)
|
||||||
|
|
||||||
@ -2241,12 +2242,14 @@
|
|||||||
(unless fullpath (error mod-kind))
|
(unless fullpath (error mod-kind))
|
||||||
(if-let [check (in module/cache fullpath)]
|
(if-let [check (in module/cache fullpath)]
|
||||||
check
|
check
|
||||||
(do
|
(if-let [check2 (module/loading fullpath)]
|
||||||
(def loader (if (keyword? mod-kind) (module/loaders mod-kind) mod-kind))
|
(error (string "circular dependency " fullpath " detected"))
|
||||||
(unless loader (error (string "module type " mod-kind " unknown")))
|
(do
|
||||||
(def env (loader fullpath args))
|
(def loader (if (keyword? mod-kind) (module/loaders mod-kind) mod-kind))
|
||||||
(put module/cache fullpath env)
|
(unless loader (error (string "module type " mod-kind " unknown")))
|
||||||
env)))
|
(def env (loader fullpath args))
|
||||||
|
(put module/cache fullpath env)
|
||||||
|
env))))
|
||||||
|
|
||||||
(defn import*
|
(defn import*
|
||||||
"Function form of import. Same parameters, but the path
|
"Function form of import. Same parameters, but the path
|
||||||
|
Loading…
Reference in New Issue
Block a user