Add actors to repl
This commit is contained in:
parent
1e28556baa
commit
46581e103d
|
@ -70,12 +70,11 @@
|
||||||
(future
|
(future
|
||||||
(reset! vm-state :running)
|
(reset! vm-state :running)
|
||||||
(loop []
|
(loop []
|
||||||
(if (= @vm-state :running)
|
(when (= @vm-state :running)
|
||||||
(do
|
|
||||||
(run! run-process (values @processes))
|
(run! run-process (values @processes))
|
||||||
(recur))
|
(recur)
|
||||||
;; (println "Ludus VM shutting down")
|
;; (println "Ludus VM shutting down")
|
||||||
)))))
|
)))))
|
||||||
|
|
||||||
(defn- stop-vm []
|
(defn- stop-vm []
|
||||||
(reset! vm-state :stopped)
|
(reset! vm-state :stopped)
|
||||||
|
@ -649,24 +648,31 @@
|
||||||
(pp/pprint (ex-data e)))))
|
(pp/pprint (ex-data e)))))
|
||||||
|
|
||||||
(defn interpret-repl
|
(defn interpret-repl
|
||||||
([parsed]
|
|
||||||
(let [base-ctx (volatile! (merge {} prelude/prelude))]
|
|
||||||
(try
|
|
||||||
(let [result (interpret-ast (::parser/ast parsed) base-ctx)]
|
|
||||||
{:result result :ctx base-ctx})
|
|
||||||
(catch clojure.lang.ExceptionInfo e
|
|
||||||
(println "Ludus panicked!")
|
|
||||||
(println (ex-message e))
|
|
||||||
{:result ::error :ctx base-ctx}))))
|
|
||||||
([parsed ctx]
|
([parsed ctx]
|
||||||
(let [orig-ctx @ctx]
|
(let [orig-ctx @ctx
|
||||||
(try
|
process (new-process)
|
||||||
(let [result (interpret-ast (::parser/ast parsed) ctx)]
|
pid (:pid @process)]
|
||||||
{:result result :ctx ctx})
|
(try
|
||||||
(catch clojure.lang.ExceptionInfo e
|
(start-vm)
|
||||||
(println "Ludus panicked!")
|
(with-bindings {#'self pid}
|
||||||
(println (ex-message e))
|
(let [result (interpret-ast (::parser/ast parsed) ctx)]
|
||||||
{:result ::error :ctx (volatile! orig-ctx)})))))
|
{:result result :ctx ctx :pid pid}))
|
||||||
|
(catch clojure.lang.ExceptionInfo e
|
||||||
|
(println "Ludus panicked!")
|
||||||
|
(println (ex-message e))
|
||||||
|
{:result :error :ctx (volatile! orig-ctx) :pid pid}))))
|
||||||
|
([parsed ctx pid]
|
||||||
|
(let [orig-ctx @ctx]
|
||||||
|
(try
|
||||||
|
(start-vm)
|
||||||
|
(with-bindings {#'self pid}
|
||||||
|
(let [result (interpret-ast (::parser/ast parsed) ctx)]
|
||||||
|
{:result result :ctx ctx :pid pid}))
|
||||||
|
(catch clojure.lang.ExceptionInfo e
|
||||||
|
(println "Ludus panicked!")
|
||||||
|
(println (ex-message e))
|
||||||
|
{:result :error :ctx (volatile! orig-ctx) :pid pid}
|
||||||
|
)))))
|
||||||
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
|
|
@ -79,25 +79,30 @@
|
||||||
(defn repl-loop []
|
(defn repl-loop []
|
||||||
(let [session-atom @current-session
|
(let [session-atom @current-session
|
||||||
session @session-atom
|
session @session-atom
|
||||||
orig-ctx (:ctx session)]
|
orig-ctx (:ctx session)
|
||||||
|
pid (:pid session)]
|
||||||
(print (str (:name session) prompt))
|
(print (str (:name session) prompt))
|
||||||
(flush)
|
(flush)
|
||||||
(let [raw-input (read-line)]
|
(let [input (read-line)]
|
||||||
(cond
|
(cond
|
||||||
(= nil raw-input) (exit)
|
(= nil input) (exit)
|
||||||
|
|
||||||
(= "" raw-input) (recur)
|
(= "" input) (recur)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(let [input (if raw-input raw-input (exit))
|
(let [parsed (-> input (scanner/scan) (parser/parse))
|
||||||
parsed (-> input (scanner/scan) (parser/parse))
|
{result :result ctx :ctx pid- :pid}
|
||||||
{result :result ctx :ctx} (interpreter/interpret-repl parsed (:ctx session))]
|
(if pid
|
||||||
|
(interpreter/interpret-repl parsed orig-ctx pid)
|
||||||
|
(interpreter/interpret-repl parsed orig-ctx))]
|
||||||
(if (= result ::interpreter/error)
|
(if (= result ::interpreter/error)
|
||||||
(recur)
|
(recur)
|
||||||
(do
|
(do
|
||||||
(println (show/show result))
|
(println (show/show result))
|
||||||
(when (not (= @ctx @orig-ctx))
|
(when (not (= @ctx @orig-ctx))
|
||||||
(swap! session-atom #(assoc % :ctx ctx)))
|
(swap! session-atom #(assoc % :ctx ctx)))
|
||||||
|
(when (not (= pid pid-))
|
||||||
|
(swap! session-atom #(assoc % :pid pid-)))
|
||||||
(recur))))))))
|
(recur))))))))
|
||||||
|
|
||||||
(defn launch []
|
(defn launch []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user