Draft changes.

This commit is contained in:
Scott Richmond 2024-01-20 18:42:12 -05:00
parent 90c97e7cfe
commit c2943e0ba7
3 changed files with 9 additions and 4 deletions

View File

@ -426,4 +426,4 @@
:floor floor :floor floor
:round round :round round
:range range- :range range-
}) })

View File

@ -664,16 +664,21 @@
) )
)) ))
(def state (atom {})) ;; for now use a global state atom
(defn- interpret-ref [ast ctx] (defn- interpret-ref [ast ctx]
(let [data (:data ast) (let [data (:data ast)
name (-> data first :data first) name (-> data first :data first)
expr (-> data second)] expr (-> data second)]
(when (contains? @ctx name) (when (contains? @ctx name)
(throw (ex-info (str "Name " name " is already bound") {:ast ast}))) (throw (ex-info (str "Name " name " is already bound") {:ast ast})))
(when (contains? @state name)
(throw (ex-info (str "A ref already has " name " name") {:ast ast})))
(let [value (interpret-ast expr ctx) (let [value (interpret-ast expr ctx)
box (atom value) box (atom value)
ref {::data/ref true ::data/value box ::data/name name}] ref {::data/ref true ::data/value box ::data/name name ::data/state state}]
(vswap! ctx update-ctx {name ref}) (vswap! ctx update-ctx {name ref})
(swap! state assoc name ref)
ref))) ref)))
(defn- interpret-loop [ast ctx] (defn- interpret-loop [ast ctx]
@ -1068,4 +1073,4 @@
(println result) (println result)
result result
) )

View File

@ -43,7 +43,7 @@
post_tokens (:tokens post_scanned) post_tokens (:tokens post_scanned)
post_parsed (p/apply-parser g/script post_tokens) post_parsed (p/apply-parser g/script post_tokens)
post_result (i/interpret-safe source post_parsed {} false) post_result (i/interpret-safe source post_parsed {} false)
ludus_result (assoc post_result :result result_str :test test_results) ludus_result (assoc post_result :result result_str :test test_results :state @i/state)
clj_result (ld->clj ludus_result) clj_result (ld->clj ludus_result)
] ]
(cond (cond