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
{org.clojure/clojurescript {:mvn/version "1.11.121"}
thheller/shadow-cljs {:mvn/version "2.26.0"}
babashka/fs {:mvn/version "0.4.19"}
}
:aliases

View File

@ -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"]]

View File

@ -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

View File

@ -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)
#?(: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
(: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 []