Finish adding clj stuff back in.

This commit is contained in:
Scott Richmond 2023-11-29 23:09:52 -05:00
parent 29fc3714f8
commit 5fd2ce2583
5 changed files with 35 additions and 16 deletions

View File

@ -1,6 +1,7 @@
{:deps {:deps
{org.clojure/clojurescript {:mvn/version "1.11.121"} {org.clojure/clojurescript {:mvn/version "1.11.121"}
thheller/shadow-cljs {:mvn/version "2.26.0"} thheller/shadow-cljs {:mvn/version "2.26.0"}
babashka/fs {:mvn/version "0.4.19"}
} }
:aliases :aliases

View File

@ -4,7 +4,7 @@
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :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/"} :url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.11.1"] :dependencies [[org.clojure/clojure "1.11.1"]
;[babashka/fs "0.1.6"] [babashka/fs "0.1.6"]
;[quil "4.0.0-SNAPSHOT"] ;[quil "4.0.0-SNAPSHOT"]
] ]
:plugins [[lein-cljfmt "0.8.0"]] :plugins [[lein-cljfmt "0.8.0"]]

View File

@ -249,7 +249,7 @@
(zero+ struct-entry) (zero+ struct-entry)
(quiet :rbrace)]) (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 (defp toplevel flat choice [import-expr
ns-expr ns-expr

View File

@ -769,7 +769,7 @@
:match (interpret-match ast ctx) :match (interpret-match ast ctx)
:cond-expr (interpret-cond ast ctx) :when-expr (interpret-cond ast ctx)
:fn-expr (interpret-fn ast ctx) :fn-expr (interpret-fn ast ctx)
@ -783,7 +783,7 @@
:ref-expr (interpret-ref ast ctx) :ref-expr (interpret-ref ast ctx)
:when-expr (interpret-ast (-> ast :data first) ctx) ;:when-expr (interpret-ast (-> ast :data first) ctx)
:recur-call :recur-call
{::data/recur true :args (interpret-ast (-> ast :data first) ctx)} {::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 ">>> " (get-line source (get-in (ex-data e) [:ast :token :line])))
(println (ex-message e)) (println (ex-message e))
(pp/pprint (ex-data e) (pp/pprint (ex-data e)
;;(System/exit 67) #?(: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)})))))

View File

@ -1,8 +1,7 @@
(ns ludus.repl (ns ludus.repl
(:require (:require
[ludus.scanner :as scanner] [ludus.scanner :as scanner]
;[ludus.parser :as parser] [ludus.parser :as p]
[ludus.parser-new :as p]
[ludus.grammar :as g] [ludus.grammar :as g]
[ludus.interpreter :as interpreter] [ludus.interpreter :as interpreter]
[ludus.prelude :as prelude] [ludus.prelude :as prelude]
@ -83,8 +82,7 @@
(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 [input (read-line)] (let [input (read-line)]
@ -102,18 +100,14 @@
(do (do
(println (p/err-msg parsed)) (println (p/err-msg parsed))
(recur)) (recur))
(let [{result :result ctx :ctx pid- :pid} (let [{result :result ctx :ctx}
(if pid (interpreter/interpret-repl parsed orig-ctx)]
(interpreter/interpret-repl parsed orig-ctx pid)
(interpreter/interpret-repl parsed orig-ctx))]
(if (= result :error) (if (= result :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 []