sci#540: one reify to rule them all
This commit is contained in:
parent
874593bae9
commit
d72aa3158a
3 changed files with 27 additions and 50 deletions
2
sci
2
sci
|
|
@ -1 +1 @@
|
|||
Subproject commit 076937baa88e774f02d50b967db29b0cdb0a3fb6
|
||||
Subproject commit 7e79c5e4717debbcef39bf972b75475b45facb8d
|
||||
|
|
@ -8,55 +8,32 @@
|
|||
(defmacro gen-reify-combos
|
||||
"Generates pre-compiled reify combinations"
|
||||
[methods]
|
||||
(let [subsets (rest (combo/subsets (seq methods)))]
|
||||
(reduce (fn [opts [classes protocols?]]
|
||||
(let [prelude '[reify]
|
||||
prelude (if protocols?
|
||||
(conj prelude
|
||||
'sci.impl.types.IReified
|
||||
'(getInterfaces [this]
|
||||
interfaces)
|
||||
'(getMethods [this]
|
||||
methods)
|
||||
'(getProtocols [this]
|
||||
protocols))
|
||||
prelude)]
|
||||
(assoc opts
|
||||
(cond-> (set (map #(list 'quote %)
|
||||
(map first classes)))
|
||||
protocols?
|
||||
(conj (list 'quote 'sci.impl.types.IReified)))
|
||||
(list 'fn ['interfaces 'methods 'protocols]
|
||||
(concat prelude
|
||||
(mapcat
|
||||
(fn [[clazz methods]]
|
||||
(cons clazz
|
||||
(mapcat
|
||||
(fn [[meth arities]]
|
||||
(map
|
||||
(fn [arity]
|
||||
(list meth arity
|
||||
(list*
|
||||
(list 'get 'methods (list 'quote meth))
|
||||
arity)))
|
||||
arities))
|
||||
methods)))
|
||||
classes))))))
|
||||
{}
|
||||
(concat (map (fn [subset bool]
|
||||
[subset bool])
|
||||
subsets
|
||||
(repeat true))
|
||||
(map (fn [subset bool]
|
||||
[subset bool])
|
||||
subsets
|
||||
(repeat false))))))
|
||||
|
||||
#_(prn (macroexpand '(gen-reify-combos
|
||||
{java.io.FileFilter {accept [[this f]]}})))
|
||||
(let [prelude ['reify
|
||||
'sci.impl.types.IReified
|
||||
'(getInterfaces [this]
|
||||
interfaces)
|
||||
'(getMethods [this]
|
||||
methods)
|
||||
'(getProtocols [this]
|
||||
protocols)]]
|
||||
(list 'fn ['interfaces 'methods 'protocols]
|
||||
(concat prelude
|
||||
(mapcat (fn [[clazz methods]]
|
||||
(cons clazz
|
||||
(mapcat
|
||||
(fn [[meth arities]]
|
||||
(map
|
||||
(fn [arity]
|
||||
(list meth arity
|
||||
(list*
|
||||
(list 'get 'methods (list 'quote meth))
|
||||
arity)))
|
||||
arities))
|
||||
methods)))
|
||||
methods)))))
|
||||
|
||||
#_:clj-kondo/ignore
|
||||
(def reify-opts
|
||||
(def reify-fn
|
||||
(gen-reify-combos
|
||||
{java.nio.file.FileVisitor {preVisitDirectory [[this p attrs]]
|
||||
postVisitDirectory [[this p attrs]]
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
[babashka.impl.pprint :refer [pprint-namespace]]
|
||||
[babashka.impl.process :refer [process-namespace]]
|
||||
[babashka.impl.protocols :refer [protocols-namespace]]
|
||||
[babashka.impl.reify :refer [reify-opts]]
|
||||
[babashka.impl.reify :refer [reify-fn]]
|
||||
[babashka.impl.repl :as repl]
|
||||
[babashka.impl.socket-repl :as socket-repl]
|
||||
[babashka.impl.test :as t]
|
||||
|
|
@ -569,7 +569,7 @@ Use -- to separate script command line args from bb command line args.
|
|||
:load-fn load-fn
|
||||
:uberscript uberscript
|
||||
:readers core/data-readers
|
||||
:reify reify-opts}
|
||||
:reify-fn reify-fn}
|
||||
opts (addons/future opts)
|
||||
sci-ctx (sci/init opts)
|
||||
_ (vreset! common/ctx sci-ctx)
|
||||
|
|
|
|||
Loading…
Reference in a new issue