Compare commits

...

9 commits

Author SHA1 Message Date
Michiel Borkent
7ca72b2ef7 Fix bugs 2021-03-06 10:59:14 +01:00
Michiel Borkent
5e120d3240 fixed 2021-03-06 01:00:15 +01:00
Michiel Borkent
2761f73b0d wip 2021-03-06 00:52:52 +01:00
Michiel Borkent
9344b38494 simplify 2021-03-05 23:23:06 +01:00
Michiel Borkent
e7f0b18716 wip 2021-03-05 22:26:09 +01:00
Michiel Borkent
7baae299a6 fix 2021-03-04 12:34:46 +01:00
Michiel Borkent
67a8c8d4cf add IReified 2021-03-04 12:17:53 +01:00
Michiel Borkent
e4ba7ef56f wip 2021-03-04 11:28:22 +01:00
Michiel Borkent
0655f39dc9 Add sci PR 2021-03-04 10:43:37 +01:00
2 changed files with 45 additions and 26 deletions

2
sci

@ -1 +1 @@
Subproject commit b74cdc1f7f1e9a9136a7439b828f02f22251b901
Subproject commit 32801896e4d9533b3b61453b4ebb813042c59e5c

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,33 +9,51 @@
"Generates pre-compiled reify combinations"
[methods]
(let [subsets (rest (combo/subsets (seq methods)))]
(reduce (fn [opts classes]
(assoc opts
(set (map (fn [[class _]]
(list 'quote class))
classes))
(list 'fn ['methods]
(list* 'reify
(mapcat
(fn [[clazz methods]]
(cons clazz
(mapcat
(fn [[meth arities]]
(map
(fn [arity]
(list meth arity
(list*
(list 'get-in 'methods
[(list 'quote clazz) (list 'quote meth)])
arity)))
arities))
methods)))
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
(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))))))
{}
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]]}})))
{java.io.FileFilter {accept [[this f]]}})))
#_:clj-kondo/ignore
(def reify-opts