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