Compare commits
No commits in common. "20ea25761ac1a66398488d6b79e752cb05bb296f" and "8375e19f1ebe9f0781f052c1d6758d0e82491932" have entirely different histories.
20ea25761a
...
8375e19f1e
|
@ -822,50 +822,6 @@
|
||||||
msg-string (show/show msg-value)]
|
msg-string (show/show msg-value)]
|
||||||
(throw (ex-info msg-string {:ast ast}))))
|
(throw (ex-info msg-string {:ast ast}))))
|
||||||
|
|
||||||
; TODO:
|
|
||||||
; this "are we testing?" variable should only obtain on direct-runs,
|
|
||||||
; not in scripts evaluated using `import`
|
|
||||||
(def testing? (volatile! false))
|
|
||||||
|
|
||||||
(def test-results (volatile! [::data/list]))
|
|
||||||
|
|
||||||
(defn- add-test-result [line name status msg]
|
|
||||||
(vswap! test-results conj [::data/tuple line name status msg]))
|
|
||||||
|
|
||||||
(defn- eval-test [ast ctx]
|
|
||||||
(let [name (-> ast :data first :data first)
|
|
||||||
line (-> ast :token :line)
|
|
||||||
expr (-> ast :data second)]
|
|
||||||
(println "Testing " name)
|
|
||||||
(try
|
|
||||||
(let [result (interpret-ast expr ctx)]
|
|
||||||
(if result
|
|
||||||
(add-test-result line name :pass result)
|
|
||||||
(add-test-result line name :fail result)))
|
|
||||||
(catch #?(:clj Throwable :cljs js/Object) e
|
|
||||||
(add-test-result line name :panic (ex-message e))
|
|
||||||
; {::data/error true
|
|
||||||
; :token (get-in (ex-data e) [:ast :token])
|
|
||||||
; :line (get-in (ex-data e) [:ast :token :line])
|
|
||||||
; :message (ex-message e)}
|
|
||||||
)
|
|
||||||
)))
|
|
||||||
|
|
||||||
(defn- interpret-test [ast ctx]
|
|
||||||
(let [testing? @testing?]
|
|
||||||
(if testing? (eval-test ast ctx))
|
|
||||||
::test))
|
|
||||||
|
|
||||||
(def script-result (volatile! nil))
|
|
||||||
|
|
||||||
(defn- interpret-script [ast ctx]
|
|
||||||
(let [lines (:data ast)
|
|
||||||
result (volatile! nil)]
|
|
||||||
(doseq [line lines]
|
|
||||||
(let [line-result (interpret-ast line ctx)]
|
|
||||||
(if (not= ::test line-result) (vreset! result line-result))))
|
|
||||||
@result))
|
|
||||||
|
|
||||||
(defn interpret-ast [ast ctx]
|
(defn interpret-ast [ast ctx]
|
||||||
(case (:type ast)
|
(case (:type ast)
|
||||||
|
|
||||||
|
@ -915,12 +871,11 @@
|
||||||
(interpret-ast last ctx))
|
(interpret-ast last ctx))
|
||||||
|
|
||||||
:script
|
:script
|
||||||
(interpret-script ast ctx)
|
(let [exprs (:data ast)
|
||||||
; (let [exprs (:data ast)
|
inner (pop exprs)
|
||||||
; inner (pop exprs)
|
last (peek exprs)]
|
||||||
; last (peek exprs)]
|
(run! #(interpret-ast % ctx) inner)
|
||||||
; (run! #(interpret-ast % ctx) inner)
|
(interpret-ast last ctx))
|
||||||
; (interpret-ast last ctx))
|
|
||||||
|
|
||||||
;; note that, excepting tuples and structs,
|
;; note that, excepting tuples and structs,
|
||||||
;; runtime representations are bare
|
;; runtime representations are bare
|
||||||
|
@ -938,8 +893,6 @@
|
||||||
; :struct-literal
|
; :struct-literal
|
||||||
; (interpret-struct ast ctx)
|
; (interpret-struct ast ctx)
|
||||||
|
|
||||||
:test-expr (interpret-test ast ctx)
|
|
||||||
|
|
||||||
(throw (ex-info (str "Unknown AST node type " (get ast :type :none) " on line " (get-in ast [:token :line])) {:ast ast}))))
|
(throw (ex-info (str "Unknown AST node type " (get ast :type :none) " on line " (get-in ast [:token :line])) {:ast ast}))))
|
||||||
|
|
||||||
(defn get-line [source line]
|
(defn get-line [source line]
|
||||||
|
@ -1014,10 +967,8 @@
|
||||||
(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 test?]
|
(defn interpret-safe [source parsed ctx]
|
||||||
(let [base-ctx (volatile! {::parent (volatile! (merge ludus-prelude ctx))})]
|
(let [base-ctx (volatile! {::parent (volatile! (merge ludus-prelude ctx))})]
|
||||||
(vreset! testing? test?)
|
|
||||||
(vreset! test-results [::data/list])
|
|
||||||
(try
|
(try
|
||||||
;(println "Running source: " source)
|
;(println "Running source: " source)
|
||||||
(interpret-ast parsed base-ctx)
|
(interpret-ast parsed base-ctx)
|
||||||
|
|
|
@ -30,48 +30,42 @@
|
||||||
(defn clean-out [value]
|
(defn clean-out [value]
|
||||||
#?(:clj value :cljs (clj->js value)))
|
#?(:clj value :cljs (clj->js value)))
|
||||||
|
|
||||||
(defn run
|
(defn run [source]
|
||||||
([source] (run source false))
|
(let [user_scanned (s/scan source "user input")
|
||||||
([source testing?]
|
user_tokens (:tokens user_scanned)
|
||||||
(let [user_scanned (s/scan source "user input")
|
user_parsed (p/apply-parser g/script user_tokens)
|
||||||
user_tokens (:tokens user_scanned)
|
user_result (i/interpret-safe source user_parsed {})
|
||||||
user_parsed (p/apply-parser g/script user_tokens)
|
result_str (show/show user_result)
|
||||||
user_result (i/interpret-safe source user_parsed {} testing?)
|
post_scanned (s/scan pre/postlude "postlude")
|
||||||
result_str (show/show user_result)
|
post_tokens (:tokens post_scanned)
|
||||||
test_results @i/test-results
|
post_parsed (p/apply-parser g/script post_tokens)
|
||||||
post_scanned (s/scan pre/postlude "postlude")
|
post_result (i/interpret-safe source post_parsed {})
|
||||||
post_tokens (:tokens post_scanned)
|
ludus_result (assoc post_result :result result_str)
|
||||||
post_parsed (p/apply-parser g/script post_tokens)
|
clj_result (ld->clj ludus_result)
|
||||||
post_result (i/interpret-safe source post_parsed {} false)
|
]
|
||||||
ludus_result (assoc post_result :result result_str :test test_results)
|
(cond
|
||||||
clj_result (ld->clj ludus_result)
|
(not-empty (:errors user_tokens))
|
||||||
]
|
(clean-out {:errors (:errors user_tokens)})
|
||||||
(cond
|
|
||||||
(not-empty (:errors user_tokens))
|
|
||||||
(clean-out {:errors (:errors user_tokens)})
|
|
||||||
|
|
||||||
(= :err (:status user_parsed))
|
(= :err (:status user_parsed))
|
||||||
(clean-out {:errors [(error/parse-error user_parsed)]})
|
(clean-out {:errors [(error/parse-error user_parsed)]})
|
||||||
|
|
||||||
(::data/error user_result)
|
(::data/error user_result)
|
||||||
(clean-out (assoc (ld->clj post_result) :errors [(error/run-error user_result)]))
|
(clean-out (assoc (ld->clj post_result) :errors [(error/run-error user_result)]))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(clean-out clj_result)
|
(clean-out clj_result)
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
)
|
|
||||||
|
|
||||||
(defn test-run [source] (run source true))
|
|
||||||
|
|
||||||
(do
|
|
||||||
|
|
||||||
|
(comment
|
||||||
(def source "
|
(def source "
|
||||||
|
let times = 4
|
||||||
|
repeat times print! (:foo)
|
||||||
|
|
||||||
")
|
")
|
||||||
|
|
||||||
(-> source run :test println)
|
(-> source run :errors println)
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
(println (p/err-msg parsed))
|
(println (p/err-msg parsed))
|
||||||
(recur))
|
(recur))
|
||||||
(let [{result :result ctx :ctx}
|
(let [{result :result ctx :ctx}
|
||||||
(interpreter/interpret-repl parsed orig-ctx true)]
|
(interpreter/interpret-repl parsed orig-ctx)]
|
||||||
(if (= result :error)
|
(if (= result :error)
|
||||||
(recur)
|
(recur)
|
||||||
(do
|
(do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user