Have to start being more leGit about this hehe :3
This commit is contained in:
69
.clj-kondo/buddho/macros/dhamma.clj
Normal file
69
.clj-kondo/buddho/macros/dhamma.clj
Normal file
@@ -0,0 +1,69 @@
|
||||
(ns buddho.macros.dhamma
|
||||
(:require [clojure.set :as set]))
|
||||
|
||||
(defmacro defconstructor
|
||||
[dh-name & {:keys [meta data defaults dh-defaults]
|
||||
:or {meta {} data {} dh-defaults {}}}]
|
||||
`(defn ~(symbol (str dh-name "!"))
|
||||
[& {:keys [~@(concat (keys meta) (keys data)) ~'dh-args]
|
||||
:or ~defaults}]
|
||||
(#'buddho.core.dhamma/register-dhamma!
|
||||
~(keyword dh-name)
|
||||
(merge
|
||||
~(merge {:name (keyword dh-name)}
|
||||
dh-defaults
|
||||
{:data (set/map-invert data)}
|
||||
{:meta {(keyword dh-name) (set/map-invert meta)}})
|
||||
~'dh-args))))
|
||||
|
||||
(defn extraction-bindings [datasym bindings extractor defaults]
|
||||
`(~datasym
|
||||
(~extractor
|
||||
[~'dhamma ~'parent]
|
||||
~defaults)
|
||||
|
||||
~@(mapcat (fn [[k v]] `(~k (~v ~datasym))) bindings)))
|
||||
|
||||
(defmacro defdhamma [name docstring
|
||||
{:keys [data meta
|
||||
defaults
|
||||
dh-defaults
|
||||
meta-as data-as]
|
||||
:or {defaults {}}}
|
||||
& body]
|
||||
(let [kw (keyword name)
|
||||
default-data
|
||||
(->> data
|
||||
(map (fn [[k v]] [v (defaults k)]))
|
||||
(into {}))
|
||||
default-meta
|
||||
(->> meta
|
||||
(map (fn [[k v]] [v (defaults k)]))
|
||||
(into {}))]
|
||||
`(do
|
||||
(defconstructor ~name
|
||||
:data ~data
|
||||
:meta ~meta
|
||||
:dh-defaults ~dh-defaults
|
||||
:defaults ~defaults)
|
||||
|
||||
(#'buddho.core.state/describe-dhamma!
|
||||
~kw
|
||||
~docstring)
|
||||
|
||||
(defmethod buddho.core.dhamma/impl! ~kw ~(symbol (str "impl-" name))
|
||||
[~'dhamma & [~'parent]]
|
||||
(let [~@(when (or data data-as)
|
||||
(extraction-bindings
|
||||
(or data-as `data#)
|
||||
data
|
||||
'#'buddho.core.dhamma/extract-data
|
||||
default-data))
|
||||
|
||||
~@(when (or meta meta-as)
|
||||
(extraction-bindings
|
||||
(or meta-as `meta#)
|
||||
meta
|
||||
'#'buddho.core.dhamma/extract-meta
|
||||
default-meta))]
|
||||
~@body)))))
|
@@ -1,16 +1,4 @@
|
||||
{:linters
|
||||
|
||||
;; {:clojure-lsp/unused-public-var
|
||||
;; {:level :warning
|
||||
;; :exclude #{sekai.macros.components/defcomponent
|
||||
;; my-ns/bar
|
||||
;; other-ns
|
||||
;; my-func}
|
||||
;; :exclude-regex #{"sekai.macros.components/*"}
|
||||
;; :exclude-when-defined-by #{my-ns/defflow}
|
||||
;; :exclude-when-defined-by-regex #{"sekai.macros.components/*"}
|
||||
;; :exclude-when-contains-meta #{:my-cool-meta}}}
|
||||
|
||||
{
|
||||
:unresolved-symbol
|
||||
{:exclude [(sekai.macros.components/defcomponent)]}
|
||||
@@ -23,6 +11,14 @@
|
||||
:exclude-when-defined-by-regex #{"sekai.macros.components/*"}
|
||||
}
|
||||
}
|
||||
|
||||
:hooks
|
||||
{:analyze-call {sekai.macros.components/defcomponent
|
||||
{:macroexpand {buddho.macros.dhamma/defconstructor
|
||||
buddho.macros.dhamma/defconstructor
|
||||
|
||||
buddho.macros.dhamma/defdhamma
|
||||
buddho.macros.dhamma/defdhamma
|
||||
}
|
||||
|
||||
:analyze-call {sekai.macros.components/defcomponent
|
||||
hooks.macros.components/defcomponent}}}
|
||||
|
Reference in New Issue
Block a user