Add interpret-if-let

This commit is contained in:
Scott Richmond 2022-06-19 13:46:11 -04:00
parent ed14b97a00
commit 689f3f23bc

View File

@ -165,11 +165,15 @@
(throw (ex-info (:reason match) {:ast ast}))) (throw (ex-info (:reason match) {:ast ast})))
value)) value))
(defn- interpret-if-let [ast ctx])
(defn- interpret-if [ast ctx] (defn- interpret-if [ast ctx]
(let [if-expr (:if ast) (let [if-expr (:if ast)
then-expr (:then ast) then-expr (:then ast)
else-expr (:else ast) else-expr (:else ast)
if-value (interpret-ast if-expr ctx)] if-value (if (= (::ast/type if-expr) ::ast/let)
(interpret-if-let if-expr ctx)
(interpret-ast if-expr ctx))]
(if if-value (if if-value
(interpret-ast then-expr ctx) (interpret-ast then-expr ctx)
(interpret-ast else-expr ctx)))) (interpret-ast else-expr ctx))))
@ -608,8 +612,8 @@
(with-bindings {#'self (:pid @process)} (with-bindings {#'self (:pid @process)}
(let [result (interpret-ast (::parser/ast parsed) base-ctx)] (let [result (interpret-ast (::parser/ast parsed) base-ctx)]
(swap! process #(assoc % :status :dead)) (swap! process #(assoc % :status :dead))
result)) (process/stop-vm)
(process/stop-vm)) result)))
(catch clojure.lang.ExceptionInfo e (catch clojure.lang.ExceptionInfo e
(process/stop-vm) (process/stop-vm)
(println "Ludus panicked!") (println "Ludus panicked!")
@ -645,30 +649,12 @@
))))) )))))
(comment (do
(process/start-vm) (process/start-vm)
(def source " (def source "
fn echo () -> { let foo = 3
& print (self, :echoing)
loop () with () -> {
& print (self, :looping)
receive {
msg -> {
print (\"from \", self, \": \", msg)
recur ()
}
}
}
}
let echoer = spawn echo () if let 3 = foo then :foo else :bar
send :hello to echoer
send :foo to echoer
send :bar to echoer
send :baz to echoer
sleep (1000)
") ")