Add functions for getting const and variable values from native vars
This commit is contained in:
parent
c5aa1f26b7
commit
0cfe7edb36
1 changed files with 48 additions and 0 deletions
|
|
@ -5,6 +5,8 @@
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[insn.core :as insn])
|
[insn.core :as insn])
|
||||||
(:import
|
(:import
|
||||||
|
(clojure.lang
|
||||||
|
IDeref IMeta IObj IReference)
|
||||||
(java.lang.invoke
|
(java.lang.invoke
|
||||||
VarHandle
|
VarHandle
|
||||||
MethodHandle
|
MethodHandle
|
||||||
|
|
@ -592,6 +594,52 @@
|
||||||
[:areturn]]}]}
|
[:areturn]]}]}
|
||||||
^MethodHandle handle))
|
^MethodHandle handle))
|
||||||
|
|
||||||
|
(defn- ensure-address
|
||||||
|
[symbol-or-addr]
|
||||||
|
(if (instance? Addressable symbol-or-addr)
|
||||||
|
(address-of symbol-or-addr)
|
||||||
|
(find-symbol symbol-or-addr)))
|
||||||
|
|
||||||
|
(defn const
|
||||||
|
[symbol-or-addr type]
|
||||||
|
(deserialize (ensure-address symbol-or-addr) [::pointer type]))
|
||||||
|
|
||||||
|
(deftype StaticVariable [addr type meta]
|
||||||
|
Addressable
|
||||||
|
(address [_]
|
||||||
|
addr)
|
||||||
|
IDeref
|
||||||
|
(deref [_]
|
||||||
|
(deserialize addr [::pointer type]))
|
||||||
|
|
||||||
|
IObj
|
||||||
|
(withMeta [_ meta-map]
|
||||||
|
(StaticVariable. addr type (atom meta-map)))
|
||||||
|
IMeta
|
||||||
|
(meta [_]
|
||||||
|
@meta)
|
||||||
|
IReference
|
||||||
|
(resetMeta [_ meta-map]
|
||||||
|
(reset! meta meta-map))
|
||||||
|
(alterMeta [_ f args]
|
||||||
|
(apply swap! meta f args)))
|
||||||
|
|
||||||
|
(defn freset!
|
||||||
|
[^StaticVariable static-var newval]
|
||||||
|
(serialize-into
|
||||||
|
newval (.-type static-var)
|
||||||
|
(slice-global (.-addr static-var) (size-of (.-type static-var)))
|
||||||
|
(global-scope))
|
||||||
|
newval)
|
||||||
|
|
||||||
|
(defn fswap!
|
||||||
|
[static-var f & args]
|
||||||
|
(freset! static-var (apply f @static-var args)))
|
||||||
|
|
||||||
|
(defn static-variable
|
||||||
|
[symbol-or-addr type]
|
||||||
|
(StaticVariable. (ensure-address symbol-or-addr) type (atom nil)))
|
||||||
|
|
||||||
(s/def ::defcfn-args
|
(s/def ::defcfn-args
|
||||||
(s/cat :name simple-symbol?
|
(s/cat :name simple-symbol?
|
||||||
:doc (s/? string?)
|
:doc (s/? string?)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue