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
|
(defmacro gen-reify-combos
|
||||||
"Generates pre-compiled reify combinations"
|
"Generates pre-compiled reify combinations"
|
||||||
[methods]
|
[methods]
|
||||||
(let [subsets (rest (combo/subsets (seq methods)))]
|
(let [prelude ['reify
|
||||||
(reduce (fn [opts [classes protocols?]]
|
'sci.impl.types.IReified
|
||||||
(let [prelude '[reify]
|
'(getInterfaces [this]
|
||||||
prelude (if protocols?
|
interfaces)
|
||||||
(conj prelude
|
'(getMethods [this]
|
||||||
'sci.impl.types.IReified
|
methods)
|
||||||
'(getInterfaces [this]
|
'(getProtocols [this]
|
||||||
interfaces)
|
protocols)]]
|
||||||
'(getMethods [this]
|
(list 'fn ['interfaces 'methods 'protocols]
|
||||||
methods)
|
(concat prelude
|
||||||
'(getProtocols [this]
|
(mapcat (fn [[clazz methods]]
|
||||||
protocols))
|
(cons clazz
|
||||||
prelude)]
|
(mapcat
|
||||||
(assoc opts
|
(fn [[meth arities]]
|
||||||
(cond-> (set (map #(list 'quote %)
|
(map
|
||||||
(map first classes)))
|
(fn [arity]
|
||||||
protocols?
|
(list meth arity
|
||||||
(conj (list 'quote 'sci.impl.types.IReified)))
|
(list*
|
||||||
(list 'fn ['interfaces 'methods 'protocols]
|
(list 'get 'methods (list 'quote meth))
|
||||||
(concat prelude
|
arity)))
|
||||||
(mapcat
|
arities))
|
||||||
(fn [[clazz methods]]
|
methods)))
|
||||||
(cons clazz
|
methods)))))
|
||||||
(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]]}})))
|
|
||||||
|
|
||||||
#_:clj-kondo/ignore
|
#_:clj-kondo/ignore
|
||||||
(def reify-opts
|
(def reify-fn
|
||||||
(gen-reify-combos
|
(gen-reify-combos
|
||||||
{java.nio.file.FileVisitor {preVisitDirectory [[this p attrs]]
|
{java.nio.file.FileVisitor {preVisitDirectory [[this p attrs]]
|
||||||
postVisitDirectory [[this p attrs]]
|
postVisitDirectory [[this p attrs]]
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
[babashka.impl.pprint :refer [pprint-namespace]]
|
[babashka.impl.pprint :refer [pprint-namespace]]
|
||||||
[babashka.impl.process :refer [process-namespace]]
|
[babashka.impl.process :refer [process-namespace]]
|
||||||
[babashka.impl.protocols :refer [protocols-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.repl :as repl]
|
||||||
[babashka.impl.socket-repl :as socket-repl]
|
[babashka.impl.socket-repl :as socket-repl]
|
||||||
[babashka.impl.test :as t]
|
[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
|
:load-fn load-fn
|
||||||
:uberscript uberscript
|
:uberscript uberscript
|
||||||
:readers core/data-readers
|
:readers core/data-readers
|
||||||
:reify reify-opts}
|
:reify-fn reify-fn}
|
||||||
opts (addons/future opts)
|
opts (addons/future opts)
|
||||||
sci-ctx (sci/init opts)
|
sci-ctx (sci/init opts)
|
||||||
_ (vreset! common/ctx sci-ctx)
|
_ (vreset! common/ctx sci-ctx)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue