Fix import+process bug

This commit is contained in:
Scott Richmond 2022-06-02 17:51:30 -04:00
parent 2de1d94a4a
commit 4603dcf980

View File

@ -31,7 +31,7 @@
(throw (ex-info (str "Unbound name: " (:word word)) {:ast word})) (throw (ex-info (str "Unbound name: " (:word word)) {:ast word}))
value))) value)))
(declare interpret-ast match interpret) (declare interpret-ast match interpret interpret-file)
(def processes (atom {})) (def processes (atom {}))
@ -399,7 +399,7 @@
(if (::loader/error (ex-data e)) (if (::loader/error (ex-data e))
(throw (ex-info (ex-message e) {:ast ast})) (throw (ex-info (ex-message e) {:ast ast}))
(throw e)))) (throw e))))
result (-> source (scanner/scan) (parser/parse) (interpret path))] result (-> source (scanner/scan) (parser/parse) (interpret-file path))]
;; (pp/pprint @ctx) ;; (pp/pprint @ctx)
(vswap! ctx update-ctx {name result}) (vswap! ctx update-ctx {name result})
;; (pp/pprint @ctx) ;; (pp/pprint @ctx)
@ -494,9 +494,9 @@
(let [process-atom (get @processes self) (let [process-atom (get @processes self)
inbox (promise) inbox (promise)
clauses (:clauses ast)] clauses (:clauses ast)]
(println "receiving inbox" self) ;; (println "receiving in" self)
(swap! process-atom #(assoc % :inbox inbox :status :idle)) (swap! process-atom #(assoc % :inbox inbox :status :idle))
(println "awaiting message in" self) ;; (println "awaiting message in" self)
(let [msg @inbox] (let [msg @inbox]
(swap! process-atom #(assoc % :status :occupied)) (swap! process-atom #(assoc % :status :occupied))
;; (println "message received by" self ":" msg) ;; (println "message received by" self ":" msg)
@ -626,6 +626,16 @@
(throw (ex-info "Unknown AST node type" {:ast ast})))) (throw (ex-info "Unknown AST node type" {:ast ast}))))
(defn interpret-file [parsed file]
(try
(let [base-ctx (volatile! (merge {:file file} prelude/prelude))]
(interpret-ast (::parser/ast parsed) base-ctx))
(catch clojure.lang.ExceptionInfo e
(println "Ludus panicked in" file)
(println "On line" (get-in (ex-data e) [:ast :token ::token/line]))
(println (ex-message e))
(System/exit 67))))
(defn interpret [parsed file] (defn interpret [parsed file]
(try (try
(let [base-ctx (volatile! (merge {:file file} prelude/prelude)) (let [base-ctx (volatile! (merge {:file file} prelude/prelude))