[#81] fix socket repl issue with &env
This commit is contained in:
parent
945b7685f1
commit
85aeaa354b
3 changed files with 17 additions and 11 deletions
2
sci
2
sci
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4fa8813270910d71a5fd7d590962fa1babbc19db
|
Subproject commit dcfea77c3172c78a6cb053ff51a6faae154b34dc
|
||||||
|
|
@ -6,14 +6,14 @@
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clojure.tools.reader.reader-types :as r]
|
[clojure.tools.reader.reader-types :as r]
|
||||||
[sci.core :refer [eval-string]]
|
[sci.impl.interpreter :refer [opts->ctx eval-edn-vals]]
|
||||||
[sci.impl.parser :as parser]))
|
[sci.impl.parser :as parser]))
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
(defn repl
|
(defn repl
|
||||||
"REPL with predefined hooks for attachable socket server."
|
"REPL with predefined hooks for attachable socket server."
|
||||||
[sci-opts]
|
[sci-ctx]
|
||||||
(let [in (r/indexing-push-back-reader (r/push-back-reader *in*))]
|
(let [in (r/indexing-push-back-reader (r/push-back-reader *in*))]
|
||||||
(m/repl
|
(m/repl
|
||||||
:init #(do (println "Babashka"
|
:init #(do (println "Babashka"
|
||||||
|
|
@ -32,13 +32,13 @@
|
||||||
v))
|
v))
|
||||||
request-exit))
|
request-exit))
|
||||||
:eval (fn [expr]
|
:eval (fn [expr]
|
||||||
(let [ret (eval-string (pr-str expr)
|
(let [ret (eval-edn-vals (update-in sci-ctx
|
||||||
(update sci-opts
|
[:namespaces 'clojure.core]
|
||||||
:bindings
|
merge {'*1 *1
|
||||||
merge {'*1 *1
|
'*2 *2
|
||||||
'*2 *2
|
'*3 *3
|
||||||
'*3 *3
|
'*e *e})
|
||||||
'*e *e}))]
|
[expr])]
|
||||||
ret))
|
ret))
|
||||||
:need-prompt (fn [] true))))
|
:need-prompt (fn [] true))))
|
||||||
|
|
||||||
|
|
@ -49,12 +49,13 @@
|
||||||
[(first parts) (Integer. ^String (second parts))])
|
[(first parts) (Integer. ^String (second parts))])
|
||||||
host+port (if-not host (str "localhost:" port)
|
host+port (if-not host (str "localhost:" port)
|
||||||
host+port)
|
host+port)
|
||||||
|
sci-ctx (opts->ctx sci-opts)
|
||||||
socket (server/start-server
|
socket (server/start-server
|
||||||
{:address host
|
{:address host
|
||||||
:port port
|
:port port
|
||||||
:name "bb"
|
:name "bb"
|
||||||
:accept babashka.impl.socket-repl/repl
|
:accept babashka.impl.socket-repl/repl
|
||||||
:args [sci-opts]})]
|
:args [sci-ctx]})]
|
||||||
(println "Babashka socket REPL started at" host+port)
|
(println "Babashka socket REPL started at" host+port)
|
||||||
socket))
|
socket))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,11 @@
|
||||||
(testing "*command-line-args*"
|
(testing "*command-line-args*"
|
||||||
(is (str/includes? (socket-command '*command-line-args*)
|
(is (str/includes? (socket-command '*command-line-args*)
|
||||||
"\"a\" \"b\" \"c\"")))
|
"\"a\" \"b\" \"c\"")))
|
||||||
|
(testing "&env"
|
||||||
|
(socket-command '(defmacro bindings [] (mapv #(list 'quote %) (keys &env))))
|
||||||
|
(socket-command '(defn bar [x y z] (bindings)))
|
||||||
|
(is (str/includes? (socket-command '(bar 1 2 3))
|
||||||
|
"[x y z]")))
|
||||||
(finally
|
(finally
|
||||||
(if tu/jvm?
|
(if tu/jvm?
|
||||||
(stop-repl!)
|
(stop-repl!)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue