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