1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 09:47:17 +00:00

Renable :source argument to dofile.

Allows for some more interesting usage of
loaders.
This commit is contained in:
Calvin Rose 2020-04-19 08:54:24 -05:00
parent 0745c15d7b
commit 60f8dd0bfc

View File

@ -2185,6 +2185,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)
@ -2193,8 +2194,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))
@ -2217,7 +2218,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)