diff --git a/deps.edn b/deps.edn index 43014bc..dad6c27 100644 --- a/deps.edn +++ b/deps.edn @@ -1,6 +1,7 @@ {:deps {org.clojure/clojurescript {:mvn/version "1.11.121"} thheller/shadow-cljs {:mvn/version "2.26.0"} + babashka/fs {:mvn/version "0.4.19"} } :aliases diff --git a/project.clj b/project.clj index 00f5f78..43d9e8d 100644 --- a/project.clj +++ b/project.clj @@ -4,7 +4,7 @@ :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} :dependencies [[org.clojure/clojure "1.11.1"] - ;[babashka/fs "0.1.6"] + [babashka/fs "0.1.6"] ;[quil "4.0.0-SNAPSHOT"] ] :plugins [[lein-cljfmt "0.8.0"]] diff --git a/src/ludus/grammar.cljc b/src/ludus/grammar.cljc index 2fa5909..f927ffd 100644 --- a/src/ludus/grammar.cljc +++ b/src/ludus/grammar.cljc @@ -249,7 +249,7 @@ (zero+ struct-entry) (quiet :rbrace)]) -(defp use-expr group order-1 [(quiet :use :word)]) +(defp use-expr group order-1 [:use :word]) (defp toplevel flat choice [import-expr ns-expr diff --git a/src/ludus/interpreter.cljc b/src/ludus/interpreter.cljc index 3a39a70..19a100b 100644 --- a/src/ludus/interpreter.cljc +++ b/src/ludus/interpreter.cljc @@ -769,7 +769,7 @@ :match (interpret-match ast ctx) - :cond-expr (interpret-cond ast ctx) + :when-expr (interpret-cond ast ctx) :fn-expr (interpret-fn ast ctx) @@ -783,7 +783,7 @@ :ref-expr (interpret-ref ast ctx) - :when-expr (interpret-ast (-> ast :data first) ctx) + ;:when-expr (interpret-ast (-> ast :data first) ctx) :recur-call {::data/recur true :args (interpret-ast (-> ast :data first) ctx)} @@ -859,5 +859,29 @@ (println ">>> " (get-line source (get-in (ex-data e) [:ast :token :line]))) (println (ex-message e)) (pp/pprint (ex-data e) - ;;(System/exit 67) - ))))) \ No newline at end of file + #?(:clj (System/exit 67)) + ))))) + +;; TODO: update this to use new parser pipeline & new AST representation +(defn interpret-file [source path parsed] + (try + (let [base-ctx (volatile! {::parent (volatile! prelude/prelude) :file path})] + (interpret-ast parsed base-ctx)) + (catch clojure.lang.ExceptionInfo e + (println "Ludus panicked in" path) + (println "On line" (get-in (ex-data e) [:ast :token :line])) + (println ">>> " (get-line source (get-in (ex-data e) [:ast :token :line]))) + (println (ex-message e)) + (System/exit 67)))) + +;; TODO: update this to use new parser pipeline & new AST representation +(defn interpret-repl + ([parsed ctx] + (let [orig-ctx @ctx] + (try + (let [result (interpret-ast parsed ctx)] + {:result result :ctx ctx}) + (catch clojure.lang.ExceptionInfo e + (println "Ludus panicked!") + (println (ex-message e)) + {:result :error :ctx (volatile! orig-ctx)}))))) diff --git a/src/ludus/repl.clj b/src/ludus/repl.clj index 6455f48..7069344 100644 --- a/src/ludus/repl.clj +++ b/src/ludus/repl.clj @@ -1,8 +1,7 @@ (ns ludus.repl (:require [ludus.scanner :as scanner] - ;[ludus.parser :as parser] - [ludus.parser-new :as p] + [ludus.parser :as p] [ludus.grammar :as g] [ludus.interpreter :as interpreter] [ludus.prelude :as prelude] @@ -83,8 +82,7 @@ (defn repl-loop [] (let [session-atom @current-session session @session-atom - orig-ctx (:ctx session) - pid (:pid session)] + orig-ctx (:ctx session)] (print (str (:name session) prompt)) (flush) (let [input (read-line)] @@ -102,18 +100,14 @@ (do (println (p/err-msg parsed)) (recur)) - (let [{result :result ctx :ctx pid- :pid} - (if pid - (interpreter/interpret-repl parsed orig-ctx pid) - (interpreter/interpret-repl parsed orig-ctx))] + (let [{result :result ctx :ctx} + (interpreter/interpret-repl parsed orig-ctx)] (if (= result :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 []