npmify the things!
This commit is contained in:
parent
478d0347f2
commit
58e0e8b51c
2
deps.edn
2
deps.edn
|
@ -4,6 +4,8 @@
|
|||
babashka/fs {:mvn/version "0.4.19"}
|
||||
}
|
||||
|
||||
:source-paths ["src/ludus"]
|
||||
|
||||
:aliases
|
||||
{:main
|
||||
{:exec-fn ludus.core/main!}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@ludus/ludus",
|
||||
"version": "0.1.0-ALPHA",
|
||||
"description": "Ludus: A friendly, dynamic, functional language",
|
||||
"name": "@ludus/ludus-js-pure",
|
||||
"version": "0.1.0-alpha.1",
|
||||
"description": "A Ludus interpreter in a pure JS function.",
|
||||
"main": "target/js/ludus.js",
|
||||
"directories": {},
|
||||
"keywords": [],
|
||||
|
|
|
@ -880,51 +880,51 @@
|
|||
;(println context)
|
||||
context))
|
||||
|
||||
;; TODO: update this to use new parser pipeline & new AST representation
|
||||
(defn interpret
|
||||
([source parsed] (interpret source parsed {}))
|
||||
([source parsed ctx]
|
||||
(try
|
||||
(let [base-ctx (volatile! {::parent (volatile! (merge ludus-prelude ctx))})]
|
||||
(interpret-ast parsed base-ctx))
|
||||
(catch #?(:cljs :default :clj Throwable) e
|
||||
(println "Ludus panicked!")
|
||||
(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))
|
||||
(pp/pprint (ex-data e)
|
||||
#?(:clj (System/exit 67))
|
||||
)))))
|
||||
; ;; TODO: update this to use new parser pipeline & new AST representation
|
||||
; (defn interpret
|
||||
; ([source parsed] (interpret source parsed {}))
|
||||
; ([source parsed ctx]
|
||||
; (try
|
||||
; (let [base-ctx (volatile! {::parent (volatile! (merge ludus-prelude ctx))})]
|
||||
; (interpret-ast parsed base-ctx))
|
||||
; (catch #?(:cljs :default :clj Throwable) e
|
||||
; (println "Ludus panicked!")
|
||||
; (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))
|
||||
; (pp/pprint (ex-data e)
|
||||
; #?(: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! ludus-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-file [source path parsed]
|
||||
; (try
|
||||
; (let [base-ctx (volatile! {::parent (volatile! ludus-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)})))))
|
||||
; ;; 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)})))))
|
||||
|
||||
(defn interpret-safe [source parsed ctx]
|
||||
(try
|
||||
(let [base-ctx (volatile! {::parent (volatile! (merge ludus-prelude ctx))})]
|
||||
(interpret-ast parsed base-ctx))
|
||||
(catch Throwable e
|
||||
(catch #?(:clj Throwable :cljs js/Object) e
|
||||
(println "Ludus panicked!")
|
||||
(println "On line" (get-in (ex-data e) [:ast :token :line]))
|
||||
(println ">>> " (get-line source (get-in (ex-data e) [:ast :token :line])))
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
(ns ludus.node
|
||||
; (:require [ludus.interpreter :as i]
|
||||
; [ludus.grammar :as g]
|
||||
; [ludus.parser :as p]
|
||||
; [ludus.scanner :as s])
|
||||
(:require [ludus.interpreter :as i]
|
||||
[ludus.grammar :as g]
|
||||
[ludus.parser :as p]
|
||||
[ludus.scanner :as s])
|
||||
)
|
||||
|
||||
(defn run [source]
|
||||
(println "Running source!")
|
||||
(println "(This is a stub.)")
|
||||
(clj->js {
|
||||
:result "Hello, world!"
|
||||
:errors [{:msg "An error"}, {:msg "Another error"}]
|
||||
:console ["Here's a log.", "Here's another log."]
|
||||
:draw [[:background 0]
|
||||
[:fill 255]
|
||||
[:rect 10 10 50 50]]}))
|
||||
(let [scanned (s/scan source)
|
||||
tokens (:tokens scanned)
|
||||
parsed (p/apply-parser g/script tokens)
|
||||
result (i/interpret-safe source parsed {})]
|
||||
(clj->js {:result result
|
||||
:errors []
|
||||
:console []
|
||||
:draw []})))
|
|
@ -5,5 +5,5 @@
|
|||
(def prelude
|
||||
#?(
|
||||
:clj (slurp "src/ludus/prelude.ld")
|
||||
:cljs (r/inline "prelude.ld")
|
||||
:cljs (r/inline "./prelude.ld")
|
||||
))
|
Loading…
Reference in New Issue
Block a user