This commit is contained in:
Michiel Borkent 2020-05-25 14:47:38 +02:00
parent 9a70ecfd9d
commit 1235a92f18
5 changed files with 38 additions and 12 deletions

View file

@ -12,4 +12,4 @@
:username :env/babashka_nrepl_clojars_user :username :env/babashka_nrepl_clojars_user
:password :env/babashka_nrepl_clojars_pass :password :env/babashka_nrepl_clojars_pass
:sign-releases false}]] :sign-releases false}]]
:profiles {:test {:dependencies [[borkdude/sci "0.0.13-alpha.26"]]}}) :profiles {:test {:dependencies [[borkdude/sci "0.0.13-alpha.27"]]}})

View file

@ -236,8 +236,8 @@
(defn load-ns [pod namespace callback] (defn load-ns [pod namespace callback]
(let [id (next-id) (let [id (next-id)
callback (fn [reply] callback (fn [reply]
(let [namespace (bencode->namespace pod reply)] (let [[name-sym vars] (bencode->namespace pod reply)]
(callback namespace)))] (callback {:name name-sym :vars vars})))]
(swap! callbacks assoc id callback) (swap! callbacks assoc id callback)
(write (:stdin pod) (write (:stdin pod)
{"op" "load" {"op" "load"

View file

@ -13,7 +13,9 @@
(sci/new-var (sci/new-var
(symbol (str ns-name) (str var-name)) var-value)) (symbol (str ns-name) (str var-name)) var-value))
(string? var-value) (string? var-value)
(sci/eval-string* ctx var-value)))))) (do
(prn "eval" @sci/ns var-value)
(sci/eval-string* ctx var-value)))))))
(def load-pod (def load-pod
(with-meta (with-meta
@ -40,9 +42,11 @@
v) v)
v))))})) v))))}))
namespaces (:namespaces pod) namespaces (:namespaces pod)
namespaces-to-load (when (contains? (:ops pod) :load) load? (contains? (:ops pod) :load)
(set (filter (fn [[_ns-name vars]] namespaces-to-load (when load?
(nil? vars)) (set (keep (fn [[ns-name vars]]
(when (empty? vars)
ns-name))
namespaces)))] namespaces)))]
(when (seq namespaces-to-load) (when (seq namespaces-to-load)
(let [load-fn (fn load-fn [{:keys [:namespace]}] (let [load-fn (fn load-fn [{:keys [:namespace]}]
@ -57,7 +61,9 @@
(when prev-load-fn (when prev-load-fn
(prev-load-fn m))))] (prev-load-fn m))))]
(swap! env assoc :load-fn new-load-fn))) (swap! env assoc :load-fn new-load-fn)))
(doseq [[ns-name vars] namespaces] (doseq [[ns-name vars] namespaces
:when (or (not load)
(seq vars))]
(process-namespace ctx {:name ns-name :vars vars})) (process-namespace ctx {:name ns-name :vars vars}))
(sci/future (impl/processor pod)) (sci/future (impl/processor pod))
{:pod/id (:pod-id pod)}))) {:pod/id (:pod-id pod)})))

View file

@ -80,8 +80,10 @@
;; reads thing with other tag ;; reads thing with other tag
{"name" "read-other-tag" {"name" "read-other-tag"
"code" "(defn read-other-tag [x] [x x])"}] "code" "(defn read-other-tag [x] [x x])"}]
dependents)}] dependents)}
"ops" {"shutdown" {}}}) {"name" "pod.test-pod.loaded"}]
"ops" {"shutdown" {}
"load" {}}})
(recur)) (recur))
:invoke (let [var (-> (get message "var") :invoke (let [var (-> (get message "var")
read-string read-string
@ -156,7 +158,20 @@
"id" id "id" id
"value" "#my/other-tag[1]"})) "value" "#my/other-tag[1]"}))
(recur)) (recur))
:shutdown (System/exit 0)))))) :shutdown (System/exit 0)
:load (let [path (-> (get message "path")
read-string
symbol)
id (-> (get message "id")
read-string)]
(case path
pod.test-pod.loaded
(write
{"status" ["done"]
"id" id
"name" "pod.test-pod.loaded"
"vars" [{"name" "loaded"
"code" "(defn loaded [x] (inc x))"}]}))))))))
(catch Exception e (catch Exception e
(binding [*out* *err*] (binding [*out* *err*]
(prn e)))))) (prn e))))))

View file

@ -46,6 +46,10 @@
(def tagged (pod/reader-tag)) (def tagged (pod/reader-tag))
(def other-tagged (pod/other-tag)) (def other-tagged (pod/other-tag))
(require '[pod.test-pod.loaded])
(def loaded (pod.test-pod.loaded/loaded 1))
(pods/unload-pod pod-id) (pods/unload-pod pod-id)
(def successfully-removed (nil? (find-ns 'pod.test-pod))) (def successfully-removed (nil? (find-ns 'pod.test-pod)))
@ -63,4 +67,5 @@
successfully-removed successfully-removed
x9 x9
tagged tagged
other-tagged] other-tagged
loaded]