upgrade sci (#30)

This commit is contained in:
Michiel Borkent 2019-08-27 00:06:25 +02:00 committed by GitHub
parent 284cee583d
commit b139664e56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 10 deletions

2
sci

@ -1 +1 @@
Subproject commit e2924e43257fc990d1e7074d7fe23247660e1aad Subproject commit bbd6b444187607c63c0f9570bfb836f2c9eaac50

View file

@ -80,16 +80,12 @@
--time: print execution time before exiting. --time: print execution time before exiting.
")) "))
(defn wrap-do [s]
(format "(do %s)" s))
(defn read-file [file] (defn read-file [file]
(let [f (io/file file)] (let [f (io/file file)]
(if (.exists f) (if (.exists f)
(as-> (slurp file) x (as-> (slurp file) x
;; remove shebang ;; remove shebang
(str/replace x #"^#!.*" "") (str/replace x #"^#!.*" ""))
(wrap-do x))
(throw (Exception. (str "File does not exist: " file)))))) (throw (Exception. (str "File does not exist: " file))))))
(defn get-env (defn get-env
@ -157,8 +153,7 @@
(System/setProperty "javax.net.ssl.tru stAnchors" ca-certs))) (System/setProperty "javax.net.ssl.tru stAnchors" ca-certs)))
(defn load-file* [ctx file] (defn load-file* [ctx file]
(let [s (slurp file) (let [s (slurp file)]
s (wrap-do s)]
(sci/eval-string s ctx))) (sci/eval-string s ctx)))
(defn main (defn main
@ -181,7 +176,7 @@
ctx {:bindings (assoc bindings '*command-line-args* command-line-args) ctx {:bindings (assoc bindings '*command-line-args* command-line-args)
:env env} :env env}
ctx (update ctx :bindings assoc 'load-file #(load-file* ctx %)) ctx (update ctx :bindings assoc 'load-file #(load-file* ctx %))
_preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim) (wrap-do) (sci/eval-string ctx)) _preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim) (sci/eval-string ctx))
exit-code exit-code
(or (or
#_(binding [*out* *err*] #_(binding [*out* *err*]
@ -193,7 +188,7 @@
[(print-help) 0] [(print-help) 0]
:else :else
(try (try
(let [expr (if file (read-file file) (wrap-do expression))] (let [expr (if file (read-file file) expression)]
(loop [in (read-next)] (loop [in (read-next)]
(let [ctx (update ctx :bindings assoc (with-meta '*in* (let [ctx (update ctx :bindings assoc (with-meta '*in*
(when-not stream? {:sci/deref! true})) in)] (when-not stream? {:sci/deref! true})) in)]