First pass at new state model: all refs are included in results.
This commit is contained in:
parent
f657da57ef
commit
14780bf6b8
|
@ -85,18 +85,23 @@
|
||||||
(println (stringify-args args))
|
(println (stringify-args args))
|
||||||
:ok)})
|
:ok)})
|
||||||
|
|
||||||
|
(def refs (atom {})) ;; atom not volatile!, maybe we'll be multithreaded someday
|
||||||
|
|
||||||
(def deref- {:name "deref"
|
(def deref- {:name "deref"
|
||||||
::data/type ::data/clj
|
::data/type ::data/clj
|
||||||
:body (fn [ref]
|
:body (fn [ref]
|
||||||
(if (::data/ref ref)
|
(if (::data/ref ref)
|
||||||
(deref (::data/value ref))
|
(get @refs (::data/name ref))
|
||||||
(throw (ex-info "Cannot deref something that is not a ref" {}))))})
|
(throw (ex-info "Cannot deref something that is not a ref" {}))))})
|
||||||
|
|
||||||
(def set!- {:name "set!"
|
(def set!- {:name "set!"
|
||||||
::data/type ::data/clj
|
::data/type ::data/clj
|
||||||
:body (fn [ref value]
|
:body (fn [ref value]
|
||||||
(if (::data/ref ref)
|
(if (::data/ref ref)
|
||||||
|
(do
|
||||||
|
(swap! refs assoc (::data/name ref) value)
|
||||||
(reset! (::data/value ref) value)
|
(reset! (::data/value ref) value)
|
||||||
|
value)
|
||||||
(throw (ex-info "Cannot set! something that is not a ref" {}))))})
|
(throw (ex-info "Cannot set! something that is not a ref" {}))))})
|
||||||
|
|
||||||
(def show {:name "show"
|
(def show {:name "show"
|
||||||
|
|
|
@ -673,6 +673,7 @@
|
||||||
(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}]
|
||||||
|
(swap! base/refs assoc name value)
|
||||||
(vswap! ctx update-ctx {name ref})
|
(vswap! ctx update-ctx {name ref})
|
||||||
ref)))
|
ref)))
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,12 @@
|
||||||
user_result (i/interpret-safe source user_parsed {} testing?)
|
user_result (i/interpret-safe source user_parsed {} testing?)
|
||||||
result_str (show/show user_result)
|
result_str (show/show user_result)
|
||||||
test_results @i/test-results
|
test_results @i/test-results
|
||||||
|
state @base/refs
|
||||||
post_scanned (s/scan pre/postlude "postlude")
|
post_scanned (s/scan pre/postlude "postlude")
|
||||||
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 state)
|
||||||
clj_result (ld->clj ludus_result)
|
clj_result (ld->clj ludus_result)
|
||||||
]
|
]
|
||||||
(cond
|
(cond
|
||||||
|
|
Loading…
Reference in New Issue
Block a user