sci: update to new reify config

This commit is contained in:
Michiel Borkent 2021-03-06 11:17:39 +01:00
parent 0fae952d4d
commit 1391f028bf

View file

@ -1,6 +1,7 @@
(ns babashka.impl.reify
{:no-doc true}
(:require [clojure.math.combinatorics :as combo]))
(:require [clojure.math.combinatorics :as combo]
[sci.impl.types]))
(set! *warn-on-reflection* false)
@ -8,13 +9,25 @@
"Generates pre-compiled reify combinations"
[methods]
(let [subsets (rest (combo/subsets (seq methods)))]
(reduce (fn [opts classes]
(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
(set (map (fn [[class _]]
(list 'quote class))
classes))
(list 'fn ['methods]
(list* 'reify
(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
@ -24,14 +37,20 @@
(fn [arity]
(list meth arity
(list*
(list 'get-in 'methods
[(list 'quote clazz) (list 'quote meth)])
(list 'get 'methods (list 'quote meth))
arity)))
arities))
methods)))
classes)))))
classes))))))
{}
subsets)))
(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]]}})))